Data processing method and device of distributed system, electronic equipment, medium and product

By controlling write operations with write locks in a distributed system, data is written and released in a predetermined order between the database and the local cache, solving the problem of high complexity in heterogeneous distributed transaction deployment and achieving the effects of reducing operation and maintenance costs and improving data consistency.

CN123138202APending Publication Date: 2026-11-20INSPUR SUZHOU INTELLIGENT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611530664.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-09-29
Publication Date
2026-11-20

AI Technical Summary

Technical Problem

In distributed systems, the deployment complexity of heterogeneous distributed transactions is high, leading to increased operation and maintenance costs, making it difficult to reduce operation and maintenance costs while ensuring the consistency of cache and database data.

Method used

By controlling write operations on the data to be written, we ensure that writes are completed in a predetermined order between the database and the local cache of the master control node, and release the write lock after all operations are completed, so as to maintain data consistency and reduce additional overhead.

Benefits of technology

While ensuring data consistency between the cache and the database, this reduces the operation and maintenance costs of the distributed system, improves the efficiency of concurrent data writing, and reduces additional overhead.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN123138202A_ABST
    Figure CN123138202A_ABST
Patent Text Reader

Abstract

The application discloses a data processing method and device of a distributed system, electronic equipment, medium and product. The distributed system comprises a main control node and multiple write locks. The method comprises the following steps: in response to a data write request, determining to-be-written data; determining a target write lock corresponding to the to-be-written data from the multiple write locks; locking a write operation of the to-be-written data based on the target write lock; performing the write operation on the to-be-written data, and sequentially writing the to-be-written data to a preset database and a local cache of the main control node; after successfully writing the to-be-written data to the local cache of the main control node, determining that the write operation on the to-be-written data is completed, and releasing the target write lock. Based on the data processing method of the distributed system provided in the application, the operation and maintenance cost of the distributed system can be reduced under the premise of ensuring the consistency of data in the cache and the database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of distributed data storage technology, and in particular to a data processing method, apparatus, electronic device, medium and product for a distributed system. Background Technology

[0002] In distributed systems, caching is often used to reduce direct database access, thereby improving system performance. However, for industries with extremely high data accuracy requirements, ensuring consistency between the cache and the database is essential. Currently, heterogeneous distributed transactions are mainly used to ensure the atomicity of operations between the cache and the database, thus guaranteeing data consistency. However, implementing heterogeneous distributed transactions requires a distributed transaction coordinator, and deploying a distributed transaction coordinator requires additional coordinator components, resulting in high deployment complexity and consequently high operational costs for the distributed system. Therefore, providing a method to reduce the operational costs of distributed systems while ensuring data consistency between the cache and the database has become a pressing issue in this field. Summary of the Invention

[0003] This application provides a data processing method, apparatus, electronic device, medium, and product for a distributed system, which can reduce the operation and maintenance costs of a distributed system while ensuring data consistency between the cache and the database.

[0004] This application provides a data processing method for a distributed system, the distributed system including a master control node and multiple write locks, the method including:

[0005] In response to a data write request, determine the data to be written;

[0006] Determine the target write lock corresponding to the data to be written from multiple write locks;

[0007] The write operation on the data to be written is locked based on the target write lock;

[0008] Perform write operations on the data to be written, and write the data to be written to the preset database and the local cache of the main control node in sequence;

[0009] After successfully writing the data to be written to the local cache of the master control node, the write operation on the data to be written is determined to be complete, and the target write lock is released.

[0010] This application also provides a data processing apparatus for a distributed system, the distributed system including a master control node and multiple write locks, the apparatus comprising:

[0011] The determination module is used to determine the data to be written in response to a data write request;

[0012] The determination module is also used to determine the target write lock corresponding to the data to be written from multiple write locks;

[0013] The processing module is used to lock the write operation of the data to be written based on the target write lock;

[0014] The processing module is also used to perform write operations on the data to be written, writing the data to be written sequentially to the preset database and the local cache of the main control node;

[0015] The processing module is also used to determine that the write operation of the data to be written is complete and release the target write lock after the data to be written is successfully written to the local cache of the master control node.

[0016] This application also provides an electronic device, including: a memory for storing a computer program; and a processor for executing the computer program to implement the steps of the data processing method of the distributed system described above.

[0017] This application also provides a computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the steps of the data processing method of the above-described distributed system.

[0018] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the steps of the data processing method of the distributed system described above.

[0019] The data processing method, apparatus, electronic device, medium, and product for distributed systems provided in this application control the data to be written by using write locks and completing the writing between the database and the local cache of the main control node in a predetermined order. The write locks are only released after all write operations are completed. Therefore, data consistency between the cache and the database can be maintained through write locks. Furthermore, ensuring data consistency through write locks reduces additional overhead. Therefore, the data processing method for distributed systems provided in this application can reduce the operation and maintenance costs of distributed systems while ensuring data consistency between the cache and the database. Attached Figure Description

[0020] To more clearly illustrate the embodiments of this application, the accompanying drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0021] Figure 1 This is a schematic diagram of a scenario provided for an embodiment of this application;

[0022] Figure 2A flowchart illustrating the data processing method for a distributed system provided in this application embodiment. Figure 1 ;

[0023] Figure 3 A flowchart illustrating the data processing method for a distributed system provided in this application embodiment. Figure 2 ;

