Data synchronization method and apparatus, storage medium, and electronic device

By acquiring node data and hierarchical relationships from the Zookeeper cluster through the data synchronization process and directly transmitting them to the target cluster, the problems of complex operation and low efficiency in existing technologies are solved, achieving efficient and uninterrupted cluster data synchronization.

CN116366671BActive Publication Date: 2025-12-26HAIER YOUJIA INTELLIGENT TECH (BEIJING) CO LTD +2
View PDF 3 Cites 0 Cited by

Patent Information

Application Number
CN202310215846.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-02-28
Publication Date
2025-12-26
Estimated Expiration
2043-02-28

AI Technical Summary

Technical Problem

In existing technologies, Zookeeper cluster data synchronization is cumbersome and inefficient, cannot synchronize data to multiple clusters simultaneously, and restarts can affect the normal use of dependent services.

Method used

The data synchronization process traverses the data to be synchronized in the source cluster, obtains node data and hierarchical relationships, and establishes a connection based on the Internet Protocol address of the destination cluster, directly sending the node data and hierarchical relationships to the destination cluster, achieving efficient synchronization without restarting.

Benefits of technology

It achieves efficient, restart-free cluster data synchronization, enabling simultaneous synchronization of data from multiple clusters, avoiding service interruptions and simplifying the operation process.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116366671B_ABST
    Figure CN116366671B_ABST
Patent Text Reader

Abstract

The application discloses a data synchronization method and device, a storage medium and an electronic device, relates to the technical field of smart home, and the data synchronization method comprises the following steps: in the case that an instruction indicating that a source cluster synchronizes data to a target cluster is received, traversing to-be-synchronized data of the source cluster by a data synchronization process to obtain node data of a plurality of nodes in a tree structure corresponding to the to-be-synchronized data and a hierarchical relationship of the plurality of nodes, wherein a plurality of node data are respectively stored on the plurality of nodes; and the node data and the hierarchical relationship are sent to the target cluster based on the first connection relationship, so as to instruct the target cluster to create nodes according to the hierarchical relationship and store the node data into the nodes created by the target cluster. By adopting the technical scheme, the data synchronization of the source cluster is solved, and the operation is complex and the efficiency is low.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the field of communication, in particular to a data synchronization method and device, a storage medium and an electronic device. BACKGROUND

[0002] Data synchronization of a Zookeeper (zk for short) cluster is a scenario that is often encountered by operation and development personnel in their work.

[0003] Currently, if data of a source zk cluster is to be synchronized to a target cluster, the data file of the registered node of the source zk cluster needs to be copied down first, and then the data file is manually copied to a specified directory of the target cluster, and the data can be synchronized only by restarting the target zk cluster. If the target cluster wants to synchronize data of another cluster in the future, the above operations need to be repeated, and the data can be synchronized only by restarting the zk cluster during the synchronization process. The operation is complicated, and the data cannot be synchronized to multiple clusters at the same time. During the restart period, services dependent on the cluster cannot be normally used.

[0004] In the related art, the data synchronization of the source cluster is complicated and inefficient, and an effective solution has not yet been proposed. SUMMARY

[0005] Embodiments of the present application provide a data synchronization method and device, a storage medium and an electronic device to at least solve the problem that the data synchronization of the source cluster is complicated and inefficient in the related art.

[0006] According to an embodiment of the present application, a data synchronization method is provided, comprising: in the case where an instruction indicating that a source cluster synchronizes data to a target cluster is received, traversing, by a data synchronization process, to-be-synchronized data of the source cluster to obtain node data of a plurality of nodes in a tree structure corresponding to the to-be-synchronized data and a hierarchical relationship of the plurality of nodes, wherein a plurality of node data are respectively saved on the plurality of nodes; establishing a first connection relationship between the data synchronization process and the target cluster according to an Internet protocol address of the target cluster; and sending the node data and the hierarchical relationship to the target cluster based on the first connection relationship to instruct the target cluster to create nodes according to the hierarchical relationship and store the node data into the nodes created by the target cluster.

[0007] In an example embodiment, the data synchronization process traverses the to-be-synchronized data of the source cluster to obtain node data of a plurality of nodes of the to-be-synchronized data and a hierarchical relationship of the plurality of nodes, including: determining, by the data synchronization process, whether a next-level node of an i-th level node in a tree structure corresponding to the to-be-synchronized data exists, where i is a positive integer, 1≤i≤N, and N is a number of levels of the tree structure corresponding to the to-be-synchronized data; in a case where the next-level node of the i-th level node exists, storing a node name of the next-level node of the i-th level node into a to-be-recursed container, and determining node data and a hierarchical relationship of a first-level node to the i-th level node of the to-be-synchronized data.

