CN111258976A - Distributed lock implementation method, system, device and storage medium - Google Patents

Distributed lock implementation method, system, device and storage medium Download PDF

Info

Publication number
CN111258976A
CN111258976A CN201811468636.3A CN201811468636A CN111258976A CN 111258976 A CN111258976 A CN 111258976A CN 201811468636 A CN201811468636 A CN 201811468636A CN 111258976 A CN111258976 A CN 111258976A
Authority
CN
China
Prior art keywords
lock
target
distributed
state information
requester
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
CN201811468636.3A
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.)
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Jingdong Shangke Information Technology Co 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 Beijing Jingdong Century Trading Co Ltd, Beijing Jingdong Shangke Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN201811468636.3A priority Critical patent/CN111258976A/en
Publication of CN111258976A publication Critical patent/CN111258976A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention provides a method, a system, equipment and a storage medium for realizing a distributed lock, wherein the method comprises the following steps: creating a plurality of lock files, and respectively storing each lock file to each target path of the distributed file system, wherein each lock file comprises lock state information; receiving a lock application request, and writing requester information into lock state information corresponding to a target lock of the request, wherein the lock application request comprises the requester information; judging whether the lock state information of the target lock is consistent with the requester information; if the target lock is consistent with the target lock, the requester is determined to be successful in acquiring the target lock; if not, it is determined that the requester fails to acquire the target lock. The invention realizes simple and efficient distributed lock in big data scene through the distributed file system, thereby realizing mutual exclusion operation on shared resources in multiple concurrent scenes; meanwhile, the invention does not need to introduce other storage or service, thereby reducing the complexity of the system and reducing the development cost.

Description

