CN116366671A - Data synchronization method and device, storage medium and electronic device - Google Patents

Data synchronization method and device, storage medium and electronic device Download PDF

Info

Publication number
CN116366671A
CN116366671A CN202310215846.6A CN202310215846A CN116366671A CN 116366671 A CN116366671 A CN 116366671A CN 202310215846 A CN202310215846 A CN 202310215846A CN 116366671 A CN116366671 A CN 116366671A
Authority
CN
China
Prior art keywords
node
data
data synchronization
cluster
nodes
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202310215846.6A
Other languages
Chinese (zh)
Inventor
刘守凯
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Qingdao Haier Technology Co Ltd
Haier Smart Home Co Ltd
Haier Uplus Intelligent Technology Beijing Co Ltd
Original Assignee
Qingdao Haier Technology Co Ltd
Haier Smart Home Co Ltd
Haier Uplus Intelligent Technology Beijing Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Qingdao Haier Technology Co Ltd, Haier Smart Home Co Ltd, Haier Uplus Intelligent Technology Beijing Co Ltd filed Critical Qingdao Haier Technology Co Ltd
Priority to CN202310215846.6A priority Critical patent/CN116366671A/en
Publication of CN116366671A publication Critical patent/CN116366671A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04LTRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
    • H04L67/00Network arrangements or protocols for supporting network services or applications
    • H04L67/01Protocols
    • H04L67/10Protocols in which an application is distributed across nodes in the network
    • H04L67/1095Replication or mirroring of data, e.g. scheduling or transport for data synchronisation between network nodes
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2246Trees, e.g. B+trees
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Computer Networks & Wireless Communication (AREA)
  • Signal Processing (AREA)
  • Computing Systems (AREA)
  • Software Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The application discloses a data synchronization method and device, a storage medium and an electronic device, and relates to the technical field of smart families, wherein the data synchronization method comprises the following steps: under the condition that an instruction for indicating a source cluster to synchronize data to a target cluster is received, traversing data to be synchronized of the source cluster through a data synchronization process to acquire node data of a plurality of nodes in a tree structure corresponding to the data to be synchronized and a hierarchical relationship of the plurality of nodes, wherein the plurality of node data are respectively stored on the plurality of nodes; the node data and the hierarchical relationship are sent to the target cluster based on the first connection relationship, so that the target cluster is instructed to establish nodes according to the hierarchical relationship, and the node data are stored in the nodes established by the target cluster.

Description