[0008] In an example embodiment, after the data synchronization process determines whether the next-level node of the i-th level node in the tree structure corresponding to the to-be-synchronized data exists, the method further includes: in a case where the i-th level node is traversed by the data synchronization process, determining whether a node name exists in the to-be-recursed container, where the i-th level node includes one or more i-th level nodes; in a case where the node name does not exist in the to-be-recursed container, determining that the data synchronization process traverses from a first-level node in the tree structure to an N-th level node in the tree structure; in a case where the node name exists in the to-be-recursed container, the data synchronization process accesses a next-level node of the i-th level node based on the node name.

[0009] In an example embodiment, after the data synchronization process determines whether the next-level node of the i-th level node in the tree structure corresponding to the to-be-synchronized data exists, the method further includes: a storing step of storing, in a case where the next-level node of the i-th level node in the tree structure does not exist, node data and a hierarchical relationship of the first-level node to the i-th level node of the to-be-synchronized data into a to-be-created node container; and a loop of the storing step until node data and a hierarchical relationship of the first-level node to the N-th level node are stored into the to-be-created node container.

[0010] In an example embodiment, after the node data and the hierarchical relationship of the first-level node to the N-th level node are stored into the to-be-created node container, the method further includes: disconnecting a second connection relationship between the data synchronization process and the source cluster, and establishing a first connection relationship between the data synchronization process and a destination cluster according to an internet protocol address of the destination cluster; and sending, based on the first connection relationship, the node data and the hierarchical relationship of the first-level node to the N-th level node in the to-be-created node container to the destination cluster.

[0011] In an example embodiment, establishing the first connection relationship between the data synchronization process and the destination cluster according to the Internet protocol address of the destination cluster comprises: establishing a plurality of data synchronization threads in the data synchronization process according to the number of the destination cluster, wherein the number of the plurality of data synchronization threads is the same as the number of the destination cluster; and establishing the first connection relationship between the plurality of data synchronization threads and the plurality of destination clusters according to the Internet of Things addresses of the plurality of destination clusters, respectively.

[0012] In an example embodiment, establishing the first connection relationship between the data synchronization process and the destination cluster according to the Internet protocol address of the destination cluster comprises: obtaining a key corresponding to the destination cluster, and verifying the key; in a case where a verification result satisfies a first preset condition, obtaining an Internet protocol address of the destination cluster and a verification value of the destination cluster; determining an interface corresponding to the destination cluster according to the Internet protocol address and the verification value, and establishing the first connection relationship between the data synchronization process and the destination cluster through the interface.

[0013] According to another embodiment of the present application, a data synchronization device is further provided, comprising: a traversal module configured to, in a case where an instruction indicating that a source cluster synchronizes data to a destination cluster is received, traverse, through a data synchronization process, to-be-synchronized data of the source cluster to obtain node data of a plurality of nodes in a tree structure corresponding to the to-be-synchronized data and a hierarchical relationship of the plurality of nodes, wherein a plurality of node data are respectively saved on the plurality of nodes; a establishing module configured to establish a first connection relationship between the data synchronization process and the destination cluster according to an Internet protocol address of the destination cluster; and a sending module configured to send the node data and the hierarchical relationship to the destination cluster based on the first connection relationship to instruct the destination cluster to create nodes according to the hierarchical relationship and store the node data into the nodes created by the destination cluster.

[0014] According to still another aspect of the present application, a computer readable storage medium is further provided, and the computer readable storage medium stores a computer program, wherein the computer program is configured to execute the above-mentioned data synchronization method when running.

[0015] According to still another aspect of the present application, an electronic device is further provided, comprising a memory, a processor, and a computer program stored in the memory and capable of running on the processor, wherein the processor executes the above-mentioned data synchronization method through the computer program.

[0016] In the embodiment of the present application, in the case that the instruction indicating that the source cluster synchronizes data to the destination cluster is received, the data synchronization process traverses the to-be-synchronized data of the source cluster to obtain node data of a plurality of nodes in a tree structure corresponding to the to-be-synchronized data and a hierarchical relationship of the plurality of nodes, wherein a plurality of node data are respectively stored on the plurality of nodes; a first connection relationship between the data synchronization process and the destination cluster is established according to an Internet protocol address of the destination cluster; the node data and the hierarchical relationship are sent to the destination cluster based on the first connection relationship, to instruct the destination cluster to create nodes according to the hierarchical relationship and store the node data into the nodes created by the destination cluster; by using the above technical solution, the data synchronization of the source cluster is solved, and problems such as complex operation and low efficiency are solved; in the embodiment of the present application, the data synchronization process obtains the node data of the plurality of nodes and the hierarchical relationship of the plurality of nodes of the to-be-synchronized nodes by the traversal manner, and then the Internet protocol address of the destination cluster is input to the data synchronization process, so that the to-be-synchronized data can be synchronized to the destination cluster, and the efficiency is very high. BRIEF DESCRIPTION OF DRAWINGS

