WO2024027548A1 - 一种节点选举的方法、装置、存储介质及电子设备 - Google Patents

一种节点选举的方法、装置、存储介质及电子设备 Download PDF

Info

Publication number
WO2024027548A1
WO2024027548A1 PCT/CN2023/109513 CN2023109513W WO2024027548A1 WO 2024027548 A1 WO2024027548 A1 WO 2024027548A1 CN 2023109513 W CN2023109513 W CN 2023109513W WO 2024027548 A1 WO2024027548 A1 WO 2024027548A1
Authority
WO
WIPO (PCT)
Prior art keywords
node device
node
devices
node devices
status information
Prior art date
Application number
PCT/CN2023/109513
Other languages
English (en)
French (fr)
Inventor
阳振坤
韩富晟
刘浩
肖金亮
贾德宾
Original Assignee
北京奥星贝斯科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 北京奥星贝斯科技有限公司 filed Critical 北京奥星贝斯科技有限公司
Publication of WO2024027548A1 publication Critical patent/WO2024027548A1/zh

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/06Management of faults, events, alarms or notifications
    • H04L41/0654Management of faults, events, alarms or notifications using network fault recovery
    • H04L41/0668Management of faults, events, alarms or notifications using network fault recovery by dynamic selection of recovery network elements, e.g. replacement by the most appropriate element after failure
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L41/00Arrangements for maintenance, administration or management of data switching networks, e.g. of packet switching networks
    • H04L41/30Decision processes by autonomous network management units using voting and bidding
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1097Protocols in which an application is distributed across nodes in the network for distributed storage of data in networks, e.g. transport arrangements for network file system [NFS], storage area networks [SAN] or network attached storage [NAS]
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D30/00Reducing energy consumption in communication networks
    • Y02D30/70Reducing energy consumption in communication networks in wireless communication networks