[0024] Figure 4 A flowchart illustrating the data processing method for a distributed system provided in this application embodiment. Figure 3 ;

[0025] Figure 5 A flowchart illustrating the data processing method for a distributed system provided in this application embodiment. Figure 4 ;

[0026] Figure 6 A flowchart illustrating the data processing method for a distributed system provided in this application embodiment. Figure 5 ;

[0027] Figure 7 Here is an example of the overall flowchart for processing a data write request;

[0028] Figure 8 A flowchart illustrating the data processing method for a distributed system provided in this application embodiment. Figure 6 ;

[0029] Figure 9 A flowchart illustrating the data processing method for a distributed system provided in this application embodiment. Figure 7 ;

[0030] Figure 10 A flowchart illustrating the data processing method for a distributed system provided in this application embodiment. Figure 8 ;

[0031] Figure 11 A flowchart illustrating the data processing method for a distributed system provided in this application embodiment. Figure 9 ;

[0032] Figure 12 This is a schematic diagram of the structure of a data processing device for a distributed system provided in an embodiment of this application;

[0033] Figure 13 A schematic diagram of the structure of the electronic device provided in this application. Detailed Implementation

[0034] The technical solutions of the embodiments of this application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of this application, and not all embodiments. Based on the embodiments of this application, other embodiments obtained by those of ordinary skill in the art without creative effort are all within the protection scope of this application.

[0035] It should be noted that, in the description of this application, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. The terms "first," "second," etc., in this application are used to distinguish similar objects and are not used to describe a specific order or sequence.

[0036] It should also be noted that the terms "center," "longitudinal," "lateral," "length," "width," "thickness," "upper," "lower," "front," "rear," "left," "right," "vertical," "horizontal," "top," "bottom," "inner," "outer," "clockwise," "counterclockwise," "axial," "radial," and "circumferential," etc., indicating orientation or positional relationships based on the orientation or positional relationships shown in the accompanying drawings, are only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation, and therefore should not be construed as a limitation of this application. The terms "installed," "connected," and "linked" should be interpreted broadly, for example, they can be fixed connections, detachable connections, or integral connections; they can be mechanical connections or electrical connections; they can be direct connections or indirect connections through an intermediate medium; they can be internal connections between two elements. The terms "parallel," "perpendicular," and "equal" include the described situation and situations similar to the described situation, the range of which is within an acceptable deviation range, wherein the acceptable deviation range is determined by those skilled in the art taking into account the measurement under discussion and the error associated with the measurement of a particular quantity (i.e., the limitations of the measurement system). For example, "parallel" includes absolute parallelism and approximate parallelism, where an acceptable deviation range for approximate parallelism can be, for example, within 5°; "perpendicular" includes absolute perpendicularity and approximate perpendicularity, where an acceptable deviation range for approximate perpendicularity can also be, for example, within 5°. "Equal" includes absolute equality and approximate equality, where an acceptable deviation range for approximate equality can be, for example, a difference between the two equal items being less than or equal to 5% of either one. Those skilled in the art will understand the specific meaning of the above terms in this application based on the specific circumstances.

[0037] Figure 1 This is a schematic diagram of a scenario provided for an embodiment of this application, such as... Figure 1 As shown, a distributed system includes a master control node and multiple backup control nodes (backup control node 1 to backup control node n), responsible for distributing and processing all data processing requests. When the frequency of database access requests is too high, it leads to low database access efficiency, which often becomes a bottleneck for system performance. To improve system performance, caching is often used to reduce direct database access. Specifically, data stored in the database can be cached locally on the master control node. When processing data processing requests, the master control node prioritizes accessing the local cache to reduce direct database access.

[0038] However, for industries with extremely high data accuracy requirements, ensuring data consistency between the cache and the database is an indispensable prerequisite. Currently, heterogeneous distributed transactions are mainly used to ensure the atomicity of operations between the cache and the database, thereby guaranteeing data consistency. However, implementing heterogeneous distributed transactions requires the introduction of a distributed transaction coordinator, and the deployment of a distributed transaction coordinator requires additional coordinator components, resulting in high deployment complexity and consequently high operational costs for the distributed system. Therefore, providing a method to reduce the operational costs of distributed systems while ensuring data consistency between the cache and the database has become a pressing issue in this field.

[0039] The data processing method, apparatus, electronic device, medium, and product for distributed systems provided in this application control the write operation of the data to be written using write locks and complete the writing between the database and the local cache of the main control node in a predetermined order. The write lock is released only after all write operations are completed, thus maintaining data consistency between the cache and the database through write locks. Furthermore, ensuring data consistency through write locks reduces additional overhead. Therefore, the data processing method for distributed systems provided in this application can reduce the operation and maintenance costs of distributed systems while ensuring data consistency between the cache and the database.

[0040] This application provides a data processing method for a distributed system. The method is described in detail below: The distributed system includes a master control node and multiple write locks. The distributed system architecture mainly consists of a control node and a distributed cluster database. The control node includes a master control node and backup control nodes. The master control node is the sole business logic processing process in the distributed system, responsible for distributing and processing data processing requests from all clients. The master control node is also the only path for operating the underlying database; therefore, there can only be one master control node in the distributed system at any given time. The distributed system includes at least one backup control node. When the master control node fails, causing its permissions to be revoked, one of the backup control nodes becomes the new master control node and takes over the business operations to ensure business continuity.