[0017] The accompanying drawings, which are incorporated herein and form a part of the specification, illustrate embodiments consistent with the present application and, together with the description, further serve to explain the principles of the application.

[0018] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the accompanying drawings needed to be used in the embodiments or prior art description will be briefly introduced. Obviously, for those skilled in the art, other drawings can also be obtained based on these drawings without creative labor.

[0019] Figure 1 Fig. 1 is a hardware environment schematic diagram of a data synchronization method according to an embodiment of the present application;

[0020] Figure 2 Fig. 2 is a flowchart of a data synchronization method according to an embodiment of the present application;

[0021] Figure 3 Fig. 3 is a schematic diagram of a data synchronization method according to an embodiment of the present application;

[0022] Figure 4 Fig. 4 is a structural block diagram (one) of a data synchronization device according to an embodiment of the present application;

[0023] Figure 5 Fig. 5 is a structural block diagram (two) of a data synchronization device according to an embodiment of the present application. DETAILED DESCRIPTION

[0024] In the following, the technical solutions in the embodiments of the present application will be described clearly and completely in conjunction with the drawings in the embodiments of the present application, so that those skilled in the art can better understand the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative work should fall within the scope of the present application.

[0025] It should be noted that the terms "first", "second", and the like in the specification and claims of the present application and the above-described drawings are used to distinguish similar objects, and do not necessarily indicate a specific order or a chronological sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device that includes a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but can include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0026] According to an aspect of the embodiments of the present application, a data synchronization method is provided. The data synchronization method is widely used in smart home, smart home, smart home device ecology, intelligence house ecology and other whole-house intelligent digital control application scenarios. Optionally, in the present embodiment, the above-mentioned data synchronization method can be applied to the hardware environment composed of terminal device 102 and server 104 as shown in Figure 1 As shown in Figure 1 The server 104 is connected with the terminal device 102 through the network, which can be used to provide services (such as application services, etc.) for the terminal or the client installed on the terminal, a database can be set on the server or independently of the server, which can be used to provide data storage services for the server 104, cloud computing and / or edge computing services can be configured on the server or independently of the server, which can be used to provide data operation services for the server 104.

[0027] The aforementioned network may include, but is not limited to, at least one of the following: wired network, wireless network. The aforementioned wired network may include, but is not limited to, at least one of the following: wide area network, metropolitan area network, local area network. The aforementioned wireless network may include, but is not limited to, at least one of the following: Wi-Fi (Wireless Fidelity), Bluetooth. The terminal device 102 may not be limited to PC, mobile phone, tablet computer, smart air conditioner, smart range hood, smart refrigerator, smart oven, smart stove, smart washing machine, smart water heater, smart washing equipment, smart dishwasher, smart projector, smart TV, smart clothes rack, smart curtains, smart audio-visual equipment, smart socket, smart speaker, smart speaker box, smart fresh air equipment, smart kitchen and bathroom equipment, smart bathroom equipment, smart robot vacuum cleaner, smart window cleaning robot, smart mopping robot, smart air purifier, smart steam oven, smart microwave oven, smart water heater, smart air purifier, smart water dispenser, smart door lock, etc.

[0028] This embodiment provides a data synchronization method applied to a computer terminal. Figure 2 This is a flowchart of a data synchronization method according to an embodiment of this application, which includes the following steps:

[0029] Step S202: Upon receiving an instruction to synchronize data from the source cluster to the destination cluster, the data synchronization process traverses the data to be synchronized in the source cluster to obtain the node data of multiple nodes in the tree structure corresponding to the data to be synchronized and the hierarchical relationship of the multiple nodes, wherein the multiple node data are stored on the multiple nodes respectively.

[0030] It should be noted that the data to be synchronized is of tree structure type, and the node data corresponding to the data to be synchronized is stored on the data nodes of the tree structure.

[0031] Step S204: Establish a first connection between the data synchronization process and the target cluster based on the Internet Protocol address of the target cluster;

[0032] Step S206: Based on the first connection relationship, send the node data and the hierarchical relationship to the destination cluster to instruct the destination cluster to create a node according to the hierarchical relationship and store the node data in the node created by the destination cluster.

[0033] By the above steps, in the case that an instruction indicating that a source cluster synchronizes data to a destination cluster is received, the data synchronization process traverses the to-be-synchronized data of the source cluster to obtain node data of a plurality of nodes in a tree structure corresponding to the to-be-synchronized data and a hierarchical relationship of the plurality of nodes, wherein a plurality of node data are respectively stored on the plurality of nodes; a first connection relationship between the data synchronization process and the destination cluster is established according to an Internet protocol address of the destination cluster; and the node data and the hierarchical relationship are sent to the destination cluster based on the first connection relationship, to instruct the destination cluster to create nodes according to the hierarchical relationship and store the node data into the nodes created by the destination cluster. The problems in the related art, such as complex operation and low efficiency, in data synchronization of a source cluster are solved. In the embodiment of the application, the data synchronization process obtains the node data of a plurality of nodes of a to-be-synchronized node and the hierarchical relationship of the plurality of nodes by traversal, and then the Internet protocol address of the destination cluster is input to the data synchronization process, so that the to-be-synchronized data can be synchronized to the destination cluster, which is very efficient.

