CN114942932A - Resource locking method and device - Google Patents

Resource locking method and device Download PDF

Info

Publication number
CN114942932A
CN114942932A CN202210390285.9A CN202210390285A CN114942932A CN 114942932 A CN114942932 A CN 114942932A CN 202210390285 A CN202210390285 A CN 202210390285A CN 114942932 A CN114942932 A CN 114942932A
Authority
CN
China
Prior art keywords
target
lock
locking
locking type
resource
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202210390285.9A
Other languages
Chinese (zh)
Inventor
余庆丹
钟艳辉
贺凡黎
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Bank of China Ltd
Original Assignee
Bank of China Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Bank of China Ltd filed Critical Bank of China Ltd
Priority to CN202210390285.9A priority Critical patent/CN114942932A/en
Publication of CN114942932A publication Critical patent/CN114942932A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2308Concurrency control
    • G06F16/2336Pessimistic concurrency control approaches, e.g. locking or multiple versions without time stamps
    • G06F16/2343Locking methods, e.g. distributed locking or locking implementation details
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application discloses a resource locking method and device, which can be applied to the financial field or the distributed field. The method comprises the following steps: determining a target locking type aiming at the target resource, wherein the target locking type comprises a synchronous lock for performing synchronous operation on the target resource or an asynchronous lock for performing asynchronous operation on the target resource; and locking the target resource according to the target locking type. Therefore, the corresponding distributed locks are added to the target resources in consideration of the locking types corresponding to different operations performed on the target resources, so that the unique accessibility of the target resources in the distributed transaction can be realized no matter synchronous operation or asynchronous operation is performed, and data errors caused by concurrent access are avoided.

Description