[0041] Figure 2 A flowchart illustrating the data processing method for a distributed system provided in this application embodiment. Figure 1 ,like Figure 2 As shown, it includes:

[0042] S201. In response to a data write request, determine the data to be written.

[0043] For example, the execution entity of this disclosure is the main control node. The data write request can be sent by the business layer to the main control node after receiving a new, modified or overwrite business operation. After receiving the request, the main control node parses the data content to be written from the data body, field set or business instruction carried in the request, and determines the data content as the data to be written.

[0044] S202. Determine the target write lock corresponding to the data to be written from multiple write locks.

[0045] For example, a distributed system includes a set of write locks consisting of a predetermined number of write locks. The target write lock is used for mutual exclusion control of concurrent writes to the same data to be written, preventing multiple write requests from simultaneously entering the subsequent write chain on the same data. The master control node can use the identification information in the data to be written to perform a mapping lookup of each write lock in the write lock set, thereby obtaining the target write lock corresponding to that data. This identification information can be the data name of the data to be written, and can be represented by a "key".

[0046] Optional, Figure 3 A flowchart illustrating the data processing method for a distributed system provided in this application embodiment. Figure 2 ,like Figure 3 As shown, S202 includes:

[0047] S301. Determine the number of write locks and the number of each write lock in the distributed system.

[0048] For example, the number of write locks can be pre-configured to be multiple, and each write lock is assigned a unique number. For instance, if the number of write locks is n, the write lock numbers can be: write lock 1, write lock 2, write lock 3, up to write lock n.

[0049] S302. The target value corresponding to the data to be written is obtained by performing calculations on the data to be written using a preset algorithm.

[0050] For example, the preset algorithm is used to calculate the identification information in the data to be written to obtain the corresponding target value. Optionally, the preset algorithm can be a hash algorithm, which is used to calculate the target value by performing a hash operation on the data name "key" in the data to be written.

[0051] S303. Based on the target value, perform a modulo operation on the number of write locks to obtain the corresponding modulo result.

[0052] For example, the target value is moduloed by the number of write locks, that is, the target value is divided by n and the remainder is used as the modulo result.

[0053] S304. Match the modulo result with the number of each write lock to obtain the target write lock.

[0054] For example, the modulo result is used to determine the target write lock number, thus obtaining the target write lock. For instance, if the modulo result is "1", then write lock 1 is determined as the target write lock.

[0055] Based on the method provided in this example, the mapping relationship between the data to be written and the target write lock is clear, and the lock allocation result can be stably determined by the number and number of write locks. Therefore, when writing different data concurrently, different data can be distributed to different write locks, and the data corresponding to different write locks can be written concurrently, thereby improving the efficiency of concurrent data writing.

[0056] Optionally, if the target write lock is detected to be in an occupied state, wait for the target write lock to be updated to an idle state before calling the target write lock to lock the write operation of the data to be written.

[0057] For example, if write lock 1 is detected as occupied, it means that the write lock is currently in use, and the write operation to the data to be written should be temporarily stopped. The latest status of write lock 1 can be detected in real time according to a preset detection period, which can be determined according to the actual situation, for example, 5 seconds. After the latest status of write lock 1 is updated to idle, write lock 1 can be called again to lock the write operation to the data to be written.

[0058] S203. Lock the write operation of the data to be written based on the target write lock.

[0059] For example, a distributed system includes a lock management unit, which manages the write locks in the write lock set. After identifying a target write lock, the master control node sends an acquisition request to the lock management unit. The lock management unit returns a successful acquisition indication if the target write lock is idle, and a blocked or waiting state if the target write lock is already held by another write request. After successfully acquiring the target write lock, the master control node marks the write operation to the data to be written as locked and includes the data to be written within the protection scope of the target write lock. At this time, other write requests for this data must queue and cannot enter the database write and local cache update phases.

[0060] S204. Execute the write operation on the data to be written, and write the data to be written to the preset database and the local cache of the main control node in sequence.

[0061] For example, the default database is a distributed cluster database in a distributed system, primarily responsible for the persistent storage of business data. After confirming that the data to be written has been locked by the target write lock, the master control node first writes the data to the database. Upon receiving the write command, the database performs insert, update, or overwrite operations on the data to be written and returns the processing result upon successful write. After confirming successful database write, the master control node then writes the data to its local cache. The local cache, located on the master control node, is used to store a copy of the data written to the database and maintains consistency with the current data state in the database.

[0062] Optional, Figure 4 A flowchart illustrating the data processing method for a distributed system provided in this application embodiment. Figure 3 ,like Figure 4 As shown, S204 includes:

[0063] S401. Call the preset write interface to perform the first write operation of writing the data to be written to the database based on the write interface.

[0064] For example, the main control node's data operations can be encapsulated into a unified object interface, including write and read interfaces. The database and cache use the same write and read interfaces for data writing and reading. The object interface encapsulates logic for data serialization, deserialization, caching, error retry mechanisms, and database read / write operations. Business logic does not need to be aware of the specific implementations of the cache and database; it only needs to call the object interface to complete data operations. This design clarifies business semantics and improves system flexibility and maintainability. Therefore, the write interface can be directly called to perform the first write operation and write the data to be written to the database.

[0065] S402. After successfully writing the data to be written to the database, obtain the first version number corresponding to this write of the data to be written.