[0034] In one example embodiment, the data synchronization process traverses the to-be-synchronized data of the source cluster to obtain node data of a plurality of nodes of the to-be-synchronized data and a hierarchical relationship of the plurality of nodes, including: determining, by the data synchronization process, whether an (i-1)th level node in a tree structure corresponding to the to-be-synchronized data exists, wherein i is a positive integer, 1≤i≤N, and N is a number of levels of the tree structure corresponding to the to-be-synchronized data; in the case that the (i-1)th level node exists, storing a node name of an (i+1)th level node of the (i-1)th level node into a to-be-recursed container, and determining node data and a hierarchical relationship of a 1st level node to the (i-1)th level node of the to-be-synchronized data.

[0035] Specifically, the data synchronization process traverses the tree structure of the source cluster, and determines whether each node in the traversal exists. In the case that each node exists, it is determined that the node is not a leaf node of the tree structure, i.e., the last node of the to-be-synchronized data has not been traversed, and a node name of a next level node of the (i-1)th level node is stored into the to-be-recursed container.

[0036] Optionally, the data synchronization process traverses the to-be-synchronized data of the source cluster to obtain node data of a plurality of nodes of the to-be-synchronized data and a hierarchical relationship of the plurality of nodes, including: the data synchronization process generally traverses the to-be-synchronized data of the source cluster; and the data synchronization process deeply traverses the to-be-synchronized data of the source cluster.

[0037] In an example embodiment, after determining, by the data synchronization process, whether the (i+1)th level node exists in the tree structure corresponding to the to-be-synchronized data, it is determined whether a node name exists in the to-be-recursed container in the case that the i th level node is traversed by the data synchronization process. The i th level node includes one or more i th level nodes. In the case that the node name does not exist in the to-be-recursed container, it is determined that the data synchronization process traverses from the 1st level node in the tree structure to the Nth level node in the tree structure. In the case that the node name exists in the to-be-recursed container, the data synchronization process accesses the (i+1)th level node based on the node name.

[0038] Optionally, in the case that the data synchronization process generally traverses the to-be-synchronized data of the source cluster, all nodes in the 1st level are traversed first, then all nodes in the 2nd level are traversed, and so on until all nodes in the Nth level are traversed.

[0039] In the embodiment of the application, in the case that each level of nodes is traversed, it is determined whether a node name exists in the to-be-recursed container. In the case that the node name does not exist in the to-be-recursed container, it is determined that the data synchronization process traverses from the 1st level node in the tree structure to the Nth level node in the tree structure, and then the traversal ends. In the case that the node name exists in the to-be-recursed container, the data synchronization process accesses the (i+1)th level node based on the node name, and continues to traverse the nodes according to the node name in the to-be-recursed container. Through the above embodiment, the hierarchical relationship of the nodes of the to-be-synchronized data and the node data contained in each node can be completely obtained.

[0040] In an example embodiment, after determining, by the data synchronization process, whether the (i+1)th level node exists in the tree structure corresponding to the to-be-synchronized data, a storage step is performed: in the case that the (i+1)th level node does not exist in the tree structure, the node data and the hierarchical relationship of the 1st level node to the i th level node of the to-be-synchronized data are stored in a to-be-created node container. The storage step is repeated until the node data and the hierarchical relationship of the 1st level node to the Nth level node are stored in the to-be-created node container.

[0041] For example, the Nth level node includes an N1th level node, an N2th level node, and an N3th level node. After the node data and the hierarchical relationship of the 1st level node to the N1th level node are stored in the to-be-created node container, the node data and the hierarchical relationship of the 1st level node to the N2th level node are also stored in the to-be-created node container, and so on until the node data and the hierarchical relationship of the 1st level node to the N3th level node are stored in the to-be-created node container, and the loop ends.

[0042] In one example embodiment, after storing the node data and hierarchical relationship of the first level node to the Nth level node in the to-be-created node container, the second connection relationship between the data synchronization process and the source cluster is disconnected, and the first connection relationship between the data synchronization process and the destination cluster is established according to the Internet protocol address of the destination cluster; the node data and hierarchical relationship of the first level node to the Nth level node in the to-be-created node container are sent to the destination cluster based on the first connection relationship.