Definitions

  • This specification relates to the field of computer technology, and in particular to a node election method, device, storage medium and electronic equipment.
  • distributed systems usually consist of multiple node devices (such as databases).
  • the data is divided into multiple data shards according to preset rules.
  • Data sharding refers to the scattered storage of data stored in the database in a certain dimension.
  • each data fragment is stored in multiple copies in different node devices. If a node device fails, the same copy on another node device can be operated without any problem.
  • the entire system is paralyzed due to a node equipment failure.
  • a master node device needs to be selected from each node device to read and write the data.
  • each node device when each node device detects a failure of the master node device, it usually broadcasts a voting request to become the master node to other node devices. If multiple node devices broadcast to elect themselves to become the master node in a short period of time, In response to the request of the master node device, it may happen that multiple node devices are unable to be agreed by more than half of the node devices to become the master node device. This requires each node device to re-elect the master node device. However, re-electing the master node device will still cause multiple node devices to broadcast and elect themselves to become the master node device in a short period of time. There is no guarantee that the master node device will be elected from each node device within a certain time. This will Cause the distributed system to be unavailable for a long time.
  • This specification provides a node election method, device, storage medium and electronic device to solve the problem of being unable to guarantee the election of a master node device from each node device within a certain time.
  • This specification adopts the following technical solution:
  • This specification provides a node election method. The method is applied to any target node device among the node devices.
  • the node device is used to provide database services, including: target node device When it is detected that the master node device in the current term meets the preset resigning conditions, it is determined that all node devices According to the status information of all node devices, candidate node devices are determined among all node devices; if the candidate node device is determined to be the target node device itself, the target node device is broadcast to other node devices to elect the target node device.
  • a voting request to become the master node device for the next term if it is determined that the candidate node device is another node device, the voting request will not be broadcast, and the other node device will be elected to become the master node device for the next term after receiving the broadcast from other node devices.
  • a node device makes a voting request, other node devices are voted according to the determined candidate node device.
  • the target node device detects that the master node device in the current term meets the preset resigning conditions, which specifically includes: when the target node device detects that the term of the master node device in the current term has expired and the expiration time exceeds the set time. , confirm that the preset resignation conditions are met.
  • determining candidate node devices among all node devices based on the status information of all node devices specifically includes: determining status scores of all node devices based on the status information of all node devices, and based on the status scores of all node devices, Candidate node devices are determined among all node devices.
  • determine the status scores of all node devices based on the status information of all node devices specifically including: for each node device, determine the priority of the node device to become the master node device according to the priority of the node device contained in the status information of the node device, Determine the status score of the node device.
  • the method further includes: if it is determined that the amount of received status information broadcast by other node devices is less than a set number, lowering the priority of the target node device itself to become the master node device.
  • each node device determine the status score of the node device according to the priority of the node device to become the master node device contained in the status information of the node device, specifically including: for each node device, according to the The priority of the node device to become the master node device contained in the status information of the node device and the random number generated by the node device determine the status score of the node device, where, for any node device, the node device broadcasts each time The random numbers contained in the status information are not exactly the same.
  • determine the status scores of all node devices based on the status information of all node devices specifically including: for each node device, if it is determined that the node device broadcasts status information according to a preset time interval, then based on the node device broadcast status information status information to determine the status score of the node device.
  • the method further includes: determining, according to the voting information returned by other node devices based on the voting request, that the number of other node devices that agree that the target node device itself becomes the master node device for the next term exceeds a set number. , it will become the master node device in the next term.
  • the method further includes: if it is detected that the candidate node device has sent consent to become the master of the next term, The voting information of the node device, before receiving the assumption information sent by other node devices, will no longer send voting information that agrees with other node devices other than the candidate node device to become the master node device for the next term.
  • the device is applied to any target node device among the node devices.
  • the node device is used to provide database services and includes: a detection module for the target node device to detect When the master node device in the current term meets the preset resignation conditions, determine the status information of all node devices; the determination module is used to determine candidate node devices among all node devices based on the status information of all node devices; the broadcast module is used to If it is determined that the candidate node device is the target node device itself, broadcast a voting request to other node devices to elect the target node device itself to become the master node device for the next term; a voting module, used if the candidate node device is determined If the device is another node device, it will not broadcast the voting request, and when receiving the voting request broadcast by the other node device to elect the other node device to become the master node device for the next term, the candidate node device will be determined based on the determined candidate node device. Other node devices vote.
  • This specification provides a computer-readable storage medium.
  • the storage medium stores a computer program.
  • the computer program is executed by a processor, the above-mentioned node election method is implemented.
  • This specification provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor.
  • the processor executes the program, the above node election method is implemented.
  • At least one of the above technical solutions adopted in this specification can achieve the following beneficial effects:
  • the target node device detects that the master node device in the current term meets the preset resignation conditions, it determines all node devices status information.
  • candidate node devices are determined among all node devices based on the status information of all node devices. Then, if it is determined that the candidate node device is the target node device itself, a voting request for electing the target node device itself to become the master node device for the next term is broadcast to other node devices.
  • the voting request will not be broadcast, and when a voting request broadcast by other node devices to elect other node devices to become the master node device for the next term is received, the candidate node device will be selected based on the determined candidate node device. Other node devices vote.
  • this method can determine candidate node devices among all node devices based on the status information of all node devices. If the candidate node device is determined to be the target node device itself, the voting request is broadcast to other node devices. If the candidate node device is determined to be another node device, vote for the other node device based on the determined candidate node device. Therefore, when most node devices are alive and interoperable, within a certain period of time, the master node device is elected based on the status information of all node devices, thus preventing the distributed system from being unavailable for a long time.
  • Figure 1 is a schematic flowchart of a node election method provided by an embodiment of this specification
  • Figure 2 is a schematic flow chart of node election provided by an embodiment of this specification
  • Figure 3 is a schematic structural diagram of a node election device provided by an embodiment of this specification.
  • FIG. 4 is a schematic structural diagram of an electronic device provided by an embodiment of this specification.
  • Figure 1 is a schematic flowchart of a node election method in this specification, which specifically includes the following steps S100 to S106.
  • the execution subject of the node election method may be a node device, and the node device may It is electronic equipment such as servers and desktop computers. Since this method is applied to any target node device among the node devices, for the convenience of description, only the target node device is used as the execution subject to describe the node election method provided in this specification.
  • the target node device may determine the status information of all node devices when detecting that the master node device in the current term satisfies the preset resigning conditions.
  • the status information mentioned here includes the identity of the node device.
  • the identity of the node device mentioned here may refer to the IP address, port number, device number and other information of the node device.
  • the target node device can receive status information broadcast by other node devices at set time intervals, and query its own status information to determine the status information of all node devices.
  • the target node device when the target node device detects that the term of the master node device in the current term has expired, it determines that the master node device in the current term satisfies the preset resignation conditions.
  • the master node device may broadcast a request to extend the current term or broadcast a voting request to become the master node device for the next term when the current term is about to end.
  • each node device did not receive the voting request during the current term. If you only determine whether to re-elect the master node device based on whether the term of the master node device has expired, the master node device of the current term may not be able to extend the current term or become the master node device of the next term. Therefore, when the target node device detects that the term of the master node device in the current term has expired and the expiration time exceeds the set time, it determines that the master node device in the current term meets the preset resignation conditions.
  • each node device in the embodiment of this specification is an honest node device, that is to say, each node device sends information according to actual conditions.
  • S102 Determine candidate node devices among all node devices according to the status information of all node devices.
  • each node device only determines whether to broadcast a request to elect itself as the master node device to other node devices based on whether it receives a heartbeat message from the master node device, and does not consider the status information of other node devices. If multiple node devices broadcast requests to elect themselves to become the master node device within a short period of time, it may happen that none of the multiple node devices can be agreed to become the master node device by more than half of the node devices. This requires each node device to re-elect the master node device. However, re-electing the master node device will still cause multiple node devices to broadcast and elect themselves to become the master node device in a short period of time, thus causing the distributed system to be unavailable for a long time.
  • the target node device can determine among all node devices based on the status information of all node devices Candidate node device. Therefore, when most node devices are alive and interoperable, the master node device is elected based on the status score of each node device within a certain period of time.
  • the target node device can determine the status scores of all node devices based on the status information of all node devices, and determine candidate node devices among all node devices based on the status scores of all node devices. For example, the target node device may determine the node device with the highest status score among all node devices as a candidate node device based on the status scores of all node devices.
  • the target node device can input the status information of all node devices into the preset function to determine the status scores of all node devices.
  • the preset function mentioned here may refer to a one-to-one mapping from a non-empty number set to a non-empty number set. This manual does not limit the preset function, as long as the input status information is an ordered set.
  • the ordered collection mentioned here can be strings, integers, etc.
  • preset functions can also be designed according to business needs.
  • the target node device may determine the status score of each node device according to the priority of the node device to become the master node device contained in the status information of the node device.
  • the priorities mentioned here can be determined by technical personnel based on business needs. For example, the priority may be determined based on the performance of the node device. The better the performance of the node device, the higher the priority of the node device to become the master node device. For another example, the priority may be determined based on the historical working time of the node device. The longer the historical working time of the node device, the lower the priority of the node device becoming the master node device. For another example, set the priority of all node devices to become the master node device to the same value.
  • the target node device can input the identity of the node device and the priority of the node device to become the master node device into the preset function to determine the status score of the node device, where, the node The higher the priority of a device becoming the master node device, the higher the status score of the node device. The lower the priority of the node device becoming the master node device, the lower the status score of the node device.
  • the preset function can be designed according to the requirements that the higher the priority of the device that becomes the master node, the higher the status score, and the lower the priority of the device that becomes the master node, the lower the status score.
  • the network of a node device may not receive status information broadcast by other node devices, or receive a smaller number of status information broadcast by other node devices. This will cause the node device to think that it is the node device with the highest status score, and thus send a voting request to elect itself to become the master node device for the next term, resulting in multiple node devices simultaneously electing themselves to become the master node for the next term. condition of the equipment. Based on this, the node device can determine the number of status information received by itself from other node devices. If the number is less than the set If there is a certain number, you can determine that your current network is not good, thereby reducing the priority of becoming the master node contained in the status information, and preventing other node devices from voting for itself.
  • the target node device determines that the number of received status information broadcast by other node devices is less than a set number, the target node device will lower the priority of the target node device itself to become the master node device. For example, if the target node device determines that the amount of status information broadcast by other node devices received is less than the set number, it will adjust the priority of becoming the master node contained in the status information to the lowest level.
  • the identity of the node device and the priority of the node device to become the master node device are generally fixed.
  • the identity of the node device and the priority of the node device to become the master node device will be fixed. Even if the priority is input into the preset function, the obtained status score will not change. This will cause the node device with the highest status score to always become the master node device, making the overall efficiency of the distributed system lower. Based on this, changing values can be added to the status information of the node device to avoid the problem that the status score of the same node device does not change, resulting in low efficiency of the overall distributed system.
  • the target node device can determine the node device according to the priority of the node device to become the master node device contained in the status information of the node device and the random number generated by the node device.
  • the status score wherein, for any node device, the random numbers contained in the status information broadcast by the node device each time are not exactly the same. Therefore, each node device has the opportunity to become the master node device.
  • the target node device can use the identity of the node device contained in the status information of the node device, the priority of the node device to become the master node device, and the random number generated by the node device. number to determine the status score of the node device.
  • each node device needs to broadcast its own status information at a preset time interval, and only determine the status score of the node device that broadcasts its own status information at a preset time interval to avoid voting for a failed node device.
  • the target node device determines that the node device broadcasts status information at a preset time interval, it determines the status score of the node device based on the status information broadcast by the node device.
  • the target node device determines that the node device has not broadcast status information according to the preset time interval, it will not determine the status score of the node device and invalidate the historical status information of the node device.
  • the first time interval and the second time interval are set in advance, the second time interval is greater than the first time interval, and the target node device determines the target node at the second time according to the status information of each node device received within the second time interval.
  • a node device that does not broadcast its own status information according to the first time interval within the interval invalidates the status information of a node device that does not broadcast its own status information according to the first time interval.
  • each node device can broadcast its own status information according to a set time interval to detect whether the term of the master node has expired. Since each node device elects the master node device based on the time interval, it avoids dependence on clock synchronization.
  • the voting request will not be broadcast, and when a voting request broadcast by other node devices to elect other node devices to become the master node device for the next term is received, the voting request will be determined based on the determination.
  • the candidate node device votes for other node devices.
  • the target node device determines that the candidate node device is the target node device itself, it broadcasts a voting request to other node devices to elect the target node device itself to become the master node device for the next term. That is to say, if the target node device determines that it is the node device with the highest status score, it will set itself as the master node device for the next term, and broadcast a voting request to other node devices to elect itself to become the master node device for the next term.
  • the target node device determines, based on the voting information returned by other node devices based on the voting request, that the number of other node devices that agree that the target node device itself becomes the master node device for the next term exceeds the set number, then in the next term to become the master node device.
  • the set number mentioned here may refer to a number greater than half of the total number of node devices.
  • the target node device can broadcast the information that it becomes the master node device after becoming the master node device for the next term.
  • the tenure information mentioned here can be used to notify other node devices that it has become the master node device.
  • the tenure information also includes the tenure information of the target node device itself, for example, the start time of the target node device itself becoming the master node, the target node device The end time for itself to become the master node, the duration for which the target node device itself becomes the master node, etc.
  • the target node device determines that the candidate node device is another node device, it does not broadcast a voting request, and when it receives a voting request broadcast by other node devices to elect other node devices to become the master node device for the next term, , based on the determined candidate node equipment, vote for other node equipment.
  • the target node device determines that it is not the node device with the highest status score, it will not set itself as the master node device for the next term and receive voting requests broadcast by other node devices. Then, the target node device can determine the other node device with the highest status score from each received voting request within the preset voting time, and send the content to the other node device with the highest status score to agree with the other node device. Become the voting information of the master node device.
  • the node device can broadcast a voting request to elect itself to become the master node device for the next term.
  • the node device may also broadcast a voting request to elect the candidate node device determined by the node device to become the master node device for the next term.
  • network fluctuations may occur in each node device, resulting in the node device receiving only the status information of part of the node devices or receiving the status information of each node device in batches (receiving part of the status information first).
  • the status information of the node device is received, and then the status information of another part of the node device is received).
  • the target node device first receives the status information of some node devices, and determines candidate node devices based on this part of the node devices. In this case, if the target node device receives a voting request broadcast by the candidate node device to elect to become the master node device for the next term.
  • the target node device will send voting information to the candidate node device to agree that the candidate node device will become the master node device for the next term.
  • the target node device After sending the voting information, the target node device receives the status information of another part of the node device. If the target node device combines the obtained status information of another part of the node device to determine other node devices with a higher status score than the candidate node device, and subsequently receives the election broadcast by the other node device to become the master node device for the next term The target node device will continue to send voting information to the other node device to agree that the other node device will become the master node device for the next term. As a result, there will be multiple master node devices, causing the distributed system to fail.
  • the target node device After the target node device has sent voting information agreeing that the candidate node device will become the master node device for the next term, even if it receives a voting request broadcast by other node devices to elect to become the master node device for the next term, it will No more voting information is sent to other node devices.
  • the target node device detects that it has sent voting information agreeing that the candidate node device will become the master node device for the next term, it will no longer send voting information agreeing to other nodes except the candidate node device before receiving the take-up information sent by other node devices.
  • the device becomes the voting information of the master node device for the next term.
  • FIG 2 is a schematic flow chart of node election provided by an embodiment of this specification; in Figure 2, it is assumed that node device A has the highest status score.
  • Node device A, node device B, and node device C each broadcast their own status information according to preset time intervals, and receive status information broadcast by other node devices. If node device A detects that the term of the master node device has expired and the expiration time exceeds the set time, and node device A determines that its status score is the highest, node device A itself will be selected as a candidate node device, and the election node device will be broadcast to other node devices. A itself becomes the voting request for the master node device in the next term.
  • node device B and node device C After receiving the voting request broadcast by node device A, node device B and node device C determine that the term of the master node device has expired and the expiration time exceeds the set time, and node device A has the highest status score, node device A will be selected as a candidate.
  • the node device sends voting information to node device A agreeing that node device A becomes the master node device for the next term.
  • node device A receives the voting information sent by node device B and node device C to agree that node device A will become the master node device for the next term, and confirms that node device A is agreed to become the master node device for the next term.
  • node device A After the number of voting information exceeds half of the total number of node devices, node device A becomes the master node device in the next term and broadcasts the information that it has become the master node device.
  • this method can determine candidate node devices among all node devices based on the status information of all node devices. If the candidate node device is determined to be the target node device itself, the voting request is broadcast to other node devices. If the candidate node device is determined to be another node device, vote for the other node device based on the determined candidate node device. Therefore, when most node devices are alive and interoperable, within a certain period of time, the master node device is elected based on the status information of all node devices, thus preventing the distributed system from being unavailable for a long time.
  • Figure 3 is a schematic structural diagram of a node election device provided by an embodiment of this specification.
  • the device is applied to any target node device among the node devices.
  • the node device is used to provide database services.
  • the device includes: The detection module 300 is used for the target node device to determine the status information of all node devices when it detects that the master node device in the current term meets the preset resignation conditions; the determination module 302 is used to determine the status information of all node devices based on the status information of all node devices. Determine the candidate node device among the node devices; the broadcast module 304 is used to broadcast to other node devices the election of the target node device itself to become the master node device for the next term if the candidate node device is determined to be the target node device itself.
  • Voting request configured to not broadcast the voting request if it is determined that the candidate node device is another node device, and after receiving the broadcast of the other node device, elect the other node device to become the master node device for the next term.
  • voting module 306 configured to not broadcast the voting request if it is determined that the candidate node device is another node device, and after receiving the broadcast of the other node device, elect the other node device to become the master node device for the next term.
  • other node devices are voted on based on the determined candidate node devices.
  • the detection module 300 is specifically configured to determine that the preset resignation conditions are met when the target node device detects that the term of the master node device within the current term has expired and the expiration time exceeds a set time.
  • the determination module 302 is specifically configured to determine the status scores of all node devices based on the status information of all node devices, and determine candidate node devices among all node devices based on the status scores of all node devices.
  • the determination module 302 is specifically configured to, for each node device, determine the status score of the node device according to the priority of the node device to become the master node device contained in the status information of the node device.
  • the determination module 302 is specifically configured to, if it is determined that the amount of received status information broadcast by other node devices is less than a set number, reduce the priority of the target node device itself to become the master node device.
  • the determined module 302 is specifically configured to, for each node device, determine the node device according to the priority of the node device to become the master node device contained in the status information of the node device and the random number generated by the node device. The status score of the device. For any node device, the random numbers contained in the status information broadcast by the node device each time are not exactly the same.
  • the determination module 302 is specifically configured to, for each node device, if it is determined that the node device broadcasts status information according to a preset time interval, determine the status of the node device based on the status information broadcast by the node device. score.
  • the voting module 306 is specifically configured to determine the number of other node devices that agree that the target node device itself becomes the master node device for the next term based on the voting information returned by other node devices based on the voting request. If the set number is exceeded, it will become the master node device in the next term.
  • the voting module 306 is specifically configured to: if it is detected that the voting information agreeing to the candidate node device to become the master node device for the next term has been sent, before receiving the assumption information sent by other node devices, no voting information is sent. Then send voting information that agrees with other node devices except the candidate node device to become the master node device for the next term.
  • This specification also provides a computer-readable storage medium that stores a computer program.
  • the computer program When the computer program is executed by a processor, it can be used to perform the node election method provided in Figure 1 .
  • the embodiment of this specification also provides a schematic structural diagram of an electronic device shown in FIG. 4 .
  • the electronic device includes a processor, internal bus, network interface, memory and non-volatile memory, and of course may also include other hardware required for business.
  • the processor reads the corresponding computer program from the non-volatile memory into the memory and then runs it to implement the node election method provided in Figure 1 above.
  • PLD Programmable Logic Device
  • FPGA Field Programmable Gate Array
  • HDL Hardware Description Language
  • the controller may be implemented in any suitable manner, for example, the controller may take the form of, for example, a microprocessor or processor and a computer readable medium storing computer readable program code (eg, software or firmware) executable by the (micro)processor. , logic gates, switches, Application Specific Integrated Circuit (ASIC), programmable logic controllers and embedded microcontrollers. Examples of controllers include but are not limited to the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20 and Silicone Labs C8051F320, the memory controller can also be implemented as part of the memory control logic.
  • the controller may take the form of, for example, a microprocessor or processor and a computer readable medium storing computer readable program code (eg, software or firmware) executable by the (micro)processor. , logic gates, switches, Application Specific Integrated Circuit (ASIC), programmable logic controllers and embedded microcontrollers. Examples of controllers include but are not limited to the following microcontrollers
  • the controller in addition to In addition to implementing the controller in the form of pure computer-readable program code, the controller can be implemented in the form of logic gates, switches, application-specific integrated circuits, programmable logic controllers, embedded microcontrollers, etc. by logically programming the method steps. achieve the same function. Therefore, this controller can be considered as a hardware component, and the devices included therein for implementing various functions can also be considered as structures within the hardware component. Or even, the means for implementing various functions can be considered as structures within hardware components as well as software modules implementing the methods.
  • a typical implementation device is a computer.
  • the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or A combination of any of these devices.
  • embodiments of the present specification may be provided as methods, systems, or computer program products.
  • the present description may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment that combines software and hardware aspects.
  • the present description may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk memory, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
  • These computer program instructions may also be stored in a computer-readable memory that causes a computer or other programmable data processing apparatus to operate in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including the instruction means, the instructions
  • the device implements the functions specified in a process or processes of the flowchart and/or a block or blocks of the block diagram.
  • These computer program instructions can also be loaded onto a computer or other programmable data processing device so that when computing A series of operating steps are executed on a computer or other programmable device to produce a computer-implemented process, whereby the instructions executed on the computer or other programmable device provide for implementing a process or processes in a flowchart and/or a method in a block diagram. The steps for a function specified in a box or boxes.
  • a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
  • processors CPUs
  • input/output interfaces network interfaces
  • memory volatile and non-volatile memory
  • Memory may include non-permanent storage in computer-readable media, random access memory (RAM) and/or non-volatile memory in the form of read-only memory (ROM) or flash memory (flash RAM). Memory is an example of computer-readable media.
  • RAM random access memory
  • ROM read-only memory
  • flash RAM flash random access memory
  • Computer-readable media includes both persistent and non-volatile, removable and non-removable media that can be implemented by any method or technology for storage of information.
  • Information may be computer-readable instructions, data structures, modules of programs, 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), and read-only memory.
  • PRAM phase change memory
  • SRAM static random access memory
  • DRAM dynamic random access memory
  • RAM random access memory
  • read-only memory read-only memory
  • ROM read-only memory
  • EEPROM electrically erasable programmable read-only memory
  • flash memory or other memory technology
  • compact disc read-only memory CD-ROM
  • DVD digital versatile disc
  • Magnetic tape cassettes tape magnetic disk storage or other magnetic storage devices or any other non-transmission medium can be used to store information that can be accessed by a computing device.
  • computer-readable media does not include transitory media, such as modulated data signals and carrier waves.
  • embodiments of the present specification may be provided as methods, systems, or computer program products.
  • the present description may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment that combines software and hardware aspects.
  • the present description may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk memory, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
  • program modules include routines, programs, objects that perform specific tasks or implement specific abstract data types. Objects, components, data structures, etc.
  • the present description may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through communications networks.
  • program modules may be located in both local and remote computer storage media including storage devices.

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Databases & Information Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Computing Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Management, Administration, Business Operations System, And Electronic Commerce (AREA)

