CN113660350A - Distributed lock coordination method, device, equipment and storage medium - Google Patents

Distributed lock coordination method, device, equipment and storage medium Download PDF

Info

Publication number
CN113660350A
CN113660350A CN202111207036.3A CN202111207036A CN113660350A CN 113660350 A CN113660350 A CN 113660350A CN 202111207036 A CN202111207036 A CN 202111207036A CN 113660350 A CN113660350 A CN 113660350A
Authority
CN
China
Prior art keywords
node
cluster
under
state
nodes
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
CN202111207036.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.)
Hundsun Technologies Inc
Original Assignee
Hundsun Technologies Inc
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 Hundsun Technologies Inc filed Critical Hundsun Technologies Inc
Priority to CN202111207036.3A priority Critical patent/CN113660350A/en
Publication of CN113660350A publication Critical patent/CN113660350A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/52Program synchronisation; Mutual exclusion, e.g. by means of semaphores
    • G06F9/524Deadlock detection or avoidance
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L43/00Arrangements for monitoring or testing data switching networks
    • H04L43/08Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters
    • H04L43/0805Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters by checking availability
    • H04L43/0811Monitoring or testing based on specific metrics, e.g. QoS, energy consumption or environmental parameters by checking availability by checking connectivity

Abstract

The application provides a distributed lock coordination method, a distributed lock coordination device, distributed lock coordination equipment and a storage medium, and relates to the technical field of data processing. The method comprises the following steps: if the master node is detected to be disconnected with the cluster node under the preset service type node, a plurality of slave nodes under the cluster node compete to create a state node under the cluster node; determining a target slave node of the plurality of slave nodes that successfully created the status node as a new master node; and writing back the node information of the new main node to the state node to indicate the new main node to acquire the distributed lock. Compared with the prior art, the method and the device avoid the problems that the information of the current master node of the acquired lock cannot be acquired, the function expansion is not facilitated, and the fault tolerance of the passive lock grabbing mode is low.

Description