[0043] That is, in the case where all nodes have been traversed to leaf nodes, the process is disconnected with the source cluster, and resources are released; then the process creates a first connection relationship according to the Internet protocol address of the destination cluster input by the user, and then sends the node data and hierarchical relationship of the first level node to the Nth level node in the to-be-created node container to the destination cluster based on the first connection relationship, and the destination cluster creates nodes according to the hierarchical relationship and stores the node data in the nodes created by the destination cluster, solving the problems in the related art that data synchronization of the source cluster is complex to operate and has low efficiency, etc. In the embodiment of the application, the data synchronization process obtains the node data of multiple nodes to be synchronized and the hierarchical relationship of the multiple nodes by traversing, and then inputs the Internet protocol address of the destination cluster into the data synchronization process, so that the to-be-synchronized data can be synchronized to the destination cluster, which is extremely efficient.

[0044] In one example embodiment, establishing the first connection relationship between the data synchronization process and the destination cluster according to the Internet protocol address of the destination cluster comprises: establishing multiple data synchronization threads in the data synchronization process according to the number of the destination clusters, wherein the number of the multiple data synchronization threads is the same as the number of the destination clusters; and establishing the first connection relationship between the multiple data synchronization threads and the multiple destination clusters according to the Internet protocol addresses of the multiple destination clusters.

[0045] It should be noted that the process creates the same number of threads as the number of Internet of Things addresses of the destination cluster input by the user to synchronize data, and the threads are executed in parallel, and the multiple threads are connected to the destination clusters, so that the destination clusters create nodes according to the hierarchical relationship, and after all threads are ended, the connection with the destination clusters is closed and resources are released, so that the synchronization of data is completed.

[0046] In an example embodiment, establishing the first connection relationship between the data synchronization process and the target cluster according to the Internet protocol address of the target cluster comprises: obtaining a key corresponding to the target cluster and verifying the key; in a case where a verification result satisfies a first preset condition, obtaining an Internet protocol address of the target cluster and a verification value of the target cluster; determining an interface corresponding to the target cluster according to the Internet protocol address and the verification value, and establishing the first connection relationship between the data synchronization process and the target cluster through the interface.

[0047] In the embodiment of the application, in order to enhance the security of information transmission, the data synchronization process needs to perform security verification on the target cluster before establishing the connection relationship with the target cluster. Specifically, a key corresponding to the target cluster is obtained and the key is verified. In a case where the verification is passed, an Internet protocol address of the target cluster and a verification value of the target cluster are obtained. An interface corresponding to the target cluster is determined according to the Internet protocol address and the verification value, and the first connection relationship between the data synchronization process and the target cluster is established through the interface. In a case where the verification is not passed, the connection relationship with the target cluster is refused to be established.

[0048] In order to better understand the process of the above data synchronization method, the implementation method flow of the above data synchronization is described below in combination with optional embodiments, but is not used to limit the technical scheme of the embodiments of the application.

[0049] In the embodiment, a data synchronization method is provided, Figure 3 is a schematic diagram of the data synchronization method according to the embodiment of the application, as Figure 3 shown, the specific steps are as follows:

[0050] Step S301: a connection relationship with a source cluster is established according to an Internet protocol address of the source cluster.

[0051] Step S302: to-be-synchronized data of the source cluster is obtained.

[0052] Step S303: node data corresponding to a current node is obtained by iteration.

[0053] Step S304: whether the current node has a next-level node is judged. In a case where the current node has the next-level node, step S305 is executed, otherwise, step S306 is executed.

[0054] Step S305: a node name of the next-level node is put into a node container to be recursively processed.

[0055] Step S306: node data and a hierarchical relationship of the current node are put into a node container to be created.

[0056] Step S307: determine whether all nodes of the level corresponding to the current node are traversed, if all nodes of the level corresponding to the current node are traversed, execute step S303, otherwise execute step S308;

[0057] Step S308: determine whether there is a node name in the container to be recursively traversed;

[0058] If there is, it means that there is data that has not been traversed to the root node, and the recursive traversal is continued, if there is no node name in the container, it means that all nodes have been traversed to the root node, then the process is closed, the connection with the source zk cluster is disconnected, and the resource is released.

[0059] Step S309: the process creates the same number of threads as the number of ip addresses of the destination cluster according to the purpose of synchronizing data, the threads are executed in parallel, and are connected to the destination cluster respectively;

[0060] Step S310: create nodes according to the hierarchical relationship;

[0061] Step S311: store the node data into the corresponding node;

[0062] Step S312: close the connection with the destination cluster, and release the resource.

[0063] According to the embodiment of the application, the user only needs to input the ip of the source zk cluster and the ip of the destination cluster into the program, without other cumbersome operations. Through the multi-thread mode, data synchronization can be performed on multiple clusters at the same time, and the efficiency is extremely high. Even during the use of the cluster, data synchronization operation can still be performed, without the need to restart the cluster, to realize hot synchronization, and without affecting the services relying on the cluster. After the scheme is implemented, the user only needs to maintain the input ip of the program during use.

