CN111026807A - Distributed lock synchronization method and device, computer equipment and readable storage medium - Google Patents

Distributed lock synchronization method and device, computer equipment and readable storage medium Download PDF

Info

Publication number
CN111026807A
CN111026807A CN201911165392.6A CN201911165392A CN111026807A CN 111026807 A CN111026807 A CN 111026807A CN 201911165392 A CN201911165392 A CN 201911165392A CN 111026807 A CN111026807 A CN 111026807A
Authority
CN
China
Prior art keywords
distributed lock
distributed
lock
expired
expiration time
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
CN201911165392.6A
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.)
OneConnect Smart Technology Co Ltd
OneConnect Financial Technology Co Ltd Shanghai
Original Assignee
OneConnect Financial Technology Co Ltd Shanghai
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 OneConnect Financial Technology Co Ltd Shanghai filed Critical OneConnect Financial Technology Co Ltd Shanghai
Priority to CN201911165392.6A priority Critical patent/CN111026807A/en
Publication of CN111026807A publication Critical patent/CN111026807A/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/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • 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
    • G06F16/275Synchronous replication

Abstract

The invention provides a synchronization method of a distributed lock, which can improve data security and save hardware cost, and comprises the following steps: after a slave node of a master-slave framework is switched to a new master node, responding to a triggered synchronization task, and acquiring the expiration time of each stored at least one distributed lock and at least one distributed lock in the distributed locks; comparing the expiration time of each of the distributed locks with a current time to determine a distributed lock that has not expired from at least one of the distributed locks; and sending the distributed lock which is not expired to the new main node so as to realize the synchronization purpose. The invention also provides a synchronization device of the distributed lock, a computer device and a computer readable storage medium.

Description