[0066] For example, the first version number is used to identify the data status after the write, and is usually returned by the database after a successful commit, and maintains a corresponding relationship with the data to be written.

[0067] S403. Determine the first data name of the data to be written.

[0068] For example, the first data name is used to identify the index key value "key" of the data to be written in the local cache.

[0069] S404. Check if the first data name exists in the local cache.

[0070] For example, the master control node performs a key-value lookup in the local cache for the "key" value of the data to be written, which can determine whether there is historical data cached before the data to be written exists in the local cache.

[0071] S405. If the first data name does not exist in the local cache, then a second write operation is performed based on the write interface to write the data to be written, the first version number, and the first data name to the local cache.

[0072] For example, if the query result shows that the "key" value of the data to be written does not yet exist in the local cache, it means that no historical data of any version of that "key" value has been cached locally before. Therefore, this is the first time the data to be written is written to the cache. The second write operation is to write the data to be written, the current first version number, and the "key" value of the data to be written together to the local cache. By writing the "key" value of the data to be written, the cache location of the data to be written in the local cache is determined, and the data to be written and the current first version number are stored in the corresponding cache location.

[0073] S406. If the first data name exists in the local cache, the data to be written, the first version number, and the first data name are associated, and a third write operation is performed based on the write interface to write the data to be written and the first version number to the local cache, so as to update the cache data corresponding to the first data name in the local cache.

[0074] For example, when the query result shows that the "key" value of the data to be written exists in the local cache, it means that historical data and corresponding historical versions of that "key" value previously existed in the local cache. Therefore, the third write operation can be performed this time. It is not necessary to repeatedly write the "key" value of the data to be written, i.e., the first data name of the data to be written, into the local cache; only the data to be written and the current first version number need to be written into the local cache. Then, the data to be written and the first version number are associated with the "key" value of the data to be written in the local cache to determine the corresponding cache location. Finally, the data to be written and the current first version number are stored in the corresponding cache location to replace the historical data, completing the update of the data to be written and the data version number in the local cache.

[0075] Based on the method provided in this example, after the data to be written is persisted in the database, the local cache is updated according to the first version number and the first data name of the data to be written. This reduces the state deviation caused by duplicate writing of data with the same name and ensures that the write relationship between the database and the local cache of the main control node remains consistent.

[0076] S205. After successfully writing the data to be written to the local cache of the master control node, determine that the write operation of the data to be written is completed and release the target write lock.

[0077] For example, when the master control node confirms that the local cache has completed the corresponding data update and that the data content in the cache is consistent with the database write result, it indicates that the write operation on the data to be written is complete. At this time, a release command for the target write lock is issued to the lock management unit, and the corresponding target write lock can switch from the occupied state to the idle state. At this point, the data to be written has completed its processing in both the database and the local cache, and mutual exclusion protection is no longer required. This example of ensuring data consistency through write locks can reduce additional overhead, thus reducing the operational costs of the distributed system while ensuring data consistency between the cache and the database.

[0078] Optional, Figure 5 A flowchart illustrating the data processing method for a distributed system provided in this application embodiment. Figure 4 ,like Figure 5 As shown, it also includes:

[0079] S501. If a write failure is detected during the execution of the first write operation, the first write operation will be re-executed.

[0080] For example, during the first write operation, that is, in the database write phase, if an exception causes the database write to fail, a database write retry can be performed, which means re-executing the first write operation. The master control node can determine the database write failure based on failure indicators such as commit failure response, timeout response, or connection exception signal returned by the database.

[0081] S502. If the number of times the first write operation is repeated reaches the first preset threshold and the data to be written is still not successfully written to the database, then the first write operation is stopped, the target write lock is released, and an error message of write failure is generated and reported.

[0082] For example, the first preset threshold can be determined according to the actual situation, such as 3 times. Each time the master control node receives a failure flag from the database, it increments the retry count and repeats the first write operation if the retry count has not reached 3. If the data to be written has not been successfully written to the database after repeating the first write operation 3 times, the first write operation and subsequent caching operations on the data to be written are stopped, and the previously held target write lock is released, allowing other write requests to reacquire the corresponding lock resource. Subsequently, the master control node generates an error message for the write failure, which includes at least the first data name of the data to be written, the target write lock number, the reason for failure, the number of retries, and the failure timestamp, and reports it through the log module, message channel, or status feedback interface. Based on the method provided in this example, repeated commits are allowed when the database write fails briefly, and the write operation is terminated and the lock resource is released in a timely manner when there is a continuous failure, while the error message is reported to quickly locate the write anomaly and implement timely maintenance.

[0083] Optional, Figure 6 A flowchart illustrating the data processing method for a distributed system provided in this application embodiment. Figure 5 ,like Figure 6 As shown, it also includes:

[0084] S601. If a write failure is detected during the execution of the second or third write operation, the second or third write operation shall be re-executed.

[0085] For example, during the process of performing the second or third write operation, that is, in the cache write or update phase, if an exception occurs causing the cache write or update to fail, the cache write or update can be retried, that is, the second or third write operation can be re-executed. The master control node can determine the failure of the second or third write operation based on the failure indicators returned by the cache, such as commit failure response, timeout response, or connection exception signal.