Resource locking method and device
Technical Field
The present application relates to the field of distributed technologies, and in particular, to a resource locking method and apparatus.
Background
Under the distributed architecture, the distributed application service has the characteristics of expandability, high reliability and high performance. High performance services tend to generate concurrent access to resources, while for some special resources, a distributed system generally uses a distributed lock to ensure unique accessibility within a distributed transaction, so as to avoid data errors caused by concurrent access. For example, when transfer transactions are carried out, the distributed lock ensures that other transactions cannot operate the deposit and withdrawal account number related to the transfer transactions before the transfer transactions are not completed, so that account amount errors are avoided.
In order to enable each distributed application service to respond quickly, the operation of each distributed application service can be split and arranged. For example, for some branch operations that may be delayed from completing, the branch operations may 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 unique accessibility of resources within a distributed transaction. For example, in creating a loan account, where risk domain records for the loan account may be executed asynchronously by the system back-office as a branch operation of creating the loan account. Moreover, the system may 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 an account feedback message is returned for the loan account creation operation, and the risk domain record for the loan account (asynchronous operation in the creation operation described above) performed by the system background is not complete, the system may mistakenly assume that the loan account was created and prematurely delete the distributed lock. 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 failure to recover from the transaction due to the existence of the creation and loan operations. It can be seen that existing distributed locks are not ideal for ensuring unique accessibility of resources within a distributed transaction.
Disclosure of Invention
The embodiment of the application provides a method and a device for locking resources, and aims to solve the problem that the effect of an existing distributed lock on ensuring the uniqueness of the resources in a distributed transaction is not ideal.
In a first aspect, an embodiment of the present application provides a resource locking method, including:
determining a target locking type aiming at a target resource, wherein the target locking type comprises a synchronous lock for performing synchronous operation on the target resource or an asynchronous lock for performing asynchronous operation on the target resource;
and locking the target resource according to the target locking type.
Optionally, the 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 comprises identification information associated with the target resource and identification information associated with the target lock added according to the target locking type;
and the identification information associated with the target resource and the identification information associated with the target lock are used as primary keys of the target distributed lock table, and the identification information associated with the target lock comprises the target locking type.
Optionally, after the target resource is locked according to the target locking type, the method further includes:
under the condition of carrying out new operation on the target resource, determining a new locking type aiming at the target resource according to the type of the new operation;
under the condition that the new service identification information corresponding to the new operation is the same as the target service identification information corresponding to the target lock, continuing to lock the target resource according to the new locking type and the target locking type;
and returning a locking failure message under the condition that the new service identification information is different from the target service identification information.
Optionally, the continuing to lock the target resource according to the new locking type and the target locking type includes:
under the condition that the new locking type and the target locking type are both synchronous locks, obtaining a target lock state corresponding to the target lock from the target distributed lock table;
under the condition that the target lock state is an unused state, modifying the target lock state into a used state in the target distributed lock table so as to complete locking of the target resource;
and returning a locking failure message under the condition that the target lock state is the use state.
Optionally, after returning the locking failure message, the method further includes:
and under the condition that the waiting time after the locking failure message is returned is greater than or equal to the preset time, locking the target resource again according to the new locking type and the target locking type until the number of times of locking again is greater than or equal to the preset number of times.
Optionally, the continuing to lock the target resource according to the new locking type and the target locking type includes:
and under the condition that the new locking type is a synchronous lock and the target locking type is an asynchronous lock, deleting the target distributed lock table from the database and inserting a new distributed lock table corresponding to the new locking type.
Optionally, the continuing to lock the target resource according to the new locking type and the target locking type includes:
and under the condition that the new locking type is an asynchronous lock and the target locking type is a synchronous lock, inserting a new distributed lock table corresponding to the new locking type into the database.
Optionally, the continuing to lock the target resource according to the new locking type and the target locking type includes:
and under the condition that the new locking type and the target locking type are asynchronous locks, returning a locking success message by taking the target lock as a new lock added according to the new locking type.
Optionally, the method further comprises:
and deleting the synchronous lock corresponding to the service under the condition that the service aiming at the target resource is completed.
In a second aspect, an embodiment of the present application provides a resource locking apparatus, including:
a locking type determining module, configured to determine a target locking type for a target resource, where the target locking type includes a synchronous lock that performs synchronous operation on the target resource or an asynchronous lock that performs asynchronous operation on the target resource;
and the resource locking module is used for locking the target resource according to the target locking type.
According to the technical scheme, the embodiment of the application has the following advantages:
in the embodiment of the application, by determining the target locking type for the target resource, a synchronous lock corresponding to synchronous operation or an asynchronous lock corresponding to asynchronous operation may be added to the target resource. Therefore, the corresponding distributed locks are added to the target resources in consideration of the locking types corresponding to different operations performed on the target resources, so that the unique accessibility of the target resources in the distributed transaction can be realized no matter synchronous operation or asynchronous operation is performed, and data errors caused by concurrent access are avoided.
Drawings
FIG. 1 is a flowchart of a method for locking a resource according to an embodiment of the present application;
FIG. 2 is a flow chart of another method for locking resources according to an embodiment of the present application;
FIG. 3 is a flowchart of another method for locking a resource according to an embodiment of the present application;
fig. 4 is a schematic structural diagram of a resource locking device according to an embodiment of the present application.
Detailed Description
In order to make those skilled in the art better understand the technical solutions of the present invention, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only a part of the embodiments of the present application, and not all the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
As mentioned above, at present, in order to enable each distributed application service to respond quickly, the operations thereof may be split and arranged. For example, for some branch operations that may be delayed from completing, the branch operations may 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 unique accessibility of resources within a distributed transaction.
To solve the problem, the embodiment of the 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 may be added to the target resource. Therefore, the corresponding distributed locks are added to the target resources in consideration of the locking types corresponding to different operations performed on the target resources, so that the unique accessibility of the target resources in the distributed transaction can be realized no matter synchronous operation or asynchronous operation is performed, and data errors caused by concurrent access are avoided. Various non-limiting embodiments of the present application are described in detail below with reference to the examples and the figures, respectively.
Fig. 1 is a flowchart of a resource locking method according to an embodiment of the present application. Referring to fig. 1, a resource locking method provided in an embodiment of the present application is implemented by using a distributed system as a step of executing a subject description scheme. The resource locking method can comprise the following steps:
step 101: the distributed system determines a target locking type for the target resource, the target locking type including a synchronous lock that operates synchronously with the target resource or an asynchronous lock that operates asynchronously with the target resource.
Step 102: and the distributed system locks the target resource according to the target locking type.
Optionally, the locking the target resource by the distributed system according to the target locking type may include: the distributed system inserts a target distributed lock table into a database corresponding to a target resource, wherein the target lock table comprises identification information associated with the target resource and identification information associated with a target lock added according to a target locking type; the identification information associated with the target resource and the identification information associated with the target lock are used as primary keys of a target distributed lock table, and the identification information associated with the target lock comprises a target locking type. Therefore, the target distributed lock table capable of identifying and storing the target resource and the target lock is inserted into the database, so that the target resource is locked. 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, errors can not occur when data in the target distributed lock table is modified, and the problem that the target resource is covered is avoided.
In order to facilitate understanding of a specific distributed lock applied to a target resource, in the embodiments of the present application, a target lock is taken as an example for detailed description. In this embodiment of the present application, the target resource refers to a resource that is locked by using a target lock, for example, an account that is locked by using a target lock, and this embodiment of the present application may not be specifically limited.
In the distributed lock table, the identification information associated with the resource may include resource type information, belonging function module information, and resource value information. The identification information associated with the distributed lock may include resource type information, belonging function module information, resource value information, and locking type information. In addition, the distributed lock table may also embody service identification information, a distributed lock state, and time information related to the distributed lock corresponding to the distributed lock, as shown in table 1-1.
TABLE 1-1
Figure BDA0003596638810000051
Figure BDA0003596638810000061
Specifically, in the case that the locking type is a synchronous lock, the value of the locking type in the distributed lock table may be S; in the case where the locking type is an asynchronous lock, the value of the locking type in the distributed lock table may be a. In the case that the lock state is an unused state, the value of the lock state in the distributed lock table may be 0; in the case where the lock state is the use state, the value of the lock state in the distributed lock table may be 1.
In practical application, taking the loan account creation service as an example, the target resource may be a loan account, the target lock may be a distributed lock for locking the loan account, the synchronous operation may be an operation for creating the loan account, and the asynchronous operation may be an operation for recording a risk field of the loan account. It should be noted that the resource locking method and apparatus provided by the present invention can be used in the financial field or other fields, for example, can be used in a transaction application scenario in the financial field. The other fields are arbitrary fields other than the financial field, for example, distributed fields. The above description is only an example, and does not limit the application field of the resource locking method and device provided by the present invention.
In the resource locking method provided by the embodiment of the application, the corresponding distributed lock is added to the target resource by considering the locking types corresponding to different operations performed on the target resource, so that the unique accessibility of the target resource in the distributed transaction can be realized no matter synchronous operation or asynchronous operation is performed, and data errors caused by concurrent access are avoided.
The embodiment of the application also provides another resource locking method. The resource locking method is described below with reference to the embodiments and the drawings.
Fig. 2 is a flowchart of another resource locking method according to an embodiment of the present application. Referring to fig. 2, the resource locking method provided in the embodiment of the present application is implemented by using a distributed system as a step of executing the subject description scheme. The resource locking method can comprise the following steps:
step 201: the distributed system determines a target locking type for the target resource, the target locking type including a synchronous lock that operates synchronously with the target resource or an asynchronous lock that operates asynchronously with the target resource.
Step 202: and the distributed system locks the target resource according to the target locking type.
Step 203: and under the condition that the service aiming at the target resource is completed, the distributed system deletes the synchronous lock corresponding to the service.
Here, the service for the target resource may specifically include a synchronous operation or an asynchronous operation performed on the target resource. When the service for the target resource is completed, only the synchronous lock corresponding to the synchronous operation in the service can be deleted, and the asynchronous lock corresponding to the asynchronous operation lock in the service is not operated, so that the unique accessibility of the resource in the distributed transaction is further ensured.
As can be seen from the above description, the resource locking method provided by the present application can add the corresponding distributed lock to the target resource in consideration of the locking types corresponding to different operations performed on the target resource, and can delete only the synchronous lock corresponding to the synchronous operation in the service when the service for the target resource is completed, thereby further ensuring the unique accessibility of the resource in the distributed transaction, and avoiding data errors caused by concurrent access.
It can be understood that the above scheme for 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 further provides another resource locking method, which can continue to lock the target resource after the initial locking, so as to further ensure the unique accessibility of the target resource within the distributed transaction. The resource locking method is described below with reference to the embodiments and the drawings.
Fig. 3 is a flowchart of another resource locking method according to an embodiment of the present application. Referring to fig. 3, the resource locking method provided in the embodiment of the present application is implemented by using a distributed system as a step of executing the subject description scheme. The resource locking method can comprise the following steps:
step 301: the distributed system determines a target locking type for the target resource, the target locking type including a synchronous lock that operates synchronously with the target resource or an asynchronous lock that operates asynchronously with the target resource.
Step 302: and the distributed system locks the target resource according to the target locking type.
For the operation of locking the target resource by the distributed system in step 302, reference may be made to the implementation manner in step 102 in the foregoing embodiment, which is not described herein again.
Step 303: and under the condition that the distributed system carries out new operation on the target resource, determining a new locking type aiming at the target resource according to the type of the new operation.
Step 304: and under the condition that the new service identification information corresponding to the new operation is the same as the target service 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.
Here, if the new service identification information is the same as the target service identification information, it may be indicated that the new operation and the operation corresponding to the target locking type (synchronous operation or asynchronous operation performed on the target resource) belong to the same service. Further, when the two types belong to the same service, the target resource is continuously locked according to the new locking type and the target locking type, so that the distributed lock can repeatedly lock the target resource in the same service.
Optionally, in the case that the new locking type is the same as the target locking type, the embodiment of the present application may provide different locking implementations for the two cases, that is, the synchronous lock and the asynchronous lock.
As an example, the distributed system continuing to lock the target resource based on the new locking type and the target locking type may include: under the condition that the new locking type and the target locking type are synchronous locks, the distributed system obtains a target locking state corresponding to the target lock from a target distributed locking table; under the condition that the target lock state is an unused state, the distributed system modifies the target lock state into a used state in a target distributed lock table so as to complete locking of target resources; and under the condition that the target lock state is the using state, the distributed system returns a locking failure message.
As another example, the distributed system continuing to lock the target resource based on the new locking type and the target locking type may include: and under the condition that the new locking type and the target locking type are asynchronous locks, the distributed system takes the target lock as a new lock added according to the new locking type and returns a locking success message.
Because the new locking type is the same as the target locking type, the existing target lock can be continuously used as a new lock added according to the new locking type, and therefore repeated locking operation of the distributed system is simplified. For the synchronous lock, the lock state of the existing target lock is required to be judged so as to ensure the locking completion; for the asynchronous lock, the purpose of setting the asynchronous lock is to lock the target resource in the period from the completion of the synchronous operation of the current service to the start of the asynchronous operation of the current service, and ensure that other services cannot operate or access the resource.
Optionally, in the case that the new locking type and the target locking type are different, the embodiment of the present application may provide different locking implementations for the case that the new locking type and the target locking type are respectively a synchronous lock or an asynchronous lock.
As an example, the distributed system continuing to lock the target resource based on the new locking type and the target locking type may include: and under the condition that the new locking type is a synchronous lock and the target locking type is an asynchronous lock, deleting the target distributed lock table in the database by the distributed system and inserting a new distributed lock table corresponding to the new locking type.
As another example, the distributed system continuing to lock the target resource based on the new locking type and the target locking type may include: and under the condition that the new locking type is an asynchronous lock and the target locking type is a synchronous lock, the distributed system inserts a new distributed lock table corresponding to the new locking type into the database.
Step 305: and under the condition that the new service identification information is different from the target service identification information, the distributed system returns a locking failure message.
Here, if the new service identifier is different from the target service identifier, it may indicate that the new operation and the operation corresponding to the target locking type belong to different services. Further, when the two services belong to different services, a locking failure message is directly returned, so that the distributed lock cannot repeatedly lock the target resource under different services.
Optionally, after the distributed system returns the locking failure message, the resource locking method may further include: and under the condition that the time length after the locking failure message is returned is greater than or equal to the preset time length, the distributed system locks the target resource again according to the new locking type and the target locking type until the number of times of relocking is greater than or equal to the preset number of times. The preset duration and the preset times may be configured according to the requirement of the service for the target resource, and the embodiment of the present application may not be specifically limited. By establishing the locking retry mechanism, the usability of the service is improved.
As can be seen from the above description, the resource locking method provided by the present application can consider the locking types corresponding to different operations performed on the target resource, add the corresponding distributed lock to the target resource, and comprehensively consider the existing target lock and the new locking type under the condition that the target resource needs to be continuously locked, thereby further ensuring the unique accessibility of the resource in the distributed transaction, and avoiding data errors caused by concurrent access.
Based on the resource locking method provided by the foregoing embodiment, correspondingly, the embodiment of the present application further provides a resource locking device. The resource locking device is described below with reference to the embodiments and the drawings.
Fig. 4 is a schematic structural diagram of a resource locking device according to an embodiment of the present application. As shown in fig. 4, the resource locking apparatus 400 provided in the embodiment of the present application may include:
a locking type determining module 401, configured to determine a target locking type for a target resource, where the target locking type includes a synchronous lock for performing synchronous operation on the target resource or an asynchronous lock for performing asynchronous operation on the target resource;
and a resource locking module 402, configured to lock the target resource according to the target locking type.
Optionally, the resource locking module 402 is specifically configured to insert a target distributed lock table into a database corresponding to the target resource, where 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 primary keys of a target distributed lock table, and the identification information associated with the target lock comprises a target locking type.
In the resource locking device provided in the embodiment of the present application, through the cooperation of the locking type determining module and the resource locking module, the corresponding distributed lock is added to the target resource in consideration of the locking types corresponding to different operations performed on the target resource, so that the unique accessibility of the target resource in the distributed transaction can be realized no matter the target resource is operated synchronously or asynchronously, and data errors caused by concurrent access are avoided.
In order to improve the availability of the resource locking apparatus, the resource locking apparatus 400 may further include:
a new locking type determining module 403, configured to determine, when a new operation is performed on the target resource, a new locking type for the target resource according to a type of the new operation;
a resource continuing locking module 404, configured to continue to lock the target resource according to the new locking type and the target locking type 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; and returning a locking failure message under the condition that the new service identification information is different from the target service identification information.
Therefore, by the new locking type determining module and the resource continuous locking module, the existing target lock and the new locking type can be comprehensively considered under the condition that the target resource needs to be continuously locked, so that the usability of the resource locking device is expanded, the unique accessibility of the resource in the distributed transaction is further ensured, and the data error caused by concurrent access is avoided.
As an example, the resource continuous locking module 404 may specifically include:
the target lock state obtaining module is used for obtaining a target lock state corresponding to the target lock from the target distributed lock table under the condition that the new locking type and the target locking type are synchronous locks;
the first locking module is used for modifying the target lock state into the use state in the target distributed lock table under the condition that the target lock state is the unused state so as to complete the locking of the target resource; and returning a locking failure message when the target lock state is the use state.
As another example, the resource continuing locking module 404 may specifically include:
and the second locking module is used for deleting the target distributed lock table in the database and inserting a new distributed lock table corresponding to the new locking type under the condition that the new locking type is a synchronous lock and the target locking type is an asynchronous lock.
As another example, the resource continuing locking module 404 may specifically include:
and the third locking module is used for inserting a new distributed lock table corresponding to the new locking type into the database under the condition that the new locking type is an asynchronous lock and the target locking type is a synchronous lock.
As another example, the resource continuing locking module 404 may specifically include:
and the fourth locking module is used for returning a locking success message by taking the target lock as a new lock added according to the new locking type under the condition that the new locking type and the target locking type are asynchronous locks.
Optionally, the resource locking apparatus 400 may further include:
and the relocking module is used for relocking the target resource according to the new locking type and the target locking type under the condition that the waiting time after the locking failure message is returned is greater than or equal to the preset time, until the relocking times are greater than or equal to the preset times.
Through the relocking module, a locking retry mechanism can be established, which is helpful for improving the availability of services.
Optionally, the resource locking apparatus 400 may further include:
and the synchronous lock deleting module is used for deleting the synchronous lock corresponding to the service under the condition that the service aiming at the target resource is completed.
Through the synchronous lock deleting module, only the synchronous lock corresponding to the synchronous operation in the service can be deleted when the service aiming at the target resource is completed, and the asynchronous lock corresponding to the asynchronous operation lock in the service is not operated, so that the unique accessibility of the resource in the distributed transaction is further ensured.
The above embodiments are only used to illustrate the technical solutions of the present application, and not to limit the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions in the embodiments of the present application.