Distributed lock coordination method, device, equipment and storage medium
Technical Field
The present application relates to the field of data processing technologies, and in particular, to a distributed lock coordination method, apparatus, device, and storage medium.
Background
To prevent the multiple processes in the distributed system from interfering with each other, a distributed coordination technique is required to schedule the processes (e.g., Master-Worker mode). At the heart of the distributed coordination technology, the distributed lock is realized.
The method for realizing the distributed lock based on the ZooKeeper generally comprises the steps of creating a directory, and creating a temporary sequence node under the directory when a thread A wants to acquire the lock; and then each node acquires all child nodes in the directory, then determines whether a brother node smaller than the node exists in the directory, and if not, indicates that the thread sequence number of the current node is the minimum, and then acquires the lock currently.
However, the processing method cannot acquire the information of the master node currently acquiring the lock, which is not beneficial to the expansion of the function, and the passive lock grabbing method has low fault tolerance.
Disclosure of Invention
An object of the present application is to provide a distributed lock coordination method, apparatus, device and storage medium, which are used to solve the problems that in the prior art, master node information of a currently acquired lock cannot be acquired, expansion of functions is not facilitated, and the fault tolerance of the passive lock preemption mode is low.
In order to achieve the above purpose, the technical solutions adopted in the embodiments of the present application are as follows:
in a first aspect, an embodiment of the present application provides a distributed lock coordination method, where the method includes:
if the master node is detected to be disconnected with the cluster node under the preset service type node, a plurality of slave nodes under the cluster node compete to create a state node under the cluster node;
determining a target slave node of the plurality of slave nodes that successfully created the status node as a new master node;
and writing back the node information of the new main node to the state node to indicate the new main node to acquire the distributed lock.
Optionally, before the creating of the state node by a plurality of slave nodes under the cluster node under competition of the cluster node, the method further includes:
and under the condition that the slave nodes monitor that the master node is disconnected, waiting for a preset acquisition time delay and then competing under the cluster nodes to create the state nodes.
Optionally, the method further comprises:
and the master node reestablishes the state node under the cluster node within the preset acquisition time delay after triggering the disconnection.
Optionally, the method further comprises:
and if the master node fails to reestablish the state node, the master node updates the state from the slave node to the slave node.
Optionally, before the creating of the state node by a plurality of slave nodes under the cluster node under competition of the cluster node, the method further includes:
and after the master node is disconnected with the cluster node under the preset service type node, triggering a state node deletion event of the master node to indicate the plurality of slave nodes to compete to create the state node.
Optionally, the method further comprises:
and the slave node which fails to be created in the plurality of slave nodes continues to monitor the state node deletion event of the master node.
Optionally, before the multiple slave nodes under the cluster node compete for creating the state node under the cluster if it is detected that the master node is disconnected from the cluster node under the preset service type node, the method further includes:
a plurality of nodes under the cluster node compete to create the state node;
and determining an application node which successfully creates the state node in the plurality of nodes as the main node, and writing back node information of the main node to the state node to indicate the main node to acquire the distributed lock.
Optionally, before the competing creation of the state node by the plurality of nodes under the cluster node, the method further includes:
creating the preset service type node;
creating the cluster node based on the preset service type node, wherein the preset service type node and the cluster node are permanent nodes;
registering the plurality of nodes under the cluster node.
In a second aspect, another embodiment of the present application provides a distributed lock coordination apparatus, including: a creation module, a determination module, and a write back module, wherein:
the creating module is used for competing the creation state node under the cluster node by a plurality of slave nodes under the cluster node if the disconnection between the master node and the cluster node under the preset service type node is detected;
the determining module is configured to determine that a target slave node of the plurality of slave nodes that successfully creates the status node is a new master node;
and the write-back module is used for writing back the node information of the new main node into the state node so as to indicate the new main node to acquire the distributed lock.
Optionally, the creating module is specifically configured to, when the slave nodes monitor that the master node is disconnected, wait for a preset acquisition delay before competing under the cluster node to create the state node.
Optionally, the creating module is specifically configured to re-create the state node under the preset service type node within the preset acquisition delay after the master node triggers the disconnection.
Optionally, the apparatus further comprises: and the updating module is used for updating the state slave node into the slave node by the master node if the master node fails to reestablish the state node.
Optionally, the apparatus further comprises: and the triggering module is used for triggering a state node deleting event of the master node after the master node is disconnected with the cluster node under the preset service type node so as to indicate the plurality of slave nodes to compete to create the state node.
Optionally, the apparatus further comprises: and the monitoring module is used for continuously monitoring the state node deletion event by the slave node which fails to create in the plurality of slave nodes.
Optionally, the node information of the master node and each of the slave nodes respectively includes: node IP address and port information.
Optionally, the creating module is specifically configured to create the state node by a plurality of nodes under the cluster node in a competition manner;
the determining module is specifically configured to determine, as the master node, an application node that successfully creates the state node among the plurality of nodes, and write back node information of the master node to the state node to indicate that the master node acquires the distributed lock.
Optionally, the apparatus further comprises: a registration module, wherein:
the creating module is specifically configured to create the preset service type node; creating the cluster node based on the preset service type node, wherein the preset service type node and the cluster node are permanent nodes;
the registration module is specifically configured to register the plurality of nodes to the cluster node.
In a third aspect, another embodiment of the present application provides a distributed lock coordination device, including: a processor, a storage medium and a bus, wherein the storage medium stores machine-readable instructions executable by the processor, the processor and the storage medium communicate via the bus when the distributed lock coordination apparatus is operated, and the processor executes the machine-readable instructions to perform the steps of the method according to any one of the first aspect.
In a fourth aspect, another embodiment of the present application provides a storage medium having a computer program stored thereon, where the computer program is executed by a processor to perform the steps of the method according to any one of the above first aspects.
The beneficial effect of this application is: by adopting the distributed lock coordination method provided by the application, after the disconnection between the master node and the cluster node is detected, other slave nodes under the same cluster node with the master node immediately compete for creating the state node under the cluster node, a target slave node which is successfully created is determined to be a new master node, and node information of the new master node is written into the state node to indicate that the new master node acquires the distributed lock.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings that are required to be used in the embodiments will be briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present application and therefore should not be considered as limiting the scope, and for those skilled in the art, other related drawings can be obtained from the drawings without inventive effort.
Fig. 1 is a schematic structural diagram of a node in a ZooKeeper according to an embodiment of the present application;
fig. 2 is a schematic structural diagram of a node in the ZooKeeper according to another embodiment of the present application;
fig. 3 is a schematic structural diagram of a node in the ZooKeeper according to another embodiment of the present application;
FIG. 4 is a flowchart illustrating a distributed lock coordination method according to an embodiment of the present application;
FIG. 5 is a flowchart illustrating a distributed lock coordination method according to another embodiment of the present application;
FIG. 6 is a flowchart illustrating a distributed lock coordination method according to another embodiment of the present application;
FIG. 7 is a flowchart illustrating a distributed lock coordination method according to another embodiment of the present application;
FIG. 8 is a block diagram of a distributed lock coordination apparatus according to an embodiment of the present application;
FIG. 9 is a schematic structural diagram of a distributed lock coordination apparatus according to another embodiment of the present application;
fig. 10 is a schematic structural diagram of a distributed lock coordination device according to an embodiment of the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some embodiments of the present application, but not all embodiments.
The components of the embodiments of the present application, generally described and illustrated in the figures herein, can be arranged and designed in a wide variety of different configurations. Thus, the following detailed description of the embodiments of the present application, presented in the accompanying drawings, is not intended to limit the scope of the claimed application, but is merely representative of selected embodiments of the application. All other embodiments, which can be derived by a person skilled in the art from the embodiments of the present application without making any creative effort, shall fall within the protection scope of the present application.
Additionally, the flowcharts used in this application illustrate operations implemented according to some embodiments of the present application. It should be understood that the operations of the flow diagrams may be performed out of order, and steps without logical context may be performed in reverse order or simultaneously. One skilled in the art, under the guidance of this application, may add one or more other operations to, or remove one or more operations from, the flowchart.
Before introducing the present application, a brief description of the application scenario, the prior art, and the technical problem solved by the present application will be given.
Distributed systems (distributed systems) are software systems built on top of a network; the distributed operating system comprises a plurality of processors, can manage system resources in a global mode and arbitrarily schedule network resources for users, and the scheduling process is transparent. For example, when a user submits a job, the distributed operating system can select the most appropriate processor in the system as needed, submit the job of the user to the processor for processing, and transmit the processing result to the user after the processor completes the job. In this process, the user is not aware of the existence of multiple processors, and the whole system is just like one processor.
Since multiple threads may exist in the distributed system at the same time, but in order to prevent mutual interference among multiple processes in the distributed system and ensure that one method or one attribute can only be executed by the same thread under the condition of high concurrency, a distributed coordination technology is required to schedule the processes (such as a Master-Worker mode), and the core of the distributed coordination technology is a distributed lock.
In a distributed system, zoo administrators (zookeepers) are a high-performance coordination system that can provide consistent services to distributed applications, and provide functions that can include, but are not limited to: naming service, configuration management, distributed lock, cluster management and the like, and the distributed lock coordination method provided by the application is realized by taking ZooKeeper as an example.
Specifically, the data storage structure in ZooKeeper is like a tree, and is composed of a plurality of nodes, and the nodes can be divided into four types, which are: a permanent node (PERSISTENT), a sequence node of the permanent node (PERSISTENT _ SEQUENTIAL), a temporary node (EPHEMERAL), and a sequence node of the temporary node (EPHEMERAL _ SEQUENTIAL);
wherein, the permanent node: the default node type, after the permanent node is created, will always exist on the Zookeeper server until the permanent node is manually deleted.
Sequence node of permanent node: the basic characteristics of the method are the same as those of a persistent node, but the sequentiality is increased; when a node is created, the ZooKeeper numbers the node name according to the created time sequence, and a father node maintains a self-incrementability number used for the creation sequence of child nodes; when a create permanent node is created, it will always exist on the Zookeeper server until the sequential nodes of the permanent node are manually deleted.
And (4) temporary nodes: the life cycle of the temporary node is bound with the session of the client, and once the session of the client fails, the temporary node is automatically cleaned; zookeeper specifies that temporary nodes can only be leaf nodes.
Sequence node of temporary node: when a node is created, the ZooKeeper numbers the node name according to the created time sequence; the father node maintains a self-incrementability number used for the creation sequence of the child nodes; when the client session fails, the temporary node is automatically cleaned; zookeeper specifies that the sequential nodes of the temporary node can only be leaf nodes.
In order to introduce a structure between nodes in a ZooKeeper, and a lock robbing method and a lock robbing process of node lock robbing, a possible implementation manner is provided below, specifically, fig. 1 is a schematic diagram of a node structure in a ZooKeeper provided in an embodiment of the present application, and as shown in fig. 1, a principle of implementing a distributed lock in a ZooKeeper is as follows: first, a persistent node, partentlock, is created in Zookeeper as a directory node. When a Client node 1 (Client 1) wants to obtain a Lock, a temporary sequence node 1 (Lock 1) needs to be created under a directory node, then the Client1 queries and sorts all temporary sequence nodes under the directory node, and judges whether the created Lock1 node is the top one of all current temporary sequence nodes, if so, the sequence number of the current Lock1 node is the minimum, the Lock is obtained, and at this time, the Client1 obtaining the distributed Lock is the master node under the current directory node.
In order to introduce a system structure when a plurality of nodes exist in a ZooKeeper, and a Lock snatching manner and a Lock snatching process of the plurality of nodes for Lock snatching, a possible implementation manner is provided below, specifically, fig. 2 is a schematic diagram of a node structure in the ZooKeeper provided in another embodiment of the present application, as shown in fig. 2, on the basis of fig. 1, if a Client node 2 (Client 2) and a Client node 3 (Client 3) acquire a Lock in front of each other, a temporary sequence node 2 (Lock 2) corresponding to Client2 and a temporary sequence node 3 (Lock) corresponding to Client3 need to be respectively created under a directory node; the Client2 searches all temporary sequence nodes below the directory node and sorts the nodes, judges whether the created Lock2 node is the one with the top sequence, and if not, the sequence number of the current Lock2 node is not the smallest. Client2 then registers an observation (watch) with the Lock1 node that is ranked just before it, listening for the presence of the Lock1 node. This means that Client2 fails to rob the lock and enters a wait state.
Meanwhile, the Client3 searches all temporary sequential nodes below the ParentLock and sorts the nodes, and judges whether the node Lock3 created by the Client is the one with the top sequence, and the result also shows that the sequence number of the Lock3 node is not the smallest. Client3 then registers watch with the node Lock2, ordered just before it, to listen for the Lock2 node's presence. This means that the Client3 also fails to rob the lock and enters a wait state; at this time, the Client1 that acquires the distributed lock is the master node under the current directory node, and both the Client2 and the Client3 that participate in acquiring the distributed lock are slave nodes under the current directory.
Therefore, in the process of the Lock grabbing, the Client1 obtains the Lock, the Client2 monitors the Lock1 node, and the Client3 monitors the Lock2 node, so that a waiting queue is formed, only one Client node can obtain the Lock at the same time, and mutual interference among the Client nodes is avoided.
In order to introduce that a master node and a slave node which succeed in Lock snatching already exist in a ZooKeeper and after a master node deletion event is triggered, other slave nodes perform a Lock snatching mode and a Lock snatching process, a possible implementation manner is provided below, specifically, fig. 3 is a schematic diagram of a node structure in the ZooKeeper provided in another embodiment of the present application, as shown in fig. 3, on the basis of fig. 2, if a task execution of a Client1 is completed or a Client1 is abnormal in a task execution process, which causes a disconnection with the ZooKeeper, a deletion event of a Lock1 node is triggered.
Since Client2 keeps listening for the presence status of Lock1 node, when Lock1 node is deleted, Client2 will immediately receive notification that Lock1 node is not present. At this time, the Client2 will query all nodes under the directory node again to confirm that the node Lock2 created by itself is the current minimum node. If the current directory node is the minimum, the Client2 obtains a lock in the sequential reason chapter and becomes the master node under the current directory node, and the Client3 is the slave node under the current directory node.
However, the inventor finds that in the prior art, the distributed lock function implemented based on ZooKeeper is implemented by judging the current minimum node number, that is, by passive acquisition, in such an acquisition manner, a slave node can only monitor the existence state of a temporary node created by a master node, and cannot acquire information of the master node, which is not beneficial to expansion and fault tolerance of subsequent functions.
Therefore, the present application provides a distributed lock coordination method, where a state node is introduced under a directory node, in the present application, the state node is a temporary node as described above, each node under the directory node may obtain a write right of the state node in an active obtaining manner, and the state node is created by a node that successfully obtains the state node, where the node that successfully creates the state node is a node that obtains a distributed lock, that is, a master node under the current directory node.
After the master node acquires the distributed lock, the master node information needs to be written back to the state node, so that the master node information can be determined by directly reading the information in the state node when the master node information is acquired subsequently or the master node is monitored, and the function expansion and fault tolerance are facilitated.
The distributed lock coordination method provided by the embodiment of the present application is explained below with reference to a plurality of specific application examples. Fig. 4 is a schematic flowchart of a distributed lock coordination method according to an embodiment of the present application, and as shown in fig. 4, the method includes:
s111: if the master node is detected to be disconnected with the cluster node under the preset service type node, a plurality of slave nodes under the cluster node compete to create the state node under the cluster node.
In an embodiment of the present application, each node may be, for example, a ZooKeeper-based node, where each preset service type node has a cluster node, where the cluster node is equivalent to a directory node in fig. 1 to 3, that is, each preset service type has a directory node corresponding to the preset service type, each cluster node includes a master node and at least one slave node, and each node is registered and written by a client corresponding to the preset service type.
In the embodiment of the present application, only one node under one cluster node can acquire a distributed lock at the same time, that is, only one master node exists in the next cluster node at the same time.
In the embodiment of the present application, the preset service type node and the cluster node are both permanent nodes, and each node under the cluster node is a temporary node.
In the following embodiments, cluster nodes are all cluster nodes in a preset service type, during a use process, a master node under a cluster node may be disconnected from the cluster node due to an abnormal condition, after receiving a notification of a master node disconnection event, a plurality of slave nodes located under the same cluster node as the master node participate in acquiring competition created state nodes in a dispute, and a distributed lock is acquired by acquiring created state nodes under the cluster node.
S112: and determining a target slave node of the plurality of slave nodes which successfully creates the state node as a new master node.
Wherein, under the condition that a plurality of slave nodes acquire the created state node, the target slave node which is preferentially and successfully created under the cluster node is a new master node under the cluster node, after the state node is successfully created, the other nodes will not compete for creating the state node, but monitor the connection status between the new master node and the cluster node, and only when the new master node is disconnected from the cluster node, the other slave nodes under the cluster node compete to create the state node, and stop competing with the other nodes to create the state node after the state node is successfully created, the other slave nodes which fail to be created continue to wait for the next disconnection between the master node and the cluster node, namely, the slave node which is failed to be created in the plurality of slave nodes continues to monitor the connection condition of the master node and the cluster node, and after receiving the disconnection between the main node and the cluster node, competing again under the cluster node to create the state node.
S113: and writing back the node information of the new main node into the state node.
Indicating the new master node to acquire the distributed lock; the host node information is written back to the state node, and the host node information can be acquired subsequently, or the information of the current host node can be directly determined by directly reading the information in the state node when the host node needs to be monitored.
By adopting the distributed lock coordination method provided by the application, after the disconnection between the master node and the cluster node is detected, other slave nodes under the same preset cluster node as the master node immediately compete to create the state node under the cluster node, the target slave node which is successfully created is determined to be the new master node under the current cluster node, and the node information of the new master node is written into the state node to indicate the new master node to acquire the distributed lock.
In some possible embodiments, the node information of the master node and each slave node respectively includes: the Internet Protocol (IP) address and port information of the interconnection between the node networks, where the port information may be, for example, port number information, etc., it should be understood that the foregoing embodiments are merely exemplary illustrations, and the content included in the specific node information may be flexibly adjusted according to the user needs, and is not limited to the contents provided in the foregoing embodiments.
Optionally, on the basis of the foregoing embodiments, embodiments of the present application may further provide a distributed lock coordination method, and an implementation process of the foregoing method is described as follows with reference to the accompanying drawings. Fig. 5 is a flowchart illustrating a distributed lock coordination method according to another embodiment of the present application, and as shown in fig. 5, before S101, the method may further include:
s104: a plurality of nodes under the cluster node compete for creating a state node.
In the case that no master node exists in the plurality of nodes under the cluster node of the preset service type, for example, in an initial state of the cluster node or in a case that the master node under the cluster node is disconnected, all normally connected nodes under the cluster node compete together to create a state node.
S105: and determining the application node which successfully creates the state node in the plurality of application nodes as a main node, and writing back the node information of the main node to the state node.
And writing back the node information of the main node to the state node to indicate the main node to acquire the distributed lock, namely, the node which successfully competes is the main node under the current cluster type, and the main node can write back the node information of the main node to the state node.
And if the connection state of the master node and the cluster node in the preset service type is disconnected, triggering the current state node to delete the event, and enabling all slave nodes monitoring the state node deletion event under the cluster node to compete again under the cluster node to create the state node.
In the embodiment of the present application, the node type of the state node is also a temporary node, which is created by the master node under the cluster node, and the same cluster node at the same time only includes one state node, and the node that successfully creates the temporary node is the master node in the current cluster, that is, the node that acquires the distributed lock.
Optionally, on the basis of the foregoing embodiments, embodiments of the present application may further provide a distributed lock coordination method, and an implementation process of the foregoing method is described as follows with reference to the accompanying drawings. Fig. 6 is a flowchart illustrating a distributed lock coordination method according to another embodiment of the present application, as shown in fig. 6, before S104, the method further includes:
s101: and creating a preset service type node.
The node of the preset service type may set different preset service type nodes according to different service scenarios, for example, a banking service type node may be set in a banking scenario, or a financial service type node may be set in a financial scenario, and one service scenario may include one or more preset service type nodes.
S102: and creating cluster nodes based on the service type nodes.
The preset service type nodes and the cluster nodes are permanent nodes, only one cluster node exists under one preset service type node, and the cluster nodes are equivalent to the directory nodes in fig. 1 and are used for creating temporary nodes corresponding to the clients under the cluster nodes.
S103: and registering a plurality of nodes under the cluster node.
When each client registers a node to a cluster node, for example, the node of the temporary node type corresponding to each client may be registered based on an API provided by the cluster node through a zookeeper, and the node name of each node corresponding to each client is determined according to its own node IP and port information through each node registered in this registration manner, so that node information corresponding to each node may be directly obtained according to each node, and each node under the service type node may be conveniently monitored subsequently.
In an embodiment of the application, after a master node is disconnected from a cluster node under a preset service type node, a state node deletion event of the master node is triggered to indicate that a plurality of slave nodes compete to create a state node, and since other slave nodes monitor the state of the master node all the time, the slave nodes determine that the current master node is disconnected after monitoring the state node deletion event of the master node; at this time, each slave node can compete to create a state node, and a master node which is successful in creation, i.e. becomes information, is preferentially created to acquire the current distributed lock.
Optionally, on the basis of the foregoing embodiments, embodiments of the present application may further provide a distributed lock coordination method, and an implementation process of the foregoing method is described as follows with reference to the accompanying drawings. Fig. 7 is a flowchart illustrating a distributed lock coordination method according to another embodiment of the present application, as shown in fig. 7, before S111, the method may further include:
s106: and under the condition that the master node is monitored to be disconnected, the plurality of slave nodes wait for the preset acquisition time delay and then compete for creating the state nodes under the preset service type nodes.
Correspondingly, in the preset acquisition time delay, even if the state node is deleted due to disconnection of the master node, the state node can be created again under the cluster node by the master node in the preset acquisition time delay after disconnection is triggered.
The preset acquisition time delay is used for avoiding reducing unnecessary acquisition operations under the condition of some network flash breaks, namely, the problem that master nodes and slave nodes are frequently switched under the abnormal conditions such as network flash breaks is solved, and the unnecessary acquisition operations are reduced.
After the main node is disconnected with the cluster node under the preset service type node, a node deletion event is triggered, the temporary node of the disconnected main node in the cluster node is deleted, and the temporary state nodes created under the cluster nodes are also deleted, but in the embodiment of the present application, within the preset acquisition delay, even if the main node is disconnected, the corresponding node can be created in the cluster node after reconnection, and based on the node, re-creating a state node under the cluster node, within a preset acquisition delay time, even if the master node is disconnected with the cluster node under the preset service type node, other slave nodes can not compete to create the state node, only after the preset acquisition delay time, when the state node does not exist under the current cluster node, the slave node under the cluster node can compete to create the state node.
In the embodiment of the application, when a main node is disconnected from a cluster node under a preset service type node due to an exception, a thread timer is started locally to time whether the current time exceeds a preset acquisition delay time, so that the situation that two main nodes are in the same cluster node is avoided, and if the main node is reconnected and a state node is reestablished before the timer is not finished, the timing is stopped; otherwise, after the timing is finished, other slave nodes compete for creating the state node under the cluster node.
If the master node fails to reestablish the state node, the master node updates the node state from the master node to the slave node, the master node is updated to the node of the slave node, and the master node can compete with other slave nodes to establish the state node in the subsequent lock grabbing process.
By adopting the distributed lock coordination method provided by the application, the node for preemptively establishing the state node is determined to be the main node under the current cluster node in an active lock preempting mode, and after the main node is disconnected with the cluster node, the problem of repeated initialization, data redundancy or double main nodes caused by frequent switching between the main node and the slave node due to network jitter is solved by presetting the setting of the acquired delay time, in addition, because the application is established according to the IP information and the port information of each node when each application node is established, and the main node information is written in the state node, each node included under the current cluster node can be directly checked, and the main node information under the current cluster node can be checked through checking the state node, so that the follow-up monitoring on each node is simpler and more intuitive, and the method provided by the application has a certain fault-tolerant mechanism, the problems can be well solved, and the stability and the performance of the system can be improved.
The following explains a distributed lock coordination apparatus provided in the present application with reference to the accompanying drawings, where the distributed lock coordination apparatus can execute any one of the distributed lock coordination methods in fig. 1 to 7, and specific implementation and beneficial effects of the distributed lock coordination apparatus refer to the above description, which is not described again below.
Fig. 8 is a schematic structural diagram of a distributed lock coordination apparatus according to an embodiment of the present application, and as shown in fig. 8, the apparatus may include: a creation module 201, a determination module 202, and a write back module 203, wherein:
the creating module 201 is configured to, if it is detected that the master node is disconnected from the cluster node under the preset service type node, compete for creating a state node under the cluster node by a plurality of slave nodes under the cluster node.
A determining module 202, configured to determine that a target slave node of the plurality of slave nodes that successfully creates the state node is a new master node.
And the write-back module 203 is configured to write back node information of the new master node to the state node to indicate that the new master node acquires the distributed lock.
Optionally, the creating module 201 is specifically configured to, when monitoring that the master node is disconnected, wait for a preset acquisition delay before competing for creating a state node under the cluster node by the multiple slave nodes.
Optionally, the creating module 201 is specifically configured to create a state node again under the cluster node within a preset acquisition delay after the master node triggers disconnection.
On the basis of the above embodiments, embodiments of the present application may further provide a distributed lock coordination apparatus, and an implementation process of the apparatus shown in fig. 8 is described as follows with reference to the accompanying drawings. Fig. 9 is a schematic structural diagram of a distributed lock coordination apparatus according to another embodiment of the present application, and as shown in fig. 9, the apparatus further includes: an updating module 204, configured to update the state of the slave node to the state of the slave node if the master node fails to create the state node again.
As shown in fig. 9, the apparatus further includes: the triggering module 205 is configured to trigger a state node deletion event of the master node after the master node is disconnected from the cluster node under the preset service type node, so as to indicate that the plurality of slave nodes compete to create the state node.
As shown in fig. 9, the apparatus further includes: and the monitoring module 206 is configured to continue monitoring the state node deletion event of the master node by the slave node that has failed to create among the plurality of slave nodes.
Optionally, the node information of the master node and each slave node respectively includes: node IP address and port information.
Optionally, the creating module 201 is specifically configured to create a state node by a plurality of nodes under the cluster node in a competition.
The determining module 202 is specifically configured to determine that an application node that successfully creates a state node in the multiple nodes is a master node, and write back node information of the master node to the state node to indicate the master node to acquire the distributed lock.
As shown in fig. 9, the apparatus further includes: a registration module 207, wherein:
a creating module 201, configured to create a preset service type node; and creating cluster nodes based on the preset service type nodes, wherein the preset service type nodes and the cluster nodes are permanent nodes.
The registering module 207 is specifically configured to register a plurality of nodes under a cluster node.
The above-mentioned apparatus is used for executing the method provided by the foregoing embodiment, and the implementation principle and technical effect are similar, which are not described herein again.
These above modules may be one or more integrated circuits configured to implement the above methods, such as: one or more Application Specific Integrated Circuits (ASICs), or one or more microprocessors, or one or more Field Programmable Gate Arrays (FPGAs), etc. For another example, when one of the above modules is implemented in the form of a Processing element scheduler code, the Processing element may be a general-purpose processor, such as a Central Processing Unit (CPU) or other processor capable of calling program code. For another example, these modules may be integrated together and implemented in the form of a system-on-a-chip (SOC).
Fig. 10 is a schematic structural diagram of a distributed lock coordination device according to an embodiment of the present application, where the distributed lock coordination device may be integrated in a terminal device or a chip of the terminal device.
As shown in FIG. 10, the distributed lock coordination device includes: a processor 501, a storage medium 502, and a bus 503.
The processor 501 is used for storing a program, and the processor 501 calls the program stored in the storage medium 502 to execute the method embodiment corresponding to fig. 1-7. The specific implementation and technical effects are similar, and are not described herein again.
Optionally, the present application also provides a program product, such as a storage medium, on which a computer program is stored, including a program, which, when executed by a processor, performs embodiments corresponding to the above-described method.
In the several embodiments provided in the present application, it should be understood that the disclosed apparatus and method may be implemented in other ways. For example, the above-described apparatus embodiments are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, or in a form of hardware plus a software functional unit.
The integrated unit implemented in the form of a software functional unit may be stored in a computer readable storage medium. The software functional unit is stored in a storage medium and includes several instructions for enabling a computer device (which may be a personal computer, a server, or a network device) or a processor (processor) to perform some steps of the methods according to the embodiments of the present application. And the aforementioned storage medium includes: a U disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.

