Master node election method and system based on OpenHarmony distributed networking
By quantifying node performance values and employing a hierarchical election strategy, high-performance, low-load master nodes are elected, solving the problems of low resource allocation efficiency and poor communication protocol compatibility in OpenHarmony distributed networking, thereby improving system operating efficiency and fault tolerance.
Patent Information
- Application Number
- CN202511485295.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-10-17
- Publication Date
- 2025-11-18
AI Technical Summary
In OpenHarmony distributed networking, the lack of a central control node leads to low efficiency in resource allocation among devices, poor compatibility of communication protocols, and the existing master node election method fails to effectively adapt to differences in device performance, resulting in low system efficiency.
By quantifying node performance to calculate node performance values and combining them with a tiered election strategy, high-performance, low-load candidate nodes are elected as master nodes. The tiered election strategy and priority ranking ensure that the election results of the master nodes are consistent with the actual capabilities of the nodes.
It improves the overall operating efficiency of the system, reduces the election risk of low-performance nodes, enhances the system's fault tolerance, adapts to distributed networks of different scales and types, and solves compatibility and security issues in cross-network communication.
Smart Images

Figure CN120979873A_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of distributed system technology, and in particular to a master node election method and system based on OpenHarmony distributed networking. Background Technology
[0002] OpenHarmony, as a distributed operating system for all scenarios, relies on distributed soft bus technology to achieve interconnection between devices. Although its decentralized architecture eliminates the risk of single point of failure, it has exposed many problems in cross-network applications, making the introduction of a master node an inevitable requirement.
[0003] In a cross-network environment using the OpenHarmony distributed soft bus, the lack of a central control node makes it difficult for devices to efficiently negotiate resource allocation. For example, when a home smart camera and an office server simultaneously request network bandwidth, the lack of unified scheduling may cause video transmission lag from the camera, while server resources are not fully utilized. In this situation, the master node can allocate resources in a coordinated manner based on device needs and priorities according to a global resource view, thereby improving overall resource utilization.
[0004] like Figure 1 As shown, existing cross-network communication methods based on master nodes also suffer from poor communication protocol compatibility and a lack of effective protocol conversion and adaptation mechanisms for master nodes. Furthermore, in IoT scenarios, OpenHarmony distributed networking devices exhibit significant performance differences. Existing master node election methods, such as the Bully algorithm and Raft algorithm, either ignore device performance differences or have high communication overhead and complex implementation, making them difficult to adapt to diverse device requirements. Summary of the Invention
[0005] The following is an overview of the subject matter described in detail herein. This overview is not intended to limit the scope of the claims.
[0006] The main objective of this disclosure is to propose a master node election method and system based on OpenHarmony distributed networking. By quantifying node performance to calculate node performance values and combining a hierarchical election strategy, it ensures that high-performance, low-load nodes are given priority in being elected as master nodes, thereby fully leveraging node advantages and improving the overall system operating efficiency.
[0007] A first aspect of this application proposes a master node election method based on OpenHarmony distributed networking, the method comprising: In response to the master node election signal, determine all nodes that can participate in the OpenHarmony distributed network and their corresponding node performance values; wherein, the node performance value is calculated based on the value and weight of the node's corresponding node performance index; Based on the node performance value, select multiple nodes whose node performance value is greater than a first threshold from all nodes as candidate nodes; The candidate nodes are sorted according to their performance values to obtain a sorting result; wherein, when at least two candidate nodes have the same performance value, the priority of the two candidate nodes is determined according to their node status, and the at least two candidate nodes are sorted according to their priority. The ranking result is broadcast to the OpenHarmony distributed network so that non-candidate nodes can vote for the candidate node ranked first according to the ranking result, and after the voting result of the candidate node ranked first meets the requirements, the new master node is elected; wherein, the non-candidate nodes are all nodes in the OpenHarmony distributed network other than the candidate nodes.
[0008] This embodiment provides a master node election method based on OpenHarmony distributed networking, which has at least the following advantages: This method quantifies the performance value of each node participating in the master node election and selects candidate nodes from multiple nodes based on these performance values. This ensures that the selected candidate nodes better reflect the actual capabilities of the nodes, preventing low-performance nodes from being elected as master nodes and thus avoiding system inefficiency. Furthermore, this method employs a priority election strategy. When at least two candidate nodes have the same performance value, their priorities are determined based on their current state. These two candidate nodes are then ranked according to their priority, identifying the candidate node with the better state. Finally, a vote is held on the candidate node ranked first. Only when the voting results for the top-ranked candidate node meet the requirements is that node selected as the new master node. This method, by quantifying node performance and combining it with a tiered election strategy, ensures that high-performance, low-load nodes are prioritized for master node election, fully leveraging node advantages and improving overall system efficiency.
[0009] In one embodiment of this application, the node performance metrics include at least one of computing performance, storage performance, network performance, energy status, and task load; Determine the node performance values of all nodes that can participate in the OpenHarmony distributed network, including: Determine the value of at least one of the node performance metrics; Determine the weight of at least one of the node performance metrics; Based on the values and weights of at least one of the node performance indicators, a weighted sum is calculated to obtain the node performance value corresponding to the node.
[0010] In one embodiment of this application, determining the weight of the at least one node performance metric includes: Determine the importance value of at least one of the node performance metrics; Calculate the feature vector of at least one of the node performance metrics based on the importance value; The feature vectors are calculated to sum the feature vectors of at least one of the node performance metrics; Calculate the quotient between the feature vector of the at least one node performance metric and the sum of the feature vectors; The quotient of at least one of the node performance metrics is used as the weight.
[0011] In one embodiment of this application, prior to responding to the master node election signal, the method further includes: The master node election signal is generated under at least one of the following conditions (one through five): Scenario 1 is: at least one of the nodes has not received a heartbeat packet from the current master node within multiple consecutive heartbeat cycles; Scenario 2 is: a newly added node appears in the OpenHarmony distributed network; Scenario 3 is: the load of the current master node exceeds the third threshold; Case four is: the performance value of a node exceeds the performance value of the current master node; Case 5 is: The current master node does not meet the requirements for cross-network communication.
[0012] In one embodiment of this application, when at least two candidate nodes have the same node performance value, the priority of the two candidate nodes is determined based on the node state of the candidate nodes, and the at least two candidate nodes are sorted according to the priority, including: Determine at least two candidate nodes in four states, wherein the first to fourth states are: node type, power status, node ID, and cross-network communication capability; In accordance with the order from the first state to the fourth state, when a state first appears that can distinguish the priorities of at least two candidate nodes, the priorities of at least two candidate nodes are determined according to that state, and the at least two candidate nodes are sorted according to the priorities.
[0013] In one embodiment of this application, the step of selecting a candidate node whose vote count exceeds the second threshold as the new master node when the number of votes for a candidate node exceeds the second threshold includes: If the number of votes for a candidate node exceeds half the number of all nodes, the candidate node with the number of votes exceeding half the number of all nodes is selected as the new master node.
[0014] In one embodiment of this application, the first threshold is the average of the node performance values of all nodes.
[0015] A second aspect of this application proposes a master node election system based on OpenHarmony distributed networking, the system comprising: The participating node determination module is used to respond to the master node election signal and determine all participating nodes and their corresponding node performance values in the OpenHarmony distributed network; wherein, the node performance value is calculated based on the value and weight of the node's corresponding node performance index; The candidate node filtering module is used to select multiple nodes whose node performance values are greater than a first threshold from all nodes as candidate nodes based on the node performance values. A candidate node sorting module is used to sort multiple candidate nodes according to the size of the node performance value to obtain a sorting result; wherein, when there are at least two candidate nodes with the same node performance value, the priority of the two candidate nodes is determined according to the node state of the candidate nodes, and the at least two candidate nodes are sorted according to the priority. The master node selection module is used to broadcast the ranking results to the OpenHarmony distributed network, so that non-candidate nodes can vote for the candidate node ranked first according to the ranking results, and after the voting results of the candidate node ranked first meet the requirements, the new master node is elected; wherein, the non-candidate nodes are all nodes in the OpenHarmony distributed network other than the candidate nodes.
[0016] A third aspect of this application provides an electronic device including at least one control processor and a memory for communicatively connecting to the at least one control processor; the memory stores instructions executable by the at least one control processor, which, when executed by the at least one control processor, enable the at least one control processor to perform the master node election method based on OpenHarmony distributed networking as described in the first aspect above.
[0017] A fourth aspect of this application provides a readable storage medium storing computer-executable instructions for causing a computer to perform the master node election method based on OpenHarmony distributed networking as described in the first aspect above.
[0018] Additional aspects and advantages of this application will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of this application. Attached Figure Description
[0019] To more clearly illustrate the technical solutions in the embodiments of this application, the drawings used in the description of the embodiments or related technologies will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the embodiments of this application. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0020] Figure 1 This is a schematic diagram of the cross-network communication architecture provided in the embodiments of this application; Figure 2 This is a flowchart illustrating a master node election method based on OpenHarmony distributed networking provided in an embodiment of this application; Figure 3 This is a schematic diagram of the architecture for calculating performance values provided in an embodiment of this application; Figure 4 This is a flowchart illustrating a master node election method provided in another embodiment of this application; Figure 5 This is a schematic diagram illustrating the specific process of master node election provided in the embodiments of this application; Figure 6 This is a schematic diagram of the structure of a master node election system based on OpenHarmony distributed networking provided in an embodiment of this application; Figure 7 This is a schematic diagram of the structure of the electronic device provided in the embodiments of this application. Detailed Implementation
[0021] To make the objectives, technical solutions, and advantages of this application clearer, the following detailed description is provided in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the scope of this application.
[0022] In the description of this application, the use of terms such as "first," "second," etc., is for the purpose of distinguishing technical features only and should not be construed as indicating or implying relative importance or implicitly indicating the number of technical features indicated or the order of the technical features indicated.
[0023] In the description of this application, it should be understood that the orientation descriptions, such as up, down, etc., are based on the orientation or positional relationship shown in the accompanying drawings, and are only for the convenience of describing this application and simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, be constructed or function in a specific orientation, and therefore should not be construed as a limitation of this application.
[0024] like Figures 2 to 5 One embodiment of this application provides a master node election method based on OpenHarmony distributed networking, the method including the following steps S110 to S140: Step S110: Respond to the master node election signal and determine all nodes that can participate in the OpenHarmony distributed network and their corresponding node performance values.
[0025] In this step, after the master node election signal is generated, in response to the master node election signal, first determine all nodes that can participate in the OpenHarmony distributed network. For example, if the OpenHarmony distributed network has a current master node and multiple slave nodes, and the current master node has a large load, a new master node needs to be re-elected. Then, slave nodes can participate in the election of the master node. Then, count the participating master nodes and execute the subsequent process.
[0026] In this step, the node performance value is calculated based on the numerical value and weight of the node's corresponding node performance index.
[0027] Node performance metrics include at least one of computing performance, storage performance, network performance, energy status, and task load; In this embodiment, the following describes the various performance indicators: 1) Computing performance, such as quantitative scoring based on parameters like the number of CPU cores, clock speed, and memory capacity of a node; 2) Storage performance: scored based on indicators such as node storage capacity and read / write speed; 3) Network performance: Evaluated through parameters such as signal strength, network latency, and bandwidth; 4) Energy Status: For battery-powered nodes, scores are given based on remaining power and power consumption. 5) Task load: The number and complexity score of tasks undertaken by the current node.
[0028] Step S110, which determines the node performance values of all nodes that can participate in the OpenHarmony distributed network, includes the following steps S210 to S230: Step S210: Determine the value of at least one node performance metric. The value can be quantified based on experience.
[0029] Step S220: Determine the weight of at least one node performance metric.
[0030] Step S230: Calculate a weighted sum based on the values and weights of at least one node performance indicator to obtain the node performance value corresponding to the node.
[0031] The following describes the weight of each node performance metric: Assume that the weight of computing performance is P1, the weight of storage performance is P2, the weight of network performance is P3, the weight of energy status is P4, and the weight of task load is P5.
[0032] The following describes a weight calculation scheme: Determining the weight of at least one node performance metric in step S220 includes the following steps S2210 to S2250: Step S2210: Determine the importance value of at least one node performance metric.
[0033] Step S2220: Calculate the feature vector of at least one node performance index based on the importance value.
[0034] Step S2230: Calculate the feature vectors by summing the feature vectors of at least one node performance index.
[0035] Step S2240: Calculate the quotient between the feature vector and the sum of feature vectors of at least one node performance index.
[0036] Step S2250: Use the quotient of at least one node performance metric as a weight.
[0037] Taking five node performance metrics—computing performance, storage performance, network performance, energy status, and workload—as examples: (1) First, assign a score to the "importance value" of the indicator; for example, the importance relationship is: Computational performance is the most important, followed by energy status, then storage performance, then workload, and finally network performance. Using a scale of 1-9 to represent "which is more important than which" (1 indicates equal importance, 3 indicates slightly important, 5 indicates significantly important, with higher numbers indicating greater differences), we can obtain a scoring table (i.e., a judgment matrix within the domain), as shown in the table below: Table 1
[0038] (2) Calculate the eigenvalues and eigenvectors; Enter the scoring table above into a computer (e.g., Excel or a Python tool), and it will automatically calculate two key results: Maximum eigenvalue: For example, 5.24 (this number is used to check whether the scoring is reasonable); Feature vector: For example, [0.83, 0.30, 0.13, 0.54, 0.21] (this set of numbers reflects the "relative importance" of each indicator); (3) Transform the feature vectors into weights; The sum of the numbers in the eigenvectors is: 0.83 + 0.30 + 0.13 + 0.54 + 0.21 = 2.01; Then, divide each number by the sum to get the weight (the sum is 1): Weight of computational performance: 0.83 ÷ 2.01 ≈ 0.41 (41%). Storage performance weight: 0.30 ÷ 2.01 ≈ 0.15 (15%); The weight of network performance is: 0.13 ÷ 2.01 ≈ 0.06 (6%). Weight of energy state: 0.54 ÷ 2.01 ≈ 0.27 (27%); The weight of the task load is: 0.21 ÷ 2.01 ≈ 0.10 (10%). (4) Check whether the scoring is reasonable; Using the largest eigenvalue (5.24) to calculate a consistency index, the result is less than 0.1, indicating that there is no contradiction in the scoring (for example, there will be no confusing situation such as "computing performance is more important than energy state, energy state is more important than computing performance, and finally it is said that storage performance is more important than computing performance"). Therefore, the above weights are effective.
[0039] (5) Final conclusion; The approximate weights of these 5 node performance metrics are: Computing performance accounts for 41%, energy status accounts for 27%, storage performance accounts for 15%, task load accounts for 10%, and network performance accounts for 6%.
[0040] This embodiment adds node performance metrics such as computing performance, storage performance, network performance, energy status, and workload, assigning a node performance value to each node. For example, in a smart home scenario, a smart gateway, due to its strong computing and network performance, will have a higher node performance value; while a temperature and humidity sensor, with relatively weaker computing, storage, network, energy status, and workload, will have a lower node performance value. This approach ensures that the election results more closely reflect the actual capabilities of the nodes, avoiding the problem of low-performance nodes being elected as master nodes and causing system inefficiency.
[0041] Step S120: Based on the node performance value, select multiple nodes whose node performance value is greater than the first threshold from all nodes as candidate nodes.
[0042] In this step, when a node's performance value is greater than the first threshold, the corresponding node is selected as a candidate node, thereby enabling it to participate in the election process of the master node.
[0043] In some embodiments, the first threshold may be the average node performance value of all nodes, and if a node performance value exceeds the average node performance value, the corresponding node is selected as a candidate node.
[0044] Step S130: Sort multiple candidate nodes according to their performance values to obtain a sorting result; wherein, when there are at least two candidate nodes with the same performance value, determine the priority of the two candidate nodes according to their node status, and sort the at least two candidate nodes according to their priority.
[0045] In this step, when at least two candidate nodes have the same node performance value, this example introduces a priority process, which involves a secondary sorting of all candidate nodes with the same value. In some embodiments, the priority determination process includes the following steps S310 to S320: Step S310: Determine the four states of at least two candidate nodes, where the first to fourth states are: node type, power status, node ID, and cross-network communication capability.
[0046] Step S320: In the order from the first state to the fourth state, when a state first appears that can distinguish the priority of at least two candidate nodes, the priority of at least two candidate nodes is determined according to the state, and the at least two candidate nodes are sorted according to the priority.
[0047] For example, sorting is determined by priority: 1) Node type priority: High-performance nodes such as servers and smart gateways are given priority; 2) Power status priority: Among battery-powered nodes, nodes with sufficient power have priority; 3) Node ID priority: Nodes with larger IDs have higher priority; 4) Nodes with cross-network communication capabilities are given priority (such as nodes that support multiple communication protocol conversions).
[0048] Existing election schemes lack effective node screening and priority stratification in the election process. This embodiment adopts a hierarchical election strategy. First, candidate nodes are screened based on a first threshold of node performance values to reduce communication overhead in invalid elections. Second, in priority ranking, in addition to considering node type and node ID, power status and cross-network communication capabilities are added as priorities. For example, in cross-network scenarios, nodes that support multiple communication protocol conversions are elected first. Compared with existing technologies, this better meets cross-network communication needs while reducing energy consumption and extending node lifespan.
[0049] Step S140: Broadcast the ranking results to the OpenHarmony distributed network so that non-candidate nodes can vote for the top-ranked candidate node according to the ranking results. After the voting results of the top-ranked candidate node meet the requirements, it will be elected as the new master node. Among them, non-candidate nodes are all nodes in the OpenHarmony distributed network other than the candidate nodes.
[0050] In this embodiment, a broadcast can be sent to every node in the OpenHarmony distributed network, enabling non-candidate nodes, excluding candidate nodes, to participate in the voting process.
[0051] In some embodiments, after the voting results of the top-ranked candidate node meet the requirements, a new master node is elected, including: If the number of votes for the top-ranked candidate node exceeds half the number of votes for the non-candidate nodes, the top-ranked candidate node is selected as the new master node.
[0052] In some embodiments, if the voting result of the top-ranked candidate node does not meet the requirements, voting can be conducted on the next-ranked candidate node, or the process can wait for the next master node election signal to be generated.
[0053] This application provides a master node election method based on OpenHarmony distributed networking, which has at least the following beneficial effects: 1) By quantifying the node performance value and combining it with a priority election strategy, we can ensure that high-performance, low-load candidate nodes are elected as master nodes first, give full play to the advantages of nodes, and improve the overall operating efficiency of distributed networking. 2) In the event of a master node failure or performance degradation, a rapid re-election can be conducted to effectively prevent system paralysis caused by master node problems and improve system fault tolerance. 3) The election process and master node maintenance fully consider the node's energy status and task load to reduce the energy consumption of low-performance nodes participating in the election; 4) This method is applicable to OpenHarmony distributed networking of different scales and node types. It can dynamically adjust the election strategy as the number and type of nodes change to ensure stable system operation. 5) By electing a master node with cross-network communication capabilities and adopting mechanisms such as protocol conversion, security authentication, and path optimization, the compatibility, security, and reliability issues in existing cross-network communication are effectively resolved, enabling efficient and secure communication between various distributed networks.
[0054] For ease of understanding, this application provides an embodiment of a master node election method based on OpenHarmony distributed networking. This method includes: Step S910: First, calculate the set node performance value for each node in the network; Existing election schemes include, but are not limited to, the Bully algorithm and the Raft algorithm. The Bully algorithm elects nodes solely based on their IDs, completely ignoring node performance. While the Raft algorithm supports fault tolerance, it does not adequately consider differences in node performance.
[0055] This method uses the following indicators for comprehensive calculation: The weights for computing performance are P1, storage performance is P2, network performance is P3, energy status is P4, and task load is P5.
[0056] The formula for calculating node performance is: W = P1×C + P2×S + P3×N + P4×E + P5×L, where C, S, N, E, and L are the quantified values of computing performance, storage performance, network performance, energy status, and task load, respectively.
[0057] Step S920: Trigger the master node election signal. The triggering conditions include the following: Case 1 is: at least one node has not received a heartbeat packet from the current master node within N consecutive heartbeat cycles; Scenario 2 is: A new node has been added to the OpenHarmony distributed network; Scenario 3 is: The current master node's load exceeds the third threshold; Scenario 4 is: There exists a node whose performance value exceeds that of the current master node; Case 5 is: The current master node does not meet the requirements for cross-network communication.
[0058] Step S930: Trigger the hierarchical strategy; Candidate nodes are sorted in descending order of their performance values. For nodes with the same performance value, the following priority is used to determine the order: 1) Node type priority: High-performance nodes such as servers and smart gateways are given priority; 2) Power status priority: Among battery-powered nodes, nodes with sufficient power have priority; 3) Node ID priority: Nodes with larger IDs have higher priority; 4) Nodes with cross-network communication capabilities are given priority (such as nodes that support multiple communication protocol conversions).
[0059] In step S940, the candidate node at the top of the broadcast information is voted on, and when the number of votes for a candidate node exceeds half of the total number of nodes, the candidate node is selected as the new master node; the other nodes are selected as slave nodes.
[0060] Step S950, New master node dynamic maintenance mechanism: The master node periodically sends heartbeat packets to slave nodes. If a slave node does not receive a heartbeat packet within N consecutive heartbeat cycles, a new election is triggered. The master node monitors its own load and node performance values in real time. When the load exceeds a threshold L or the node performance value falls below a certain threshold (e.g., 80% of the performance value of the current best slave node), it proactively initiates a re-election. Simultaneously, other slave nodes also monitor their own performance changes in real time. If their node performance value exceeds that of the master node, they can proactively initiate an election. The master node has protocol conversion capabilities, automatically identifying communication protocols and data formats of different distributed networks and performing protocol conversion and data adaptation. The master node employs encrypted communication and two-way authentication mechanisms to ensure the security of cross-network communication. Through intelligent routing algorithms, the master node optimizes cross-network communication paths, reduces network latency, and improves communication reliability.
[0061] like Figure 6 As shown in one embodiment of this application, a master node election system based on OpenHarmony distributed networking is provided. The system includes: The participating node determination module 1100 is used to respond to the master node election signal and determine all participating nodes and their corresponding node performance values in the OpenHarmony distributed network; wherein, the node performance value is calculated based on the value and weight of the node's corresponding node performance index; The candidate node filtering module 1200 is used to select multiple nodes whose node performance values are greater than a first threshold as candidate nodes from all nodes based on the node performance values. The candidate node sorting module 1300 is used to sort multiple candidate nodes according to the size of their node performance values to obtain a sorting result; wherein, when there are at least two candidate nodes with the same node performance value, the priority of the two candidate nodes is determined according to the node status of the candidate nodes, and the at least two candidate nodes are sorted according to the priority. The master node selection module 1400 is used to broadcast the ranking results to the OpenHarmony distributed network so that non-candidate nodes can vote for the top-ranked candidate node according to the ranking results. After the voting results of the top-ranked candidate node meet the requirements, the new master node is elected. Among them, non-candidate nodes are all nodes in the OpenHarmony distributed network other than the candidate nodes.
[0062] It should be noted that the master node election system based on OpenHarmony distributed networking in this application embodiment is based on the same inventive concept as the aforementioned master node election method based on OpenHarmony distributed networking. Therefore, the master node election system based on OpenHarmony distributed networking in this application embodiment corresponds to the aforementioned master node election method based on OpenHarmony distributed networking. For the specific implementation process, please refer to the aforementioned master node election method based on OpenHarmony distributed networking, which will not be repeated here.
[0063] This application also provides an electronic device, which includes: At least one memory; At least one processor; At least one program; The program is stored in memory, and the processor executes at least one program to implement the master node election method based on OpenHarmony distributed networking described above in this disclosure.
[0064] This electronic device can be any smart terminal, including mobile phones, tablets, personal digital assistants (PDAs), and in-vehicle computers.
[0065] The following is combined Figure 7 The electronic devices described in the embodiments of this application will be described in detail.
[0066] like Figure 7 , Figure 7 The hardware structure of an electronic device according to another embodiment is illustrated. The electronic device includes: The processor 1600 can be implemented using a general-purpose central processing unit (CPU), microprocessor, application-specific integrated circuit (ASIC), or one or more integrated circuits, and is used to execute relevant programs to implement the technical solutions provided in the embodiments of this disclosure. The memory 1700 can be implemented as a read-only memory (ROM), static storage device, dynamic storage device, or random access memory (RAM). The memory 1700 can store the operating system and other application programs. When the technical solutions provided in the embodiments of this specification are implemented through software or firmware, the relevant program code is stored in the memory 1700 and is called and executed by the processor 1600 to execute a master node election method based on OpenHarmony distributed networking according to an embodiment of this disclosure.
[0067] The input / output interface 1800 is used to implement information input and output. The communication interface 1900 is used to enable communication and interaction between this device and other devices. Communication can be achieved through wired means (such as USB, Ethernet cable, etc.) or wireless means (such as mobile network, WIFI, Bluetooth, etc.). Bus 2000 transmits information between various components of the device (e.g., processor 1600, memory 1700, input / output interface 1800, and communication interface 1900); The processor 1600, memory 1700, input / output interface 1800 and communication interface 1900 communicate with each other within the device via bus 2000.
[0068] This disclosure also provides a storage medium, which is a computer-readable storage medium storing computer-executable instructions for causing a computer to execute the aforementioned master node election method based on OpenHarmony distributed networking.
[0069] Memory, as a non-transitory computer-readable storage medium, can be used to store non-transitory software programs and non-transitory computer-executable programs. Furthermore, memory may include high-speed random access memory, and may also include non-transitory memory, such as at least one disk storage device, flash memory device, or other non-transitory solid-state storage device. In some embodiments, memory may optionally include memory remotely located relative to the processor, which can be linked to the processor via a network. Examples of such networks include, but are not limited to, the Internet, intranets, local area networks, mobile communication networks, and combinations thereof.
[0070] The embodiments described in this disclosure are for the purpose of more clearly illustrating the technical solutions of this disclosure and do not constitute a limitation on the technical solutions provided by this disclosure. As those skilled in the art will know, with the evolution of technology and the emergence of new application scenarios, the technical solutions provided by this disclosure are also applicable to similar technical problems.
[0071] Those skilled in the art will understand that the technical solutions shown in the figures do not constitute a limitation on the embodiments of this disclosure, and may include more or fewer steps than shown, or combine certain steps, or different steps.
[0072] The device embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs.
[0073] Those skilled in the art will understand that all or some of the steps in the methods disclosed above, as well as the functional modules / units in the systems and devices, can be implemented as software, firmware, hardware, or suitable combinations thereof.
[0074] The terms “first,” “second,” “third,” “fourth,” etc. (if present) in the specification and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this application described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms “comprising” and “having,” and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0075] It should be understood that in this application, "at least one (item)" means one or more, and "more than" means two or more. "And / or" is used to describe the relationship between related objects, indicating that three relationships can exist. For example, "A and / or B" can represent three cases: only A exists, only B exists, and both A and B exist simultaneously, where A and B can be singular or plural. The character " / " generally indicates that the preceding and following related objects are in an "or" relationship. "At least one (item) of the following" or similar expressions refer to any combination of these items, including any combination of single or plural items. For example, at least one (item) of a, b, or c can represent: a, b, c, "a and b", "a and c", "b and c", or "a and b and c", where a, b, and c can be single or multiple.
[0076] In the several embodiments provided in this application, it should be understood that the disclosed apparatus and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication links shown or discussed may be through some interfaces; the indirect coupling or communication links between apparatuses or units may be electrical, mechanical, or other forms.
[0077] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0078] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0079] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes multiple instructions to cause an electronic device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this application. The aforementioned storage medium includes various media capable of storing programs, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0080] The embodiments of the present invention have been described above with reference to the accompanying drawings. However, the present invention is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of the present invention without departing from the spirit and scope of the claims. All of these forms are within the protection scope of the present invention.
Claims
1. A master node election method based on OpenHarmony distributed networking, characterized in that, The method includes: In response to the master node election signal, determine all nodes that can participate in the OpenHarmony distributed network and their corresponding node performance values; wherein, the node performance value is calculated based on the value and weight of the node's corresponding node performance index; Based on the node performance value, select multiple nodes whose node performance value is greater than a first threshold from all nodes as candidate nodes; The candidate nodes are sorted according to their performance values to obtain a sorting result; wherein, when at least two candidate nodes have the same performance value, the priority of the two candidate nodes is determined according to their node status, and the at least two candidate nodes are sorted according to their priority. The ranking result is broadcast to the OpenHarmony distributed network so that non-candidate nodes can vote for the candidate node ranked first according to the ranking result, and after the voting result of the candidate node ranked first meets the requirements, the new master node is elected; wherein, the non-candidate nodes are all nodes in the OpenHarmony distributed network other than the candidate nodes.
2. The master node election method based on OpenHarmony distributed networking according to claim 1, characterized in that, The node performance metrics include at least one of computing performance, storage performance, network performance, energy status, and task load. Determine the node performance values of all nodes that can participate in the OpenHarmony distributed network, including: Determine the value of at least one of the node performance metrics; Determine the weight of at least one of the node performance metrics; Based on the values and weights of at least one of the node performance indicators, a weighted sum is calculated to obtain the node performance value corresponding to the node.
3. The master node election method based on OpenHarmony distributed networking according to claim 2, characterized in that, Determining the weights of at least one of the node performance metrics includes: Determine the importance value of at least one of the node performance metrics; Calculate the feature vector of at least one of the node performance metrics based on the importance value; The feature vectors are calculated to sum the feature vectors of at least one of the node performance metrics; Calculate the quotient between the feature vector of the at least one node performance metric and the sum of the feature vectors; The quotient of at least one of the node performance metrics is used as the weight.
4. The master node election method based on OpenHarmony distributed networking according to claim 2, characterized in that, Before responding to the master node election signal, the following is also included: The master node election signal is generated under at least one of the following conditions (one through five): Scenario 1 is: at least one of the nodes has not received a heartbeat packet from the current master node within multiple consecutive heartbeat cycles; Scenario 2 is: a newly added node appears in the OpenHarmony distributed network; Scenario 3 is: the load of the current master node exceeds the third threshold; Case four is: the performance value of a node exceeds the performance value of the current master node; Case 5 is: The current master node does not meet the requirements for cross-network communication.
5. The master node election method based on OpenHarmony distributed networking according to claim 2, characterized in that, When at least two candidate nodes have the same node performance value, the priority of the two candidate nodes is determined based on their node status, and the at least two candidate nodes are sorted according to their priority, including: Determine at least two candidate nodes in four states, wherein the first to fourth states are: node type, power status, node ID, and cross-network communication capability; In accordance with the order from the first state to the fourth state, when a state first appears that can distinguish the priorities of at least two candidate nodes, the priorities of at least two candidate nodes are determined according to that state, and the at least two candidate nodes are sorted according to the priorities.
6. The master node election method based on OpenHarmony distributed networking according to claim 1, characterized in that, After the voting results of the candidate node at the top of the ranking meet the requirements, a new master node is elected, including: If the number of votes for the top-ranked candidate node exceeds half the number of votes for the non-candidate nodes, the top-ranked candidate node is selected as the new master node.
7. The master node election method based on OpenHarmony distributed networking according to claim 1, characterized in that, The first threshold is the average of the node performance values of all the nodes.
8. A master node election system based on OpenHarmony distributed networking, characterized in that, The system includes: The participating node determination module is used to respond to the master node election signal and determine all participating nodes and their corresponding node performance values in the OpenHarmony distributed network; wherein, the node performance value is calculated based on the value and weight of the node's corresponding node performance index; The candidate node filtering module is used to select multiple nodes whose node performance values are greater than a first threshold from all nodes as candidate nodes based on the node performance values. A candidate node sorting module is used to sort multiple candidate nodes according to the size of the node performance value to obtain a sorting result; wherein, when there are at least two candidate nodes with the same node performance value, the priority of the two candidate nodes is determined according to the node state of the candidate nodes, and the at least two candidate nodes are sorted according to the priority. The master node selection module is used to broadcast the ranking results to the OpenHarmony distributed network, so that non-candidate nodes can vote for the candidate node ranked first according to the ranking results, and after the voting results of the candidate node ranked first meet the requirements, the new master node is elected; wherein, the non-candidate nodes are all nodes in the OpenHarmony distributed network other than the candidate nodes.
9. An electronic device, characterized in that, It includes at least one control processor and a memory for communicatively connecting to the at least one control processor; the memory stores instructions executable by the at least one control processor, which, when executed by the at least one control processor, enables the at least one control processor to perform the master node election method based on OpenHarmony distributed networking as described in any one of claims 1 to 7.
10. A readable storage medium, characterized in that: The readable storage medium stores computer-executable instructions for causing a computer to execute the master node election method based on OpenHarmony distributed networking as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Node election method and device, storage medium and electronic equipment
CN115002143A
Equipment networking method and system, intelligent terminal and computer readable storage medium
CN118714010A
Equipment control method and device, electronic equipment, storage medium and product
CN120567658A
Multi-master election method and device based on OpenHarmony soft bus
CN120750732A
Node election voting methods and apparatuses based on consensus system
US20250227037A1