[0086] S602. If the number of times the second write operation is repeated reaches the second preset threshold and the data to be written, the first version number, and the first data name are still not written to the local cache, then the second write operation is stopped; or, if the number of times the third write operation is repeated reaches the second preset threshold and the data to be written and the first version number are still not updated to the local cache, then the third write operation is stopped and the cached data corresponding to the first data name in the local cache is deleted.

[0087] For example, the second preset threshold can be the same as or different from the first preset threshold. This example uses a second preset threshold of 3 attempts for illustration. Each time the master control node receives a failure flag returned by the cache, it increments the retry count by one and repeats the second or third write operation if the retry count has not reached 3. If, after repeating the second write operation 3 times, the data to be written, the current first version number, and the first data name are still not successfully written to the cache, the second write operation is stopped. Similarly, if, after repeating the third write operation 3 times, the data to be written and the current first version number are still not successfully updated to the cache, the third write operation is stopped. After stopping the second or third write operation, all cached data related to the first data name is simultaneously deleted from the cache to prevent subsequent read requests from reading old data related to the first data name.

[0088] Optionally, if the operation to delete cached data fails, the local cache of the master control node is closed, an alarm signal is generated and reported, and the target write lock is released after the operation to delete cached data is successful or the alarm signal is generated and reported.

[0089] For example, if cache deletion also fails, the main control node will disable the local caching mechanism. Simultaneously, an alarm signal is generated, which must include at least the first data name of the data to be written, the target write lock number, the reason for failure, the number of retries, and the failure timestamp. This alarm signal is then reported via the log module, message channel, or status feedback interface. Additionally, the alarm signal can be sent to the operations and maintenance personnel's client for manual intervention to handle the anomaly.

[0090] If the cache data deletion operation is successful, there is no need to generate an alarm signal for reporting. After completing the above series of operations, the previously held target write lock is released, allowing other write requests to reacquire the corresponding lock resource. During the local cache shutdown period, all read operations can directly retrieve data from the database. This example can be repeated if the cache operation fails; if failures continue, it switches to cache deletion and alarm handling, and releases the target write lock after successful cache deletion or alarm reporting, allowing the lock resource to be reclaimed in a timely manner. This limits cache exceptions to the local scope corresponding to the current data name, and triggers the shutdown and reporting mechanism when write failures persist, thereby maintaining the continuity of write control and the traceability of exception handling.

[0091] Figure 7 Here is an example of the overall flowchart for processing a data write request, such as... Figure 7 As shown, upon receiving a data write request, the system first acquires the target write lock corresponding to the data to be written. It then performs a first write operation to write the data to the database. If the database write operation fails, it retryes. If the number of retries reaches a first preset threshold, the target write lock is released, and a write failure error message is generated and reported. If the database write operation succeeds, the current first version number is returned. Simultaneously, a second write operation is performed to write the data to be written, the first version number, and the first data name of the data to be written to the cache, or a third write operation is performed to update the data to be written and the first version number to the cache. If the cache write or update operation fails, it retryes. If the number of retries reaches a second preset threshold, all cached data related to the first data name is deleted. If cache deletion fails, an alarm signal is generated and reported. If the cache write or update operation succeeds, cache deletion succeeds, or an alarm signal is reported, the target write lock is released, and a message indicating successful release of the target write lock is returned.

[0092] Optional, Figure 8 A flowchart illustrating the data processing method for a distributed system provided in this application embodiment. Figure 6 ,like Figure 8 As shown, it also includes:

[0093] S801, in response to a data read request, determine the second data name carried in the data read request.

[0094] For example, a read data request represents the need to read data from a database or cache. The data to be read corresponding to the read data request can be defined as the target data, and the second data name is the "key" value corresponding to the target data.

[0095] S802, Check the status of the local cache.

[0096] For example, checking the status of the local cache can determine whether the local cache is currently enabled.

[0097] S803. If local caching is enabled, check if a second data name exists in the local cache.

[0098] For example, if the local cache is enabled, it means that the local cache can be accessed, and the corresponding target data will be read from the local cache first. Therefore, the first step is to check whether the target data exists in the local cache using the second data name.

[0099] S804. If a second data name exists in the local cache, the target data corresponding to the second data name is read from the local cache based on the read interface.

[0100] For example, the existence of a second data name in the local cache indicates the presence of the target data, which is the data corresponding to the second data name. The target data corresponding to the second data name can be directly read from the local cache via the read interface.

[0101] S805. If the second data name does not exist in the local cache, the target data corresponding to the second data name is read from the database based on the read interface.

[0102] For example, if local caching is enabled, but the second data name does not exist in the local cache, it means that the target data does not exist in the local cache. In this case, it is necessary to access the database and read the target data from the database.

[0103] S806. If the local cache is not enabled, the target data corresponding to the second data name is read from the database based on the read interface.

[0104] For example, if local caching is not enabled, it means that local cache is currently inaccessible. Therefore, it is necessary to access the database and read the target data from the database. Similarly, when reading the target data from the database, the target data corresponding to the second data name can be read from the database through the read interface.

[0105] In addition, if there are concurrent reads of the target data corresponding to the second data name, only one thread is allowed to perform the read operation on the target data, and other processes can wait for the target data to be read.

[0106] Based on the method provided in this example, the local cache can be accessed first to read the target data when the local cache is enabled, and the database can be accessed when the local cache is disabled or the local cache does not hit the target data, thereby reducing the frequency of database access and improving the performance of the distributed system.