Distributed lock synchronization method and device, computer equipment and readable storage medium
Technical Field
The invention relates to the technical field of data processing, in particular to a method and a device for synchronizing distributed locks, computer equipment and a computer readable storage medium.
Background
In many scenarios, in order to ensure data consistency, many technical solutions are required to support, such as distributed locks. Distributed locks are a way to control synchronous access to shared resources between distributed systems where there is often a need to coordinate their actions. If one or a group of resources are shared between different systems or different hosts of the same system, then access to these resources often requires mutual exclusion to prevent interference with each other to ensure consistency, in which case a distributed lock is used. Common distributed locks include a database-based distributed lock, a Redis-based distributed lock, and a Zookeeper-based distributed lock.
At present, a widely used distributed lock technology is based on Redis to realize distributed locks, but when Redis is a master-slave structure, if a certain client successfully applies a lock on a master node and the master node does not synchronize information of the client successfully applying the lock on the master node to a slave node, and meanwhile, the master node is hung up and the slave node is lifted up to the master node, another client applies the lock on a new master node.
The prior art generally solves the above problem through the RedLock algorithm, that is, by providing a plurality of independent Redis instances without master-slave relationship and utilizing most mechanisms. For example, when locking, a del instruction needs to be sent to all nodes only when more than half of the nodes are successfully set and the locking is considered to be successfully unlocked. However, this approach may have problems such as an error retry, adding multiple Redis nodes, and performance degradation compared to a single node.
Therefore, it is a technical problem to be solved in the art to provide a synchronization method, apparatus, computer device and computer readable storage medium for distributed locks to improve data security and save hardware cost.
Disclosure of Invention
The invention aims to provide a synchronization method and device of a distributed lock, computer equipment and a computer readable storage medium, which can improve data security and save hardware cost.
One aspect of the present invention provides a method for synchronizing distributed locks, including: after a slave node of a master-slave framework is switched to a new master node, responding to a triggered synchronization task, and acquiring the stored expiration time of at least one distributed lock and each distributed lock in the at least one distributed lock; comparing the expiration time of each of the distributed locks with a current time to determine a distributed lock that has not expired from at least one of the distributed locks; and sending the unexpired distributed lock to the new main node to achieve the synchronization purpose.
Optionally, the comparing the expiration time of each of the distributed locks with the current time to determine a distributed lock that has not expired from at least one of the distributed locks includes: for each distributed lock, judging whether the expiration time of the distributed lock is greater than the current time; and under the condition that the expiration time of the distributed lock is judged to be larger than the current time, determining the distributed lock as the unexpired distributed lock.
Optionally, the synchronization method of the distributed lock further includes: starting a cleaning task for cleaning the distributed lock at preset time intervals, and acquiring the starting time of the cleaning task; judging whether the expiration time of the distributed locks is less than the starting time or not aiming at each stored distributed lock; and under the condition that the expiration time of the distributed lock is judged to be less than the starting time, determining the distributed lock as an expired distributed lock, and deleting the expired distributed lock.
Optionally, the synchronization method of the distributed lock further includes: judging whether the expired distributed lock exists in the new main node; and deleting the expired distributed lock existing in the new master node when the expired distributed lock exists in the new master node.
Optionally, the synchronization method of the distributed lock further includes: setting a new distributed lock at the new master node; and after the setting is successful, storing the new distributed lock to the local.
Optionally, each of the distributed locks includes a key and a key value corresponding to the key, where the key includes a name of the distributed lock, and the key value includes an expiration time of the distributed lock.
Another aspect of the present invention provides a synchronization apparatus for a distributed lock, including: the acquisition module is used for responding to a triggered synchronization task after a slave node of a master-slave framework is switched to a new master node, and acquiring the expiration time of each stored at least one distributed lock and at least one stored distributed lock; a determining module, configured to compare an expiration time of each of the distributed locks with a current time to determine a distributed lock that has not expired from at least one of the distributed locks; and the sending module is used for sending the unexpired distributed lock to the new main node so as to achieve the aim of synchronization.
Optionally, the determining module is further configured to: for each distributed lock, judging whether the expiration time of the distributed lock is greater than the current time; and under the condition that the expiration time of the distributed lock is judged to be larger than the current time, determining the distributed lock as the unexpired distributed lock.
Optionally, the synchronization apparatus for a distributed lock further includes: the cleaning module is used for starting a cleaning task for cleaning the distributed lock at intervals of preset time and acquiring the starting time for currently starting the cleaning task; a first judging module, configured to judge, for each stored distributed lock, whether expiration time of the distributed lock is less than the start time; and the processing module is used for determining that the distributed lock is an expired distributed lock and deleting the expired distributed lock under the condition that the expiration time of the distributed lock is judged to be less than the starting time.
Optionally, the synchronization apparatus for a distributed lock further includes: a second judging module, configured to judge whether the expired distributed lock exists in the new master node; and the deleting module is used for deleting the expired distributed lock existing in the new main node under the condition that the expired distributed lock exists in the new main node.
Optionally, the synchronization apparatus for a distributed lock further includes: a setting module, configured to set a new distributed lock in the new master node; and the storage module is used for storing the new distributed lock to the local after the setting is successful.
Optionally, each of the distributed locks includes a key and a key value corresponding to the key, where the key includes a name of the distributed lock, and the key value includes an expiration time of the distributed lock.
Yet another aspect of the present invention provides a computer device, specifically including: the present invention relates to a distributed lock synchronization method, and more particularly, to a distributed lock synchronization method, and a computer program stored in a memory and executable on a processor.
Yet another aspect of the present invention provides a computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the above-described steps of the method for synchronizing distributed locks.
The method, the device, the computer equipment and the computer readable storage medium for synchronizing the distributed locks provided by the invention backup the successfully set distributed locks in the original master node of a master-slave framework, when the original master node does not synchronize the distributed locks into slave nodes, the original master node is hung off and becomes a new master node from the slave nodes, the equipment for backing up the distributed locks actively implements synchronization by adopting a compensation idea, and the undecided backed distributed locks are synchronized into the new master node, so that the problem of insecurity of the distributed locks when the slave nodes are switched into the master nodes is solved. Moreover, if the device storing the backup distributed lock is hung, the system flow cannot be influenced at all, and because the distributed lock acquired by the thread and the backup distributed lock are lost, the consistency of the distributed locks in the device and the main node can be maintained. In addition, according to the embodiment, insecurity of loss of the distributed lock is avoided without using a plurality of nodes, and insecurity of multiple locking can be prevented only by the scheme, so that hardware cost and maintenance cost are saved.
Drawings
Various other advantages and benefits will become apparent to those of ordinary skill in the art upon reading the following detailed description of the preferred embodiments. The drawings are only for purposes of illustrating the preferred embodiments and are not to be construed as limiting the invention. Also, like reference numerals are used to refer to like parts throughout the drawings. In the drawings:
FIG. 1 schematically illustrates a flow diagram of a method of synchronization of distributed locks according to an embodiment of the invention;
FIG. 2 schematically illustrates a schematic diagram of a synchronization scheme for a distributed lock, according to an embodiment of the invention;
FIG. 3 schematically illustrates a block diagram of a synchronization apparatus for a distributed lock according to an embodiment of the present invention;
FIG. 4 schematically illustrates a block diagram of a computer device suitable for implementing a synchronization method for distributed locks, in accordance with an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention more apparent, the present invention is described in further detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative of the invention and are not intended to limit the invention. 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 invention.
It should be noted that, in this document, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The following describes a synchronization method of distributed locks provided by the present invention with reference to the accompanying drawings.
FIG. 1 schematically shows a flow diagram of a method of synchronization of distributed locks according to an embodiment of the invention. As shown in fig. 1, the synchronization method of the distributed lock may include steps S101 to S103, where:
step S101, after a slave node of a master-slave framework is switched to a new master node, responding to a triggered synchronization signal, and acquiring the expiration time of each stored at least one distributed lock and at least one distributed lock.
It should be noted that, the solution is implemented based on a Redis master-slave architecture, does not involve adding a Redis node, and can solve the problem of loss of the distributed lock only under the condition of maintaining the current architecture. In the Redis master-slave architecture, a master node is responsible for processing a write request, a slave node only processes a read request, and after the master node receives and processes the write request, the master node needs to inform that data of the slave node is changed to keep data of the master node and the slave node consistent, and this behavior may be called master-slave synchronization. When the distributed lock is realized based on the Redis master-slave architecture, the distributed lock is basically set at the master node, and then the master node synchronizes the distributed lock to the slave node.
Additionally, the Sentinel cluster (known as Sentinel cluster) is a highly available Redis deployment scenario. When the master node in the Redis master-slave architecture is hung up, one slave node can be selected as a new master node, and continuous availability of the Redis service can be realized through self-adjustment of the Sentinel cluster without human intervention. The Sentinel cluster has the following functions: 1. monitoring: it is continuously monitored whether the master and slave nodes in the Redis master-slave architecture are available. 2. And (3) notification: the system administrator is notified that some of the services in the Redis master-slave architecture are unavailable. 3. And (3) fault switching: if the master node hangs up, the Sentinel cluster will initiate a failover, select one of the slave nodes as the new master node, and the application using Redis will also be informed of the use of the new master node. 4. Providing configuration information: the Sentinel cluster provides a service discovery function for the Redis client, and the client accesses the Sentinel cluster and is informed of the current host node address.
The present embodiment can be applied to, but not limited to, a server, a desktop computer, a notebook computer, etc., and for easy understanding, a specific solution of the present embodiment will be explained in detail below with reference to fig. 2 by taking the server as an example.
FIG. 2 schematically illustrates a synchronization scheme for a distributed lock according to an embodiment of the invention. As shown in fig. 2, in addition to setting a distributed lock at a master node, a server (e.g., server a, server B) may also store the distributed lock that was successfully set at the master node locally, for example, in a memory. In this embodiment, a synchronization task (e.g., the trigger task in fig. 2) may also be set in the server in advance, and the synchronization task may synchronize the distributed lock stored locally in the server to the new master node. In this embodiment, if a distributed lock in an original master node in a Redis master-slave architecture is not synchronized to a slave node and the original master node is hung, to ensure availability of the Redis service, a Sentinel cluster may select one slave node from the Redis master-slave architecture as a new master node, and trigger a synchronization task in a server, and the server may respond to the synchronization task triggered by the Sentinel cluster and synchronize a locally stored distributed lock to the new slave node through a series of operations, for example, the server may first obtain the locally (e.g., memory) stored distributed lock and determine an expiration time of each distributed lock. When the distributed lock is stored locally (for example, in a memory), a ConcurrentHashMap structure may be adopted, and a voltate modification is used, and the advantage of adopting the voltate modification is that it may be ensured that the change of the locally stored distributed lock is visible to the trigger task and the service thread.
It should be noted that each distributed lock may include a key and a key corresponding to the key, the key may include a name of the distributed lock, and the key may include an expiration time of the distributed lock. For example, the format of the distributed lock is key-value, and the key is a key and is used to store the name of the distributed lock. value is a key value and is divided into two parts which can be connected through colon, wherein the first part is the expiration time of the distributed lock, such as the first 14 character storage year YYYY, month MM, day DD, hour HH, minute MM and second SS, specifically YYYYMMDDHHMMSS; the second part is actual value information, that is, the overall structure of the value key value of this embodiment is YYYYMMDDHHMMSS: value.
Step S102, the expiration time of each distributed lock is compared with the current time, so as to determine the distributed lock which has not expired from at least one distributed lock.
To avoid synchronizing an expired distributed lock to a new master node, the embodiment may determine an unexpired distributed lock before synchronizing the distributed lock. Specifically, it can be determined by step S102.
Alternatively, step S102 may include step S1021 and step S1022, wherein:
step S1021, aiming at each distributed lock, judging whether the expiration time of the distributed lock is larger than the current time;
in step S1022, when it is determined that the expiration time of the distributed lock is greater than the current time, the distributed lock is determined to be a distributed lock that has not expired yet.
Specifically, for each distributed lock stored locally by the server, the following operations may be performed in turn: and judging whether the expiration time of the current distributed lock is greater than the current time, if so, indicating that the distributed lock is the unexpired distributed lock, and then continuously and sequentially judging each remaining distributed lock.
Further, in order to avoid the expired distributed locks occupying the system space, a cleaning task may be set in the server to clean the expired distributed locks. Optionally, the synchronization method of the distributed lock may further include:
starting a cleaning task for cleaning the distributed lock at preset time intervals, and acquiring the starting time of the current cleaning task;
judging whether the expiration time of the distributed locks is less than the starting time or not aiming at each stored distributed lock;
and under the condition that the expiration time of the distributed lock is judged to be less than the starting time, determining the distributed lock as the expired distributed lock, and deleting the expired distributed lock.
Specifically, a cleaning task (such as the timing task in fig. 2) may be set on the server to clean the expired distributed locks, where the cleaning task is started periodically, and for each distributed lock stored on the server, the following steps may be performed in turn: and judging whether the expiration time of the current distributed lock is less than the starting time of the current started cleaning task, if so, determining that the distributed lock is expired, and further deleting the distributed lock from the server locally.
Further, in order to ensure that the distributed lock stored locally by the server is consistent with the distributed lock stored in the new master node, the synchronization method of the distributed lock may further include:
judging whether an expired distributed lock exists in the new main node;
and deleting the expired distributed lock existing in the new main node under the condition that the expired distributed lock exists in the new main node.
It should be noted that, when the original master node is not hung, the embodiment may also be applied to the original master node. Optionally, the expired distributed lock stored locally by the server is deleted first, and then the expired distributed lock stored in the master node is deleted, so that the purpose of the embodiment is: if the distributed lock stored in the master node is deleted first but the distributed lock locally stored in the server is not deleted yet, because the master node does not already have the distributed lock, if other servers apply for the lock to the master node at this time, the situation that two servers simultaneously have two locks occurs.
And step S103, sending the unexpired distributed lock to a new main node to achieve the synchronization purpose.
After determining that the distributed lock is not expired, the server can send the distributed lock to the new master node to achieve the purpose of synchronizing the effective distributed lock to the new master node, and the problem that the distributed lock is insecure when the Redis slave node is switched to the master node is solved. The embodiment adopts a compensation idea, because the distributed locks are not synchronized during Redis master-slave switching, synchronization can be actively implemented through the equipment for backing up the distributed locks, if the equipment for storing the backup distributed locks is hung, the system flow cannot be influenced at all, because the distributed locks acquired by threads and the backup distributed locks are lost, and the data consistency can be maintained. In addition, according to the embodiment, the distributed lock is not required to be safely lost by using a plurality of Redis nodes, the unsafe condition of locking for multiple times can be prevented only by the scheme, and the hardware cost and the maintenance cost are saved.
Further, even if there is already a new master node and a successful distributed lock set in the original master node is synchronized to the new master node, in order to completely avoid the insecurity problem of the distributed lock, the method for synchronizing the distributed lock may further include:
setting a new distributed lock at a new main node;
and after the setting is successful, storing the new distributed lock to the local.
For example, after a new master node successfully sets a new distributed lock, the distributed lock is stored in a local memory, and the expired distributed lock is cleared periodically by a cleaning task.
The purpose of firstly setting the distributed lock on the master node and then storing the successfully set distributed lock to the local is as follows: avoiding the system from doing too much useless work. If the distributed lock is stored locally and then set in the master node, and if the distributed lock is not set in the master node successfully, the local distributed lock needs to be deleted again to ensure data consistency, which wastes resources.
The embodiment of the present invention further provides a synchronization apparatus for a distributed lock, where the synchronization apparatus for a distributed lock corresponds to the synchronization method for a distributed lock provided in the foregoing embodiment, and corresponding technical features and technical effects are not described in detail in this embodiment, and reference may be made to the foregoing embodiment for relevant points. In particular, FIG. 3 schematically illustrates a block diagram of a synchronization apparatus for a distributed lock, according to an embodiment of the present invention. As shown in fig. 3, the synchronization apparatus 300 of the distributed lock may include an obtaining module 301, a determining module 302, and a sending module 303, wherein:
an obtaining module 301, configured to respond to a triggered synchronization task after a slave node of a master-slave architecture is switched to a new master node, and obtain expiration times of at least one stored distributed lock and each stored distributed lock in the at least one stored distributed lock;
a determining module 302, configured to compare the expiration time of each distributed lock with the current time to determine a distributed lock that has not expired from among the at least one distributed lock;
a sending module 303, configured to send the unexpired distributed lock to a new master node, so as to achieve a synchronization purpose.
Optionally, the determining module may be further configured to: judging whether the expiration time of the distributed locks is greater than the current time or not for each distributed lock; and under the condition that the expiration time of the distributed lock is judged to be larger than the current time, determining the distributed lock as the distributed lock which is not expired yet.
Optionally, the synchronization apparatus of the distributed lock may further include: the cleaning module is used for starting a cleaning task for cleaning the distributed lock at intervals of preset time and acquiring the starting time of the current cleaning task; the first judgment module is used for judging whether the expiration time of the distributed locks is less than the starting time or not aiming at each stored distributed lock; and the processing module is used for determining that the distributed lock is an expired distributed lock and deleting the expired distributed lock under the condition that the expiration time of the distributed lock is judged to be less than the starting time.
Optionally, the synchronization apparatus of the distributed lock may further include: the second judgment module is used for judging whether an expired distributed lock exists in the new main node; and the deleting module is used for deleting the expired distributed lock existing in the new main node under the condition that the expired distributed lock exists in the new main node.
Optionally, the synchronization apparatus of the distributed lock may further include: the setting module is used for setting a new distributed lock at a new main node; and the storage module is used for storing the new distributed lock to the local after the setting is successful.
Optionally, each distributed lock may include a key and a key corresponding to the key, the key may include a name of the distributed lock, and the key may include an expiration time of the distributed lock.
FIG. 4 schematically illustrates a block diagram of a computer device suitable for implementing a synchronization method for distributed locks, in accordance with an embodiment of the present invention. In this embodiment, the computer device 400 may be a smart phone, a tablet computer, a notebook computer, a desktop computer, a rack server, a blade server, a tower server, or a rack server (including an independent server or a server cluster composed of a plurality of servers), and the like that execute programs. As shown in fig. 4, the computer device 400 of the present embodiment includes at least, but is not limited to: a memory 401, a processor 402, a network interface 403 communicatively coupled to each other via a system bus. It is noted that FIG. 4 only shows the computer device 400 having components 401 and 403, but it is understood that not all of the shown components are required and that more or fewer components may be implemented instead.
In this embodiment, the memory 403 includes at least one type of computer-readable storage medium, which includes flash memory, a hard disk, a multimedia card, a card-type memory (e.g., SD or DX memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, and the like. In some embodiments, the storage 401 may be an internal storage unit of the computer device 400, such as a hard disk or a memory of the computer device 400. In other embodiments, the memory 401 may also be an external storage device of the computer device 400, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), etc. provided on the computer device 400. Of course, the memory 401 may also include both internal and external storage devices for the computer device 400. In the present embodiment, the memory 401 is generally used for storing a program code of a synchronization method of an operating system and various types of application software, such as a distributed lock, etc., installed in the computer apparatus 400. Further, the memory 401 may also be used to temporarily store various types of data that have been output or are to be output.
Processor 402 may be a Central Processing Unit (CPU), controller, microcontroller, microprocessor, or other data Processing chip in some embodiments. The processor 402 is generally used to control the overall operation of the computer device 400. Such as performing control and processing related to data interaction or communication with computer device 400. In this embodiment, the processor 402 is used to execute the program code of the steps of the synchronization method of the distributed lock stored in the memory 401.
In this embodiment, the synchronization method of the distributed lock stored in the memory 401 may be further divided into one or more program modules and executed by one or more processors (in this embodiment, the processor 402) to complete the present invention.
The network interface 403 may comprise a wireless network interface or a wired network interface, the network interface 403 typically being used to establish communication links between the computer device 400 and other computer devices. For example, the network interface 403 is used to connect the computer apparatus 400 with an external terminal through a network, establish a data transmission channel and a communication link between the computer apparatus 400 and the external terminal, and the like. The network may be a wireless or wired network such as an Intranet (Intranet), the Internet (Internet), a Global System of Mobile communication (GSM), Wideband Code Division Multiple Access (WCDMA), 4G network, 5G network, Bluetooth (Bluetooth), Wi-Fi, etc.
The present embodiments also provide a computer-readable storage medium comprising a flash memory, a hard disk, a multimedia card, a card-type memory (e.g., SD or DX memory, etc.), a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a read-only memory (ROM), an electrically erasable programmable read-only memory (EEPROM), a programmable read-only memory (PROM), a magnetic memory, a magnetic disk, an optical disk, a server, an App application mall, etc., having stored thereon a computer program that when executed by a processor implements the steps of the synchronization method of the distributed lock.
It will be apparent to those skilled in the art that the modules or steps of the embodiments of the invention described above may be implemented by a general purpose computing device, they may be centralized on a single computing device or distributed across a network of multiple computing devices, and alternatively, they may be implemented by program code executable by a computing device, such that they may be stored in a storage device and executed by a computing device, and in some cases, the steps shown or described may be performed in an order different than that described herein, or they may be separately fabricated into individual integrated circuit modules, or multiple ones of them may be fabricated into a single integrated circuit module. Thus, embodiments of the invention are not limited to any specific combination of hardware and software.
Through the above description of the embodiments, those skilled in the art will clearly understand that the method of the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but in many cases, the former is a better implementation manner.
The above description is only a preferred embodiment of the present invention, and not intended to limit the scope of the present invention, and all modifications of equivalent structures and equivalent processes, which are made by using the contents of the present specification and the accompanying drawings, or directly or indirectly applied to other related technical fields, are included in the scope of the present invention.