Distributed lock implementation method, system, device and storage medium
Technical Field
The invention relates to the field of logistics, in particular to a distributed lock implementation method, a system, equipment and a storage medium based on an HDFS file system.
Background
With the advent of the big data era, a hadoop framework becomes a basic framework of the big data field, and big data processing by using hadoop becomes very convenient and popular. The Hadoop mainly comprises a computing module MapReduce and a Distributed File storage module (HDFS), and File storage using the HDFS is a very mature and general technology, but the mutually exclusive access to shared resources still has a problem in a big data scene. Meanwhile, in the internet environment, almost all large websites and applications are deployed in a distributed manner, and the problem of data consistency in a distributed scene is always an important topic. The distributed CAP theory tells us that "any one distributed system cannot satisfy Consistency (Consistency), Availability (Availability) and Partition tolerance (Partition tolerance) at the same time, and at most, can satisfy both items at the same time. So, many systems have to make a trade-off for these three at the beginning of the design. In most scenarios in the field of big data and internet, strong consistency needs to be sacrificed in exchange for high availability of the system, and the system often only needs to ensure "final consistency" as long as the final time is within an acceptable range for users. In a distributed system, the mutual exclusion access problem of shared resources is very common, and a common solution to the mutual exclusion problem of accessing shared resources is to use a distributed lock.
In many scenarios, to ensure the final consistency of data, many technical solutions are required to support, such as distributed transactions, distributed locks, and the like. It is sometimes necessary to ensure that a method can only be executed by the same thread at the same time. In a single machine environment, Java actually provides a plurality of APIs related to concurrent processing, but the APIs cannot be used in a distributed scene, namely a pure Java API cannot provide the capability of distributed locking. There are currently a number of solutions for the implementation of distributed locks. For the implementation of distributed locks, the following schemes are currently used: the distributed lock is realized based on a database (mysql), the distributed lock is realized based on a cache (redis, memcached, tair), and the distributed lock is realized based on a Zookeeper.
The most simple way to implement the distributed lock is to directly create a lock table and then implement the lock by operating the data in the table. When a method or resource is to be locked, a record is added to the table and deleted when the lock is to be released.
A database table methodLock is created containing 4 fields: id (primary key), method _ name (locked method name), desc (remark information), and update _ time (update time). When a method is desired to be locked, the following SQL is executed:
insert into methodLock(method_name,desc)values(‘method_name’,‘desc’)
because of the uniqueness constraint on the method _ name, if multiple requests are submitted to the database at the same time, the database will ensure that only one operation can be successful, and then the thread that the operation is successful can be considered to obtain the lock of the method, and the method body content can be executed. When the method is executed and the lock is released, the following Sq is executed:
delete from methodLock where method_name='method_name'
the simple implementation of distributed locks based on database tables has several problems:
a. the lock strongly depends on the availability of the database, the database is a single point, and once the database is hung, the business system can be unavailable;
b. this makes the lock only non-blocking because the insert operation of data will report an error directly in case of an insertion failure. Threads which do not acquire the lock do not enter the queue, and the lock acquiring operation is triggered again to acquire the lock again;
c. this makes the lock non-reentrant, and the same thread cannot acquire the lock again until the lock is not released because the data already exists in the data.
Compared with a scheme of realizing distributed locks based on a database, the method has the advantages that the performance is better realized based on the cache, and a plurality of caches can be deployed in a cluster, so that the single-point problem can be solved. There are many mature caching products including Redis, memcached. The cache lock has the advantages of high performance, convenient realization, no influence on the normal use of the system under the condition of allowing accidental lock failure, and the adoption of the cache lock is suggested; the disadvantage is that the lock timeout mechanism is not very reliable, and when the thread acquires the lock, the lock timeout is caused by too long processing time, and the lock function is disabled.
The distributed lock based on the zookeeper temporary ordered node can be realized by the following general idea: when each client locks a certain method, a unique instant ordered node is generated under the directory of the appointed node corresponding to the method on the zookeeper. The mode of judging whether to acquire the lock is simple, only the smallest serial number in the ordered nodes needs to be judged, and when the lock is released, only the instant node needs to be deleted. Meanwhile, the deadlock problem caused by the fact that the lock cannot be released due to service downtime can be avoided. The disadvantage of this approach is that it does not perform as well as implementing distributed locks using caches; the method has the advantages that the lock is released without depending on overtime, the reliability is high, and a zookeeper lock is suggested to be adopted when the system requires high reliability; the disadvantage is that the performance is inferior to the cache lock because nodes are created and deleted frequently.
In a big data scene, a new storage or service framework needs to be introduced into a system to realize distributed locks by using a database (mysql), a cache (redis), a zookeeper and the like, so that the defects that the complexity of the system is increased and corresponding resources need to be applied additionally exist.
It is to be noted that the information disclosed in the above background section is only for enhancement of understanding of the background of the present invention and therefore may include information that does not constitute prior art known to a person of ordinary skill in the art.
Disclosure of Invention
Aiming at the problems in the prior art, the distributed lock is realized through the HDFS, and the method does not need to introduce new storage or service in a big data environment, thereby reducing the complexity of the system, simultaneously not needing to apply for extra resources and reducing the cost.
The embodiment of the invention provides a distributed lock implementation method, which comprises the following steps:
creating a plurality of lock files, and respectively storing each lock file to each target path of a distributed file system, wherein each lock file comprises lock state information;
receiving a lock application request, and writing requester information into lock state information corresponding to a target lock of the request, wherein the lock application request comprises the requester information;
judging whether the lock state information of the target lock is consistent with the requester information;
if the target lock is consistent with the target lock, determining that the requester successfully acquires the target lock;
if not, it is determined that the requester fails to acquire the target lock.
Preferably, each lock file further includes lock identification information, and the lock application request further includes the lock identification information of the target lock;
the writing of the requester information into the lock state information corresponding to the requested target lock includes the following steps:
determining a target path of the target lock according to the lock identification information of the target lock in the lock application request, and judging whether a value of lock state information stored under the target path is an initial value;
and if the lock state information is an initial value, writing the requester information into the lock state information in the corresponding target lock file.
Preferably, after determining whether the value of the lock state information stored in the target path is an initial value, the method further includes the following steps:
if the lock state information is an initial value, the requester information is written into the lock state information in the corresponding lock file, and then the lock state information of the target lock is obtained from a target path;
and if the lock state information is not an initial value, directly acquiring the lock state information of the target lock from a target path.
Preferably, the distributed file system comprises an HDFS distributed system, each of the lock files using a separate HDFS target path.
Preferably, the lock identification information further includes a set time-to-failure threshold.
Preferably, after the target lock is successfully acquired, the method further comprises the following steps:
starting a timer, and calculating the difference between the current time and the acquisition time of the target lock at intervals of specific time;
judging whether the obtained difference is larger than the set failure time threshold value or not;
if so, releasing the target lock and setting the lock state information as an initial value.
Preferably, after confirming that the requester successfully acquires the target lock, the method further includes the following steps:
and when a lock release request is received, releasing the target lock and setting the lock state information as an initial value.
Preferably, the requester information includes an IP in which the requester program operates, a process ID, a thread ID, and an application time.
The embodiment of the present invention further provides a distributed lock implementation system, including a construction unit, a user unit, a writing unit, and a determination unit, where:
the building unit is used for creating a plurality of lock files;
the user unit is used for receiving a lock application request;
the writing unit is used for writing the requester information into the lock state information corresponding to the target lock of the request;
the judging unit is used for comparing the lock state information of the target lock with the requester information and determining whether the requester acquires the target lock successfully according to a comparison result.
Preferably, the distributed lock implementation system further includes a timing unit, configured to start a timer after the determining unit determines that the requester successfully acquires the target lock, and calculate a difference between the current time and the acquisition time of the target lock at a specific time interval.
Preferably, the determining unit is further configured to determine whether a difference obtained by subtracting the current time from the acquisition time of the distributed lock every certain time interval by the timing unit is greater than a set expiration time threshold;
the user unit is further configured to release the target lock and set the lock state information to an initial state when the determining unit determines that the difference is greater than the set expiration time threshold.
The embodiment of the present invention further provides a distributed lock implementation device, which is characterized by including:
a processor;
a memory having stored therein executable instructions of the processor;
wherein the processor is configured to perform the steps of the distributed lock implementation method via execution of the executable instructions.
An embodiment of the present invention also provides a computer-readable storage medium storing a program, wherein the program, when executed, implements the steps of the distributed lock implementation method.
The method realizes simple and efficient distributed locks under a big data scene through the distributed system, and can realize mutual exclusion operation on shared resources under multiple concurrent scenes by performing operations such as lock creation, lock competition, lock acquisition, lock release, lock timeout and the like on the distributed system, particularly lock files on the HDFS. Meanwhile, the method only uses the distributed system and does not introduce other storage or service, so that the realization of the distributed lock is very simple, the complexity of the system is reduced, and the dependence on external resources is reduced. Under the condition that resources are not changed in a big data platform, the method provided by the invention is used for sharing the resources, thereby reducing the development cost and improving the efficiency.
Drawings
Other features, objects, and advantages of the invention will be apparent from the following detailed description of non-limiting embodiments, which proceeds with reference to the accompanying drawings and which is incorporated in and constitutes a part of this specification, illustrating embodiments consistent with the present application and together with the description serve to explain the principles of the application. It is obvious that the drawings in the following description are only some embodiments of the invention, and that for a person skilled in the art, other drawings can be derived from them without inventive effort.
FIG. 1 is a flow diagram of a distributed lock implementation method according to an embodiment of the invention;
FIG. 2 is a diagram of a distributed lock implementation system according to an embodiment of the present invention;
FIG. 3 is a schematic structural diagram of a distributed lock implementation apparatus according to an embodiment of the present invention;
fig. 4 is a schematic structural diagram of a computer-readable storage medium according to an embodiment of the present invention.
Detailed Description
Example embodiments will now be described more fully with reference to the accompanying drawings. Example embodiments may, however, be embodied in many different forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the concept of example embodiments to those skilled in the art. The described features, structures, or characteristics may be combined in any suitable manner in one or more embodiments.
Furthermore, the drawings are merely schematic illustrations of the present disclosure and are not necessarily drawn to scale. The same reference numerals in the drawings denote the same or similar parts, and thus their repetitive description will be omitted. Some of the block diagrams shown in the figures are functional entities and do not necessarily correspond to physically or logically separate entities. These functional entities may be implemented in the form of software, or in one or more hardware modules or integrated circuits, or in different networks and/or processor devices and/or microcontroller devices.
Fig. 1 is a flowchart of a distributed lock implementation method according to an embodiment of the present invention, where the method specifically includes the following steps:
first, S100, creating a plurality of lock files, and storing each of the lock files to each target path of the distributed file system, where each of the lock files includes lock state information. The distributed file system comprises an HDFS distributed system, and each lock file uses an independent HDFS target path, so that distributed locks are independent and do not influence each other.
An HDFS distributed system is a distributed file system designed to fit on common hardware. It has many similarities with existing distributed file systems. But at the same time, its distinction from other distributed file systems is also clear. HDFS is a highly fault tolerant system suitable for deployment on inexpensive machines; the HDFS can provide data access with high throughput, and is very suitable for application on a large-scale data set; HDFS relaxes a portion of the POSIX constraints to achieve the goal of streaming file system data. HDFS was originally developed as an infrastructure for the Apache Nutch search engine project. HDFS is part of the Apache Hadoop Core project. HDFS is characterized by high fault tolerance and is designed to be deployed on inexpensive hardware. And it provides high throughput access to application data, suitable for applications with very large data sets. HDFS relaxes the POSIX requirements so that access to data in a file system in the form of streams can be achieved.
Executing S200, receiving a lock application request, and writing requester information into lock state information corresponding to a target lock of the request, wherein the lock application request comprises the requester information; in one embodiment, the requester information may include the IP at which the requester program runs, a process ID, a thread ID, and an application time. The application of the invention does not have a mode of acquiring corresponding script generation information through a service request.
In an embodiment, each lock file further includes lock identification information, the lock application request further includes lock identification information of a target lock, and the step of writing the requester information into the lock state information corresponding to the requested target lock includes:
determining a target path of the target lock according to the lock identification information of the target lock in the lock application request, and judging whether a value of the lock state information stored under the target path is an initial value, wherein the initial value can be set to be any value, and the initial value is not any requester information;
if the lock state information is an initial value, which indicates that the target lock in the lock application request is in an unoccupied state, the requester information is written into the corresponding lock state information in the target lock file, i.e., the lock state information is changed from the initial value to the requester information, which indicates that the target lock in the lock application request is already occupied by the requester. The method of the present invention does not need to use a queue to store the lock application request, and the prior requester can occupy the target lock as long as the target lock in the lock application request is in an unoccupied state.
In the embodiment, whether the value of the lock state information stored in the target path is an initial value is judged, if the lock state information is the initial value, the lock state information of the target lock is acquired from the target path after the requester information is written into the lock state information in the corresponding lock file; but if the lock state information is not the initial value, the lock state information of the target lock is directly acquired from the target path.
Then executing S300, judging whether the lock state information of the target lock is consistent with the requester information,
if so, S400, it is determined that the requester successfully acquires the target lock and the requester may take the target lock and operate the required shared resource. After the requester completes the operation, the requester can send a release request, and when the system receives the lock release request, the system releases the target lock and sets the lock state information as an initial value.
If not, S500, the requester is determined to fail to acquire the target lock, and the system waits for the next lock application request.
In general, to allocate resources properly, the system will set the time each requester can acquire the target lock, which in our embodiment is accomplished by:
the lock identification information also comprises a set failure time threshold, after the target lock is successfully acquired, the system starts a timer, calculates the difference value between the current time and the acquisition time of the target lock at a specific time interval, the difference value actually represents the time for the requester to occupy the target lock, judges whether the obtained difference value is greater than the set failure time threshold, and releases the target lock when the difference value, namely the time for occupying the target lock is greater than the set failure time threshold, and sets the lock state information as an initial value. This step is a process of forcibly releasing the lock.
Fig. 2 is a schematic diagram of a distributed lock implementation system according to an embodiment of the present invention, where the system includes a construction unit 1, a user unit 2, a writing unit 3, and a determination unit 4, where:
the building unit 1 is used for creating a plurality of lock files;
the user unit 2 is used for receiving a lock application request;
the write-in unit 3 is used for writing the requester information into the lock state information corresponding to the target lock of the request;
the judging unit 4 is configured to compare the lock state information of the target lock with the requester information, and determine whether the requester acquires the target lock successfully according to a comparison result.
In an embodiment, the distributed lock implementation system further includes a timing unit, configured to start a timer after the determining unit determines that the requester successfully acquires the target lock, and calculate a difference between the current time and the acquisition time of the target lock at a specific interval. The judging unit 4 is further configured to judge whether a difference obtained by subtracting the current time from the acquisition time of the distributed lock every certain time interval by the timing unit 1 is greater than a set expiration time threshold; the user unit 2 is further configured to release the target lock and set the lock state information to the initial state when the determining unit 4 determines that the difference is greater than the set expiration time threshold.
An electronic device 600 according to this embodiment of the invention is described below with reference to fig. 3. The electronic device 600 shown in fig. 4 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present invention.
As shown in fig. 3, the electronic device 600 is embodied in the form of a general purpose computing device. The components of the electronic device 600 may include, but are not limited to: at least one processing unit 610, at least one memory unit 620, a bus 630 connecting the different platform components (including the memory unit 620 and the processing unit 610), a display unit 640, etc.
Wherein the storage unit stores program code executable by the processing unit 610 to cause the processing unit 610 to perform steps according to various exemplary embodiments of the present invention described in the above-mentioned electronic prescription flow processing method section of the present specification. For example, processing unit 610 may perform the steps as shown in fig. 1.
The storage unit 620 may include readable media in the form of volatile memory units, such as a random access memory unit (RAM)6201 and/or a cache memory unit 6202, and may further include a read-only memory unit (ROM) 6203.
The memory unit 620 may also include a program/utility 6204 having a set (at least one) of program modules 6205, such program modules 6205 including, but not limited to: an operating system, one or more application programs, other program modules, and program data, each of which, or some combination thereof, may comprise an implementation of a network environment.
Bus 630 may be one or more of several types of bus structures, including a memory unit bus or memory unit controller, a peripheral bus, an accelerated graphics port, a processing unit, or a local bus using any of a variety of bus architectures.
The electronic device 600 may also communicate with one or more external devices 700 (e.g., keyboard, pointing device, bluetooth device, etc.), with one or more devices that enable a user to interact with the electronic device 600, and/or with any devices (e.g., router, modem, etc.) that enable the electronic device 600 to communicate with one or more other computing devices. Such communication may occur via an input/output (I/O) interface 650. Also, the electronic device 600 may communicate with one or more networks (e.g., a Local Area Network (LAN), a Wide Area Network (WAN), and/or a public network such as the Internet) via the network adapter 660. The network adapter 660 may communicate with other modules of the electronic device 600 via the bus 630. It should be appreciated that although not shown in the figures, other hardware and/or software modules may be used in conjunction with the electronic device 600, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage platforms, to name a few.
The embodiment of the invention also provides a computer readable storage medium for storing a program, wherein the program is executed to realize the steps of the method for realizing the distributed lock based on the HDFS in the sorting process. In some possible embodiments, the aspects of the present invention may also be implemented in the form of a program product comprising program code for causing a terminal device to perform the steps according to various exemplary embodiments of the present invention described in the above-mentioned electronic prescription flow processing method section of this specification, when the program product is run on the terminal device.
Referring to fig. 4, a program product 800 for implementing the above method according to an embodiment of the present invention is described, which may employ a portable compact disc read only memory (CD-ROM) and include program code, and may be run on a terminal device, such as a personal computer. However, the program product of the present invention is not limited in this regard and, in the present document, a readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, for example, but not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable disk, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
A computer readable storage medium may include a propagated data signal with readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take many forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A readable storage medium may also be any readable medium that is not a readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device. Program code embodied on a readable storage medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, as a stand-alone software package, partly on the user's computing device and partly on a remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device through any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., through the internet using an internet service provider).
In summary, the present invention provides a method, a system, a device and a storage medium for implementing a distributed lock, wherein the method includes the following steps: creating a plurality of lock files, and respectively storing each lock file to each target path of the distributed file system, wherein each lock file comprises lock state information; receiving a lock application request, and writing requester information into lock state information corresponding to a target lock of the request, wherein the lock application request comprises the requester information; judging whether the lock state information of the target lock is consistent with the requester information; if the target lock is consistent with the target lock, the requester is determined to be successful in acquiring the target lock; if not, it is determined that the requester fails to acquire the target lock. The invention realizes simple and efficient distributed lock in big data scene through the distributed system, and can realize mutual exclusion operation of shared resources in multi-concurrency scene by performing operations such as lock creation, lock competition, lock acquisition, lock release, lock overtime and the like on the distributed system, especially lock files on the HDFS. Meanwhile, the invention only uses the distributed system and does not introduce other storage or service, so that the realization of the distributed lock is very simple, the complexity of the system is reduced, and the dependence on external resources is reduced. Under the condition that resources are not changed in a big data platform, the method provided by the invention is used for sharing the resources, thereby reducing the development cost and improving the efficiency.
The foregoing is a more detailed description of the invention in connection with specific preferred embodiments and it is not intended that the invention be limited to these specific details. It will be evident to those skilled in the art that the present application is not limited to the details of the foregoing illustrative embodiments, and that the present application may be embodied in other specific forms without departing from the spirit or essential attributes thereof. The present embodiments are therefore to be considered in all respects as illustrative and not restrictive, the scope of the application being indicated by the appended claims rather than by the foregoing description, and all changes which come within the meaning and range of equivalency of the claims are therefore intended to be embraced therein. Any reference sign in a claim should not be construed as limiting the claim concerned. Furthermore, it is obvious that the word "comprising" does not exclude other elements or steps, and the singular does not exclude the plural. A plurality of units or means recited in the apparatus claims may also be implemented by one unit or means in software or hardware. The terms first, second, etc. are used to denote names, but not any particular order.