[0107] Optional, Figure 9A flowchart illustrating the data processing method for a distributed system provided in this application embodiment. Figure 7 ,like Figure 9 As shown, after reading the target data corresponding to the second data name from the database, the process also includes:

[0108] S901, Re-check if the second data name exists in the local cache.

[0109] For example, when executing a data read request, there may be a write operation to the target data cache at the same time. Therefore, after reading the target data from the database, it is possible to check again whether the second data name exists in the local cache, that is, to check whether the target data corresponding to the second data name exists in the local cache.

[0110] S902. If the second data name does not exist in the local cache, then if the local cache is enabled, the target data read from the database, the second data name, and the current second version number of the target data will be written to the local cache.

[0111] For example, if the target data corresponding to the second data name does not yet exist in the local cache, the operation of writing the target data to the local cache is executed. Specifically, the current second version number of the target data is obtained from the database, and the target data, the second data name, and the second version number are written to the local cache through the write interface.

[0112] S903. If a second data name exists in the local cache, then determine the third version number corresponding to the second data name in the local cache.

[0113] For example, if the second data name already exists in the local cache, it means that the data corresponding to the second data name already exists in the local cache. In this case, the third version number of the data about the second data name written to the local cache can be determined.

[0114] S904. When the second version number is greater than the third version number, associate the target data and the second version number with the second data name, and update the target data and the second version number to the local cache based on the write interface.

[0115] For example, comparing the third version number and the second version number, if the second version number is greater than the third version number, it means that the target data for the second data name stored in the database has been updated, while the data for the second data name stored in the local cache is historical data from a previous version of the target data. Therefore, the target data and the second version number are associated with the second data name, and the target data and the second version number are updated to the storage location of the second data name in the local cache via the write interface. Alternatively, if the second version number is equal to the third version number, it means that the data for the second data name stored in the local cache is equivalent to the target data, and therefore no update to the local cache is needed.

[0116] Based on the method provided in this example, after reading the target data from the database, the target data is written to the local cache through a secondary cache verification and version comparison mechanism to ensure the consistency between the database and the local cache data.

[0117] Optional, Figure 10 A flowchart illustrating the data processing method for a distributed system provided in this application embodiment. Figure 8 ,like Figure 10 As shown, it also includes:

[0118] S1001. In response to the switch of the master control node, determine the new master control node.

[0119] For example, when a master control node switch is required, a new master control node needs to be determined from among the backup control nodes. The new master control node is the backup control node that gains control.

[0120] S1002. Obtain the data name list, which includes the data names of each data stored in the database.

[0121] For example, the list of data names includes the names of all the data stored in the database, which are the "key" values ​​of all the data.

[0122] S1003. Traverse the list of data names. Based on the reading interface, read the corresponding data and the latest version number of the data from the database in the order of the data names.

[0123] For example, according to the data names recorded in the data name list, the data corresponding to each data name stored in the database, as well as the latest version number of each data, are read in sequence.

[0124] S1004. Identify each data name, the corresponding data, and the latest version number of each data name as the data to be recovered.

[0125] For example, since the new master control node's local cache does not contain the data from the database, it is necessary to restore each data name in the data name list, along with the corresponding data and the latest version number, to the new master control node's local cache. Therefore, each data name in the data name list, along with the corresponding data and the latest version number, can be identified as the data to be restored.

[0126] S1005. Based on the write interface, the data to be recovered is written to the local cache of the new master control node in batches according to the preset rate.

[0127] For example, the data to be recovered is written to the local cache of the new master control node in batches according to a preset rate via the write interface. The preset rate and batch granularity can be configured according to the cache capacity and recovery bandwidth to control the amount of data written in a single operation and keep the recovery process continuous and stable.

[0128] Based on the method provided in this example, after the master control node is switched, the database can be read sequentially according to the data name list, and the read data and the latest version number can be restored to the local cache of the new master control node in batches. This allows the new master control node to quickly rebuild the cache state and maintain consistency with the data in the database, thereby shortening the business recovery time.

[0129] Optional, Figure 11 A flowchart illustrating the data processing method for a distributed system provided in this application embodiment. Figure 9 ,like Figure 11 As shown, S1005 includes:

[0130] S1101. Determine the data ratio for each batch and the interval between any adjacent batches.

[0131] For example, the data ratio is used to limit the proportion of each batch in the total data to be recovered, and the interval duration is used to limit the time interval between adjacent batches. The data ratio and interval duration can be determined according to the actual situation.

[0132] S1102. Based on the data proportions corresponding to each batch, determine the portion of data to be recovered for each batch.

[0133] For example, the data ratio can be 30%:30%:40%, and the interval can be 1 hour. Therefore, the first batch of data accounts for 30% of the data to be recovered, the second batch of data also accounts for 30% of the data to be recovered, and the third batch of data also accounts for 40% of the data to be recovered.

[0134] Optionally, determine the access frequency of the data corresponding to each data name; after arranging the access frequency of each data in ascending order, determine the portion of data to be recovered for each batch according to the data proportion corresponding to each batch.

[0135] For example, access frequency can characterize the popularity of data. Arranging the access frequencies of each data point in ascending order determines the popularity distribution of each data point. The top 30% of the most accessed data is considered the first batch, the middle 30% as the second batch, and the bottom 40% as the third batch. Therefore, based on this example method, priority can be given to restoring highly popular data to ensure normal access to it, thereby improving business execution efficiency.

