Distributed cluster management method and device, lock service cluster and distributed cluster

The application message is sent to each lock service node of the lock service cluster in each data node in the distributed cluster, and the locks are locked after receiving the lock service node of the lock service node that receives a proportion of not less than the preset ratio. The problem of distributed lock management caused by the performance fluctuations of the master node or downtime, which improves the stability of distributed lock management.

CN119357210AActive Publication Date: 2025-01-24BEIJING OCEANBASE TECHNOLOGY CO LTD

Patent Information

Application Number
CN202411944388.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-26
Publication Date
2025-01-24
Estimated Expiration
2044-12-26

AI Technical Summary

Technical Problem

In the prior art, when the main node of the lock service cluster fluctuates or goes down, it will cause chaos or errors in the distributed lock management within the distributed cluster, affecting the performance of the data service.

Method used

In a distributed cluster, each data node sends a lock application message to each lock service node at the lock service cluster, and locks after receiving the lock confirmation message sent by the lock service node that is not less than the preset ratio.

Benefits of technology

By making each lock service node participate in the management of distributed locks, it is ensured that as long as a certain proportion of lock service nodes are in normal status, the management of distributed locks can proceed normally, which improves the stability of distributed lock management and avoids the main Technical issues affecting node status.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119357210A_ABST
    Figure CN119357210A_ABST
Patent Text Reader

Abstract

The invention provides a distributed cluster management method and device, a lock service cluster and a distributed cluster, and the method comprises the steps: sending a lock application message to each lock service node of the lock service cluster, the lock service node is used for sending a lock confirmation message to one of the at least one data node after receiving a lock application message sent by the at least one data node; if a lock confirmation message sent by the lock service nodes with the proportion not smaller than the preset proportion in the lock service cluster is received, locking in the distributed cluster succeeds, and if the lock confirmation message sent by the lock service nodes with the proportion not smaller than the preset proportion in the lock service cluster is not received, locking in the distributed cluster fails.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] One or more embodiments of the present specification relate to the field of database technology, and in particular, to a distributed cluster management method and device, a lock service cluster, and a distributed cluster. Background Art

[0002] The distributed architecture of a database is a database system distributed in multiple physical locations. It stores data in multiple nodes and coordinates and accesses them through network connections. Its main advantages are high availability, scalability, and fault tolerance. For example, a distributed cluster can be formed by setting up a master database and a slave database. The master database can provide write services to the outside world and synchronize data updates to the slave database. For another example, multiple replicas can be set up in a database (such as a master database or a slave database) to form a distributed cluster. The master replica among multiple replicas can provide services to the outside world and synchronize data updates to other replicas. In the database field, the role management of data nodes in the above-mentioned different forms of distributed clusters is often performed through the management of distributed locks, such as selecting a master database or a master replica in a distributed cluster.

[0003] However, in the related art, the lock service cluster used to manage the distributed locks often selects a master node from multiple lock service nodes, and then the master node manages the roles of the data nodes in the distributed cluster. This method relies on the stable performance of the master node. That is, once the performance of the master node fluctuates or even crashes, the management of the distributed locks in the distributed cluster will be chaotic or even wrong, thereby affecting the data service performance of the distributed cluster. Summary of the invention

[0004] In view of this, one or more embodiments of the present specification provide a data system, a data management method and device, an electronic device, and a storage medium.

[0005] To achieve the above objectives, one or more embodiments of this specification provide the following technical solutions: According to a first aspect of one or more embodiments of this specification, a distributed lock management method is proposed, which is applied to any data node of a distributed cluster. The method includes: Sending a lock application message to each lock service node of the lock service cluster, wherein the lock service node is used to send a lock confirmation message to one of the at least one data node after receiving the lock application message sent by the at least one data node; If lock confirmation messages are received from lock service nodes in the lock service cluster that are not less than a preset proportion, locking is successful in the distributed cluster; if lock confirmation messages are not received from lock service nodes in the lock service cluster that are not less than a preset proportion, locking fails in the distributed cluster.

[0006] In a possible embodiment of the present specification, the lock application message includes a node identifier and a priority of the data node; The lock service node is used to send a lock confirmation message to a data node with the highest priority among the at least one data node after receiving a lock application message sent by the at least one data node.

[0007] In a possible embodiment of the present specification, sending a lock request message to each lock service node of the lock service cluster includes: If the time between the current time and the last time the lock request message was sent is the first time, then the lock request message is sent to each lock service node in the lock service cluster.

[0008] In a possible embodiment of the present specification, the lock service node is used to send a lock confirmation message to the in-place node when receiving a lock request message sent by the in-place node before the lease of the in-place node expires, wherein the in-place node is the data node currently holding the lock, and the duration of the lease is greater than the first duration.

[0009] In a possible embodiment of the present specification, the lock application message includes a node identifier and a priority of the data node; The lock service node is used to record the received lock application message after receiving the lock application message, or update the recorded lock application message of the same data node based on the received lock application message; The lock service node is used to delete the lock application message that has not been updated for a second time period in the recorded lock application message, where the second time period is greater than the first time period; The lock service node is used to send a lock confirmation message to the data node corresponding to the lock application message with the highest priority in the recorded lock application messages if the lock service node has not received the lock application message sent by the in-place node before the lease of the in-place node expires, wherein the in-place node is the data node currently holding the lock, and the lease duration is greater than the first duration.