Claims (13)

1. A distributed lock implementation method is characterized by comprising the following steps:
creating a plurality of lock files, and respectively storing each lock file to each target path of a distributed file system, wherein each lock file comprises lock state information;
receiving a lock application request, and writing requester information into lock state information corresponding to a target lock of the request, wherein the lock application request comprises the requester information;
judging whether the lock state information of the target lock is consistent with the requester information;
if the target lock is consistent with the target lock, determining that the requester successfully acquires the target lock;
if not, it is determined that the requester fails to acquire the target lock.
2. The distributed lock implementation method of claim 1, wherein each of the lock files further includes lock identification information, and the lock application request further includes the lock identification information of a target lock;
the writing of the requester information into the lock state information corresponding to the requested target lock includes the following steps:
determining a target path of the target lock according to the lock identification information of the target lock in the lock application request, and judging whether a value of lock state information stored under the target path is an initial value;
and if the lock state information is an initial value, writing the requester information into the lock state information in the corresponding target lock file.
3. The distributed lock implementation method according to claim 2, wherein after determining whether the value of the lock state information stored in the target path is an initial value, the method further includes the following steps:
if the lock state information is an initial value, the requester information is written into the lock state information in the corresponding lock file, and then the lock state information of the target lock is obtained from a target path;
and if the lock state information is not an initial value, directly acquiring the lock state information of the target lock from a target path.
4. The distributed lock implementation method of claim 1, wherein the distributed file system comprises an HDFS distributed system, and wherein each of the lock files uses a separate HDFS target path.
5. The distributed lock implementation method of claim 2, wherein the lock identification information further comprises a set time-to-failure threshold.
6. The distributed lock implementation method of claim 5, further comprising the following steps after the target lock is successfully acquired:
starting a timer, and calculating the difference between the current time and the acquisition time of the target lock at intervals of specific time;
judging whether the obtained difference is larger than the set failure time threshold value or not;
if so, releasing the target lock and setting the lock state information as an initial value.
7. The distributed lock implementation method of claim 1, wherein after confirming that the requester successfully acquires the target lock, the method further comprises the following steps:
and when a lock release request is received, releasing the target lock and setting the lock state information as an initial value.
8. The distributed lock implementation method of claim 1, wherein the requester information comprises an IP at which the requester program runs, a process ID, a thread ID, and an application time.
9. The utility model provides a distributed lock implementation system which characterized in that, includes that construction element, user element, write in unit and judgement unit, wherein:
the building unit is used for creating a plurality of lock files;
the user unit is used for receiving a lock application request;
the writing unit is used for writing the requester information into the lock state information corresponding to the target lock of the request;
the judging unit is used for comparing the lock state information of the target lock with the requester information and determining whether the requester acquires the target lock successfully according to a comparison result.
10. The distributed lock implementation system according to claim 9, further comprising a timing unit, configured to start a timer after the determining unit determines that the requester successfully acquires the target lock, and calculate a difference between a current time and an acquisition time of the target lock at a specific time interval.
11. The distributed lock implementation system of claim 10, wherein:
the judging unit is also used for judging whether a difference value obtained by subtracting the current time from the acquisition time of the distributed lock at a specific time interval by the timing unit is greater than a set failure time threshold value or not;
the user unit is further configured to release the target lock and set the lock state information to an initial state when the determining unit determines that the difference is greater than the set expiration time threshold.
12. A distributed lock implementation device, comprising:
a processor;
a memory having stored therein executable instructions of the processor;
wherein the processor is configured to perform the steps of the distributed lock implementation method of any one of claims 1 to 8 via execution of the executable instructions.
13. A computer readable storage medium storing a program which when executed performs the steps of the distributed lock implementation method of any one of claims 1 to 8.
CN201811468636.3A 2018-12-03 2018-12-03 Distributed lock implementation method, system, device and storage medium Pending CN111258976A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811468636.3A CN111258976A (en) 2018-12-03 2018-12-03 Distributed lock implementation method, system, device and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811468636.3A CN111258976A (en) 2018-12-03 2018-12-03 Distributed lock implementation method, system, device and storage medium