Data synchronization method and device, storage medium and electronic device
Technical Field
The present invention relates to the field of communications, and in particular, to a data synchronization method and apparatus, a storage medium, and an electronic device.
Background
The data synchronization of a Zookeeper (zk for short) cluster is a scene which often occurs in operation and maintenance and development work.
At present, if data of one zk cluster is to be synchronized to another cluster, registered node data files of the source zk cluster are usually copied, then manually copied to a designated directory of a destination cluster, then the data can be synchronized by restarting the destination zk cluster, if the subsequent cluster wants to resynchronize the data of the other cluster, the operations are repeated, and the zk cluster is restarted in the synchronization process to synchronize the data, so that the operations are complicated, the data cannot be synchronized to a plurality of clusters at the same time, and the problems that services depending on the clusters cannot be normally used still occur during restarting are also caused.
Aiming at the problems of complex operation, low efficiency and the like in the data synchronization of the source clusters in the related technology, no effective solution is proposed yet.
Disclosure of Invention
The embodiment of the application provides a data synchronization method and device, a storage medium and an electronic device, which are used for at least solving the problems of complex operation, low efficiency and the like of data synchronization of a source cluster in the related technology.
According to an embodiment of the present application, there is provided a data synchronization method including: under the condition that an instruction for indicating a source cluster to synchronize data to a target cluster is received, traversing data to be synchronized of the source cluster through a data synchronization process to acquire node data of a plurality of nodes in a tree structure corresponding to the data to be synchronized and a hierarchical relationship of the plurality of nodes, wherein the plurality of node data are respectively stored on the plurality of nodes; establishing a first connection relation between the data synchronization process and the target cluster according to the 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 storing the node data into the nodes created by the target cluster.
In an exemplary embodiment, traversing the data to be synchronized of the source cluster by a data synchronization process to obtain node data of a plurality of nodes of the data to be synchronized and a hierarchical relationship of the plurality of nodes, including: determining whether an ith node in the tree structure corresponding to the data to be synchronized exists as a next node or not through the data synchronization process, wherein i is a positive integer, i is more than or equal to 1 and less than or equal to N, and N is the number of layers of the tree structure corresponding to the data to be synchronized; and storing the node name of the next-level node of the ith-level node into a container to be recursion under the condition that the next-level node exists in the ith-level node, and determining the node data and the hierarchical relationship from the 1 st-level node to the ith-level node of the data to be synchronized.
In an exemplary embodiment, after determining, by the data synchronization process, whether the ith level node in the tree structure corresponding to the data to be synchronized has a next level node, the method further includes: determining whether a node name exists in the container to be recursion under the condition that an ith level node is traversed through the data synchronization process, wherein the ith level node comprises: one or more i-th level nodes; determining traversing from a 1 st level node in the tree structure to an nth level node in the tree structure by the data synchronization process in the case that no node name exists in the container to be recursion; in the case that a node name exists in the container to be recursively, the data synchronization process accesses a next level node of the ith level node based on the node name.
In an exemplary embodiment, after determining, by the data synchronization process, whether the ith level node in the tree structure corresponding to the data to be synchronized has a next level node, the method further includes: the storage step: storing node data and a hierarchical relationship from the 1 st level node to the i th level node of the data to be synchronized into a node container to be created under the condition that the i th level node in the tree structure does not have a next level node; and cycling the storing step until the node data and the hierarchical relation from the 1 st hierarchical node to the N th hierarchical node are stored into the node container to be created.
In an exemplary embodiment, after storing the node data and the hierarchical relationship from the 1 st hierarchical node to the N-th hierarchical node into the node container to be created, the method further includes: disconnecting the second connection relation between the data synchronization process and the source cluster, and establishing the first connection relation between the data synchronization process and the destination cluster according to the Internet protocol address of the destination cluster; and transmitting node data and a hierarchical relationship from the 1 st hierarchical node to the N th hierarchical node in the node container to be created to the target cluster based on the first connection relationship.
In an exemplary embodiment, establishing a first connection relationship between the data synchronization process and the destination cluster according to an internet protocol address of the destination cluster includes: establishing a plurality of data synchronization threads in the data synchronization process according to the number of the target clusters, wherein the number of the plurality of data synchronization threads is the same as the number of the target clusters; and respectively establishing first connection relations between the plurality of data synchronization threads and the plurality of target clusters according to the Internet of things addresses of the plurality of target clusters.
In an exemplary embodiment, establishing a first connection relationship between the data synchronization process and the destination cluster according to an internet protocol address of the destination cluster includes: acquiring a key corresponding to the target cluster, and checking the key; under the condition that the verification result meets a first preset condition, acquiring an internet protocol address of the target cluster and a verification value of the target cluster; and determining an interface corresponding to the target cluster according to the Internet protocol address and the check value, and establishing a first connection relation between a data synchronization process and the target cluster through the interface.
According to another embodiment of the present application, there is also provided a data synchronization apparatus including: the system comprises a traversing module, a data synchronization module and a data synchronization module, wherein the traversing module is used for traversing the data to be synchronized of a source cluster through a data synchronization process under the condition of receiving an instruction for indicating the source cluster to synchronize the data to a target cluster so as to acquire node data of a plurality of nodes in a tree structure corresponding to the data to be synchronized and the hierarchical relationship of the plurality of nodes, wherein the plurality of node data are respectively stored on the plurality of nodes; the establishing module is used for establishing a first connection relation between the data synchronization process and the target cluster according to the Internet protocol address of the target cluster; and the sending module is used for sending the node data and the hierarchical relationship to the target cluster based on the first connection relationship so as to instruct the target cluster to create a node according to the hierarchical relationship and store the node data into the node created by the target cluster.
According to a further aspect of embodiments of the present application, there is also provided a computer readable storage medium having a computer program stored therein, wherein the computer program is configured to perform the above-described data synchronization method when run.
According to still another aspect of the embodiments of the present application, there is further provided an electronic device including a memory, a processor, and a computer program stored on the memory and executable on the processor, wherein the processor executes the data synchronization method described above through the computer program.
In the embodiment of the application, under the condition that an instruction for indicating a source cluster to synchronize data to a target cluster is received, traversing data to be synchronized of the source cluster through a data synchronization process to acquire node data of a plurality of nodes in a tree structure corresponding to the data to be synchronized and a hierarchical relationship of the plurality of nodes, wherein the plurality of node data are respectively stored on the plurality of nodes; establishing a first connection relation between the data synchronization process and the target cluster according to the Internet protocol address of the target cluster; transmitting the node data and the hierarchical relationship to the destination cluster based on the first connection relationship to instruct the destination cluster to create a node according to the hierarchical relationship, and storing the node data into the node created by the destination cluster; by adopting the technical scheme, the problems of complex operation, low efficiency and the like of the data synchronization of the source cluster are solved, and in the embodiment of the invention, the data synchronization process acquires the node data of a plurality of nodes of the node to be synchronized and the hierarchical relationship of the nodes in a traversing manner, so that the data synchronization process is transmitted into the Internet protocol address of the target cluster, and the data to be synchronized can be synchronized into the target cluster with extremely high efficiency.
Drawings
The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the application and together with the description, serve to explain the principles of the application.
In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings that are required to be used in the description of the embodiments or the prior art will be briefly described below, and it will be obvious to those skilled in the art that other drawings can be obtained from these drawings without inventive effort.
FIG. 1 is a schematic diagram of a hardware environment of a data synchronization method according to an embodiment of the present application;
FIG. 2 is a flow chart of a data synchronization method according to an embodiment of the present application;
FIG. 3 is a schematic diagram of a data synchronization method according to an embodiment of the present application;
FIG. 4 is a block diagram (one) of a data synchronization device according to an embodiment of the present application;
fig. 5 is a block diagram (ii) of a data synchronization device according to an embodiment of the present application.
Detailed Description
In order to make the present application solution better understood by those skilled in the art, the following description will be made in detail and with reference to the accompanying drawings in the embodiments of the present application, it is apparent that the described embodiments are only some embodiments of the present application, not all embodiments. All other embodiments, which can be made by one of ordinary skill in the art based on the embodiments herein without making any inventive effort, shall fall within the scope of the present application.
It should be noted that the terms "first," "second," and the like in the description and claims of the present application and the above figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that embodiments of the present application described herein may be implemented in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
According to one aspect of the embodiments of the present application, a data synchronization method is provided. The data synchronization method is widely applied to full-house intelligent digital control application scenes such as intelligent Home (Smart Home), intelligent Home equipment ecology, intelligent Home (Intelligence House) ecology and the like. Alternatively, in the present embodiment, the above-described data synchronization method may be applied to a hardware environment constituted by the terminal device 102 and the server 104 as shown in fig. 1. As shown in fig. 1, the server 104 is connected to the terminal device 102 through a network, and may be used to provide services (such as application services and the like) for a terminal or a client installed on the terminal, a database may be set on the server or independent of the server, for providing data storage services for the server 104, and cloud computing and/or edge computing services may be configured on the server or independent of the server, for providing data computing services for the server 104.
The network may include, but is not limited to, at least one of: wired network, wireless network. The wired network may include, but is not limited to, at least one of: a wide area network, a metropolitan area network, a local area network, and the wireless network may include, but is not limited to, at least one of: WIFI (Wireless Fidelity ), bluetooth. The terminal device 102 may not be limited to a PC, a mobile phone, a tablet computer, an intelligent air conditioner, an intelligent smoke machine, an intelligent refrigerator, an intelligent oven, an intelligent cooking range, an intelligent washing machine, an intelligent water heater, an intelligent washing device, an intelligent dish washer, an intelligent projection device, an intelligent television, an intelligent clothes hanger, an intelligent curtain, an intelligent video, an intelligent socket, an intelligent sound box, an intelligent fresh air device, an intelligent kitchen and toilet device, an intelligent bathroom device, an intelligent sweeping robot, an intelligent window cleaning robot, an intelligent mopping robot, an intelligent air purifying device, an intelligent steam box, an intelligent microwave oven, an intelligent kitchen appliance, an intelligent purifier, an intelligent water dispenser, an intelligent door lock, and the like.
In this embodiment, a data synchronization method is provided and applied to a computer terminal, and fig. 2 is a flowchart of the data synchronization method according to an embodiment of the present application, where the flowchart includes the following steps:
step S202, under the condition that an instruction for indicating a source cluster to synchronize data to a target cluster is received, traversing data to be synchronized of the source cluster through a data synchronization process to acquire node data of a plurality of nodes in a tree structure corresponding to the data to be synchronized and a hierarchical relationship of the plurality of nodes, wherein the plurality of node data are respectively stored on the plurality of nodes;
it should be noted that, the data type of the data to be synchronized is a tree structure type, and the node data corresponding to the data to be synchronized is stored on the data nodes of the tree structure.
Step S204, a first connection relation between the data synchronization process and the target cluster is established according to the Internet protocol address of the target cluster;
and step S206, 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 the node data is stored in the nodes created by the target cluster.
Under the condition that an instruction for indicating a source cluster to synchronize data to a target cluster is received, traversing data to be synchronized of the source cluster through a data synchronization process to acquire node data of a plurality of nodes in a tree structure corresponding to the data to be synchronized and a hierarchical relationship of the plurality of nodes, wherein the plurality of node data are respectively stored on the plurality of nodes; establishing a first connection relation between the data synchronization process and the target cluster according to the Internet protocol address of the target cluster; the node data and the hierarchical relationship are sent to the target cluster based on the first connection relationship, so that the target cluster is instructed to create nodes according to the hierarchical relationship, the node data are stored in the nodes created by the target cluster, the problems that in the related technology, the source cluster is complicated in operation, low in efficiency and the like exist in data synchronization are solved, in the embodiment of the invention, the data synchronization process acquires the node data of a plurality of nodes of the node to be synchronized and the hierarchical relationship of the plurality of nodes in a traversing mode, and further transmits the internet protocol address of the target cluster to the data synchronization process, so that the data to be synchronized can be synchronized into the target cluster, and the efficiency is extremely high.
In an exemplary embodiment, traversing the data to be synchronized of the source cluster by a data synchronization process to obtain node data of a plurality of nodes of the data to be synchronized and a hierarchical relationship of the plurality of nodes, including: determining whether an ith node in the tree structure corresponding to the data to be synchronized exists as a next node or not through the data synchronization process, wherein i is a positive integer, i is more than or equal to 1 and less than or equal to N, and N is the number of layers of the tree structure corresponding to the data to be synchronized; and storing the node name of the next-level node of the ith-level node into a container to be recursion under the condition that the next-level node exists in the ith-level node, and determining the node data and the hierarchical relationship from the 1 st-level node to the ith-level node of the data to be synchronized.
Specifically, traversing the tree structure of the source cluster through a data synchronization process, determining whether each traversed node has a next level node, and under the condition that each node has the next level node, indicating that the traversed node is not a leaf node of the tree structure, namely, the traversed node is not traversed to the last node of the data to be synchronized, and further storing the node name of the next level node of the ith level node into a container to be recursion.
Optionally, traversing the data to be synchronized of the source cluster through a data synchronization process to obtain node data of a plurality of nodes of the data to be synchronized and a hierarchical relationship of the plurality of nodes, including: the data to be synchronized of the source cluster is traversed in a generalized mode through a data synchronization process; and deeply traversing the data to be synchronized of the source cluster through a data synchronization process.
In an exemplary embodiment, after determining, by the data synchronization process, whether an ith level node in the tree structure corresponding to the data to be synchronized has a next level node, determining, in a case that the ith level node is traversed by the data synchronization process, whether the node name exists in the container to be recursively, where the ith level node includes: one or more i-th level nodes; determining traversing from a 1 st level node in the tree structure to an nth level node in the tree structure by the data synchronization process in the case that no node name exists in the container to be recursion; in the case that a node name exists in the container to be recursively, the data synchronization process accesses a next level node of the ith level node based on the node name.
Optionally, in the case of broadly traversing the data to be synchronized of the source cluster through the data synchronization process, all nodes of the 1 st level are traversed, and then all nodes … … of the 2 nd level are traversed.
In the embodiment of the invention, under the condition that the nodes of each level are traversed, determining whether node names exist in the container to be recursion, and under the condition that the node names do not exist in the container to be recursion, traversing from the 1 st level node in the tree structure to the N th level node in the tree structure through the data synchronization process is determined, and then finishing the traversing; and under the condition that the node names exist in the container to be recursion, the data synchronization process accesses the next-level node of the ith-level node based on the node names, and continues to traverse the nodes according to the node names in the container to be recursion. By the embodiment, the hierarchical relationship of the nodes of the data to be synchronized and the node data contained in each node can be completely acquired.
In an exemplary embodiment, after determining, by the data synchronization process, whether the ith level node in the tree structure corresponding to the data to be synchronized has a next level node, the storing step includes: storing node data and a hierarchical relationship from the 1 st level node to the i th level node of the data to be synchronized into a node container to be created under the condition that the i th level node in the tree structure does not have a next level node; and cycling the storing step until the node data and the hierarchical relation from the 1 st hierarchical node to the N th hierarchical node are stored into the node container to be created.
For example, the nth level node includes: after the node data and the hierarchical relation from the 1 st level node to the N1 st level node are stored in the node container to be created, the node data and the hierarchical relation from the 1 st level node to the N2 nd level node are also stored in the node container to be created until the node data and the hierarchical relation from the 1 st level node to the N3 rd level node are stored in the node container to be created, and the cycle is ended.
In an exemplary embodiment, after storing node data and a hierarchical relationship from a 1 st hierarchical node to the nth hierarchical node in a node container to be created, 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 transmitting node data and a hierarchical relationship from the 1 st hierarchical node to the N th hierarchical node in the node container to be created to the target cluster based on the first connection relationship.
That is, in the case that all nodes have traversed to the leaf node, the process is closed to connect with the source cluster, and the resource is released; and then the process creates a first connection relation according to the ip of the destination cluster needing to synchronize data, and further sends the node data and the hierarchical relation from the 1 st hierarchical node to the N th hierarchical node in the node container to be created to the destination cluster based on the first connection relation, the destination cluster creates nodes according to the hierarchical relation, and stores the node data into the nodes created by the destination cluster, so that the problems of complex operation, low efficiency and the like in the data synchronization of the source cluster in the related technology are solved.
In an exemplary embodiment, establishing a first connection relationship between the data synchronization process and the destination cluster according to an internet protocol address of the destination cluster includes: establishing a plurality of data synchronization threads in the data synchronization process according to the number of the target clusters, wherein the number of the plurality of data synchronization threads is the same as the number of the target clusters; and respectively establishing first connection relations between the plurality of data synchronization threads and the plurality of target clusters according to the Internet of things addresses of the plurality of target clusters.
The process creates the same number of threads according to the number of the internet of things addresses of the target clusters needing to synchronize data, which are input by the user, the threads are executed in parallel, the threads are respectively connected with the target clusters, so that the target clusters create nodes according to the hierarchical relation, after all the threads are finished, the connection with the target clusters is closed, resources are released, and the data synchronization can be completed.
In an exemplary embodiment, establishing a first connection relationship between the data synchronization process and the destination cluster according to an internet protocol address of the destination cluster includes: acquiring a key corresponding to the target cluster, and checking the key; under the condition that the verification result meets a first preset condition, acquiring an internet protocol address of the target cluster and a verification value of the target cluster; and determining an interface corresponding to the target cluster according to the Internet protocol address and the check value, and establishing a first connection relation between a data synchronization process and the target cluster through the interface.
In the embodiment of the invention, 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, and the method is specific in that: acquiring a key corresponding to the target cluster, checking the key, and acquiring an internet protocol address of the target cluster and a check value of the target cluster under the condition that the verification is passed; determining an interface corresponding to the target cluster according to the Internet protocol address and the check value, and establishing a first connection relation between a data synchronization process and the target cluster through the interface; and refusing to establish the connection relation of the target cluster under the condition that the verification is not passed.
In order to better understand the process of the data synchronization method, the following description is provided with reference to an optional embodiment to describe the flow of the method for implementing data synchronization, but the method is not limited to the technical solution of the embodiment of the present application.
In this embodiment, a data synchronization method is provided, and fig. 3 is a schematic diagram of the data synchronization method according to an embodiment of the present application, as shown in fig. 3, specifically including the following steps:
step S301: establishing a connection relation with the source cluster according to the Internet protocol address of the source cluster;
step S302: acquiring data to be synchronized of a source cluster;
step S303: traversing to obtain node data corresponding to the current node;
step S304: judging whether the current node has a next level node, executing the step S305 under the condition that the current node has the next level node, otherwise executing the step S306;
step S305: the node name of the next level node is put into a node container to be recursion;
step S306: the node data and the hierarchical relation of the current node are put into a node container to be created;
step S307: determining whether all nodes of the hierarchy corresponding to the current node are traversed, executing step S303 when all nodes of the hierarchy corresponding to the current node are traversed, otherwise executing step S308;
step S308: determining whether a node name exists in the container to be recursively;
if so, continuing to carry out recursive traversal, if the data which is not traversed to the root node exists, and if the container has no node name, and if all the nodes are traversed to the root node, closing the connection between the process and the source zk cluster, and releasing the resources.
Step S309: the process creates the threads with the same number according to the number of ip addresses of the target clusters needing synchronous data, the threads execute in parallel, and the threads are respectively connected with the target clusters;
step S310: creating nodes according to the hierarchical relationship;
step S311: storing the node data into the corresponding nodes;
step S312: and closing the connection with the target cluster and releasing the resource.
According to the embodiment of the invention, a user only needs to transmit the ip of the source zk cluster and the ip of the target cluster to the program, and other complicated operations are not needed. The data synchronization can be carried out on a plurality of clusters simultaneously in a multithreading mode, and the efficiency is extremely high. Even during the use of the cluster, the data synchronization operation can be performed, the cluster is not required to be restarted, the thermal synchronization is realized, and the service depending on the cluster is not influenced. After the scheme is landed, a user only needs to maintain the ip of the incoming program when in use.
From the description of the above embodiments, it will be clear to a person skilled in the art that the method according to the above embodiments may be implemented by means of software plus the necessary general hardware platform, but of course also by means of hardware, but in many cases the former is a preferred embodiment. Based on such understanding, the technical solution of the present application may be embodied essentially or in a part contributing to the prior art in the form of a software product stored in a storage medium (such as ROM/RAM, magnetic disk, optical disk), comprising several instructions for causing a terminal device (which may be a mobile phone, a computer, a server, or a network device, etc.) to perform the method of the embodiments of the present application.
FIG. 4 is a block diagram (one) of a data synchronization device according to an embodiment of the present application; as shown in fig. 4, includes:
the traversing module 42 is configured to, when receiving an instruction indicating that a source cluster synchronizes data to a destination cluster, traverse data to be synchronized of the source cluster through a data synchronization process to obtain node data of a plurality of nodes in a tree structure corresponding to the data to be synchronized and a hierarchical relationship of the plurality of nodes, where the plurality of node data are respectively stored on the plurality of nodes;
an establishing module 44, 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;
a sending module 46, configured to send the node data and the hierarchical relationship to the destination cluster based on the first connection relationship, so as to instruct the destination cluster to create a node according to the hierarchical relationship, and store the node data into the node created by the destination cluster.
By the device, under the condition that an instruction for indicating a source cluster to synchronize data to a target cluster is received, traversing the data to be synchronized of the source cluster through a data synchronization process to acquire node data of a plurality of nodes in a tree structure corresponding to the data to be synchronized and the hierarchical relationship of the plurality of nodes, wherein the plurality of node data are respectively stored on the plurality of nodes; establishing a first connection relation between the data synchronization process and the target cluster according to the Internet protocol address of the target cluster; the node data and the hierarchical relationship are sent to the target cluster based on the first connection relationship, so that the target cluster is instructed to create nodes according to the hierarchical relationship, the node data are stored in the nodes created by the target cluster, the problems that in the related technology, the source cluster is complicated in operation, low in efficiency and the like exist in data synchronization are solved, in the embodiment of the invention, the data synchronization process acquires the node data of a plurality of nodes of the node to be synchronized and the hierarchical relationship of the plurality of nodes in a traversing mode, and further transmits the internet protocol address of the target cluster to the data synchronization process, so that the data to be synchronized can be synchronized into the target cluster, and the efficiency is extremely high.
In an exemplary embodiment, the traversing module 42 is configured to determine, through the data synchronization process, whether a next level node exists in an ith level node in a tree structure corresponding to the data to be synchronized, where i is a positive integer, i is greater than or equal to 1 and less than or equal to N, and N is a level number of the tree structure corresponding to the data to be synchronized; and storing the node name of the next-level node of the ith-level node into a container to be recursion under the condition that the next-level node exists in the ith-level node, and determining the node data and the hierarchical relationship from the 1 st-level node to the ith-level node of the data to be synchronized.
In an exemplary embodiment, the traversing module 42 is configured to determine whether a node name exists in the container to be recursively when an ith level node is traversed through the data synchronization process, where the ith level node includes: one or more i-th level nodes; determining traversing from a 1 st level node in the tree structure to an nth level node in the tree structure by the data synchronization process in the case that no node name exists in the container to be recursion; in the case that a node name exists in the container to be recursively, the data synchronization process accesses a next level node of the ith level node based on the node name.
In one exemplary embodiment, fig. 5 is a block diagram (ii) of a data synchronization apparatus according to an embodiment of the present application; as shown in fig. 5, includes: a storage module 52 for performing the storage steps of: storing node data and a hierarchical relationship from the 1 st level node to the i th level node of the data to be synchronized into a node container to be created under the condition that the i th level node in the tree structure does not have a next level node; and cycling the storing step until the node data and the hierarchical relation from the 1 st hierarchical node to the N th hierarchical node are stored into the node container to be created.
In an exemplary embodiment, the sending module 46 is configured to disconnect the second connection relationship between the data synchronization process and the source cluster, and establish the first connection relationship between the data synchronization process and the destination cluster according to the internet protocol address of the destination cluster; and transmitting node data and a hierarchical relationship from the 1 st hierarchical node to the N th hierarchical node in the node container to be created to the target cluster based on the first connection relationship.
In an exemplary embodiment, the establishing 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, where the number of the plurality of data synchronization threads is the same as the number of the destination clusters; and respectively establishing first connection relations between the plurality of data synchronization threads and the plurality of target clusters according to the Internet of things addresses of the plurality of target clusters.
In an exemplary embodiment, the establishing module 44 is configured to obtain a key corresponding to the destination cluster, and verify the key; under the condition that the verification result meets a first preset condition, acquiring an internet protocol address of the target cluster and a verification value of the target cluster; and determining an interface corresponding to the target cluster according to the Internet protocol address and the check value, and establishing a first connection relation between a data synchronization process and the target cluster through the interface.
Embodiments of the present application also provide a storage medium including a stored program, wherein the program performs the method of any one of the above when run.
Alternatively, in the present embodiment, the above-described storage medium may be configured to store program code for performing the steps of:
s1, under the condition that an instruction for indicating a source cluster to synchronize data to a target cluster is received, traversing data to be synchronized of the source cluster through a data synchronization process to acquire node data of a plurality of nodes in a tree structure corresponding to the data to be synchronized and a hierarchical relationship of the plurality of nodes, wherein the plurality of node data are respectively stored on the plurality of nodes;
s2, establishing a first connection relation between the data synchronization process and the target cluster according to the Internet protocol address of the target cluster;
and S3, transmitting the node data and the hierarchical relationship to the target cluster based on the first connection relationship so as to instruct the target cluster to create a node according to the hierarchical relationship, and storing the node data into the node created by the target cluster.
Embodiments of the present application also provide an electronic device comprising a memory having a computer program stored therein and a processor arranged to run the computer program to perform the steps of any of the method embodiments described above.
Optionally, the electronic apparatus may further include a transmission device and an input/output device, where the transmission device is connected to the processor, and the input/output device is connected to the processor.
Alternatively, in the present embodiment, the above-described processor may be configured to execute the following steps by a computer program:
s1, under the condition that an instruction for indicating a source cluster to synchronize data to a target cluster is received, traversing data to be synchronized of the source cluster through a data synchronization process to acquire node data of a plurality of nodes in a tree structure corresponding to the data to be synchronized and a hierarchical relationship of the plurality of nodes, wherein the plurality of node data are respectively stored on the plurality of nodes;
s2, establishing a first connection relation between the data synchronization process and the target cluster according to the Internet protocol address of the target cluster;
and S3, transmitting the node data and the hierarchical relationship to the target cluster based on the first connection relationship so as to instruct the target cluster to create a node according to the hierarchical relationship, and storing the node data into the node created by the target cluster.
Alternatively, in the present embodiment, the storage medium may include, but is not limited to: a U-disk, a Read-Only Memory (ROM), a random access Memory (Random Access Memory, RAM), a removable hard disk, a magnetic disk, or an optical disk, or other various media capable of storing program codes.
Alternatively, specific examples in this embodiment may refer to examples described in the foregoing embodiments and optional implementations, and this embodiment is not described herein.
It will be appreciated by those skilled in the art that the modules or steps of the application described above may be implemented in a general purpose computing device, they may be centralized on a single computing device, or distributed across a network of computing devices, or they may alternatively be implemented in program code executable by computing devices, such that they may be stored in a memory device for execution by the computing devices and, in some cases, the steps shown or described may be performed in a different order than what is shown or described, or they may be implemented as individual integrated circuit modules, or as individual integrated circuit modules. Thus, the present application is not limited to any specific combination of hardware and software.
The foregoing is merely a preferred embodiment of the present application and it should be noted that modifications and adaptations to those skilled in the art may be made without departing from the principles of the present application and are intended to be comprehended within the scope of the present application.

