Node election method and related apparatus

By acquiring the network and application status of distributed system nodes, the node with the highest utility value is dynamically elected as the master node. Combined with the target switching window mechanism, the problem of low efficiency in master node selection in cross-geographical distributed databases is solved, thereby improving system performance and enhancing stability.

WO2026148846A1PCT designated stage Publication Date: 2026-07-16HUAWEI TECH CO LTD +1

Patent Information

Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
HUAWEI TECH CO LTD
Filing Date
2025-08-08
Publication Date
2026-07-16

AI Technical Summary

Technical Problem

Distributed databases deployed across geographical regions are inefficient in selecting master nodes, leading to increased system transaction processing time, decreased user experience, and wasted system resources.

Method used

By acquiring the network and application status of multiple nodes, the utility value of each node is dynamically determined, and the node with the highest utility value is elected as the master node. Combined with the target switching window mechanism, frequent switching is avoided, thereby improving the election accuracy and system stability.

Benefits of technology

Significantly reduces transaction latency, improves system throughput and stability, and ensures rapid response and smooth operation of the system in dynamic network environments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2025113544_16072026_PF_FP_ABST
    Figure CN2025113544_16072026_PF_FP_ABST
Patent Text Reader

Abstract

The present application belongs to the technical field of computers. Disclosed are a node election method and a related apparatus. In the method, since a network status is used for describing a network situation between a corresponding node and other nodes in a distributed system, and an application status is used for describing the situation of the corresponding node handling a data access request initiated by a client, a utility value corresponding to each node can be dynamically determined in combination with the network status and the application status of each of a plurality of nodes; moreover, the utility values of the nodes are determined from multiple dimensions, such that the accuracy of the determined utility values is relatively high. Since a utility value refers to a performance improvement value brought about to a distributed system after a node is elected as a master node, selecting a node having the highest utility value to serve as a new master node can improve the accuracy and effectiveness of master node election, thereby significantly reducing the transaction latency and improving the system throughput and stability.
Need to check novelty before this filing date? Find Prior Art

Description

Node election method and related devices

[0001] This application claims priority to Chinese Patent Application No. 202510038686.1, filed on January 9, 2025, entitled "Node Election Method and Related Apparatus", the entire contents of which are incorporated herein by reference. Technical Field

[0002] This application relates to the field of computer technology, and in particular to a node election method and related apparatus. Background Technology

[0003] To meet the demands for globalized and efficient data access, distributed systems deployed across geographical regions can be used to manage massive amounts of data. However, the main challenge facing distributed databases deployed across geographical regions lies in the selection of the master node within the consensus protocol. Therefore, how to efficiently elect the master node and improve system performance has become an urgent problem to be solved. Summary of the Invention

[0004] This application provides a node election method and related apparatus, which can actively switch master nodes, reduce transaction latency, and improve system throughput and stability. The technical solution is as follows:

[0005] Firstly, a node election method is provided. The distributed system includes multiple nodes. The method includes: acquiring the network state and application state of the multiple nodes, whereby the network state describes the network situation between the node and other nodes in the distributed system, and the application state describes the node's handling of data access requests initiated by clients; determining the utility value corresponding to each of the multiple nodes based on their network state and application state, where the utility value refers to the performance improvement brought to the distributed system after the node is elected as the master node; determining the target node with the highest utility value from among the multiple nodes based on their respective utility values; and electing the target node as the master node of the distributed system.

[0006] Since network state describes the network situation between the corresponding node and other nodes in the distributed system, and application state describes the processing status of the corresponding node for data access requests initiated by clients, combining the network and application states of multiple nodes allows for the dynamic determination of the utility value of each node. Furthermore, determining the utility value from multiple dimensions ensures high accuracy. Because utility value refers to the performance improvement a node brings to the distributed system after being elected as the master node, selecting the node with the highest utility value as the new master node improves the accuracy and effectiveness of master node election, thereby significantly reducing transaction latency and improving system throughput and stability. In other words, this embodiment actively acquires the network and application states of multiple nodes, determines the utility value of nodes based on these states from multiple dimensions, and actively switches master nodes, thereby significantly improving system performance while maintaining system consistency.

[0007] In one possible implementation, the network state includes the network latency between the node and other nodes in the distributed system, and the application state includes the read / write ratio and the number of requests of the node. The read / write ratio refers to the ratio of read operations to write operations processed by the node in the data access requests initiated by the client, and the number of requests refers to the number of requests processed by the node in the data access requests initiated by the client.

[0008] Network latency can be the round-trip time (RTT) between nodes, or the one-way delay between nodes, which is half of the RTT. Of course, network latency can also be represented by other time parameters.

[0009] Although a distributed system includes a master node, not all data access requests are handled by the master node; some requests may be processed by slave nodes. In other words, every node in a distributed system can potentially handle data access requests initiated by clients. Furthermore, client-initiated data access requests may include read operations, write operations, or both. The read-write ratio refers to the ratio of the number of read operations to the number of write operations processed by that node. In other words, it's the ratio of the number of read operations to the number of write operations in the data access requests processed by that node.

[0010] In one possible implementation, determining the utility value corresponding to each of the plurality of nodes based on the network status and application status of the plurality of nodes includes: determining the popularity of the plurality of nodes based on the number of requests to the plurality of nodes, wherein the popularity is positively correlated with the number of requests; and determining the utility value corresponding to each of the plurality of nodes based on the network latency between the plurality of nodes and other nodes in the distributed system, the read / write ratio of the plurality of nodes, and the popularity.

[0011] For any one of these multiple nodes, there are various ways to determine its popularity based on the number of requests it receives, as long as the node's popularity is positively correlated with its request count. This application does not limit this approach. As an example, the number of requests a node receives can be used to determine its popularity; alternatively, the request counts of the multiple nodes can be normalized, and the normalized value can be used to determine the node's popularity.

[0012] In one possible implementation, the utility value is negatively correlated with the network latency, positively correlated with the read / write ratio, and positively correlated with the popularity.

[0013] Network latency measures the network conditions between nodes and affects the response time of data access requests initiated by clients. Utility value indicates the performance improvement brought by a node. Therefore, the lower the network latency, the shorter the response time of data access requests and the higher the utility value. Conversely, the higher the network latency, the longer the response time of data access requests and the lower the utility value.

[0014] Similarly, the read-write ratio measures the load on a node, and since the processing time for read operations is less than that for write operations, it affects the processing time of data access requests initiated by clients. The utility value indicates the performance improvement brought by the node. Therefore, the lower the read-write ratio, the more write operations there are than read operations, the heavier the node load, the longer the processing time of data access requests, and the lower the utility value. Conversely, the higher the read-write ratio, the fewer write operations there are than read operations, the lighter the node load, the shorter the processing time of data access requests, and the higher the utility value.

[0015] Similarly, the number of requests is used to measure the popularity of a node, which can also be called node popularity, while the utility value is used to indicate the performance improvement brought by the node. The lower the number of requests, the lower the popularity of the node and the lower the utility value. Conversely, the higher the number of requests, the higher the popularity of the node and the higher the utility value.

[0016] Since parameters such as network latency, read / write ratio, and popularity can reflect a node's performance from multiple important dimensions, determining a node's utility value through these parameters can improve the accuracy of the utility value, thereby improving the accuracy of subsequent target node identification.

[0017] In one possible implementation, the utility value corresponding to a node includes a utility value. In this case, the node with a positive utility value among the multiple nodes can be identified as a candidate node, resulting in one or more candidate nodes. From these one or more candidate nodes, the node with the highest utility value is selected as the target node.

[0018] Since nodes with positive utility values ​​provide higher performance gains, they are best suited to be potential master nodes or leaders. Therefore, selecting these nodes as candidate nodes and electing a master node from among them can increase the probability of a successful election.