Publications (1)

Publication Number Publication Date
CN111258976A true CN111258976A (en) 2020-06-09

Family

ID=70953803

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811468636.3A Pending CN111258976A (en) 2018-12-03 2018-12-03 Distributed lock implementation method, system, device and storage medium

Country Status (1)

Country Link
CN (1) CN111258976A (en)

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111858079A (en) * 2020-07-27 2020-10-30 北京达佳互联信息技术有限公司 Distributed lock migration method and device, electronic equipment and storage medium
CN112380000A (en) * 2020-10-23 2021-02-19 成都佰维存储科技有限公司 Serial port sharing method and device, readable storage medium and electronic equipment
CN112486694A (en) * 2020-11-30 2021-03-12 山东浪潮通软信息科技有限公司 Network lock processing method and device based on Redis
CN112486696A (en) * 2020-12-11 2021-03-12 上海悦易网络信息技术有限公司 Method and equipment for acquiring distributed lock
CN112565467A (en) * 2021-02-22 2021-03-26 常州微亿智造科技有限公司 Service processing method, device and storage medium
CN113535762A (en) * 2021-07-14 2021-10-22 北京数码视讯支付技术有限公司 Secure account payment substitution method and device
CN113556933A (en) * 2021-07-19 2021-10-26 英华达(上海)科技有限公司 Intelligent feeding system, method, equipment and storage medium
CN113806031A (en) * 2020-09-28 2021-12-17 京东科技控股股份有限公司 Method and apparatus for securing resources through object locks
CN114327691A (en) * 2021-12-10 2022-04-12 北京五八信息技术有限公司 Application program processing method, device, equipment and storage medium
CN115878696A (en) * 2023-03-06 2023-03-31 中国西安卫星测控中心 High-availability method and device for distributed data processing cluster

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102156928A (en) * 2011-04-29 2011-08-17 浪潮通信信息系统有限公司 Method for system concurrency control through business logic lock
US9171019B1 (en) * 2013-02-19 2015-10-27 Amazon Technologies, Inc. Distributed lock service with external lock information database
CN107656815A (en) * 2016-07-26 2018-02-02 北京京东尚科信息技术有限公司 Method and apparatus for controlling distributed lock
CN108089926A (en) * 2018-01-08 2018-05-29 马上消费金融股份有限公司 Method, device and equipment for acquiring distributed lock and readable storage medium
CN108874552A (en) * 2018-06-28 2018-11-23 杭州云英网络科技有限公司 Distributed lock executes method, apparatus and system, application server and storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN102156928A (en) * 2011-04-29 2011-08-17 浪潮通信信息系统有限公司 Method for system concurrency control through business logic lock
US9171019B1 (en) * 2013-02-19 2015-10-27 Amazon Technologies, Inc. Distributed lock service with external lock information database
CN107656815A (en) * 2016-07-26 2018-02-02 北京京东尚科信息技术有限公司 Method and apparatus for controlling distributed lock
CN108089926A (en) * 2018-01-08 2018-05-29 马上消费金融股份有限公司 Method, device and equipment for acquiring distributed lock and readable storage medium
CN108874552A (en) * 2018-06-28 2018-11-23 杭州云英网络科技有限公司 Distributed lock executes method, apparatus and system, application server and storage medium

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
周梅;: "分布式锁的设计与实现", 计算机工程, no. 16 *