Claims (11)

1. A distributed lock coordination method, the method comprising:
if the master node is detected to be disconnected with the cluster node under the preset service type node, a plurality of slave nodes under the cluster node compete to create a state node under the cluster node;
determining a target slave node of the plurality of slave nodes that successfully created the status node as a new master node;
and writing back the node information of the new main node to the state node to indicate the new main node to acquire the distributed lock.
2. The method of claim 1, wherein before the creating of the state node by a plurality of slave nodes under a cluster node contending under the cluster node, the method further comprises:
and under the condition that the slave nodes monitor that the master node is disconnected, waiting for a preset acquisition time delay and then competing under the cluster nodes to create the state nodes.
3. The method of claim 2, wherein the method further comprises:
and the master node reestablishes the state node under the cluster node within the preset acquisition time delay after triggering the disconnection.
4. The method of claim 3, wherein the method further comprises:
and if the master node fails to reestablish the state node, the master node updates the state from the slave node to the slave node.
5. The method of claim 1, wherein before the creating of the state node by a plurality of slave nodes under a cluster node contending under the cluster node, the method further comprises:
and after the master node is disconnected with the cluster node under the preset service type node, triggering a state node deletion event of the master node to indicate the plurality of slave nodes to compete to create the state node.
6. The method of claim 5, wherein the method further comprises:
and the slave node which fails to be created in the plurality of slave nodes continues to monitor the state node deletion event of the master node.
7. The method of claim 1, wherein if it is detected that the master node is disconnected from the cluster node under the preset traffic type node, before a plurality of slave nodes under the cluster node compete for creating a status node under the cluster, the method further comprises:
a plurality of nodes under the cluster node compete to create the state node;
and determining an application node which successfully creates the state node in the plurality of nodes as the main node, and writing back node information of the main node to the state node to indicate the main node to acquire the distributed lock.
8. The method of claim 7, wherein prior to said competing creation of said state node by a plurality of nodes under said cluster node, said method further comprises:
creating the preset service type node;
creating the cluster node based on the preset service type node, wherein the preset service type node and the cluster node are permanent nodes;
registering the plurality of nodes under the cluster node.
9. A distributed lock coordination apparatus, the apparatus comprising: a creation module, a determination module, and a write back module, wherein:
the creating module is used for competing the creation state node under the cluster node by a plurality of slave nodes under the cluster node if the disconnection between the master node and the cluster node under the preset service type node is detected;
the determining module is configured to determine that a target slave node of the plurality of slave nodes that successfully creates the status node is a new master node;
and the write-back module is used for writing back the node information of the new main node into the state node so as to indicate the new main node to acquire the distributed lock.
10. A distributed lock coordination device, characterized in that the device comprises: a processor, a storage medium and a bus, the storage medium storing machine-readable instructions executable by the processor, the processor and the storage medium communicating via the bus when the distributed lock coordination apparatus is operating, the processor executing the machine-readable instructions to perform the method of any of claims 1-8.
11. A storage medium, characterized in that the storage medium has stored thereon a computer program which, when being executed by a processor, performs the method of any of the preceding claims 1-8.
CN202111207036.3A 2021-10-18 2021-10-18 Distributed lock coordination method, device, equipment and storage medium Pending CN113660350A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111207036.3A CN113660350A (en) 2021-10-18 2021-10-18 Distributed lock coordination method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111207036.3A CN113660350A (en) 2021-10-18 2021-10-18 Distributed lock coordination method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN113660350A true CN113660350A (en) 2021-11-16