[0064] Through the description of the above embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be realized by means of software and the necessary general hardware platform, of course, it can also be realized by hardware, but in many cases, the former is a better embodiment. Based on such understanding, the technical solutions of the application can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a plurality of instructions for making a terminal device (which can be a mobile phone, computer, server, or network device) execute the method of each embodiment of the application.

[0065] Figure 4 is a structural block diagram of a data synchronization device according to an embodiment of the application (one); as shown in Figure 4 , comprising:

[0066] The traversal module 42 is configured to, in response to receiving an instruction indicating that the source cluster synchronizes data to the destination cluster, traverse, by a data synchronization process, to-be-synchronized data of the source cluster to obtain node data of a plurality of nodes in a tree structure corresponding to the to-be-synchronized data and a hierarchical relationship of the plurality of nodes, wherein the plurality of node data are respectively stored in the plurality of nodes.

[0067] The establishment module 44 is configured to establish a first connection relationship between the data synchronization process and the destination cluster according to an Internet Protocol address of the destination cluster.

[0068] The sending module 46 is configured to send the node data and the hierarchical relationship to the destination cluster based on the first connection relationship, to instruct the destination cluster to create nodes according to the hierarchical relationship and store the node data into the nodes created by the destination cluster.

[0069] With the above device, in response to receiving an instruction indicating that the source cluster synchronizes data to the destination cluster, a data synchronization process is used to traverse to-be-synchronized data of the source cluster to obtain node data of a plurality of nodes in a tree structure corresponding to the to-be-synchronized data and a hierarchical relationship of the plurality of nodes, wherein the plurality of node data are respectively stored in the plurality of nodes; a first connection relationship between the data synchronization process and the destination cluster is established according to an Internet Protocol address of the destination cluster; and the node data and the hierarchical relationship are sent to the destination cluster based on the first connection relationship, to instruct the destination cluster to create nodes according to the hierarchical relationship and store the node data into the nodes created by the destination cluster, thereby solving the problems in the prior art that data synchronization of a source cluster is complex and inefficient, and in the embodiment of the present application, the data synchronization process obtains node data of a plurality of nodes of to-be-synchronized nodes and a hierarchical relationship of the plurality of nodes by traversal, and then the Internet Protocol address of the destination cluster is input to the data synchronization process, so that the to-be-synchronized data can be synchronized to the destination cluster, which is highly efficient.

[0070] In one example embodiment, the traversal module 42 is configured to determine, by the data synchronization process, whether a next-level node exists for an i-level node in the tree structure corresponding to the to-be-synchronized data, wherein i is a positive integer, 1≤i≤N, and N is a number of levels of the tree structure corresponding to the to-be-synchronized data; in response to determining that the next-level node exists for the i-level node, store a node name of the next-level node of the i-level node into a to-be-recursed container, and determine node data and a hierarchical relationship of a first-level node to the i-level node of the to-be-synchronized data.

[0071] In an example embodiment, the traversal module 42 is configured to determine whether there is a node name in the to-be-recursed container in the case that the i-th level node is traversed through the data synchronization process, wherein the i-th level node comprises one or more i-th level nodes; in the case that there is no node name in the to-be-recursed container, it is determined that the data synchronization process traverses from the first level node in the tree structure to the N-th level node in the tree structure; in the case that there is a node name in the to-be-recursed container, the data synchronization process accesses the next level node of the i-th level node based on the node name.

[0072] In an example embodiment, Figure 5 is a structural block diagram of a data synchronization device according to an embodiment of the present application (II); as shown in Figure 5 the storage module 52 is configured to perform a storage step: in the case that the i-th level node in the tree structure does not have a next level node, storing the node data and the hierarchical relationship of the first level node to the i-th level node of the to-be-synchronized data into the to-be-created node container; and repeating the storage step until the node data and the hierarchical relationship of the first level node to the N-th level node are stored into the to-be-created node container.

[0073] In an example embodiment, the sending module 46 is configured to disconnect the second connection relationship between the data synchronization process and the source cluster, and establish a first connection relationship between the data synchronization process and the destination cluster according to the Internet protocol address of the destination cluster; and send the node data and the hierarchical relationship of the first level node to the N-th level node in the to-be-created node container to the destination cluster based on the first connection relationship.

[0074] In an example embodiment, the establishment module 44 is configured to establish a plurality of data synchronization threads in the data synchronization process according to the number of the destination clusters, wherein the number of the plurality of data synchronization threads is the same as the number of the destination clusters; and establish a first connection relationship between the plurality of data synchronization threads and the plurality of destination clusters according to the Internet of Things addresses of the plurality of destination clusters, respectively.

[0075] In an example embodiment, the establishment module 44 is configured to obtain the key corresponding to the destination cluster, and verify the key; in the case that the verification result satisfies a first preset condition, obtain the Internet protocol address of the destination cluster and the verification value of the destination cluster; determine the interface corresponding to the destination cluster according to the Internet protocol address and the verification value, and establish a first connection relationship between the data synchronization process and the destination cluster through the interface.