Cited By (14)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111858079A (en) * 2020-07-27 2020-10-30 北京达佳互联信息技术有限公司 Distributed lock migration method and device, electronic equipment and storage medium
CN111858079B (en) * 2020-07-27 2024-03-12 北京达佳互联信息技术有限公司 Distributed lock migration method and device, electronic equipment and storage medium
CN113806031A (en) * 2020-09-28 2021-12-17 京东科技控股股份有限公司 Method and apparatus for securing resources through object locks
CN112380000A (en) * 2020-10-23 2021-02-19 成都佰维存储科技有限公司 Serial port sharing method and device, readable storage medium and electronic equipment
CN112486694B (en) * 2020-11-30 2023-07-25 浪潮通用软件有限公司 Redis-based network lock processing method and device
CN112486694A (en) * 2020-11-30 2021-03-12 山东浪潮通软信息科技有限公司 Network lock processing method and device based on Redis
CN112486696A (en) * 2020-12-11 2021-03-12 上海悦易网络信息技术有限公司 Method and equipment for acquiring distributed lock
CN112565467A (en) * 2021-02-22 2021-03-26 常州微亿智造科技有限公司 Service processing method, device and storage medium
CN113535762A (en) * 2021-07-14 2021-10-22 北京数码视讯支付技术有限公司 Secure account payment substitution method and device
CN113535762B (en) * 2021-07-14 2024-01-26 北京数码视讯支付技术有限公司 Secure account payment method and device
CN113556933A (en) * 2021-07-19 2021-10-26 英华达(上海)科技有限公司 Intelligent feeding system, method, equipment and storage medium
CN114327691A (en) * 2021-12-10 2022-04-12 北京五八信息技术有限公司 Application program processing method, device, equipment and storage medium
CN115878696B (en) * 2023-03-06 2023-04-28 中国西安卫星测控中心 High availability method and device for distributed data processing cluster
CN115878696A (en) * 2023-03-06 2023-03-31 中国西安卫星测控中心 High-availability method and device for distributed data processing cluster