[0010] In a possible embodiment of the present specification, the distributed cluster includes a first database and a second database, wherein the database that is successfully locked in the distributed cluster obtains the master database identity, and the database that fails to be locked in the distributed cluster obtains the standby database identity; or, The distributed cluster includes multiple replicas, wherein a replica that is successfully locked in the distributed cluster obtains a master replica role, and a replica that fails to be locked in the distributed cluster obtains a common replica role.

[0011] In a possible embodiment of the present specification, sending a lock request message to each lock service node of the lock service cluster includes: Sending a lock application message to a lock service node in a lock service cluster, so that the lock service node receiving the lock application message forwards the lock application message to each of the remaining lock service nodes; or, The lock request message is sent to each lock service node in the lock service cluster.

[0012] According to a second aspect of one or more embodiments of this specification, a distributed lock management method is proposed, which is applied to any lock service node of a lock service cluster, and the method includes: Receive a lock request message sent by at least one data node in the distributed cluster; Sending a lock confirmation message to one of the at least one data node; Among them, the data node is used to: if the lock confirmation message sent by the lock service nodes in the lock service cluster is not less than a preset proportion, the locking in the distributed cluster is successful; if the lock confirmation message sent by the lock service nodes in the lock service cluster is not less than a preset proportion, the locking in the distributed cluster fails.

[0013] According to a third aspect of one or more embodiments of this specification, a distributed lock management device is proposed, which is applied to any data node of a distributed cluster, and the device includes: An application module, configured to send a lock application message to each lock service node of the lock service cluster, wherein the lock service node is configured to send a lock confirmation message to one of the at least one data node after receiving the lock application message sent by the at least one data node; The locking module is used to successfully lock the distributed cluster if lock confirmation messages are received from lock service nodes of no less than a preset proportion in the lock service cluster; and to fail to lock the distributed cluster if lock confirmation messages are not received from lock service nodes of no less than a preset proportion in the lock service cluster.

[0014] According to a fourth aspect of one or more embodiments of this specification, a distributed lock management device is proposed, which is applied to any lock service node of a lock service cluster, and the device includes: A receiving module, used to receive a lock request message sent by at least one data node in a distributed cluster; A voting module, configured to send a lock confirmation message to one of the at least one data node; Among them, if the data node receives lock confirmation messages sent by lock service nodes in the lock service cluster that are not less than a preset proportion, locking is successful in the distributed cluster; if the data node does not receive lock confirmation messages sent by lock service nodes in the lock service cluster that are not less than a preset proportion, locking fails in the distributed cluster.

[0015] According to a fifth aspect of one or more embodiments of this specification, a lock service cluster is provided, wherein the lock service cluster includes a plurality of lock service nodes; The lock service node is used to send a lock confirmation message to one of the at least one data node after receiving a lock application message sent by the at least one data node.

[0016] According to a sixth aspect of one or more embodiments of this specification, a distributed cluster is provided, wherein the distributed cluster includes a plurality of data nodes, and the data nodes are used to: Send a lock request message to each lock service node in the lock service cluster. If lock confirmation messages are received from lock service nodes in the lock service cluster that are not less than a preset ratio, locking is successful in the distributed cluster; If the lock confirmation message sent by the lock service nodes in the lock service cluster that is not less than the preset ratio is not received, locking fails in the distributed cluster.

[0017] According to a seventh aspect of one or more embodiments of the present specification, a computer program product is proposed, comprising a computer program / instruction, which implements the steps of the method described in the first aspect or the second aspect when executed by a processor.

[0018] According to an eighth aspect of one or more embodiments of this specification, an electronic device is provided, including: processor; a memory for storing processor-executable instructions; The processor implements the method as described in the first aspect or the second aspect by running the executable instructions.

[0019] According to a ninth aspect of one or more embodiments of the present specification, a computer-readable storage medium is provided, on which computer instructions are stored, and when the instructions are executed by a processor, the steps of the method described in the first aspect or the second aspect are implemented.

[0020] The technical solutions provided by the embodiments of this specification may have the following beneficial effects: In the distributed lock management method provided in the embodiments of this specification, each data node in the distributed cluster can send a lock application message to each lock service node in the lock service cluster, and the lock is successfully locked after receiving a lock confirmation message sent by no less than a preset proportion of lock service nodes in the lock service cluster. Compared with the method of managing distributed locks by the master node in the lock service cluster in the related art, this method enables each lock service node in the lock service cluster to participate in the management of distributed locks in the distributed cluster, and as long as a certain proportion of the lock service nodes are in normal state, the normal management of the distributed lock can be maintained, which improves the stability of the distributed lock management and avoids the technical problem that the distributed lock management is affected by the master node state. BRIEF DESCRIPTION OF THE DRAWINGS

[0021] Figure 1 is a schematic diagram of a distributed cluster provided by an exemplary embodiment.

[0022] Figure 2 It is a flowchart of a distributed lock management method applied to any data node provided by an exemplary embodiment.

[0023] Figure 3 It is a schematic diagram of renewal of a distributed lock provided by an exemplary embodiment.