[0076] The embodiment of the present application further provides a storage medium comprising a stored program, wherein the program performs any of the above methods when running.

[0077] Optionally, in the embodiment, the storage medium can be configured to store program code for performing the following steps:

[0078] S1, in the case where an instruction indicating that a source cluster synchronizes data to a destination cluster is received, traversing, by a data synchronization process, to-be-synchronized data of the source cluster to obtain node data of a plurality of nodes in a tree structure corresponding to the to-be-synchronized data and a hierarchical relationship of the plurality of nodes, wherein a plurality of node data are respectively stored on the plurality of nodes;

[0079] S2, establishing, according to an Internet protocol address of the destination cluster, a first connection relationship between the data synchronization process and the destination cluster;

[0080] S3, sending, based on the first connection relationship, the node data and the hierarchical relationship to the destination cluster, to instruct the destination cluster to create nodes according to the hierarchical relationship and store the node data into the nodes created by the destination cluster.

[0081] The embodiment of the present application further provides an electronic device comprising a memory and a processor, the memory storing a computer program, and the processor being configured to run the computer program to perform the steps in any of the above method embodiments.

[0082] Optionally, the electronic device can further comprise a transmission device and an input / output device, wherein the transmission device is connected to the processor, and the input / output device is connected to the processor.

[0083] Optionally, in the embodiment, the processor can be configured to perform the following steps by the computer program:

[0084] S1, in the case where an instruction indicating that a source cluster synchronizes data to a destination cluster is received, traversing, by a data synchronization process, to-be-synchronized data of the source cluster to obtain node data of a plurality of nodes in a tree structure corresponding to the to-be-synchronized data and a hierarchical relationship of the plurality of nodes, wherein a plurality of node data are respectively stored on the plurality of nodes;

[0085] S2, establishing, according to an Internet protocol address of the destination cluster, a first connection relationship between the data synchronization process and the destination cluster;

[0086] S3, sending the node data and the hierarchical relationship to the target cluster based on the first connection relationship, to instruct the target cluster to create nodes according to the hierarchical relationship and store the node data into the nodes created by the target cluster.

[0087] Optionally, in the embodiment, the storage medium can include, but is not limited to, a U disk, a read-only memory (ROM), a random access memory (RAM), a mobile hard disk, a magnetic disk or an optical disk, and various storage medium capable of storing program codes.

[0088] Optionally, specific examples in the embodiment can refer to the examples described in the above embodiments and optional implementation manners, and the embodiment will not be described here.

[0089] Obviously, those skilled in the art should understand that the modules or steps of the present application described above can be realized by general computing devices, which can be concentrated on a single computing device or distributed on a network composed of multiple computing devices, and can be realized by program codes executable by the computing devices, so that they can be stored in storage devices and executed by the computing devices, and in some cases, the steps shown or described can be executed in different order, or they can be manufactured into individual integrated circuit modules, or multiple modules or steps can be manufactured into a single integrated circuit module. Therefore, the present application is not limited to any specific combination of hardware and software.

[0090] The above only describes the preferred embodiments of the present application, and it should be pointed out that those skilled in the art can make several improvements and refinements without departing from the principles of the present application, and these improvements and refinements should also be considered as the protection scope of the present application.

Claims

1. A method of data synchronization, the method comprising: The method comprises the following steps: In the case of receiving an instruction indicating that a source cluster synchronizes data to a destination cluster, traversing, by a data synchronization process, to-be-synchronized data of the source cluster to obtain node data of a plurality of nodes in a tree structure corresponding to the to-be-synchronized data and a hierarchical relationship of the plurality of nodes, wherein a plurality of node data are respectively saved in the plurality of nodes; According to an Internet Protocol address of the destination cluster, establishing a first connection relationship between the data synchronization process and the destination cluster; Based on the first connection relationship, sending the node data and the hierarchical relationship to the destination cluster to instruct the destination cluster to create nodes according to the hierarchical relationship and store the node data into the nodes created by the destination cluster; Wherein, traversing, by a data synchronization process, to-be-synchronized data of the source cluster to obtain node data of a plurality of nodes of the to-be-synchronized data and a hierarchical relationship of the plurality of nodes, comprises: Determining, by the data synchronization process, whether a next-level node of an i-th level node in a tree structure corresponding to the to-be-synchronized data exists, wherein i is a positive integer, 1≤i≤N, and N is a number of levels of the tree structure corresponding to the to-be-synchronized data; In the case that the i-th level node has a next-level node, storing a node name of the next-level node of the i-th level node into a to-be-recursed container, and determining node data and a hierarchical relationship of a first-level node to the i-th level node of the to-be-synchronized data; In the case that the i-th level node in the tree structure does not have a next-level node, performing a storage step of storing node data and a hierarchical relationship of a first-level node to the i-th level node of the to-be-synchronized data into a to-be-created node container; Cycling the storage step until node data and a hierarchical relationship of a first-level node to an N-th level node are stored into the to-be-created node container; Based on the first connection relationship, sending node data and a hierarchical relationship of a first-level node to an N-th level node in the to-be-created node container to the destination cluster.