Abstract

本说明书公开了一种节点选举的方法、装置、存储介质及电子设备,首先,目标节点设备在检测到当前任期内的主节点设备满足预设卸任条件时,确定所有节点设备的状态信息。其次,根据所有节点设备的状态信息,在所有节点设备中确定候选节点设备。而后,若确定候选节点设备为目标节点设备自身,则向其他节点设备广播投票请求。若确定候选节点设备为其他节点设备,则不广播投票请求,并在接收到其他节点设备广播的投票请求时,根据确定出的候选节点设备,对其他节点设备进行投票。本方法可以在多数节点设备存活且互通的情况下,在确定的时间内,根据所有节点设备的状态信息,选举出主节点设备,避免了分布式系统长时间不可用。

Description

一种节点选举的方法、装置、存储介质及电子设备 技术领域
本说明书涉及计算机技术领域,尤其涉及一种节点选举的方法、装置、存储介质及电子设备。
背景技术
目前,分布式系统通常由多个节点设备(如数据库)组成,数据按照预设的规则划分为多个数据分片,数据分片是指按照某个维度将存放在数据库中的数据分散存储在多个节点设备中的数据,每个数据分片以多个副本的方式存储到不同的节点设备中,若某一节点设备出现故障,可以对另一节点设备上的相同副本进行操作,不会因一处节点设备故障而造成整个系统的瘫痪。而为了避免多个节点设备对同一数据进行读写操作产生冲突的情况,需要从各节点设备中选举出主节点设备对数据进行读写操作。
但是,现有的选举算法中各节点设备在检测到主节点设备出现故障时,通常向其他节点设备广播自身成为主节点的投票请求,若在较短的时间内多个节点设备广播选举自身成为主节点设备的请求,可能出现多个节点设备均无法达到被半数以上的节点设备同意成为主节点设备的情况。这就需要各节点设备重新选举主节点设备。但是,重新选举主节点设备仍会出现在较短的时间内多个节点设备广播选举自身成为主节点设备的情况,无法保证在确定的时间内从各节点设备中选举出主节点设备,这会导致分布式系统长时间不可用。
所以,如何能够保证在确定的时间内从各节点设备中选举出主节点设备,则是一个亟待解决的问题。
发明内容
本说明书提供一种节点选举的方法、装置、存储介质及电子设备,以解决无法保证在确定的时间内从各节点设备中选举出主节点设备的问题。
本说明书采用下述技术方案:本说明书提供了一种节点选举的方法,所述方法应用于各节点设备中的任意一个目标节点设备,所述节点设备用于提供数据库服务,包括:目标节点设备在检测到当前任期内的主节点设备满足预设卸任条件时,确定所有节点设 备的状态信息;根据所有节点设备的状态信息,在所有节点设备中确定候选节点设备;若确定所述候选节点设备为所述目标节点设备自身,则向其他节点设备广播选举所述目标节点设备自身成为下一任期主节点设备的投票请求;若确定所述候选节点设备为其他节点设备,则不广播所述投票请求,并在接收到其他节点设备广播的选举其他节点设备成为下一任期主节点设备的投票请求时,根据确定出的所述候选节点设备,对其他节点设备进行投票。
可选地,目标节点设备检测到当前任期内的主节点设备满足预设卸任条件,具体包括:目标节点设备在检测到当前任期内的主节点设备的任期过期,且过期时长超过设定时长时,确定满足预设卸任条件。
可选地,根据所有节点设备的状态信息,在所有节点设备中确定候选节点设备,具体包括:根据所有节点设备的状态信息,确定所有节点设备的状态评分,并根据所有节点设备的状态评分,在所有节点设备中确定候选节点设备。
可选地,根据所有节点设备的状态信息,确定所有节点设备的状态评分,具体包括:针对每个节点设备,根据该节点设备的状态信息中包含的该节点设备成为主节点设备的优先级,确定该节点设备的状态评分。
可选地,所述方法还包括:若确定接收到的其他节点设备广播的状态信息的数量小于设定数量,则降低所述目标节点设备自身成为主节点设备的优先级。
可选地,针对每个节点设备,根据该节点设备的状态信息中包含的该节点设备成为主节点设备的优先级,确定该节点设备的状态评分,具体包括:针对每个节点设备,根据该节点设备的状态信息中包含的该节点设备成为主节点设备的优先级以及该节点设备生成的随机数,确定该节点设备的状态评分,其中,针对任意一个节点设备,该节点设备每次广播的状态信息中包含的随机数不完全相同。
可选地,根据所有节点设备的状态信息,确定所有节点设备的状态评分,具体包括:针对每个节点设备,若确定该节点设备按照预设的时间间隔广播状态信息,则根据该节点设备广播的状态信息,确定该节点设备的状态评分。
可选地,所述方法还包括:若根据其他节点设备基于所述投票请求返回的投票信息,确定同意所述目标节点设备自身成为下一任期主节点设备的其他节点设备的数量超过设定数量,则在下一任期中成为主节点设备。
可选地,所述方法还包括:若监测到已发送同意所述候选节点设备成为下一任期主 节点设备的投票信息,则在接收到其他节点设备发送的上任信息之前,不再发送同意除所述候选节点设备以外的其他节点设备成为所述下一任期主节点设备的投票信息。
本说明书提供了一种节点选举的装置,所述装置应用于各节点设备中的任意一个目标节点设备,所述节点设备用于提供数据库服务,包括:检测模块,用于目标节点设备在检测到当前任期内的主节点设备满足预设卸任条件时,确定所有节点设备的状态信息;确定模块,用于根据所有节点设备的状态信息,在所有节点设备中确定候选节点设备;广播模块,用于若确定所述候选节点设备为所述目标节点设备自身,则向其他节点设备广播选举所述目标节点设备自身成为下一任期主节点设备的投票请求;投票模块,用于若确定所述候选节点设备为其他节点设备,则不广播所述投票请求,并在接收到其他节点设备广播的选举其他节点设备成为下一任期主节点设备的投票请求时,根据确定出的所述候选节点设备,对其他节点设备进行投票。
本说明书提供了一种计算机可读存储介质,所述存储介质存储有计算机程序,所述计算机程序被处理器执行时实现上述节点选举的方法。
本说明书提供了一种电子设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,所述处理器执行所述程序时实现上述节点选举的方法。
本说明书采用的上述至少一个技术方案能够达到以下有益效果:在本说明书提供的节点选举的方法中,目标节点设备在检测到当前任期内的主节点设备满足预设卸任条件时,确定所有节点设备的状态信息。其次,根据所有节点设备的状态信息,在所有节点设备中确定候选节点设备。而后,若确定候选节点设备为目标节点设备自身,则向其他节点设备广播选举目标节点设备自身成为下一任期主节点设备的投票请求。若确定候选节点设备为其他节点设备,则不广播投票请求,并在接收到其他节点设备广播的选举其他节点设备成为下一任期主节点设备的投票请求时,根据确定出的候选节点设备,对其他节点设备进行投票。
从上述方法中可以看出,本方法可以根据所有节点设备的状态信息,在所有节点设备中确定候选节点设备,若确定候选节点设备为目标节点设备自身,向其他节点设备广播投票请求。若确定候选节点设备为其他节点设备,根据确定出的候选节点设备,对其他节点设备进行投票。从而,在多数节点设备存活且互通的情况下,在确定的时间内,根据所有节点设备的状态信息,选举出主节点设备,避免了分布式系统长时间不可用。
附图说明
此处所说明的附图用来提供对本说明书的进一步理解,构成本说明书的一部分,本说明书的示意性实施例及其说明用于解释本说明书,并不构成对本说明书的不当限定。在附图中:
图1为本说明书实施例提供的一种节点选举的方法的流程示意图;
图2为本说明书实施例提供的一种节点选举的流程示意图;
图3为本说明书实施例提供的一种节点选举的装置的结构示意图;
图4为本说明书实施例提供的一种电子设备的结构示意图。
具体实施方式
为使本说明书的目的、技术方案和优点更加清楚,下面将结合本说明书具体实施例及相应的附图对本说明书技术方案进行清楚、完整地描述。显然,所描述的实施例仅是本说明书一部分实施例,而不是全部的实施例。基于本说明书中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本说明书保护的范围。
以下结合附图,详细说明本说明书各实施例提供的技术方案。
为使本说明书的目的、技术方案和优点更加清楚,下面将结合本说明书具体实施例及相应的附图对本说明书技术方案进行清楚、完整地描述。显然,所描述的实施例仅是本说明书一部分实施例,而不是全部的实施例。基于本说明书中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都属于本说明书保护的范围。
以下结合附图,详细说明本说明书各实施例提供的技术方案。
图1为本说明书中一种节点选举的方法的流程示意图,具体包括以下步骤S100至S106。
S100:目标节点设备在检测到当前任期内的主节点设备满足预设卸任条件时,确定所有节点设备的状态信息。
在本说明书实施例中,节点选举的方法的执行主体可以是节点设备,节点设备可以 是服务器、台式电脑等电子设备。由于,本方法应用于各节点设备中的任意一个目标节点设备,为了便于描述,下面仅以目标节点设备为执行主体,对本说明书提供的节点选举的方法进行说明。
在本说明书实施例中,目标节点设备可以在检测到当前任期内的主节点设备满足预设卸任条件时,确定所有节点设备的状态信息。这里提到的状态信息包括节点设备的身份标识。这里提到的节点设备的身份标识可以是指节点设备的IP地址、端口编号、设备编号等信息。
目标节点设备可以接收其他节点设备按照设定时间间隔广播的状态信息,并查询自身的状态信息,以确定所有节点设备的状态信息。
其中,目标节点设备在检测到当前任期内的主节点设备的任期过期,确定当前任期内的主节点设备满足预设卸任条件。
进一步的,由于,各节点设备之间传输信息需要具有一定的传输时长,主节点设备可能会在当前任期即将结束时,广播延长当前任期的请求或广播成为下一任期主节点设备的投票请求,但由于传输时长,各节点设备未在当前任期内接收到该投票请求。若仅根据主节点设备的任期是否过期,判断是否重新选举主节点设备,可能会导致当前任期的主节点设备无法延长当前任期或成为下一任期主节点设备。因此,目标节点设备在检测到当前任期内的主节点设备的任期过期,且过期时长超过设定时长时,确定当前任期内的主节点设备满足预设卸任条件。
需要说明的是,本说明书实施例中的各节点设备均是诚实节点设备,也就是说,各节点设备均按照实际情况发送信息。
S102:根据所有节点设备的状态信息,在所有节点设备中确定候选节点设备。
在实际应用中,每个节点设备仅根据是否接收到主节点设备的心跳消息,判断是否向其他节点设备广播选举自身成为主节点设备的请求,并不会考虑其他节点设备的状态信息。若在较短的时间内多个节点设备广播选举自身成为主节点设备的请求,可能出现多个节点设备均无法达到被半数以上的节点设备同意成为主节点设备的情况。这就需要各节点设备重新选举主节点设备。但是,重新选举主节点设备仍会出现在较短的时间内多个节点设备广播选举自身成为主节点设备的情况,从而,导致分布式系统长时间不可用。
基于此,目标节点设备可以根据所有节点设备的状态信息,在所有节点设备中确定 候选节点设备。从而,在多数节点设备存活且互通的情况下,在确定的时间内基于各节点设备的状态评分选举出主节点设备。
在本说明书实施例中,目标节点设备可以根据所有节点设备的状态信息,确定所有节点设备的状态评分,并根据所有节点设备的状态评分,在所有节点设备中确定候选节点设备。例如,目标节点设备可以根据所有节点设备的状态评分,在所有节点设备中确定状态评分最高的节点设备,作为候选节点设备。
具体的,目标节点设备可以将所有节点设备的状态信息输入到预设函数中,确定所有节点设备的状态评分。这里提到的预设函数可以是指从非空数集到非空数集的一对一映射。本说明书不对预设函数进行限定,只要是输入状态信息,输出是某个有序的集合即可。这里提到的有序的集合可以是字符串、整数等。当然,预设函数也可以根据业务需求进行设计。
在本说明书实施例中,目标节点设备可以针对每个节点设备,根据该节点设备的状态信息中包含的该节点设备成为主节点设备的优先级,确定该节点设备的状态评分。这里提到的优先级可以是技术人员按照业务需求确定的。例如,优先级可以是根据节点设备的性能确定的,节点设备的性能越好,该节点设备成为主节点设备的优先级越高。再例如,优先级可以是根据节点设备的历史工作时长确定的,节点设备的历史工作时长越长,该节点设备成为主节点设备的优先级越低。再例如,将所有节点设备成为主节点设备的优先级设置为相同的数值。
进一步的,针对每个节点设备,目标节点设备可以将该节点设备的身份标识以及该节点设备成为主节点设备的优先级输入到预设函数中,确定该节点设备的状态评分,其中,该节点设备成为主节点设备的优先级越高,该节点设备的状态评分越高,该节点设备成为主节点设备的优先级越低,该节点设备的状态评分越低。
需要说明的是,预设函数可以按照成为主节点设备的优先级越高,状态评分越高,成为主节点设备的优先级越低,状态评分越低的需求进行设计。
在实际应用中,若节点设备的网络不佳,可能接收不到其他节点设备广播的状态信息,或接收到较少数量的其他节点设备广播的状态信息。这会出现该节点设备认为自身是状态评分最高的节点设备的情况,从而发送选举自身成为下一任期的主节点设备的投票请求,导致出现多个节点设备同时选举自身成为下一任期的主节点设备的情况。基于此,节点设备可以判断自身接收到的各其他节点设备的状态信息的数量,若数量小于设 定数量,则可以确定自身当前的网络不佳,从而降低状态信息中包含的自身成为主节点的优先级,避免其他节点设备投票给自身。
在本说明书实施例中,目标节点设备若确定接收到的其他节点设备广播的状态信息的数量小于设定数量,则降低所述目标节点设备自身成为主节点设备的优先级。例如,目标节点设备若确定接收到的其他节点设备广播的状态信息的数量小于设定数量,将状态信息中包含的自身成为主节点的优先级调整为最低级别。
在实际应用中,节点设备的身份标识以及该节点设备成为主节点设备的优先级在一般情况下是固定不变的,将固定不变的节点设备的身份标识以及该节点设备成为主节点设备的优先级输入到预设函数中,得到的状态评分也不会改变,这会导致状态评分最高的节点设备一直成为主节点设备,使得分布式系统整体的效率较低。基于此,节点设备的状态信息中可以增加会发生变化的数值,以避免同一节点设备的状态评分不会发生改变,导致的分布式系统整体的效率较低的问题。
在本说明书实施例中,针对每个节点设备,目标节点设备可以根据该节点设备的状态信息中包含的该节点设备成为主节点设备的优先级以及该节点设备生成的随机数,确定该节点设备的状态评分,其中,针对任意一个节点设备,该节点设备每次广播的状态信息中包含的随机数不完全相同。从而,使得各节点设备均有机会成为主节点设备。
进一步的,目标节点设备针对每个节点设备,目标节点设备可以根据该节点设备的状态信息中包含的该节点设备的身份标识、该节点设备成为主节点设备的优先级以及该节点设备生成的随机数,确定该节点设备的状态评分。
在实际应用中,若当前状态评分最高的节点设备在广播自身的状态信息后出现故障,而其他节点设备在给该节点设备投票后,该节点设备由于故障原因无法成为主节点设备,这会导致分布式系统整体出现故障。基于此,各节点设备需要按照预设的时间间隔广播自身的状态信息,仅确定按照预设的时间间隔广播自身的状态信息的节点设备的状态评分,以避免给出现故障的节点设备进行投票。
在本说明书实施例中,针对每个节点设备,目标节点设备若确定该节点设备按照预设的时间间隔广播状态信息,则根据该节点设备广播的状态信息,确定该节点设备的状态评分。
目标节点设备若确定该节点设备未按照预设的时间间隔广播状态信息,则不确定该节点设备的状态评分,并无效该节点设备的历史状态信息。
具体的,预先设置第一时间间隔、第二时间间隔,第二时间间隔大于第一时间间隔,目标节点设备根据在第二时间间隔内接收到的各节点设备的状态信息,确定在第二时间间隔内未按照第一时间间隔广播自身的状态信息的节点设备,无效未按照第一时间间隔广播自身的状态信息的节点设备的状态信息。
在实际应用中,目前的选举算法需要各节点设备之间进行时钟同步,若各节点设备之间的时钟偏差较大,目前的选举算法可能无法工作。而在本说明书实施例中,各节点设备可以按照设定的时间间隔广播自身的状态信息,检测主节点的任期是否过期。由于各节点设备是以时间间隔为标准,选举主节点设备,从而,避免了对时钟同步的依赖。
S104:若确定所述候选节点设备为所述目标节点设备自身,则向其他节点设备广播选举所述目标节点设备自身成为下一任期主节点设备的投票请求。
S106:若确定所述候选节点设备为其他节点设备,则不广播所述投票请求,并在接收到其他节点设备广播的选举其他节点设备成为下一任期主节点设备的投票请求时,根据确定出的所述候选节点设备,对其他节点设备进行投票。
在本说明书实施例中,目标节点设备若确定候选节点设备为目标节点设备自身,则向其他节点设备广播选举目标节点设备自身成为下一任期主节点设备的投票请求。也就是说,目标节点设备若确定自身为状态评分最高的节点设备,将自身设为下一任期的主节点设备,向其他节点设备广播选举自身成为下一任期主节点设备的投票请求。
然后,目标节点设备若根据其他节点设备基于所述投票请求返回的投票信息,确定同意所述目标节点设备自身成为下一任期主节点设备的其他节点设备的数量超过设定数量,则在下一任期中成为主节点设备。这里提到的设定数量可以是指大于节点设备总数的一半的数量。
当然,目标节点设备可以在成为下一任期主节点设备后,广播自身成为主节点设备的上任信息。这里提到的上任信息可以用于通知其他节点设备,自身已经成为主节点设备,上任信息中还包括目标节点设备自身的任期信息,例如,目标节点设备自身成为主节点的开始时间、目标节点设备自身成为主节点的结束时间,目标节点设备自身成为主节点的持续时长等。
在本说明书实施例中,目标节点设备若确定候选节点设备为其他节点设备,则不广播投票请求,并在接收到其他节点设备广播的选举其他节点设备成为下一任期主节点设备的投票请求时,根据确定出的候选节点设备,对其他节点设备进行投票。
也就是说,目标节点设备若确定自身不为状态评分最高的节点设备,不将自身设为下一任期的主节点设备,接收其他节点设备广播的投票请求。然后,目标节点设备可以在预设的投票时间内,从接收到的各投票请求中,确定出状态评分最高的其他节点设备,并向状态评分最高的其他节点设备发送内容为同意该其他节点设备成为主节点设备的投票信息。
需要说明的是,节点设备可以广播的选举自身成为下一任期主节点设备的投票请求。节点设备也可以广播的选举该节点设备确定出的候选节点设备成为下一任期主节点设备的投票请求。
在实际应用中,各节点设备会出现网络波动的情况,从而导致节点设备仅接收到各节点设备中的部分节点设备的状态信息或分批次接收到各节点设备的状态信息(先接收到部分节点设备的状态信息,再接收到另一部分节点设备的状态信息)。在网络波动的情况下,目标节点设备先接收到部分节点设备的状态信息,并会根据这部分节点设备,确定出候选节点设备。在这种情况下,若目标节点设备接收到候选节点设备广播的选举成为下一任期主节点设备的投票请求。目标节点设备将会向候选节点设备发送同意候选节点设备成为下一任期主节点设备的投票信息。
目标节点设备在发送投票信息后,又接收到另一部分节点设备的状态信息。若目标节点设备结合获取到的另一部分节点设备的状态信息,确定出状态评分比候选节点设备更高的其他节点设备,并在后续接收到该其他节点设备广播的选举成为下一任期主节点设备的投票请求,目标节点设备将会继续给该其他节点设备发送同意该其他节点设备成为下一任期主节点设备的投票信息。这样一来,将会出现多个主节点设备,进而导致分布式系统出现故障。
为了避免上述情况的发生,目标节点设备在已发送同意候选节点设备成为下一任期主节点设备的投票信息之后,即使接收到其他节点设备广播的选举成为下一任期主节点设备的投票请求,也不再向其他节点设备发送投票信息。
即,目标节点设备若监测到已发送同意候选节点设备成为下一任期主节点设备的投票信息,则在接收到其他节点设备发送的上任信息之前,不再发送同意除候选节点设备以外的其他节点设备成为下一任期主节点设备的投票信息。通过这种方法,使得节点设备在每一轮次的投票时间内仅能进行一次投票,从而保证在轮投票中能够顺利的选举出下一任期的主节点设备,保证分布式系统的正常运行。
图2为本说明书实施例提供的一种节点选举的流程示意图;在图2中,假设节点设备A的状态评分最高。节点设备A、节点设备B、节点设备C按照预设的时间间隔,各自广播自身的状态信息,并接收其他节点设备广播的状态信息。节点设备A若检测到主节点设备的任期过期且过期时长超过设定时长,且节点设备A确定自身的状态评分最高,将节点设备A自身作为候选节点设备,则向其他节点设备广播选举节点设备A自身成为下一任期主节点设备的投票请求。节点设备B、节点设备C在接收到节点设备A广播的投票请求后,若确定主节点设备的任期过期且过期时长超过设定时长,且节点设备A的状态评分最高,将节点设备A作为候选节点设备,向节点设备A发送同意节点设备A成为下一任期主节点设备的投票信息。节点设备A在预设的投票时间内,接收到节点设备B、节点设备C发送到同意节点设备A成为下一任期主节点设备的投票信息,确定同意节点设备A成为下一任期主节点设备的投票信息的数量超过节点设备总数的一半后,节点设备A在下一任期中成为主节点设备,并广播自身成为主节点设备的上任信息。
从上述过程中可以看出,本方法可以根据所有节点设备的状态信息,在所有节点设备中确定候选节点设备,若确定候选节点设备为目标节点设备自身,向其他节点设备广播投票请求。若确定候选节点设备为其他节点设备,根据确定出的候选节点设备,对其他节点设备进行投票。从而,在多数节点设备存活且互通的情况下,在确定的时间内,根据所有节点设备的状态信息,选举出主节点设备,避免了分布式系统长时间不可用。
以上为本说明书实施例提供的一种节点选举的方法,基于同样的思路,本说明书还提供了相应的装置、存储介质和电子设备。
图3为本说明书实施例提供的一种节点选举的装置的结构示意图,所述装置应用于各节点设备中的任意一个目标节点设备,所述节点设备用于提供数据库服务,所述装置包括:检测模块300,用于目标节点设备在检测到当前任期内的主节点设备满足预设卸任条件时,确定所有节点设备的状态信息;确定模块302,用于根据所有节点设备的状态信息,在所有节点设备中确定候选节点设备;广播模块304,用于若确定所述候选节点设备为所述目标节点设备自身,则向其他节点设备广播选举所述目标节点设备自身成为下一任期主节点设备的投票请求;投票模块306,用于若确定所述候选节点设备为其他节点设备,则不广播所述投票请求,并在接收到其他节点设备广播的选举其他节点设备成为下一任期主节点设备的投票请求时,根据确定出的所述候选节点设备,对其他节点设备进行投票。
可选地,所述检测模块300具体用于,目标节点设备在检测到当前任期内的主节点设备的任期过期,且过期时长超过设定时长时,确定满足预设卸任条件。
可选地,所述确定模块302具体用于,根据所有节点设备的状态信息,确定所有节点设备的状态评分,并根据所有节点设备的状态评分,在所有节点设备中确定候选节点设备。
可选地,所述确定模块302具体用于,针对每个节点设备,根据该节点设备的状态信息中包含的该节点设备成为主节点设备的优先级,确定该节点设备的状态评分。
可选地,所述确定模块302具体还用于,若确定接收到的其他节点设备广播的状态信息的数量小于设定数量,则降低所述目标节点设备自身成为主节点设备的优先级。
可选地,所确定模块302具体用于,针对每个节点设备,根据该节点设备的状态信息中包含的该节点设备成为主节点设备的优先级以及该节点设备生成的随机数,确定该节点设备的状态评分,其中,针对任意一个节点设备,该节点设备每次广播的状态信息中包含的随机数不完全相同。
可选地,所述确定模块302具体用于,针对每个节点设备,若确定该节点设备按照预设的时间间隔广播状态信息,则根据该节点设备广播的状态信息,确定该节点设备的状态评分。
可选地,所述投票模块306具体还用于,若根据其他节点设备基于所述投票请求返回的投票信息,确定同意所述目标节点设备自身成为下一任期主节点设备的其他节点设备的数量超过设定数量,则在下一任期中成为主节点设备。
可选地,所述投票模块306具体还用于,若监测到已发送同意所述候选节点设备成为下一任期主节点设备的投票信息,则在接收到其他节点设备发送的上任信息之前,不再发送同意除所述候选节点设备以外的其他节点设备成为所述下一任期主节点设备的投票信息。
本说明书还提供了一种计算机可读存储介质,所述存储介质存储有计算机程序,所述计算机程序被处理器执行时可用于执行上述图1提供的节点选举的方法。
本说明书实施例还提供了图4所示的一种电子设备的结构示意图。如图4,在硬件层面,该电子设备包括处理器、内部总线、网络接口、内存以及非易失性存储器,当然还可能包括其他业务所需要的硬件。处理器从非易失性存储器中读取对应的计算机程序到内存中然后运行,以实现上述图1提供的节点选举的方法。
当然,除了软件实现方式之外,本说明书并不排除其他实现方式,比如逻辑器件抑或软硬件结合的方式等等,也就是说以下处理流程的执行主体并不限定于各个逻辑单元,也可以是硬件或逻辑器件。
需要说明的是,本申请中所有获取信号、信息或数据的动作都是在遵照所在地国家相应的数据保护法规政策的前提下,并获得由相应装置所有者给予授权的情况下进行的。
在20世纪90年代,对于一个技术的改进可以很明显地区分是硬件上的改进(例如,对二极管、晶体管、开关等电路结构的改进)还是软件上的改进(对于方法流程的改进)。然而,随着技术的发展,当今的很多方法流程的改进已经可以视为硬件电路结构的直接改进。设计人员几乎都通过将改进的方法流程编程到硬件电路中来得到相应的硬件电路结构。因此,不能说一个方法流程的改进就不能用硬件实体模块来实现。例如,可编程逻辑器件(Programmable Logic Device,PLD)(例如现场可编程门阵列(Field Programmable Gate Array,FPGA))就是这样一种集成电路,其逻辑功能由用户对器件编程来确定。由设计人员自行编程来把一个数字系统“集成”在一片PLD上,而不需要请芯片制造厂商来设计和制作专用的集成电路芯片。而且,如今,取代手工地制作集成电路芯片,这种编程也多半改用“逻辑编译器(logic compiler)”软件来实现,它与程序开发撰写时所用的软件编译器相类似,而要编译之前的原始代码也得用特定的编程语言来撰写,此称之为硬件描述语言(Hardware Description Language,HDL),而HDL也并非仅有一种,而是有许多种,如ABEL(Advanced Boolean Expression Language)、AHDL(Altera Hardware Description Language)、Confluence、CUPL(Cornell University Programming Language)、HDCal、JHDL(Java Hardware Description Language)、Lava、Lola、MyHDL、PALASM、RHDL(Ruby Hardware Description Language)等,目前最普遍使用的是VHDL(Very-High-Speed Integrated Circuit Hardware Description Language)与Verilog。本领域技术人员也应该清楚,只需要将方法流程用上述几种硬件描述语言稍作逻辑编程并编程到集成电路中,就可以很容易得到实现该逻辑方法流程的硬件电路。
控制器可以按任何适当的方式实现,例如,控制器可以采取例如微处理器或处理器以及存储可由该(微)处理器执行的计算机可读程序代码(例如软件或固件)的计算机可读介质、逻辑门、开关、专用集成电路(Application Specific Integrated Circuit,ASIC)、可编程逻辑控制器和嵌入微控制器的形式,控制器的例子包括但不限于以下微控制器:ARC 625D、Atmel AT91SAM、Microchip PIC18F26K20以及Silicone Labs C8051F320,存储器控制器还可以被实现为存储器的控制逻辑的一部分。本领域技术人员也知道,除 了以纯计算机可读程序代码方式实现控制器以外,完全可以通过将方法步骤进行逻辑编程来使得控制器以逻辑门、开关、专用集成电路、可编程逻辑控制器和嵌入微控制器等的形式来实现相同功能。因此这种控制器可以被认为是一种硬件部件,而对其内包括的用于实现各种功能的装置也可以视为硬件部件内的结构。或者甚至,可以将用于实现各种功能的装置视为既可以是实现方法的软件模块又可以是硬件部件内的结构。
上述实施例阐明的系统、装置、模块或单元,具体可以由计算机芯片或实体实现,或者由具有某种功能的产品来实现。一种典型的实现设备为计算机。具体的,计算机例如可以为个人计算机、膝上型计算机、蜂窝电话、相机电话、智能电话、个人数字助理、媒体播放器、导航设备、电子邮件设备、游戏控制台、平板计算机、可穿戴设备或者这些设备中的任何设备的组合。
为了描述的方便,描述以上装置时以功能分为各种单元分别描述。当然,在实施本说明书时可以把各单元的功能在同一个或多个软件和/或硬件中实现。
本领域内的技术人员应明白,本说明书的实施例可提供为方法、系统、或计算机程序产品。因此,本说明书可采用完全硬件实施例、完全软件实施例、或结合软件和硬件方面的实施例的形式。而且,本说明书可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
本说明书是参照根据本说明书实施例的方法、设备(系统)、和计算机程序产品的流程图和/或方框图来描述的。应理解可由计算机程序指令实现流程图和/或方框图中的每一流程和/或方框、以及流程图和/或方框图中的流程和/或方框的结合。可提供这些计算机程序指令到通用计算机、专用计算机、嵌入式处理机或其他可编程数据处理设备的处理器以产生一个机器,使得通过计算机或其他可编程数据处理设备的处理器执行的指令产生用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的装置。
这些计算机程序指令也可存储在能引导计算机或其他可编程数据处理设备以特定方式工作的计算机可读存储器中,使得存储在该计算机可读存储器中的指令产生包括指令装置的制造品,该指令装置实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能。
这些计算机程序指令也可装载到计算机或其他可编程数据处理设备上,使得在计算 机或其他可编程设备上执行一系列操作步骤以产生计算机实现的处理,从而在计算机或其他可编程设备上执行的指令提供用于实现在流程图一个流程或多个流程和/或方框图一个方框或多个方框中指定的功能的步骤。
在一个典型的配置中,计算设备包括一个或多个处理器(CPU)、输入/输出接口、网络接口和内存。
内存可能包括计算机可读介质中的非永久性存储器,随机存取存储器(RAM)和/或非易失性内存等形式,如只读存储器(ROM)或闪存(flash RAM)。内存是计算机可读介质的示例。
计算机可读介质包括永久性和非永久性、可移动和非可移动媒体可以由任何方法或技术来实现信息存储。信息可以是计算机可读指令、数据结构、程序的模块或其他数据。计算机的存储介质的例子包括,但不限于相变内存(PRAM)、静态随机存取存储器(SRAM)、动态随机存取存储器(DRAM)、其他类型的随机存取存储器(RAM)、只读存储器(ROM)、电可擦除可编程只读存储器(EEPROM)、快闪记忆体或其他内存技术、只读光盘只读存储器(CD-ROM)、数字多功能光盘(DVD)或其他光学存储、磁盒式磁带,磁带磁磁盘存储或其他磁性存储设备或任何其他非传输介质,可用于存储可以被计算设备访问的信息。按照本文中的界定,计算机可读介质不包括暂存电脑可读媒体(transitory media),如调制的数据信号和载波。
还需要说明的是,术语“包括”、“包含”或者其任何其他变体意在涵盖非排他性的包含,从而使得包括一系列要素的过程、方法、商品或者设备不仅包括那些要素,而且还包括没有明确列出的其他要素,或者是还包括为这种过程、方法、商品或者设备所固有的要素。在没有更多限制的情况下,由语句“包括一个……”限定的要素,并不排除在包括所述要素的过程、方法、商品或者设备中还存在另外的相同要素。
本领域技术人员应明白,本说明书的实施例可提供为方法、系统或计算机程序产品。因此,本说明书可采用完全硬件实施例、完全软件实施例或结合软件和硬件方面的实施例的形式。而且,本说明书可采用在一个或多个其中包含有计算机可用程序代码的计算机可用存储介质(包括但不限于磁盘存储器、CD-ROM、光学存储器等)上实施的计算机程序产品的形式。
本说明书可以在由计算机执行的计算机可执行指令的一般上下文中描述,例如程序模块。一般地,程序模块包括执行特定任务或实现特定抽象数据类型的例程、程序、对 象、组件、数据结构等等。也可以在分布式计算环境中实践本说明书,在这些分布式计算环境中,由通过通信网络而被连接的远程处理设备来执行任务。在分布式计算环境中,程序模块可以位于包括存储设备在内的本地和远程计算机存储介质中。
本说明书中的各个实施例均采用递进的方式描述,各个实施例之间相同相似的部分互相参见即可,每个实施例重点说明的都是与其他实施例的不同之处。尤其,对于系统实施例而言,由于其基本相似于方法实施例,所以描述的比较简单,相关之处参见方法实施例的部分说明即可。
以上所述仅为本说明书的实施例而已,并不用于限制本说明书。对于本领域技术人员来说,本说明书可以有各种更改和变化。凡在本说明书的精神和原理之内所作的任何修改、等同替换、改进等,均应包含在本说明书的权利要求范围之内。