[0019] The determination of a node's utility value may be frequent. If a target node is directly selected and a new master node is elected every time a utility value is determined, it could lead to frequent master node elections, thus impacting the stability of the distributed system. Therefore, this application also proposes the concept of a target switching window. By determining an appropriately sized target switching window, not only can frequent master node elections be avoided, but also timely re-election of the master node can be ensured in unstable network environments, enabling rapid responses to dynamic network conditions and improving the stability of the distributed system.

[0020] In another possible implementation, the utility value corresponding to the node includes multiple utility values ​​of the node within the target switching window;

[0021] The step of determining the target node with the highest utility value from the plurality of nodes based on the utility values ​​corresponding to the plurality of nodes includes: if it is determined that there is a first type of node among the plurality of nodes based on the multiple utility values ​​of the plurality of nodes in the target switching window, then the first type of node among the plurality of nodes is determined as a candidate node, resulting in one or more candidate nodes, wherein the first type of node refers to a node whose multiple utility values ​​are always positive in the target switching window; and the candidate node with the highest utility value among the one or more candidate nodes is determined as the target node.

[0022] Since each candidate node has multiple utility values ​​within the target switching window, the average of these utility values ​​for each candidate node within the target switching window can be determined, and the candidate node with the largest average value can be selected as the target node. Alternatively, other methods can be used to select the candidate node with the highest utility value as the target node. For example, the median of the multiple utility values ​​for each candidate node within the target switching window can be determined, and the candidate node with the largest median value can be selected as the target node.

[0023] The target switching window is used to observe changes in a node's utility value. For the first re-election of a master node, the target switching window size can be the initial window size. For subsequent re-elections of a master node, the target switching window size is the window size ultimately determined during the previous master node election.

[0024] In one possible implementation, after determining that a first-type node exists among the plurality of nodes based on multiple utility values ​​of the plurality of nodes within the target switching window, the method further includes: increasing the target switching window. Thus, the increased target switching window is used as the window for the next master node election. That is, during the next master node election, multiple utility values ​​of each node within the increased target switching window can be determined, thereby identifying the target node.

[0025] In one possible implementation, increasing the target switching window includes: increasing the target switching window based on a window constraint range, so that the size of the increased target switching window is within the window constraint range. This avoids problems caused by the window being too large or too small during the dynamic increase or decrease of the target switching window.

[0026] Understandably, determining whether to re-elect a master node at the end of the target switching window involves checking if multiple utility values ​​of a node remain positive throughout the target switching window. If any of these nodes consistently have positive utility values ​​within the target switching window, it indicates that a target node capable of delivering performance improvements can be identified based on the current network environment. In this case, a new master node can be elected, and the target switching window will gradually increase, thus reducing the switching frequency. Furthermore, increasing the target switching window based on its limited range ensures that it will not exceed a set threshold when dynamically increasing, avoiding latency issues caused by an excessively large target switching window.

[0027] Since nodes with positive utility values ​​provide higher performance gains, these nodes are best suited as potential master nodes or leaders. Therefore, selecting nodes with consistently positive utility values ​​within the target switching window as candidate nodes and electing a master node from these nodes not only increases the probability of a successful election but also avoids frequent master node elections, thereby improving the stability of the distributed system.

[0028] In one possible implementation, the method further includes: if it is determined that there is no first type node among the plurality of nodes based on multiple utility values ​​of the plurality of nodes within the target switching window, then the target switching window is narrowed, and multiple utility values ​​of the plurality of nodes within the narrowed target switching window are re-determined; if it is determined that there is a first type node among the plurality of nodes based on multiple utility values ​​of the plurality of nodes within the narrowed target switching window, then the first type node among the plurality of nodes is determined as a candidate node, resulting in one or more candidate nodes; and the candidate node with the highest corresponding utility value among the one or more candidate nodes is determined as the target node.

[0029] If, based on the utility values ​​of multiple nodes within the target switching window, it is determined that no node of the first type exists among these nodes, it indicates that the target switching window is too large, and the utility values ​​of the nodes within the target switching window are all negative or invalid. Therefore, the target switching window needs to be reduced. If, based on the utility values ​​of multiple nodes within the reduced target switching window, it is still determined that no node of the first type exists among these nodes, the target switching window is further reduced until a node's utility value within the reduced target switching window is consistently positive. In this way, the finally determined target switching window can be used as the window for the next master node election.

[0030] In one possible implementation, shrinking the target switching window includes: shrinking the target switching window based on window limitation range, so that the size of the shrunken target switching window is within the window limitation range.

[0031] Understandably, determining whether to re-elect the master node at the end of the target switching window involves checking if multiple utility values ​​of a node remain consistently positive within that window. If all utility values ​​of the node within the target switching window are negative or invalid, it indicates that the target switching window is too large to promptly detect dynamic changes in the network environment. In this case, the target switching window needs to be reduced until a node consistently maintains a positive utility value within the reduced window. This allows for timely re-election of the master node even in unstable network conditions, enabling rapid responses to dynamic network environments and improving the stability of the distributed system. Furthermore, reducing the target switching window based on window limits ensures that the dynamically reduced window does not exceed a set threshold, preventing frequent switching issues caused by an excessively small target switching window.

[0032] In both scenarios described above, the size of the switching window is adjusted in real time based on network conditions to avoid system jitter caused by frequent adjustments. Furthermore, by introducing a window limitation range, the distributed system maintains a dynamic balance between "response speed" and "frequent switching".

[0033] In one possible implementation, the method is applied to a first node, which is the master node of the distributed system, and the target node is not the same node as the first node.

[0034] The step of electing the target node as the master node of the distributed system includes: synchronizing log information to the target node and stopping sending heartbeat messages to enable the target node to start the election process; if a data access request initiated by the client is received during the election process, the data access request is cached; if the target node is successfully elected as the master node of the distributed system, the first node is demoted to a slave node of the distributed system, and the data access request cached during the election process is sent to the target node so that the target node can take over from the first node to handle the data access request.

[0035] Before switching master nodes, the first node actively synchronizes the latest log information to the target node. This ensures that the new master node does not need to wait for the log synchronization to complete after taking over the distributed system, thus significantly reducing system downtime.

[0036] The master node sends heartbeat messages to let other nodes know that the master node is in a normal state and has not failed. Therefore, before the target node starts the election process, the first node stops sending heartbeat messages. In this way, after the target node is successfully elected as the master node, the target node will send heartbeat messages. This not only confirms that the target node has been successfully elected as the master node, but also confirms the status of the target node.

[0037] Furthermore, during the election of the target node, the first node can continue to receive data access requests from clients and cache these requests. Once the first node receives a heartbeat message from the target node and confirms that the target node has been successfully elected as the master node, it can send the cached data access requests to the target node, allowing the target node to take over from the first node to handle the data access requests. This ensures a seamless transition throughout the entire switchover process. In other words, during the target node election, data access requests are not blocked and can be sent normally. There are no downtime periods in the entire distributed system, avoiding interruptions in data access requests and data inconsistencies during master node switchover.

[0038] Although the target node is the node with the highest utility value, there is a possibility that the election of the target node may fail. In this case, the first node can continue to be the master node of the distributed system to handle data access requests initiated by clients. That is, in one possible implementation, the method further includes: if the target node is not successfully elected as the master node of the distributed system, then the first node is determined to continue to be the master node of the distributed system, continues to send heartbeat messages, and processes cached data access requests.

[0039] In one possible implementation, the distributed system is a distributed system deployed across geographical regions.

[0040] Secondly, a node election apparatus is provided, the apparatus having the function of implementing the method behavior described in the first aspect. The apparatus includes at least one module for implementing the method provided in the first aspect.

[0041] Thirdly, a computer device is provided, comprising a processor and a memory, the memory being used to store a computer program for performing the methods provided in the first aspect. The processor is configured to execute the computer program stored in the memory to implement the methods described in the first aspect.