Claims (10)

1. A method for synchronizing a distributed lock, comprising:
after a slave node of a master-slave framework is switched to a new master node, responding to a triggered synchronization task, and acquiring the expiration time of each stored at least one distributed lock and at least one distributed lock in the distributed locks;
comparing the expiration time of each of the distributed locks with a current time to determine a distributed lock that has not expired from at least one of the distributed locks;
and sending the distributed lock which is not expired to the new main node so as to realize the synchronization purpose.
2. The method of claim 1, wherein comparing the expiration time of each of the distributed locks with a current time to determine a distributed lock that has not expired from at least one of the distributed locks comprises:
for each distributed lock, judging whether the expiration time of the distributed lock is greater than the current time;
determining that the distributed lock is the distributed lock that has not expired if it is determined that the expiration time of the distributed lock is greater than the current time.
3. The method of claim 1, further comprising:
starting a cleaning task for cleaning the distributed lock at intervals of a preset time interval, and acquiring the starting time of the cleaning task;
for each stored distributed lock, judging whether the expiration time of the distributed lock is less than the starting time;
and under the condition that the expiration time of the distributed lock is judged to be less than the starting time, determining that the distributed lock is an expired distributed lock, and deleting the expired distributed lock.
4. The method of claim 3, further comprising:
judging whether the expired distributed lock exists in the new master node;
deleting the expired distributed lock present in the new master node if it is determined that the expired distributed lock is present in the new master node.
5. The method of claim 1, further comprising:
setting a new distributed lock at the new master node;
and after the setting is successful, storing the new distributed lock to the local.
6. The method of claim 1, wherein each of the distributed locks comprises a key and a key corresponding to the key, wherein the key comprises a name of the distributed lock, and wherein the key comprises an expiration time of the distributed lock.
7. A synchronization apparatus for a distributed lock, comprising:
the acquisition module is used for responding to a triggered synchronization task after a slave node of a master-slave framework is switched to a new master node, and acquiring the expiration time of each stored at least one distributed lock and at least one distributed lock;
a determining module, configured to compare the expiration time of each distributed lock with the current time to determine a distributed lock that has not expired from among at least one distributed lock;
and the sending module is used for sending the unexpired distributed lock to the new main node so as to achieve the aim of synchronization.
8. The apparatus of claim 7, wherein the determining module is further configured to:
for each distributed lock, judging whether the expiration time of the distributed lock is greater than the current time;
determining that the distributed lock is the distributed lock that has not expired if it is determined that the expiration time of the distributed lock is greater than the current time.
9. A computer device, the computer device comprising: memory, processor and computer program stored on the memory and executable on the processor, characterized in that the processor implements the steps of the method of any of claims 1 to 6 when executing the computer program.
10. A computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 6.
CN201911165392.6A 2019-11-25 2019-11-25 Distributed lock synchronization method and device, computer equipment and readable storage medium Pending CN111026807A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911165392.6A CN111026807A (en) 2019-11-25 2019-11-25 Distributed lock synchronization method and device, computer equipment and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911165392.6A CN111026807A (en) 2019-11-25 2019-11-25 Distributed lock synchronization method and device, computer equipment and readable storage medium