Claims (12)

  1. 一种节点选举的方法,所述方法应用于各节点设备中的任意一个目标节点设备,所述节点设备用于提供数据库服务,包括:
    目标节点设备在检测到当前任期内的主节点设备满足预设卸任条件时,确定所有节点设备的状态信息;
    根据所有节点设备的状态信息,在所有节点设备中确定候选节点设备;
    若确定所述候选节点设备为所述目标节点设备自身,则向其他节点设备广播选举所述目标节点设备自身成为下一任期主节点设备的投票请求;
    若确定所述候选节点设备为其他节点设备,则不广播所述投票请求,并在接收到其他节点设备广播的选举其他节点设备成为下一任期主节点设备的投票请求时,根据确定出的所述候选节点设备,对其他节点设备进行投票。
  2. 如权利要求1所述的方法,目标节点设备检测到当前任期内的主节点设备满足预设卸任条件,具体包括:
    目标节点设备在检测到当前任期内的主节点设备的任期过期,且过期时长超过设定时长时,确定满足预设卸任条件。
  3. 如权利要求1所述的方法,根据所有节点设备的状态信息,在所有节点设备中确定候选节点设备,具体包括:
    根据所有节点设备的状态信息,确定所有节点设备的状态评分,并根据所有节点设备的状态评分,在所有节点设备中确定候选节点设备。
  4. 如权利要求3所述的方法,根据所有节点设备的状态信息,确定所有节点设备的状态评分,具体包括:
    针对每个节点设备,根据该节点设备的状态信息中包含的该节点设备成为主节点设备的优先级,确定该节点设备的状态评分。
  5. 如权利要求4所述的方法,所述方法还包括:
    若确定接收到的其他节点设备广播的状态信息的数量小于设定数量,则降低所述目标节点设备自身成为主节点设备的优先级。
  6. 如权利要求4所述的方法,针对每个节点设备,根据该节点设备的状态信息中包含的该节点设备成为主节点设备的优先级,确定该节点设备的状态评分,具体包括:
    针对每个节点设备,根据该节点设备的状态信息中包含的该节点设备成为主节点设备的优先级以及该节点设备生成的随机数,确定该节点设备的状态评分,其中,针对任意一个节点设备,该节点设备每次广播的状态信息中包含的随机数不完全相同。
  7. 如权利要求3所述的方法,根据所有节点设备的状态信息,确定所有节点设备的状态评分,具体包括:
    针对每个节点设备,若确定该节点设备按照预设的时间间隔广播状态信息,则根据该节点设备广播的状态信息,确定该节点设备的状态评分。
  8. 如权利要求1所述的方法,所述方法还包括:
    若根据其他节点设备基于所述投票请求返回的投票信息,确定同意所述目标节点设备自身成为下一任期主节点设备的其他节点设备的数量超过设定数量,则在下一任期中成为主节点设备。
  9. 如权利要求1所述的方法,所述方法还包括:
    若监测到已发送同意所述候选节点设备成为下一任期主节点设备的投票信息,则在接收到其他节点设备发送的上任信息之前,不再发送同意除所述候选节点设备以外的其他节点设备成为所述下一任期主节点设备的投票信息。
  10. 一种节点选举的装置,所述装置应用于各节点设备中的任意一个目标节点设备,所述节点设备用于提供数据库服务,包括:
    检测模块,用于目标节点设备在检测到当前任期内的主节点设备满足预设卸任条件时,确定所有节点设备的状态信息;
    确定模块,用于根据所有节点设备的状态信息,在所有节点设备中确定候选节点设备;
    广播模块,用于若确定所述候选节点设备为所述目标节点设备自身,则向其他节点设备广播选举所述目标节点设备自身成为下一任期主节点设备的投票请求;
    投票模块,用于若确定所述候选节点设备为其他节点设备,则不广播所述投票请求,并在接收到其他节点设备广播的选举其他节点设备成为下一任期主节点设备的投票请求时,根据确定出的所述候选节点设备,对其他节点设备进行投票。
  11. 一种计算机可读存储介质,所述存储介质存储有计算机程序,所述计算机程序被处理器执行时实现上述权利要求1-9任一项所述的方法。
  12. 一种电子设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,所述处理器执行所述程序时实现上述权利要求1-9任一项所述的方法。