[0024] Figure 4 It is a schematic diagram of the transfer of a distributed lock provided by an exemplary embodiment.

[0025] Figure 5 It is a flowchart of a distributed lock management method applied to any lock service node provided by an exemplary embodiment.

[0026] Figure 6 It is a structural schematic diagram of a device provided by an exemplary embodiment.

[0027] Figure 7 It is a block diagram of a distributed lock management device applied to any data node provided by an exemplary embodiment.

[0028] Figure 8 It is a block diagram of a distributed lock management device applied to any data node provided by an exemplary embodiment. DETAILED DESCRIPTION

[0029] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with one or more embodiments of this specification. Instead, they are merely examples of devices and methods consistent with some aspects of one or more embodiments of this specification as detailed in the appended claims.

[0030] It should be noted that: in other embodiments, the steps of the corresponding method are not necessarily performed in the order shown and described in this specification. In some other embodiments, the steps included in the method may be more or less than those described in this specification. In addition, a single step described in this specification may be decomposed into multiple steps for description in other embodiments; and multiple steps described in this specification may be combined into a single step for description in other embodiments.

[0031] First, some concepts involved in this specification are explained.

[0032] Distributed lock: A distributed lock is a mechanism that provides highly reliable lock services in a distributed manner. It ensures that a single applicant has exclusive access to the lock service to avoid anomalies caused by certain resources being used or modified by multiple users at the same time.

[0033] Primary copy: A single data shard in a distributed system usually contains multiple copies, of which only one copy provides modification services for the shard, called the primary copy.

[0034] Lease: The validity period of a lock holder, including the start time and duration (or end time).

[0035] Based on the above technical problems in the background technology, at least one embodiment of the present specification provides a distributed lock management method, which can enable each lock service node in the lock service cluster to participate in the distributed lock management of the distributed cluster, thereby improving the stability of the distributed lock management and avoiding the problem of poor stability caused by the distributed lock management in the related technology due to the influence of the main node in the lock service cluster.

[0036] The purpose of this method is to manage distributed locks in a distributed cluster. A distributed cluster includes multiple data nodes. For example, please refer to the attached Figure 1 The distributed cluster includes two data nodes, a first database and a second database, wherein the database that is successfully locked in the distributed cluster obtains the master database identity, and the database that fails to be locked in the distributed cluster obtains the backup database identity. It should be understood that the first database and the second database can be stand-alone databases, or database clusters (see Appendix Figure 1 The first database and the second database in the distributed cluster are both database clusters), and the two can be set in different geographical locations, such as different provinces, so as to improve the security of data backup. For another example, the distributed cluster includes multiple replicas (each replica is a data node), wherein the replica that successfully locks in the distributed cluster obtains the master replica role, and the replica that fails to lock in the distributed cluster obtains the ordinary replica role. It should be understood that the multiple replicas can be multiple replicas of a certain data shard, for example, a certain shard in the above-mentioned attachment Figure 1 If each database instance of the first database in the cluster has a replica, then these replicas form a distributed cluster.

[0037] The method performs distributed lock management of distributed clusters based on a lock service cluster. The lock service cluster may include multiple lock service nodes. The lock service cluster may perform distributed lock management on different distributed clusters at the same time.

[0038] Next, this method is introduced in detail from the data node side in the distributed cluster and the lock service node side in the lock service cluster.

[0039] Please refer to the attached Figure 2 , which exemplarily shows the process of the distributed lock management method applied to any data node in a distributed cluster, including steps S201 to S202.

[0040] In step S201, a lock application message is sent to each lock service node of the lock service cluster, wherein the lock service node is used to send a lock confirmation message to one of the at least one data node after receiving the lock application message sent by the at least one data node.

[0041] Exemplarily, a lock request message can be sent to each lock service node in the lock service cluster in the following manner: sending the lock request message to a lock service node in the lock service cluster, so that the lock service node that receives the lock request message forwards the lock request message to each remaining lock service node; or, sending the lock request message to each lock service node in the lock service cluster.

[0042] Exemplarily, the lock request message includes the node identifier and priority of the data node; for example, each data node in the distributed cluster is pre-assigned with a priority, such as assigning a priority according to a geographical location. The lock service node is used to send a lock confirmation message to a data node with the highest priority among the at least one data node after receiving a lock request message sent by at least one data node.

[0043] This example allows the data node with the highest priority to hold the distributed lock, which not only makes the distributed lock management more orderly, but also improves the data service quality of the distributed cluster by providing write services to the outside through the data node with the highest priority. For example, the data node in the main computer room has the highest priority, while the data node in the backup computer room has the lowest priority. The main computer room can provide better data service performance with its advantages in all aspects.

[0044] In step S202, if lock confirmation messages are received from lock service nodes of no less than a preset proportion in the lock service cluster, locking is successful in the distributed cluster; if lock confirmation messages are not received from lock service nodes of no less than a preset proportion in the lock service cluster, locking fails in the distributed cluster.

[0045] Among them, the preset ratio can be 50% or other proportions.

[0046] For example, if the distributed cluster includes a first database and a second database, the database that is successfully locked in the distributed cluster obtains the master database identity, and the database that fails to be locked in the distributed cluster obtains the standby database identity.