[0042] Fourthly, a computer-readable storage medium is provided, wherein the storage medium stores instructions that, when executed on a computer, cause the computer to perform the method described in the first aspect.

[0043] Fifthly, a computer program product containing instructions is provided, which, when executed on a computer, cause the computer to perform the method described in the first aspect.

[0044] The technical effects achieved by the second to fifth aspects mentioned above are similar to those achieved by the corresponding technical means in the first aspect, and will not be repeated here. Attached Figure Description

[0045] Figure 1 is a schematic diagram of a distributed system provided in an embodiment of this application;

[0046] Figure 2 is a schematic diagram of the structure of nodes in a distributed system provided in an embodiment of this application;

[0047] Figure 3 is a flowchart of a node election method provided in an embodiment of this application;

[0048] Figure 4 is a schematic diagram of a target node selection process provided in an embodiment of this application;

[0049] Figure 5 is a schematic diagram of determining a target node through a target switching window according to an embodiment of this application;

[0050] Figure 6 is a schematic diagram of a master node switching process provided in an embodiment of this application;

[0051] Figure 7 is a schematic diagram illustrating the effect achieved by a master node switching process according to an embodiment of this application;

[0052] Figure 8 is a schematic diagram of a node election device provided in an embodiment of this application. Detailed Implementation

[0053] To make the objectives, technical solutions, and advantages of the embodiments of this application clearer, the implementation methods of this application will be further described in detail below with reference to the accompanying drawings.

[0054] Before providing a detailed explanation of the methods provided in the embodiments of this application, the application scenarios and implementation environments involved in the embodiments of this application will be introduced first.

[0055] First, the application scenarios involved in the embodiments of this application will be introduced.

[0056] With the rapid development of internet technology, the application scope of distributed systems is becoming increasingly wide. This distributed system can be a distributed database, a distributed server cluster, or other types. The following section will use a distributed database as an example.

[0057] In the context of globalization, multinational corporations and internet service providers rely on distributed databases spanning geographical regions to manage massive amounts of data. For example, global banking systems, large e-commerce platforms, and other cross-regional, high-reliability data management scenarios can all rely on distributed databases spanning geographical regions to manage data.

[0058] Traditional centralized databases, limited by a single data center, cannot meet the demands of globalized and efficient data access. Therefore, distributed databases deployed across geographical regions have become the preferred choice. However, the main challenge for distributed databases deployed across geographical regions lies in the selection of the master node within the consistency protocol. In distributed databases deployed across geographical regions, network latency, differences in node load, and variations in node popularity all affect the efficiency of master node selection. An inappropriate selection will significantly increase the system's transaction processing time, degrade user experience, and waste system resources.

[0059] Based on this, this application provides a master node election method. In this method, the network status and application status of multiple nodes are obtained. The network status describes the network situation between the corresponding node and other nodes in the distributed system, and the application status describes the processing status of the corresponding node for data access requests initiated by clients. Therefore, by combining the network status and application status of these multiple nodes, the utility value of each node can be dynamically determined. Moreover, determining the utility value of a node from multiple dimensions ensures high accuracy. Since the utility value refers to the performance improvement brought to the distributed system after a node is elected as the master node, selecting the node with the highest utility value as the new master node improves the accuracy and effectiveness of master node election, thereby significantly reducing transaction latency and improving system throughput and stability.

[0060] Secondly, the implementation environment involved in the embodiments of this application will be introduced.

[0061] Referring to Figure 1, the distributed system includes multiple nodes 101, which are connected via a network. These nodes 101 are located in different geographical areas, although some nodes may be located in the same geographical area. This distributed system acts as a server to provide services to clients.

[0062] The multiple nodes 101 include one master node and multiple slave nodes. The master node can also be called the leader node, and the slave nodes can also be called followers. The master node is used to receive and process data access requests from clients. That is, when a client accesses data in this distributed system, the client can send a data access request to the master node, which receives and processes the data access request.

[0063] Of course, the client can also randomly select one of the multiple nodes 101 and send a data access request to the selected node 101. When the node 101 receives the data access request and the node 101 is not the master node, the node 101 sends the data access request to the master node so that the master node can process the data access request.

[0064] It should be noted that Node 101 can be a computer device, a standalone server, or a server cluster consisting of multiple physical servers. It can also be a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communication, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms, or a cloud computing service center.

[0065] The method provided in this application is a process for re-electing a master node in a distributed system when a master node (such as the first node) already exists. This method is applied to the first node; that is, the first node is the execution subject of this method. The architecture of the nodes in the distributed system will be described next from a hardware perspective.

[0066] Please refer to Figure 2, which is a schematic diagram of the structure of a node in a distributed system according to an embodiment of this application. The node includes at least one processor 201, a communication bus 202, a memory 203, and at least one communication interface 204.

[0067] The processor 201 can be a general-purpose central processing unit (CPU), a network processor (NP), a microprocessor, or one or more integrated circuits for implementing the solutions of this application, such as an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The aforementioned PLD can be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.

[0068] The communication bus 202 is used to transmit information between the aforementioned components. The communication bus 202 can be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, it is represented by only one thick line in the figure, but this does not indicate that there is only one bus or one type of bus.

[0069] The memory 203 may be a read-only memory (ROM), a random access memory (RAM), an electrically erasable programmable read-only memory (EEPROM), an optical disc (including a compact disc read-only memory (CD-ROM), a compressed optical disc, a laser disc, a digital versatile optical disc, a Blu-ray disc, etc.), a magnetic disk storage medium, or other magnetic storage device, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures that can be accessed by a computer, but not limited thereto. The memory 203 may exist independently and be connected to the processor 201 via the communication bus 202. The memory 203 may also be integrated with the processor 201.

[0070] Communication interface 204 uses any transceiver-like device for communicating with other devices or communication networks. Communication interface 204 includes a wired communication interface and may also include a wireless communication interface. The wired communication interface may be, for example, an Ethernet interface. The Ethernet interface may be an optical interface, an electrical interface, or a combination thereof. The wireless communication interface may be a wireless local area network (WLAN) interface, a cellular network communication interface, or a combination thereof.

[0071] As an example, processor 201 may include one or more CPUs, such as CPU0 and CPU1 as shown in FIG2.

[0072] As an example, a computer device may include multiple processors, such as processor 201 and processor 205 as shown in Figure 2. Each of these processors may be a single-core processor or a multi-core processor. Here, "processor" may refer to one or more devices, circuits, and / or processing cores used to process data (such as computer program instructions).

[0073] In some embodiments, memory 203 is used to store program code 210 for executing the scheme of this application, and processor 201 can execute the program code 210 stored in memory 203. The program code 210 may include one or more software modules, and the computer device can implement the methods provided in the embodiments below through processor 201 and program code 210 in memory 203.

[0074] The methods provided in the embodiments of this application will now be explained in detail.

[0075] Figure 3 is a flowchart of a node election method provided in an embodiment of this application. The distributed system includes multiple nodes. This method is a process of re-electing a master node for the distributed system when a master node (such as the first node) already exists. This method is applied to the first node. Referring to Figure 3, the method includes the following steps.

[0076] Step 301: Obtain the network status and application status of multiple nodes. The network status describes the network situation between the corresponding node and other nodes in the distributed system, and the application status describes the processing status of the corresponding node for data access requests initiated by the client.

[0077] In some embodiments, network status includes the network latency between the corresponding node and other nodes in the distributed system. For example, the distributed system includes 5 nodes, namely node 1 to node 5, and the network status of node 1 includes the network latency between node 1 and node 2, the network latency between node 1 and node 3, the network latency between node 1 and node 4, and the network latency between node 1 and node 5.

