CN111162942A - Cluster election method and system - Google Patents

Cluster election method and system Download PDF

Info

Publication number
CN111162942A
CN111162942A CN201911376179.XA CN201911376179A CN111162942A CN 111162942 A CN111162942 A CN 111162942A CN 201911376179 A CN201911376179 A CN 201911376179A CN 111162942 A CN111162942 A CN 111162942A
Authority
CN
China
Prior art keywords
node
identification information
election
information
main
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201911376179.XA
Other languages
Chinese (zh)
Inventor
张建鹏
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hangzhou Tuya Information Technology Co Ltd
Original Assignee
Hangzhou Tuya Information Technology Co Ltd
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 Hangzhou Tuya Information Technology Co Ltd filed Critical Hangzhou Tuya Information Technology Co Ltd
Priority to CN201911376179.XA priority Critical patent/CN111162942A/en
Publication of CN111162942A publication Critical patent/CN111162942A/en
Pending legal-status Critical Current

Links

Images

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/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/104Peer-to-peer [P2P] networks
    • H04L67/1044Group management mechanisms 
    • H04L67/1051Group master selection mechanisms

Landscapes

  • Engineering & Computer Science (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Mathematical Physics (AREA)
  • Theoretical Computer Science (AREA)
  • Mobile Radio Communication Systems (AREA)

Abstract

The application discloses a cluster election method, which comprises the following steps: a first node sends first election main node information, wherein the first election main node information comprises first identification information of the first node; the first node receives second election main node information sent by a second node, wherein the second election main node information comprises second identification information of the second node; when the second identification information is superior to the first identification information according to a preset rule, the first node stops sending the first election main node information; and when the first identification information is superior to the second identification information according to the preset rule, the first node becomes a main node. Compared with the prior art, the method has the following beneficial effects: the method adopts a lightweight election algorithm, can meet actual use requirements, has simpler logic and less resource occupation, and is more suitable for embedded equipment.

Description

Cluster election method and system
Technical Field
The application relates to the field of Internet of things, in particular to a cluster election method.
Background
The existing cluster election algorithm, such as Raft, PBFT and the like, has the disadvantages of complex logic, difficult understanding, difficult realization and maintenance, more occupied equipment resources and unsuitability for embedded equipment with sensitive resources.
Disclosure of Invention
The main objective of the present application is to provide a cluster election method, including:
a first node sends first election main node information, wherein the first election main node information comprises first identification information of the first node;
the first node receives second election main node information sent by a second node, wherein the second election main node information comprises second identification information of the second node;
when the second identification information is superior to the first identification information according to a preset rule, the first node stops sending the first election main node information;
and when the first identification information is superior to the second identification information according to the preset rule, the first node becomes a main node.
Optionally, when the first identification information is better than the second identification information according to the preset rule, the first node becomes a master node and includes:
and when the first node continuously transmits the first election main node information for n times and does not receive the second election main node information containing second identification information superior to the first identification information, the first node becomes a main node, wherein n is a natural number.
Optionally, n is equal to 3.
Optionally, the first identification information is definition capability information of the first node, and the second identification information is definition capability information of the second node.
Optionally, the first identification information is a mac address of the first node, and the second identification information is a mac address of the second node.
Optionally, the predetermined rule is that the nodes with large mac addresses are better than the nodes with small mac addresses in the order of the mac addresses.
According to another aspect of the present application, there is also provided a cluster election system, including:
a first node sending module, configured to send, by a first node, first election master node information, where the first election master node information includes first identification information of the first node;
a first node receiving module, configured to receive, by a first node, second election master node information sent by a second node, where the second election master node information includes second identification information of the second node;
when the second identification information is superior to the first identification information according to a preset rule, the first node stops sending the first election main node information; and when the first identification information is superior to the second identification information according to the preset rule, the first node becomes a main node.
The application also discloses a computer device, which comprises a memory, a processor and a computer program stored in the memory and capable of being executed by the processor, wherein the processor realizes the method of any one of the above items when executing the computer program.
The application also discloses a computer-readable storage medium, a non-volatile readable storage medium, having stored therein a computer program which, when executed by a processor, implements the method of any of the above.
The present application also discloses a computer program product comprising computer readable code which, when executed by a computer device, causes the computer device to perform the method of any of the above.
Compared with the prior art, the method has the following beneficial effects:
the method adopts a lightweight election algorithm, can meet actual use requirements, has simpler logic and less resource occupation, and is more suitable for embedded equipment.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this application, serve to provide a further understanding of the application and to enable other features, objects, and advantages of the application to be more apparent. The drawings and their description illustrate the embodiments of the invention and do not limit it. In the drawings:
FIG. 1 is a schematic flow diagram of a cluster election method according to one embodiment of the present application;
FIG. 2 is a schematic diagram of a computer device according to one embodiment of the present application; and
FIG. 3 is a schematic diagram of a computer-readable storage medium according to one embodiment of the present application.
Detailed Description
In order to make the technical solutions better understood by those skilled in the art, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are only partial embodiments of the present application, but not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
It should be noted that the terms "first," "second," and the like in the description and claims of this application and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order. It should be understood that the data so used may be interchanged under appropriate circumstances such that embodiments of the application described herein may be used. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed, but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
It should be noted that the embodiments and features of the embodiments in the present application may be combined with each other without conflict. The present application will be described in detail below with reference to the embodiments with reference to the attached drawings.
Referring to fig. 1, an embodiment of the present application provides a cluster election method, including:
s2: a first node sends first election main node information, wherein the first election main node information comprises first identification information of the first node;
s4: the first node receives second election main node information sent by a second node, wherein the second election main node information comprises second identification information of the second node;
s6: when the second identification information is superior to the first identification information according to a preset rule, the first node stops sending the first election main node information;
s8: and when the first identification information is superior to the second identification information according to the preset rule, the first node becomes a main node.
For example, after each node is powered on, the main node election is started, and an election broadcast message is sent to the outside. When the node receives the election broadcast message larger than the node, the node does not send the broadcast, otherwise, the node continues to send the broadcast periodically. After a period of time, only one node is left to transmit broadcast, and when the node continuously transmits 3 election broadcasts and does not receive other election broadcasts, the node becomes a main node. When the node does not send the broadcast any more and continuously receives the election broadcast of the same node for 3 times, the node becomes a common node, and the broadcaster is regarded as a main node.
In this embodiment, the message is sent in a broadcast manner because the usage scenario of this embodiment is defined as in the smart home lan, but not limited thereto. The message is not limited to be sent in a broadcast mode, and other modes can be adopted. Meanwhile, the method is not limited to the cluster election in the local area network, and is also applicable to the cluster election of the non-local area network, and the method is within the scope claimed by the application. In addition, in the present embodiment, the transmission message is transmitted periodically, but the present invention is not limited to this, and other transmission frequencies, such as timing transmission or real-time transmission, may also be used, and all fall within the scope of the present invention.
The first node and the second node described in the present application do not refer to a specific node, but refer to a specific type of node. That is, when the node is the node that sends the election master node information, it is the first node. When the node is used as the node for receiving the election main node information, the node is the second node. When the node is used as both the node for sending the election master node information and the node for receiving the election master node information, the node is a first node and a second node.
In an embodiment of the present application, when the first identification information is better than the second identification information according to the preset rule, the first node becomes a master node, and the first node includes:
and when the first node continuously transmits the first election main node information for n times and does not receive the second election main node information containing second identification information superior to the first identification information, the first node becomes a main node, wherein n is a natural number.
The node n that sends election master node information is equal to 3.
And the first identification information of the node sending the election master node information is the definition capability information of the first node, and the second identification information is the definition capability information of the second node.
The first identification information of the node sending the election main node information is the media access control address (mac address) of the first node, and the second identification information is the media access control address of the second node. However, the present invention is not limited thereto, and those skilled in the art may use other identification information to specify the preset rule, and may also use several kinds of identification information at the same time, or even use non-identification information to specify the preset rule. And the advantages in the preset rule are not equal to the advantages, but any size relationship, functional relationship and the like can be equal to the advantages.
The preset rule of the nodes sending the election main node information is sorted according to the size of the MAC address, and the nodes with large MAC addresses are superior to the nodes with small MAC addresses.
The present application further provides a cluster election system, which includes:
a first node sending module, configured to send, by a first node, first election master node information, where the first election master node information includes first identification information of the first node;
a first node receiving module, configured to receive, by a first node, second election master node information sent by a second node, where the second election master node information includes second identification information of the second node;
when the second identification information is superior to the first identification information according to a preset rule, the first node stops sending the first election main node information; and when the first identification information is superior to the second identification information according to the preset rule, the first node becomes a main node.
Compared with the prior art, the method has the following beneficial effects:
the method adopts a lightweight election algorithm, can meet actual use requirements, has simpler logic and less resource occupation, and is more suitable for embedded equipment.
Referring to fig. 2, the present application further provides a computer device including a memory, a processor, and a computer program stored in the memory and executable by the processor, wherein the processor implements the method of any one of the above methods when executing the computer program.
Referring to fig. 3, a computer-readable storage medium, a non-volatile readable storage medium, having stored therein a computer program which, when executed by a processor, implements any of the methods described above.
A computer program product comprising computer readable code which, when executed by a computer device, causes the computer device to perform the method of any of the above.
It will be apparent to those skilled in the art that the modules or steps of the present invention described above may be implemented by a general purpose computing device, they may be centralized on a single computing device or distributed across a network of multiple computing devices, and they may alternatively be implemented by program code executable by a computing device, such that they may be stored in a storage device and executed by a computing device, or fabricated separately as individual integrated circuit modules, or fabricated as a single integrated circuit module from multiple modules or steps. Thus, the present invention is not limited to any specific combination of hardware and software.
The above description is only a preferred embodiment of the present application and is not intended to limit the present application, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, improvement and the like made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims (10)

1. A method for cluster election, comprising:
a first node sends first election main node information, wherein the first election main node information comprises first identification information of the first node;
the first node receives second election main node information sent by a second node, wherein the second election main node information comprises second identification information of the second node;
when the second identification information is superior to the first identification information according to a preset rule, the first node stops sending the first election main node information;
and when the first identification information is superior to the second identification information according to the preset rule, the first node becomes a main node.
2. The method of claim 1, wherein when the first identity information is better than the second identity information according to the predetermined rule, the first node becoming a master node comprises:
and when the first node continuously transmits the first election main node information for n times and does not receive the second election main node information containing second identification information superior to the first identification information, the first node becomes a main node, wherein n is a natural number.
3. A method of cluster election according to claim 2, characterized in that n equals 3.
4. A method as claimed in claim 3, wherein the first identification information is the definition capability information of the first node, and the second identification information is the definition capability information of the second node.
5. A method as claimed in claim 3, wherein the first identification information is the mac address of the first node and the second identification information is the mac address of the second node.
6. The method of claim 5, wherein the predetermined rule is that nodes with larger MAC addresses are ordered according to the MAC address size, and nodes with smaller MAC addresses are preferred.
7. A cluster election system comprising:
a first node sending module, configured to send, by a first node, first election master node information, where the first election master node information includes first identification information of the first node;
a first node receiving module, configured to receive, by a first node, second election master node information sent by a second node, where the second election master node information includes second identification information of the second node;
when the second identification information is superior to the first identification information according to a preset rule, the first node stops sending the first election main node information; and when the first identification information is superior to the second identification information according to the preset rule, the first node becomes a main node.
8. A computer device comprising a memory, a processor and a computer program stored in the memory and executable by the processor, wherein the processor implements the method of any one of claims 1-6 when executing the computer program.
9. A computer-readable storage medium, a non-transitory readable storage medium, having stored therein a computer program, characterized in that the computer program, when executed by a processor, implements the method according to any one of claims 1-6.
10. A computer program product comprising computer readable code that, when executed by a computer device, causes the computer device to perform the method of any of claims 1-6.
CN201911376179.XA 2019-12-27 2019-12-27 Cluster election method and system Pending CN111162942A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911376179.XA CN111162942A (en) 2019-12-27 2019-12-27 Cluster election method and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911376179.XA CN111162942A (en) 2019-12-27 2019-12-27 Cluster election method and system

Publications (1)

Publication Number Publication Date
CN111162942A true CN111162942A (en) 2020-05-15

Family

ID=70558482

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911376179.XA Pending CN111162942A (en) 2019-12-27 2019-12-27 Cluster election method and system

Country Status (1)

Country Link
CN (1) CN111162942A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113596176A (en) * 2021-08-12 2021-11-02 杭州萤石软件有限公司 Self-selection method and device of Internet of things center node, Internet of things equipment and system
CN113765795A (en) * 2021-10-15 2021-12-07 北京小米移动软件有限公司 Networking method, device, system and storage medium

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101217402A (en) * 2008-01-15 2008-07-09 杭州华三通信技术有限公司 A method to enhance the reliability of the cluster and a high reliability communication node
CN103491168A (en) * 2013-09-24 2014-01-01 浪潮电子信息产业股份有限公司 Cluster election design method
US20180314601A1 (en) * 2017-04-28 2018-11-01 Splunk Inc. Intelligent captain selection for disaster recovery of search head cluster
CN109995835A (en) * 2017-12-29 2019-07-09 浙江宇视科技有限公司 Host node electoral machinery, device and distributed memory system
CN110062027A (en) * 2019-03-18 2019-07-26 中科恒运股份有限公司 Load-balancing method, central server and terminal device
CN110501979A (en) * 2018-05-18 2019-11-26 深圳市优必选科技有限公司 Cluster control method, system and terminal equipment

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101217402A (en) * 2008-01-15 2008-07-09 杭州华三通信技术有限公司 A method to enhance the reliability of the cluster and a high reliability communication node
CN103491168A (en) * 2013-09-24 2014-01-01 浪潮电子信息产业股份有限公司 Cluster election design method
US20180314601A1 (en) * 2017-04-28 2018-11-01 Splunk Inc. Intelligent captain selection for disaster recovery of search head cluster
CN109995835A (en) * 2017-12-29 2019-07-09 浙江宇视科技有限公司 Host node electoral machinery, device and distributed memory system
CN110501979A (en) * 2018-05-18 2019-11-26 深圳市优必选科技有限公司 Cluster control method, system and terminal equipment
CN110062027A (en) * 2019-03-18 2019-07-26 中科恒运股份有限公司 Load-balancing method, central server and terminal device

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113596176A (en) * 2021-08-12 2021-11-02 杭州萤石软件有限公司 Self-selection method and device of Internet of things center node, Internet of things equipment and system
CN113596176B (en) * 2021-08-12 2024-03-08 杭州萤石软件有限公司 Self-selection method and device of center node of Internet of things, internet of things equipment and system
CN113765795A (en) * 2021-10-15 2021-12-07 北京小米移动软件有限公司 Networking method, device, system and storage medium

Similar Documents

Publication Publication Date Title
CN109936640A (en) From the address distribution method and device of node device
CN106598760B (en) Consumption method and device of message queue
CN109379448B (en) File distributed deployment method and device, electronic equipment and storage medium
CN105337755A (en) Master-slave architecture server, service processing method thereof and service processing system thereof
CN110061992B (en) Method for dynamically configuring FPGA and network security equipment
CN113946431B (en) Resource scheduling method, system, medium and computing device
CN115587065A (en) Master-slave machine control method, master-slave machine control system and blood cabinet
US10412751B2 (en) Scheduling method and apparatus
CN110557416B (en) Multi-node collaborative blocking method and system
CN111162942A (en) Cluster election method and system
CN109298924A (en) Management method, computer readable storage medium and the terminal device of timed task
CN114710571B (en) Data packet processing system
CN108170417B (en) Method and device for integrating high-performance job scheduling framework in MESOS cluster
CN114285695B (en) Communication method, device, apparatus, system and storage medium
CN105207866B (en) Communication method of control terminal based on air conditioner control network and air conditioner control network
CN116483547A (en) Resource scheduling method, device, computer equipment and storage medium
CN107920035B (en) Multi-core processor type device, system and vehicle for deterministic switched Ethernet
CN109309671A (en) A kind of communications device data management method and device based on block chain
CN105450488B (en) A kind of data processing method and relevant apparatus
CN111309467B (en) Task distribution method and device, electronic equipment and storage medium
CN113839783A (en) Task processing method, device and equipment
CN113901015A (en) Distributed data sharing method and device, storage node card and computer equipment
CN112541038A (en) Time series data management method, system, computing device and storage medium
CN111030925A (en) Multi-gateway communication method and system based on remote procedure call
CN114172864B (en) Internet of things terminal address allocation method and device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication
RJ01 Rejection of invention patent application after publication

Application publication date: 20200515