Family

ID=78494549

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111207036.3A Pending CN113660350A (en) 2021-10-18 2021-10-18 Distributed lock coordination method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN113660350A (en)

Cited By (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114257591A (en) * 2021-12-16 2022-03-29 富盛科技股份有限公司 Networking method and system for weak centralized distributed system
CN114567540A (en) * 2022-02-25 2022-05-31 北京百度网讯科技有限公司 Master/standby node switching method, device, equipment, medium and program product
CN114756356A (en) * 2022-06-14 2022-07-15 恒生电子股份有限公司 Task processing method, work node device, main node device and storage medium
CN115002121A (en) * 2022-08-03 2022-09-02 浩鲸云计算科技股份有限公司 Method for realizing one-master multi-slave Git cluster based on preemption lock
CN115277379A (en) * 2022-07-08 2022-11-01 北京城市网邻信息技术有限公司 Distributed lock disaster tolerance processing method and device, electronic equipment and storage medium
CN115866018A (en) * 2023-02-28 2023-03-28 浪潮电子信息产业股份有限公司 Service processing method and device, electronic equipment and computer readable storage medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
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
US20210136145A1 (en) * 2018-06-30 2021-05-06 Huawei Technologies Co., Ltd. Method for Changing Member in Distributed System and Distributed System
CN112860787A (en) * 2019-11-27 2021-05-28 上海哔哩哔哩科技有限公司 Method for switching master nodes in distributed master-slave system, master node device and storage medium
CN112860386A (en) * 2019-11-27 2021-05-28 上海哔哩哔哩科技有限公司 Method for switching nodes in distributed master-slave system
CN112887367A (en) * 2021-01-11 2021-06-01 华云数据控股集团有限公司 Method, system and computer readable medium for realizing high availability of distributed cluster
WO2021184177A1 (en) * 2020-03-17 2021-09-23 深圳市欢太科技有限公司 Master node selection method and apparatus, electronic device, and storage medium

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20210136145A1 (en) * 2018-06-30 2021-05-06 Huawei Technologies Co., Ltd. Method for Changing Member in Distributed System and Distributed 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
CN112860787A (en) * 2019-11-27 2021-05-28 上海哔哩哔哩科技有限公司 Method for switching master nodes in distributed master-slave system, master node device and storage medium
CN112860386A (en) * 2019-11-27 2021-05-28 上海哔哩哔哩科技有限公司 Method for switching nodes in distributed master-slave system
WO2021184177A1 (en) * 2020-03-17 2021-09-23 深圳市欢太科技有限公司 Master node selection method and apparatus, electronic device, and storage medium
CN112887367A (en) * 2021-01-11 2021-06-01 华云数据控股集团有限公司 Method, system and computer readable medium for realizing high availability of distributed cluster

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114257591A (en) * 2021-12-16 2022-03-29 富盛科技股份有限公司 Networking method and system for weak centralized distributed system
CN114567540A (en) * 2022-02-25 2022-05-31 北京百度网讯科技有限公司 Master/standby node switching method, device, equipment, medium and program product
CN114756356A (en) * 2022-06-14 2022-07-15 恒生电子股份有限公司 Task processing method, work node device, main node device and storage medium
CN115277379A (en) * 2022-07-08 2022-11-01 北京城市网邻信息技术有限公司 Distributed lock disaster tolerance processing method and device, electronic equipment and storage medium
CN115002121A (en) * 2022-08-03 2022-09-02 浩鲸云计算科技股份有限公司 Method for realizing one-master multi-slave Git cluster based on preemption lock
CN115002121B (en) * 2022-08-03 2022-11-11 浩鲸云计算科技股份有限公司 Method for realizing one-master multi-slave Git cluster based on preemption lock
CN115866018A (en) * 2023-02-28 2023-03-28 浪潮电子信息产业股份有限公司 Service processing method and device, electronic equipment and computer readable storage medium

Similar Documents

Publication Publication Date Title
CN113660350A (en) Distributed lock coordination method, device, equipment and storage medium
US7925817B2 (en) Computer system and method for monitoring an access path
WO2018036148A1 (en) Server cluster system
US7996851B2 (en) Locally providing globally consistent information to communications layers
US8484659B2 (en) Distributed processing of binary objects via message queues including a failover safeguard
US9736034B2 (en) System and method for small batching processing of usage requests
CN114787781A (en) System and method for enabling high availability managed failover services
US9992058B2 (en) Redundant storage solution
CN112235136B (en) Network file system backup method, system, terminal and storage medium
CN107666493B (en) Database configuration method and equipment thereof
CN111338773A (en) Distributed timed task scheduling method, scheduling system and server cluster
CN109173270B (en) Game service system and implementation method
CN110324262B (en) Resource preemption method and device
WO2021226781A1 (en) Firewall rule updating method and apparatus, server, and storage medium
CN105373563B (en) Database switching method and device
CN108512753B (en) Method and device for transmitting messages in cluster file system
US20110238959A1 (en) Distributed controller, distributed processing system, and distributed processing method
CN112015595B (en) Master-slave database switching method, computing device and storage medium
US7240088B2 (en) Node self-start in a decentralized cluster
US6990608B2 (en) Method for handling node failures and reloads in a fault tolerant clustered database supporting transaction registration and fault-in logic
CN110620684A (en) Storage double-control split-brain-preventing method, system, terminal and storage medium
Sun et al. Adaptive trade‐off between consistency and performance in data replication
WO2022062347A1 (en) Data transmission method and apparatus, and electronic device and storage medium
CN111885169B (en) Method, system and device for realizing high availability of cloud hard disk service
CN114422335A (en) Communication method, communication device, server and storage medium

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
RJ01 Rejection of invention patent application after publication

Application publication date: 20211116

RJ01 Rejection of invention patent application after publication