[0078] Network latency can be the round-trip time (RTT) between nodes, or the one-way delay between nodes, which is half of the RTT. Of course, network latency can also be represented by other time parameters.

[0079] For any one of these nodes, if the network latency is either round-trip time or one-way time, that node can send a heartbeat message to other nodes and record the sending time of the heartbeat message. After receiving the heartbeat message, other nodes return a response message to that node. That node receives the response message and records the receiving time of the response message. The difference between the recorded sending time and receiving time is determined as the round-trip time, and half of the round-trip time is determined as the one-way time.

[0080] Since the network latency of each node is collected by that node itself, and the execution subject in this embodiment is the first node, each node can send its collected network latency to the first node after collecting it. Of course, the first node can also periodically obtain the network latency collected by each node from the other nodes.

[0081] In some embodiments, after the first node obtains the network latency between every two nodes in the plurality of nodes, it can also construct a delay matrix based on the network latency between every two nodes. The elements of this delay matrix are the network latency between every two nodes in the plurality of nodes. For example, the delay matrix is ​​an N*N matrix, where N is the number of nodes in the distributed system. The elements T in this delay matrix... i j This represents the network delay from node i to node j. The diagonal elements of this delay matrix are 0, meaning the delay from a node to itself is 0.

[0082] In some embodiments, the application state includes the node's read-write ratio and request number. The read-write ratio refers to the ratio of read operations to write operations processed by the node in a data access request initiated by the client, and the request number refers to the number of requests processed by the node in a data access request initiated by the client.

[0083] Although a distributed system includes a master node, not all data access requests are handled by the master node; some requests may be processed by slave nodes. In other words, every node in a distributed system can potentially handle data access requests initiated by clients. Furthermore, client-initiated data access requests may include read operations, write operations, or both. The read-write ratio refers to the ratio of the number of read operations to the number of write operations processed by that node. In other words, it's the ratio of the number of read operations to the number of write operations in the data access requests processed by that node.

[0084] For any one of these nodes, its read / write ratio and request count can be collected by that node itself. Since the execution entity in this embodiment is the first node, each node, after collecting its own read / write ratio and request count, can send these data to the first node. Alternatively, the first node can periodically retrieve the read / write ratio and request count collected by each node from the other nodes.

[0085] In some embodiments, after the first node obtains the read-write ratio and the number of requests for each node, it can construct a read-write ratio vector based on the read-write ratios of these multiple nodes. This read-write ratio vector is {W1, W2, ..., W...} N This includes N elements, each representing the read / write ratio of the corresponding node. Similarly, a request number vector can be constructed based on the number of requests from these multiple nodes, which is {Q1, Q2, ..., Q}. N}, which includes N elements, where each element represents the number of requests for the corresponding node.

[0086] The distributed system mentioned in the embodiments of this application is a distributed system deployed across geographical regions. Of course, it can also be a distributed system that is not deployed across geographical regions. The embodiments of this application do not limit this.

[0087] Step 302: Based on the network status and application status of the multiple nodes, determine the utility value corresponding to each of the multiple nodes. The utility value refers to the performance improvement value brought to the distributed system after the corresponding node is elected as the master node.

[0088] Given network conditions including network latency and application conditions including read / write ratio and request count, the process of determining utility values ​​includes: determining the popularity of these nodes based on the request count, where popularity is positively correlated with request count; and determining the utility value of each node based on its network latency with other nodes in the distributed system, its read / write ratio, and its popularity.

[0089] For any one of these multiple nodes, there are various ways to determine its popularity based on the number of requests it receives, as long as the node's popularity is positively correlated with its request count. This application does not limit this approach. As an example, the number of requests a node receives can be used to determine its popularity; alternatively, the request counts of the multiple nodes can be normalized, and the normalized value can be used to determine the node's popularity.

[0090] In some embodiments, after determining the popularity of the multiple nodes, a popularity vector can be constructed based on the popularity of the multiple nodes. This popularity vector is {P1, P2, ..., P...} N}, which includes N elements, each of which represents the popularity of the corresponding node.

[0091] Based on the network latency between these nodes and other nodes in the distributed system, the read / write ratio of these nodes, and their popularity, there are several ways to determine the utility value of each node. As long as the utility value is negatively correlated with network latency, positively correlated with read / write ratio, and positively correlated with popularity, it is acceptable.

[0092] In some embodiments, the utility value corresponding to a node is determined according to the following formula (1).

[0093] In the above formula (1), U i P refers to the utility value of the i-th node, N refers to the number of nodes, and P is the total utility value of the nodes. i This refers to the popularity of the i-th node. T refers to the network latency from the i-th node to the master node (i.e., the first node) of the distributed system. i N W refers to the network latency from the i-th node to the N-th node. i This refers to the read / write ratio of the i-th node. This refers to the network latency from the middle node among multiple nodes to the master node (i.e., the first node) of the distributed system. This refers to the network latency from the middle node among the multiple nodes to the Nth node.

[0094] In this context, the node in the middle position among the multiple nodes refers to the k-th node, where k is the median of the total number of nodes. If the number of nodes is odd (N is odd), then k is the integer part of N / 2, rounded up. For example, if N is 5, k is 5 / 2, rounded up, which is 3. Therefore, the node in the middle position is the 3rd node. If the number of nodes is even (N is even), then k is either N / 2, or a value greater than or adjacent to N / 2. For example, if N is 6, k is 6 / 2, which is 3, or 4. Therefore, the node in the middle position is either the 3rd or 4th node.

[0095] It is easy to see from the above formula (1) that utility value is negatively correlated with network latency, positively correlated with read / write ratio, and positively correlated with popularity. Alternatively, it can be understood that utility value is positively correlated with the number of requests.

[0096] Network latency measures the network conditions between nodes and affects the response time of data access requests initiated by clients. Utility value indicates the performance improvement brought by a node. Therefore, the lower the network latency, the shorter the response time of data access requests and the higher the utility value. Conversely, the higher the network latency, the longer the response time of data access requests and the lower the utility value.

[0097] Similarly, the read-write ratio measures the load on a node, and since the processing time for read operations is less than that for write operations, it affects the processing time of data access requests initiated by clients. The utility value indicates the performance improvement brought by the node. Therefore, the lower the read-write ratio, the more write operations there are than read operations, the heavier the node load, the longer the processing time of data access requests, and the lower the utility value. Conversely, the higher the read-write ratio, the fewer write operations there are than read operations, the lighter the node load, the shorter the processing time of data access requests, and the higher the utility value.

[0098] Similarly, the number of requests is used to measure the popularity of a node, which can also be called node popularity, while the utility value is used to indicate the performance improvement brought by the node. The lower the number of requests, the lower the popularity of the node and the lower the utility value. Conversely, the higher the number of requests, the higher the popularity of the node and the higher the utility value.

[0099] In some embodiments, after determining the utility values ​​corresponding to the plurality of nodes, a utility vector can be constructed based on the utility values ​​of the plurality of nodes. The utility vector includes N elements, each of which is the utility value of the corresponding node.

[0100] In other embodiments, after determining the utility values ​​corresponding to the plurality of nodes, during the process of constructing a utility value vector based on the utility values ​​of the plurality of nodes, if the utility value corresponding to a certain node is positive, then the element corresponding to that node in the utility value vector is determined to be 1; if the utility value corresponding to a certain node is not positive, then the element corresponding to that node in the utility value vector is determined to be 0. For example, the distributed system includes 5 nodes, and the utility value vector is 10001, indicating that the utility values ​​of the 1st and 5th nodes among the plurality of nodes are positive, and the utility values ​​of the other nodes are not positive, that is, negative or 0.

[0101] Since parameters such as network latency, read / write ratio, and popularity can reflect a node's performance from multiple important dimensions, determining a node's utility value through these parameters can improve the accuracy of the utility value, thereby improving the accuracy of subsequent target node identification.