[0136] S1103. Based on the write interface and according to the time interval between any adjacent batches, write the corresponding part of the data to be recovered for each batch into the local cache of the new master control node in sequence at a preset rate.

[0137] For example, the first batch of data is restored to the local cache of the new master control node via the write interface. After restoring the first batch of data to the local cache of the new master control node, a 1-hour interval is observed before restoring the second batch of data to the local cache of the new master control node via the write interface. After restoring the second batch of data to the local cache of the new master control node, another 1-hour interval is observed before finally restoring the third batch of data to the local cache of the new master control node via the write interface.

[0138] Based on the method provided in this example, by splitting the data to be recovered into multiple proportionally controlled batches and setting the interval between adjacent batches, the new master control node can complete local cache recovery at a controlled rate, which can reduce instantaneous write pressure and keep the cache recovery process continuous and controllable.

[0139] Figure 12 This is a schematic diagram of the structure of a data processing device for a distributed system provided in an embodiment of this application. The distributed system includes a master control node and multiple write locks, such as... Figure 12 As shown, the device includes:

[0140] The determination module 121 is used to determine the data to be written in response to a data write request;

[0141] The determining module 121 is also used to determine the target write lock corresponding to the data to be written from multiple write locks;

[0142] Processing module 122 is used to lock the write operation of the data to be written based on the target write lock;

[0143] The processing module 122 is also used to perform write operations on the data to be written, and to write the data to be written sequentially to the preset database and the local cache of the main control node;

[0144] The processing module 122 is also used to determine that the write operation of the data to be written is completed and release the target write lock after the data to be written is successfully written to the local cache of the master control node.

[0145] The description of the features of the distributed system data processing device corresponding to the embodiment provided in this embodiment can be found in the relevant description of the distributed system data processing method corresponding to the embodiment, and will not be repeated here.

[0146] Figure 13 A schematic diagram of the structure of the electronic device provided in this application. Figure 13 As shown, the electronic device 50 provided in this embodiment includes at least one processor 501 and a memory 502. Optionally, the electronic device 50 further includes a communication component 503. The processor 501, memory 502, and communication component 503 are connected via a bus.

[0147] In a specific implementation, at least one processor 501 executes computer execution instructions stored in memory 502, causing at least one processor 501 to execute the above-described data processing method embodiment of the distributed system.

[0148] The specific implementation process of processor 501 can be found in the above method embodiments, and its implementation principle and technical effect are similar. It will not be repeated here.

[0149] In the above embodiments, it should be understood that the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in the application can be directly manifested as being executed by a hardware processor, or executed by a combination of hardware and software modules within the processor.

[0150] The memory may include random access memory (RAM) and may also include non-volatile memory (NVM), such as at least one disk storage device.

[0151] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.

[0152] Embodiments of this application also provide a computer-readable storage medium storing a computer program, wherein the computer program is configured to execute the steps in any of the above-described embodiments of the data processing method for a distributed system.

[0153] In one exemplary embodiment, the aforementioned computer-readable storage medium may include, but is not limited to, various media capable of storing computer programs, such as a USB flash drive, read-only memory (ROM), random access memory (RAM), portable hard disk, magnetic disk, or optical disk.

[0154] Embodiments of this application also provide a computer program product, which includes a computer program that, when executed by a processor, implements the steps in any of the above-described embodiments of the data processing method for a distributed system.

[0155] Embodiments of this application also provide another computer program product, including a non-volatile computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps in any of the above-described distributed system data processing method embodiments.

[0156] It should be noted that the division of units is merely a logical functional division. In actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or units, and may be electrical, mechanical, or other forms.

[0157] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0158] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0159] If a function is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0160] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments; and the aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.

[0161] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that this application is not limited to the described order of actions, as some steps may be performed in other orders or simultaneously according to this application. Furthermore, those skilled in the art should also understand that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily essential to this application.

[0162] It should be understood that the above-described device embodiments are merely illustrative, and the device of this application can also be implemented in other ways. For example, the division of units / modules in the above embodiments is only a logical functional division, and there may be other division methods in actual implementation.

[0163] The foregoing has provided a detailed description of a data processing method, apparatus, electronic device, medium, and product for a distributed system provided in this application. Specific examples have been used to illustrate the principles and implementation methods of this application. The descriptions of the embodiments above are merely for the purpose of helping to understand the method and its core ideas. It should be noted that those skilled in the art can make various improvements and modifications to this application without departing from its principles, and these improvements and modifications also fall within the protection scope of the claims of this application.

Claims

1. A data processing method for a distributed system, characterized in that, The distributed system includes a master control node and multiple write locks, and the method includes: In response to a data write request, determine the data to be written; Determine the target write lock corresponding to the data to be written from the plurality of write locks; The write operation of the data to be written is locked based on the target write lock; Perform a write operation on the data to be written, and write the data to be written sequentially to a preset database and the local cache of the main control node; After successfully writing the data to be written to the local cache of the master control node, it is determined that the write operation on the data to be written is completed, and the target write lock is released.