Claims (10)

1. A method of data synchronization, comprising:
under the condition that an instruction for indicating a source cluster to synchronize data to a target cluster is received, traversing data to be synchronized of the source cluster through a data synchronization process to acquire node data of a plurality of nodes in a tree structure corresponding to the data to be synchronized and a hierarchical relationship of the plurality of nodes, wherein the plurality of node data are respectively stored on the plurality of nodes;
establishing a first connection relation between the data synchronization process and the target cluster according to the 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 storing the node data into the nodes created by the target cluster.
2. The data synchronization method according to claim 1, wherein traversing the data to be synchronized of the source cluster by a data synchronization process to obtain node data of a plurality of nodes of the data to be synchronized and a hierarchical relationship of the plurality of nodes comprises:
determining whether an ith node in the tree structure corresponding to the data to be synchronized exists as a next node or not through the data synchronization process, wherein i is a positive integer, i is more than or equal to 1 and less than or equal to N, and N is the number of layers of the tree structure corresponding to the data to be synchronized;
and storing the node name of the next-level node of the ith-level node into a container to be recursion under the condition that the next-level node exists in the ith-level node, and determining the node data and the hierarchical relationship from the 1 st-level node to the ith-level node of the data to be synchronized.
3. The data synchronization method according to claim 2, wherein after determining, by the data synchronization process, whether a next level node exists in an i-th level node in a tree structure corresponding to the data to be synchronized, the method further comprises:
determining whether a node name exists in the container to be recursion under the condition that an ith level node is traversed through the data synchronization process, wherein the ith level node comprises: one or more i-th level nodes;
determining traversing from a 1 st level node in the tree structure to an nth level node in the tree structure by the data synchronization process in the case that no node name exists in the container to be recursion; in the case that a node name exists in the container to be recursively, the data synchronization process accesses a next level node of the ith level node based on the node name.
4. The data synchronization method according to claim 2, wherein after determining, by the data synchronization process, whether a next level node exists in an i-th level node in a tree structure corresponding to the data to be synchronized, the method further comprises:
the storage step: in case that the i-th level node in the tree structure does not have a next level node,
storing node data and a hierarchical relation from the 1 st level node to the i-th level node of the data to be synchronized into a node container to be created;
and cycling the storing step until the node data and the hierarchical relation from the 1 st hierarchical node to the N th hierarchical node are stored into the node container to be created.
5. The data synchronization method according to claim 4, wherein after storing node data and hierarchical relationships of 1 st-level nodes to the N-th-level nodes into a node container to be created, the method further comprises:
disconnecting the second connection relation between the data synchronization process and the source cluster, and establishing the first connection relation between the data synchronization process and the destination cluster according to the Internet protocol address of the destination cluster;
and transmitting node data and a hierarchical relationship from the 1 st hierarchical node to the N th hierarchical node in the node container to be created to the target cluster based on the first connection relationship.
6. The method according to claim 1, wherein establishing a first connection relationship between the data synchronization process and the destination cluster according to an 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 target clusters, wherein the number of the plurality of data synchronization threads is the same as the number of the target clusters;
and respectively establishing first connection relations between the plurality of data synchronization threads and the plurality of target clusters according to the Internet of things addresses of the plurality of target clusters.
7. The method according to claim 1, wherein establishing a first connection relationship between the data synchronization process and the destination cluster according to an internet protocol address of the destination cluster comprises:
acquiring a key corresponding to the target cluster, and checking the key;
under the condition that the verification result meets a first preset condition, acquiring an internet protocol address of the target cluster and a verification value of the target cluster;
and determining an interface corresponding to the target cluster according to the Internet protocol address and the check value, and establishing a first connection relation between a data synchronization process and the target cluster through the interface.
8. A data synchronization device, comprising:
the system comprises a traversing module, a data synchronization module and a data synchronization module, wherein the traversing module is used for traversing the data to be synchronized of a source cluster through a data synchronization process under the condition of receiving an instruction for indicating the source cluster to synchronize the data to a target cluster so as to acquire node data of a plurality of nodes in a tree structure corresponding to the data to be synchronized and the hierarchical relationship of the plurality of nodes, wherein the plurality of node data are respectively stored on the plurality of nodes;
the establishing module is used for establishing a first connection relation between the data synchronization process and the target cluster according to the Internet protocol address of the target cluster;
and the sending module is used for sending the node data and the hierarchical relationship to the target cluster based on the first connection relationship so as to instruct the target cluster to create a node according to the hierarchical relationship and store the node data into the node created by the target cluster.
9. A computer readable storage medium, characterized in that the computer readable storage medium comprises a stored program, wherein the program when run performs the method of any of the preceding claims 1 to 7.
10. An electronic device comprising a memory and a processor, characterized in that the memory has stored therein a computer program, the processor being arranged to execute the method according to any of the claims 1 to 7 by means of the computer program.
CN202310215846.6A 2023-02-28 2023-02-28 Data synchronization method and device, storage medium and electronic device Pending CN116366671A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202310215846.6A CN116366671A (en) 2023-02-28 2023-02-28 Data synchronization method and device, storage medium and electronic device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202310215846.6A CN116366671A (en) 2023-02-28 2023-02-28 Data synchronization method and device, storage medium and electronic device