PCT/CN2023/109513 2022-08-01 2023-07-27 一种节点选举的方法、装置、存储介质及电子设备 WO2024027548A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210916766.9 2022-08-01
CN202210916766.9A CN115002143B (zh) 2022-08-01 2022-08-01 一种节点选举的方法、装置、存储介质及电子设备

Publications (1)

Publication Number Publication Date
WO2024027548A1 true WO2024027548A1 (zh) 2024-02-08

Family

ID=83022133

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2023/109513 WO2024027548A1 (zh) 2022-08-01 2023-07-27 一种节点选举的方法、装置、存储介质及电子设备

Country Status (2)

Country Link
CN (2) CN116170289A (zh)
WO (1) WO2024027548A1 (zh)

Families Citing this family (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116170289A (zh) * 2022-08-01 2023-05-26 北京奥星贝斯科技有限公司 一种节点选举的方法、装置、存储介质及电子设备
CN116466592A (zh) * 2023-03-28 2023-07-21 深圳市集贤科技有限公司 多设备联动方法、装置、存储介质和智能设备
CN116932278A (zh) * 2023-06-21 2023-10-24 天云融创数据科技(北京)有限公司 一种数据库灾备方法、装置和存储介质

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7421578B1 (en) * 2003-07-22 2008-09-02 Cisco Technology, Inc. Method and apparatus for electing a leader node in a computer network
CN112261135A (zh) * 2020-10-22 2021-01-22 腾讯科技(深圳)有限公司 基于一致性协议的节点选举方法、系统、装置及设备
CN114189421A (zh) * 2022-02-17 2022-03-15 江西农业大学 一种领导者节点选举方法、系统、存储介质及设备
CN115002143A (zh) * 2022-08-01 2022-09-02 北京奥星贝斯科技有限公司 一种节点选举的方法、装置、存储介质及电子设备

Family Cites Families (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6993587B1 (en) * 2000-04-07 2006-01-31 Network Appliance Inc. Method and apparatus for election of group leaders in a distributed network
CN109167660B (zh) * 2018-09-07 2021-05-14 腾讯科技(深圳)有限公司 选举代表节点设备方法、装置、计算机设备及存储介质
CN112865959B (zh) * 2020-12-30 2022-05-31 杭州趣链科技有限公司 分布式节点设备的共识方法、节点设备及分布式网络
CN114363154A (zh) * 2021-12-29 2022-04-15 中国电信股份有限公司 节点选举方法、装置、电子设备及存储介质

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7421578B1 (en) * 2003-07-22 2008-09-02 Cisco Technology, Inc. Method and apparatus for electing a leader node in a computer network
CN112261135A (zh) * 2020-10-22 2021-01-22 腾讯科技(深圳)有限公司 基于一致性协议的节点选举方法、系统、装置及设备
CN114189421A (zh) * 2022-02-17 2022-03-15 江西农业大学 一种领导者节点选举方法、系统、存储介质及设备
CN115002143A (zh) * 2022-08-01 2022-09-02 北京奥星贝斯科技有限公司 一种节点选举的方法、装置、存储介质及电子设备

Also Published As

Publication number Publication date
CN115002143B (zh) 2023-01-20
CN116170289A (zh) 2023-05-26
CN115002143A (zh) 2022-09-02

Similar Documents

Publication Publication Date Title
WO2024027548A1 (zh) 一种节点选举的方法、装置、存储介质及电子设备
US9858052B2 (en) Decentralized operating system
WO2017050014A1 (zh) 一种数据存储处理方法和装置
US8429666B2 (en) Computing platform with resource constraint negotiation
WO2022063284A1 (zh) 数据同步方法、装置、设备及计算机可读介质
US9680692B2 (en) Method and system for using a recursive event listener on a node in hierarchical data structure
US11429594B2 (en) Synchronization between primary database and secondary database
US20190347167A1 (en) Primary Node-Standby Node Data Transmission Method, Control Node, and Database System
WO2021057108A1 (zh) 一种读数据方法、写数据方法及服务器
JP2007072975A (ja) ディスクへのトランザクション・データ書き込みの方式を動的に切り替える装置、切り替える方法、及び切り替えるプログラム
CN103458036A (zh) 一种集群文件系统的访问装置和方法
JP2017530437A (ja) 通信障害後の分散ワークロード再割り当て
WO2021082465A1 (zh) 一种保证数据一致性的方法及相关设备
CN111061431B (zh) 一种分布式存储方法、服务器及客户端
US20230030856A1 (en) Distributed table storage processing method, device and system
WO2018072561A1 (zh) 一种视频切换方法、装置及视频巡逻系统
US11784905B2 (en) Method and apparatus for ensuring continued device operational reliability in cloud-degraded mode
US9742692B2 (en) Acquiring resource lease using multiple lease servers
CN105302489A (zh) 一种异构多核远程嵌入式存储器系统与方法
CN111930530A (zh) 一种基于物联网的设备消息处理方法、装置及介质
CN117056033A (zh) 数据处理方法、装置、mec服务器及存储介质
EP4040279A1 (en) Method and apparatus for accessing solid state disk
CN116594551A (zh) 一种数据存储方法及装置
CN117041980B (zh) 一种网元管理方法、装置、存储介质及电子设备
WO2023221804A1 (zh) 内存管理方法、网络设备及计算机可读存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 23849256

Country of ref document: EP

Kind code of ref document: A1