Publications (1)

Publication Number Publication Date
CN111026807A true CN111026807A (en) 2020-04-17

Family

ID=70201767

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911165392.6A Pending CN111026807A (en) 2019-11-25 2019-11-25 Distributed lock synchronization method and device, computer equipment and readable storage medium

Country Status (1)

Country Link
CN (1) CN111026807A (en)

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113268348A (en) * 2021-05-31 2021-08-17 上海数禾信息科技有限公司 Switching method and device of distributed lock server, computer equipment and medium
CN113535416A (en) * 2021-06-30 2021-10-22 北京百度网讯科技有限公司 Method and device for realizing reentrant distributed lock, electronic equipment and storage medium
CN114567540A (en) * 2022-02-25 2022-05-31 北京百度网讯科技有限公司 Master/standby node switching method, device, equipment, medium and program product

Citations (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040220931A1 (en) * 2003-04-29 2004-11-04 Guthridge D. Scott Discipline for lock reassertion in a distributed file system
US20080183894A1 (en) * 2007-01-25 2008-07-31 Oracle International Corporation Synchronizing cluster time
CN104239418A (en) * 2014-08-19 2014-12-24 天津南大通用数据技术股份有限公司 Distributed lock method for supporting distributed database and distributed database system
CN107133369A (en) * 2017-06-16 2017-09-05 郑州云海信息技术有限公司 A kind of distributed reading shared buffer memory aging method based on the expired keys of redis
CN107145396A (en) * 2016-03-01 2017-09-08 阿里巴巴集团控股有限公司 Distributed lock implementation method and equipment
CN107426265A (en) * 2016-03-11 2017-12-01 阿里巴巴集团控股有限公司 The synchronous method and apparatus of data consistency
CN107818018A (en) * 2016-09-14 2018-03-20 北京京东尚科信息技术有限公司 The control method and device of distributed lock
CN108123851A (en) * 2017-12-29 2018-06-05 北京奇虎科技有限公司 The lifetime detection method and device of main and subordinate node synchronization link in distributed system
CN108874552A (en) * 2018-06-28 2018-11-23 杭州云英网络科技有限公司 Distributed lock executes method, apparatus and system, application server and storage medium
US20180373750A1 (en) * 2017-06-21 2018-12-27 Alibaba Group Holding Limited Allocation method and device for a distributed lock
CN109240840A (en) * 2017-07-11 2019-01-18 阿里巴巴集团控股有限公司 Disaster recovery method, device and the machine readable media of group system
CN109639794A (en) * 2018-12-10 2019-04-16 杭州数梦工场科技有限公司 A kind of stateful cluster recovery method, apparatus, equipment and readable storage medium storing program for executing
CN109857527A (en) * 2019-01-04 2019-06-07 四川虹美智能科技有限公司 A kind of distributed task dispatching method, system, distributed devices and Redis database

Patent Citations (13)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20040220931A1 (en) * 2003-04-29 2004-11-04 Guthridge D. Scott Discipline for lock reassertion in a distributed file system
US20080183894A1 (en) * 2007-01-25 2008-07-31 Oracle International Corporation Synchronizing cluster time
CN104239418A (en) * 2014-08-19 2014-12-24 天津南大通用数据技术股份有限公司 Distributed lock method for supporting distributed database and distributed database system
CN107145396A (en) * 2016-03-01 2017-09-08 阿里巴巴集团控股有限公司 Distributed lock implementation method and equipment
CN107426265A (en) * 2016-03-11 2017-12-01 阿里巴巴集团控股有限公司 The synchronous method and apparatus of data consistency
CN107818018A (en) * 2016-09-14 2018-03-20 北京京东尚科信息技术有限公司 The control method and device of distributed lock
CN107133369A (en) * 2017-06-16 2017-09-05 郑州云海信息技术有限公司 A kind of distributed reading shared buffer memory aging method based on the expired keys of redis
US20180373750A1 (en) * 2017-06-21 2018-12-27 Alibaba Group Holding Limited Allocation method and device for a distributed lock
CN109240840A (en) * 2017-07-11 2019-01-18 阿里巴巴集团控股有限公司 Disaster recovery method, device and the machine readable media of group system
CN108123851A (en) * 2017-12-29 2018-06-05 北京奇虎科技有限公司 The lifetime detection method and device of main and subordinate node synchronization link in distributed system
CN108874552A (en) * 2018-06-28 2018-11-23 杭州云英网络科技有限公司 Distributed lock executes method, apparatus and system, application server and storage medium
CN109639794A (en) * 2018-12-10 2019-04-16 杭州数梦工场科技有限公司 A kind of stateful cluster recovery method, apparatus, equipment and readable storage medium storing program for executing
CN109857527A (en) * 2019-01-04 2019-06-07 四川虹美智能科技有限公司 A kind of distributed task dispatching method, system, distributed devices and Redis database

Cited By (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113268348A (en) * 2021-05-31 2021-08-17 上海数禾信息科技有限公司 Switching method and device of distributed lock server, computer equipment and medium
CN113268348B (en) * 2021-05-31 2023-03-21 上海数禾信息科技有限公司 Switching method and device of distributed lock server, computer equipment and medium
CN113535416A (en) * 2021-06-30 2021-10-22 北京百度网讯科技有限公司 Method and device for realizing reentrant distributed lock, electronic equipment and storage medium
CN113535416B (en) * 2021-06-30 2024-02-27 北京百度网讯科技有限公司 Implementation method and device of reentrant distributed lock, electronic equipment and storage medium
CN114567540A (en) * 2022-02-25 2022-05-31 北京百度网讯科技有限公司 Master/standby node switching method, device, equipment, medium and program product

Similar Documents

Publication Publication Date Title
CN111026807A (en) Distributed lock synchronization method and device, computer equipment and readable storage medium
US11888933B2 (en) Cloud service processing method and device, cloud server, cloud service system and storage medium
CN112463448B (en) Distributed cluster database synchronization method, device, equipment and storage medium
CN103152390B (en) The node configuration method of distributed memory system, device, node and system
CN110830283B (en) Fault detection method, device, equipment and system
US8533525B2 (en) Data management apparatus, monitoring apparatus, replica apparatus, cluster system, control method and computer-readable medium
EP3528431A1 (en) Paxos protocol-based methods and apparatuses for online capacity expansion and reduction of distributed consistency system
CN103530200A (en) Server hot backup system and method
CN109361525B (en) Method, device, control terminal and medium for restarting distributed deployment of multiple services
US20170090904A1 (en) Application management device, application management method, and computer-readable recording medium
CN110990190A (en) Distributed file lock fault processing method, system, terminal and storage medium
CN112418794A (en) Service transfer method and device
CN112865992A (en) Method and device for switching master nodes in distributed master-slave system and computer equipment
US20130254588A1 (en) Standby system device, a control method, and a program thereof
CN110069365B (en) Method for managing database and corresponding device, computer readable storage medium
CN112955874A (en) System and method for self-healing in decentralized model building using machine learning of blockchains
CN104516744A (en) Software updating method and system
CN112860787A (en) Method for switching master nodes in distributed master-slave system, master node device and storage medium
EP3660679B1 (en) Data backup method, device and system
CN109257396B (en) Distributed lock scheduling method and device
CN114238495A (en) Method and device for switching main cluster and standby cluster of database, computer equipment and storage medium
CN116185697B (en) Container cluster management method, device and system, electronic equipment and storage medium
CN114490196A (en) Database switching method, system, device and medium
CN114020279A (en) Application software distributed deployment method, system, terminal and storage medium
US11010269B2 (en) Distributed processing system and method for management of distributed processing system

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