2. The data synchronization method of claim 1, wherein, After determining, by the data synchronization process, whether a next-level node of an i-th level node in a tree structure corresponding to the to-be-synchronized data exists, the method further comprises: In the case that the i-th level node has a next-level node, storing a node name of the next-level node of the i-th level node into a to-be-recursed container, and determining node data and a hierarchical relationship of a first-level node to the i-th level node of the to-be-synchronized data; In the case that the i-th level node in the tree structure does not have a next-level node, performing a storage step of storing node data and a hierarchical relationship of a first-level node to the i-th level node of the to-be-synchronized data into a to-be-created node container; Cycling the storage step until node data and a hierarchical relationship of a first-level node to an N-th level node are stored into the to-be-created node container; 3. The data synchronization method of claim 1, wherein, Based on the first connection relationship, sending node data and a hierarchical relationship of a first-level node to an N-th level node in the to-be-created node container to the destination cluster. After storing node data and a hierarchical relationship of a first-level node to an N-th level node into a to-be-created node container, the method further comprises: Disconnecting a second connection relationship between the data synchronization process and the source cluster, and establishing a first connection relationship between the data synchronization process and the destination cluster according to an Internet Protocol address of the destination cluster.

4. The data synchronization method of claim 1, wherein, The first connection relationship between the data synchronization process and the target cluster is established according to an Internet Protocol address of the target cluster, comprising: According to the number of the target cluster, a plurality of data synchronization threads are established in the data synchronization process, wherein the number of the plurality of data synchronization threads is the same as the number of the target cluster; According to the Internet of Things address of the plurality of target clusters, the first connection relationship between the plurality of data synchronization threads and the plurality of target clusters is established respectively.

5. The data synchronization method of claim 1, wherein, The first connection relationship between the data synchronization process and the target cluster is established according to an Internet Protocol address of the target cluster, comprising: Obtaining the key corresponding to the target cluster and verifying the key; In the case where the verification result meets the first preset condition, the Internet Protocol address of the target cluster and the verification value of the target cluster are obtained; According to the Internet Protocol address and the verification value, the interface corresponding to the target cluster is determined, and the first connection relationship between the data synchronization process and the target cluster is established through the interface.

6. A data synchronization apparatus, characterized by comprising: Comprising: The traversal module is configured to, in a case where an instruction indicating that a source cluster synchronizes data to a target cluster is received, traverse, through a data synchronization process, to-be-synchronized data of the source cluster, to obtain node data of a plurality of nodes in a tree structure corresponding to the to-be-synchronized data and a hierarchical relationship of the plurality of nodes, wherein a plurality of node data are respectively saved on the plurality of nodes; The establishment module is configured to establish a first connection relationship between the data synchronization process and the target cluster according to an Internet Protocol address of the target cluster; The sending module is configured to send the node data and the hierarchical relationship to the target cluster based on the first connection relationship, to instruct the target cluster to create nodes according to the hierarchical relationship and store the node data into the nodes created by the target cluster; The traversal module is further configured to determine, through the data synchronization process, whether an (i+1)th level node exists for an ith level node in the tree structure corresponding to the to-be-synchronized data, wherein i is a positive integer, 1≤i≤N, and N is a number of levels of the tree structure corresponding to the to-be-synchronized data; in a case where the (i+1)th level node exists for the ith level node, store a node name of the (i+1)th level node of the ith level node into a to-be-recursed container, and determine node data and a hierarchical relationship of a first level node to the ith level node of the to-be-synchronized data; The storage module is further configured to, in a case where the (i+1)th level node does not exist for the ith level node in the tree structure, perform a storage step of storing the node data and the hierarchical relationship of the first level node to the ith level node of the to-be-synchronized data into a to-be-created node container; and repeatedly perform the storage step until the node data and the hierarchical relationship of the first level node to the Nth level node are stored into the to-be-created node container; The sending module is further configured to send the node data and the hierarchical relationship of the first level node to the Nth level node in the to-be-created node container to the target cluster based on the first connection relationship.

7. A computer readable storage medium, characterized in that, The computer readable storage medium comprises a stored program, wherein the program performs the method in any one of claims 1 to 5 when executed. 8.An electronic device comprising a memory and a processor, the electronic device comprising: The memory stores a computer program, and the processor is configured to execute the method in any one of claims 1 to 5 by using the computer program.

Citation Information

Patent Citations

  • Data synchronization method, device and system and storage medium

    CN112835862A

  • Data synchronization method and device, equipment and medium

    CN115129676A

  • Performing a write-prioritized tree copy

    US20210042336A1