Master-slave node election method, device, equipment and storage medium in distributed system
By allocating self-increasing identification to nodes of distributed systems and using heartbeat data for election, the problems of 'schizon' and redundant costs in the dual-center architecture are solved, and the stability and high availability of the system are achieved.
Patent Information
- Application Number
- CN202411589045.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-11-08
- Publication Date
- 2025-03-11
- Estimated Expiration
- 2044-11-08
AI Technical Summary
In a distributed system with dual-center architecture, existing consistency algorithms are prone to 'schizontal brain' when partitioning networks, resulting in frequent state switching, affecting service stability, and require redundant nodes to achieve high availability, which is costly.
Automatic election and failover of master and slave nodes are achieved by assigning a self-increasing identifier to each node and combining periodic heartbeat data to determine the central master and slave nodes, as well as the global master node.
In a dual-center architecture, ensuring that the system can maintain stability and business continuity in normal operation, 'schizon' or unilateral center failures, reducing system complexity and maintenance costs, and achieving high availability and maintaining business continuity even in extreme cases.
Smart Images

Figure CN119128018B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the field of distributed computing technology, and in particular to a method, device, equipment and storage medium for selecting a master-slave node in a distributed system. Background Art
[0002] In the design of distributed systems, the CAP theory points out that only two of the three requirements, consistency, availability, and partition tolerance, can be satisfied.
[0003] The current mainstream distributed system solutions, such as software products based on Paxos, Raft or Zab consensus algorithms, perform well in a single-center architecture. However, in a dual-center architecture, especially in an unstable network environment such as a remote dual-center, these consensus algorithms tend to become very sensitive, resulting in frequent state switching, which in turn affects the stability of the overall service.
[0004] In financial private clouds, single-center, dual-center in the same city (active / hot standby, cold standby), or dual-center in different locations (active / hot standby, cold standby) are usually used. The dual-center active-active architecture can maximize the use of server resources and ensure that the system can still provide services when a single center fails, thereby reducing the risk of financial service interruption caused by external factors.
[0005] The dual-center architecture usually relies on high-cost, limited-bandwidth dedicated line connections, especially in remote dual centers, this limitation is more obvious. Multi-center or distributed services in the industry usually conduct elections through voting, which means that 3 or more odd nodes are required to reach a consensus. However, the dual-center architecture itself cannot meet this condition because when the network is partitioned (such as the dedicated line is disconnected), both centers may think that the other party is "down", which is called "brain split", even though both sides are actually still running.
[0006] Due to the above reasons, financial private clouds usually do not support software products based on these consistency algorithms in a dual-center environment, that is, these products are only used in a single-center environment and do not provide cross-center service support.
[0007] In addition, these consensus algorithms rely on voting and require at least 3 odd nodes to produce consistent results. When the number of cluster nodes is less than n / 2+1 (n is the total number of cluster nodes), the cluster will not work properly due to insufficient votes. This means that to achieve highly available distributed services, the cost of redundancy must be paid. However, for business scenarios with low concurrency, this redundancy cost is too high and uneconomical. Summary of the invention
[0008] The present disclosure provides a method, device, equipment and storage medium for selecting a master-slave node in a distributed system, so as to at least solve the above technical problems existing in the prior art.
[0009] According to a first aspect of the present disclosure, a method for selecting a master-slave node in a distributed system is provided, the method comprising:
[0010] Determining a plurality of centers connected to a database, each of the centers comprising a plurality of nodes;
[0011] According to the order of the running time of each node entering the system, the database assigns a self-incrementing identifier to each node, wherein the smaller the self-incrementing identifier is, the earlier the running time of the node is;
[0012] Each of the nodes sends periodic heartbeat data to the database;
[0013] Determine the central master node and central slave node of each center according to the periodic heartbeat data and the self-incrementing identifier of each node, and determine the global master node from the multiple central master nodes;
[0014] When the global master node fails, a new global master node is elected based on the periodic heartbeat data and self-incrementing identifier of each central master node;
[0015] When the central master node of each center fails, a new central master node is elected based on the periodic heartbeat data and self-incrementing identifier of each central slave node.
[0016] In one possible implementation, determining the central master node and central slave node of each center according to the periodic heartbeat data and the self-incrementing identifier of each node, and determining the global master node from the plurality of central master nodes, includes:
[0017] Select the node with the smallest self-incrementing identifier and the last heartbeat time of the periodic heartbeat data in each center as the center master node, and the remaining nodes as the center slave nodes;
[0018] The central master node whose last heartbeat time of periodic heartbeat data is within the preset range and whose self-incrementing identifier is the smallest is selected as the global master node.
[0019] In one possible implementation, when the global master node fails, a new global master node is elected according to the periodic heartbeat data and the self-incrementing identifier of each central master node, including:
[0020] When the global master node fails, a central master node whose last heartbeat time of periodic heartbeat data is within a preset range and whose self-incrementing identifier is the smallest is selected as the new global master node.
[0021] In one possible implementation, when the central master node of each center fails, a new central master node is elected according to the periodic heartbeat data and the self-incrementing identifier of each central slave node, including:
[0022] When the central master node of each center fails, the central slave node whose last heartbeat time of periodic heartbeat data in each center is within a preset range and whose self-incrementing identifier is the smallest is selected as the new central master node.
[0023] In one embodiment, the method further comprises:
[0024] After the central master node and the global master node are determined, the central slave node of each center sends data to the central master node, the central master node sends data to the global master node, and the global master node sends data to the database.
[0025] In one embodiment, the method further comprises:
[0026] When the central master node is disconnected from the global master node, the central master node connects to the database and sends data to the database.
[0027] In one possible implementation, the preset range is 30-60s.
[0028] According to a second aspect of the present disclosure, a master-slave node election device in a distributed system is provided, the device comprising:
[0029] A first determining unit is configured to determine a plurality of centers connected to the database, each of the centers including a plurality of nodes;
[0030] an allocating unit, configured to allocate a self-incrementing identifier to each node according to the order of the running time of each node entering the system, wherein the smaller the self-incrementing identifier is, the earlier the running time of the node is;
[0031] A sending unit, configured to send periodic heartbeat data to the database for each of the nodes;
[0032] A second determination unit is configured to determine a central master node and a central slave node of each of the centers according to the periodic heartbeat data and the self-incrementing identifier of each of the nodes, and to determine a global master node from the plurality of central master nodes;
[0033] A first election unit is configured to elect a new global master node according to the periodic heartbeat data and the self-incrementing identifier of each of the central master nodes when the global master node fails;
[0034] The second election unit is configured to elect a new central master node according to the periodic heartbeat data and self-incrementing identifier of each central slave node when a central master node of each center fails.
[0035] According to a third aspect of the present disclosure, there is provided an electronic device, including:
[0036] at least one processor; and
[0037] a memory communicatively connected to the at least one processor; wherein,
[0038] The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method described in the present disclosure.
[0039] According to a fourth aspect of the present disclosure, a non-transitory computer-readable storage medium storing computer instructions is provided, wherein the computer instructions are used to cause the computer to execute the method described in the present disclosure.
[0040] The master-slave node election method, device, equipment and storage medium in the distributed system disclosed in the present invention, by adding a self-incrementing identifier, uses the self-incrementing identifier and periodic heartbeat data as a global unified election standard, so that in a dual-center architecture or even a multi-center architecture, whether it is normal operation, dual-center "brain split" or a unilateral center "downtime and offline", a single center can continue to work normally, and the accuracy of the data can be maintained within a controllable range. This design ensures the stability of the system and maintains business continuity even in extreme cases.
[0041] In addition, the database-based election mechanism no longer relies on the traditional voting process, which means that the system can operate normally regardless of how many nodes are online, and can even ensure stability and availability with only one node. For business scenarios with small concurrency, high availability can be achieved with as few as two machines, which greatly reduces the complexity and maintenance costs of the system.
[0042] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present disclosure, nor is it intended to limit the scope of the present disclosure. Other features of the present disclosure will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS
[0043] The above and other objects, features and advantages of the exemplary embodiments of the present disclosure will become readily understood by reading the detailed description below with reference to the accompanying drawings. In the accompanying drawings, several embodiments of the present disclosure are shown in an exemplary and non-limiting manner, in which:
[0044] In the drawings, the same or corresponding reference numerals represent the same or corresponding parts.
[0045] Figure 1 A schematic diagram of a process flow of a master-slave node election method in a distributed system provided by an embodiment of the present disclosure;
[0046] Figure 2 The process of the master-slave node election method in the distributed system provided by the embodiment of the present disclosure Figure 1 ;
[0047] Figure 3 The process of the master-slave node election method in the distributed system provided by the embodiment of the present disclosure Figure 2 ;
[0048] Figure 4 This is the working scenario 1 of the master-slave nodes in the distributed system;
[0049] Figure 5 This is the second working scenario of the master-slave nodes in the distributed system;
[0050] Figure 6 This is the working scenario three of the master-slave nodes in the distributed system;
[0051] Figure 7 This is the fourth working scenario of the master-slave nodes in the distributed system;
[0052] Figure 8 A schematic diagram of the structure of a master-slave node election device in a distributed system provided by an embodiment of the present disclosure;
[0053] Fig. 9 A schematic diagram of the structure of an electronic device according to an embodiment of the present disclosure is shown. DETAILED DESCRIPTION
[0054] In order to make the purpose, features, and advantages of the present disclosure more obvious and easy to understand, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below in conjunction with the drawings in the embodiments of the present disclosure. Obviously, the described embodiments are only part of the embodiments of the present disclosure, not all of the embodiments. Based on the embodiments in the present disclosure, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present disclosure.
[0055] The present disclosure provides a method for selecting a master-slave node in a distributed system. Figure 1A schematic diagram of a process flow of a master-slave node election method in a distributed system provided by an embodiment of the present disclosure, such as Figure 1 As shown, the method comprises the following steps:
[0056] Step 101, determining a plurality of centers connected to a database, each center including a plurality of nodes.
[0057] Figure 2 The process of the master-slave node election method in the distributed system provided by the embodiment of the present disclosure Figure 1 .
[0058] like Figure 2 As shown, in the distributed system, there are multiple centers connected to the database, and each center has multiple nodes. In the embodiment of the present disclosure, dual centers are used as an example for explanation, that is, including center A and center B.
[0059] Step 102: According to the order in which each node enters the system, the database assigns a self-incrementing identifier to each node, wherein the smaller the self-incrementing identifier is, the earlier the node was run.
[0060] In this embodiment, in order to realize automatic screening of master and slave roles, it is necessary to introduce a global monotonically increasing attribute as a global unified election standard. Therefore, this embodiment introduces a self-incrementing flag to realize this function.
[0061] When the service of the distributed system is started, data is inserted into the database table, and the database generates an auto-incrementing identifier for each node. The auto-incrementing identifier indicates the order in which each node enters the system for operation. The earlier the node enters the system for operation, the smaller the auto-incrementing identifier. For example, the auto-incrementing identifier of the first node to enter the system for operation is 1, and the auto-incrementing identifier of the second node to enter the system for operation is 2, and so on. An auto-incrementing identifier is assigned to each node that enters the system for operation.
[0062] Step 103: Each node sends periodic heartbeat data to the database.
[0063] During the entire service operation, each node will periodically send a keep-alive heartbeat to the database and update the heartbeat time in the database. Each node sends periodic heartbeat data to the database to confirm whether the node has failed. If the database does not receive the heartbeat data of the node within a period of time, it can be considered that the node has failed. If the node is the master node, the next step is to replace the master node in time to ensure that the center can work normally and ensure the stability of the system.
[0064] Step 104, determining the central master node and central slave node of each center according to the periodic heartbeat data and the self-incrementing identifier of each node, and determining the global master node from multiple central master nodes.
[0065] In order to ensure data consistency, each center and the entire distributed system need to elect master nodes and slave nodes, which are managed uniformly by the master node.
[0066] In one embodiment, according to the periodic heartbeat data and the self-incrementing identifier of each node, the central master node and the central slave node of each center are determined, and the global master node is determined from multiple central master nodes, including:
[0067] Select the node with the smallest self-incrementing identifier and the last heartbeat time of the periodic heartbeat data in each center as the center master node, and the remaining nodes as the center slave nodes;
[0068] The central master node whose last heartbeat time of periodic heartbeat data is within the preset range and whose self-incrementing identifier is the smallest is selected as the global master node.
[0069] Specifically, during the election process, the election criteria for the master node are that the last heartbeat time of the periodic heartbeat data is within a preset range and the self-incrementing identifier is the smallest.
[0070] In a dual-center environment, this method can select a master node in a data center. In order to avoid the "split brain" problem, each data center needs to be abstracted as an election node, and cross-center elections are conducted through the master nodes in the center, and finally a global master node is selected to uniformly manage global write operations, thereby ensuring global data consistency.
[0071] In one embodiment, the preset range is 30-60s. In a preferred embodiment, the preset range is 60s.
[0072] Figure 3 The process of the master-slave node election method in the distributed system provided by the embodiment of the present disclosure Figure 2 .
[0073] In this embodiment, the central master node of each center is first elected according to the election standard, and the remaining nodes are central slave nodes. Then, the global master node is elected from the central master node of each center. Figure 2 As shown, first select the central master nodes of center A and center B respectively, and then, as Figure 3 As shown, a global master node is elected from the central master nodes of center A and center B, for example, the central master node of center A is elected as the global master node.
[0074] At this time, the central master node of center A is in the "global master node" state, while the central master node of center B is divided into two states: "central master node" and "global slave node". Under normal working conditions, the central master node of center B runs in the "global slave node" state, forwarding data to the "global master node" for decision-making in real time to ensure the consistency of global data; when a "brain split" occurs, the central master node of center B will switch to the "central master node" state, take over the write operation in center B, and ensure the availability of center B.
[0075] Step 105: When a global master node fails, a new global master node is elected based on the periodic heartbeat data and the self-incrementing identifier of each central master node.
[0076] In one embodiment, when a global master node fails, a new global master node is elected based on the periodic heartbeat data and the self-incrementing flag of each central master node, including:
[0077] When a global master node fails, a central master node whose last heartbeat time of periodic heartbeat data is within a preset range and whose self-incrementing identifier is the smallest is selected as the new global master node.
[0078] Specifically, when a global master node fails, a new global master node will be selected from the remaining central master nodes according to the election criteria to ensure data consistency.
[0079] Step 106, when the central master node of each center fails, a new central master node is elected based on the periodic heartbeat data and self-incrementing identifier of each central slave node.
[0080] In one embodiment, when a central master node of each center fails, a new central master node is elected based on the periodic heartbeat data and self-incrementing identifier of each central slave node, including:
[0081] When the central master node of each center fails, the central slave node whose last heartbeat time of periodic heartbeat data in each center is within a preset range and whose self-incrementing identifier is the smallest is selected as the new central master node.
[0082] Specifically, when a central master node of a center fails, a new central master node will be elected from the remaining slave nodes of the center according to the election criteria.
[0083] Figure 4 This is the first working scenario of the master-slave nodes in a distributed system.
[0084] like Figure 4As shown, center A includes two nodes, A1 and A2, and center B includes two nodes, B1 and B2. A1 is the global master node, and B1 is the central master node of center B. In this scenario, A1, A2, B1, and B2 all work normally.
[0085] In one embodiment, after the central master node and the global master node are determined, the central slave node of each center sends data to the central master node, the central master node sends data to the global master node, and the global master node sends data to the database.
[0086] Specifically, Figure 4 As shown, A2 sends data to A1, B2 sends data to B1, and B1 sends data to A1. A1 synchronizes the data to the database regularly, so that the global master node can uniformly manage the global write operation to ensure global data consistency.
[0087] Figure 5 This is the second working scenario of the master-slave nodes in a distributed system.
[0088] like Figure 5 As shown, when the original global master node A1 goes down, the central master node B1 will be upgraded to the global master node, and A2 will be upgraded to the central master node of center A.
[0089] The upgraded global master node B1 and central master node A2 will download the data previously synchronized to the database from the database to ensure the normal operation of the system.
[0090] Figure 6 This is the third working scenario of the master-slave nodes in a distributed system.
[0091] like Figure 6 As shown, all nodes in center B are down. In this case, the downtime of center B does not affect the normal operation of center A.
[0092] Figure 7 This is the fourth working scenario of the master-slave nodes in the distributed system.
[0093] In one embodiment, when the central master node is disconnected from the global master node, the central master node is connected to the database and sends data to the database.
[0094] like Figure 7 As shown, when the dedicated line between the central master node B1 and the global master node A1 is disconnected or a "brain split" occurs, the central master node B1 will directly connect to the database and synchronize data to the database regularly.
[0095] In the disclosed embodiment, a self-incrementing flag is added, and the self-incrementing flag and the periodic heartbeat data are used as a global unified election standard. In this way, in a dual-center architecture or even a multi-center architecture, whether it is normal operation, dual-center "brain split" or a single-center overall "downtime and offline", a single center can continue to work normally, and the accuracy of the data can be maintained within a controllable range. This design ensures the stability of the system and maintains business continuity even in extreme situations.
[0096] In addition, the database-based election mechanism no longer relies on the traditional voting process, which means that the system can operate normally regardless of how many nodes are online, and can even ensure stability and availability with only one node. For business scenarios with small concurrency, high availability can be achieved with as few as two machines, which greatly reduces the complexity and maintenance costs of the system.
[0097] The embodiment of the present disclosure also provides a master-slave node election device in a distributed system, Figure 8 The structure diagram of the master-slave node election device in the distributed system provided by the embodiment of the present disclosure is as follows: Figure 8 As shown, the device comprises:
[0098] A first determining unit 801 is configured to determine a plurality of centers connected to a database, each center including a plurality of nodes;
[0099] The allocation unit 802 is configured to allocate a self-incrementing identifier to each node according to the order of the running time of each node entering the system, wherein the smaller the self-incrementing identifier is, the earlier the node is running;
[0100] A sending unit 803, configured for each node to send periodic heartbeat data to the database;
[0101] The second determining unit 804 is configured to determine the central master node and the central slave node of each center according to the periodic heartbeat data and the self-incrementing identifier of each node, and determine the global master node from the multiple central master nodes;
[0102] The first election unit 805 is configured to elect a new global master node according to the periodic heartbeat data and the self-incrementing flag of each central master node when a global master node fails;
[0103] The second election unit 806 is configured to elect a new central master node according to the periodic heartbeat data and self-incrementing identifier of each central slave node when a central master node of each center fails.
[0104] In one embodiment, the second determining unit 804 is specifically configured to: select the node whose last heartbeat time of periodic heartbeat data in each center is within a preset range and whose self-increment identifier is the smallest as the center master node, and the remaining nodes as the center slave nodes;
[0105] The central master node whose last heartbeat time of periodic heartbeat data is within the preset range and whose self-incrementing identifier is the smallest is selected as the global master node.
[0106] In one embodiment, the first election unit 805 is specifically configured to: when a global master node fails, select a central master node whose last heartbeat time of periodic heartbeat data is within a preset range and whose self-incrementing identifier is the smallest as a new global master node.
[0107] In one embodiment, the second election unit 806 is specifically configured as follows: when a central master node of each center fails, a central slave node whose last heartbeat time of periodic heartbeat data in each center is within a preset range and whose self-increment identifier is the smallest is selected as the new central master node.
[0108] In one embodiment, the device also includes: a data sending unit 807, which is configured to, after determining the central master node and the global master node, the central slave node of each center sends data to the central master node, the central master node sends data to the global master node, and the global master node sends data to the database.
[0109] In one embodiment, the device further includes: a connection unit 808, configured to connect the central master node to the database and send data to the database when the central master node is disconnected from the global master node.
[0110] According to an embodiment of the present disclosure, the present disclosure also provides an electronic device and a readable storage medium.
[0111] Fig. 9 A schematic block diagram of an example electronic device 900 that can be used to implement an embodiment of the present disclosure is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processing, cellular phones, smart phones, wearable devices, and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely examples and are not intended to limit the implementation of the present disclosure described and / or required herein.
[0112] like Fig. 9As shown, the device 900 includes a computing unit 901, which can perform various appropriate actions and processes according to a computer program stored in a read-only memory (ROM) 902 or a computer program loaded from a storage unit 908 into a random access memory (RAM) 903. In the RAM 903, various programs and data required for the operation of the device 900 can also be stored. The computing unit 901, the ROM 902, and the RAM 903 are connected to each other via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.
[0113] A number of components in the device 900 are connected to the I / O interface 905, including: an input unit 906, such as a keyboard, a mouse, etc.; an output unit 907, such as various types of displays, speakers, etc.; a storage unit 908, such as a disk, an optical disk, etc.; and a communication unit 909, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 909 allows the device 900 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0114] The computing unit 901 may be a variety of general and / or special processing components with processing and computing capabilities. Some examples of the computing unit 901 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various computing units running machine learning model algorithms, digital signal processors (DSPs), and any appropriate processors, controllers, microcontrollers, etc. The computing unit 901 performs the various methods and processes described above, such as a master-slave node election method in a distributed system. For example, in some embodiments, the master-slave node election method in a distributed system may be implemented as a computer software program, which is tangibly contained in a machine-readable medium, such as a storage unit 908. In some embodiments, part or all of the computer program may be loaded and / or installed on the device 900 via the ROM 902 and / or the communication unit 909. When the computer program is loaded into the RAM 903 and executed by the computing unit 901, one or more steps of the master-slave node election method in the distributed system described above may be performed. Alternatively, in other embodiments, the computing unit 901 may be configured to execute the master-slave node election method in a distributed system in any other appropriate manner (eg, by means of firmware).
[0115] Various implementations of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), complex programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various implementations can include: being implemented in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which can be a special purpose or general purpose programmable processor that can receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.
[0116] The program code for implementing the method of the present disclosure may be written in any combination of one or more programming languages. These program codes may be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code may be executed entirely on the machine, partially on the machine, partially on the machine and partially on a remote machine as a stand-alone software package, or entirely on a remote machine or server.
[0117] In the context of the present disclosure, a machine-readable medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. A machine-readable medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. A more specific example of a machine-readable storage medium may include an electrical connection based on one or more lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0118] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).
[0119] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.
[0120] A computer system may include a client and a server. The client and the server are generally remote from each other and usually interact through a communication network. The relationship of client and server is generated by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, a server of a distributed system, or a server combined with a blockchain.
[0121] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps recorded in this disclosure can be executed in parallel, sequentially or in different orders, as long as the desired results of the technical solutions disclosed in this disclosure can be achieved, and this document does not limit this.
[0122] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of the present disclosure, the meaning of "plurality" is two or more, unless otherwise clearly and specifically defined.
[0123] The above is only a specific embodiment of the present disclosure, but the protection scope of the present disclosure is not limited thereto. Any person skilled in the art who is familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present disclosure, which should be included in the protection scope of the present disclosure. Therefore, the protection scope of the present disclosure should be based on the protection scope of the claims.
Claims
1. A method for selecting a master-slave node in a distributed system, characterized in that: The method comprises: Determining a plurality of centers connected to a database, each of the centers comprising a plurality of nodes; According to the order of the running time of each node entering the system, the database assigns a self-incrementing identifier to each node, wherein the smaller the self-incrementing identifier is, the earlier the running time of the node is; Each of the nodes sends periodic heartbeat data to the database; Determine the central master node and central slave node of each center according to the periodic heartbeat data and the self-incrementing identifier of each node, and determine the global master node from the multiple central master nodes; When the global master node fails, a new global master node is elected based on the periodic heartbeat data and self-incrementing identifier of each central master node; When the central master node of each center fails, a new central master node is elected based on the periodic heartbeat data and self-incrementing identifier of each central slave node.
2. The method according to claim 1, characterized in that Determining the central master node and central slave node of each center according to the periodic heartbeat data and the self-incrementing identifier of each node, and determining the global master node from the multiple central master nodes, includes: Select the node whose last heartbeat time of periodic heartbeat data in each center is within the preset range and whose self-incrementing identifier is the smallest as the center master node, and the remaining nodes as the center slave nodes; The central master node whose last heartbeat time of periodic heartbeat data is within the preset range and whose self-incrementing identifier is the smallest is selected as the global master node.
3. The method according to claim 1, characterized in that When the global master node fails, a new global master node is elected according to the periodic heartbeat data and the self-incrementing identifier of each central master node, including: When the global master node fails, a central master node whose last heartbeat time of periodic heartbeat data is within a preset range and whose self-incrementing identifier is the smallest is selected as the new global master node.
4. The method according to claim 1, characterized in that: When the central master node of each center fails, a new central master node is elected according to the periodic heartbeat data and the self-incrementing identifier of each central slave node, including: When the central master node of each center fails, the central slave node whose last heartbeat time of periodic heartbeat data in each center is within a preset range and whose self-incrementing identifier is the smallest is selected as the new central master node.
5. The method according to claim 1, characterized in that: The method further comprises: After the central master node and the global master node are determined, the central slave node of each center sends data to the central master node, the central master node sends data to the global master node, and the global master node sends data to the database.
6. The method according to claim 1, characterized in that The method further comprises: When the central master node is disconnected from the global master node, the central master node connects to the database and sends data to the database.
7. The method according to any one of claims 2 to 4, characterized in that: The preset range is 30-60s.
8. A master-slave node election device in a distributed system, characterized in that: The device comprises: A first determining unit is configured to determine a plurality of centers connected to the database, each of the centers including a plurality of nodes; an allocating unit, configured to allocate a self-incrementing identifier to each node according to the order of the running time of each node entering the system, wherein the smaller the self-incrementing identifier is, the earlier the running time of the node is; A sending unit, configured to send periodic heartbeat data to the database for each of the nodes; A second determining unit is configured to determine a central master node and a central slave node of each of the centers according to the periodic heartbeat data and the self-incrementing identifier of each of the nodes, and to determine a global master node from the plurality of central master nodes; A first election unit is configured to elect a new global master node according to the periodic heartbeat data and the self-incrementing identifier of each of the central master nodes when the global master node fails; The second election unit is configured to elect a new central master node according to the periodic heartbeat data and self-incrementing identifier of each central slave node when a central master node of each center fails.
9. An electronic device, characterized in that: include: at least one processor; as well as a memory communicatively connected to the at least one processor; wherein, The memory stores instructions that can be executed by the at least one processor, and the instructions are executed by the at least one processor to enable the at least one processor to perform the method according to any one of claims 1 to 7.
10. A non-transitory computer-readable storage medium storing computer instructions, characterized in that: The computer instructions are used to make a computer execute the method according to any one of claims 1-7.
Citation Information
Patent Citations
Node election method in distributed system
CN108183971A
Method for determining main node in cluster, electronic equipment and storage medium
CN111538763A