Publications (1)

Publication Number Publication Date
CN116366671A true CN116366671A (en) 2023-06-30

Family

ID=86913039

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202310215846.6A Pending CN116366671A (en) 2023-02-28 2023-02-28 Data synchronization method and device, storage medium and electronic device

Country Status (1)

Country Link
CN (1) CN116366671A (en)

Similar Documents

Publication Publication Date Title
CN114697150B (en) Command issuing method and device, storage medium and electronic device
CN116107975A (en) Control method and device of equipment, storage medium and electronic device
CN116366671A (en) Data synchronization method and device, storage medium and electronic device
CN116033006A (en) Data processing method, system, storage medium and electronic device
CN116027937A (en) Rendering method and device of component to be edited, storage medium and electronic device
CN116225834A (en) Alarm information sending method and device, storage medium and electronic device
CN116361155A (en) Method and device for testing software development kit, storage medium and electronic device
CN115296948B (en) Scene information updating method and device, storage medium and electronic device
CN115174296B (en) Equipment function access method and device, storage medium and electronic device
CN115296947B (en) Control command response method and device, storage medium and electronic device
CN115314245B (en) Authority management method, system, storage medium and electronic device
CN116301767A (en) Interface file generation method and device, storage medium and electronic device
CN115296958B (en) Distribution method and device of equipment control tasks, storage medium and electronic device
CN114697345B (en) Information updating method and device, storage medium and electronic device
CN115002014B (en) Method and device for determining test result, storage medium and electronic device
CN117749843A (en) Scene triggering method and device, storage medium and electronic device
CN115174382B (en) Equipment upgrading method, storage medium and electronic device
CN116561019A (en) Cache updating method and device, storage medium and electronic device
CN117896848A (en) Binding method and device of intelligent equipment, storage medium and electronic device
CN116346686A (en) Information transmission method and device, storage medium and electronic device
CN116684374A (en) Gateway message processing method and device, storage medium and electronic device
CN117527459A (en) Control method and device of intelligent equipment, storage medium and electronic device
CN116389068A (en) Login method and device of application system, storage medium and electronic device
CN116846936A (en) Method and device for sending control instruction, storage medium and electronic device
CN116132209A (en) Scene construction method and device, storage medium and electronic device

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination