A data synchronization method, terminal and computer readable storage medium
The data synchronization method addresses inefficiencies in Postgresql database synchronization by detecting synchronization states and saving key data packets, ensuring efficient and uninterrupted data transfer in dual-master scenarios.
Patent Information
- Application Number
- CN202411452153.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-17
- Publication Date
- 2025-01-03
- Estimated Expiration
- 2044-10-17
AI Technical Summary
The existing data synchronization process in Postgresql databases is inefficient and cannot be restored if interrupted, particularly in dual-master scenarios where historical data is deleted and re-synced, leading to database inconsistencies.
A data synchronization method that detects the current synchronization state of the standby node, uses historical data and control information to manage synchronization, and saves key data packets for resumed synchronization, enhancing efficiency by allowing retrieval of stored data during interruptions.
Improves data synchronization efficiency by enabling the retrieval and continuation of synchronization using stored key data packets, ensuring seamless data transfer even in interrupted processes.
Smart Images

Figure CN118972401B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image technology, and in particular to a data synchronization method, a terminal and a computer-readable storage medium. Background Art
[0002] Currently, the open source database Postgresql has been widely used in the market. Postgresql database is referred to as PG. In the common high-availability master-slave solution of PG database, such as a master-slave architecture, if a master-slave switch occurs, the slave node is promoted to the new master node, and then it becomes a dual-master scenario. If you want to rebuild a new master-slave cluster, you need to make the original historical master node into the current standby node and rejoin the cluster. Specifically, all the historical data of the current standby node is deleted, and a current standby node is completely backed up from the current master node, and then added to the cluster. However, this data synchronization method is inefficient, and the data synchronization process cannot be restored if it is interrupted. Summary of the invention
[0003] The main technical problem solved by the present invention is to provide a data synchronization method, a terminal and a computer-readable storage medium to solve the problem that the data synchronization process cannot be restored after being interrupted in the prior art.
[0004] In order to solve the above technical problems, the first technical solution adopted by the present invention is: to provide a data synchronization method, which is applied to a control device of a data synchronization system, wherein the data synchronization system also includes a current master node and a current standby node, and the current master node and the current standby node are respectively connected to the control device for communication; the current master node is a node after the historical standby node that has completed synchronization has been switched, and the current master node has control information and data information; the current standby node is a node after the historical master node that has completed synchronization has been switched, and the current standby node has historical control information and historical data information; the data synchronization method includes:
[0005] Detect the current synchronization status of the current standby node during the current synchronization process;
[0006] Based on the historical storage data stored before the current synchronization state of the current standby node, the control information and data information corresponding to the current master node, and the historical control information and historical data information corresponding to the current standby node, control the synchronization of the data information and / or control information of the current master node to the current standby node.
[0007] The data synchronization method further includes:
[0008] Check whether the current standby node has status record information during the current synchronization process;
[0009] In response to the current standby node having status record information, detecting the current synchronization state of the current standby node; the current synchronization state includes one of a start state, a transmission state, and an update state;
[0010] In response to the current standby node not having status record information, the control information and data information corresponding to the current master node and the historical control information and historical data information corresponding to the current standby node are acquired to generate status record information.
[0011] Wherein, based on the historical storage data stored before the current synchronization state of the current standby node, the control information and data information corresponding to the current master node, and the historical control information and historical data information corresponding to the current standby node, the data information and / or control information of the current master node is synchronized to the current standby node, including:
[0012] In response to the current synchronization state of the current standby node being a start state, determining that the historical storage data stored before the start state is empty;
[0013] Based on the data information of the current master node and the historical data information of the current standby node, the historical data information of the current standby node is updated to obtain the data information of the current standby node;
[0014] The current synchronization state of the current standby node is controlled to be updated to an updated state, and the historical control information of the current standby node is updated based on the control information of the current master node to obtain the control information of the current standby node.
[0015] Wherein, based on the data information of the current master node and the historical data information of the current standby node, the historical data information of the current standby node is updated to obtain the data information of the current standby node, including:
[0016] Generate synchronization difference data based on the data information of the current master node and the historical data information of the current standby node;
[0017] Control and save the control information of the current master node, the historical control information of the current standby node, and the synchronization difference data;
[0018] Control to update the current synchronization state of the current standby node to the transmission state, pre-process the historical data information of the current standby node based on the synchronization difference data, obtain the processing method of each historical data information corresponding to the current standby node and the data to be entered and save them;
[0019] The data information corresponding to the data to be entered in the current master node is synchronized to the current standby node, and the historical data information of the current standby node is processed based on the processing method of each historical data information in the current standby node to obtain the data information of the current standby node.
[0020] Wherein, based on the historical storage data stored before the current synchronization state of the current standby node, the control information and data information corresponding to the current master node, and the historical control information and historical data information corresponding to the current standby node, the data information and / or control information of the current master node is synchronized to the current standby node, including:
[0021] In response to the current synchronization state of the current standby node being a transmission state, extracting historical storage data stored before the transmission state; the historical storage data stored before the transmission state includes control information of the current master node, historical control information of the current standby node, and synchronization difference data;
[0022] Preprocess the historical data information of the current standby node based on the synchronization difference data, obtain the processing method of each historical data information corresponding to the current standby node and the data to be entered and save them;
[0023] Control to synchronize the data information corresponding to the data to be entered in the current master node to the current standby node, and process the historical data information of the current standby node based on the processing method of each historical data information in the current standby node to obtain the data information of the current standby node;
[0024] The current synchronization state of the current standby node is controlled to be updated to an updated state, and the historical control information of the current standby node is updated based on the control information of the current master node to obtain the control information of the current standby node.
[0025] Wherein, based on the historical storage data stored before the current synchronization state of the current standby node, the control information and data information corresponding to the current master node, and the historical control information and historical data information corresponding to the current standby node, the data information and / or control information of the current master node is synchronized to the current standby node, including:
[0026] In response to the current synchronization state of the current standby node being an update state, extracting the historical storage data stored before the update state; the historical storage data stored before the update state includes the control information of the current master node, the historical control information of the current standby node, the synchronization difference data, the processing method of each historical data information corresponding to the current standby node, and the data to be entered;
[0027] The historical control information of the current standby node is updated based on the control information of the current master node to obtain the control information of the current standby node.
[0028] Wherein, the historical control information of the current standby node is updated based on the control information of the current master node to obtain the control information of the current standby node, including:
[0029] Mark the current standby node as a standby node;
[0030] The control unit synchronizes the control information of the current master node to the current standby node and deletes the historical control information of the current standby node to obtain the control information of the current standby node.
[0031] The data synchronization method further includes:
[0032] In response to the current synchronization state of the current standby node being the end state, the historical storage data stored before the end state is deleted; the historical storage data stored before the end state includes the control information of the current master node, the historical control information of the current standby node, the synchronization difference data, the processing method of each historical data information corresponding to the current standby node, and the data to be entered.
[0033] To solve the above technical problems, the second technical solution adopted by the present invention is: to provide a terminal, the terminal includes a memory, a processor, and a computer program stored in the memory and running on the processor, the processor is used to execute program data to implement the steps in the above data synchronization method.
[0034] To solve the above technical problems, the third technical solution adopted by the present invention is: providing a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the steps in the above data synchronization method are implemented.
[0035] The beneficial effects of the present invention are as follows: different from the prior art, a data synchronization method, a terminal and a computer-readable storage medium are provided, the data synchronization method is applied to a control device of a data synchronization system, the data synchronization system also includes a current master node and a current standby node, the current master node and the current standby node are respectively communicated with the control device; the current master node is a node after the historical standby node that has completed synchronization historically is switched, and the current master node has control information and data information; the current standby node is a node after the historical master node that has completed synchronization historically is switched, and the current standby node has historical control information and historical data information; the data synchronization method includes: detecting the current synchronization state of the current standby node during the current synchronization process; based on the historical storage data stored before the current synchronization state of the current standby node, the control information and data information corresponding to the current master node, and the historical control information and historical data information corresponding to the current standby node, controlling the synchronization of the data information and / or control information of the current master node to the current standby node. The present application saves the key data packets of the current standby node during the data synchronization process. When an interruption occurs in the data synchronization process of the current standby node, the key data packets stored before the current synchronization state of the current standby node can be retrieved, so as to continue to synchronize the data of the current standby node based on the key data packets stored before the current synchronization state, thereby improving the data synchronization efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0036] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.
[0037] Figure 1 It is a flowchart of the data synchronization method provided by the present invention;
[0038] Figure 2 It is a flow chart of an embodiment of a data synchronization method provided by the present invention;
[0039] Figure 3 It is a flowchart of a specific embodiment of the data synchronization method provided by the present invention;
[0040] Figure 4 It is a schematic diagram of the framework of an embodiment of a data synchronization device provided by the present invention;
[0041] Figure 5 It is a schematic diagram of the framework of a terminal embodiment provided by the present invention;
[0042] Figure 6 It is a schematic diagram of a framework of an embodiment of a computer-readable storage medium provided by the present invention. DETAILED DESCRIPTION
[0043] The scheme of the embodiment of the present application is described in detail below in conjunction with the drawings of the specification.
[0044] In the following description, for the purpose of explanation rather than limitation, specific details such as specific system structures, interfaces, and technologies are provided to facilitate a thorough understanding of the present application.
[0045] The term "and / or" in this article is only a description of the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, the character " / " in this article generally indicates that the associated objects before and after are in an "or" relationship. In addition, "many" in this article means two or more than two.
[0046] In order to enable those skilled in the art to better understand the technical solution of the present invention, a data synchronization method provided by the present invention is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0047] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0048] Before further describing the embodiments of the present application in detail, the nouns and terms involved in the embodiments of the present application are explained. The nouns and terms involved in the embodiments of the present application are subject to the following interpretations.
[0049] PostgreSQL is a full-featured free software database. The PG database has a master-slave cluster, which includes a master node and at least one standby node. When a master-slave switch occurs, a standby node is promoted to the new master node as the current master node. A new master-slave cluster needs to be rebuilt, and the historical master node is switched to the current standby node and then re-entered into the newly built master-slave cluster, and the control files and data files of the current master node are synchronized to the current standby node.
[0050] Through the open source pg_rewind tool provided by the PG database, this tool only synchronizes the partial data between the historical data information of the current standby node and the data information of the current master node. There is no need to synchronize the full amount of data, and the process of converting the historical master node into the current standby node can be completed efficiently.
[0051] Since the open source tool pg_rewind only needs to synchronize the difference data part, it can greatly improve the efficiency of the process of turning the historical master node into the current standby node. However, the pg_rewind tool itself still has some defects. If pg_rewind is abnormally terminated during the data file transmission process when it is running, an error will be reported when the pg_rewind tool is re-run, because the pg_rewind tool is transmitting data while modifying the historical data information on the current standby node in real time during the operation. If the operation is interrupted before it is completed, part of the historical data information of the current standby node will be modified, resulting in inconsistency of the database of the historical master node, and the database of the historical master node cannot be started normally, which will cause an error when the pg_rewind tool is run again, because pg_rewind will try to start the PG database when it is running, and because some data information has been modified during the last operation, the PG database cannot be started normally.
[0052] See also Figure 1 , Figure 1 It is a flowchart of the data synchronization method provided by the present invention.
[0053] In this embodiment, a data synchronization method is provided, and the data synchronization method is applied to a control device of a data synchronization system, and the data synchronization system includes a current master node and a current standby node, and the current master node and the current standby node are respectively connected to the control device in communication, and the current master node and the current standby node are connected in communication. The control device refers to a device with control capability, and the control device can be other devices independent of the master node and the standby node, or any node in the master node, or any node in the standby node. Here, the control device is only exemplarily described without specific limitation.
[0054] The following uses the execution subject as a control device as an example to illustrate the data synchronization method provided in the embodiment of the present application. In other embodiments, the current master node or the current standby node can also be used as a control device to execute the data synchronization method in the following embodiments. When the current master node or the current standby node is used as a control device, the current master node and the current standby node are connected in communication.
[0055] The current master node is a node after the historical backup node that has completed synchronization has switched, and the current master node has control information and data information; the current backup node is a node after the historical master node that has completed synchronization has switched, and the current backup node has historical control information and historical data information. The data synchronization method includes the following steps.
[0056] S1: Detect the current synchronization status of the current standby node during the current synchronization process.
[0057] S2: Based on the historical storage data stored before the current synchronization state of the current standby node, the control information and data information corresponding to the current master node, and the historical control information and historical data information corresponding to the current standby node, control the synchronization of the data information and / or control information of the current master node to the current standby node.
[0058] The pg_rewind tool is used to control the synchronization of the control files and data files of the current master node in the current synchronization process to the current standby node. The synchronization process is divided into several stages, and the corresponding status information is introduced after each stage is completed. When the synchronization process is not completed and an interruption or exception occurs, it is convenient to query the completed stages and saved data of the last unfinished synchronization process, so that the relevant data can be restored and synchronized in the subsequent synchronization process.
[0059] See also Figure 2 , Figure 2 It is a flowchart of an embodiment of a data synchronization method provided by the present invention.
[0060] In one embodiment, the data synchronization method further includes the following steps.
[0061] Check whether the current standby node has status record information during the current synchronization process. Specifically, when the current synchronization process has not yet adopted the pg_rewind tool to start data synchronization, the current standby node in the current synchronization process has not created status record information. When the pg_rewind tool has been adopted to start data synchronization during the current synchronization process, the current standby node creates status record information, and the current synchronization status in the status record information is the start status. Among them, the name of the current synchronization status is defined as pg_rewind_status, which is used to distinguish which execution stage pg_rewind is currently in, in order to adopt different processing logic according to different states when executing pg_rewind again.
[0062] In response to the current standby node having status record information, the current synchronization state of the current standby node is detected; the current synchronization state includes one of a start state, a transmission state, and an update state.
[0063] In response to the current standby node not having status record information, the control information and data information corresponding to the current master node and the historical control information and historical data information corresponding to the current standby node are acquired to generate status record information.
[0064] See also Figure 3 , Figure 3 It is a flowchart of a specific embodiment of the data synchronization method provided by the present invention.
[0065] Specifically, in step S2, based on the historical storage data stored before the current synchronization state of the current standby node, the control information and data information corresponding to the current master node, and the historical control information and historical data information corresponding to the current standby node, the specific implementation method of synchronizing the data information and / or control information of the current master node to the current standby node is as follows.
[0066] In one embodiment, in response to the current synchronization state of the current standby node being the start state, the historical storage data stored before the start state is empty.
[0067] Specifically, in response to the current synchronization state of the current standby node being the start state, parameter judgment is performed, and the control information of the current master node and the historical control information of the current standby node are obtained, and then the master-slave switching point of the current master node and the historical master node is determined. Among them, the historical master node is the master node in the previous completed synchronization process adjacent to the current synchronization process. In the current synchronization process, the historical master node switches to the current standby node, and the historical control information of the current standby node is the control information of the master node of the historical master node in the adjacent previous completed synchronization process; the historical data information of the current standby node is the data information of the master node of the historical master node in the adjacent previous completed synchronization process. When the master-slave switching point of the current master node and the historical master node is determined, the data information of the current master node and the historical data information of the current standby node are obtained. In the current synchronization process, the data information and control information of the current master node need to be synchronized to the current standby node to control the update of the historical data information and historical control information of the current standby node.
[0068] The historical data information of the current standby node is updated based on the data information of the current master node and the historical data information of the current standby node to obtain the data information of the current standby node.
[0069] In a specific embodiment, synchronization difference data is generated based on the data information of the current master node and the historical data information of the current backup node; the control information of the current master node, the historical control information of the current backup node and the synchronization difference data are controlled to be saved as the first key data packet. This is convenient for directly re-synchronizing after an interruption occurs during the synchronization process. There is no need to re-process the data, thereby improving synchronization efficiency.
[0070] The current synchronization state of the current standby node is controlled to be updated to a transmission state, and the historical storage data before the transmission state includes a first key data packet.
[0071] Based on the synchronization difference data, the historical data information of the current standby node is preprocessed to obtain the processing method of each historical data information corresponding to the current standby node and the data to be entered and save them. Specifically, the control saves the processing method of each historical data information corresponding to the current standby node and the data to be entered as the second key data packet. Specifically, the control saves the second key data packet into the binary file of the current standby node.
[0072] In a specific embodiment, a record table is created in advance on the current master node, and the table name is fetchchunks. The historical data information of the current standby node is preprocessed according to the synchronization difference data, and each synchronization difference data is traversed to obtain the processing method of each historical data information corresponding to the current standby node and the data to be entered that does not exist in the current standby node and needs to be copied and synchronized from the current master node.
[0073] Specifically, the processing methods of historical data information include not processing, deleting, directly clearing, and if the file is a directory or a soft link, directly creating the directory or soft link on the old master.
[0074] Specifically, based on the synchronization difference data, the control filters the data information that does not exist in the current standby node and records it in the record table named fetchchunks, the information that needs to be completely copied and replaced from the current master node, and the partial data information that needs to be synchronized from the current master node. The fields, types and related descriptions of the specific recorded information. For example, the fields can be path, begin, len, etc.; the types can be text, int, etc.; the related descriptions can be file path, start position, length, etc.
[0075] Controls the synchronization of the data information corresponding to the data to be entered in the current primary node to the current standby node. Specifically, after the preprocessing is completed, pg_rewind sends a SQL statement (SELECT path, begin pg_read_binary_file (path, begin, len, true) AS chunk from fetchchunks) to the current primary node to query the contents of the fetchchunks table and start synchronizing the required data information from the current primary node to the current standby node.
[0076] The historical data information of the current standby node is processed based on the processing method of each historical data information in the current standby node to obtain the data information of the current standby node.
[0077] Through this step, the historical data information on the current standby node has been modified. If an interruption occurs during the operation of this stage, pg_rewind cannot be run again.
[0078] The current synchronization state of the current standby node is controlled to be updated to an updated state, and the historical control information of the current standby node is updated based on the control information of the current master node to obtain the control information of the current standby node.
[0079] In a specific embodiment, a backup_label file is created on the current standby node to mark the current standby node as a standby node. The control information of the current master node is synchronized to the current standby node and the historical control information of the current standby node is deleted to obtain the control information of the current standby node so as to start the current standby node.
[0080] In one embodiment, in response to the current synchronization state of the current standby node being a transmission state, historical storage data stored before the transmission state is extracted; the historical storage data stored before the transmission state includes control information of the current master node, historical control information of the current standby node, and synchronization difference data.
[0081] The historical data information of the current standby node is preprocessed based on the synchronization difference data, and the processing method of each historical data information corresponding to the current standby node and the data to be entered are obtained and saved.
[0082] Control to synchronize the data information corresponding to the data to be entered in the current master node to the current standby node, process the historical data information of the current standby node based on the processing method of each historical data information in the current standby node, and obtain the data information of the current standby node.
[0083] The current synchronization state of the current standby node is controlled to be updated to an updated state, and the historical control information of the current standby node is updated based on the control information of the current master node to obtain the control information of the current standby node.
[0084] In one embodiment, in response to the current synchronization state of the current standby node being an update state, historical storage data stored before the update state is extracted; the historical storage data stored before the update state includes control information of the current master node, historical control information of the current standby node, synchronization difference data, a processing method for each historical data information corresponding to the current standby node, and data to be entered;
[0085] The historical control information of the current standby node is updated based on the control information of the current master node to obtain the control information of the current standby node.
[0086] In one embodiment, the data synchronization method further includes the following steps.
[0087] In response to the current synchronization state of the current standby node being the end state, the control deletes the historical storage data stored before the end state; the historical storage data stored before the end state includes the control information of the current master node, the historical control information of the current standby node, the synchronization difference data, the processing method of each historical data information corresponding to the current standby node, and the data to be entered, that is, the control deletes the intermediate data such as the first key data packet and the second key data packet stored in the current synchronization process.
[0088] In one embodiment, when the current standby node has status record information, but the current synchronization state is not any of the start state, transmission state, update state, and end state, data synchronization is abnormal and the current synchronization process is directly terminated.
[0089] The data synchronization method provided in this embodiment detects the current synchronization state of the current standby node during the current synchronization process; based on the historical storage data stored before the current synchronization state of the current standby node, the control information and data information corresponding to the current master node, and the historical control information and historical data information corresponding to the current standby node, controls the synchronization of the data information and / or control information of the current master node to the current standby node. This application saves the key data packets of the current standby node during the data synchronization process. When an interruption occurs in the data synchronization process of the current standby node, the key data packets stored before the current synchronization state of the current standby node can be retrieved, so as to continue to synchronize the data of the current standby node based on the key data packets stored before the current synchronization state, thereby improving the data synchronization efficiency.
[0090] See also Figure 4 , Figure 4 It is a schematic diagram of the framework of an embodiment of a data synchronization device provided by the present invention.
[0091] This embodiment provides a data synchronization device 60, which is applied to a control device of a data synchronization system, wherein the data synchronization system further includes a current master node and a current standby node, wherein the current master node and the current standby node are respectively connected to the control device for communication; the current master node is a node after switching from a historical standby node that has completed synchronization in history, and the current master node has control information and data information; the current standby node is a node after switching from a historical master node that has completed synchronization in history, and the current standby node has historical control information and historical data information. The data synchronization device 60 includes a detection module 61 and a synchronization module 62.
[0092] The detection module 61 is used to detect the current synchronization state of the current standby node in the current synchronization process.
[0093] The synchronization module 62 is used to control the synchronization of the data information and / or control information of the current master node to the current standby node based on the historical storage data stored before the current synchronization state of the current standby node, the control information and data information corresponding to the current master node, and the historical control information and historical data information corresponding to the current standby node.
[0094] The data synchronization device provided in this embodiment saves the key data packets of the current standby node during the data synchronization process. When an interruption occurs in the data synchronization process of the current standby node, the key data packets stored before the current synchronization state of the current standby node can be retrieved, so as to continue to synchronize the data of the current standby node based on the key data packets stored before the current synchronization state, thereby improving data synchronization efficiency.
[0095] See also Figure 5 , Figure 580 is a schematic diagram of a terminal embodiment provided by the present invention. The terminal 80 includes a memory 81 and a processor 82 coupled to each other, and the processor 82 is used to execute program instructions stored in the memory 81 to implement the steps of any of the above data synchronization method embodiments. In a specific implementation scenario, the terminal 80 may include but is not limited to: a microcomputer, a server, and in addition, the terminal 80 may also include a mobile device such as a laptop computer and a tablet computer, which is not limited here.
[0096] Specifically, the processor 82 is used to control itself and the memory 81 to implement the steps of any of the above data synchronization method embodiments. The processor 82 can also be called a CPU (Central Processing Unit). The processor 82 may be an integrated circuit chip with signal processing capabilities. The processor 82 can also be a general-purpose processor, a digital signal processor (Digital Signal Processor, DSP), an application-specific integrated circuit (Application Specific Integrated Circuit, ASIC), a field-programmable gate array (Field-Programmable Gate Array, FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor, etc. In addition, the processor 82 can be implemented by an integrated circuit chip.
[0097] In the above scheme, the data synchronization method is applied to the control device of the data synchronization system, and the data synchronization system also includes a current master node and a current standby node, and the current master node and the current standby node are respectively communicated with the control device; the current master node is a node after the historical standby node that has completed synchronization historically is switched, and the current master node has control information and data information; the current standby node is a node after the historical master node that has completed synchronization historically is switched, and the current standby node has historical control information and historical data information; the data synchronization method includes: detecting the current synchronization state of the current standby node during the current synchronization process; based on the historical storage data stored before the current synchronization state of the current standby node, the control information and data information corresponding to the current master node, and the historical control information and historical data information corresponding to the current standby node, controlling the synchronization of the data information and / or control information of the current master node to the current standby node.
[0098] See also Figure 6 , Figure 6 The computer-readable storage medium 90 stores program instructions 901 that can be executed by a processor, and the program instructions 901 are used to implement the steps of any of the above data synchronization method embodiments.
[0099] In the above scheme, the data synchronization method is applied to the control device of the data synchronization system, and the data synchronization system also includes a current master node and a current standby node, and the current master node and the current standby node are respectively communicated with the control device; the current master node is a node after the historical standby node that has completed synchronization historically is switched, and the current master node has control information and data information; the current standby node is a node after the historical master node that has completed synchronization historically is switched, and the current standby node has historical control information and historical data information; the data synchronization method includes: detecting the current synchronization state of the current standby node during the current synchronization process; based on the historical storage data stored before the current synchronization state of the current standby node, the control information and data information corresponding to the current master node, and the historical control information and historical data information corresponding to the current standby node, controlling the synchronization of the data information and / or control information of the current master node to the current standby node.
[0100] In some embodiments, the functions or modules included in the device provided by the embodiments of the present disclosure can be used to execute the method described in the above method embodiments. The specific implementation can refer to the description of the above method embodiments, and for the sake of brevity, it will not be repeated here.
[0101] The above description of various embodiments tends to emphasize the differences between the various embodiments. The same or similar aspects can be referenced to each other, and for the sake of brevity, they will not be repeated herein.
[0102] In the several embodiments provided in the present application, it should be understood that the disclosed methods and devices can be implemented in other ways. For example, the device implementation described above is only schematic. For example, the division of modules or units is only a logical function division. There may be other division methods in actual implementation, such as units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, and the indirect coupling or communication connection of devices or units can be electrical, mechanical or other forms.
[0103] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0104] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium, including several instructions to enable a computer device (which can be a personal computer, server, or network device, etc.) or a processor to execute all or part of the steps of each implementation method of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program code.
[0105] The above are only implementation modes of the present invention, and are not intended to limit the patent protection scope of the present invention. Any equivalent structure or equivalent process transformation made using the contents of the present invention specification and drawings, or directly or indirectly applied in other related technical fields, are also included in the patent protection scope of the present invention.
Claims
1. A data synchronization method, characterized in that: A control device applied to a data synchronization system, the data synchronization system further comprising a current master node and a current standby node, the current master node and the current standby node being respectively connected to the control device in communication; the current master node is a node after switching from a historical standby node that has completed synchronization in history, and the current master node has control information and data information; the current standby node is a node after switching from a historical master node that has completed synchronization in history, and the current standby node has historical control information and historical data information; The data synchronization method comprises: Detecting a current synchronization state of the current standby node during the current synchronization process; the current synchronization state includes one of a start state, a transmission state, and an update state; Based on the historical storage data stored before the current synchronization state of the current standby node, the control information and the data information corresponding to the current master node, and the historical control information and the historical data information corresponding to the current standby node, control the synchronization of the data information and / or control information of the current master node to the current standby node; The step of synchronizing the data information and / or control information of the current master node to the current standby node based on the historical storage data stored before the current synchronization state of the current standby node, the control information and the data information corresponding to the current master node, and the historical control information and the historical data information corresponding to the current standby node includes: In response to the current synchronization state of the current standby node being the transmission state, extracting the historical storage data stored before the transmission state; the historical storage data stored before the transmission state includes the control information of the current master node, the historical control information of the current standby node, and synchronization difference data; Preprocess the historical data information of the current standby node based on the synchronization difference data, obtain the processing method of each historical data information corresponding to the current standby node and the data to be entered, and save them; Controlling synchronization of the data information corresponding to the data to be entered in the current master node to the current standby node, and processing the historical data information of the current standby node based on the processing method of each historical data information in the current standby node to obtain the data information of the current standby node; The current synchronization state of the current standby node is controlled to be updated to the updated state, and the historical control information of the current standby node is updated based on the control information of the current master node to obtain the control information of the current standby node.
2. The data synchronization method according to claim 1, characterized in that: The data synchronization method further includes: Detecting whether the current standby node has status record information during the current synchronization process; In response to the current standby node having the status record information, detecting a current synchronization state of the current standby node; In response to the current standby node not having the status record information, the control information and the data information corresponding to the current master node and the historical control information and the historical data information corresponding to the current standby node are acquired to generate the status record information.
3. The data synchronization method according to claim 2, characterized in that: The step of synchronizing the data information and / or control information of the current master node to the current standby node based on the historical storage data stored before the current synchronization state of the current standby node, the control information and the data information corresponding to the current master node, and the historical control information and the historical data information corresponding to the current standby node, further includes: In response to the current synchronization state of the current standby node being the start state, determining that the historical storage data stored before the start state is empty; Based on the data information of the current master node and the historical data information of the current standby node, the historical data information of the current standby node is updated to obtain the data information of the current standby node; The current synchronization state of the current standby node is controlled to be updated to the updated state, and the historical control information of the current standby node is updated based on the control information of the current master node to obtain the control information of the current standby node.
4. The data synchronization method according to claim 3, characterized in that: The updating the historical data information of the current standby node based on the data information of the current master node and the historical data information of the current standby node to obtain the data information of the current standby node includes: Generate synchronization difference data based on the data information of the current master node and the historical data information of the current standby node; The control information of the current master node, the historical control information of the current standby node and the synchronization difference data are saved; Controlling the updating of the current synchronization state of the current standby node to the transmission state, preprocessing the historical data information of the current standby node based on the synchronization difference data, obtaining the processing mode of each historical data information corresponding to the current standby node and the data to be entered and saving them; Control to synchronize the data information corresponding to the data to be entered in the current master node to the current standby node, process the historical data information of the current standby node based on the processing method of each historical data information in the current standby node, and obtain the data information of the current standby node.
5. The data synchronization method according to claim 2, characterized in that: The step of synchronizing the data information and / or control information of the current master node to the current standby node based on the historical storage data stored before the current synchronization state of the current standby node, the control information and the data information corresponding to the current master node, and the historical control information and the historical data information corresponding to the current standby node, further includes: In response to the current synchronization state of the current standby node being the update state, extracting the historical storage data stored before the update state; the historical storage data stored before the update state includes the control information of the current master node, the historical control information of the current standby node, the synchronization difference data, the processing method of each of the historical data information corresponding to the current standby node, and the data to be entered; The historical control information of the current standby node is updated based on the control information of the current master node to obtain the control information of the current standby node.
6. The data synchronization method according to any one of claims 3 to 5, characterized in that: The updating of the historical control information of the current standby node based on the control information of the current master node to obtain the control information of the current standby node includes: Marking the current standby node as a standby node; The control information of the current master node is controlled to be synchronized to the current standby node and the historical control information of the current standby node is deleted to obtain the control information of the current standby node.
7. The data synchronization method according to claim 2, characterized in that: The data synchronization method further includes: In response to the current synchronization state of the current standby node being an end state, the historical storage data stored before the end state is deleted; the historical storage data stored before the end state includes the control information of the current master node, the historical control information of the current standby node, the synchronization difference data, the processing method of each historical data information corresponding to the current standby node, and the data to be entered.
8. A terminal, characterized in that: The terminal includes a memory, a processor, and a computer program stored in the memory and running on the processor, and the processor is used to execute program data to implement the steps in the data synchronization method as described in any one of claims 1 to 7.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the data synchronization method as described in any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Data synchronization remediation and storage method and cluster device
CN111352959A
Database synchronization method, system and device and medium
CN114116885A