[0102] Step 303: Based on the utility values ​​corresponding to the multiple nodes, determine the target node with the highest utility value from among the multiple nodes.

[0103] In some embodiments, the utility value corresponding to a node includes a utility value. In this case, the node with a positive utility value among the multiple nodes can be identified as a candidate node, resulting in one or more candidate nodes. From the one or more candidate nodes, the node with the highest utility value is identified as the target node.

[0104] Since nodes with positive utility values ​​provide higher performance gains, they are best suited to be potential master nodes or leaders. Therefore, selecting these nodes as candidate nodes and electing a master node from among them can increase the probability of a successful election.

[0105] The selection process for the target node will be described below with reference to the attached diagram. Please refer to Figure 4; the distributed system consists of 5 nodes, numbered 1 through 5. The network latency T1 for collecting data from node 1 is... 2 T1 3 T1 4 T1 5 The system collects the read / write ratio W1 and request count Q1 for node 1, and similarly collects the network latency, read / write ratio, and request count for other nodes. A latency matrix is ​​constructed based on the network latency of each node, a read / write ratio vector is constructed based on the read / write ratio of each node, and the popularity of each node is determined based on the request count, with a popularity vector constructed as well. Then, based on the latency matrix, read / write ratio vector, and popularity vector, the utility value of each node is determined. If the utility values ​​of nodes 1 and 5 are positive, and the utility values ​​of other nodes are not positive, then nodes 1 and 5 are identified as candidate nodes. Finally, the node with the highest utility value among nodes 1 and 5 is selected as the target node.

[0106] The determination of a node's utility value may be frequent. If a target node is directly selected and a new master node is elected every time a utility value is determined, it could lead to frequent master node elections, thus impacting the stability of the distributed system. Therefore, this application also proposes the concept of a target switching window. By determining an appropriately sized target switching window, not only can frequent master node elections be avoided, but also timely re-election of the master node can be ensured in unstable network environments, enabling rapid responses to dynamic network conditions and improving the stability of the distributed system.

[0107] In other embodiments, the utility value corresponding to a node includes multiple utility values ​​of the node within the target switching window. In this case, the target node is determined as follows. The following will describe two separate cases.

[0108] In the first case, if it is determined that there is a first type of node among the multiple nodes based on the multiple utility values ​​of the multiple nodes in the target switching window, then the first type of node among the multiple nodes is determined as a candidate node, and one or more candidate nodes are obtained. The first type of node refers to the node whose multiple utility values ​​are always positive in the target switching window; the candidate node with the highest corresponding utility value among the one or more candidate nodes is determined as the target node.

[0109] For any given node among these nodes, if all of its utility values ​​within the target switching window are positive, then that node is classified as a first-class node. If not all of its utility values ​​within the target switching window are positive, then that node is not classified as a first-class node. By similarly determining the utility values ​​of these nodes within the target switching window, the first-class nodes can be identified, thus yielding one or more candidate nodes. These candidate nodes can also be referred to as candidates.

[0110] Since each candidate node has multiple utility values ​​within the target switching window, the average of these utility values ​​for each candidate node within the target switching window can be determined, and the candidate node with the largest average value can be selected as the target node. Alternatively, other methods can be used to select the candidate node with the highest utility value as the target node. For example, the median of the multiple utility values ​​for each candidate node within the target switching window can be determined, and the candidate node with the largest median value can be selected as the target node.

[0111] The target switching window is used to observe changes in a node's utility value. For the first re-election of a master node, the target switching window size can be the initial window size. For subsequent re-elections of a master node, the target switching window size is the window size ultimately determined during the previous master node election.

[0112] It should be noted that the initial window size is usually larger than the period during which the master node sends heartbeat messages, and is directly proportional to the period during which the master node sends heartbeat messages. This application does not limit this aspect in the embodiments.

[0113] If, based on the multiple utility values ​​of these nodes within the target switching window, it is determined that a node of the first type exists among these nodes, the target switching window can be increased. This increased target switching window can then be used as the window for the next master node election. In other words, during the next master node election, the multiple utility values ​​of each node within the increased target switching window can be determined, thereby identifying the target node.

[0114] In some embodiments, increasing the target switching window can be achieved in various ways, such as increasing it by 1.5 times, 2 times, 3 times, etc., or increasing it by a fixed step size. Of course, in other embodiments, to avoid problems caused by the window becoming too large or too small during the dynamic increase or decrease of the target switching window, a window limit range can be set. Thus, when increasing the target switching window, it can be increased based on the window limit range, ensuring that the size of the increased target switching window remains within the window limit range.

[0115] For example, the window limit range is [2, 128]. When increasing the target switching window, the target switching window can be increased by 2 times to obtain the first window size. If the first window size is greater than 128, the size of the increased target switching window is determined to be 128. If the first window size is not greater than 128, the size of the increased target switching window is determined to be the first window size.

[0116] Understandably, determining whether to re-elect a master node at the end of the target switching window involves checking if multiple utility values ​​of a node remain positive throughout the target switching window. If any of these nodes consistently have positive utility values ​​within the target switching window, it indicates that a target node capable of delivering performance improvements can be identified based on the current network environment. In this case, a new master node can be elected, and the target switching window will gradually increase, thus reducing the switching frequency. Furthermore, increasing the target switching window based on its limited range ensures that it will not exceed a set threshold when dynamically increasing, avoiding latency issues caused by an excessively large target switching window.

[0117] Since nodes with positive utility values ​​provide higher performance gains, these nodes are best suited as potential master nodes or leaders. Therefore, selecting nodes with consistently positive utility values ​​within the target switching window as candidate nodes and electing a master node from these nodes not only increases the probability of a successful election but also avoids frequent master node elections, thereby improving the stability of the distributed system.

[0118] In the second scenario, if it is determined that there are no first-type nodes among the multiple nodes based on the multiple utility values ​​of the multiple nodes within the target switching window, then the target switching window is narrowed, and the multiple utility values ​​of the multiple nodes within the narrowed target switching window are re-determined; if it is determined that there are first-type nodes among the multiple nodes based on the multiple utility values ​​of the multiple nodes within the narrowed target switching window, then the first-type nodes among the multiple nodes are identified as candidate nodes, resulting in one or more candidate nodes; the candidate node with the highest corresponding utility value among the one or more candidate nodes is identified as the target node.

[0119] If, based on the utility values ​​of multiple nodes within the target switching window, it is determined that no node of the first type exists among these nodes, it indicates that the target switching window is too large, and the utility values ​​of the nodes within the target switching window are all negative or invalid. Therefore, the target switching window needs to be reduced. If, based on the utility values ​​of multiple nodes within the reduced target switching window, it is still determined that no node of the first type exists among these nodes, the target switching window is further reduced until a node's utility value within the reduced target switching window is consistently positive. In this way, the finally determined target switching window can be used as the window for the next master node election.

[0120] In some embodiments, the target switching window can be reduced in various ways, such as reducing it by a factor of 1.5, 2, or 3, or reducing it by a fixed increment. Of course, in other embodiments, to avoid problems caused by the window becoming too large or too small during the dynamic enlargement or reduction of the target switching window, a window limit range can be set. Thus, when reducing the target switching window, it can be reduced based on the window limit range so that the size of the reduced target switching window is within the window limit range.

[0121] For example, the window limit range is [2, 128]. When shrinking the target switching window, the target switching window can be shrunk by 2 times to obtain the second window size. If the second window size is less than 2, the size of the shrunk target switching window is determined to be 2. If the second window size is not less than 2, the size of the shrunk target switching window is determined to be the second window size.