Claims (10)

1. A method for locking a resource, comprising:
determining a target locking type for a target resource, wherein the target locking type comprises a synchronous lock for performing synchronous operation on the target resource or an asynchronous lock for performing asynchronous operation on the target resource;
and locking the target resource according to the target locking type.
2. The method of claim 1, wherein the locking the target resource according to the target locking type comprises:
inserting a target distributed lock table into a database corresponding to the target resource, wherein the target distributed lock table comprises identification information associated with the target resource and identification information associated with the target lock added according to the target locking type;
and the identification information associated with the target resource and the identification information associated with the target lock are used as primary keys of the target distributed lock table, and the identification information associated with the target lock comprises the target locking type.
3. The method of claim 2, wherein after the locking the target resource according to the target locking type, the method further comprises:
under the condition of carrying out new operation on the target resource, determining a new locking type aiming at the target resource according to the type of the new operation;
under the condition that the new service identification information corresponding to the new operation is the same as the target service identification information corresponding to the target lock, continuing to lock the target resource according to the new locking type and the target locking type;
and returning a locking failure message under the condition that the new service identification information is different from the target service identification information.
4. The method of claim 3, wherein continuing to lock the target resource according to the new locking type and the target locking type comprises:
under the condition that the new locking type and the target locking type are both synchronous locks, obtaining a target lock state corresponding to the target lock from the target distributed lock table;
under the condition that the target lock state is an unused state, modifying the target lock state into a used state in the target distributed lock table so as to complete locking of the target resource;
and returning a locking failure message under the condition that the target lock state is the use state.
5. The method of claim 3 or 4, wherein after returning the locking failure message, the method further comprises:
and when the time length after the locking failure message is returned is greater than or equal to the preset time length, locking the target resource again according to the new locking type and the target locking type until the number of times of re-locking is greater than or equal to the preset number of times.
6. The method of claim 3, wherein continuing to lock the target resource according to the new locking type and the target locking type comprises:
and under the condition that the new locking type is a synchronous lock and the target locking type is an asynchronous lock, deleting the target distributed lock table from the database and inserting a new distributed lock table corresponding to the new locking type.
7. The method according to claim 3, wherein the continuing to lock the target resource according to the new locking type and the target locking type comprises:
and under the condition that the new locking type is an asynchronous lock and the target locking type is a synchronous lock, inserting a new distributed lock table corresponding to the new locking type into the database.
8. The method of claim 3, wherein continuing to lock the target resource according to the new locking type and the target locking type comprises:
and under the condition that the new locking type and the target locking type are asynchronous locks, returning a locking success message by taking the target lock as a new lock added according to the new locking type.
9. The resource locking method according to claim 1, 2, 3, 4, 6 or 7, further comprising:
and deleting the synchronous lock corresponding to the service under the condition that the service aiming at the target resource is completed.
10. A resource locking apparatus, comprising:
a locking type determining module, configured to determine a target locking type for a target resource, where the target locking type includes a synchronous lock that performs synchronous operation on the target resource or an asynchronous lock that performs asynchronous operation on the target resource;
and the resource locking module is used for locking the target resource according to the target locking type.
CN202210390285.9A 2022-04-14 2022-04-14 Resource locking method and device Pending CN114942932A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202210390285.9A CN114942932A (en) 2022-04-14 2022-04-14 Resource locking method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202210390285.9A CN114942932A (en) 2022-04-14 2022-04-14 Resource locking method and device