[0047] For another example, if the distributed cluster includes multiple replicas, the replica that is successfully locked in the distributed cluster obtains the role of the master replica, and the replica that fails to be locked in the distributed cluster obtains the role of the ordinary replica.

[0048] In the distributed lock management method provided in the embodiments of this specification, each data node in the distributed cluster can send a lock application message to each lock service node in the lock service cluster, and the lock is successfully locked after receiving a lock confirmation message sent by no less than a preset proportion of lock service nodes in the lock service cluster. Compared with the method of managing distributed locks by the master node in the lock service cluster in the related art, this method enables each lock service node in the lock service cluster to participate in the management of distributed locks in the distributed cluster, and as long as a certain proportion of the lock service nodes are in normal state, the normal management of the distributed lock can be maintained, which improves the stability of the distributed lock management and avoids the technical problem that the distributed lock management is affected by the master node state.

[0049] It should be understood that when a distributed cluster applies for a distributed lock for the first time, the lock service node may wait for a certain period of time to receive all lock application messages issued in the distributed cluster, and then randomly or according to priority select a data node to which a lock application message belongs to send a lock confirmation message. For example, a distributed cluster consisting of a first database and a second database may apply for a distributed lock for the first time when the system is initialized or the system as a whole recovers from a failure.

[0050] Distributed locks can have leases, that is, each distributed lock allocated has a validity period, which can avoid distributed cluster failures and downtime caused by failures of the partition node holding the distributed lock.

[0051] Based on the lease design of distributed locks, in some embodiments of the present disclosure, the above-mentioned purpose can be achieved by means of periodic detection, that is, whether the data node holding the distributed lock in the distributed cluster is in a normal state, and when the data node holding the distributed lock is in an abnormal state, the distributed lock is transferred to other data nodes in time to ensure the performance stability of the distributed cluster.

[0052] In this embodiment, the above step S201 can be performed in the following manner: if the time between the current moment and the last time a lock application message was sent is the first time, a lock application message is sent to each lock service node in the lock service cluster. That is, the lock application message is periodically sent to each lock service node in the lock service cluster at intervals of the first time.

[0053] Furthermore, when a distributed cluster applies for a distributed lock for the first time, the lock service node may wait twice the first time period to receive all lock application messages issued in the distributed cluster, and then randomly or based on priority select a data node to which a lock application message belongs to send a lock confirmation message.

[0054] In this embodiment, the lock application message may include the node identifier and priority of the data node; the lock service node is used to record the received lock application message after receiving the lock application message, or update the recorded lock application message of the same data node based on the received lock application message; the lock service node is used to delete the lock application message that has not been updated for a second time period in the recorded lock application message, and the second time period is greater than the first time period. That is, the lock service node can record the lock application message sent by a data node after receiving it, and if the lock application message sent by the data node is received again within the second time period, the previously recorded lock application message is replaced with the newly received lock application message (in fact, if the content of the application message sent twice is the same, the timing result of the recorded lock application message can be directly cleared to zero); if the lock application message sent by the data node is not received again within the second time period, the recorded lock application message is deleted.

[0055] Furthermore, the lock service node may send a lock confirmation message to the in-place node if it receives a lock request message sent by the in-place node before the lease of the in-place node expires, wherein the in-place node is the data node currently holding the lock and the lease duration is greater than the first duration.

[0056] Furthermore, the lock service node is used to send a lock confirmation message to the data node corresponding to the lock application message with the highest priority in the recorded lock application messages if the lock application message sent by the in-place node is not received before the lease of the in-place node expires, wherein the in-place node is the data node currently holding the lock. Preferably, the duration of the lease is greater than the second duration.

[0057] Next, a more specific example is used to illustrate the effect of this embodiment.

[0058] The first duration is 5 seconds, the second duration is 6 seconds, and the duration of the lease is 10 seconds.

[0059] The distributed cluster includes a first database and a second database. After the distributed cluster applies for the distributed lock for the first time, the first database and the second database periodically send lock application messages to each lock service node in the lock service cluster at intervals of 5 seconds. After waiting for 10 seconds, each lock service node sends a lock confirmation message to the first database, and the first database is locked successfully and obtains the role of the master database.

[0060] Please refer to the attached Figure 3 When the first database is normal, after the lease lasts for 5 seconds, the lock service node receives the lock application message sent by the first database and the lock application message sent by the second database, and then sends a lock confirmation message to the first database, thereby maintaining the first database continuously locked.

[0061] Please refer to the attached Figure 4 When the first database is abnormal, the lock service node does not receive the lock application message sent by the first database after the lease lasts for 5 seconds, but receives the lock application message sent by the second database. At this time, the lock service node does not send a lock confirmation message. After the lease lasts for 6 seconds, the lock service node deletes the lock application message of the first database from the recorded lock application message of the first database and the lock application message of the second database. After the lease lasts for 10 seconds, the lock service node sends a lock confirmation message to the second database to which the only lock application message recorded by it belongs, so that the distributed lock is transferred from the first database to the second database in time.

[0062] This embodiment achieves the stability and security of distributed locks by setting data nodes to periodically send lock application messages, lock service nodes to record lock application messages and clean up expired lock application messages, and give priority to voting for in-place nodes. The so-called stability means that the distributed lock is kept in a partition node as much as possible without changing, and the so-called security means that the distributed lock can be transferred to a normal partition node in time when the in-place node is abnormal, thereby improving the service stability of the distributed cluster.

[0063] Please refer to the attached Figure 5, which exemplarily shows the process of the distributed lock management method applied to any lock service node in the lock service cluster, including steps S501 to S502.

[0064] In step S501, a lock request message sent by at least one data node in a distributed cluster is received; In step S502, a lock confirmation message is sent to one of the at least one data node; Among them, the data node is used to: if the lock confirmation message sent by the lock service nodes in the lock service cluster is not less than a preset proportion, the locking in the distributed cluster is successful; if the lock confirmation message sent by the lock service nodes in the lock service cluster is not less than a preset proportion, the locking in the distributed cluster fails.

[0065] Exemplarily, the lock application message includes the node identifier and priority of the data node; the step S502 may be performed in the following manner: A lock confirmation message is sent to a data node with the highest priority among the at least one data node.

[0066] Exemplarily, the data node periodically sends a lock request message to each lock service node of the lock service cluster at intervals of the first duration; step S502 may be performed in the following manner: If a lock request message sent by the in-place node is received before the lease of the in-place node expires, the in-place node sends a lock confirmation message, wherein the in-place node is the data node currently holding the lock and the lease duration is greater than the first duration.

[0067] Exemplarily, the method further includes: If a lock request message is received, the received lock request message is recorded or the recorded lock request message of the same data node is updated based on the received lock request message; Delete the lock application messages in the recorded lock application messages that have not been updated for a second time period, wherein the second time period is greater than the first time period; The step S502 may be performed in the following manner: If the lock application message sent by the in-place node is not received before the lease of the in-place node expires, a lock confirmation message is sent to the data node corresponding to the lock application message with the highest priority in the recorded lock application messages, wherein the in-place node is the data node currently holding the lock, and the lease duration is greater than the first duration.

[0068] More details about the above steps and embodiments have been fully and detailed introduced in the method on the data node side, and will not be repeated here.

[0069] At least one embodiment of this specification further provides a lock service cluster, wherein the lock service cluster includes a plurality of lock service nodes; The lock service node is used to send a lock confirmation message to one of the at least one data node after receiving a lock application message sent by the at least one data node.

[0070] Exemplarily, the lock service node is used to send a lock confirmation message to a data node with the highest priority among the at least one data node after receiving a lock request message sent by the at least one data node.

[0071] Exemplarily, the lock application message includes the node identifier and priority of the data node; Each data node in the distributed cluster periodically sends a lock request message to each lock service node in the lock service cluster at intervals of a first duration; The lock service node is used to record the received lock application message after receiving the lock application message, or update the recorded lock application message of the same data node based on the received lock application message; The lock service node is used to delete the lock application message that has not been updated for a second time period in the recorded lock application message, where the second time period is greater than the first time period; The lock service node is used to send a lock confirmation message to the in-place node when the lock application message sent by the in-place node is received before the lease of the in-place node expires, and to send a lock confirmation message to the data node corresponding to the lock application message with the highest priority in the recorded lock application messages when the lock application message sent by the in-place node is not received before the lease of the in-place node expires, wherein the in-place node is the data node currently holding the lock, and the duration of the lease is greater than the first duration.

[0072] More details about the above embodiments have been fully and detailed introduced in the method on the data node side, and will not be repeated here.

[0073] At least one embodiment of the present specification further provides a distributed cluster, wherein the distributed cluster includes a plurality of data nodes, and the data nodes are used to: Send a lock request message to each lock service node in the lock service cluster. If lock confirmation messages are received from lock service nodes in the lock service cluster that are not less than a preset ratio, locking is successful in the distributed cluster; If the lock confirmation message sent by the lock service nodes in the lock service cluster that is not less than the preset ratio is not received, locking fails in the distributed cluster.

[0074] Exemplarily, the data node is used to periodically send a lock request message to each lock service node in the lock service cluster at intervals of a first duration.

[0075] More details about the above embodiments have been fully and detailed introduced in the method on the data node side, and will not be repeated here.

[0076] Figure 6 is a schematic structural diagram of a device provided by an exemplary embodiment. Figure 6 At the hardware level, the device includes a processor 602, an internal bus 604, a network interface 606, a memory 608, and a non-volatile memory 610, and may also include hardware required for other tasks. One or more embodiments of this specification may be implemented based on software, such as the processor 602 reading the corresponding computer program from the non-volatile memory 610 into the memory 608 and then running it. Of course, in addition to the software implementation, one or more embodiments of this specification do not exclude other implementations, such as logic devices or a combination of software and hardware, etc., that is, the execution subject of the following processing flow is not limited to each logic unit, but can also be hardware or logic devices.

[0077] Please refer to Figure 7 , the distributed lock management device can be applied to Figure 6 The data node running on the device shown in the figure is used to implement the technical solution of this specification. The data node is any partition node in the distributed cluster, and the management device of the distributed lock may include: The application module 701 is used to send a lock application message to each lock service node of the lock service cluster, wherein the lock service node is used to send a lock confirmation message to one of the at least one data node after receiving the lock application message sent by the at least one data node; The locking module 702 is used to successfully lock the distributed cluster if lock confirmation messages are received from lock service nodes of no less than a preset proportion in the lock service cluster; if lock confirmation messages are not received from lock service nodes of no less than a preset proportion in the lock service cluster, locking fails in the distributed cluster.

[0078] In a possible embodiment of the present specification, the lock application message includes a node identifier and a priority of the data node; The lock service node is used to send a lock confirmation message to a data node with the highest priority among the at least one data node after receiving a lock application message sent by the at least one data node.

[0079] In a possible embodiment of this specification, the application module is used to: If the time between the current time and the last time the lock request message was sent is the first time, then the lock request message is sent to each lock service node in the lock service cluster.

[0080] In a possible embodiment of the present specification, the lock service node is used to send a lock confirmation message to the in-place node when receiving a lock request message sent by the in-place node before the lease of the in-place node expires, wherein the in-place node is the data node currently holding the lock, and the duration of the lease is greater than the first duration.

[0081] In a possible embodiment of the present specification, the lock application message includes a node identifier and a priority of the data node; The lock service node is used to record the received lock application message after receiving the lock application message, or update the recorded lock application message of the same data node based on the received lock application message; The lock service node is used to delete the lock application message that has not been updated for a second time period in the recorded lock application message, where the second time period is greater than the first time period; The lock service node is used to send a lock confirmation message to the data node corresponding to the lock application message with the highest priority in the recorded lock application messages if the lock service node has not received the lock application message sent by the in-place node before the lease of the in-place node expires, wherein the in-place node is the data node currently holding the lock, and the lease duration is greater than the first duration.

[0082] In a possible embodiment of the present specification, the distributed cluster includes a first database and a second database, wherein the database that is successfully locked in the distributed cluster obtains the master database identity, and the database that fails to be locked in the distributed cluster obtains the standby database identity; or, The distributed cluster includes multiple replicas, wherein a replica that is successfully locked in the distributed cluster obtains a master replica role, and a replica that fails to be locked in the distributed cluster obtains a common replica role.

[0083] In a possible embodiment of this specification, the application module is used to: Sending a lock application message to a lock service node in a lock service cluster, so that the lock service node receiving the lock application message forwards the lock application message to each of the remaining lock service nodes; or, The lock request message is sent to each lock service node in the lock service cluster.

[0084] Please refer to Figure 8 , the distributed lock management device can be applied to Figure 6The lock service node running on the device shown in the figure implements the technical solution of this specification. The lock service node is any lock service node in the lock service cluster, and the distributed lock management device may include: The receiving module 801 is used to receive a lock request message sent by at least one data node in the distributed cluster; A voting module 802 is configured to send a lock confirmation message to one of the at least one data node; Among them, if the data node receives lock confirmation messages sent by lock service nodes in the lock service cluster that are not less than a preset proportion, locking is successful in the distributed cluster; if the data node does not receive lock confirmation messages sent by lock service nodes in the lock service cluster that are not less than a preset proportion, locking fails in the distributed cluster.

[0085] In a possible embodiment of the present specification, the lock application message includes a node identifier and a priority of the data node; The voting module is used to: A lock confirmation message is sent to a data node with the highest priority among the at least one data node.

[0086] In a possible embodiment of the present specification, the data node periodically sends a lock request message to each lock service node of the lock service cluster at intervals of a first duration; The voting module is used to: If a lock request message sent by the in-place node is received before the lease of the in-place node expires, the in-place node sends a lock confirmation message, wherein the in-place node is the data node currently holding the lock and the lease duration is greater than the first duration.

[0087] In a possible embodiment of the present specification, the device further includes a message management module, which is used to: If a lock request message is received, the received lock request message is recorded or the recorded lock request message of the same data node is updated based on the received lock request message; Delete the lock application messages in the recorded lock application messages that have not been updated for a second time period, wherein the second time period is greater than the first time period; The voting module is used to: If the lock application message sent by the in-place node is not received before the lease of the in-place node expires, a lock confirmation message is sent to the data node corresponding to the lock application message with the highest priority in the recorded lock application messages, wherein the in-place node is the data node currently holding the lock, and the lease duration is greater than the first duration.

[0088] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer, which may be in the form of a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email transceiver, a game console, a tablet computer, a wearable device or a combination of any of these devices.

[0089] In a typical configuration, a computer includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0090] Memory may include non-permanent storage in a computer-readable medium, in the form of random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium.

[0091] Computer-readable media include permanent and non-permanent, removable and non-removable media that can be used to store information by any method or technology. Information can be computer-readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, disk storage, quantum memory, graphene-based storage media or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include temporary computer-readable media (transitory media), such as modulated data signals and carrier waves.

[0092] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0093] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.

[0094] The terms used in one or more embodiments of this specification are only for the purpose of describing specific embodiments, and are not intended to limit one or more embodiments of this specification. The singular forms of "a", "said" and "the" used in one or more embodiments of this specification and the appended claims are also intended to include plural forms, unless the context clearly indicates other meanings. It should also be understood that the term "and / or" used herein refers to and includes any or all possible combinations of one or more associated listed items.

[0095] The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this manual are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0096] It should be understood that although the terms first, second, third, etc. may be used to describe various information in one or more embodiments of this specification, these information should not be limited to these terms. These terms are only used to distinguish the same type of information from each other. For example, without departing from the scope of one or more embodiments of this specification, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the word "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".

[0097] The above description is merely a preferred embodiment of one or more embodiments of the present specification and is not intended to limit one or more embodiments of the present specification. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of one or more embodiments of the present specification shall be included in the scope of protection of one or more embodiments of the present specification.

Claims

1. A distributed lock management method, applied to any data node of a distributed cluster, the method comprising: Sending a lock application message to each lock service node of the lock service cluster, wherein the lock service node is used to send a lock confirmation message to one of the at least one data node after receiving the lock application message sent by the at least one data node; If lock confirmation messages are received from lock service nodes in the lock service cluster that are not less than a preset proportion, locking is successful in the distributed cluster; if lock confirmation messages are not received from lock service nodes in the lock service cluster that are not less than a preset proportion, locking fails in the distributed cluster.

2. According to the distributed lock management method of claim 1, the lock application message includes the node identification and priority of the data node; The lock service node is used to send a lock confirmation message to a data node with the highest priority among the at least one data node after receiving a lock application message sent by the at least one data node.

3. The distributed lock management method according to claim 1, wherein the step of sending a lock request message to each lock service node in the lock service cluster comprises: If the time between the current time and the last time the lock request message was sent is the first time, then the lock request message is sent to each lock service node in the lock service cluster.

4. The distributed lock management method according to claim 3, wherein the lock service node is used to send a lock confirmation message to the in-place node when receiving a lock application message sent by the in-place node before the lease of the in-place node expires, wherein: The in-place node is a data node that currently holds the lock, and the duration of the lease is greater than the first duration.

5. The distributed lock management method according to claim 3, wherein the lock application message includes a node identifier and a priority of the data node; The lock service node is used to record the received lock application message after receiving the lock application message, or update the recorded lock application message of the same data node based on the received lock application message; The lock service node is used to delete the lock application message that has not been updated for a second time period in the recorded lock application message, where the second time period is greater than the first time period; The lock service node is used to send a lock confirmation message to the data node corresponding to the lock application message with the highest priority in the recorded lock application messages when the lock application message sent by the in-place node is not received before the lease of the in-place node expires, wherein: The in-place node is a data node that currently holds the lock, and the duration of the lease is greater than the first duration.

6. The distributed lock management method according to claim 1, wherein the distributed cluster comprises a first database and a second database, wherein: The database that successfully locks in the distributed cluster obtains the master database identity, and the database that fails to lock in the distributed cluster obtains the backup database identity; or, The distributed cluster includes multiple replicas, wherein a replica that is successfully locked in the distributed cluster obtains a master replica role, and a replica that fails to be locked in the distributed cluster obtains a common replica role.

7. The distributed lock management method according to claim 1, wherein the step of sending a lock request message to each lock service node in the lock service cluster comprises: Sending a lock application message to a lock service node in a lock service cluster, so that the lock service node receiving the lock application message forwards the lock application message to each of the remaining lock service nodes; or, The lock request message is sent to each lock service node in the lock service cluster.

8. A distributed lock management method, applied to any lock service node of a lock service cluster, the method comprising: Receive a lock request message sent by at least one data node in the distributed cluster; Sending a lock confirmation message to one of the at least one data node; Among them, the data node is used to: if the lock confirmation message sent by the lock service nodes in the lock service cluster is not less than a preset proportion, the locking in the distributed cluster is successful; if the lock confirmation message sent by the lock service nodes in the lock service cluster is not less than a preset proportion, the locking in the distributed cluster fails.

9. The distributed lock management method according to claim 8, wherein the lock application message includes a node identifier and a priority of the data node; The sending a lock confirmation message to one of the at least one data node comprises: A lock confirmation message is sent to a data node with the highest priority among the at least one data node.

10. The distributed lock management method according to claim 9, wherein the data node periodically sends a lock request message to each lock service node of the lock service cluster at intervals of the first time length; The sending a lock confirmation message to one of the at least one data node comprises: If a lock request message sent by the in-place node is received before the lease of the in-place node expires, the in-place node sends a lock confirmation message, wherein the in-place node is the data node currently holding the lock and the lease duration is greater than the first duration.

11. The distributed lock management method according to claim 10, further comprising: If a lock request message is received, the received lock request message is recorded or the recorded lock request message of the same data node is updated based on the received lock request message; Delete the lock application messages in the recorded lock application messages that have not been updated for a second time period, wherein the second time period is greater than the first time period; The sending a lock confirmation message to one of the at least one data node comprises: If the lock application message sent by the in-place node is not received before the lease of the in-place node expires, a lock confirmation message is sent to the data node corresponding to the lock application message with the highest priority in the recorded lock application messages, wherein the in-place node is the data node currently holding the lock, and the lease duration is greater than the first duration.

12. A distributed lock management device, applied to any data node of a distributed cluster, the device comprising: An application module, configured to send a lock application message to each lock service node of the lock service cluster, wherein the lock service node is configured to send a lock confirmation message to one of the at least one data node after receiving the lock application message sent by the at least one data node; The locking module is used to successfully lock the distributed cluster if lock confirmation messages are received from lock service nodes of no less than a preset proportion in the lock service cluster; and to fail to lock the distributed cluster if lock confirmation messages are not received from lock service nodes of no less than a preset proportion in the lock service cluster.

13. The distributed lock management device according to claim 12, wherein the distributed cluster comprises a first database and a second database, wherein: The database that successfully locks in the distributed cluster obtains the master database identity, and the database that fails to lock in the distributed cluster obtains the backup database identity; or, The distributed cluster includes multiple replicas, wherein a replica that is successfully locked in the distributed cluster obtains a master replica role, and a replica that fails to be locked in the distributed cluster obtains a common replica role.

14. A distributed lock management device, applied to any lock service node of a lock service cluster, the device comprising: A receiving module, used to receive a lock request message sent by at least one data node in a distributed cluster; A voting module, configured to send a lock confirmation message to one of the at least one data node; Among them, if the data node receives lock confirmation messages sent by lock service nodes in the lock service cluster that are not less than a preset proportion, locking is successful in the distributed cluster; if the data node does not receive lock confirmation messages sent by lock service nodes in the lock service cluster that are not less than a preset proportion, locking fails in the distributed cluster.

15. The distributed lock management device according to claim 14, wherein the lock application message includes a node identifier and a priority of the data node; The voting module is used to: A lock confirmation message is sent to a data node with the highest priority among the at least one data node.

16. The distributed lock management device according to claim 15, wherein the data node periodically sends a lock request message to each lock service node of the lock service cluster at intervals of the first time length; The voting module is used to: If the in-place node receives a lock request message sent by the in-place node before the lease of the in-place node expires, the in-place node sends a lock confirmation message, wherein: The in-place node is a data node that currently holds the lock, and the duration of the lease is greater than the first duration.

17. The distributed lock management device according to claim 16, further comprising a message management module, configured to: If a lock request message is received, the received lock request message is recorded or the recorded lock request message of the same data node is updated based on the received lock request message; Delete the lock application messages recorded in the lock application messages that have not been updated for a second period of time, where: The second duration is greater than the first duration; The voting module is used to: If the lock application message sent by the in-place node is not received before the lease of the in-place node expires, a lock confirmation message is sent to the data node corresponding to the lock application message with the highest priority in the recorded lock application messages, wherein the in-place node is the data node currently holding the lock, and the lease duration is greater than the first duration.

18. A lock service cluster, the lock service cluster comprising a plurality of lock service nodes; in, The lock service node is used to send a lock confirmation message to one of the at least one data node after receiving a lock application message sent by the at least one data node.

19. The lock service cluster according to claim 18, wherein the lock service node is used to send a lock confirmation message to a data node with the highest priority among the at least one data node after receiving a lock request message sent by the at least one data node.

20. The lock service cluster according to claim 18, wherein the lock request message includes a node identifier and a priority of the data node; Each data node in the distributed cluster periodically sends a lock request message to each lock service node in the lock service cluster at intervals of the first time length; The lock service node is used to record the received lock application message after receiving the lock application message, or update the recorded lock application message of the same data node based on the received lock application message; The lock service node is used to delete the lock application message that has not been updated for a second time period in the recorded lock application message, where the second time period is greater than the first time period; The lock service node is used to send a lock confirmation message to the in-place node when the lock application message sent by the in-place node is received before the lease of the in-place node expires, and to send a lock confirmation message to the data node corresponding to the lock application message with the highest priority in the recorded lock application messages when the lock application message sent by the in-place node is not received before the lease of the in-place node expires, wherein: The in-place node is a data node that currently holds the lock, and the duration of the lease is greater than the first duration.

21. A distributed cluster, comprising a plurality of data nodes, wherein the data nodes are used to: Send a lock request message to each lock service node in the lock service cluster. If lock confirmation messages are received from lock service nodes in the lock service cluster that are not less than a preset ratio, locking is successful in the distributed cluster; If the lock confirmation message sent by the lock service nodes in the lock service cluster that is not less than the preset ratio is not received, locking fails in the distributed cluster.

22. The distributed cluster according to claim 21, wherein the data node is used to periodically send a lock request message to each lock service node of the lock service cluster at intervals of a first duration.

23. A computer program product comprising a computer program / instructions, which when executed by a processor implement the steps of the method according to any one of claims 1 to 11.

24. An electronic device comprising: processor; a memory for storing processor-executable instructions; The processor implements the method according to any one of claims 1 to 11 by running the executable instructions.

25. A computer-readable storage medium having computer instructions stored thereon, which, when executed by a processor, implement the steps of the method according to any one of claims 1 to 11.

Citation Information

Patent Citations

  • Cluster distributed type lock management method based on storage area network SAN

    CN101252603A

  • Distributed transaction processing method and system and related equipment

    CN115145715A

  • Distributed lock processing method, equipment, storage medium and system

    CN117608766A

  • Distributed lock administration

    US20110137879A1

Cited By

  • Distributed lock management method and apparatus

    WO2026138725A1