2. The method according to claim 1, characterized in that, Determining the target write lock corresponding to the data to be written includes: Determine the number of write locks and the number of each write lock in the distributed system; The target value corresponding to the data to be written is obtained by performing calculations on the data to be written using a preset algorithm. Based on the target value, a modulo operation is performed on the number of write locks to obtain the corresponding modulo result; The modulus result is matched with the number of each write lock to obtain the target write lock.

3. The method according to claim 1, characterized in that, Also includes: If the target write lock is detected to be in an occupied state, wait for the target write lock to be updated to an idle state before calling the target write lock to lock the write operation of the data to be written.

4. The method according to claim 1, characterized in that, The step of sequentially writing the data to be written to a preset database and the local cache of the main control node includes: A preset write interface is invoked to perform a first write operation that writes the data to be written to the database based on the write interface; After successfully writing the data to be written to the database, obtain the first version number corresponding to this write of the data to be written; Determine the first data name of the data to be written; In the local cache, check if the first data name exists; If the first data name does not exist in the local cache, then a second write operation is performed based on the write interface to write the data to be written, the first version number, and the first data name to the local cache; If the first data name exists in the local cache, the data to be written, the first version number, and the first data name are associated, and a third write operation is performed based on the write interface to write the data to be written and the first version number to the local cache, so as to update the cache data and version number corresponding to the first data name in the local cache.

5. The method according to claim 4, characterized in that, Also includes: If a write failure is detected during the execution of the first write operation, the first write operation is re-executed; If the number of times the first write operation is repeated reaches a first preset threshold and the data to be written is still not successfully written to the database, then the first write operation is stopped, the target write lock is released, and an error message indicating a write failure is generated and reported.

6. The method according to claim 4, characterized in that, Also includes: If a write failure is detected during the execution of the second or third write operation, the second or third write operation will be re-executed. If the number of times the second write operation is repeated reaches the second preset threshold and the data to be written, the first version number, and the first data name are still not written to the local cache, then the second write operation is stopped. Alternatively, if the number of times the third write operation is repeated reaches a second preset threshold and the data to be written and the first version number are still not updated to the local cache, then the third write operation is stopped and the cached data corresponding to the first data name in the local cache is deleted.

7. The method according to claim 6, characterized in that, Also includes: If the operation to delete the cached data fails, the local cache of the main control node is closed, an alarm signal is generated and reported, and the target write lock is released after the operation to delete the cached data is successful or the alarm signal is generated and reported.

8. The method according to claim 1, characterized in that, Also includes: In response to a data read request, determine the second data name carried in the data read request; Detect the status of the local cache; If the local cache is enabled, then check whether the second data name exists in the local cache; If the second data name exists in the local cache, the target data corresponding to the second data name is read from the local cache based on the read interface; If the second data name does not exist in the local cache, the target data corresponding to the second data name is read from the database based on the read interface; If the local cache is not enabled, the target data corresponding to the second data name is read from the database based on the read interface.

9. The method according to claim 8, characterized in that, After reading the target data corresponding to the second data name from the database, the method further includes: Re-check whether the second data name exists in the local cache; If the second data name does not exist in the local cache, then if the local cache is enabled, the target data read from the database, the second data name, and the current second version number of the target data will be written to the local cache. If the second data name exists in the local cache, then determine the third version number corresponding to the second data name in the local cache; When the second version number is greater than the third version number, the target data and the second version number are associated with the second data name, and the target data and the second version number are updated to the local cache based on the write interface.

10. The method according to claim 1, characterized in that, Also includes: In response to the switch of the master control node, a new master control node is determined; Obtain a list of data names, wherein the list of data names includes the data names of each piece of data stored in the database; Traverse the list of data names, and based on the reading interface, read the corresponding data and the latest version number of the data from the database in sequence according to the order of the data names; Each of the data names, the data corresponding to each data name, and the latest version number of the data are determined as the data to be recovered; Based on the write interface, the data to be recovered is written to the local cache of the new master control node in batches according to a preset rate.

11. The method according to claim 10, characterized in that, The step of writing the data to be recovered to the local cache of the new master control node in batches according to a preset rate based on the write interface includes: Determine the data proportions for each batch and the time interval between any adjacent batches; Based on the data proportions corresponding to each batch, determine the portion of data to be recovered for each batch; Based on the write interface and according to the time interval between any two adjacent batches, the corresponding portion of the data to be recovered for each batch is sequentially written into the local cache of the new master control node at a preset rate.

12. A data processing device for a distributed system, characterized in that, The distributed system includes a master control node and multiple write locks, and the device includes: The determination module is used to determine the data to be written in response to a data write request; The determining module is also used to determine the target write lock corresponding to the data to be written from the plurality of write locks; The processing module is used to lock the write operation of the data to be written based on the target write lock; The processing module is also used to perform a write operation on the data to be written, and to write the data to be written sequentially to a preset database and the local cache of the main control node; The processing module is also used to determine that the write operation on the data to be written is complete and release the target write lock after the data to be written is successfully written to the local cache of the master control node.

13. An electronic device, characterized in that, include: Memory, used to store computer programs; A processor, configured to implement the steps of the data processing method for a distributed system as described in any one of claims 1 to 11 when executing the computer program.

14. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program, wherein when the computer program is executed by a processor, it implements the steps of the data processing method for a distributed system as described in any one of claims 1 to 11.

15. A computer program product, characterized in that, It includes a computer program that, when executed by a processor, implements the steps of the data processing method for a distributed system as described in any one of claims 1 to 11.