Similar Documents

Publication Publication Date Title
CN111258976A (en) Distributed lock implementation method, system, device and storage medium
US9563673B2 (en) Query method for a distributed database system and query apparatus
US8495618B1 (en) Updating firmware in a high availability enabled computer system
EP2738698B1 (en) Locking protocol for partitioned and distributed tables
CN109491801B (en) Micro-service access scheduling method, micro-service access scheduling device, medium and electronic equipment
CN107710155B (en) System and method for booting application servers in parallel
CN104065636B (en) Data processing method and system
US9553951B1 (en) Semaphores in distributed computing environments
US20190042149A1 (en) Writing composite objects to a data store
CN106802939B (en) Method and system for solving data conflict
KR20160147909A (en) System and method for supporting common transaction identifier (xid) optimization and transaction affinity based on resource manager (rm) instance awareness in a transactional environment
CN113076304A (en) Distributed version management method, device and system
CN108139927B (en) Action-based routing of transactions in an online transaction processing system
CN112148695A (en) Resource lock management method and device
CN111722933A (en) Deadlock resolution between distributed processes
CN110633046A (en) Storage method and device of distributed system, storage equipment and storage medium
CN112579307A (en) Physical lock resource allocation detection method and device and electronic equipment
CN111818188B (en) Load balancing availability improving method and device for Kubernetes cluster
US10169441B2 (en) Synchronous data replication in a content management system
CN107967265B (en) File access method, data server and file access system
CN116974983A (en) Data processing method, device, computer readable medium and electronic equipment
US11327785B2 (en) Computing system including enhanced application performance based on last completed operation sequence value
US10310921B2 (en) Computing system including PLSO command to maintain equivalency between independent coupling facilities
CN118140213A (en) Lock controller and method for realizing buffer lock through remote direct memory access
JP2020184365A (en) System and method for booting application servers in parallel

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