Resource locking method and device
By determining the lock type according to the operation type of the target resource in a distributed system and managing distributed locks in the database, the unique accessibility problem of distributed locks in asynchronous operation scenarios is solved, and the unique accessibility of resources and business reliability are achieved.
Patent Information
- Application Number
- CN202210390285.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-04-14
- Publication Date
- 2025-04-15
- Estimated Expiration
- 2042-04-14
AI Technical Summary
Existing distributed locks are difficult to ensure unique accessibility of resources within distributed transactions, especially in asynchronous operation scenarios, which may lead to data errors or transaction failures.
By determining the target lock type of the target resource, a synchronous lock or an asynchronous lock is used to lock the target resource. The specific steps include inserting the target distributed lock table in the database, modifying the lock status according to the lock type, and deleting the synchronous lock when the service is completed.
The unique accessibility of the target resource in distributed transactions is achieved, and data errors and transaction failures caused by concurrent access are avoided.
Smart Images

Figure CN114942932B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of distributed technology, and in particular to a resource locking method and device. Background Art
[0002] Under the distributed architecture, distributed application services are characterized by scalability, high reliability and high performance. High-performance services will inevitably generate concurrent access to resources. For some special resources, distributed systems generally use distributed locks to ensure their unique access within distributed transactions, thereby avoiding data errors caused by concurrent access. For example, when conducting a transfer transaction, distributed locks are used to ensure that other transactions cannot operate on the deposit and withdrawal accounts involved in the transfer transaction before the transfer transaction is completed, so as to avoid account balance errors.
[0003] In order to enable each distributed application service to respond quickly, its operations can be split and orchestrated. For example, for some branch operations that can be completed late, they can be executed asynchronously by the system background after the main operation returns. However, in the scenario of locking such asynchronous operations, it is difficult for existing distributed locks to ensure the unique accessibility of resources within distributed transactions. For example, when creating a loan account, the risk field record for the loan account can be executed asynchronously by the system background as a branch operation for creating the loan account. In addition, the system can set a distributed lock to ensure that other transactions such as loan transactions cannot operate on the loan account before the loan account is created. However, when the creation operation for the loan account returns an account feedback message, and the risk field record for the loan account executed by the system background (the asynchronous operation in the above creation operation) is not completed, the system may mistakenly believe that the loan account has been created and delete the distributed lock in advance. At this time, if a loan operation is initiated for the loan account, the creation operation for the loan account may actually continue to modify the loan account, resulting in data errors or transaction failures in the loan account due to the existence of the above two operations of creation and loan. Cannot be reversed. It can be seen that the existing distributed locks are not ideal for ensuring the unique accessibility of resources within distributed transactions. Summary of the invention
[0004] The embodiments of the present application provide a resource locking method and device to solve the problem that the existing distributed locks are not ideal for ensuring the unique accessibility of resources in distributed transactions.
[0005] In a first aspect, an embodiment of the present application provides a resource locking method, comprising:
[0006] Determine a target lock type for a target resource, where the target lock type includes a synchronous lock for performing a synchronous operation on the target resource or an asynchronous lock for performing an asynchronous operation on the target resource;
[0007] The target resource is locked according to the target locking type.
[0008] Optionally, locking the target resource according to the target locking type includes:
[0009] Inserting a target distributed lock table into a database corresponding to the target resource, wherein the target distributed lock table includes identification information associated with the target resource and identification information associated with the target lock added according to the target locking type;
[0010] The identification information associated with the target resource and the identification information associated with the target lock serve as the primary key of the target distributed lock table, and the identification information associated with the target lock includes the target locking type.
[0011] Optionally, after locking the target resource according to the target locking type, the method further includes:
[0012] In the case of a new operation being performed on the target resource, determining a new lock type for the target resource according to the type of the new operation;
[0013] When the new service identification information corresponding to the new operation is the same as the target service identification information corresponding to the target lock, continue to lock the target resource according to the new locking type and the target locking type;
[0014] When the new service identification information is different from the target service identification information, a locking failure message is returned.
[0015] Optionally, continuing to lock the target resource according to the new locking type and the target locking type includes:
[0016] In the case where both the new lock type and the target lock type are synchronous locks, obtaining a target lock state corresponding to the target lock from the target distributed lock table;
[0017] When the target lock state is in an unused state, modifying the target lock state to a used state in the target distributed lock table to complete locking of the target resource;
[0018] When the target lock state is in use, a lock failure message is returned.
[0019] Optionally, after returning the lock failure message, the method further includes:
[0020] When the waiting time after returning the lock failure message is greater than or equal to the preset time, the target resource is locked again according to the new lock type and the target lock type until the number of re-locks is greater than or equal to the preset number of times.
[0021] Optionally, continuing to lock the target resource according to the new locking type and the target locking type includes:
[0022] In the case where the new lock type is a synchronous lock and the target lock type is an asynchronous lock, the target distributed lock table is deleted in the database, and a new distributed lock table corresponding to the new lock type is inserted.
[0023] Optionally, continuing to lock the target resource according to the new locking type and the target locking type includes:
[0024] In the case where the new lock type is an asynchronous lock and the target lock type is a synchronous lock, a new distributed lock table corresponding to the new lock type is inserted into the database.
[0025] Optionally, continuing to lock the target resource according to the new locking type and the target locking type includes:
[0026] In the case that both the new lock type and the target lock type are asynchronous locks, the target lock is used as a new lock added according to the new lock type, and a lock success message is returned.
[0027] Optionally, it is characterized by further comprising:
[0028] When the service for the target resource is completed, the synchronization lock corresponding to the service is deleted.
[0029] In a second aspect, an embodiment of the present application provides a resource locking device, including:
[0030] A lock type determination module, used to determine a target lock type for a target resource, wherein the target lock type includes a synchronous lock for performing a synchronous operation on the target resource or an asynchronous lock for performing an asynchronous operation on the target resource;
[0031] The resource locking module is used to lock the target resource according to the target locking type.
[0032] It can be seen from the above technical solutions that the embodiments of the present application have the following advantages:
[0033] In the embodiment of the present application, by determining the target lock type for the target resource, a synchronous lock corresponding to the synchronous operation or an asynchronous lock corresponding to the asynchronous operation can be added to the target resource. In this way, considering the lock types corresponding to different operations performed on the target resource, a corresponding distributed lock is added to the target resource, so that whether it is a synchronous operation or an asynchronous operation, the unique accessibility of the target resource in the distributed transaction can be achieved, avoiding data errors caused by concurrent access. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] Figure 1 is a flow chart of a resource locking method provided in an embodiment of the present application;
[0035] Figure 2 is a flow chart of another resource locking method provided in an embodiment of the present application;
[0036] Figure 3 This is a flowchart of another resource locking method provided in an embodiment of the present application;
[0037] Figure 4 It is a structural diagram of a resource locking device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0038] In order to enable those skilled in the art to better understand the scheme of the present invention, the technical scheme in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0039] As mentioned above, currently, in order to enable each distributed application service to respond quickly, its operations can be split and orchestrated. For example, for some branch operations that can be completed late, they can be executed asynchronously by the system background after the main operation returns. However, in the scenario of locking such asynchronous operations, the existing distributed locks are difficult to guarantee the unique accessibility of resources within the distributed transaction.
[0040] To address this problem, an embodiment of the present application provides a resource locking method and device. By determining the target locking type for the target resource, a synchronous lock corresponding to a synchronous operation or an asynchronous lock corresponding to an asynchronous operation can be added to the target resource. In this way, considering the locking types corresponding to different operations performed on the target resource, a corresponding distributed lock is added to the target resource, so that whether it is a synchronous operation or an asynchronous operation, the unique accessibility of the target resource within the distributed transaction can be achieved, avoiding data errors caused by concurrent access. The various non-limiting implementation methods of the embodiments of the present application are described in detail below in conjunction with the embodiments and drawings.
[0041] Figure 1 Flowchart of a resource locking method provided by an embodiment of the present application. Figure 1 As shown, the resource locking method provided in the embodiment of the present application is implemented by using a distributed system as the execution subject to describe the steps of the scheme. The resource locking method may include:
[0042] Step 101: The distributed system determines a target lock type for a target resource, where the target lock type includes a synchronous lock for performing synchronous operations on the target resource or an asynchronous lock for performing asynchronous operations on the target resource.
[0043] Step 102: The distributed system locks the target resource according to the target locking type.
[0044] Optionally, the distributed system locks the target resource according to the target locking type, which may include: the distributed system inserts a target distributed lock table into the database corresponding to the target resource, the target lock table includes identification information associated with the target resource, and identification information associated with the target lock added according to the target locking type; wherein the identification information associated with the target resource and the identification information associated with the target lock serve as the primary key of the target distributed lock table, and the identification information associated with the target lock includes the target locking type. In this way, the target resource is locked by inserting a target distributed lock table that can identify and save the target resource and the target lock into the database. In addition, by using the identification information associated with the target resource and the identification information associated with the target lock as the primary key of the target distributed lock table, it is helpful to prevent errors when the data in the target distributed lock table is modified, thereby avoiding the problem of target resources being overwritten.
[0045] In order to facilitate understanding of a specific distributed lock applied to a target resource, in the embodiment of the present application, a target lock is used as an example for detailed description. In the embodiment of the present application, the target resource refers to a resource locked by a target lock, such as an account locked by a target lock, and the embodiment of the present application does not specifically limit this.
[0046] In the distributed lock table, the identification information associated with the resource may include resource type information, function module information, and resource value information. The identification information associated with the distributed lock may include resource type information, function module information, resource value information, and lock type information. In addition, the distributed lock table may also reflect the business identification information corresponding to the distributed lock, the distributed lock status, and the time information related to the distributed lock, as shown in Table 1-1.
[0047] Table 1-1
[0048]
[0049]
[0050] Specifically, when the lock type is a synchronous lock, the value of the lock type in the distributed lock table may be S; when the lock type is an asynchronous lock, the value of the lock type in the distributed lock table may be A. When the lock state is an unused state, the value of the lock state in the distributed lock table may be 0; when the lock state is a used state, the value of the lock state in the distributed lock table may be 1.
[0051] In actual applications, taking the creation of a loan account business as an example, the target resource may be a loan account, the target lock may be a distributed lock that locks the loan account, the synchronous operation may be an operation to create the loan account, and the asynchronous operation may be an operation to record the risk area of the loan account. It should be noted that the resource locking method and device provided by the present invention can be used in the financial field or other fields, for example, it can be used in transaction application scenarios in the financial field. Other fields are any fields other than the financial field, for example, distributed fields. The above is only an example and does not limit the application field of the resource locking method and device provided by the present invention.
[0052] The above is the resource locking method provided in the embodiment of the present application. By considering the locking types corresponding to different operations performed on the target resources, the corresponding distributed locks are added to the target resources, so that whether it is a synchronous operation or an asynchronous operation, the unique accessibility of the target resource can be achieved within the distributed transaction, avoiding data errors caused by concurrent access.
[0053] The embodiment of the present application also provides another resource locking method. The resource locking method is described below in conjunction with the embodiments and drawings.
[0054] Figure 2 Flowchart of another resource locking method provided by an embodiment of the present application. Figure 2 As shown, the resource locking method provided in the embodiment of the present application is implemented by using a distributed system as the execution subject to describe the steps of the scheme. The resource locking method may include:
[0055] Step 201: The distributed system determines a target lock type for a target resource, where the target lock type includes a synchronous lock for performing synchronous operations on the target resource or an asynchronous lock for performing asynchronous operations on the target resource.
[0056] Step 202: The distributed system locks the target resource according to the target locking type.
[0057] Step 203: When the service for the target resource is completed, the distributed system deletes the synchronization lock corresponding to the service.
[0058] Here, the business for the target resource may specifically include synchronous operations or asynchronous operations on the target resource. When the business for the target resource is completed, only the synchronous lock corresponding to the synchronous operation in the business may be deleted, and the asynchronous lock corresponding to the asynchronous operation lock in the business may not be operated, thereby further ensuring the unique accessibility of the resource in the distributed transaction.
[0059] From the above description, it can be seen that the resource locking method provided by the present application can consider the locking types corresponding to different operations performed on the target resources, add corresponding distributed locks to the target resources, and when the business for the target resources is completed, only the synchronization locks corresponding to the synchronization operations in the business can be deleted, thereby further ensuring the unique accessibility of resources within the distributed transaction and avoiding data errors caused by concurrent access.
[0060] It can be understood that the above-mentioned scheme of locking the target resource according to the target locking type is an initial locking scheme, and in order to provide the availability of the resource locking method, the embodiment of the present application also provides another resource locking method, which can continue to lock the target resource after the initial locking, and further ensure the unique accessibility of the target resource in the distributed transaction. The resource locking method is described below in conjunction with the embodiments and drawings.
[0061] Figure 3 This is a flowchart of another resource locking method provided in an embodiment of the present application. Figure 3 As shown, the resource locking method provided in the embodiment of the present application is implemented by using a distributed system as the execution subject to describe the steps of the scheme. The resource locking method may include:
[0062] Step 301: The distributed system determines a target lock type for a target resource, where the target lock type includes a synchronous lock for performing synchronous operations on the target resource or an asynchronous lock for performing asynchronous operations on the target resource.
[0063] Step 302: The distributed system locks the target resource according to the target locking type.
[0064] Regarding the operation of the distributed system locking the target resource in step 302, reference may be made to the implementation of step 102 in the aforementioned embodiment, which will not be described in detail here.
[0065] Step 303: When the distributed system performs a new operation on the target resource, the distributed system determines a new lock type for the target resource according to the type of the new operation.
[0066] Step 304: When the new business identification information corresponding to the new operation is identical to the target business identification information corresponding to the target lock, the distributed system continues to lock the target resource according to the new locking type and the target locking type.
[0067] Here, if the new business identification information is the same as the target business identification information, it can indicate that the new operation and the operation corresponding to the target lock type (synchronous operation or asynchronous operation on the target resource) belong to the same business. Furthermore, only when the two belong to the same business, the target resource is locked according to the new lock type and the target lock type, so that the distributed lock can repeatedly lock the target resource in the same business.
[0068] Optionally, when the new locking type and the target locking type are the same, the embodiment of the present application may provide different locking implementations for the two cases where both are synchronous locks or asynchronous locks.
[0069] As an example, the distributed system continues to lock the target resource according to the new lock type and the target lock type, which may include: when the new lock type and the target lock type are both synchronous locks, the distributed system obtains the target lock state corresponding to the target lock from the target distributed lock table; when the target lock state is in an unused state, the distributed system modifies the target lock state to a used state in the target distributed lock table to complete locking the target resource; when the target lock state is in a used state, the distributed system returns a lock failure message.
[0070] As another example, the distributed system continues to lock the target resource according to the new lock type and the target lock type, which may include: when the new lock type and the target lock type are both asynchronous locks, the distributed system uses the target lock as the new lock added according to the new lock type, and returns a lock success message.
[0071] Since the new lock type is the same as the target lock type, the existing target lock can continue to be used as the new lock added according to the new lock type, thereby simplifying the repeated locking operations of the distributed system. For synchronous locks, it is also necessary to determine the lock status of the existing target lock to ensure that the locking is completed; for asynchronous locks, since the purpose of setting asynchronous locks is to lock the target resource from the completion of the synchronous operation of the current business to the start of the asynchronous operation of the current business, to ensure that other businesses cannot operate or access the resources, therefore, when the target lock is an asynchronous lock, it can be indicated that the target resource is being locked by the asynchronous lock, so there is no need to determine the lock status.
[0072] Optionally, when the new locking type and the target locking type are different, the embodiment of the present application may provide different locking implementation methods for the cases where the two are synchronous locks or asynchronous locks respectively.
[0073] As an example, the distributed system continues to lock the target resource according to the new lock type and the target lock type, which may include: when the new lock type is a synchronous lock and the target lock type is an asynchronous lock, the distributed system deletes the target distributed lock table in the database and inserts a new distributed lock table corresponding to the new lock type.
[0074] As another example, the distributed system continues to lock the target resource according to the new lock type and the target lock type, which may include: when the new lock type is an asynchronous lock and the target lock type is a synchronous lock, the distributed system inserts a new distributed lock table corresponding to the new lock type into the database.
[0075] Step 305: When the new service identification information is different from the target service identification information, the distributed system returns a lock failure message.
[0076] Here, if the new business identifier is different from the target business identifier, it can indicate that the new operation and the operation corresponding to the target lock type belong to different businesses. Further, when the two belong to different businesses, a lock failure message is directly returned, so that the distributed lock cannot repeatedly lock the target resource under different businesses.
[0077] Optionally, after the distributed system returns a lock failure message, the resource locking method may further include: when the time after the lock failure message is returned is greater than or equal to a preset time, the distributed system re-locks the target resource according to the new lock type and the target lock type until the number of re-locks is greater than or equal to a preset number of times. Among them, the preset time and the preset number of times can be configured according to the needs of the business for the target resource, and the embodiments of the present application may not be specifically limited to this. By establishing the above-mentioned lock retry mechanism, it helps to improve the availability of the business.
[0078] From the above description, it can be seen that the resource locking method provided by the present application can consider the locking types corresponding to different operations performed on the target resources, add corresponding distributed locks to the target resources, and when it is necessary to continue locking the target resources, comprehensively consider the existing target locks and new locking types, thereby further ensuring the unique accessibility of resources within distributed transactions and avoiding data errors caused by concurrent access.
[0079] Based on the resource locking method provided in the above embodiment, the embodiment of the present application also provides a resource locking device. The resource locking device is described below in conjunction with the embodiments and drawings.
[0080] Figure 4 Schematic diagram of a resource locking device provided in an embodiment of the present application. Figure 4 As shown, the resource locking device 400 provided in the embodiment of the present application may include:
[0081] The lock type determination module 401 is used to determine the target lock type for the target resource, where the target lock type includes a synchronous lock for performing synchronous operations on the target resource or an asynchronous lock for performing asynchronous operations on the target resource;
[0082] The resource locking module 402 is used to lock the target resource according to the target locking type.
[0083] Optionally, the resource locking module 402 is specifically used to insert a target distributed lock table into a database corresponding to the target resource, wherein the target distributed lock table includes identification information associated with the target resource and identification information associated with the target lock added according to the target locking type; wherein the identification information associated with the target resource and the identification information associated with the target lock serve as the primary key of the target distributed lock table, and the identification information associated with the target lock includes the target locking type.
[0084] The above is the resource locking device provided in the embodiment of the present application. Through the cooperation of the lock type determination module and the resource locking module, the corresponding distributed lock is added to the target resource taking into account the lock types corresponding to different operations performed on the target resource. This allows the target resource to be uniquely accessible within the distributed transaction regardless of whether it is a synchronous operation or an asynchronous operation, thereby avoiding data errors caused by concurrent access.
[0085] In order to improve the availability of the resource locking device, the resource locking device 400 may further include:
[0086] A new lock type determination module 403 is used to determine a new lock type for the target resource according to the type of the new operation when a new operation is performed on the target resource;
[0087] The resource continuation locking module 404 is used to continue locking the target resource according to the new locking type and the target locking type when the new business identification information corresponding to the new operation is the same as the target business identification information corresponding to the target lock; and return a locking failure message when the new business identification information is different from the target business identification information.
[0088] In this way, through the new lock type determination module and the resource continuation locking module, when it is necessary to continue locking the target resource, the existing target lock and the new lock type can be comprehensively considered, thereby expanding the availability of the above-mentioned resource locking device, further ensuring the unique accessibility of resources within distributed transactions, and avoiding data errors caused by concurrent access.
[0089] As an example, the resource continued locking module 404 may specifically include:
[0090] The target lock state acquisition module is used to obtain the target lock state corresponding to the target lock from the target distributed lock table when the new lock type and the target lock type are both synchronous locks;
[0091] The first locking module is used to modify the target lock state to the used state in the target distributed lock table when the target lock state is unused to complete the locking of the target resource; when the target lock state is used, return a locking failure message.
[0092] As another example, the resource continued locking module 404 may specifically include:
[0093] The second locking module is used to delete the target distributed lock table in the database and insert a new distributed lock table corresponding to the new locking type when the new locking type is a synchronous lock and the target locking type is an asynchronous lock.
[0094] As another example, the resource continued locking module 404 may specifically include:
[0095] The third locking module is used to insert a new distributed lock table corresponding to the new locking type into the database when the new locking type is an asynchronous lock and the target locking type is a synchronous lock.
[0096] As another example, the resource continued locking module 404 may specifically include:
[0097] The fourth locking module is used to return a locking success message using the target lock as a new lock added according to the new locking type when both the new locking type and the target locking type are asynchronous locks.
[0098] Optionally, the resource locking device 400 may further include:
[0099] The re-locking module is used to re-lock the target resource according to the new lock type and target lock type when the waiting time after returning the lock failure message is greater than or equal to the preset time, until the number of re-locks is greater than or equal to the preset number.
[0100] By re-locking the module, a lock retry mechanism can be established, which helps to improve business availability.
[0101] Optionally, the resource locking device 400 may further include:
[0102] The synchronization lock deletion module is used to delete the synchronization lock corresponding to the business when the business for the target resource is completed.
[0103] Through the synchronous lock deletion module, when the business for the target resource is completed, only the synchronous lock corresponding to the synchronous operation in the business can be deleted, without operating the asynchronous lock corresponding to the asynchronous operation lock in the business, thereby further ensuring the unique accessibility of resources within the distributed transaction.
[0104] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A resource locking method, characterized in that: include: Determine a target lock type for a target resource, where the target lock type includes a synchronous lock for performing a synchronous operation on the target resource or an asynchronous lock for performing an asynchronous operation on the target resource; Locking the target resource according to the target locking type; The step of locking the target resource according to the target locking type includes: Inserting a target distributed lock table into a database corresponding to the target resource, wherein the target distributed lock table includes identification information associated with the target resource and identification information associated with the target lock added according to the target locking type; The identification information associated with the target resource and the identification information associated with the target lock are used as the primary key of the target distributed lock table, and the identification information associated with the target lock includes the target locking type; Performing a new operation on the target resource, and determining a new lock type for the target resource according to the type of the new operation; When the new service identification information corresponding to the new operation is the same as the target service identification information corresponding to the target lock, continue to lock the target resource according to the new locking type and the target locking type; If the new service identification information is different from the target service identification information, a lock failure message is returned; The step of continuing to lock the target resource according to the new locking type and the target locking type includes: In the case where both the new lock type and the target lock type are synchronous locks, obtaining a target lock state corresponding to the target lock from the target distributed lock table; When the target lock state is in an unused state, modifying the target lock state to a used state in the target distributed lock table to complete locking of the target resource; When the target lock state is in use, a lock failure message is returned; In the case where the new lock type is a synchronous lock and the target lock type is an asynchronous lock, deleting the target distributed lock table in the database, and inserting a new distributed lock table corresponding to the new lock type; In a case where the new lock type is an asynchronous lock and the target lock type is a synchronous lock, inserting a new distributed lock table corresponding to the new lock type into the database; In the case that both the new lock type and the target lock type are asynchronous locks, the target lock is used as a new lock added according to the new lock type, and a lock success message is returned.
2. The resource locking method according to claim 1, characterized in that: After returning the lock failure message, the method further includes: When the time after returning the lock failure message is greater than or equal to the preset time, the target resource is locked again according to the new lock type and the target lock type until the number of re-locks is greater than or equal to the preset number.
3. The resource locking method according to claim 1, characterized in that: Also includes: When the service for the target resource is completed, the synchronization lock corresponding to the service is deleted.
4. A resource locking device, characterized in that: include: A lock type determination module, used to determine a target lock type for a target resource, wherein the target lock type includes a synchronous lock for performing a synchronous operation on the target resource or an asynchronous lock for performing an asynchronous operation on the target resource; A resource locking module, used to lock the target resource according to the target locking type; The step of locking the target resource according to the target locking type includes: Inserting a target distributed lock table into a database corresponding to the target resource, wherein the target distributed lock table includes identification information associated with the target resource and identification information associated with the target lock added according to the target locking type; The identification information associated with the target resource and the identification information associated with the target lock are used as the primary key of the target distributed lock table, and the identification information associated with the target lock includes the target locking type; A lock type determination module after adding a new operation is used to perform a new operation on the target resource and determine a new lock type for the target resource according to the type of the new operation; A resource locking module after adding a new operation is used to continue locking the target resource according to the new locking type and the target locking type when the new business identification information corresponding to the new operation is the same as the target business identification information corresponding to the target lock; If the new service identification information is different from the target service identification information, a lock failure message is returned; The step of continuing to lock the target resource according to the new locking type and the target locking type includes: In the case where both the new lock type and the target lock type are synchronous locks, obtaining a target lock state corresponding to the target lock from the target distributed lock table; When the target lock state is in an unused state, modifying the target lock state to a used state in the target distributed lock table to complete locking of the target resource; When the target lock state is in use, a lock failure message is returned; In the case where the new lock type is a synchronous lock and the target lock type is an asynchronous lock, deleting the target distributed lock table in the database, and inserting a new distributed lock table corresponding to the new lock type; In a case where the new lock type is an asynchronous lock and the target lock type is a synchronous lock, inserting a new distributed lock table corresponding to the new lock type into the database; In the case that both the new lock type and the target lock type are asynchronous locks, the target lock is used as a new lock added according to the new lock type, and a lock success message is returned.
Citation Information
Patent Citations
XML data concurrency control method based on local path lock
CN101702176A