Unified distributed lock implementation method and system
Through unified distributed lock implementation methods and systems, user needs are obtained, multiple distributed lock implementation methods are matched and called, and the problem that the existing technology cannot meet diversified business scenarios is solved, and distributed locks with high availability and resource efficiency are achieved Serve.
Patent Information
- Application Number
- CN202410484485.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-04-22
- Publication Date
- 2024-11-08
AI Technical Summary
The existing distributed lock implementation solutions cannot fully meet the performance and consistency requirements of various business scenarios, and the high availability mechanism is complex, which increases system complexity and resource waste.
A unified distributed lock implementation method and system is proposed. By obtaining the user's distributed lock requirements information, matching and calling various implementation methods, such as distributed lock implementation based on relational database, Redis, Ignite, Zookeeper, Etcd, and providing Unified interface, automatically routed to the corresponding cluster, meeting the needs of different business scenarios.
It realizes high availability and flexibility of distributed locks, reduces the threshold for the use of distributed locks for applications, improves resource utilization efficiency, and meets the performance and consistency requirements in different business scenarios.
Smart Images

Figure CN118916186A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field related to distributed locks, and in particular to a unified distributed lock implementation method and system. Background Art
[0002] There are various distributed lock implementation schemes in the prior art. The use scenarios of distributed locks are relatively complex, and various distributed lock methods have their own advantages and disadvantages. Existing distributed locks sometimes require relatively high performance requirements, and sometimes require relatively high consistency. A single distributed lock implementation scheme cannot fully meet the needs of various business scenarios. The high availability mechanism of distributed locks is relatively complex. The threshold for building a highly available distributed lock cluster independently in a distributed system is relatively high, which increases the complexity of the application system and causes serious waste of resources.
[0003] In response to the above technical issues, distributed locks need to establish a unified enterprise-level service, so a unified distributed lock implementation method and system are proposed. Provide a consistent access interface to the outside world, and the backend provides the implementation of multiple distributed lock mechanisms and achieves high availability. Consumers can specify the implementation method of distributed locks according to the characteristics of the business scenario; or only specify performance and consistency requirements, and the distributed lock service automatically routes to the corresponding distributed lock cluster to provide a distributed lock implementation solution that meets the requirements of consumers. In addition, by building an enterprise-level distributed lock service, consumers only need to use distributed locks through APIs, which lowers the threshold for applications to use distributed locks and also improves resource utilization efficiency.
[0004] It is worth noting that the data collection and migration activities involved in this application have been agreed by the user and are necessary for the applicant to carry out normal business activities. The applicant has performed desensitization processing such as anonymization and confidentiality on the collected data, and has set up data access rights accordingly to ensure that the user's privacy is not leaked. The data compliance measures involved in this application are only listed, and the applicant has also set up other relevant data compliance measures. The data processing activities carried out by the applicant comply with the provisions of laws and regulations such as the Data Security Law and the Personal Information Protection Law. Summary of the invention
[0005] In order to solve the shortcomings of the existing situation, the present invention aims at the defects of the above background technology and proposes a unified distributed lock implementation method and system. It includes:
[0006] The first aspect of the present application proposes a unified distributed lock implementation method, which is characterized by comprising:
[0007] S1. Obtain the user's first distributed lock requirement information, wherein the first distributed lock requirement information includes directly specifying the implementation method of the distributed lock or specifying the performance requirement information and consistency requirement information of the distributed lock;
[0008] S2. Match the first requirement information of the distributed lock with the existing implementation method of the distributed lock to obtain a first matching result;
[0009] S3. Calling a distributed lock implementation method based on the first matching result, wherein the distributed lock implementation method includes a distributed lock implementation method based on a relational database (such as MySql), Redis, Ignite, Zookeeper, and Etcd;
[0010] S4. The distributed lock implementation module implements the distributed lock in response to the call of the first matching result.
[0011] Furthermore, the distributed lock is implemented based on Redis distributed lock, including setting the timeout of the distributed lock, and the timeout includes a locking timeout and an acquisition timeout.
[0012] Furthermore, the method includes: determining whether the time for acquiring the lock exceeds the acquisition timeout period, and if so, giving up acquiring the lock; determining whether the locking time exceeds the locking timeout period, and if so, releasing the lock.
[0013] Furthermore, the method is implemented by using a Redisson development framework.
[0014] Furthermore, the distributed lock is implemented based on the Etcd distributed lock, including setting the unique path name as the Key value and setting the effective time of the distributed lock.
[0015] Furthermore, the method is implemented by using a Jetcd development framework.
[0016] The second aspect of the present application proposes a unified distributed lock implementation device, which is characterized by comprising:
[0017] A unified interface module, used to obtain the user's first distributed lock requirement information, wherein the first distributed lock requirement information includes directly specifying the implementation method of the distributed lock or specifying the performance requirement information and consistency requirement information of the distributed lock;
[0018] A matching module, used to match the first requirement information of the distributed lock with the existing implementation method of the distributed lock to obtain a first matching result;
[0019] A calling module, used to call the implementation of the distributed lock based on the first matching result, wherein the implementation of the distributed lock includes a distributed lock implementation based on a relational database (such as MySql), Redis, Ignite, Zookeeper, and Etcd;
[0020] The distributed lock implementation module includes a relational database (such as MySql) distributed lock implementation module, a Redis distributed lock implementation module, an Ignite distributed lock implementation module, a Zookeeper distributed lock implementation module, and an Etcd distributed lock implementation module, which are used to implement a distributed lock method corresponding to the first matching result.
[0021] The third aspect of the present application provides an electronic device, characterized in that it includes: a processor, and a memory communicatively connected to the processor;
[0022] The memory stores computer-executable instructions;
[0023] The processor executes the computer-executable instructions stored in the memory to implement the above-mentioned unified distributed lock implementation method.
[0024] In a fourth aspect, the present application proposes a computer-readable storage medium, characterized in that the computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, they are used to implement the above-mentioned unified distributed lock implementation method.
[0025] The fifth aspect of the present application proposes a computer program product, characterized in that it includes a computer program, which implements the above-mentioned unified distributed lock implementation method when executed by a processor.
[0026] The beneficial effects of the present invention are: building distributed locks as unified enterprise-level services, providing consistent access interfaces to the outside world, and providing multiple distributed lock mechanism implementations on the back end, and achieving high availability. Consumers can directly specify the implementation method of distributed locks according to the characteristics of the business scenario; or only specify performance and consistency requirements, and the distributed lock service automatically routes to the corresponding distributed lock cluster, providing distributed lock implementation solutions that meet the requirements of consumers, and meeting different requirements for performance and consistency in different business scenarios; in addition, by building an enterprise-level distributed lock service, consumers only need to use distributed locks through APIs, which lowers the threshold for applications to use distributed locks and also improves resource utilization efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0027] Figure 1 The figure is a flow chart of the unified distributed lock implementation method of the present invention.
[0028] Figure 2 This is a structural block diagram of the unified distributed lock implementation device of the present invention.
[0029] Figure 3 The figure is a schematic diagram of the specific structure of the distributed lock implementation module of the present invention.
[0030] Figure 4A schematic structural diagram of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0031] In order to more clearly understand the content of the present invention, it will be described in detail with reference to the drawings and embodiments.
[0032] However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the present invention. In addition, in the following description, the description of known structures and technologies is omitted to avoid unnecessary confusion of the concept of the present invention. The terms used herein are only for describing specific embodiments and are not intended to limit the present invention. The words "one", "one (kind)" and "the" used herein should also include the meaning of "multiple" and "multiple", unless the context clearly indicates otherwise. In addition, the terms "including", "comprising" and the like used herein indicate the presence of the features, steps, operations and / or parts, but do not exclude the presence or addition of one or more other features, steps, operations or parts.
[0033] All terms (including technical and scientific terms) used herein have the meanings commonly understood by those skilled in the art unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification and should not be interpreted in an idealized or overly rigid manner. The present invention is an improvement of existing patented technology, so the parts not described in this application are implemented with the prior art.
[0034] The main principle of the present invention is to set the parameters and interfaces required to implement various distributed lock methods respectively, have a unified interface to the outside, and call the required distributed lock based on the distributed lock required by the user. Since the implemented distributed locks include relational database (such as MySql) implementation, Redis implementation, Ignite implementation, Zookeeper implementation, Etcd implementation and other methods, different distributed lock implementation methods can be selected according to different application scenarios. Similarly, the optimized distributed locks can also be added to this application to achieve the expansion of distributed lock implementation.
[0035] Figure 1 The first aspect of the present application proposes a unified distributed lock implementation method, which is characterized by comprising:
[0036] S1. Obtain the user's first distributed lock requirement information, wherein the first distributed lock requirement information includes directly specifying the implementation method of the distributed lock or specifying the performance requirement information and consistency requirement information of the distributed lock;
[0037] Furthermore, the first demand information is actively sent by the user, and may include the user directly specifying a distributed lock implementation method, such as Redis, or proposing performance requirement information or consistency requirement information for the distributed lock, and the interface parsing the requirement information, and combining the characteristics of various distributed lock implementation methods to achieve matching. Specifically, methods such as scoring and establishing a relationship library can be used to select a distributed lock implementation method that suits the user's needs.
[0038] Specifically, the distributed lock implementation method is also set by default and then changed based on user demand information. For example, Redis is used by default, but it can be changed to a distributed lock method based on Zookeeper or an implementation method based on Etcd according to user demand information. For distributed lock implementation methods that can be implemented uniformly, a unified statement can be set to call or implement the distributed lock.
[0039] For example, the unified interface of distributed locks provides several methods similar to the following:
[0040] / *Lock resource initialization
[0041] / *Input parameter: type specifies the lock implementation method, such as "redis", "etcd", if not specified, the default implementation method is set* / void init(String type)throws ExecutionException,InterruptedException;
[0042] / *Lock* / public void lock();
[0043] / *Unlock* / public void unlock();
[0044] / *Lock resource release* / void destroy();
[0045] S2. Match the first requirement information of the distributed lock with the existing implementation method of the distributed lock to obtain a first matching result;
[0046] Specifically, if the user requires high performance, the distributed lock implementation methods can be ranked by performance, and then based on the user's other demand information, the overall distributed lock implementation method can be evaluated, and the existing distributed lock implementation method that is more suitable for the user's needs can be selected. The matching results that meet the user's needs can also be calculated by scoring according to the needs.
[0047] S3. Calling a distributed lock implementation method based on the first matching result, wherein the distributed lock implementation method includes a distributed lock implementation method based on a relational database (such as MySql), Redis, Ignite, Zookeeper, Etcd, etc.;
[0048] S4. The distributed lock implementation module implements the distributed lock in response to the call of the first matching result.
[0049] Furthermore, the distributed lock is implemented based on Redis distributed lock, including setting the timeout of the distributed lock, and the timeout includes a locking timeout and an acquisition timeout.
[0050] Furthermore, the method includes: determining whether the time for acquiring the lock exceeds the acquisition timeout period, and if so, giving up acquiring the lock; determining whether the locking time exceeds the locking timeout period, and if so, releasing the lock.
[0051] Furthermore, the method is implemented by using a Redisson development framework.
[0052] Furthermore, the distributed lock is implemented based on the Etcd distributed lock, including setting the unique path name as the Key value and setting the effective time of the distributed lock.
[0053] Furthermore, the method is implemented by using a Jetcd development framework.
[0054] Specifically, the distributed lock implementation method includes a basic distributed lock implementation method and an improved distributed lock implementation method. Different scoring criteria can be used to measure the basic distributed lock implementation method or the improved distributed lock implementation method to achieve a distributed lock implementation method that meets user needs.
[0055] Figure 2 This is a structural block diagram of the unified distributed lock implementation device of the present invention. Figure 3 The figure is a schematic diagram of the specific structure of the distributed lock implementation module of the present invention.
[0056] The second aspect of the present application proposes a unified distributed lock implementation device, which is characterized by comprising:
[0057] A unified interface module, used to obtain the user's first distributed lock requirement information, wherein the first distributed lock requirement information includes directly specifying the implementation method of the distributed lock or specifying the performance requirement information and consistency requirement information of the distributed lock;
[0058] A matching module, used to match the first requirement information of the distributed lock with the existing implementation method of the distributed lock to obtain a first matching result;
[0059] A calling module, used to call the implementation of the distributed lock based on the first matching result, wherein the implementation of the distributed lock includes a distributed lock implementation based on a relational database (such as MySql), Redis, Ignite, Zookeeper, and Etcd;
[0060] The distributed lock implementation module includes a relational database (such as MySql) distributed lock implementation module, a Redis distributed lock implementation module, an Ignite distributed lock implementation module, a Zookeeper distributed lock implementation module, and an Etcd distributed lock implementation module, which are used to implement a distributed lock method corresponding to the first matching result.
[0061] Furthermore, the distributed lock is implemented based on Redis distributed lock, including setting the timeout of the distributed lock, and the timeout includes a locking timeout and an acquisition timeout.
[0062] Furthermore, the method includes: determining whether the time for acquiring the lock exceeds the acquisition timeout period, and if so, giving up acquiring the lock; determining whether the locking time exceeds the locking timeout period, and if so, releasing the lock.
[0063] Furthermore, the method is implemented by using a Redisson development framework.
[0064] Furthermore, the distributed lock is implemented based on the Etcd distributed lock, including setting the unique path name as the Key value and setting the effective time of the distributed lock.
[0065] Furthermore, the method is implemented by using a Jetcd development framework.
[0066] Figure 4 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 4 As shown, the electronic device may include: a transceiver 121 , a processor 122 , and a memory 123 .
[0067] The processor 122 executes the computer execution instructions stored in the memory, so that the processor 122 executes the scheme in the above embodiment. The processor 122 can be a general-purpose processor, including a central processing unit CPU, a network processor (network processor, NP), etc.; it can also be a digital signal processor DSP, an application-specific integrated circuit ASIC, a field programmable gate array FPGA or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.
[0068] The memory 123 is connected to the processor 122 via a system bus and completes communication between them. The memory 123 is used to store computer program instructions.
[0069] The transceiver 121 may be used to obtain the user's first distributed lock requirement information.
[0070] The system bus can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The system bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The transceiver is used to realize the communication between the database access device and other computers (such as clients, read-write libraries, and read-only libraries). The memory may include random access memory (RAM) and may also include non-volatile memory.
[0071] The electronic device provided in the embodiment of the present application may be the terminal device of the above embodiment.
[0072] An embodiment of the present application also provides a chip for executing instructions, which is used to execute the technical solution of the method for implementing the unified distributed lock in the above embodiment.
[0073] An embodiment of the present application further provides a computer-readable storage medium, in which computer instructions are stored. When the computer instructions are executed on a computer, the computer executes the technical solution of the method for implementing the unified distributed lock in the above embodiment.
[0074] An embodiment of the present application also provides a computer program product, which includes a computer program stored in a computer-readable storage medium. At least one processor can read the computer program from the computer-readable storage medium. When at least one processor executes the computer program, the technical solution of the above-mentioned unified distributed lock implementation method can be implemented.
[0075] The beneficial effects of the present invention are: building distributed locks as unified enterprise-level services, providing a consistent access interface to the outside world, and providing multiple distributed lock mechanism implementations on the back end, and achieving high availability. Consumers can specify the implementation method of distributed locks according to the characteristics of the business scenario; or only specify performance and consistency requirements, and the distributed lock service automatically routes to the corresponding distributed lock cluster, providing a distributed lock implementation solution that meets the requirements of the consumer, and meeting different requirements for performance and consistency in different business scenarios; in addition, by building an enterprise-level distributed lock service, consumers only need to use distributed locks through APIs, which lowers the threshold for applications to use distributed locks and also improves resource utilization efficiency.
[0076] It is worth noting that the data collection and migration activities involved in this application have been agreed by the user and are necessary for the applicant to carry out normal business activities. The applicant has performed desensitization processing such as anonymization and confidentiality on the collected data, and has set up data access rights accordingly to ensure that the user's privacy is not leaked. The data compliance measures involved in this application are only listed, and the applicant has also set up other relevant data compliance measures. The data processing activities carried out by the applicant comply with the provisions of laws and regulations such as the Data Security Law and the Personal Information Protection Law.
[0077] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.
[0078] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.
[0079] Those skilled in the art may further realize that the algorithm steps in combination with the embodiments of this document may be implemented in the form of electronic hardware, computer software, or a combination of the two, and whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art may use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present invention.
[0080] Although the preferred embodiments of the present invention have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the present invention.
[0081] The above is only a preferred specific embodiment of the present invention, but the protection scope of the present invention is not limited thereto. Any changes or substitutions that can be easily thought of by a person skilled in the art within the technical scope disclosed by the present invention should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention should be based on the protection scope of the claims.
Claims
1. A unified distributed lock implementation method, characterized in that: include: S1. Obtain the user's first distributed lock requirement information, wherein the first distributed lock requirement information includes directly specifying the implementation method of the distributed lock or specifying the performance requirement information and consistency requirement information of the distributed lock; S2. Match the first requirement information of the distributed lock with the existing implementation method of the distributed lock to obtain a first matching result; S3. Calling a distributed lock implementation method based on the first matching result, wherein the distributed lock implementation method includes a distributed lock implementation method based on a relational database, Redis, Ignite, Zookeeper, Etcd, etc.; S4. The distributed lock implementation module implements the distributed lock in response to the call of the first matching result.
2. The method according to claim 1, characterized in that The implementation method of the distributed lock is based on Redis distributed lock implementation, including setting the timeout time of the distributed lock, and the timeout time includes the locking timeout time and the acquisition timeout time.
3. The method according to claim 2, characterized in that The method comprises: judging whether the time of acquiring the lock exceeds the acquisition timeout time, and if so, giving up acquiring the lock; judging whether the locking time exceeds the locking timeout time, and if so, releasing the lock.
4. The method according to claim 3, characterized in that The method is implemented by using a Redisson development framework.
5. The method according to claim 1, characterized in that The distributed lock is implemented based on the Etcd distributed lock, including setting the unique path name as the Key value and setting the effective time of the distributed lock.
6. The method according to claim 5, characterized in that The method is implemented by using the Jetcd development framework.
7. A unified distributed lock implementation device, characterized in that: include: A unified interface module, used to obtain the user's first distributed lock requirement information, wherein the first distributed lock requirement information includes directly specifying the implementation method of the distributed lock or specifying the performance requirement information and consistency requirement information of the distributed lock; A matching module, used to match the first requirement information of the distributed lock with the existing implementation method of the distributed lock to obtain a first matching result; A calling module, used to call the implementation of the distributed lock based on the first matching result, wherein the implementation of the distributed lock includes a distributed lock implementation based on a relational database, Redis, Ignite, Zookeeper, and Etcd; The distributed lock implementation module includes a relational database distributed lock implementation module, a Redis distributed lock implementation module, an Ignite distributed lock implementation module, a Zookeeper distributed lock implementation module, and an Etcd distributed lock implementation module, which are used to implement a distributed lock method corresponding to the first matching result.
8. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 6 when executed by a processor.
10. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 6 when being executed by a processor.