[0122] Understandably, determining whether to re-elect the master node at the end of the target switching window involves checking if multiple utility values ​​of a node remain consistently positive within that window. If all utility values ​​of the node within the target switching window are negative or invalid, it indicates that the target switching window is too large to promptly detect dynamic changes in the network environment. In this case, the target switching window needs to be reduced until a node consistently maintains a positive utility value within the reduced window. This allows for timely re-election of the master node even in unstable network conditions, enabling rapid responses to dynamic network environments and improving the stability of the distributed system. Furthermore, reducing the target switching window based on window limits ensures that the dynamically reduced window does not exceed a set threshold, preventing frequent switching issues caused by an excessively small target switching window.

[0123] In both scenarios described above, the size of the switching window is adjusted in real time based on network conditions to avoid system jitter caused by frequent adjustments. Furthermore, by introducing a window limitation range, the distributed system maintains a dynamic balance between "response speed" and "frequent switching".

[0124] The process of determining the target node through the target switching window will be explained below with reference to the accompanying diagram. Referring to Figure 5, the distributed system includes three nodes. The utility value of each node can be determined by its network latency, read / write ratio, and popularity, forming a utility value vector. A 1 in this vector represents a utility value greater than 0 (positive), and a 0 represents a utility value less than or equal to 0 (negative). In the previous re-election of the master node, the target switching window used was window 1. As shown in Figure 5, the utility value of node 3 within window 1 is consistently positive, so the master node switch occurs at the end of window 1. Simultaneously, window 1 is enlarged to obtain window 2. In this re-election of the master node, the utility values ​​of each node within window 2 are determined. As shown in Figure 5, not all utility values ​​of each node within window 2 are positive, so the master node switch is not performed; instead, window 2 is shrunk to obtain window 3. The utility values ​​of each node within window 3 are redefined. As shown in Figure 5, the utility value of node 2 is always positive among the utility values ​​determined within window 3. Therefore, the main node is switched at the end of window 3.

[0125] Step 304: Elect the target node as the master node of the distributed system.

[0126] If the target node and the first node are not the same node, the first node will synchronize log information to the target node and stop sending heartbeat messages so that the target node can start the election process. If a data access request initiated by a client is received during the election process, the data access request initiated by the client will be cached. If the target node is successfully elected as the master node of the distributed system, the first node will be demoted to a slave node of the distributed system, and the data access requests cached during the election process will be sent to the target node so that the target node can take over the processing of data access requests from the first node.

[0127] Before switching master nodes, the first node actively synchronizes the latest log information to the target node. This ensures that the new master node does not need to wait for the log synchronization to complete after taking over the distributed system, thus significantly reducing system downtime.

[0128] The master node sends heartbeat messages to let other nodes know that the master node is in a normal state and has not failed. Therefore, before the target node starts the election process, the first node stops sending heartbeat messages. In this way, after the target node is successfully elected as the master node, the target node will send heartbeat messages. This not only confirms that the target node has been successfully elected as the master node, but also confirms the status of the target node.

[0129] Furthermore, during the election of the target node, the first node can continue to receive data access requests from clients and cache these requests. Once the first node receives a heartbeat message from the target node and confirms that the target node has been successfully elected as the master node, it can send the cached data access requests to the target node, allowing the target node to take over from the first node to handle the data access requests. This ensures a seamless transition throughout the entire switchover process. In other words, during the target node election, data access requests are not blocked and can be sent normally. There are no downtime periods in the entire distributed system, avoiding interruptions in data access requests and data inconsistencies during master node switchover.

[0130] In some embodiments, during the target node election process, the first node can initially be demoted to a helper node. This allows the first node to stop processing data access requests from clients, and then forward cached data access requests to the target node after it has been successfully elected as the master node. Afterward, the first node can be demoted to a slave node. In other words, the helper node plays a transitional role before the master node switch is successfully completed.

[0131] The following explanation, with reference to the accompanying diagram, illustrates the master node switching process and its effects. Referring to Figure 6, the distributed system comprises five nodes, designated as nodes 1 through 5. Node 1 is the primary node, currently the master node. During the processing of data access requests from clients, if node 3 is identified as the target node, the node synchronizes its log information with node 3 and stops sending heartbeat messages. Node 1 is demoted to a helper node, and node 3 initiates an election process. Specifically, during the election process, node 1 caches client-initiated data access requests, while node 3 sends voting requests to all other nodes. Other nodes report their voting results to node 3, allowing node 3 to determine whether the election is successful. If the election conditions are met, node 3 is successfully elected as the master node, and it sends heartbeat messages to all nodes. Upon receiving the heartbeat message from node 3, node 1 becomes a slave node and sends the cached data access requests from the election process to node 3, enabling node 3 to process these requests.

[0132] Referring to Figure 7, this embodiment proactively determines a target node in advance when the master node (i.e., the first node) is down. Log information is then pre-synchronized to the target node, heartbeat messages are stopped, and the target node is demoted to a helper node. The target node initiates an election process, and after it is successfully elected as the master node, the first node sends the data access requests cached during the election process to the target node, which then handles these requests. This way, the performance of the entire distributed system is not affected even if the first node fails. Compared to waiting for one or more rounds of elections after the master node fails, and the entire system being unavailable during the heartbeat timeout and election processes, the switching method provided in this embodiment ensures that data access requests are not blocked during the target node election process and can be sent normally. There are no downtime periods in the distributed system, avoiding interruptions in data access requests and data inconsistencies during master node switching.

[0133] Although the target node is the node with the highest utility value, there is a possibility that it will fail to be elected as the target node during the election process. In this case, the first node can continue to be the master node of the distributed system to handle data access requests initiated by clients. That is, in some embodiments, if the target node is not successfully elected as the master node of the distributed system, the first node is determined to continue to be the master node of the distributed system, continue to send heartbeat messages, and process cached data access requests.

[0134] If the first node is demoted to an assistant node during the election process of the target node, the first node can still be promoted to the master node and continue to send heartbeat messages.

[0135] In this embodiment, the network and application states of multiple nodes are acquired. The network state describes the network situation between the corresponding node and other nodes in the distributed system, while the application state describes the processing status of the corresponding node for data access requests initiated by clients. Therefore, by combining the network and application states of these multiple nodes, the utility value of each node can be dynamically determined. Moreover, determining the utility value of a node from multiple dimensions ensures high accuracy. Since the utility value refers to the performance improvement brought to the distributed system after a node is elected as the master node, selecting the node with the highest utility value as the new master node improves the accuracy and effectiveness of master node election, thereby significantly reducing transaction latency and improving system throughput and stability. In other words, this embodiment actively acquires the network and application states of multiple nodes, determines the utility value of nodes from multiple dimensions based on these states, and actively switches the master node, thereby significantly improving system performance while maintaining system consistency. In addition, this application also proposes the concept of a target switching window. By determining a target switching window of an appropriate size, it is possible not only to avoid frequent election of the master node, but also to ensure timely re-election of the master node in the event of network instability, thereby enabling a rapid response to dynamic network environments and improving the stability of the distributed system.

[0136] Figure 8 is a schematic diagram of a node election device provided in an embodiment of this application. This device can be implemented as part or all of a computer device by software, hardware, or a combination of both. The computer device can be the device shown in Figure 2. Referring to Figure 8, the device includes: a status acquisition module 801, a utility value determination module 802, a target node determination module 803, and a master node switching module 804.

[0137] The status acquisition module 801 is used to acquire the network status and application status of multiple nodes. The network status describes the network situation between the node and other nodes in the distributed system, and the application status describes the node's handling of data access requests initiated by the client. For detailed implementation process, please refer to the relevant description of step 301 in the embodiment shown in Figure 3, which will not be repeated here.

[0138] The utility value determination module 802 is used to determine the utility value corresponding to each of the multiple nodes based on the network and application states of the nodes. The utility value refers to the performance improvement brought to the distributed system after a node is elected as the master node. For detailed implementation process, please refer to the relevant description of step 302 in the embodiment shown in Figure 3, which will not be repeated here.

[0139] The target node determination module 803 is used to determine the target node with the highest utility value from among multiple nodes based on the utility values ​​corresponding to each node. For detailed implementation process, please refer to the relevant description of step 303 in the embodiment shown in Figure 3, which will not be repeated here.

[0140] The master node switching module 804 is used to elect the target node as the master node of the distributed system. For detailed implementation process, please refer to the description of step 304 in the embodiment shown in Figure 3, which will not be repeated here.

[0141] In one possible implementation, network state includes network latency between the node and other nodes in the distributed system, and application state includes the node's read / write ratio and the number of requests. The read / write ratio refers to the ratio of read operations to write operations processed by the node in a data access request initiated by the client, and the number of requests refers to the number of requests processed by the node in a data access request initiated by the client.

[0142] In one possible implementation, the utility value determination module 802 is specifically used for:

[0143] The popularity of multiple nodes is determined based on the number of requests to them, and the popularity is positively correlated with the number of requests.

[0144] Based on the network latency between multiple nodes and other nodes in the distributed system, the read / write ratio of multiple nodes, and their popularity, the utility value corresponding to each of the multiple nodes is determined.

[0145] In one possible implementation, utility value is negatively correlated with network latency, positively correlated with read / write ratio, and positively correlated with popularity.

[0146] In one possible implementation, the utility value corresponding to a node includes multiple utility values ​​of the node within the target switching window;

[0147] The target node determination module 803 is specifically used for:

[0148] If it is determined that there are first-type nodes among the multiple nodes based on the multiple utility values ​​of multiple nodes within the target switching window, then the first-type nodes among the multiple nodes are identified as candidate nodes, resulting in one or more candidate nodes. First-type nodes refer to nodes whose multiple utility values ​​are always positive within the target switching window.

[0149] The candidate node with the highest utility value among one or more candidate nodes is identified as the target node.

[0150] In one possible implementation, the device further includes:

[0151] The window shrinking module is used to shrink the target switching window and redetermine the multiple utility values ​​of the multiple nodes in the shrunken target switching window if it is determined that there are no first-type nodes among the multiple nodes based on the multiple utility values ​​of multiple nodes in the target switching window.

[0152] The target node determination module 803 is also specifically used for:

[0153] If, based on the utility values ​​of multiple nodes within the narrowed target switching window, it is determined that there are first-type nodes among the multiple nodes, then the first-type nodes among the multiple nodes are identified as candidate nodes, resulting in one or more candidate nodes.

[0154] The candidate node with the highest utility value among one or more candidate nodes is identified as the target node.

[0155] In one possible implementation, the window shrinking module is specifically used for:

[0156] Based on the window limit range, the target switching window is reduced in size so that the size of the reduced target switching window is within the window limit range.

[0157] In one possible implementation, the device further includes:

[0158] The window enlargement module is used to enlarge the target switching window.

[0159] In one possible implementation, the window enlargement module is specifically used for:

[0160] Based on the window limit range, increase the size of the target switching window so that the size of the increased target switching window is within the window limit range.

[0161] In one possible implementation, the device is included in a first node, which is the master node of the distributed system, and the target node is not the same node as the first node;

[0162] The master node switching module 804 is specifically used for:

[0163] Synchronize log information to the target node and stop sending heartbeat messages so that the target node can start the election process;

[0164] If a data access request initiated by a client is received during the election process, the data access request is cached.

[0165] If the target node is successfully elected as the master node of the distributed system, the first node will be demoted to a slave node of the distributed system, and the data access requests cached during the election process will be sent to the target node so that the target node can take over the processing of data access requests from the first node.

[0166] In one possible implementation, the master node switching module 804 is further specifically used for:

[0167] If the target node is not successfully elected as the master node of the distributed system, the first node is determined to continue as the master node of the distributed system, continues to send heartbeat messages, and processes cached data access requests.

[0168] In one possible implementation, the distributed system is a distributed system deployed across geographical regions.

[0169] In this embodiment, the network and application states of multiple nodes are acquired. The network state describes the network situation between the corresponding node and other nodes in the distributed system, while the application state describes the processing status of the corresponding node for data access requests initiated by clients. Therefore, by combining the network and application states of these multiple nodes, the utility value of each node can be dynamically determined. Moreover, determining the utility value of a node from multiple dimensions ensures high accuracy. Since the utility value refers to the performance improvement brought to the distributed system after a node is elected as the master node, selecting the node with the highest utility value as the new master node improves the accuracy and effectiveness of master node election, thereby significantly reducing transaction latency and improving system throughput and stability. In other words, this embodiment actively acquires the network and application states of multiple nodes, determines the utility value of nodes from multiple dimensions based on these states, and actively switches the master node, thereby significantly improving system performance while maintaining system consistency. In addition, this application also proposes the concept of a target switching window. By determining a target switching window of an appropriate size, it is possible not only to avoid frequent election of the master node, but also to ensure timely re-election of the master node in the event of network instability, thereby enabling a rapid response to dynamic network environments and improving the stability of the distributed system.

[0170] It should be noted that the node election device provided in the above embodiments is only illustrated by the division of the above functional modules during node election. In practical applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the node election device and the node election method embodiments provided in the above embodiments belong to the same concept, and the specific implementation process can be found in the method embodiments, which will not be repeated here.

[0171] This application also provides a computer-readable storage medium storing instructions that, when executed on a computer, cause the computer to perform the above-described node election method.

[0172] This application also provides a computer program product containing instructions that, when executed on a computer, cause the computer to perform the above-described node election method.

[0173] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium accessible to a computer, or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., digital versatile disc (DVD)), or a semiconductor medium (e.g., solid state disk (SSD)). It is worth noting that the computer-readable storage medium mentioned in the embodiments of this application can be a non-volatile storage medium; in other words, it can be a non-transient storage medium.

[0174] It should be understood that "multiple" as mentioned herein refers to two or more. In the description of the embodiments of this application, unless otherwise stated, " / " means "or," for example, A / B can mean A or B; "and / or" in this document is merely a description of the relationship between related objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, and B existing alone. In addition, to facilitate a clear description of the technical solutions of the embodiments of this application, the terms "first," "second," etc., are used in the embodiments of this application to distinguish identical or similar items with substantially the same function and effect. Those skilled in the art will understand that the terms "first," "second," etc., do not limit the quantity or execution order, and the terms "first," "second," etc., do not necessarily imply that they are different.

[0175] It should be noted that the information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, data stored, data displayed, etc.) and signals involved in the embodiments of this application are all authorized by the user or fully authorized by all parties, and the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions.

[0176] The above descriptions are embodiments provided in this application and are not intended to limit this application. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.

Claims

1. A node election method, characterized in that, The distributed system comprises multiple nodes, and the method includes: The network status and application status of the multiple nodes are obtained. The network status is used to describe the network situation between the node and other nodes in the distributed system, and the application status is used to describe the processing status of the node in response to data access requests initiated by the client. Based on the network status and application status of the multiple nodes, the utility value corresponding to each of the multiple nodes is determined. The utility value refers to the performance improvement value brought to the distributed system after the node is elected as the master node. Based on the utility values ​​corresponding to the multiple nodes, determine the target node with the highest utility value from among the multiple nodes; The target node is elected as the master node of the distributed system.

2. The method as described in claim 1, characterized in that, The network status includes the network latency between the node and other nodes in the distributed system, and the application status includes the read / write ratio and the number of requests of the node. The read / write ratio refers to the ratio of read operations to write operations processed by the node in the data access requests initiated by the client, and the number of requests refers to the number of requests processed by the node in the data access requests initiated by the client.

3. The method as described in claim 2, characterized in that, The determination of the utility value corresponding to each of the multiple nodes based on the network state and application state of the multiple nodes includes: Based on the number of requests to the multiple nodes, the popularity of the multiple nodes is determined, and the popularity is positively correlated with the number of requests. Based on the network latency between the plurality of nodes and other nodes in the distributed system, the read / write ratio of the plurality of nodes, and their popularity, the utility value corresponding to each of the plurality of nodes is determined.

4. The method as described in claim 3, characterized in that, The utility value is negatively correlated with the network latency, positively correlated with the read / write ratio, and positively correlated with the popularity.

5. The method according to any one of claims 1-4, characterized in that, The utility value corresponding to the node includes multiple utility values ​​of the node within the target switching window; The step of determining the target node with the highest utility value from among the multiple nodes based on their respective utility values ​​includes: If a first type of node is determined to exist among the multiple nodes based on the multiple utility values ​​of the multiple nodes within the target switching window, then the first type of node among the multiple nodes is determined as a candidate node, resulting in one or more candidate nodes. The first type of node refers to a node whose multiple utility values ​​within the target switching window are always positive. The candidate node with the highest utility value among the one or more candidate nodes is determined as the target node.

6. The method as described in claim 5, characterized in that, The method further includes: If it is determined that there is no first type node among the multiple nodes based on the multiple utility values ​​of the multiple nodes within the target switching window, then the target switching window is narrowed, and the multiple utility values ​​of the multiple nodes within the narrowed target switching window are re-determined; If, based on the utility values ​​of the multiple nodes within the narrowed target switching window, it is determined that there is a first type of node among the multiple nodes, then the first type of node among the multiple nodes is determined as a candidate node, resulting in one or more candidate nodes. The candidate node with the highest utility value among the one or more candidate nodes is determined as the target node.

7. The method as described in claim 6, characterized in that, The process of narrowing the target switching window includes: Based on the window limit range, the target switching window is reduced in size so that the size of the reduced target switching window is within the window limit range.

8. The method according to any one of claims 5-7, characterized in that, If, based on multiple utility values ​​of the multiple nodes within the target switching window, it is determined that a first-type node exists among the multiple nodes, the method further includes: Increase the target switching window.

9. The method as described in claim 8, characterized in that, Increasing the target switching window includes: Based on the window limit range, the target switching window is increased so that the size of the increased target switching window is within the window limit range.

10. The method according to any one of claims 1-9, characterized in that, The method is applied to a first node, which is the master node of the distributed system, and the target node is not the same node as the first node. The step of electing the target node as the master node of the distributed system includes: The log information is synchronized to the target node, and heartbeat messages are stopped, so that the target node can start the election process; If a data access request initiated by the client is received during the election process, the data access request is cached. If the target node is successfully elected as the master node of the distributed system, the first node is demoted to a slave node of the distributed system, and the data access requests cached during the election process are sent to the target node so that the target node can take over from the first node to handle the data access requests.

11. The method as described in claim 10, characterized in that, The method further includes: If the target node is not successfully elected as the master node of the distributed system, then the first node is determined to continue to be the master node of the distributed system, continues to send heartbeat messages, and processes cached data access requests.

12. The method according to any one of claims 1-11, characterized in that, The distributed system is a distributed system deployed across geographical regions.

13. A node election device, characterized in that, The distributed system includes multiple nodes, and the device includes: The status acquisition module is used to acquire the network status and application status of the multiple nodes. The network status is used to describe the network situation between the node and other nodes in the distributed system, and the application status is used to describe the processing status of the node in response to data access requests initiated by the client. The utility value determination module is used to determine the utility value corresponding to each of the multiple nodes based on the network status and application status of the multiple nodes. The utility value refers to the performance improvement value brought to the distributed system after the node is elected as the master node. The target node determination module is used to determine the target node with the highest utility value from the plurality of nodes based on the utility values ​​corresponding to the plurality of nodes respectively; The master node switching module is used to elect the target node as the master node of the distributed system.

14. The apparatus as claimed in claim 13, characterized in that, The network status includes the network latency between the node and other nodes in the distributed system, and the application status includes the read / write ratio and the number of requests of the node. The read / write ratio refers to the ratio of read operations to write operations processed by the node in the data access requests initiated by the client, and the number of requests refers to the number of requests processed by the node in the data access requests initiated by the client.

15. The apparatus as claimed in claim 14, characterized in that, The utility value determination module is specifically used for: Based on the number of requests to the multiple nodes, the popularity of the multiple nodes is determined, and the popularity is positively correlated with the number of requests. Based on the network latency between the plurality of nodes and other nodes in the distributed system, the read / write ratio of the plurality of nodes, and their popularity, the utility value corresponding to each of the plurality of nodes is determined.

16. The apparatus as claimed in claim 15, characterized in that, The utility value is negatively correlated with the network latency, positively correlated with the read / write ratio, and positively correlated with the popularity.

17. The apparatus according to any one of claims 13-16, characterized in that, The utility value corresponding to the node includes multiple utility values ​​of the node within the target switching window; The target node determination module is specifically used for: If a first type of node is determined to exist among the multiple nodes based on the multiple utility values ​​of the multiple nodes within the target switching window, then the first type of node among the multiple nodes is determined as a candidate node, resulting in one or more candidate nodes. The first type of node refers to a node whose multiple utility values ​​within the target switching window are always positive. The candidate node with the highest utility value among the one or more candidate nodes is determined as the target node.

18. The apparatus as claimed in claim 17, characterized in that, The device further includes: The window shrinking module is used to shrink the target switching window and redetermine the multiple utility values ​​of the multiple nodes in the shrunken target switching window if it is determined that there is no first type node among the multiple nodes based on multiple utility values ​​of the multiple nodes in the target switching window. The target node determination module is also specifically used for: If, based on the utility values ​​of the multiple nodes within the narrowed target switching window, it is determined that there is a first type of node among the multiple nodes, then the first type of node among the multiple nodes is determined as a candidate node, resulting in one or more candidate nodes. The candidate node with the highest utility value among the one or more candidate nodes is determined as the target node.

19. The apparatus as claimed in claim 18, characterized in that, The window shrinking module is specifically used for: Based on the window limit range, the target switching window is reduced in size so that the size of the reduced target switching window is within the window limit range.

20. The apparatus according to any one of claims 17-19, characterized in that, The device further includes: The window enlargement module is used to enlarge the target switching window.

21. The apparatus as claimed in claim 20, characterized in that, The window enlargement module is specifically used for: Based on the window limit range, the target switching window is increased so that the size of the increased target switching window is within the window limit range.

22. The apparatus according to any one of claims 13-21, characterized in that, The device is included in a first node, which is the master node of the distributed system, and the target node is not the same node as the first node; The master node switching module is specifically used for: The log information is synchronized to the target node, and heartbeat messages are stopped, so that the target node can start the election process; If a data access request initiated by the client is received during the election process, the data access request is cached. If the target node is successfully elected as the master node of the distributed system, the first node is demoted to a slave node of the distributed system, and the data access requests cached during the election process are sent to the target node so that the target node can take over from the first node to handle the data access requests.

23. The apparatus as claimed in claim 22, characterized in that, The master node switching module is also specifically used for: If the target node is not successfully elected as the master node of the distributed system, then the first node is determined to continue to be the master node of the distributed system, continues to send heartbeat messages, and processes cached data access requests.

24. The apparatus according to any one of claims 13-23, characterized in that, The distributed system is a distributed system deployed across geographical regions.

25. A computer device, characterized in that, The computer device includes a memory and a processor, the memory being used to store computer programs and the processor being used to execute the computer programs stored in the memory to implement the method according to any one of claims 1-12.

26. A computer-readable storage medium, characterized in that, The storage medium stores instructions that, when executed on the computer, cause the computer to perform the method described in any one of claims 1-12.

27. A computer program product containing instructions, characterized in that, When the instructions are executed on a computer, the computer causes the computer to perform the method according to any one of claims 1-12.