Data processing method, electronic device, storage medium, and program product
By introducing a barrier lock mechanism, the problem that basic distributed locks cannot meet high concurrency performance is solved, and data consistency is achieved between concurrent access of read locks and blocking of write locks, thus meeting the high concurrency requirements of distributed systems.
Patent Information
- Application Number
- CN202611339855.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-31
- Publication Date
- 2026-11-27
AI Technical Summary
Existing basic distributed locks are unable to meet the growing demand for high concurrency performance and cannot achieve efficient mutual exclusion and synchronization among multiple machines, resulting in frequent blocking of read and write requests, which affects data consistency and business performance.
A barrier lock mechanism is introduced, which arranges lock acquisition requests in chronological order by setting a lock request queue. This allows concurrent access to read locks but blocks write locks, ensuring data consistency, preventing write locks from modifying data, and achieving high concurrency performance.
The barrier lock mechanism allows subsequent read locks to access data concurrently without blocking, prohibits write locks from modifying data, ensures data consistency, meets high concurrency performance requirements, and avoids process blocking and data corruption.
Smart Images

Figure CN123178109A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of distributed locks, and more specifically to a data processing method, electronic device, storage medium, and program product. Background Technology
[0002] In distributed systems, mutual exclusion and synchronization between multiple machines are often required, necessitating the introduction of distributed locks, such as those used to control access to critical sections. However, the distributed locks provided by relevant methods are mostly basic distributed locks, which have limited functionality, offering only an exclusive mutual exclusion mode. Therefore, they are insufficient to meet the growing demands for high concurrency performance in applications. Summary of the Invention
[0003] In view of the above problems, this application provides a data processing method, an electronic device, a storage medium, and a program product.
[0004] According to a first aspect of this application, a data processing method is provided, comprising: responding to a target barrier lock acquisition request initiated by a target business process, determining the order of the target barrier lock acquisition requests in a lock request queue, wherein the barrier lock is used to access target data, and the lock request queue includes: lock acquisition requests for the target data arranged in order of request time from earliest to latest; allowing the target business process to acquire the barrier lock if the target lock acquisition request preceding the target barrier lock acquisition request is in a predetermined state; during the access period when the target business process uses the target barrier lock to access the target data, allowing read lock acquisition requests following the target barrier lock acquisition request to allow reading the target data through read locks during the access period; and prohibiting write lock acquisition requests following the target barrier lock acquisition request during the access period to prohibit modification of the target data through write locks during the access period.
[0005] According to embodiments of this application, by setting a barrier lock, read lock acquisition requests following the target barrier lock acquisition request are allowed during the access period when the target business process uses the target barrier lock to access the target data. This allows the target data to be read through read locks during the access period, so that the barrier lock does not block all subsequent read locks, but blocks subsequent write locks. Thus, during the access period when the barrier lock is used to access data, read locks following the barrier lock can also work normally, avoiding a large number of processes being blocked. By prohibiting write lock acquisition requests following the target barrier lock acquisition request during the access period, the target data cannot be modified through write locks during the access period, ensuring that the data is not modified during the access period, thereby ensuring data consistency. This can meet the growing demand for high concurrency performance from the business.
[0006] According to embodiments of this application, a target lock acquisition request preceding a target barrier lock acquisition request being in a predetermined state includes at least one of the following: there is no target lock acquisition request preceding a target barrier lock acquisition request in the lock request queue; or all lock records corresponding to the target lock acquisition requests have been deleted.
[0007] According to an embodiment of this application, each lock acquisition request has a corresponding version number, and the version number corresponds to the initiation time of the lock acquisition request; the data processing method further includes: determining the target version number corresponding to the target barrier lock acquisition request; if the target version number is the minimum version number corresponding to the lock request queue, determining that there is no target lock acquisition request in the lock request queue.
[0008] According to an embodiment of this application, the data processing method further includes: when the target version number is not the minimum version number, listening for a deletion event of the request record of the target lock acquisition request; in response to listening for the deletion event, determining that the target lock acquisition request has been released; wherein the deletion event includes: deleting the request record in response to the business process that initiated the target lock acquisition request completing access to the target data; and / or, deleting the request record in response to the expiration of the validity period of the target lock acquisition request.
[0009] According to an embodiment of this application, the version number increases sequentially from earliest to latest according to the initiation time. The data processing method further includes: arranging the lock acquisition requests sequentially from front to back according to the version number in ascending order to obtain a lock request queue.
[0010] According to embodiments of this application, a target lock acquisition request includes at least one of the following: a read lock acquisition request, a write lock acquisition request, and a barrier lock acquisition request.
[0011] According to an embodiment of this application, the data processing method further includes: in response to the deletion of the request record corresponding to the target lock acquisition request, releasing the barrier lock, and allowing write lock acquisition requests that are scheduled after the target barrier lock acquisition request.
[0012] A second aspect of this application provides an electronic device, comprising: one or more processors; and a memory for storing one or more computer programs, wherein the one or more processors execute the one or more computer programs to implement the steps of the method described above.
[0013] A third aspect of this application also provides a computer-readable storage medium having a computer program or instructions stored thereon, which, when executed by a processor, implement the steps of the above-described method.
[0014] A fourth aspect of this application also provides a computer program product, including a computer program or instructions that, when executed by a processor, implement the steps of the above-described method. Attached Figure Description
[0015] The above-mentioned contents, other objects, features and advantages of this application will become clearer from the following description of embodiments with reference to the accompanying drawings, in which:
[0016] Figure 1 This illustration schematically depicts application scenarios of a data processing method, electronic device, storage medium, and program product according to embodiments of this application.
[0017] Figure 2 A flowchart illustrating a data processing method according to an embodiment of this application is shown schematically.
[0018] Figure 3 A flowchart illustrating the read lock operation logic according to an embodiment of this application is shown schematically.
[0019] Figure 4 A flowchart illustrating the write lock operation logic according to an embodiment of this application is shown schematically.
[0020] Figure 5 A schematic diagram illustrating a data processing method according to an embodiment of this application is shown.
[0021] Figure 6 A block diagram schematically illustrates an electronic device suitable for implementing a data processing method according to an embodiment of this application. Detailed Implementation
[0022] The embodiments of this application will now be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of this application. In the following detailed description, numerous specific details are set forth to provide a thorough understanding of the embodiments of this application for ease of explanation. However, it will be apparent that one or more embodiments may be implemented without these specific details. Furthermore, descriptions of well-known structures and technologies are omitted in the following description to avoid unnecessarily obscuring the concepts of this application.
[0023] The terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the scope of this application. The terms “comprising,” “including,” etc., as used herein indicate the presence of features, steps, operations, and / or components, but do not exclude the presence or addition of one or more other features, steps, operations, or components.
[0024] All terms used herein (including technical and scientific terms) have the meanings commonly understood by those skilled in the art, unless otherwise defined. It should be noted that the terms used herein are to be interpreted in a manner consistent with the context of this specification, and not in an idealized or overly rigid way.
[0025] When using expressions such as "at least one of A, B and C", they should generally be interpreted in accordance with the meaning that is commonly understood by those skilled in the art (e.g., "a system having at least one of A, B and C" should include, but is not limited to, a system having A alone, a system having B alone, a system having C alone, a system having A and B, a system having A and C, a system having B and C, and / or a system having A, B and C, etc.).
[0026] In distributed applications, distributed locks are often introduced to achieve mutual exclusion and synchronization among multiple machines. For example, distributed key-value databases based on the RAFT consensus algorithm, such as the ETCD database, do not have distributed lock functionality. However, the official Concurrency package includes a mutex lock implementation based on ETCD.
[0027] The Concurrency package utilizes lease mechanisms, prefix mechanisms, listening mechanisms, and version mechanisms to implement a fair basic distributed mutex lock. The order in which the lock is acquired strictly follows the order in which the lock is requested.
[0028] For example, besides ETCD, there are many other distributed locks implemented using other middleware, such as exclusive locks based on relational databases, distributed locks based on Redis, and distributed locks based on ZooKeeper. However, the Concurrency package typically only provides the simplest mutex lock implementation, such as only providing the exclusive mutual exclusion mode. This means that multiple business nodes cannot operate on the same critical resource simultaneously, they are mutually exclusive, cannot operate in parallel, and at any given time, only one node can possess the same resource, while all other nodes wait. Therefore, it is difficult to meet the ever-increasing demands of businesses for high concurrency performance.
[0029] In view of this, embodiments of this application provide a data processing method. Figure 1 The illustration shows an application scenario diagram of a data processing method, electronic device, storage medium, and program product according to embodiments of this application.
[0030] like Figure 1 As shown, a distributed cluster can include multiple independent business servers, such as server A, server B, and server C. The database can include a distributed shared database. Servers A, B, and C can share the same set of data resources in the database. For example, servers A, B, and C can access the database simultaneously, with servers A and C performing read operations and server B performing write operations.
[0031] For example, if the above data operations are controlled based on a basic distributed mutex lock, all read and write requests from other servers will be blocked while any server holds the lock, and even multiple groups of read requests without data conflicts cannot be executed in parallel. In distributed business scenarios, especially for time-consuming tasks, the abuse of mutex locks and write locks should be avoided to improve concurrency, because both mutex locks and write locks will block other services from accessing critical resources. By designing a barrier lock, all subsequent read locks can be blocked, but subsequent write locks can be blocked. This allows subsequent read locks to work normally while accessing data using the barrier lock, avoiding blocking a large number of processes; disabling write locks also ensures that data is not modified during data access, thereby ensuring data consistency.
[0032] For example, in response to a target barrier lock acquisition request initiated by a target business process, the order of the target barrier lock acquisition requests in the lock request queue can be determined. The barrier lock is used to access target data, and the lock request queue includes: lock acquisition requests for the target data arranged in ascending order of request time; if a target lock acquisition request preceding the target barrier lock acquisition request is in a predetermined state, the target business process is allowed to acquire the barrier lock; during the access period where the target business process uses the target barrier lock to access the target data, read lock acquisition requests following the target barrier lock acquisition request are allowed to read the target data during the access period; and during the access period, write lock acquisition requests following the target barrier lock acquisition request are prohibited to modify the target data using write locks during the access period.
[0033] Figure 2 A flowchart illustrating a data processing method according to an embodiment of this application is shown.
[0034] like Figure 2 As shown, the data processing method of this embodiment includes the following operations.
[0035] In operation S210, in response to the target barrier lock acquisition request initiated by the target business process, the order of the target barrier lock acquisition requests in the lock request queue is determined.
[0036] The barrier lock is used to access the target data, and the lock request queue includes lock acquisition requests for the target data arranged in order of request time from earliest to latest.
[0037] For example, a barrier lock can be a separate third type of lock, distinct from read locks and write locks. For instance, with a read lock, multiple services can acquire it simultaneously, and the read lock only blocks write locks, not other read locks; with a write lock, it is an exclusive lock, and once held, all subsequent read and write locks are blocked; however, with a barrier lock, while it is held, subsequent read lock requests are not restricted, allowing concurrent read operations, and subsequent write lock requests are restricted, preventing write locks from modifying data; furthermore, the barrier lock itself must adhere to the global lock request sequence, waiting for all previously acquired read locks, write locks, and barrier locks to be released before it can be acquired.
[0038] The working logic of a barrier lock can include: creating a lease and specifying the TTL; creating a lock key and binding it to the lease, in the format / prefix / lock / barrier / KEYID, and recording the key's version number; the background performs timed lease renewals to prevent deadlocks caused by keys not being released during business anomalies; for each lock request generated, a version number corresponding to the request time can be assigned to the key corresponding to that lock request, and this version number is assigned sequentially according to the order in which lock requests are generated, used to represent the request sequence; all lock requests can be queried by specifying the prefix / prefix / lock. The system retrieves the lock key and checks if an earlier key exists. If no earlier key exists, the barrier lock is acquired. If an earlier key exists, the system listens for the deletion event of the previous key. Upon detecting the deletion event of the previous key, the system checks again for an earlier key and acquires the barrier lock if the conditions are met. After acquiring the barrier lock, the system identifies the type of subsequent lock requests based on the key's prefix, allowing subsequent read lock requests to acquire the lock and blocking subsequent write lock requests. After the business process ends, the corresponding key can be deleted.
[0039] For example, the target business process may include a program execution unit for processing business, such as business programs running on server A, server B, or server C. The target business process may act as the subject initiating lock requests, initiating barrier lock acquisition requests, read lock acquisition requests, write lock acquisition requests, etc., and performing database data read and write operations after acquiring the lock.
[0040] A target barrier lock acquisition request can be a request issued by the target business process to apply for a barrier lock. It may carry information such as the identifier of the target data to be accessed and the time the request was initiated. Target data may include, for example, product inventory data, order statistics, or other types of data; this is not limited here.
[0041] The lock request queue can include a time-series queue set up for the same set of data to be accessed (such as target data). It can include various lock acquisition requests initiated by at least one business process for the target data, such as read lock acquisition requests, write lock acquisition requests, barrier lock acquisition requests, etc. Lock acquisition requests can be arranged in order of request time from earliest to latest.
[0042] For example, if the target data includes product inventory data, and multiple servers successively submit read lock acquisition requests, barrier lock acquisition requests, and write lock acquisition requests, these requests can all be categorized into the lock request queue corresponding to the product inventory data. The system can then process the requests in the lock request queue sequentially according to the order in which they were submitted. For the target barrier lock acquisition request submitted by server D, its order in the lock request queue can be determined.
[0043] In operation S220, if the target lock acquisition request preceding the target barrier lock acquisition request is in a predetermined state, the target business process is allowed to acquire the barrier lock.
[0044] For example, the target lock acquisition request may include at least one lock acquisition request in the lock request queue whose request time is earlier than the target barrier lock acquisition request, and may include various types such as read lock acquisition request, barrier lock acquisition request, and write lock acquisition request.
[0045] Predefined states include, for example, the release of the lock resource corresponding to the target lock acquisition request. Under these conditions, the target business process can acquire the barrier lock and gain access to the target data.
[0046] In operation S230, during the access of target data by the target business process using the target barrier lock, read lock acquisition requests that are scheduled after the target barrier lock acquisition request are allowed to read the target data through the read lock during the access.
[0047] In operation S240, during access, write lock acquisition requests that follow the target barrier lock acquisition request are prohibited, so as to prevent modification of target data by write lock during access.
[0048] For example, the characteristics of a barrier lock may include non-blocking read locks and blocking write locks.
[0049] During access, read lock acquisition requests that only request to read data and are queued after the target barrier lock acquisition request in the lock acquisition queue do not need to block and wait for the barrier lock corresponding to the target barrier lock acquisition request to be released; they can directly acquire the read lock.
[0050] For example, while the business process of server D acquires the barrier lock and accesses the inventory data, the read requests of servers A and C, which are in the lock request queue after the target barrier lock acquisition request, do not need to wait for server D to finish writing and can directly query the inventory in parallel.
[0051] During the access, all write lock acquisition requests that modify data and are queued after the target barrier lock acquisition request in the lock acquisition queue are blocked, and the write lock cannot be acquired.
[0052] For example, while the business process of server D acquires the barrier lock and accesses or modifies inventory data, a write request from server B to modify the same data is blocked and must wait for server D to release the barrier lock before it can execute the write.
[0053] According to embodiments of this application, by setting a barrier lock, read lock acquisition requests following the target barrier lock acquisition request are allowed during the access period when the target business process uses the target barrier lock to access the target data. This allows the target data to be read through read locks during the access period, so that the barrier lock does not block all subsequent read locks, but blocks subsequent write locks. Thus, during the access period when the barrier lock is used to access data, read locks following the barrier lock can also work normally, avoiding a large number of processes being blocked. By prohibiting write lock acquisition requests following the target barrier lock acquisition request during the access period, the target data cannot be modified through write locks during the access period, ensuring that the data is not modified during the access period, thereby ensuring data consistency. This can meet the growing demand for high concurrency performance from the business.
[0054] According to an embodiment of this application, the data processing method further includes: in response to the deletion of the request record corresponding to the target barrier lock acquisition request, releasing the barrier lock, and allowing write lock acquisition requests that are scheduled after the target barrier lock acquisition request.
[0055] For example, since the barrier lock's characteristics include blocking write locks, all write lock acquisition requests that request to modify data and are placed after the target barrier lock acquisition request are blocked and cannot acquire write locks. To ensure that the business process can modify data smoothly, the blocking of the above write lock acquisition requests can be canceled after the request record corresponding to the target barrier lock acquisition request is deleted and the barrier lock resource is released, allowing write lock acquisition requests placed after the target barrier lock acquisition request.
[0056] According to the embodiments of this application, by prohibiting modification of target data through write locks during access, and releasing the barrier lock and allowing write lock acquisition requests that follow the target barrier lock acquisition request after the request record corresponding to the target barrier lock acquisition request is deleted, the situation of concurrent modification of data during access can be avoided. This can avoid problems such as data disorder, numerical calculation deviation, and data overwriting and loss caused by simultaneous writing by multiple nodes, thus ensuring the consistency of target data modification. By allowing write locks at the end of the queue to be processed only after the barrier lock is fully released, write requests can be strictly scheduled according to the order of application, preventing later-initiated write requests from preempting resources and avoiding the problems of business task starvation and long-term blocking of core write business. By releasing the barrier lock in a timely manner after the request record corresponding to the target lock acquisition request is deleted, it can be ensured that the business process can modify data smoothly.
[0057] According to embodiments of this application, a target lock acquisition request includes at least one of the following: a read lock acquisition request, a write lock acquisition request, and a barrier lock acquisition request.
[0058] For example, the barrier lock's characteristics also include that it can be blocked by any other lock applied for earlier than itself, and it will not be blocked by any other lock applied for later than itself. Other locks include read locks, write locks, and other shielding locks.
[0059] According to the embodiments of this application, the target lock acquisition request includes various types of requests such as read lock acquisition request, write lock acquisition request, and barrier lock acquisition request. The barrier lock can be constrained by all preceding locks and is not interfered with by subsequent locks, thereby ensuring that all lock operations are strictly executed in the order of initiation time. Whether it is a read lock, write lock, or barrier lock, the resource access permission requested first is processed first, which can avoid the situation where the lock initiated later preempts the resources, thereby avoiding long-term blocking and starvation of business tasks.
[0060] Figure 3 A flowchart illustrating the read lock operation logic according to an embodiment of this application is shown schematically.
[0061] like Figure 3As shown, the working logic of a read lock can include: creating a lease and specifying a Time To Live (TTL); creating a key and binding it to the lease. For example, when a business process requests a lock, the system can generate a dedicated storage entry key in the database. The key format can be / prefix / lock / read / KEYID, and the key version can also be recorded; renewing the lease periodically in the background; querying all write lock keys with the specified prefix / prefix / lock / write; determining whether the version of its own key is earlier than all of them; if it is already the earliest version, then acquiring the lock; if its own key version is not the earliest, listening for the deletion event of the previous key, and then acquiring the read lock; after the business process ends, deleting its own key.
[0062] Figure 4 A flowchart illustrating the write lock operation logic according to an embodiment of this application is shown schematically.
[0063] like Figure 4 As shown, the working logic of a write lock can include: creating a lease and specifying the TTL; creating a key and binding it to the lease. For example, when a business process requests a lock, the system can generate a dedicated storage entry key in the database. The key format can be / prefix / lock / write / KEYID, and the key version can also be recorded; renewing the lease periodically in the background; querying all lock keys by specifying the prefix / prefix / lock; determining whether the version of its own key is earlier than all of them; if it is already the earliest version, then acquiring the lock; if its own key version is not the earliest, listening for the deletion event of the previous key, and then acquiring the write lock; after the business process ends, deleting its own key.
[0064] contrast Figure 3 and Figure 4 As can be seen, read locks only query all write locks, and read locks are not mutually exclusive; write locks need to query the keys of all types of locks, and write locks will be mutually exclusive with any other lock.
[0065] For example, the prefixes for read locks and write locks can be different, such as / prefix / lock / read / KEYID for read locks and / prefix / lock / write / KEYID for write locks. / prefix / lock can be the prefix for any lock.
[0066] By setting different prefixes for read locks and write locks, when checking for the existence of an earlier write lock, the read lock only queries records under the write lock prefix, without having to traverse a massive number of read lock records, thereby narrowing the query range and reducing the traversal of invalid data.
[0067] According to embodiments of this application, a target lock acquisition request preceding a target barrier lock acquisition request being in a predetermined state includes at least one of the following: there is no target lock acquisition request preceding a target barrier lock acquisition request in the lock request queue; or all lock records corresponding to the target lock acquisition requests have been deleted.
[0068] For example, the lock request queue may not contain any target lock acquisition requests preceding the target barrier lock acquisition request. This could include situations where the target barrier lock acquisition request is at the top of the lock request queue, and the queue does not include lock requests submitted earlier or ranked higher. In this case, there are no preceding lock resources waiting to be released in the lock request queue, and the barrier lock acquisition conditions can be directly met, thus eliminating the need to wait for other locks to be released.
[0069] The deletion of lock records corresponding to target lock acquisition requests can include: the storage records of lock requests that are ranked before the target barrier lock request in the lock request queue have been deleted.
[0070] The deletion of a lock record can indicate that the business process corresponding to the lock record has successfully completed data access and actively released the lock, or that the lock's lease has expired, thus automatically clearing the lock record. When a lock record has been deleted, the preceding lock no longer occupies the target data resource.
[0071] For example, the lock request queue is arranged in the following order: server C requests a read lock, server B requests a barrier lock; server C completes data reading and deletes its own lock record, releases all preceding locks, and determines that the predetermined state has been reached, at which point server B can acquire the barrier lock.
[0072] According to the embodiments of this application, the target business process is only allowed to acquire the barrier lock if there is no target lock acquisition request preceding the target barrier lock acquisition request in the lock request queue, or if the request record of the target lock acquisition request has been deleted. This can ensure the timing fairness of the lock request queue, and the access request submitted earlier will complete the data operation first, avoiding queue jumping. This can prevent the barrier lock initiated later from bypassing the earlier lock and directly occupying the target data, causing the preceding lock request to be delayed indefinitely, leading to problems such as business starvation.
[0073] Figure 5 A schematic diagram of a data processing method according to an embodiment of this application is shown.
[0074] For example, consider five processes a, b, c, d, and e that sequentially request locks. Process a requests a write lock, process b requests a read lock, process c requests a barrier lock, process d requests a read lock, and process e requests a write lock. The lock acquisition order from earliest to latest is as follows: process a acquires the write lock, process a releases the write lock, processes b and d simultaneously acquire the read lock, process b releases the read lock, process c acquires the barrier lock, d releases the read lock, process c releases the barrier lock, process e acquires the write lock, and process e releases the write lock. Process c only considers whether processes a and b, which precede it, have released their locks; it does not consider process d, which follows it.
[0075] The working logic of a barrier lock can include: creating a lease and specifying the TTL; creating a key and binding it to the lease, in the format / prefix / lock / barrier / KEYID, and recording the version of its own key; renewing the lease periodically in the background; querying all lock keys with the specified prefix / prefix / lock, and determining whether its own key version is the earliest; if it is already the earliest version, acquiring the lock; if its own key version is not the earliest, listening for the deletion event of the previous key, and then acquiring the lock; deleting its own key after the business ends.
[0076] According to embodiments of this application, each lock acquisition request has a corresponding version number, and the version number corresponds to the initiation time of the lock acquisition request. The data processing method further includes: determining the target version number corresponding to the target barrier lock acquisition request; and if the target version number is the minimum version number corresponding to the lock request queue, determining that there is no target lock acquisition request in the lock request queue.
[0077] For example, each lock acquisition request in the lock request queue can be bound to its own version number. The size of the version number can be matched with the order in which the lock acquisition request was initiated. For example, the earlier the initiation time, the smaller the version number value, and the later the initiation time, the larger the assigned version number value. If the target version number is the smallest version number corresponding to the lock request queue, it means that the target barrier lock acquisition request was initiated earliest.
[0078] For example, the lock request queue includes: a read lock with version number 1, a barrier lock with version number 2, and a write lock with version number 3. Since the version number 2 of the barrier lock is not the minimum value, it means that there is a preceding read lock, that is, a read lock with version number 1. The form of the version number is only an example and is not limited. It can be limited according to actual needs.
[0079] According to an embodiment of this application, the data processing method further includes: when the target version number is not the minimum version number, listening for the deletion event of the request record of the target lock acquisition request; in response to listening for the deletion event, determining that the target lock acquisition request has been released; wherein the deletion event includes: deleting the request record in response to the business process that initiated the target lock acquisition request completing access to the target data; and / or, deleting the request record in response to the expiration of the validity period.
[0080] For example, if the target version number is not the minimum version number, it means that there are earlier lock acquisition requests in the lock request queue. In this case, the system can continuously monitor the storage records corresponding to all the earlier lock acquisition requests and capture the signal that the above storage records have been deleted. The deletion of the storage record means that the earlier lock no longer occupies the target data resources.
[0081] For example, when a business process completes the read / write operation of the target data and no longer needs to occupy lock resources, the business process can proactively send a command to the database to request the deletion of its corresponding lock request record, thereby generating a deletion event.
[0082] For example, each lock record is bound to a validity period (such as an ETCD lease). In the event of a business process crash or program freeze, the lock record cannot be actively deleted. However, when the bound validity period expires automatically, the database can automatically clear the lock request record, thereby automatically generating a deletion event.
[0083] According to the embodiments of this application, by setting each lock acquisition request to have a corresponding version number, and binding the version number to the lock request initiation time, the order of lock requests can be distinguished intuitively and accurately, simplifying the judgment process.
[0084] According to an embodiment of this application, the version number increases sequentially from earliest to latest according to the initiation time. The data processing method further includes: arranging the lock acquisition requests sequentially from front to back according to the version number in ascending order to obtain a lock request queue.
[0085] For example, the earlier a lock acquisition request is initiated, the earlier it is in the lock acquisition queue, and the smaller the version number it is bound to.
[0086] For example, a total of 3 lock acquisition requests are initiated for the target data, including: read lock (first committed, version number 1), barrier lock (middle committed, version number 2), and write lock (last committed, version number 3); therefore, the order of the lock acquisition queue for the target data is: read lock acquisition request, barrier lock acquisition request, and write lock acquisition request.
[0087] Based on the above data processing method, this application also provides a data processing apparatus. The data processing apparatus may include: a sequence determination module, configured to determine the order of target barrier lock acquisition requests in a lock request queue in response to a target business process's target barrier lock acquisition request, wherein the barrier lock is used to access target data, and the lock request queue includes lock acquisition requests for target data arranged in ascending order of request time; a barrier lock acquisition module, configured to allow the target business process to acquire the barrier lock when a target lock acquisition request preceding the target barrier lock acquisition request is in a predetermined state; a request permission module, configured to allow read lock acquisition requests following the target barrier lock acquisition request during the access period when the target business process uses the target barrier lock to access target data, so as to allow reading the target data via read lock during the access period; and a request prohibition module, configured to prohibit write lock acquisition requests following the target barrier lock acquisition request during the access period, so as to prohibit modification of the target data via write lock during the access period.
[0088] The data processing device further includes: a version number determination module, used to determine the target version number corresponding to the target barrier lock acquisition request; and a request determination module, used to determine that, if the target version number is the minimum version number corresponding to the lock request queue, there is no target lock acquisition request in the lock request queue that is preceding the target barrier lock acquisition request.
[0089] The data processing device further includes: a listening module, used to listen for deletion events of the request record of the target lock request when the version number is not the minimum version number; and a release module, used to determine that the target lock acquisition request has been released in response to the detected deletion event; wherein the deletion event includes: deleting the request record in response to the business process that initiated the target lock acquisition request completing access to the target data; and / or deleting the request record in response to the expiration of the validity period.
[0090] The data processing device also includes a sorting module, which arranges the lock acquisition requests sequentially from front to back according to the version number in ascending order, to obtain a lock request queue.
[0091] The data processing device further includes a release module, used to release the barrier lock in response to the deletion of the request record corresponding to the target lock acquisition request, and to allow write lock acquisition requests that are scheduled after the target barrier lock acquisition request.
[0092] Figure 6 A block diagram schematically illustrates an electronic device suitable for implementing a data processing method according to an embodiment of this application.
[0093] like Figure 6As shown, an electronic device 600 according to an embodiment of this application includes a processor 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage portion 608 into a random access memory (RAM) 603. The processor 601 may include, for example, a general-purpose microprocessor (e.g., a CPU), an instruction set processor and / or an associated chipset and / or a special-purpose microprocessor (e.g., an application-specific integrated circuit (ASIC)), etc. The processor 601 may also include onboard memory for caching purposes. The processor 601 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of this application.
[0094] RAM 603 stores various programs and data required for the operation of electronic device 600. Processor 601, ROM 602, and RAM 603 are interconnected via bus 604. Processor 601 executes various operations of the method flow according to embodiments of this application by executing programs in ROM 602 and / or RAM 603. It should be noted that programs may also be stored in one or more memories other than ROM 602 and RAM 603. Processor 601 may also execute various operations of the method flow according to embodiments of this application by executing programs stored in one or more memories.
[0095] According to embodiments of this application, the electronic device 600 may further include an input / output (I / O) interface 605, which is also connected to a bus 604. The electronic device 600 may also include one or more of the following components connected to the input / output (I / O) interface 605: an input section 606 including a keyboard, mouse, etc.; an output section 607 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN card, modem, etc. The communication section 609 performs communication processing via a network such as the Internet. A drive 610 is also connected to the input / output (I / O) interface 605 as needed. A removable medium 611, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., is installed on the drive 610 as needed so that computer programs read from it can be installed into the storage section 608 as needed.
[0096] This application also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiments; or it may exist independently and not assembled into the device / apparatus / system. The computer-readable storage medium carries one or more programs, which, when executed, implement the method according to the embodiments of this application.
[0097] According to embodiments of this application, the computer-readable storage medium can be a non-volatile computer-readable storage medium, such as including but not limited to: portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this application, the computer-readable storage medium can be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. For example, according to embodiments of this application, the computer-readable storage medium may include ROM 602 and / or RAM 603 and / or one or more memories other than ROM 602 and RAM 603 described above.
[0098] Embodiments of this application also include a computer program product comprising a computer program containing program code for performing the methods shown in the flowchart. When the computer program product is run on a computer system, the program code is used to cause the computer system to implement the methods provided in the embodiments of this application.
[0099] When the computer program is executed by the processor 601, it performs the functions defined in the system / apparatus of this application embodiment. According to the embodiments of this application, the systems, apparatuses, modules, units, etc., described above can be implemented by computer program modules.
[0100] In one embodiment, the computer program may rely on a tangible storage medium such as an optical storage device or a magnetic storage device. In another embodiment, the computer program may also be transmitted and distributed in the form of signals over a network medium, and downloaded and installed via the communication section 609, and / or installed from the removable medium 611. The program code contained in the computer program can be transmitted using any suitable network medium, including but not limited to: wireless, wired, etc., or any suitable combination thereof.
[0101] In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 609, and / or installed from the removable medium 611. When the computer program is executed by the processor 601, it performs the functions defined in the system of this application embodiment. According to the embodiments of this application, the systems, devices, apparatuses, modules, units, etc., described above can be implemented by computer program modules.
[0102] According to embodiments of this application, program code for executing the computer programs provided in the embodiments of this application can be written in any combination of one or more programming languages. Specifically, these computational programs can be implemented using high-level procedural and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages include, but are not limited to, languages such as Java, C++, Python, "C", or similar programming languages. The program code can be executed entirely on the user's computing device, partially on the user's device, partially on a remote computing device, or entirely on a remote computing device or server. In cases involving remote computing devices, the remote computing device can be connected to the user's computing device via any type of network, including a local area network (LAN) or a wide area network (WAN), or it can be connected to an external computing device (e.g., via the Internet using an Internet service provider).
[0103] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in a block diagram or flowchart, and combinations of blocks in a block diagram or flowchart, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0104] Those skilled in the art will understand that the features described in the various embodiments of this application can be combined and / or combined in various ways, even if such combinations or combinations are not explicitly described in this application. In particular, the features described in the various embodiments of this application can be combined and / or combined in various ways without departing from the spirit and teachings of this application. All such combinations and / or combinations fall within the scope of this application.
[0105] The embodiments of this application have been described above. However, these embodiments are merely illustrative and not intended to limit the scope of this application. Although various embodiments have been described above, this does not mean that the measures in the various embodiments cannot be used advantageously in combination. Without departing from the scope of this application, those skilled in the art can make various substitutions and modifications, all of which should fall within the scope of this application.
Claims
1. A data processing method, characterized in that, The method includes: In response to a target barrier lock acquisition request initiated by a target business process, the order of the target barrier lock acquisition requests in the lock request queue is determined, wherein the barrier lock is used to access target data, and the lock request queue includes: lock acquisition requests for the target data arranged in order of request time from earliest to latest; If the target lock acquisition request preceding the target barrier lock acquisition request is in a predetermined state, the target service process is allowed to acquire the barrier lock; During the access to the target data by the target business process using the target barrier lock, a read lock acquisition request is allowed that follows the target barrier lock acquisition request, so as to allow reading the target data via a read lock during the access; and During the access period, write lock acquisition requests following the target barrier lock acquisition request are prohibited to prevent modification of the target data via write locks during the access period.
2. The method according to claim 1, characterized in that, The target lock acquisition request preceding the target barrier lock acquisition request is in a predetermined state including at least one of the following: There is no target lock acquisition request in the lock request queue that is preceding the target barrier lock acquisition request; The request records corresponding to the target lock acquisition request have all been deleted.
3. The method according to claim 2, characterized in that, Each lock acquisition request has a corresponding version number, and the version number corresponds to the initiation time of the lock acquisition request; The method further includes: Determine the target version number corresponding to the target barrier lock acquisition request; If the target version number is the minimum version number corresponding to the lock request queue, it is determined that there is no target lock acquisition request in the lock request queue.
4. The method according to claim 3, characterized in that, The method further includes: If the target version number is not the minimum version number, listen for the deletion event of the request record of the target lock acquisition request; In response to the detection of the deletion event, it is determined that the target lock acquisition request has been released; The deletion event includes: deleting the request record in response to the business process that initiated the target lock acquisition request completing access to the target data; and / or deleting the request record in response to the expiration of the validity period of the target lock acquisition request.
5. The method according to claim 3, characterized in that, The version number increments sequentially from earliest to latest based on the initiation time, and the method further includes: The lock acquisition requests are arranged sequentially from front to back according to the version number in ascending order to obtain the lock request queue.
6. The method according to claim 1, characterized in that, The target lock acquisition request includes at least one of the following: read lock acquisition request, write lock acquisition request, and barrier lock acquisition request.
7. The method according to claim 1, characterized in that, The method further includes: In response to the deletion of the request record corresponding to the target barrier lock acquisition request, the barrier lock is released, and write lock acquisition requests following the target barrier lock acquisition request are allowed.
8. An electronic device, comprising: One or more processors; Memory, used to store one or more computer programs. The characteristic feature is that the one or more processors execute the one or more computer programs to implement the steps of the method according to any one of claims 1 to 7.
9. A computer-readable storage medium having a computer program or instructions stored thereon, characterized in that, When the computer program or instructions are executed by a processor, they implement the steps of the method according to any one of claims 1 to 7.
10. A computer program product comprising a computer program that, when executed by a processor, implements the method according to any one of claims 1 to 7.