Publications (1)

Publication Number Publication Date
CN114942932A true CN114942932A (en) 2022-08-26

Family

ID=82908043

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202210390285.9A Pending CN114942932A (en) 2022-04-14 2022-04-14 Resource locking method and device

Country Status (1)

Country Link
CN (1) CN114942932A (en)

Similar Documents

Publication Publication Date Title
EP3779732A1 (en) Data backup method, storage medium, and computing device
KR100625595B1 (en) Parallel Logging Method of Transaction Processing System
CN105574187B (en) A kind of Heterogeneous Database Replication transaction consistency support method and system
CN106844014B (en) Method and device for realizing suspension prevention of distributed transactions
US11836154B2 (en) Data synchronization method and device for databases, and storage medium
CN102203779B (en) Method for updating data and control apparatus thereof
CN102891849A (en) Service data synchronization method, data recovery method, data recovery device and network device
WO2020108325A1 (en) Transaction processing method, apparatus and device
US6944635B2 (en) Method for file deletion and recovery against system failures in database management system
CN113204530B (en) Data writing method, device, equipment and medium of distributed file system
CN112688799B (en) Redis cluster-based client number distribution method and distribution device
CN112053149A (en) Method and device for preventing repeated payment, electronic equipment and readable storage medium
WO2015062113A1 (en) Affair processing method and device
WO2021082925A1 (en) Transaction processing method and apparatus
CN109462661A (en) Method of data synchronization, device, computer equipment and storage medium
CN111143041B (en) Data consistency method, distributed coordinator and central coordinator
CN114942932A (en) Resource locking method and device
CN115098889B (en) Authority management method, device, equipment and storage medium
CN115269730A (en) Wide table synchronization method and device
CN114328564A (en) Method and device for realizing distributed lock
CN109740027B (en) Data exchange method, device, server and storage medium
CN107704557B (en) Processing method and device for operating mutually exclusive data, computer equipment and storage medium
CN115756768B (en) Distributed transaction processing method, device, equipment and medium based on saga
CN110046192B (en) System and method for generating serial number of request information
CN114116732B (en) Transaction processing method and device, storage device and server

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination