CN116366671A - Data synchronization method and device, storage medium and electronic device - Google Patents
Data synchronization method and device, storage medium and electronic device Download PDFInfo
- 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
- cluster
- data synchronization
- 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.)
- Granted
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/10—Protocols in which an application is distributed across nodes in the network
- H04L67/1095—Replication or mirroring of data, e.g. scheduling or transport for data synchronisation between network nodes
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/22—Indexing; Data structures therefor; Storage structures
- G06F16/2228—Indexing structures
- G06F16/2246—Trees, e.g. B+trees
-
- G—PHYSICS
- G06—COMPUTING OR CALCULATING; COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/27—Replication, 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)
- Software Systems (AREA)
- Computing Systems (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
Description
技术领域technical field
本申请涉及通信领域,具体而言,涉及一种数据同步方法和装置、存储介质及电子装置。The present application relates to the communication field, and in particular, to a data synchronization method and device, a storage medium, and an electronic device.
背景技术Background technique
Zookeeper(简称为zk)集群的数据同步是运维及开发在工作中经常会出现的场景。The data synchronization of the Zookeeper (zk for short) cluster is a scene that often occurs in the work of operation and maintenance and development.
目前,如果要将一个zk集群的数据同步到另一个集群,通常需要先将源zk集群的注册的节点数据文件拷贝下来,然后人工再将其手动复制到目的集群的指定目录下,再通过重启目的zk集群的方式才能将数据进行同步,如果后续该集群想要再同步另一个集群的数据时,还需要如此反复以上操作,并且在同步过程中还需重启zk集群才能将数据同步,操作繁琐,无法同时给多个集群进行数据同步且重启期间还会出现依赖该集群的服务无法正常使用等问题。At present, if you want to synchronize the data of one zk cluster to another cluster, you usually need to copy the registered node data files of the source zk cluster first, and then manually copy them to the specified directory of the destination cluster, and then restart the The data can only be synchronized in the way of zk cluster. If the cluster wants to synchronize the data of another cluster in the future, the above operations need to be repeated, and the zk cluster needs to be restarted to synchronize the data during the synchronization process. The operation is cumbersome , it is impossible to synchronize data for multiple clusters at the same time, and during the restart period, there will be problems such as services that depend on the cluster cannot be used normally.
针对相关技术中,源集群的数据同步,存在操作复杂、效率较低等问题,尚未提出有效的解决方案。In the related technology, the data synchronization of the source cluster has problems such as complex operation and low efficiency, and no effective solution has been proposed.
发明内容Contents of the invention
本申请实施例提供了一种数据同步方法和装置、存储介质及电子装置,以至少解决相关技术中,源集群的数据同步,存在操作复杂、效率较低等问题。Embodiments of the present application provide a data synchronization method and device, a storage medium, and an electronic device, so as to at least solve the problems of complex operations and low efficiency in data synchronization of source clusters in related technologies.
根据本申请实施例的一个实施例,提供了一种数据同步方法,包括:在接收到指示源集群向目的集群同步数据的指令的情况下,通过数据同步进程遍历所述源集群的待同步数据,以获取所述待同步数据对应的树形结构中的多个节点的节点数据和所述多个节点的层级关系,其中,多个节点数据分别保存在所述多个节点上;根据所述目的集群的互联网协议地址建立所述数据同步进程与所述目的集群的第一连接关系;基于所述第一连接关系将所述节点数据和所述层级关系发送至所述目的集群,以指示所述目的集群根据所述层级关系创建节点,并将所述节点数据存储至所述目的集群创建的节点中。According to an embodiment of the embodiment of the present application, a data synchronization method is provided, including: in the case of receiving an instruction instructing the source cluster to synchronize data with the destination cluster, traversing the data to be synchronized of the source cluster through a data synchronization process , 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 respectively stored on the multiple nodes; according to the The Internet protocol address of the destination cluster establishes a first connection relationship between the data synchronization process and the destination cluster; based on the first connection relationship, the node data and the hierarchical relationship are sent to the destination cluster to indicate the The target cluster creates nodes according to the hierarchical relationship, and stores the node data into the nodes created by the target cluster.
在一个示例性实施例中,通过数据同步进程遍历所述源集群的待同步数据,以获取所述待同步数据的多个节点的节点数据和所述多个节点的层级关系,包括:通过所述数据同步进程确定所述待同步数据对应的树形结构中的第i级节点是否存在下一级节点,其中,i为正整数,1≤i≤N,N为所述待同步数据对应的树形结构的层级数;在所述第i级节点存在下一级节点的情况下,将所述第i级节点的下一级节点的节点名称存储至待递归容器中,以及确定所述待同步数据的第1级节点至所述第i级节点的节点数据和层级关系。In an exemplary embodiment, traversing the data to be synchronized in the source cluster through a data synchronization process to obtain the node data of multiple nodes of the data to be synchronized and the hierarchical relationship of the multiple nodes includes: through the The data synchronization process determines whether there is a next-level node in the i-th level node in the tree structure corresponding to the data to be synchronized, wherein, i is a positive integer, 1≤i≤N, and N is the node corresponding to the data to be synchronized The number of levels of the tree structure; when there is a next-level node in the i-th level node, store the node name of the next-level node of the i-th level node in the container to be recursed, and determine the to-be-recursive container Synchronize node data and hierarchical relationships between the first-level nodes of the data and the i-th level nodes.
在一个示例性实施例中,通过所述数据同步进程确定所述待同步数据对应的树形结构中的第i级节点是否存在下一级节点之后,所述方法还包括:在通过所述数据同步进程遍历完第i层级节点的情况下,确定所述待递归容器中是否存在节点名称,其中,所述第i层级节点包括:一个或多个第i级节点;在所述待递归容器中不存在节点名称的情况下,确定通过所述数据同步进程从所述树形结构中的第1层级节点遍历至所述树形结构中的第N层级节点;在所述待递归容器中存在节点名称的情况下,所述数据同步进程基于所述节点名称访问所述第i级节点的下一级节点。In an exemplary embodiment, after determining through the data synchronization process whether there is a next-level node in the i-th level node in the tree structure corresponding to the data to be synchronized, the method further includes: When the synchronization process has traversed the i-th level node, determine whether there is a node name in the container to be recursed, wherein the i-th level node includes: one or more i-th level nodes; in the container to be recursed In the absence of a node name, determine that the data synchronization process traverses from the first level node in the tree structure to the Nth level node in the tree structure; there is a node in the recursive container In the case of a name, the data synchronization process accesses the next-level node of the i-th level node based on the node name.
在一个示例性实施例中,通过所述数据同步进程确定所述待同步数据对应的树形结构中的第i级节点是否存在下一级节点之后,所述方法还包括:存储步骤:在所述树形结构中的第i级节点不存在下一级节点的情况下,将所述待同步数据的第1级节点至所述第i级节点的节点数据和层级关系存储至待创建节点容器中;循环所述存储步骤,直至将第1层级节点至第N层级节点的节点数据和层级关系存储至待创建节点容器中。In an exemplary embodiment, after determining through the data synchronization process whether there is a next-level node in the i-th level node in the tree structure corresponding to the data to be synchronized, the method further includes: a storing step: in the In the case that the i-th level node in the tree structure does not have a next-level node, the node data and hierarchical relationship from the first level node to the i-level node of the data to be synchronized are stored in the node container to be created Middle; the storage step is repeated until the node data and hierarchical relationship of the first level node to the Nth level node are stored in the node container to be created.
在一个示例性实施例中,将第1层级节点至所述第N层级节点的节点数据和层级关系存储至待创建节点容器中之后,所述方法还包括:断开所述数据同步进程与所述源集群的第二连接关系,并根据目的集群的互联网协议地址建立所述数据同步进程与所述目的集群的第一连接关系;基于所述第一连接关系将所述待创建节点容器中的第1层级节点至所述第N层级节点的节点数据和层级关系发送至所述目的集群。In an exemplary embodiment, after storing the node data and hierarchical relationships from the first level node to the Nth level node in the node container to be created, the method further includes: disconnecting the data synchronization process from the The second connection relationship of 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; based on the first connection relationship, the node container to be created will be The node data and hierarchical relationships from the first level node to the Nth level node are sent to the destination cluster.
在一个示例性实施例中,根据所述目的集群的互联网协议地址建立所述数据同步进程与所述目的集群的第一连接关系,包括:根据所述目的集群的数量,在所述数据同步进程中建立多个数据同步线程,其中,所述多个数据同步线程的数量与所述目的集群的数量相同;根据多个所述目的集群的物联网地址分别建立所述多个数据同步线程与所述多个所述目的集群的第一连接关系。In an exemplary embodiment, establishing the first connection relationship between the data synchronization process and the destination cluster according to the IP address of the destination cluster includes: according to the number of the destination clusters, in the data synchronization process Establish a plurality of data synchronization threads, wherein, the number of the plurality of data synchronization threads is the same as the number of the target clusters; respectively establish the plurality of data synchronization threads and the number of the target clusters according to the Internet of Things addresses of the plurality of target clusters The first connection relationship of the plurality of target clusters.
在一个示例性实施例中,根据所述目的集群的互联网协议地址建立所述数据同步进程与所述目的集群的第一连接关系,包括:获取所述目的集群对应的密钥,并校验所述密钥;在校验结果满足第一预设条件的情况下,获取所述目的集群的互联网协议地址和所述目的集群的校验值;根据所述互联网协议地址和所述校验值确定所述目的集群对应的接口,并通过所述接口建立数据同步进程与所述目的集群的第一连接关系。In an exemplary embodiment, establishing the first connection relationship between the data synchronization process and the destination cluster according to the IP address of the destination cluster includes: obtaining a key corresponding to the destination cluster, and verifying the the key; in the case that the verification result satisfies the first preset condition, obtain the Internet Protocol address of the destination cluster and the verification value of the destination cluster; determine according to the Internet Protocol address and the verification value An interface corresponding to the target cluster, and establishing a first connection relationship between the data synchronization process and the target cluster through the interface.
根据本申请实施例的另一个实施例,还提供了一种数据同步装置,包括:遍历模块,用于在接收到指示源集群向目的集群同步数据的指令的情况下,通过数据同步进程遍历所述源集群的待同步数据,以获取所述待同步数据对应的树形结构中的多个节点的节点数据和所述多个节点的层级关系,其中,多个节点数据分别保存在所述多个节点上;建立模块,用于根据所述目的集群的互联网协议地址建立所述数据同步进程与所述目的集群的第一连接关系;发送模块,用于基于所述第一连接关系将所述节点数据和所述层级关系发送至所述目的集群,以指示所述目的集群根据所述层级关系创建节点,并将所述节点数据存储至所述目的集群创建的节点中。According to another embodiment of the embodiment of the present application, there is also provided a data synchronization device, including: a traversal module, configured to traverse all The data to be synchronized of 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 respectively stored in the multiple on a node; an establishment module, configured to establish a first connection relationship between the data synchronization process and the destination cluster according to the IP address of the destination cluster; a sending module, configured to transfer the first connection relationship based on the first connection relationship The node data and the hierarchical relationship are sent to the target cluster, 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.
根据本申请实施例的又一方面,还提供了一种计算机可读的存储介质,该计算机可读的存储介质中存储有计算机程序,其中,该计算机程序被设置为运行时执行上述数据同步方法。According to yet another aspect of the embodiments of the present application, a computer-readable storage medium is also provided, and a computer program is stored in the computer-readable storage medium, wherein the computer program is configured to execute the above-mentioned data synchronization method when running .
根据本申请实施例的又一方面,还提供了一种电子装置,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,其中,上述处理器通过计算机程序执行上述的数据同步方法。According to yet another aspect of the embodiments of the present application, there is also provided an electronic device, including a memory, a processor, and a computer program stored on the memory and operable on the processor, wherein the above-mentioned processor executes the above-mentioned Data synchronization method.
在本申请实施例中,在接收到指示源集群向目的集群同步数据的指令的情况下,通过数据同步进程遍历所述源集群的待同步数据,以获取所述待同步数据对应的树形结构中的多个节点的节点数据和所述多个节点的层级关系,其中,多个节点数据分别保存在所述多个节点上;根据所述目的集群的互联网协议地址建立所述数据同步进程与所述目的集群的第一连接关系;基于所述第一连接关系将所述节点数据和所述层级关系发送至所述目的集群,以指示所述目的集群根据所述层级关系创建节点,并将所述节点数据存储至所述目的集群创建的节点中;采用上述技术方案,解决了源集群的数据同步,存在操作复杂、效率较低等问题,本发明实施例中,数据同步进程通过遍历的方式获取待同步节点的多个节点的节点数据和所述多个节点的层级关系,进而给数据同步进程传入目的集群的互联网协议地址,即可实现将待同步数据同步至目的集群中,效率极高。In the embodiment of the present application, when an instruction instructing the source cluster to synchronize data with the target cluster is received, the data to be synchronized of the source cluster is traversed through the data synchronization process to obtain the tree structure corresponding to the data to be synchronized The node data of multiple nodes and the hierarchical relationship of the multiple nodes, wherein the multiple node data are respectively stored on the multiple nodes; the data synchronization process and the data synchronization process are established according to the Internet Protocol address of the target cluster a first connection relationship of the destination cluster; sending 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 The node data is stored in the node created by the destination cluster; using the above technical solution, the data synchronization of the source cluster is solved, and there are problems such as complicated operation and low efficiency. In the embodiment of the present invention, the data synchronization process passes through the The node data of multiple nodes of the node to be synchronized and the hierarchical relationship of the multiple nodes are obtained by means of the method, and then the Internet protocol address of the destination cluster is passed to the data synchronization process, so that the data to be synchronized can be synchronized to the destination cluster, and the efficiency extremely high.
附图说明Description of 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 technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings that need to be used in the description of the embodiments or the prior art. Obviously, for those of ordinary skill in the art, In other words, other drawings can also be obtained from these drawings without paying creative labor.
图1是本申请实施例的一种数据同步方法的硬件环境示意图;FIG. 1 is a schematic diagram of a hardware environment of a data synchronization method according to an embodiment of the present application;
图2是根据本申请实施例的数据同步方法的流程图;Fig. 2 is a flowchart of a data synchronization method according to an embodiment of the present application;
图3是根据本申请实施例的数据同步方法的示意图;FIG. 3 is a schematic diagram of a data synchronization method according to an embodiment of the present application;
图4是根据本申请实施例的一种数据同步装置的结构框图(一);FIG. 4 is a structural block diagram (1) of a data synchronization device according to an embodiment of the present application;
图5是根据本申请实施例的一种数据同步装置的结构框图(二)。Fig. 5 is a structural block diagram (2) of a data synchronization device according to an embodiment of the present application.
具体实施方式Detailed ways
为了使本技术领域的人员更好地理解本申请方案,下面将结合本申请实施例中的附图,对本申请实施例中的技术方案进行清楚、完整地描述,显然,所描述的实施例仅仅是本申请一部分的实施例,而不是全部的实施例。基于本申请中的实施例,本领域普通技术人员在没有做出创造性劳动前提下所获得的所有其他实施例,都应当属于本申请保护的范围。In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiment of the application will be clearly and completely described below in conjunction with the accompanying drawings in the embodiment of the application. Obviously, the described embodiment is only It is an embodiment of a part of the application, but not all of the embodiments. Based on the embodiments in this application, all other embodiments obtained by persons of ordinary skill in the art without creative efforts shall fall within the scope of protection of this application.
需要说明的是,本申请的说明书和权利要求书及上述附图中的术语“第一”、“第二”等是用于区别类似的对象,而不必用于描述特定的顺序或先后次序。应该理解这样使用的数据在适当情况下可以互换,以便这里描述的本申请的实施例能够以除了在这里图示或描述的那些以外的顺序实施。此外,术语“包括”和“具有”以及他们的任何变形,意图在于覆盖不排他的包含,例如,包含了一系列步骤或单元的过程、方法、系统、产品或设备不必限于清楚地列出的那些步骤或单元,而是可包括没有清楚地列出的或对于这些过程、方法、产品或设备固有的其它步骤或单元。It should be noted that the terms "first" and "second" in the description and claims of the present application and the above drawings are used to distinguish similar objects, but not necessarily used to describe a specific sequence or sequence. It is to be understood that the data so used are interchangeable under appropriate circumstances such that the embodiments of the application described herein can be practiced in sequences other than those illustrated or described herein. Furthermore, the terms "comprising" and "having", as well as any variations thereof, are intended to cover a non-exclusive inclusion, for example, a process, method, system, product or device comprising a sequence of steps or elements is not necessarily limited to the expressly listed instead, may include other steps or elements not explicitly listed or inherent to the process, method, product or apparatus.
根据本申请实施例的一个方面,提供了一种数据同步方法。该数据同步方法广泛应用于智慧家庭(Smart Home)、智能家居、智能家用设备生态、智慧住宅(IntelligenceHouse)生态等全屋智能数字化控制应用场景。可选地,在本实施例中,上述数据同步方法可以应用于如图1所示的由终端设备102和服务器104所构成的硬件环境中。如图1所示,服务器104通过网络与终端设备102进行连接,可用于为终端或终端上安装的客户端提供服务(如应用服务等),可在服务器上或独立于服务器设置数据库,用于为服务器104提供数据存储服务,可在服务器上或独立于服务器配置云计算和/或边缘计算服务,用于为服务器104提供数据运算服务。According to an aspect of the embodiments of the present application, a data synchronization method is provided. This data synchronization method is widely used in whole-house intelligent digital control application scenarios such as smart home (Smart Home), smart home, smart home device ecology, and smart house (Intelligence House) ecology. Optionally, in this embodiment, the above data synchronization method may be applied to a hardware environment composed of a
上述网络可以包括但不限于以下至少之一:有线网络,无线网络。上述有线网络可以包括但不限于以下至少之一:广域网,城域网,局域网,上述无线网络可以包括但不限于以下至少之一:WIFI(Wireless Fidelity,无线保真),蓝牙。终端设备102可以并不限定于为PC、手机、平板电脑、智能空调、智能烟机、智能冰箱、智能烤箱、智能炉灶、智能洗衣机、智能热水器、智能洗涤设备、智能洗碗机、智能投影设备、智能电视、智能晾衣架、智能窗帘、智能影音、智能插座、智能音响、智能音箱、智能新风设备、智能厨卫设备、智能卫浴设备、智能扫地机器人、智能擦窗机器人、智能拖地机器人、智能空气净化设备、智能蒸箱、智能微波炉、智能厨宝、智能净化器、智能饮水机、智能门锁等。The foregoing network may include but not limited to at least one of the following: a wired network and a wireless network. The above-mentioned wired network may include but not limited to at least one of the following: wide area network, metropolitan area network, and local area network, and the above-mentioned wireless network may include but not limited to at least one of the following: WIFI (Wireless Fidelity, Wireless Fidelity), Bluetooth. The
在本实施例中提供了一种数据同步方法,应用于计算机终端,图2是根据本申请实施例的数据同步方法的流程图,该流程包括如下步骤:In this embodiment, a data synchronization method is provided, which is applied to a computer terminal. FIG. 2 is a flowchart of a data synchronization method according to an embodiment of the present application. The process includes the following steps:
步骤S202,在接收到指示源集群向目的集群同步数据的指令的情况下,通过数据同步进程遍历所述源集群的待同步数据,以获取所述待同步数据对应的树形结构中的多个节点的节点数据和所述多个节点的层级关系,其中,多个节点数据分别保存在所述多个节点上;Step S202, when receiving an instruction instructing the source cluster to synchronize data with the target cluster, traverse the data to be synchronized of the source cluster through the data synchronization process to obtain multiple data in the tree structure corresponding to the data to be synchronized The node data of the node and the 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.
步骤S204,根据所述目的集群的互联网协议地址建立所述数据同步进程与所述目的集群的第一连接关系;Step S204, establishing a first connection relationship between the data synchronization process and the destination cluster according to the IP address of the destination cluster;
步骤S206,基于所述第一连接关系将所述节点数据和所述层级关系发送至所述目的集群,以指示所述目的集群根据所述层级关系创建节点,并将所述节点数据存储至所述目的集群创建的节点中。Step S206, sending 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 in the In the nodes created by the target cluster.
通过上述步骤,在接收到指示源集群向目的集群同步数据的指令的情况下,通过数据同步进程遍历所述源集群的待同步数据,以获取所述待同步数据对应的树形结构中的多个节点的节点数据和所述多个节点的层级关系,其中,多个节点数据分别保存在所述多个节点上;根据所述目的集群的互联网协议地址建立所述数据同步进程与所述目的集群的第一连接关系;基于所述第一连接关系将所述节点数据和所述层级关系发送至所述目的集群,以指示所述目的集群根据所述层级关系创建节点,并将所述节点数据存储至所述目的集群创建的节点中,解决了相关技术中,源集群的数据同步,存在操作复杂、效率较低等问题,本发明实施例中,数据同步进程通过遍历的方式获取待同步节点的多个节点的节点数据和所述多个节点的层级关系,进而给数据同步进程传入目的集群的互联网协议地址,即可实现将待同步数据同步至目的集群中,效率极高。Through the above steps, when an instruction instructing the source cluster to synchronize data with the target cluster is received, the data to be synchronized of the source cluster is traversed through the data synchronization process to obtain multiple data in the tree structure corresponding to the data to be synchronized. The node data of a node and the hierarchical relationship of the multiple nodes, wherein the multiple node data are respectively stored on the multiple nodes; the data synchronization process and the target cluster are established according to the Internet protocol address of the target cluster The first connection relationship of the cluster; based on the first connection relationship, the node data and the hierarchical relationship are sent to the target cluster to instruct the target cluster to create a node according to the hierarchical relationship, and the node The data is stored in the node created by the target cluster, which solves the problems of complex operation and low efficiency in the data synchronization of the source cluster in the related technology. The node data of multiple nodes of the node and the hierarchical relationship of the multiple nodes, and then the data synchronization process is passed to the Internet protocol address of the target cluster, so that the data to be synchronized can be synchronized to the target cluster, which is extremely efficient.
在一个示例性实施例中,通过数据同步进程遍历所述源集群的待同步数据,以获取所述待同步数据的多个节点的节点数据和所述多个节点的层级关系,包括:通过所述数据同步进程确定所述待同步数据对应的树形结构中的第i级节点是否存在下一级节点,其中,i为正整数,1≤i≤N,N为所述待同步数据对应的树形结构的层级数;在所述第i级节点存在下一级节点的情况下,将所述第i级节点的下一级节点的节点名称存储至待递归容器中,以及确定所述待同步数据的第1级节点至所述第i级节点的节点数据和层级关系。In an exemplary embodiment, traversing the data to be synchronized in the source cluster through a data synchronization process to obtain the node data of multiple nodes of the data to be synchronized and the hierarchical relationship of the multiple nodes includes: through the The data synchronization process determines whether there is a next-level node in the i-th level node in the tree structure corresponding to the data to be synchronized, wherein, i is a positive integer, 1≤i≤N, and N is the node corresponding to the data to be synchronized The number of levels of the tree structure; when there is a next-level node in the i-th level node, store the node name of the next-level node of the i-th level node in the container to be recursed, and determine the to-be-recursive container Synchronize node data and hierarchical relationships between the first-level nodes of the data and the i-th level nodes.
具体的,通过数据同步进程遍历所述源集群的树形结构,以及确定遍历的每个节点是否存在下一级节点,在每一个节点存在以下一级节点的情况下,说明此时遍历的节点不是所述树形结构的叶子节点,即此时未遍历到所述待同步数据的最后一个节点,进而将所述第i级节点的下一级节点的节点名称存储至待递归容器中。Specifically, traverse the tree structure of the source cluster through the data synchronization process, and determine whether each node traversed has a lower-level node, and if each node has a lower-level node, indicate the node traversed at this time It is not a leaf node of the tree structure, that is, the last node of the data to be synchronized has not been traversed at this time, and then the node name of the next-level node of the i-th level node is stored in the to-be-recursive container.
可选地,通过数据同步进程遍历所述源集群的待同步数据,以获取所述待同步数据的多个节点的节点数据和所述多个节点的层级关系,包括:通过数据同步进程广义遍历所述源集群的待同步数据;通过数据同步进程深度遍历所述源集群的待同步数据。Optionally, traversing the data to be synchronized in the source cluster through a data synchronization process to obtain node data of multiple nodes of the data to be synchronized and the hierarchical relationship of the multiple nodes includes: generalized traversal through the data synchronization process The data to be synchronized of the source cluster; the data to be synchronized of the source cluster is deeply traversed through the data synchronization process.
在一个示例性实施例中,通过所述数据同步进程确定所述待同步数据对应的树形结构中的第i级节点是否存在下一级节点之后,在通过所述数据同步进程遍历完第i层级节点的情况下,确定所述待递归容器中是否存在节点名称,其中,所述第i层级节点包括:一个或多个第i级节点;在所述待递归容器中不存在节点名称的情况下,确定通过所述数据同步进程从所述树形结构中的第1层级节点遍历至所述树形结构中的第N层级节点;在所述待递归容器中存在节点名称的情况下,所述数据同步进程基于所述节点名称访问所述第i级节点的下一级节点。In an exemplary embodiment, after determining through the data synchronization process whether there is a next-level node in the i-th level node in the tree structure corresponding to the data to be synchronized, after traversing the i-th level node through the data synchronization process In the case of a hierarchical node, determine whether there is a node name in the container to be recursed, wherein the i-th hierarchical node includes: one or more i-th level nodes; if there is no node name in the container to be recursed Next, it is determined to traverse from the first level node in the tree structure to the Nth level node in the tree structure through the data synchronization process; if there is a node name in the recursive container, the The data synchronization process accesses the next-level node of the i-th level node based on the node name.
可选地,通过数据同步进程广义遍历所述源集群的待同步数据的情况下,先遍历第1层级的所有节点,再遍历第2层级的所有节点……遍历第N层级的所有节点。Optionally, when traversing the data to be synchronized in the source cluster in a broad sense through the data synchronization process, first traverse all the nodes at the first level, then traverse all the nodes at the second level... and traverse all the nodes at the Nth level.
本发明实施例中,在遍历完每一层级的节点的情况下,确定待递归容器中是否存在节点名称,在确定待递归容器中不存在节点名称的情况下,确定通过所述数据同步进程从所述树形结构中的第1层级节点遍历至所述树形结构中的第N层级节点,进而结束遍历;在所述待递归容器中存在节点名称的情况下,所述数据同步进程基于所述节点名称访问所述第i级节点的下一级节点,继续根据待递归容器中的节点名称遍历节点。通过上述实施例,可以完整地获取所述待同步数据的节点的层级关系和所述每个节点中包含的节点数据。In the embodiment of the present invention, after traversing the nodes of each level, it is determined whether there is a node name in the container to be recursed, and when it is determined that there is no node name in the container to be recursed, it is determined that the The first level node in the tree structure traverses to the Nth level node in the tree structure, and then ends the traversal; if there is a node name in the container to be recursed, the data synchronization process is based on the The above-mentioned node name accesses the next-level node of the i-th level node, and continues to traverse the nodes according to the node name in the container to be recursed. Through the above embodiments, the hierarchical relationship of the nodes of the data to be synchronized and the node data included in each node can be completely obtained.
在一个示例性实施例中,通过所述数据同步进程确定所述待同步数据对应的树形结构中的第i级节点是否存在下一级节点之后,存储步骤:在所述树形结构中的第i级节点不存在下一级节点的情况下,将所述待同步数据的第1级节点至所述第i级节点的节点数据和层级关系存储至待创建节点容器中;循环所述存储步骤,直至将第1层级节点至第N层级节点的节点数据和层级关系存储至待创建节点容器中。In an exemplary embodiment, after determining through the data synchronization process whether there is a next-level node in the i-th level node in the tree structure corresponding to the data to be synchronized, the storing step: in the tree structure When there is no next-level node in the i-level node, store the node data and hierarchical relationship from the first-level node to the i-level node of the data to be synchronized in the node container to be created; cycle the storage Step until the node data and hierarchical relationship of the first level node to the Nth level node are stored in the node container to be created.
举例来讲,第N层级节点中包括:第N1级节点、第N2级节点、第N2级节点,在将第1级节点至第N1级节点的节点数据和层级关系存储至待创建节点容器中之后,还要将第1级节点至第N2级节点的节点数据和层级关系存储至待创建节点容器中,直到将第1级节点至第N3级节点的节点数据和层级关系存储至待创建节点容器中,结束循环。For example, the N-level nodes include: N1-level nodes, N2-level nodes, and N2-level nodes, and store the node data and hierarchical relationships from the 1st-level nodes to the N1-level nodes in the node container to be created Afterwards, store the node data and hierarchical relationship from the 1st level node to the N2th level node in the node container to be created until the node data and hierarchical relationship from the 1st level node to the N3rd level node are stored in the node to be created container, end the loop.
在一个示例性实施例中,将第1层级节点至所述第N层级节点的节点数据和层级关系存储至待创建节点容器中之后,断开所述数据同步进程与所述源集群的第二连接关系,并根据目的集群的互联网协议地址建立所述数据同步进程与所述目的集群的第一连接关系;基于所述第一连接关系将所述待创建节点容器中的第1层级节点至所述第N层级节点的节点数据和层级关系发送至所述目的集群。In an exemplary embodiment, after storing the node data and hierarchical relationships from the first level node to the Nth level node in the node container to be created, disconnect the data synchronization process from the second node of the source cluster. connection relationship, 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; based on the first connection relationship, connect the first-level node in the node container to be created to the The node data and hierarchical relationship of the Nth level node are sent to the target cluster.
也就是说,在所有的节点都已经遍历到叶子节点的情况下,则关闭进程与源集群的连接,释放资源;随后进程根据用户输入的需要同步数据的目的集群的ip创建第一连接关系,进而基于所述第一连接关系将所述待创建节点容器中的第1层级节点至所述第N层级节点的节点数据和层级关系发送至所述目的集群,所述目的集群根据所述层级关系创建节点,并将所述节点数据存储至所述目的集群创建的节点中,解决了相关技术中,源集群的数据同步,存在操作复杂、效率较低等问题,本发明实施例中,数据同步进程通过遍历的方式获取待同步节点的多个节点的节点数据和所述多个节点的层级关系,进而给数据同步进程传入目的集群的互联网协议地址,即可实现将待同步数据同步至目的集群中,效率极高。That is to say, when all nodes have traversed to the leaf nodes, the connection between the process and the source cluster is closed to release resources; then the process creates the first connection relationship according to the ip of the destination cluster that needs to synchronize data input by the user, Further, based on the first connection relationship, the node data and hierarchical relationship from the first level node to the Nth level node in the node container to be created are sent to the target cluster, and the target cluster is based on the hierarchical relationship Create a node, and store the node data in the node created by the destination cluster, which solves the problems of complex operation and low efficiency in the data synchronization of the source cluster in the related technology. In the embodiment of the present invention, the data synchronization The process obtains the node data of multiple nodes of the node to be synchronized and the hierarchical relationship of the multiple nodes through traversal, and then passes the Internet Protocol address of the destination cluster to the data synchronization process, so that the data to be synchronized can be synchronized to the destination In a cluster, the efficiency is extremely high.
在一个示例性实施例中,根据所述目的集群的互联网协议地址建立所述数据同步进程与所述目的集群的第一连接关系,包括:根据所述目的集群的数量,在所述数据同步进程中建立多个数据同步线程,其中,所述多个数据同步线程的数量与所述目的集群的数量相同;根据多个所述目的集群的物联网地址分别建立所述多个数据同步线程与所述多个所述目的集群的第一连接关系。In an exemplary embodiment, establishing the first connection relationship between the data synchronization process and the destination cluster according to the IP address of the destination cluster includes: according to the number of the destination clusters, in the data synchronization process Establish a plurality of data synchronization threads, wherein, the number of the plurality of data synchronization threads is the same as the number of the target clusters; respectively establish the plurality of data synchronization threads and the number of the target clusters according to the Internet of Things addresses of the plurality of target clusters The first connection relationship of the plurality of target clusters.
需要说明的而是,进程根据用户输入的需要同步数据的目的集群的物联网地址的数量创建相同数量的线程,线程之间并行执行,多个线程分别连接目的集群,以使所述目的集群根据所述层级关系创建节点,待所有线程结束后,关闭与目的集群的连接,释放资源,即可完成数据的同步。It should be noted that the process creates the same number of threads according to the number of Internet of Things addresses of the destination clusters that need to synchronize data input by the user, and the threads are executed in parallel, and multiple threads are respectively connected to the destination cluster, so that the destination cluster according to The hierarchical relationship creation node closes the connection with the target cluster after all the threads are finished, releases resources, and then completes data synchronization.
在一个示例性实施例中,根据所述目的集群的互联网协议地址建立所述数据同步进程与所述目的集群的第一连接关系,包括:获取所述目的集群对应的密钥,并校验所述密钥;在校验结果满足第一预设条件的情况下,获取所述目的集群的互联网协议地址和所述目的集群的校验值;根据所述互联网协议地址和所述校验值确定所述目的集群对应的接口,并通过所述接口建立数据同步进程与所述目的集群的第一连接关系。In an exemplary embodiment, establishing the first connection relationship between the data synchronization process and the destination cluster according to the IP address of the destination cluster includes: obtaining a key corresponding to the destination cluster, and verifying the the key; in the case that the verification result satisfies the first preset condition, obtain the Internet Protocol address of the destination cluster and the verification value of the destination cluster; determine according to the Internet Protocol address and the verification value An interface corresponding to the target cluster, and establishing a first connection relationship between the data synchronization process and the target cluster through the interface.
本发明实施例中,为了增强信息传输的安全性,数据同步进程在建立与目的集群的连接关系之前,需要对目标集群进行安全性验证,具体的:获取所述目的集群对应的密钥,并校验所述密钥,在验证通过的情况下,获取所述目的集群的互联网协议地址和所述目的集群的校验值;根据所述互联网协议地址和所述校验值确定所述目的集群对应的接口,并通过所述接口建立数据同步进程与所述目的集群的第一连接关系;在验证不通过的情况下,拒绝建立于所述目的集群的连接关系。In the embodiment of the present 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 a connection relationship with the target cluster, specifically: obtain the key corresponding to the target cluster, and verifying the key, and obtaining the IP address of the destination cluster and the check value of the destination cluster when the verification is passed; determining the destination cluster according to the IP address and the check value corresponding interface, and establish the first connection relationship between the data synchronization process and the target cluster through the interface; if the verification fails, refuse to establish the connection relationship with the target cluster.
为了更好的理解上述数据同步方法的过程,以下再结合可选实施例对上述数据同步的实现方法流程进行说明,但不用于限定本申请实施例的技术方案。In order to better understand the process of the above data synchronization method, the flow of the above data synchronization implementation method will be described below in conjunction with an optional embodiment, but it is not intended to limit the technical solution of the embodiment of the present application.
在本实施例中提供了一种数据同步方法,图3是根据本申请实施例的数据同步方法的示意图,如图3所示,具体如下步骤:A data synchronization method is provided in this embodiment, and FIG. 3 is a schematic diagram of a data synchronization method according to an embodiment of the present application, as shown in FIG. 3 , and the specific steps are as follows:
步骤S301:根据源集群的互联网协议地址建立与源集群的连接关系;Step S301: Establish a connection relationship with the source cluster according to the IP address of the source cluster;
步骤S302:获取源集群的待同步数据;Step S302: Obtain the data to be synchronized of the source cluster;
步骤S303:遍历获取当前节点对应的节点数据;Step S303: Obtain node data corresponding to the current node through traversal;
步骤S304:判断当前节点是否存在下一级节点,在当前节点存在下一级节点的情况下,执行步骤S305,否则执行步骤S306;Step S304: Determine whether the current node has a lower-level node, and if the current node has a lower-level node, execute step S305, otherwise execute step S306;
步骤S305:将下一级节点的节点名称放入待递归的节点容器;Step S305: put the node name of the next level node into the node container to be recursed;
步骤S306:将当前节点的节点数据和层级关系放入待创建的节点容器;Step S306: put the node data and hierarchical relationship of the current node into the node container to be created;
步骤S307:确定是否遍历完当前节点对应的层级的所有节点,在遍历完当前节点对应的层级的所有节点的情况下,执行步骤S303,否则执行步骤S308;Step S307: Determine whether all nodes of the level corresponding to the current node have been traversed, and if all nodes of the level corresponding to the current node have been traversed, step S303 is executed, otherwise step S308 is executed;
步骤S308:确定所述待递归的容器中是否有节点名称;Step S308: Determine whether there is a node name in the container to be recursed;
如果有,说明还有未遍历到根节点的数据,则继续进行递归遍历,如果容器中没有节点名称,说明所有的节点都已经遍历到根节点了,则关闭进程与源zk集群的连接,释放资源。If there is, it means that there is still data that has not been traversed to the root node, then continue to traverse recursively, if there is no node name in the container, it means that all nodes have traversed to the root node, then close the connection between the process and the source zk cluster, and release resource.
步骤S309:进程根据需要同步数据的目的集群的ip地址的数量创建相同数量的线程,线程之间并行执行,分别连接目的集群;Step S309: The process creates the same number of threads according to the number of ip addresses of the destination clusters that need to synchronize data, and the threads are executed in parallel to connect to the destination clusters respectively;
步骤S310:根据层级关系创建节点;Step S310: Create nodes according to the hierarchical relationship;
步骤S311:将节点数据存储至对应的节点中;Step S311: storing node data into corresponding nodes;
步骤S312:关闭与目的集群的连接,释放资源。Step S312: close the connection with the destination cluster, and release resources.
本发明实施例,用户只需给程序传入源zk集群的ip及目的集群的ip即可,无需其他繁琐操作。通过多线程的方式可同时对多个集群进行数据同步,效率极高。即使在集群使用期间,依然可以进行数据的同步操作,无需重启集群,实现热同步,不会对依赖该集群的服务产生影响。方案落地后,用户仅需在使用时对传入程序的ip进行维护即可。In the embodiment of the present invention, the user only needs to pass in the ip of the source zk cluster and the ip of the destination cluster to the program, without other cumbersome operations. Data synchronization of multiple clusters can be performed at the same time through multi-threading, which is extremely efficient. Even when the cluster is in use, data synchronization can still be performed without restarting the cluster to achieve hot synchronization without affecting services that depend on the cluster. After the solution is implemented, the user only needs to maintain the ip of the incoming program when using it.
通过以上的实施方式的描述,本领域的技术人员可以清楚地了解到根据上述实施例的方法可借助软件加必需的通用硬件平台的方式来实现,当然也可以通过硬件,但很多情况下前者是更佳的实施方式。基于这样的理解,本申请的技术方案本质上或者说对现有技术做出贡献的部分可以以软件产品的形式体现出来,该计算机软件产品存储在一个存储介质(如ROM/RAM、磁碟、光盘)中,包括若干指令用以使得一台终端设备(可以是手机,计算机,服务器,或者网络设备等)执行本申请各个实施例的方法。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 implemented by means of software plus a necessary general-purpose hardware platform, and of course also by hardware, but in many cases the former is better implementation. Based on such an understanding, the technical solution of the present application can be embodied in the form of a software product in essence or the part that contributes to the prior art, and the computer software product is stored in a storage medium (such as ROM/RAM, disk, CD) contains several instructions to make a terminal device (which may be a mobile phone, a computer, a server, or a network device, etc.) execute the method of each embodiment of the present application.
图4是根据本申请实施例的一种数据同步装置的结构框图(一);如图4所示,包括:Fig. 4 is a structural block diagram (1) of a data synchronization device according to an embodiment of the present application; as shown in Fig. 4 , it includes:
遍历模块42,用于在接收到指示源集群向目的集群同步数据的指令的情况下,通过数据同步进程遍历所述源集群的待同步数据,以获取所述待同步数据对应的树形结构中的多个节点的节点数据和所述多个节点的层级关系,其中,多个节点数据分别保存在所述多个节点上;The
建立模块44,用于根据所述目的集群的互联网协议地址建立所述数据同步进程与所述目的集群的第一连接关系;An
发送模块46,用于基于所述第一连接关系将所述节点数据和所述层级关系发送至所述目的集群,以指示所述目的集群根据所述层级关系创建节点,并将所述节点数据存储至所述目的集群创建的节点中。A sending
通过上述装置,在接收到指示源集群向目的集群同步数据的指令的情况下,通过数据同步进程遍历所述源集群的待同步数据,以获取所述待同步数据对应的树形结构中的多个节点的节点数据和所述多个节点的层级关系,其中,多个节点数据分别保存在所述多个节点上;根据所述目的集群的互联网协议地址建立所述数据同步进程与所述目的集群的第一连接关系;基于所述第一连接关系将所述节点数据和所述层级关系发送至所述目的集群,以指示所述目的集群根据所述层级关系创建节点,并将所述节点数据存储至所述目的集群创建的节点中,解决了相关技术中,源集群的数据同步,存在操作复杂、效率较低等问题,本发明实施例中,数据同步进程通过遍历的方式获取待同步节点的多个节点的节点数据和所述多个节点的层级关系,进而给数据同步进程传入目的集群的互联网协议地址,即可实现将待同步数据同步至目的集群中,效率极高。With the above device, when receiving an instruction instructing the source cluster to synchronize data with the target cluster, the data to be synchronized of the source cluster is traversed through the data synchronization process to obtain multiple data in the tree structure corresponding to the data to be synchronized. The node data of a node and the hierarchical relationship of the multiple nodes, wherein the multiple node data are respectively stored on the multiple nodes; the data synchronization process and the target cluster are established according to the Internet protocol address of the target cluster The first connection relationship of the cluster; based on the first connection relationship, the node data and the hierarchical relationship are sent to the target cluster to instruct the target cluster to create a node according to the hierarchical relationship, and the node The data is stored in the node created by the target cluster, which solves the problems of complex operation and low efficiency in the data synchronization of the source cluster in the related technology. The node data of multiple nodes of the node and the hierarchical relationship of the multiple nodes, and then the data synchronization process is passed to the Internet protocol address of the target cluster, so that the data to be synchronized can be synchronized to the target cluster, which is extremely efficient.
在一个示例性实施例中,遍历模块42,用于通过所述数据同步进程确定所述待同步数据对应的树形结构中的第i级节点是否存在下一级节点,其中,i为正整数,1≤i≤N,N为所述待同步数据对应的树形结构的层级数;在所述第i级节点存在下一级节点的情况下,将所述第i级节点的下一级节点的节点名称存储至待递归容器中,以及确定所述待同步数据的第1级节点至所述第i级节点的节点数据和层级关系。In an exemplary embodiment, the
在一个示例性实施例中,遍历模块42,用于在通过所述数据同步进程遍历完第i层级节点的情况下,确定所述待递归容器中是否存在节点名称,其中,所述第i层级节点包括:一个或多个第i级节点;在所述待递归容器中不存在节点名称的情况下,确定通过所述数据同步进程从所述树形结构中的第1层级节点遍历至所述树形结构中的第N层级节点;在所述待递归容器中存在节点名称的情况下,所述数据同步进程基于所述节点名称访问所述第i级节点的下一级节点。In an exemplary embodiment, the
在一个示例性实施例中,图5是根据本申请实施例的一种数据同步装置的结构框图(二);如图5所示,包括:存储模块52,用于执行存储步骤:在所述树形结构中的第i级节点不存在下一级节点的情况下,将所述待同步数据的第1级节点至所述第i级节点的节点数据和层级关系存储至待创建节点容器中;循环所述存储步骤,直至将第1层级节点至第N层级节点的节点数据和层级关系存储至待创建节点容器中。In an exemplary embodiment, FIG. 5 is a structural block diagram (2) of a data synchronization device according to an embodiment of the present application; as shown in FIG. 5 , it includes: a
在一个示例性实施例中,发送模块46,用于断开所述数据同步进程与所述源集群的第二连接关系,并根据目的集群的互联网协议地址建立所述数据同步进程与所述目的集群的第一连接关系;基于所述第一连接关系将所述待创建节点容器中的第1层级节点至所述第N层级节点的节点数据和层级关系发送至所述目的集群。In an exemplary embodiment, the sending
在一个示例性实施例中,建立模块44,用于根据所述目的集群的数量,在所述数据同步进程中建立多个数据同步线程,其中,所述多个数据同步线程的数量与所述目的集群的数量相同;根据多个所述目的集群的物联网地址分别建立所述多个数据同步线程与所述多个所述目的集群的第一连接关系。In an exemplary embodiment, the establishing
在一个示例性实施例中,建立模块44,用于获取所述目的集群对应的密钥,并校验所述密钥;在校验结果满足第一预设条件的情况下,获取所述目的集群的互联网协议地址和所述目的集群的校验值;根据所述互联网协议地址和所述校验值确定所述目的集群对应的接口,并通过所述接口建立数据同步进程与所述目的集群的第一连接关系。In an exemplary embodiment, the
本申请的实施例还提供了一种存储介质,该存储介质包括存储的程序,其中,上述程序运行时执行上述任一项的方法。An embodiment of the present application further provides a storage medium, the storage medium includes a stored program, wherein the above-mentioned program executes any one of the above-mentioned methods when running.
可选地,在本实施例中,上述存储介质可以被设置为存储用于执行以下步骤的程序代码:Optionally, in this embodiment, the above-mentioned storage medium may be configured to store program codes for performing the following steps:
S1,在接收到指示源集群向目的集群同步数据的指令的情况下,通过数据同步进程遍历所述源集群的待同步数据,以获取所述待同步数据对应的树形结构中的多个节点的节点数据和所述多个节点的层级关系,其中,多个节点数据分别保存在所述多个节点上;S1. In the case of receiving an instruction instructing the source cluster to synchronize data with the target cluster, traverse the data to be synchronized of the source cluster through a data synchronization process to obtain multiple nodes in the tree structure corresponding to the data to be synchronized The node data and the hierarchical relationship of the plurality of nodes, wherein the plurality of node data are respectively stored on the plurality of nodes;
S2,根据所述目的集群的互联网协议地址建立所述数据同步进程与所述目的集群的第一连接关系;S2. Establish a first connection relationship between the data synchronization process and the destination cluster according to the IP address of the destination cluster;
S3,基于所述第一连接关系将所述节点数据和所述层级关系发送至所述目的集群,以指示所述目的集群根据所述层级关系创建节点,并将所述节点数据存储至所述目的集群创建的节点中。S3. 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 in the In the node created by the destination cluster.
本申请的实施例还提供了一种电子装置,包括存储器和处理器,该存储器中存储有计算机程序,该处理器被设置为运行计算机程序以执行上述任一项方法实施例中的步骤。An embodiment of the present application also provides an electronic device, including a memory and a processor, where a computer program is stored in the memory, and the processor is configured to run the computer program to perform the steps in any one of the above method embodiments.
可选地,上述电子装置还可以包括传输设备以及输入输出设备,其中,该传输设备和上述处理器连接,该输入输出设备和上述处理器连接。Optionally, the above-mentioned electronic device may further include a transmission device and an input-output device, wherein the transmission device is connected to the above-mentioned processor, and the input-output device is connected to the above-mentioned processor.
可选地,在本实施例中,上述处理器可以被设置为通过计算机程序执行以下步骤:Optionally, in this embodiment, the above-mentioned processor may be configured to execute the following steps through a computer program:
S1,在接收到指示源集群向目的集群同步数据的指令的情况下,通过数据同步进程遍历所述源集群的待同步数据,以获取所述待同步数据对应的树形结构中的多个节点的节点数据和所述多个节点的层级关系,其中,多个节点数据分别保存在所述多个节点上;S1. In the case of receiving an instruction instructing the source cluster to synchronize data with the target cluster, traverse the data to be synchronized of the source cluster through a data synchronization process to obtain multiple nodes in the tree structure corresponding to the data to be synchronized The node data and the hierarchical relationship of the plurality of nodes, wherein the plurality of node data are respectively stored on the plurality of nodes;
S2,根据所述目的集群的互联网协议地址建立所述数据同步进程与所述目的集群的第一连接关系;S2. Establish a first connection relationship between the data synchronization process and the destination cluster according to the IP address of the destination cluster;
S3,基于所述第一连接关系将所述节点数据和所述层级关系发送至所述目的集群,以指示所述目的集群根据所述层级关系创建节点,并将所述节点数据存储至所述目的集群创建的节点中。S3. 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 in the In the node created by the destination cluster.
可选地,在本实施例中,上述存储介质可以包括但不限于:U盘、只读存储器(Read-Only Memory,简称为ROM)、随机存取存储器(Random Access Memory,简称为RAM)、移动硬盘、磁碟或者光盘等各种可以存储程序代码的介质。Optionally, in this embodiment, the above-mentioned storage medium may include but not limited to: U disk, read-only memory (Read-Only Memory, ROM for short), random access memory (Random Access Memory, RAM for short), Various media that can store program codes such as removable hard disks, magnetic disks, or optical disks.
可选地,本实施例中的具体示例可以参考上述实施例及可选实施方式中所描述的示例,本实施例在此不再赘述。Optionally, for specific examples in this embodiment, reference may be made to the examples described in the foregoing embodiments and optional implementation manners, and details are not repeated in this embodiment.
显然,本领域的技术人员应该明白,上述的本申请的各模块或各步骤可以用通用的计算装置来实现,它们可以集中在单个的计算装置上,或者分布在多个计算装置所组成的网络上,可选地,它们可以用计算装置可执行的程序代码来实现,从而,可以将它们存储在存储装置中由计算装置来执行,并且在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤,或者将它们分别制作成各个集成电路模块,或者将它们中的多个模块或步骤制作成单个集成电路模块来实现。这样,本申请不限制于任何特定的硬件和软件结合。Obviously, those skilled in the art should understand that each module or each step of the above-mentioned application can be realized by a general-purpose computing device, and they can be concentrated on a single computing device, or distributed in a network composed of multiple computing devices Alternatively, they may be implemented in program code executable by a computing device so that they may be stored in a storage device to be executed by a computing device, and in some cases in an order different from that shown here The steps shown or described are carried out, or they are separately fabricated into individual integrated circuit modules, or multiple modules or steps among them are fabricated into a single integrated circuit module for implementation. As such, the present application is not limited to any specific combination of hardware and software.
以上所述仅是本申请的优选实施方式,应当指出,对于本技术领域的普通技术人员来说,在不脱离本申请原理的前提下,还可以做出若干改进和润饰,这些改进和润饰也应视为本申请的保护范围。The above description is only the preferred embodiment of the present application. It should be pointed out that for those of ordinary skill in the art, without departing from the principle of the present application, some improvements and modifications can also be made. These improvements and modifications are also It should be regarded as the protection scope of this application.
Claims (10)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202310215846.6A CN116366671B (en) | 2023-02-28 | 2023-02-28 | Data synchronization methods and apparatus, storage media and electronic devices |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN202310215846.6A CN116366671B (en) | 2023-02-28 | 2023-02-28 | Data synchronization methods and apparatus, storage media and electronic devices |
Publications (2)
| Publication Number | Publication Date |
|---|---|
| CN116366671A true CN116366671A (en) | 2023-06-30 |
| CN116366671B CN116366671B (en) | 2025-12-26 |
Family
ID=86913039
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN202310215846.6A Active CN116366671B (en) | 2023-02-28 | 2023-02-28 | Data synchronization methods and apparatus, storage media and electronic devices |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN116366671B (en) |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN119691072A (en) * | 2024-11-29 | 2025-03-25 | 中移动信息技术有限公司 | Database bidirectional synchronization method and computer program product |
Citations (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20110137916A1 (en) * | 2009-06-30 | 2011-06-09 | International Business Machines Corporation | System and method for synchronized content directories on cluster devices |
| US20190065322A1 (en) * | 2017-08-31 | 2019-02-28 | Cohesity, Inc. | Restoring a database using a fully hydrated backup |
| CN111917834A (en) * | 2020-07-13 | 2020-11-10 | 腾讯科技(深圳)有限公司 | A data synchronization method, device, storage medium and computer equipment |
| CN112162963A (en) * | 2020-10-15 | 2021-01-01 | 苏州交驰人工智能研究院有限公司 | Data synchronization method and device, computer equipment and storage medium |
| US20210042336A1 (en) * | 2019-08-08 | 2021-02-11 | International Business Machines Corporation | Performing a write-prioritized tree copy |
| CN112835862A (en) * | 2019-11-22 | 2021-05-25 | 北京达佳互联信息技术有限公司 | Data synchronization method, device and system and storage medium |
| CN115129676A (en) * | 2022-07-22 | 2022-09-30 | 济南浪潮数据技术有限公司 | Data synchronization method, device, equipment and medium |
-
2023
- 2023-02-28 CN CN202310215846.6A patent/CN116366671B/en active Active
Patent Citations (7)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| US20110137916A1 (en) * | 2009-06-30 | 2011-06-09 | International Business Machines Corporation | System and method for synchronized content directories on cluster devices |
| US20190065322A1 (en) * | 2017-08-31 | 2019-02-28 | Cohesity, Inc. | Restoring a database using a fully hydrated backup |
| US20210042336A1 (en) * | 2019-08-08 | 2021-02-11 | International Business Machines Corporation | Performing a write-prioritized tree copy |
| CN112835862A (en) * | 2019-11-22 | 2021-05-25 | 北京达佳互联信息技术有限公司 | Data synchronization method, device and system and storage medium |
| CN111917834A (en) * | 2020-07-13 | 2020-11-10 | 腾讯科技(深圳)有限公司 | A data synchronization method, device, storage medium and computer equipment |
| CN112162963A (en) * | 2020-10-15 | 2021-01-01 | 苏州交驰人工智能研究院有限公司 | Data synchronization method and device, computer equipment and storage medium |
| CN115129676A (en) * | 2022-07-22 | 2022-09-30 | 济南浪潮数据技术有限公司 | Data synchronization method, device, equipment and medium |
Cited By (1)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN119691072A (en) * | 2024-11-29 | 2025-03-25 | 中移动信息技术有限公司 | Database bidirectional synchronization method and computer program product |
Also Published As
| Publication number | Publication date |
|---|---|
| CN116366671B (en) | 2025-12-26 |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| CN105281957B (en) | A kind of method and server of the access device in Internet of Things | |
| CN116366671A (en) | Data synchronization method and device, storage medium and electronic device | |
| CN116389068A (en) | Application system login method, device, storage medium and electronic device | |
| CN116634464A (en) | Equipment distribution network method and device, storage medium and electronic equipment | |
| CN116033006A (en) | Data processing method, system, storage medium and electronic device | |
| WO2020048194A1 (en) | Method for performing task processing on common service entity, common service entity, apparatus for performing task processing and medium | |
| CN110647734A (en) | Equipment unlocking method and device based on Internet of things operating system | |
| CN116382107A (en) | Method, device, storage medium and electronic device for acquiring equipment instructions | |
| CN115473852A (en) | Current-limiting method, storage medium and electronic device for client input request | |
| CN116546055A (en) | Service message processing method and device, storage medium and electronic device | |
| CN115473752A (en) | Method and device for sending control command, storage medium and electronic device | |
| CN115481179A (en) | Asynchronous file export method, system, storage medium and electronic device | |
| CN116614858A (en) | Data transmission method and device, storage medium and electronic equipment | |
| WO2024001163A1 (en) | Attribute data conversion method and apparatus, storage medium, and electronic device | |
| CN116527738A (en) | Service information processing method and device, storage medium and electronic device | |
| CN116450229A (en) | Pre-starting method and device of application software, storage medium and electronic device | |
| CN115314332A (en) | Method and device for setting equipment theme, storage medium and electronic device | |
| CN115967588B (en) | Method, storage medium and electronic device for controlling equipment | |
| CN115378656B (en) | Token backfill method, storage medium and electronic device | |
| CN115297345B (en) | Screen projection request processing method, device, storage medium and electronic device | |
| CN116301767A (en) | Method, device, storage medium and electronic device for generating interface file | |
| CN116248647A (en) | Method and device for sending resource pack, storage medium and electronic device | |
| CN115484163A (en) | System switching method and device, storage medium and electronic device | |
| CN119155077A (en) | Device binding method and apparatus, storage medium, electronic apparatus, and computer program product | |
| CN115174296A (en) | Equipment function access method, 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 | ||
| GR01 | Patent grant | ||
| GR01 | Patent grant |