Distributed system, data synchronization method, electronic device, and storage medium
By setting each second node in the distributed system corresponding to the target node and synchronizing data with the target node, the problem of poor scalability in the distributed system due to the performance limitation of a single node is solved, and data consistency and high availability are achieved. At the same time, it improves the scalability and response efficiency of the system.
Patent Information
- Application Number
- PCT/CN2024/094274
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2023-05-24
- Filing Date
- 2024-05-20
- Publication Date
- 2024-11-28
AI Technical Summary
When ensuring data consistency, existing distributed systems are limited by the performance of a single node, resulting in poor scalability. Especially when responding to task requests, the scalability of the second node is limited by the performance of the leader node.
By setting each second node in the distributed system to correspond to a target node and using the target node to synchronize the target data to the second node, the second node can respond to task requests based on the synchronized target data, thereby avoiding a single node from going to The scalability problem caused by synchronizing data from the second node improves the scalability of the distributed system.
It realizes the scalability of distributed systems while maintaining data consistency and high availability, reduces dependence on the performance of a single node, and enhances the scalability and response efficiency of the system.
Smart Images

Figure CN2024094274_28112024_PF_FP_ABST
Abstract
Description
A distributed system, data synchronization method, electronic device and storage medium
[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on May 24, 2023, with application number 202310597808.1 and application name “A distributed system, data synchronization method, electronic device and storage medium”, the entire contents of which are incorporated by reference into this application. Technical Field
[0002] The embodiments in this specification relate to the field of computer application technology, specifically, to distributed technology under the field of computer application technology, and more specifically, to a distributed system, a data synchronization method, an electronic device, and a storage medium. Background Art
[0003] Distributed systems are widely used in various application scenarios such as cloud computing, cloud storage and data distribution due to their high availability, high performance and low cost.
[0004] However, in current distributed systems, the performance of a single node is limited, resulting in poor scalability of distributed systems.
[0005] Summary of the Invention
[0006] Multiple embodiments in this specification provide a distributed system, a data synchronization method, an electronic device, and a storage medium to achieve the purpose of improving the scalability of the distributed system while ensuring data consistency among nodes in the system.
[0007] In a first aspect, an embodiment of the present specification provides a distributed system, comprising: a plurality of first nodes and a plurality of second nodes; wherein,
[0008] The plurality of first nodes maintain consistency of target data stored in the plurality of first nodes based on a consistency protocol; each of the second nodes corresponds to a target node among the plurality of first nodes;
[0009] The target node is configured to synchronize the target data to a second node corresponding thereto;
[0010] The second node is configured to respond to a task request based on the target data.
[0011] In a second aspect, an embodiment of the present specification provides a data synchronization method, applied to a target node among multiple first nodes in a distributed system, wherein the distributed system includes multiple first nodes and multiple second nodes, wherein the multiple first nodes maintain consistency of target data stored by the multiple first nodes based on a consistency protocol; each second node corresponds to a target node among the multiple first nodes; the data synchronization method includes:
[0012] The target data is synchronized to a second node corresponding thereto, so that the second node responds to a task request based on the target data.
[0013] In a third aspect, an embodiment of this specification provides an electronic device, including: a processor and a memory;
[0014] The memory is connected to the processor, and is used to store computer programs;
[0015] The processor is used to implement the above-mentioned data synchronization method by running the computer program stored in the memory.
[0016] In a fourth aspect, an embodiment of the present specification provides a storage medium having a computer program stored thereon, and when the computer program is executed by a processor, the data synchronization method as described above is implemented.
[0017] In a fifth aspect, an embodiment of the present specification provides a computer program product or a computer program, wherein the computer program product or the computer program includes computer instructions, and the computer instructions are stored in a computer-readable storage medium; the processor of the computer device reads the computer instructions from the computer-readable storage medium, and the processor implements the steps of the above-mentioned data synchronization method when executing the computer instructions.
[0018] The multiple implementation methods provided in this specification maintain the consistency of target data stored in each of the multiple first nodes based on a consistency protocol, and ensure the data consistency of each node and the high availability of the system by making each second node correspond to a target node among the multiple first nodes and using the target node to synchronize the target data to the second node corresponding to it; in addition, since the second node as the task request response node corresponds to a target node and can synchronize target data from the target node corresponding to the second node, rather than corresponding to a specific node, the problem of poor scalability of the second node caused by synchronizing data to the second node through a single node is solved, and the scalability of the distributed system is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0019] FIG1 is a schematic diagram of the structure of a distributed system;
[0020] FIG2 is a schematic diagram of an application scenario of a distributed system provided by one embodiment of this specification;
[0021] FIG3 is a schematic diagram of the structure of a distributed system provided by one embodiment of this specification;
[0022] FIG4 is a flow chart of a data synchronization method provided in one embodiment of this specification;
[0023] FIG5 is a schematic structural diagram of an electronic device provided in one embodiment of this specification. DETAILED DESCRIPTION
[0024] Unless otherwise defined, technical or scientific terms used in the embodiments of this specification should have the same ordinary meaning as those understood by persons of ordinary skill in the art to which this specification pertains. The terms "first," "second," and similar terms used in the embodiments of this specification do not denote any order, quantity, or importance, but are provided solely to avoid confusion between constituent elements.
[0025] Unless the context requires otherwise, throughout this specification, the term "plurality" means "at least two," and "including" is to be interpreted as open and inclusive, meaning "including, but not limited to." Throughout this specification, the terms "one embodiment," "some embodiments," "exemplary embodiments," "example," "specific example," or "some examples" are intended to indicate that a particular feature, structure, material, or characteristic associated with the embodiment or example is included in at least one embodiment or example of this specification. The schematic representations of these terms do not necessarily refer to the same embodiment or example.
[0026] The following will be combined with the drawings in the embodiments of this specification to clearly and completely describe the technical solutions in the embodiments of this specification. Obviously, the embodiments described are only part of the embodiments of this specification, not all of the embodiments. Based on the embodiments in this specification, all other embodiments obtained by ordinary technicians in this field without making any creative efforts are within the scope of protection of this specification.
[0027] Overview
[0028] A distributed system is composed of multiple independent computers or groups of computers that communicate and collaborate over a network to complete a task. These computers (or groups) are called nodes and can be deployed in the same or different regions. The design goals of a distributed system are to improve system reliability, scalability, and performance. Common applications of distributed systems include distributed DNS (Domain Name System), distributed router systems, distributed databases, distributed file systems, distributed computing, distributed search engines, and distributed caching. These applications help us better utilize computer resources and improve system reliability and performance.
[0029] Core challenges in distributed systems include maintaining data consistency and high system availability. Data consistency ensures that all nodes in a distributed system store identical data, preventing different nodes from returning different results for the same task request. High availability ensures that a distributed system can maintain continuous and stable operation despite various failures, errors, or abnormalities, ensuring that users can always access and use all system functions normally, thereby achieving high system reliability and stability. This requires distributed systems to possess self-diagnosis, self-repair, and self-protection capabilities. It also requires highly reliable hardware and software, as well as sufficient redundancy and backup mechanisms, to address various potential failures and risks.
[0030] In related technologies, to maintain data consistency across nodes in a distributed system and improve system availability, a consistency protocol can be used to keep the data of nodes in the distributed system consistent, ensuring that each node responds identically to the same task request. Maintaining data consistency across multiple nodes in the system prevents data loss caused by failures or anomalies in a single node or nodes, thereby improving system data reliability. Furthermore, when the system restarts unexpectedly, the consistency algorithm can quickly restore the latest data from multiple nodes in the system, ensuring high system availability.
[0031] However, during the specific application process, the inventors found that while the current distributed system uses consistency protocols to ensure data consistency and high availability, it may cause the system to be limited by the performance of a single node, resulting in poor scalability of the distributed system.
[0032] Specifically, the Raft Consensus Protocol (Raft Consensus Protocol) in the consensus protocol is used as an example for illustration. In the Raft protocol, nodes in a distributed system are mainly divided into the following types: leader nodes, follower nodes, candidate nodes, and learner nodes.
[0033] Among them, follower nodes can exist as candidate nodes during the election process. Follower nodes and leader nodes can be called voter nodes. Learner nodes do not cast votes, nor do they receive votes as candidate nodes. The leader node is the node that obtains the majority of votes from nodes during an election process. The leader node is responsible for data synchronization among all follower nodes and learner nodes during a term. At the same time, the leader node will also periodically send heartbeat messages to candidate nodes to notify them of the leader node's survival status. Candidate nodes are the most common nodes. They receive heartbeat messages from the leader node and update their own status according to the leader node's instructions. If a candidate node does not receive a heartbeat message from the leader node within a certain period of time, it will assume that the leader node has failed or is abnormal and will enter election mode.
[0034] After a candidate node enters election mode, it automatically converts to a candidate node and sends voting requests to other nodes (excluding learner nodes) and waits for responses from other nodes. If a candidate node receives votes from a majority of voting nodes, it will become the new leader node. If no candidate node receives votes from a majority of voting nodes, it will enter the next round of elections.
[0035] The above mechanism, on the one hand, ensures data consistency between the leader node and candidate nodes, and on the other hand, ensures the election mechanism of a new leader node when the leader node fails or is abnormal, thus ensuring data consistency and high availability of the distributed system.
[0036] Learner nodes are special nodes used to back up the leader node's data and maintain data consistency with the leader node. Learner nodes do not participate in voting and do not receive votes from other nodes. Referring to Figure 1, in mainstream distributed systems, leader nodes and candidate nodes can serve as nodes in the system's control plane. These nodes are responsible for ensuring data consistency and high availability across all nodes within the system. After a node becomes the leader, they configure learner node data to ensure that the data in the learner node is consistent with the leader node's data. Multiple learner nodes can serve as nodes in the system's data plane, specifically responsible for processing task requests received by the distributed system (such as DNS resolution requests, routing requests, etc.) and returning the results of the task requests. The distributed system shown in Figure 1 suffers from poor scalability. This is because the number of nodes responsible for responding to task requests in a distributed system is extremely large. A single leader node not only needs to configure data for a large number of learner nodes but also needs to ensure data consistency among follower nodes. This makes the performance of the leader node a constraint on system scalability. When the performance required for data synchronization between follower nodes and learner nodes exceeds the maximum performance that can be allocated by the leader node, the distributed system no longer supports adding nodes, resulting in poor scalability of the overall system.
[0037] In order to solve this problem, the inventors discovered through research that a second node corresponding to a target node (the target node may refer to a first node corresponding to a second node) among multiple first nodes can be set in a distributed system, so that each second node corresponds to a target node (the target nodes corresponding to different second nodes may be the same or different). The target node can synchronize the target data to the second node corresponding to the target node, and enable the second node to respond to the task request based on the synchronized target data. In this way, all second nodes do not need to synchronize data from the same node, avoiding the performance of a certain node becoming a limitation on the scalability of the system; solving the problem of poor scalability of the second node caused by synchronizing data from a single node to the second node, and improving the scalability of the distributed system. In addition, each target node can correspond to multiple second nodes and be responsible for data synchronization of multiple second nodes, greatly increasing the scalability of the system.
[0038] Based on the above-mentioned inventive concept, the embodiments of this specification provide a distributed system, which will be exemplarily described below.
[0039] Scenario Example
[0040] Refer to Figure 2, which shows a feasible application scenario of a distributed system. The application scenario can be a data distribution scenario. The user sends a task request to the distributed system 10 through the client 12, and the distributed system 10 responds to the task request and returns the response result to the client 12.
[0041] Specifically, the data distribution scenario can be a DNS resolution scenario. A user sends a resolution request to the DNS system through the client 12. The load management node in the DNS system distributes the resolution request to the second node based on the load balancing algorithm. The second node responds to the resolution request and returns the response result to the client, completing a DNS domain name resolution task.
[0042] The DNS system can be a distributed system 10, in which the nodes can be divided into first nodes and second nodes according to functional configuration. Specifically, the node with the data configuration function of the second node can be divided into the first node, and the node responsible for processing the specific resolution request can be divided into the second node. All first nodes constitute a control plane, and all second nodes can constitute a data plane.
[0043] In addition to the above-mentioned DNS resolution scenario, the distributed system provided by the embodiments of this specification can also be applied to a data packet distribution scenario. The routing system in this scenario can be a distributed system, and the target data of each node in the system can include a routing table.
[0044] In addition to the DNS domain name resolution scenario and data packet distribution scenario exemplified above, the distributed system provided in the embodiments of this specification can also be applied to other feasible data distribution scenarios, which are not limited in this specification.
[0045] In the application scenario shown in Figure 2, the client 12 can be an electronic device with network access capabilities. Specifically, for example, the client 12 can be a desktop computer, tablet computer, laptop computer, smartphone, digital assistant, smart wearable device, shopping guide terminal, television, smart speaker, microphone, etc. Smart wearable devices include, but are not limited to, smart bracelets, smart watches, smart glasses, smart helmets, smart necklaces, etc. Alternatively, the client can be software that can run on the electronic device. In the distributed system 10, the node 11 can include at least one server. The server can be an electronic device with certain computing and processing capabilities. It can have a network communication module, a processor, and memory. Of course, the server can also refer to software running on the electronic device. The server can also be a distributed server, which can be a system with multiple processors, memories, network communication modules, etc. operating in coordination. Alternatively, the server can be a server cluster formed by multiple servers. Alternatively, with the advancement of science and technology, the server can also be a new technical means that can implement the corresponding functions of the embodiments of this specification. For example, it can be a new form of "server" based on quantum computing.
[0046] Example system
[0047] One embodiment of this specification provides a distributed system, as shown in FIG3 , including: a plurality of first nodes 101 and a plurality of second nodes 102; wherein,
[0048] The multiple first nodes 101 maintain consistency of target data stored in the multiple first nodes based on a consistency protocol; each second node 102 corresponds to a target node in the multiple first nodes 101;
[0049] The target node is configured to synchronize the target data to the second node 102 corresponding thereto;
[0050] The second node 102 is configured to respond to a task request based on the target data.
[0051] The first node 101 may be a node in the control plane of the distributed system 100. For example, the first node 101 may be a node with management and / or data configuration functions. Taking the distributed system 100 based on the Raft protocol as an example, the first node 101 may include a leader node and a follower node (in the election process, the first node 101 may also include a candidate node). In this embodiment, there may be multiple target nodes among the multiple first nodes 101. When a first node 101 corresponds to a second node 102, it may be referred to as a target node, that is, the target node may be regarded as a special type of first node 101. The second node 102 may be a node in the data plane of the distributed system 100. For example, the second node 102 may be a node in the distributed system 100 for responding to task requests. Unlike the learner node in the Raft protocol, each second node 102 corresponds to a target node, and the target nodes corresponding to each second node 102 can be different. Multiple second nodes 102 can correspond to multiple target nodes respectively. In this way, the second node 102 can obtain the required target data from the target node corresponding to it without relying on a single leader node, avoiding the problem that the learner node is highly bound to the leader node, which causes the scalability of the distributed system 100 to be constrained by the performance of a single leader node, thereby improving the scalability of the distributed system 100. It can be said that when the consistency protocol is the Raft protocol, the second node 102 is an extension of the Raft protocol, and the data consistency of each node in the system is maintained by the Raft protocol. The correspondence between the extended second node 102 and the target node and the data synchronization logic are used to improve the scalability of the distributed system. In addition to the Raft protocol, in some embodiments, the consistency protocol may also be the Paxos protocol. This specification does not limit the specific content of the consistency protocol. As long as it has a data consistency maintenance logic similar to the Raft protocol, that is, the data consistency of the node is maintained based on the log index, and the system data will not roll back.
[0052] In addition, as mentioned above, in this embodiment, the multiple first nodes 101 maintain consistency of target data stored by the multiple first nodes based on the consistency protocol, which can ensure the data consistency of the distributed system 100 and the high availability of the system. Optionally, the consistency protocol includes but is not limited to the Raft protocol mentioned above. The multiple first nodes 101 maintain consistency of target data stored by the multiple first nodes based on the consistency protocol, which may mean that the multiple first nodes 101 maintain consistency of target data between most of the first nodes 101 based on the consistency protocol, or it may mean that the multiple first nodes 101 maintain consistency of target data stored between each of the first nodes 101 based on the consistency protocol.
[0053] The target data refers to the data required by the distributed system 100 to respond to a task request. Taking the DNS system as an example, the target data may include the data required for the domain name resolution request task, such as the correspondence between domain names and IP addresses. Taking the routing system as an example, the target data may include the routing table.
[0054] Each first node among the multiple first nodes can serve as a target node of the second node and correspond to it. Therefore, when the multiple second nodes correspond to their respective target nodes, there can be multiple target nodes among the multiple first nodes. As can be seen from Figure 3, the second node 102 corresponds to a target node among the multiple first nodes. The target node can correspond to one second node 102 or two or more second nodes 102. There may also be a first node 101 among the multiple first nodes 101 that does not correspond to the second node 102. In some embodiments, the correspondence between the target node and the second node 102 is not fixed, and the correspondence can be re-established according to actual conditions. For example, when a target node fails, the second node 102 corresponding to the target node can establish a correspondence with other target nodes and synchronize the target data from the newly corresponding target node.
[0055] The target node is used to synchronize the target data to the corresponding second node, which can be understood as follows: assuming that the target node A corresponds to the second node a, the second node b and the second node c, and the target node B corresponds to the second node d and the second node e, then the target node A is used to synchronize the target data to the second node a, the second node b and the second node c; the target node B is used to synchronize the target data to the second node d and the second node e.
[0056] In general, in this embodiment, the distributed system 100 maintains consistency in the target data stored in each of the multiple first nodes 101 based on the consistency protocol, and ensures the data consistency of each node and the high availability of the system by corresponding each second node 102 to one of the target nodes and using the target node to synchronize the target data to the second node 102 corresponding to it; in addition, since the second node 102 as the task request response node corresponds to one target node and can synchronize the target data from the target node corresponding to the second node 102, rather than corresponding to a specific node, the problem of poor scalability of the second node 102 caused by synchronizing data to the second node 102 through a single node is solved, and the scalability of the distributed system 100 is improved.
[0057] In order to improve the data synchronization speed between the second node 102 and the target node, in some embodiments, the first node 101 stores the location information of each first node 101, and the location information is used to represent the geographical location where the first node 101 is deployed;
[0058] The second node 102 is further configured to obtain location information of each first node 101 from any first node 101, and establish a corresponding relationship with a neighboring target node based on the location information of each first node 101;
[0059] The neighboring target node includes the first node 101 whose geographical location is closest to the geographical location of the second node 102 .
[0060] As mentioned above, the target node is also a type of first node 101 , and therefore, the location information of each first node 101 is also stored in the target node, and the location information is used to represent the geographical location where the first node 101 is deployed.
[0061] At present, it is becoming more and more common for enterprises to deploy services in distributed systems with hybrid cloud and multi-cloud architectures, resulting in a surge in the demand for expansion of data nodes used to respond to task requests in distributed systems. Taking the Raft protocol as an example, if the second node 102 synchronizes data with the leader node, it will inevitably lead to a large amount of cross-cloud and cross-regional traffic. These traffics not only have high latency, but also increase the cost of use for the enterprise. Therefore, in this embodiment, after the second node 102 is established or restarted, it can obtain the location information of each of the first nodes 101 from the first node 101, and determine the neighboring target node based on this location information and establish a corresponding relationship with it. In this way, in the subsequent data synchronization process, the communication path between the second node 102 and the neighboring target node is shorter, which can improve the data synchronization speed, reduce the probability of the second node 102 synchronizing data across clouds and regions, and reduce the user's cost of use.
[0062] The location information may include first location information and second location information, wherein the first location information is used to characterize the first geographical range in which the first node 101 is deployed, and the second location information is used to characterize the second geographical range in which the first node 101 is deployed, and the first geographical range is larger than the second geographical range. When determining a neighboring target node, the second node 102 preferentially searches for a neighboring target node within the second geographical range to which the second node 102 belongs. When there is no node within the second geographical range that can serve as a neighboring target node, the neighboring target node may be searched within the first geographical range to which the second node 102 belongs. When there is no node within the first geographical range to which the second node 102 belongs that can serve as a neighboring target node, the neighboring target node may be searched across the first geographical range. The first geographical range may be, for example, a larger range such as a continent or a country, and the second geographical range may be, for example, a smaller range such as a city or a commercial district.
[0063] In order to improve the synchronization speed of the target data between the target node and the second node 102, in some embodiments, the first node 101 and the second node 102 store log indexes corresponding to previous data updates, and the log indexes are used to identify data update messages, and the data update messages include incremental data of the target data after the data update;
[0064] The target node synchronizes the target data to the corresponding second node 102 specifically for:
[0065] Sending a data update message corresponding to the first target log index to the second node 102, so that the second node 102 updates the data according to the first target log index;
[0066] The first target log index includes the log index after the first index in the target node, and the first index is the log index corresponding to the last data update in the second node 102.
[0067] In this embodiment, data update refers to updating the target data in the node, and data update may include adding, deleting and modifying the target data. Each data update of a node in the system is implemented by sending a data update message to the cluster in the distributed system 100. Each data update message has a log index (index) to identify it, and the data update message may include incremental data of the target data after each data update. The incremental data refers to the change data of the target data after the data update compared to the target data before the data update. In some embodiments, the log index can be a continuously increasing 64-bit positive number.
[0068] For example, assuming that the target node has undergone 100 data updates from log index 1 to log index 100 to reach the latest state of the target data, and the second node 102 has undergone 90 data updates from log index 1 to log index 90, the target node can send the data update message corresponding to log index 91 to log index 100 to the second node 102, so that the second node 102 can perform the final 10 data updates according to the data update message corresponding to log index 91 to log index 100, so that the target data in the second node 102 remains synchronized with the target data in the target node.
[0069] By sending the data update message corresponding to the log index after the first index to the second node 102 to update the target data in the second node 102, the amount of data required to be transmitted between the target node and the second node 102 can be reduced, which is conducive to improving the data synchronization efficiency between the target node and the second node 102.
[0070] In some embodiments, after the second node 102 establishes a corresponding relationship and a communication connection with the target node, the second node 102 is further configured to send the target node a log index corresponding to the last data update in the second node 102, so that the target node can learn the first index in each second node 102. In this embodiment, by having the second node 102 send the first index to the target node, the target node does not need to query the second node 102 for the first index, which helps reduce the burden on the target node.
[0071] In some embodiments, in order to improve the speed of data synchronization between the target node and the second node 102 and reduce the time required for restarting or creating the second node 102, the first node 101 is further configured to generate first snapshot information after multiple data updates; the first snapshot information includes the target data in the first node 101 at the time the first snapshot information is generated;
[0072] The target node synchronizes the target data to the corresponding second node 102 specifically for:
[0073] Sending a data update message corresponding to the second target log index and the most recently generated first snapshot information to the second node 102, so that the second node 102 can update data according to the first snapshot information and the second target log index;
[0074] The second target log index includes the log index after the second index in the target node, and the second index is the log index corresponding to the last data update of the target node when the first snapshot information is generated.
[0075] Accordingly, the second node 102 performs data update according to the first target log index specifically for:
[0076] Obtaining the first snapshot information most recently generated in the target node;
[0077] Loading target data in the first snapshot information;
[0078] The loaded target data is updated according to a data update message corresponding to a log index following the second index in the first target log index.
[0079] Unlike the log index, the first snapshot information (snapshot) is the information that represents the status of the first node 101 at that moment after multiple data updates. It is a full amount of data. It is still assumed that the target node has experienced 100 data updates from log index 1 to log index 100 to reach the latest state of the target data, and the second node 102 has undergone 90 data updates from log index 1 to log index 90.
[0080] However, after the target node updates the data corresponding to log index 95, it generates a first snapshot representing the state at that moment. This first snapshot includes all target data after the target node has updated 95 times. The target node can then send this first snapshot and log indexes 96 to 100 to second node 102. After loading this first snapshot, second node 102 can then perform only five data updates to reach the latest target data state. This reduces the number of data updates, improves the efficiency of restarting or re-creating second node 102, and reduces waiting time.
[0081] Especially when the number of data updates of each node in the system is too large (for example, tens of millions or hundreds of millions of data updates), the data update method provided in this embodiment can greatly reduce the time required for data synchronization when the second node 102 is restarted or newly created, and can also reduce the amount of communication data between the target node and the second node 102.
[0082] In some embodiments, after generating the first snapshot information, the first node 101 may delete the log index before the time of generating the first snapshot information and the data update message corresponding to the log index to reduce the storage space occupied by the first node 101.
[0083] For example, after the first node 101 updates the data corresponding to log index 10000, it generates a first snapshot information representing the status at that moment. Then, the log indexes 1 to 10000 and their corresponding data update messages can be deleted. When the number of data updates is large, the storage space occupied by the log indexes 1 to 10000 and their corresponding data update messages on the first node 101 can be greatly reduced.
[0084] Some embodiments of this specification also provide another method for reducing data synchronization time after the second node 102 is restarted. Specifically, in an optional embodiment, the second node 102 is further configured to generate second snapshot information after multiple data updates; the second snapshot information includes target data in the second node 102 at the time the second snapshot information is generated;
[0085] The second node 102 performs data update according to the first target log index specifically for:
[0086] Loading target data in the second snapshot information generated most recently;
[0087] updating the loaded target data according to a data update message corresponding to a log index subsequent to the third index in the first target log index;
[0088] The third index is the log index corresponding to the last data update of the second node 102 when the second snapshot information is generated.
[0089] In this embodiment, similar to the first snapshot information, the second node 102 can generate a full set of data representing the current state of the target data (i.e., the second snapshot information) after multiple data updates (e.g., every 100 or 200 data updates). Assume again that the first node 101 has experienced 100 data updates from log index 1 to log index 100 to reach the latest state of the target data, while the second node 102 has experienced 90 data updates from log index 1 to log index 90.
[0090] Then after the second node 102 is restarted, the target data in the second node 102 is lost. In some embodiments, the second node 102 needs to perform 90 data updates based on the data update messages corresponding to the historical log indexes 1 to 90, and then perform 10 data updates based on the data update messages corresponding to the log indexes 91 to 100 sent by the target node to reach the latest target data status.
[0091] However, in this embodiment, assume that after the second node 102 updates the data corresponding to log index 80, it generates a second snapshot representing the state at that moment. That is, the second snapshot includes all target data after the second node 102 has performed 80 data updates. Therefore, after the second node 102 restarts, it only needs to load the second snapshot to restore to the state of the target data corresponding to log index 80. Then, it can perform 20 data updates based on log indexes 81 to 100. This greatly reduces the number of data updates and the time required to restart the second node 102.
[0092] In some implementations, after generating the second snapshot information, the second node 102 may delete the log index and the data update message corresponding to the log index before the second snapshot information is generated, so as to reduce the storage space occupied by the second node 102 .
[0093] For example, after the second node 102 updates the data corresponding to log index 10000, it generates a second snapshot information representing the status at that moment. Then, the log indexes 1 to 10000 and their corresponding data update messages can be deleted. When the number of data updates is large, the storage space occupied by the log indexes 1 to 10000 and their corresponding data update messages on the second node 102 can be greatly reduced.
[0094] In some embodiments, the consistency protocol includes a consensus algorithm based on leader election. For example, the consistency protocol may include a Raft protocol.
[0095] Accordingly, the plurality of first nodes 101 include a leader node and a plurality of follower nodes;
[0096] The leader node is configured to push the updated target data to the follower nodes after updating the target data of the leader node;
[0097] The follower node is configured to update the target data stored in the follower node according to the target data pushed by the leader node.
[0098] In this embodiment, the leader node and the follower node are the roles played by the first node in the Raft protocol. When the first node corresponds to a second node, regardless of whether the first node acts as a leader node or a follower node in the Raft protocol, the first node can be referred to as the target node. The consensus algorithm based on leader election has the characteristics of strong consistency, high availability and fault tolerance. Combined with the characteristics that each second node 102 can correspond to a target node among multiple first nodes 101 and synchronize target data from the corresponding target node, the distributed system 100 can have good scalability on the basis of data consistency, high availability and fault tolerance.
[0099] In summary, the second node 102 provided in the embodiments of this specification has the following specific features:
[0100] Each second node 102 corresponds to a target node, and node changes of the second node 102 do not need to be synchronized to all first nodes 101 in the cluster of the distributed system 100;
[0101] The second node 102 may synchronize target data from a target node and determine the data synchronization progress through a log index;
[0102] Each time the second node 102 is restarted or a new second node 102 is deployed, the nearest first node 101 may be used as a neighboring target node, and the first snapshot information is obtained from the nearest first node 101, and then the incremental data after the first snapshot information is obtained;
[0103] In order to reduce the startup time of the second node 102, the second node 102 may periodically generate second snapshot information. After startup, the second snapshot information may be loaded locally first, and then a data update message corresponding to the log index following the second snapshot information may be requested from the target node.
[0104] After establishing a communication connection with the target node, each second node 102 can inform the target node of the currently synchronized log index. After synchronizing to the new data update message, the target node pushes the incremental data to the second node 102 according to the log index last synchronized by the second node 102.
[0105] The target node and the second node 102 may be provided with location information, so that the second node 102 can select a neighboring target node according to the location information when starting up, establish a corresponding relationship with the neighboring target node, and synchronize data from the neighboring target node.
[0106] Accordingly, an embodiment of this specification further provides a data synchronization method, as shown in FIG4 , which is applied to a target node among multiple first nodes in a distributed system, wherein the distributed system includes multiple first nodes and multiple second nodes, wherein the multiple first nodes maintain consistency of target data stored by the multiple first nodes based on a consistency protocol; each second node corresponds to a target node among the multiple first nodes; the data synchronization method includes:
[0107] S401: Synchronize the target data to a corresponding second node, so that the second node can respond to a task request based on the target data.
[0108] The data synchronization method provided in this embodiment is based on the same application concept as the distributed system provided in the above embodiments of this specification. For technical details not fully described in this embodiment, please refer to the specific processing content of the distributed system provided in the above embodiments of this specification, and will not be repeated here.
[0109] Example electronic devices, storage media, and software
[0110] Another embodiment of this specification also proposes a computing device. As shown in Figure 5, an exemplary embodiment of this specification also provides a computing device, including: a memory and a processor, the memory stores a computer program, and the processor executes the steps of the data synchronization method according to various embodiments of this specification described in the above embodiments of this specification when executing the computer program.
[0111] The internal structure of the computing device can be shown in Figure 5. The computing device includes a processor, a memory, a network interface, and an input device connected via a system bus. The processor of the computing device is used to provide computing and control capabilities. The memory of the central control device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computing device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, the steps in the data synchronization method according to various embodiments of the present specification described in the above embodiments of the present specification are performed.
[0112] The processor may include a main processor, and may also include a baseband chip, a modem, etc.
[0113] The memory stores a computer program that executes the technical solution of the present invention, and may also store an operating system and other key programs. Specifically, the computer program may include program code, which includes computer operating instructions. More specifically, the memory may include read-only memory (ROM), other types of static storage devices that can store static information and instructions, random access memory (RAM), other types of dynamic storage devices that can store information and instructions, disk storage, flash memory, etc.
[0114] The processor may be a general-purpose processor, such as a general-purpose processor (CPU), a microprocessor, or an application-specific integrated circuit (ASIC), or one or more integrated circuits for controlling the execution of the program of the present invention. It may also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic device, discrete gate or transistor logic device, or discrete hardware components.
[0115] The input device may include a device for receiving data and information input by the user, such as a keyboard, mouse, camera, scanner, light pen, voice input device, touch screen, pedometer or gravity sensor.
[0116] Output devices may include means that allow information to be output to a user, such as display screens, printers, speakers, and the like.
[0117] The communication interface may include any device such as a transceiver to communicate with other devices or communication networks, such as Ethernet, Radio Access Network (RAN), Wireless Local Area Network (WLAN), etc.
[0118] The processor executes the computer program stored in the memory and calls other devices, which can be used to implement the various steps of any data synchronization method provided in the above embodiments of the present application.
[0119] The computing device may also include a display component and a voice component. The display component may be a liquid crystal display or an electronic ink display. The input device of the computing device may be a touch layer covering the display component, or a button, trackball or touchpad provided on the housing of the computing device, or an external keyboard, touchpad or mouse.
[0120] Those skilled in the art will understand that the structure shown in FIG5 is merely a block diagram of a portion of the structure related to the solution of this specification, and does not constitute a limitation on the computing device to which the solution of this specification is applied. The specific computing device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.
[0121] In addition to the above-mentioned methods and devices, the data synchronization method provided in the embodiments of this specification may also be a computer program product, which includes a computer program, which, when executed by a processor, enables the processor to execute the steps of the data synchronization method according to various embodiments of this specification described in the above-mentioned "Exemplary Method" section of this specification.
[0122] The computer program product may be written in any combination of one or more programming languages to implement the operations of the embodiments of this specification, including object-oriented programming languages such as Java, C++, and conventional procedural programming languages such as "C" or similar programming languages. The program code may be executed entirely on the user's computing device, partially on the user's computing device, as a stand-alone software package, partially on the user's computing device and partially on a remote computing device, or entirely on a remote computing device or server.
[0123] In addition, an embodiment of this specification also provides a computer-readable storage medium on which a computer program is stored, and the computer program is used by a processor to execute the steps of the data synchronization method according to various embodiments of this specification described in the above "Example Method" section of this specification.
[0124] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this manual are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.
[0125] It should be understood that the specific examples in this document are only intended to help those skilled in the art better understand the implementation methods of this specification, rather than to limit the scope of this specification.
[0126] It can be understood that in the various implementations of this specification, the size of the serial number of each process does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the implementation methods of this specification.
[0127] It can be understood that the various embodiments described in this specification can be implemented individually or in combination, and the embodiments in this specification are not limited to this.
[0128] Unless otherwise indicated, all technical and scientific terms used in the embodiments of this specification have the same meaning as those commonly understood by those skilled in the art in the technical field of this specification. The terms used in this specification are only for the purpose of describing specific embodiments and are not intended to limit the scope of this specification. The term "and / or" used in this specification includes any and all combinations of one or more related listed items. The singular forms "a", "above", and "the" used in the embodiments of this specification and the appended claims are also intended to include plural forms unless the context clearly indicates otherwise.
[0129] It is understood that the processor in the embodiments of this specification can be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method embodiment can be completed by hardware integrated logic circuits in the processor or software instructions. The above processor can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. The various methods, steps, and logic block diagrams disclosed in the embodiments of this specification can be implemented or executed. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in the embodiments of this specification can be directly implemented and executed by a hardware decoding processor, or by a combination of hardware and software modules in the decoding processor. The software module can be located in a storage medium mature in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, etc. The storage medium is located in the memory, and the processor reads the information in the memory and, in conjunction with its hardware, completes the steps of the above method.
[0130] It will be understood that the memory in the embodiments of this specification may be a volatile memory or a non-volatile memory, or may include both volatile and non-volatile memories. Among them, the non-volatile memory may be a read-only memory (ROM), a programmable read-only memory (Programmable ROM, PROM), an erasable programmable read-only memory (Erasable PROM, EPROM), an electrically erasable programmable read-only memory (EEPROM) or a flash memory. The volatile memory may be a random access memory (RAM). It should be noted that the memory of the systems and methods described herein is intended to include, but is not limited to, these and any other suitable types of memory.
[0131] Those skilled in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this specification.
[0132] Those skilled in the art will clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described systems, devices and units can refer to the corresponding processes in the aforementioned method implementation methods and will not be repeated here.
[0133] In the several embodiments provided in this specification, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For example, the division of the units is merely a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0134] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of this embodiment.
[0135] In addition, each functional unit in each embodiment of this specification may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.
[0136] If the functions are implemented in the form of software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this specification, or the part that contributes to the prior art, or the part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the method described in each embodiment of this specification. The aforementioned storage medium includes various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0137] The above description is merely a specific embodiment of this specification, but the scope of protection of this specification is not limited thereto. Any changes or substitutions that can be easily conceived by a person skilled in the art within the technical scope disclosed in this specification should be included in the scope of protection of this specification. Therefore, the scope of protection of this specification should be based on the scope of protection of the claims.
Claims
1. A distributed system, characterized in that: include: A plurality of first nodes and a plurality of second nodes; wherein, The multiple first nodes keep the target data stored in the multiple first nodes consistent based on the consistency protocol; each of the second nodes corresponds to a target node in the multiple first nodes; The target node is used to synchronize the target data to a second node corresponding to the target node; The second node is used to respond to the task request based on the target data.
2. The system according to claim 1, characterized in that The first nodes store location information of each of the first nodes, where the location information is used to represent a geographical location where the first nodes are deployed; The second node is further configured to obtain location information of each of the first nodes from any of the first nodes, and establish a corresponding relationship with a neighboring target node according to the location information of each of the first nodes; The neighboring target node includes a first node whose geographical location of deployment is closest to the geographical location of deployment of the second node.
3. The system according to claim 1, characterized in that The first node and the second node store log indexes corresponding to previous data updates, the log indexes are used to identify data update messages, and the data update messages include incremental data of the target data after the data update; The target node synchronizes the target data to the second node corresponding thereto, specifically for: Sending a data update message corresponding to the first target log index to the second node, so that the second node updates the data according to the first target log index; The first target log index includes the log index after the first index in the target node, and the first index is the log index corresponding to the last data update in the second node.
4. The system according to claim 3, characterized in that The first node is further used to generate first snapshot information after multiple data updates; the first snapshot information includes target data in the first node at the time when the first snapshot information is generated; The target node synchronizes the target data to the second node corresponding thereto, specifically for: Sending a data update message corresponding to the second target log index and the most recently generated first snapshot information to the second node, so that the second node updates the data according to the first snapshot information and the second target log index; The second target log index includes the log index after the second index in the target node, and the second index is the log index corresponding to the last data update of the target node when the first snapshot information is generated.
5. The system according to claim 4, characterized in that The second node performs data updating according to the first snapshot information and the second target log index specifically for: saving target data included in the first snapshot information; The target data is updated according to the data update message corresponding to the second target log index.
6. The system according to claim 4, characterized in that The second node performs data updating according to the first target log index specifically for: Obtaining the first snapshot information most recently generated in the target node; Loading target data in the first snapshot information; The loaded target data is updated according to a data update message corresponding to a log index after the second index in the first target log index.
7. The system according to claim 4, characterized in that The first node is further configured to, after generating the first snapshot information, delete the log index saved when the first snapshot information is generated and the data update message corresponding to the log index.
8. The system according to claim 3, characterized in that The second node is further used to generate second snapshot information after multiple data updates; the second snapshot information includes the target data in the second node at the time when the second snapshot information is generated; The second node performs data updating according to the first target log index specifically for: Loading target data in the second snapshot information generated most recently; According to the data update message corresponding to the log index after the third index in the first target log index, updating the loaded target data; The third index is the log index corresponding to the last data update of the second node when the second snapshot information is generated.
9. The system according to claim 8, characterized in that The second node is further configured to, after generating the second snapshot information, delete the log index saved when the second snapshot information is generated and the data update message corresponding to the log index.
10. The system according to claim 3, characterized in that The second node is further configured to, after establishing a communication connection with the target node, send to the target node a log index corresponding to the last data update in the second node.
11. The system according to any one of claims 1 to 8, characterized in that: The consistency protocol includes a consensus algorithm based on leader election; The plurality of first nodes include a leader node and a plurality of follower nodes; The leader node is configured to push the updated target data to the follower nodes after updating the target data of the leader node; The follower node is used to update the target data stored in itself according to the target data pushed by the leader node.
12. A data synchronization method, characterized in that: Applied to a target node among a plurality of first nodes in a distributed system, the distributed system comprising a plurality of first nodes and a plurality of second nodes, the plurality of first nodes maintaining consistency of target data stored in the plurality of first nodes based on a consistency protocol; Each of the second nodes corresponds to a target node among the plurality of first nodes; The data synchronization method comprises: The target data is synchronized to a second node corresponding thereto, so that the second node can respond to a task request based on the target data.
13. An electronic device, characterized in that: include: Processor and memory; Wherein, the memory is connected to the processor, and the memory is used to store a computer program; The processor is used to implement the data synchronization method as claimed in claim 12 by running the computer program stored in the memory.
14. A storage medium, characterized in that: The storage medium stores a computer program, and when the computer program is executed by the processor, the data synchronization method according to claim 12 is implemented.
Citation Information
Patent Citations
Data updating method, device and system
CN110609844A
Distributed storage system and data processing method and related device thereof
CN113946287A
Data synchronization method and device of distributed system, equipment and medium
CN115174594A
Distributed system, data synchronization method, electronic equipment and storage medium
CN116340431A
Node device operation method, work status switching apparatus, node device, and medium
US20190342149A1
Cited By
Data synchronization method and device, server and program product
CN119946073A
Cloud service system, information update method, device, storage medium, and program product
WO2026149096A1
