CN114090690A - Data synchronization method and device and electronic equipment - Google Patents

Data synchronization method and device and electronic equipment Download PDF

Info

Publication number
CN114090690A
CN114090690A CN202111399746.0A CN202111399746A CN114090690A CN 114090690 A CN114090690 A CN 114090690A CN 202111399746 A CN202111399746 A CN 202111399746A CN 114090690 A CN114090690 A CN 114090690A
Authority
CN
China
Prior art keywords
data
newly
added data
newly added
database
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111399746.0A
Other languages
Chinese (zh)
Inventor
王章川
吕争让
侯中青
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Construction Bank Corp
Original Assignee
China Construction Bank Corp
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Construction Bank Corp filed Critical China Construction Bank Corp
Priority to CN202111399746.0A priority Critical patent/CN114090690A/en
Publication of CN114090690A publication Critical patent/CN114090690A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • G06F16/275Synchronous replication

Abstract

The present application relates to the field of data storage technologies, and in particular, to a data synchronization method, apparatus and electronic device, where the method includes: when the first newly added data in the master database is detected to be inconsistent with the second newly added data in the slave database, the first newly added data is imported into the backup table, then the data in the backup table is compared with the second newly added data, the data to be modified corresponding to the second newly added data is determined, and the data to be modified is adjusted to be consistent with the data in the backup table. Based on the data synchronization method, the data in the master database and the data in the slave database can be consistent under the condition that the data in the slave database does not need to be emptied, so that the problem of service interruption caused by emptying the data in the slave database is avoided.

Description

Data synchronization method and device and electronic equipment
Technical Field
The present application relates to the field of data storage technologies, and in particular, to a data synchronization method and apparatus, and an electronic device.
Background
In a distributed transaction system, it is usually necessary to synchronize partial data from a master database to each slave database, and during the data synchronization, consistency between synchronization data derived from the master database and synchronization data received from each slave database is also guaranteed.
At present, data is synchronized from the master database to the slave database, and generally, the data in the master database is totally exported, then the slave database is emptied, and finally the data exported from the master database is imported into the slave database, so that the data consistency between the master database and the slave database is realized.
The above method for data synchronization needs to empty the slave database, so that the slave database has no data for a while before data is imported, which causes service interruption of the device using the slave database.
Disclosure of Invention
The application provides a data synchronization method, a data synchronization device and electronic equipment, which can realize the consistency of data in a master database and a slave database under the condition of not emptying the data in the slave database, thereby avoiding the problem of service interruption caused by emptying the data in the slave database.
In a first aspect, the present application provides a data synchronization method, including:
when detecting that first newly-added data in a main database is inconsistent with second newly-added data in a secondary database, importing the first newly-added data into a backup table;
and comparing the data in the backup table with the second newly added data, determining to-be-modified data corresponding to the second newly added data, and adjusting the to-be-modified data to be consistent with the data in the backup table.
By the method, when the first newly added data in the master database and the second newly added data in the slave database are detected to be inconsistent, the first newly added data in the master database is led into the backup table, then the second newly added data in the slave database is adjusted to be consistent with the data in the backup table, and the data in the master database and the data in the slave database can be consistent under the condition that the data in the slave database does not need to be emptied, so that the problem of service interruption caused by emptying the data in the slave database is avoided.
In one possible design, before detecting that the first newly added data in the master database and the second newly added data in the slave database are inconsistent, the method includes:
determining first newly-added data of the master database in a preset time period and second newly-added data of the slave database in the preset time period;
creating a backup table in the secondary database, wherein the backup table is consistent with an original table structure, and the original table is used for storing the second newly-added data;
and judging whether the first newly added data is consistent with the second newly added data.
In the above manner, a backup table for storing the first newly added data is created and it is determined whether a data synchronization operation needs to be performed between the current master database and the slave database.
Further, the determining whether the first newly added data is consistent with the second newly added data includes:
respectively exporting the first newly added data and the second newly added data to obtain two data texts;
judging whether the number of the data in the two data texts is consistent;
if not, indicating that the first newly added data is inconsistent with the second newly added data;
if so, sorting the data in the two data texts according to a preset rule, and judging whether the two data corresponding to the same sequence number in the two data texts are consistent.
Based on the above manner, it is determined whether it is currently necessary to perform the data synchronization operation by determining whether the first newly added data in the master database and the second newly added data in the slave database are consistent.
Further, the importing the first newly added data into the backup table when detecting that the first newly added data in the master database and the second newly added data in the slave database are inconsistent comprises:
stopping updating data of a synchronization table in a master database when detecting that first newly-added data in the master database and second newly-added data in a slave database are inconsistent, wherein the synchronization table is used for storing the first newly-added data;
and importing the first newly added data into a backup table, wherein the backup table does not contain data.
By means of the method, the first newly-added data in the master database are imported into the backup table in the slave database, data query in the slave database is not affected, and reference data used for comparing with the second newly-added data in the slave database can be established.
Further, comparing the data in the backup table with the second newly added data, determining data to be modified corresponding to the second newly added data, and adjusting the data to be modified to be consistent with the data in the backup table, including:
matching any data in the backup table with any data in the second newly added data;
if first data is inconsistent with second data in the second newly-added data and the first data and the second data have the same identification, adjusting the second data to be consistent with the first data;
if the identification corresponding to the first data is inconsistent with the identification corresponding to all the data in the second newly added data, importing the first data into a secondary database;
and if the identifications corresponding to all the data in the backup table are inconsistent with the identifications corresponding to the second data, deleting the second data.
By the method, the difference data, the redundant data and the missing data corresponding to the second newly added data in the secondary database can be determined, and the second newly added data is adjusted to be consistent with the first newly added data, so that the synchronization between the primary database and the secondary database is realized.
In one possible design, after the adjusting the data to be modified to be consistent with the data in the backup table, the method includes:
deleting the backup table; and
continuing to update data to a synchronization table in the master database, the synchronization table being used to store the first newly added data, and synchronizing the updated data to a slave database.
By the method, after the synchronous operation of the master database and the slave database is completed, the backup table is deleted to save the space of the slave database, and the writing function of the synchronous table in the master database is continuously started to ensure the updating of the master database.
In a second aspect, the present application provides a data synchronization apparatus, the apparatus comprising:
the import module is used for importing the first newly added data into the backup table when the inconsistency between the first newly added data in the main database and the second newly added data in the secondary database is detected;
and the adjusting module is used for comparing the data in the backup table with the second newly-added data, determining data to be modified corresponding to the second newly-added data, and adjusting the data to be modified to be consistent with the data in the backup table.
In one possible design, the apparatus further includes:
the determining module is used for determining first newly-added data of the master database in a preset time period and second newly-added data of the slave database in the preset time period;
the creating module is used for creating a backup table which is consistent with an original table structure in the slave database, wherein the original table is used for storing the second newly-added data;
and the judging module is used for judging whether the first newly added data is consistent with the second newly added data.
Further, the determination module is specifically configured to:
respectively exporting the first newly added data and the second newly added data to obtain two data texts;
judging whether the number of the data in the two data texts is consistent;
if not, indicating that the first newly added data is inconsistent with the second newly added data;
if so, sorting the data in the two data texts according to a preset rule, and judging whether the two data corresponding to the same sequence number in the two data texts are consistent.
Further, the import module is specifically configured to:
stopping updating data of a synchronization table in a master database when detecting that first newly-added data in the master database and second newly-added data in a slave database are inconsistent, wherein the synchronization table is used for storing the first newly-added data;
and importing the first newly added data into a backup table, wherein the backup table does not contain data.
Further, the adjusting module is specifically configured to:
matching any data in the backup table with any data in the second newly added data;
if first data is inconsistent with second data in the second newly-added data and the first data and the second data have the same identification, adjusting the second data to be consistent with the first data;
if the identification corresponding to the first data is inconsistent with the identification corresponding to all the data in the second newly added data, importing the first data into a secondary database;
and if the identifications corresponding to all the data in the backup table are inconsistent with the identifications corresponding to the second data, deleting the second data.
In one possible design, the apparatus further includes:
deleting the backup table; and
continuing to update data to a synchronization table in the master database, the synchronization table being used to store the first newly added data, and synchronizing the updated data to a slave database.
In a third aspect, the present application provides an electronic device, comprising:
a memory for storing a computer program;
and the processor is used for realizing the steps of the data synchronization method when executing the computer program stored in the memory.
In a fourth aspect, the present application provides a computer-readable storage medium having stored therein a computer program which, when executed by a processor, implements the above-mentioned data synchronization method steps.
In a fifth aspect, the present application provides a computer program product which, when run on a computer, causes the computer to perform the above-mentioned data synchronization method steps.
Based on the data synchronization method, when the first newly added data in the master database and the second newly added data in the slave database are detected to be inconsistent, the first newly added data in the master database is led into the backup table, and then the second newly added data in the slave database is adjusted to be consistent with the data in the backup table.
For each of the second to fifth aspects and possible technical effects of each aspect, reference is made to the above description of the possible technical effects of the first aspect or various possible solutions of the first aspect, and repeated descriptions are omitted here.
Drawings
Fig. 1 is a flowchart of a data synchronization method provided in the present application;
fig. 2 is a schematic structural diagram of a data synchronization apparatus provided in the present application;
fig. 3 is a schematic structural diagram of an electronic device provided in the present application.
Detailed Description
In order to make the objects, technical solutions and advantages of the present application more clear, the present application will be further described in detail with reference to the accompanying drawings. The particular methods of operation in the method embodiments may also be applied to apparatus embodiments or system embodiments. It should be noted that "a plurality" is understood as "at least two" in the description of the present application. "and/or" describes the association relationship of the associated objects, meaning that there may be three relationships, e.g., a and/or B, which may mean: a exists alone, A and B exist simultaneously, and B exists alone. A is connected with B and can represent: a and B are directly connected and A and B are connected through C. In addition, in the description of the present application, the terms "first," "second," and the like are used for descriptive purposes only and are not intended to indicate or imply relative importance nor order to be construed.
The embodiments of the present application will be described in detail below with reference to the accompanying drawings.
In a distributed transaction system, data is synchronized from a master database to a slave database, generally, the data in the master database is totally exported, then the slave database is emptied, and finally the data exported from the master database is imported into the slave database, so that the data consistency between the master database and the slave database is realized.
In order to solve the above problems, the present application provides a data access method, when detecting that the newly added data in the master database is inconsistent with the newly added data in the slave database, the newly added data in the master database is imported into a newly created backup table in the slave database, then the data in the backup table is compared with the newly added data in the slave database to determine the data to be modified in the slave database, and the data to be modified is adjusted to be consistent with the data in the backup table.
By the data synchronization method, the data in the master database and the data in the slave database can be consistent, and when the data in the master database is synchronized to the slave database, the data in the slave database does not need to be emptied, so that the service interruption of equipment using the slave database is avoided. The method and the device in the embodiment of the application are based on the same technical concept, and because the principles of the problems solved by the method and the device are similar, the device and the embodiment of the method can be mutually referred, and repeated parts are not described again.
As shown in fig. 1, a flowchart of a data synchronization method provided in the present application specifically includes the following steps:
s11, when the first newly added data in the main database and the second newly added data in the secondary database are detected to be inconsistent, importing the first newly added data into a backup table;
in the embodiment of the application, before the data in the master database is synchronized to the slave database, a backup table needs to be created, wherein the backup table does not contain the data; and then detecting whether the data in the master database and the data in the slave database are consistent, if so, not needing to carry out data synchronization operation, and if not, stopping updating the data of a synchronization table in the master database, wherein the synchronization table is used for storing the newly added data, and synchronizing the data in the master database to the slave database through a backup table, thereby ensuring the consistency of the data in the master database and the data in the slave database.
In the above process, the method of detecting whether the data in the master database and the data in the slave database are consistent may be:
determining first newly-added data of a master database in a preset time period and second newly-added data of a slave database in the same preset time period, wherein the preset time period can be determined according to the data synchronization condition between the master database and the slave database, for example, the time point of last completion of synchronization of the data in the master database to the slave database is 11 months, 28 days, 24:00, and the current time point is 11 months, 29 days, 24:00, so that in order to ensure that all the newly-added data in the master database are synchronized to the slave database, the preset time period can be set to be 11 months, 28 days, 24:00 to 11 months, 29 days, 24:00, and then the newly-added data of the master database in the preset time period is marked as first newly-added data, and the newly-added data of the slave database in the preset time period is marked as second new data;
next, whether the first newly added data is consistent with the second newly added data is determined by a comparison method, and the specific determination process is as follows:
and respectively exporting the first newly added data and the second newly added data to obtain two data texts, and judging whether the number of the data in the two data texts is consistent.
If the number of the data in the two data texts is inconsistent, the first newly added data and the second newly added data are inconsistent.
And if the number of the data in the two data texts is consistent, sequencing the data in the two data texts according to a preset rule, and judging whether the two data corresponding to the same sequence number in the two data texts are consistent, wherein the preset rule can be sequencing according to the time sequence of the newly added data.
For example, the increasing time of the data a, b, and c in the first newly added data is respectively 10:58 on 29 days of 11 months, 10: 35 on 29 days of 11 months, 11:08 on 29 days of 11 months, then, according to the sequence of time, the data a, b, and c in the text corresponding to the first newly added data are sorted into a, c, and b, that is, the sequence numbers corresponding to a, c, and b are respectively 1, 2, and 3, and similarly, after the data A, C, B in the text corresponding to the second newly added data is sorted according to the same preset rule, the corresponding text data is A, B, C, that is, the sequence numbers corresponding to A, B, C are respectively 1, 2, and 3. At this time, based on the same serial number, a can be compared with a, B can be compared with B, and C can be compared with C;
if two data corresponding to the same sequence number in the two data texts are inconsistent, the first newly-added data and the second newly-added data are inconsistent.
When the first newly added data and the second newly added data are detected to be inconsistent, data synchronization operation needs to be carried out on the master database and the slave database, and at the moment, data updating on a synchronization table in the master database is stopped, wherein the synchronization table is used for storing the first newly added data;
and then, importing the first newly-added data into a backup table, wherein the data in the backup table is used as reference data of the newly-added data in the slave database, and when the device calls the data in the slave database, only the data in the original table is used, and the data in the backup table does not participate in the business process.
Because the data in the original table of the slave database is not emptied, the condition of service interruption can not occur when the equipment inquires the data in the slave database.
And S12, comparing the data in the backup table with the second newly added data, determining the data to be modified in the second newly added data, and adjusting the data to be modified to be consistent with the data in the backup table.
In the embodiment of the application, after the first newly added data is imported into the backup table, the data in the backup table is used as a reference object, and the data in the backup table is compared with the second newly added data in the slave database, so that the data to be modified corresponding to the second newly added data can be determined, wherein the data to be modified at least comprises difference data, redundant data and missing data. Specifically, the method for determining the data to be modified corresponding to the second new data may be:
matching any data in the backup table with any data in the second newly added data;
if the first data is inconsistent with the second data in the second newly-added data and the first data and the second data have the same identifier, determining that the second data is differential data, and adjusting the second data to be consistent with the first data, for example, the data in the backup table is as shown in table 1:
name (I) Department of department Age (age)
Zhang San Research and development department Age 26 years old
Li Si Research and development department Age 27
Wang Wu Research and development department Age 27 years old
TABLE 1
The second new data from the database is shown in table 2:
name (I) Department of department Age (age)
Zhang San Research and development department Age 26 years old
Li Si Research and development department Age 27
Wang Wu Research and development department Age 28 years old
TABLE 2
Through comparison, the 'wangwu research and development department, age 27' in table 1 and the 'wangwu research and development department, age 28' in table 2 are inconsistent and correspond to the same identifier, 'wangwu', and at this time, it can be determined that the 'age 28' in table 2 is difference data, and therefore, the 'age 28' in table 2 is adjusted to 'age 27';
if the identifier corresponding to the first data is not consistent with the identifiers corresponding to all the data in the second newly added data, determining that the first data is missing data in the secondary database, and importing the first data into the second newly added data, for example, the data in the backup table refers to table 1, the newly added data in the secondary database is shown in table 3, and the specific data in table 3 is as follows:
name (I) Department of department Age (age)
Zhang San Research and development department Age 26 years old
Li Si Research and development department Age 27
TABLE 3
By comparing any data in table 1 with any data in table 3, it is found that "wang wu" in table 1 cannot match all names in table 3, and therefore, the data "wang wu research and development department, 27 years old" corresponding to "wang wu" can be determined as missing data in table 2, and therefore, "wang wu research and development department, 27 years old" is added to table 2;
and if the identifications corresponding to all the data in the backup table are inconsistent with the identifications corresponding to the second data, determining that the second data are redundant data. For example, if the data in the backup table is shown in table 3 and the second newly added data in the database is shown in table 1, the data "wang wu research and development department 27 years" in table 1 is deleted because it can be determined that "wang wu research and development department 27 years" is the redundant data in table 1 by comparing any data in table 3 with any data in table 1.
In a possible design, after the data to be modified in the slave database is adjusted, the data in the slave database can be consistent with the data in the master database, and further, the backup table can be deleted, so that the space of the slave database is saved, the writing function of the synchronization table in the master database can be recovered, and the updating of the data of the synchronization table is ensured.
According to the data synchronization method, when the first newly added data in the master database and the second newly added data in the slave database are detected to be inconsistent, the first newly added data in the master database is led into the backup table, then the second newly added data in the slave database is adjusted to be consistent with the data in the backup table, the data in the master database and the data in the slave database can be consistent, and the slave database does not need to be emptied in the data synchronization process, so that service interruption caused by inquiring the data in the slave database can be avoided.
Based on the same inventive concept, an embodiment of the present application further provides a data synchronization apparatus, as shown in fig. 2, which is a schematic structural diagram of the data synchronization apparatus in the present application, and the apparatus includes:
the import module 21 is configured to import the first newly added data into the backup table when detecting that the first newly added data in the master database is inconsistent with the second newly added data in the slave database;
and an adjusting module 22, configured to compare the data in the backup table with the second newly added data, determine data to be modified corresponding to the second newly added data, and adjust the data to be modified to be consistent with the data in the backup table.
In one possible design, the apparatus further includes:
the determining module is used for determining first newly-added data of the master database in a preset time period and second newly-added data of the slave database in the preset time period;
the creating module is used for creating a backup table which is consistent with an original table structure in the slave database, wherein the original table is used for storing the second newly-added data;
and the judging module is used for judging whether the first newly added data is consistent with the second newly added data.
Further, the determination module is specifically configured to:
respectively exporting the first newly added data and the second newly added data to obtain two data texts;
judging whether the number of the data in the two data texts is consistent;
if not, indicating that the first newly added data is inconsistent with the second newly added data;
if so, sorting the data in the two data texts according to a preset rule, and judging whether the two data corresponding to the same sequence number in the two data texts are consistent.
Further, the import module 21 is specifically configured to:
stopping updating data of a synchronization table in a master database when detecting that first newly-added data in the master database and second newly-added data in a slave database are inconsistent, wherein the synchronization table is used for storing the first newly-added data;
and importing the first newly added data into a backup table, wherein the backup table does not contain data.
Further, the adjusting module 22 is specifically configured to:
matching any data in the backup table with any data in the second newly added data;
if first data is inconsistent with second data in the second newly-added data and the first data and the second data have the same identification, adjusting the second data to be consistent with the first data;
if the identification corresponding to the first data is inconsistent with the identification corresponding to all the data in the second newly added data, importing the first data into a secondary database;
and if the identifications corresponding to all the data in the backup table are inconsistent with the identifications corresponding to the second data, deleting the second data.
In one possible design, the apparatus further includes:
deleting the backup table; and
continuing to update data to a synchronization table in the master database and synchronizing the updated data to a slave database, wherein the synchronization table is used for storing the first newly-added data.
By the data synchronization device, when the first newly added data in the master database and the second newly added data in the slave database are detected to be inconsistent, the first newly added data in the master database is led into the backup table, then the second newly added data in the slave database is adjusted to be consistent with the data in the backup table, the data in the master database and the data in the slave database can be consistent, and the slave database does not need to be emptied in the data synchronization process, so that service interruption caused by inquiring the data in the slave database can be avoided.
Based on the same inventive concept, an embodiment of the present application further provides an electronic device, where the electronic device can implement the function of the foregoing data synchronization apparatus, and with reference to fig. 3, the electronic device includes:
at least one processor 31, and a memory 32 connected to the at least one processor 31, in this embodiment, a specific connection medium between the processor 31 and the memory 32 is not limited, and fig. 3 illustrates an example where the processor 31 and the memory 32 are connected through a bus 30. The bus 30 is shown in fig. 3 by a thick line, and the connection between other components is merely illustrative and not limited thereto. The bus 30 may be divided into an address bus, a data bus, a control bus, etc., and is shown with only one thick line in fig. 3 for ease of illustration, but does not represent only one bus or type of bus. Alternatively, the processor 31 may also be referred to as a controller, without limitation to name a few.
In the embodiment of the present application, the memory 32 stores instructions executable by the at least one processor 31, and the at least one processor 31 can execute the data synchronization method discussed above by executing the instructions stored in the memory 32. The processor 31 may implement the functions of the various modules in the apparatus shown in fig. 2.
The processor 31 is a control center of the apparatus, and may be connected to various parts of the entire control device by using various interfaces and lines, and perform various functions of the apparatus and process data by operating or executing instructions stored in the memory 32 and calling data stored in the memory 32, thereby performing overall monitoring of the apparatus.
In one possible design, processor 31 may include one or more processing units, and processor 31 may integrate an application processor, which primarily handles operating systems, user interfaces, application programs, and the like, and a modem processor, which primarily handles wireless communications. It will be appreciated that the modem processor described above may not be integrated into the processor 31. In some embodiments, the processor 31 and the memory 32 may be implemented on the same chip, or in some embodiments, they may be implemented separately on separate chips.
The processor 31 may be a general-purpose processor, such as a Central Processing Unit (CPU), digital signal processor, application specific integrated circuit, field programmable gate array or other programmable logic device, discrete gate or transistor logic, discrete hardware components, or any combination thereof, that implements or performs the methods, steps, and logic blocks disclosed in embodiments of the present application. A general purpose processor may be a microprocessor or any conventional processor or the like. The steps of the data synchronization method disclosed in the embodiments of the present application may be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules in the processor.
The memory 32, which is a non-volatile computer-readable storage medium, may be used to store non-volatile software programs, non-volatile computer-executable programs, and modules. The Memory 32 may include at least one type of storage medium, and may include, for example, a flash Memory, a hard disk, a multimedia card, a card-type Memory, a Random Access Memory (RAM), a Static Random Access Memory (SRAM), a Programmable Read Only Memory (PROM), a Read Only Memory (ROM), a charge Erasable Programmable Read Only Memory (EEPROM), a magnetic Memory, a magnetic disk, an optical disk, and the like. The memory 32 is any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer, but is not limited to such. The memory 32 in the embodiments of the present application may also be circuitry or any other device capable of performing a storage function for storing program instructions and/or data.
The processor 31 is programmed to solidify the code corresponding to the data synchronization method described in the foregoing embodiment into the chip, so that the chip can execute the steps of the data synchronization method of the embodiment shown in fig. 1 when running. How to program the processor 31 is well known to those skilled in the art and will not be described in detail here.
Based on the same inventive concept, the present application also provides a storage medium storing computer instructions, which when executed on a computer, cause the computer to perform the data synchronization method discussed above.
In some possible embodiments, the aspects of the data synchronization method provided herein may also be implemented in the form of a program product comprising program code for causing a control device to perform the steps of the data synchronization method according to various exemplary embodiments of the present application described above in this specification, when the program product is run on an apparatus.
The program product may employ any combination of one or more readable media. The readable medium may be a readable signal medium or a readable storage medium. A readable storage medium may be, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the foregoing. More specific examples (a non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable disk, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
The program product of the data synchronization method provided in the embodiments of the present invention may employ a portable compact disc read only memory (CD-ROM) and include program code, and may be run on a computing device. However, the program product of the present invention is not limited in this regard and, in the present document, a readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
A readable signal medium may include a propagated data signal with readable program code embodied therein, for example, in baseband or as part of a carrier wave. Such a propagated data signal may take any of a variety of forms, including, but not limited to, electro-magnetic, optical, or any suitable combination thereof. A readable signal medium may also be any readable medium that is not a readable storage medium and that can communicate, propagate, or transport a program for use by or in connection with an instruction execution system, apparatus, or device.
Program code embodied on a readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.
Program code for carrying out operations for aspects of the present invention may be written in any combination of one or more programming languages, including an object oriented programming language such as Java, C + + or the like and conventional procedural programming languages, such as the "C" programming language or similar programming languages. The program code may execute entirely on the user's computing device, partly on the user's device, as a stand-alone software package, partly on the user's computing device and partly on a remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device may be connected to the user computing device over any kind of network, including a Local Area Network (LAN) or a Wide Area Network (WAN), or may be connected to an external computing device (e.g., over the internet using an internet service provider).
It should be noted that although several units or sub-units of the apparatus are mentioned in the above detailed description, such division is merely exemplary and not mandatory. Indeed, the features and functions of two or more of the units described above may be embodied in one unit, according to embodiments of the invention. Conversely, the features and functions of one unit described above may be further divided into embodiments by a plurality of units.
Moreover, while the operations of the method of the invention are depicted in the drawings in a particular order, this does not require or imply that the operations must be performed in this particular order, or that all of the illustrated operations must be performed, to achieve desirable results. Additionally or alternatively, certain steps may be omitted, multiple steps combined into one step execution, and/or one step broken down into multiple step executions.
As will be appreciated by one skilled in the art, embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the application. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
It will be apparent to those skilled in the art that various changes and modifications may be made in the present application without departing from the spirit and scope of the application. Thus, if such modifications and variations of the present application fall within the scope of the claims of the present application and their equivalents, the present application is intended to include such modifications and variations as well.

Claims (15)

1. A method of data synchronization, the method comprising:
when detecting that first newly-added data in a main database is inconsistent with second newly-added data in a secondary database, importing the first newly-added data into a backup table;
and comparing the data in the backup table with the second newly added data, determining to-be-modified data corresponding to the second newly added data, and adjusting the to-be-modified data to be consistent with the data in the backup table.
2. The method of claim 1, prior to detecting an inconsistency between the first newly added data in the master database and the second newly added data in the slave database, comprising:
determining first newly-added data of the master database in a preset time period and second newly-added data of the slave database in the preset time period;
creating a backup table in the secondary database, wherein the backup table is consistent with an original table structure, and the original table is used for storing the second newly-added data;
and judging whether the first newly added data is consistent with the second newly added data.
3. The method of claim 2, wherein the determining whether the first new added data and the second added data are consistent comprises:
respectively exporting the first newly added data and the second newly added data to obtain two data texts;
judging whether the number of the data in the two data texts is consistent;
if not, indicating that the first newly added data is inconsistent with the second newly added data;
if yes, sorting the data in the two data texts according to a preset rule, and judging whether the two data corresponding to the same sequence number in the two data texts are consistent.
4. The method of claim 1, wherein importing the first added data into a backup table upon detecting that the first added data in the master database and the second added data in the slave database are inconsistent comprises:
stopping updating data of a synchronization table in a master database when detecting that first newly-added data in the master database and second newly-added data in a slave database are inconsistent, wherein the synchronization table is used for storing the first newly-added data;
and importing the first newly added data into a backup table, wherein the backup table does not contain data.
5. The method of claim 1, wherein comparing the data in the backup table with the second newly added data to determine data to be modified corresponding to the second newly added data, and adjusting the data to be modified to be consistent with the data in the backup table comprises:
matching any data in the backup table with any data in the second newly added data;
if first data is inconsistent with second data in the second newly-added data and the first data and the second data have the same identification, adjusting the second data to be consistent with the first data;
if the identification corresponding to the first data is inconsistent with the identification corresponding to all the data in the second newly added data, importing the first data into a secondary database;
and if the identifications corresponding to all the data in the backup table are inconsistent with the identifications corresponding to the second data, deleting the second data.
6. The method of claim 1, wherein after the adjusting the data to be modified to be consistent with the data in the backup table, comprising:
deleting the backup table; and
continuing to update data to a synchronization table in the master database, the synchronization table being used to store the first newly added data, and synchronizing the updated data to a slave database.
7. A data synchronization apparatus, the apparatus comprising:
the import module is used for importing the first newly added data into the backup table when the inconsistency between the first newly added data in the main database and the second newly added data in the secondary database is detected;
and the adjusting module is used for comparing the data in the backup table with the second newly-added data, determining data to be modified corresponding to the second newly-added data, and adjusting the data to be modified to be consistent with the data in the backup table.
8. The apparatus of claim 7, wherein the apparatus further comprises:
the determining module is used for determining first newly-added data of the master database in a preset time period and second newly-added data of the slave database in the preset time period;
the creating module is used for creating a backup table which is consistent with an original table structure in the slave database, wherein the original table is used for storing the second newly-added data;
and the judging module is used for judging whether the first newly added data is consistent with the second newly added data.
9. The apparatus of claim 8, wherein the determination module is specifically configured to:
respectively exporting the first newly added data and the second newly added data to obtain two data texts;
judging whether the number of the data in the two data texts is consistent;
if not, indicating that the first newly added data is inconsistent with the second newly added data;
if so, sorting the data in the two data texts according to a preset rule, and judging whether the two data corresponding to the same sequence number in the two data texts are consistent.
10. The apparatus of claim 7, wherein the import module is specifically configured to:
stopping updating data of a synchronization table in a master database when detecting that first newly-added data in the master database and second newly-added data in a slave database are inconsistent, wherein the synchronization table is used for storing the first newly-added data;
and importing the first newly added data into a backup table, wherein the backup table does not contain data.
11. The apparatus of claim 7, wherein the adjustment module is specifically configured to:
matching any data in the backup table with any data in the second newly added data;
if first data is inconsistent with second data in the second newly-added data and the first data and the second data have the same identifier, adjusting the second data to be consistent with the first data;
if the identification corresponding to the first data is inconsistent with the identification corresponding to all the data in the second newly added data, importing the first data into a secondary database;
and if the identifications corresponding to all the data in the backup table are inconsistent with the identifications corresponding to the second data, deleting the second data.
12. The apparatus of claim 7, wherein the apparatus further comprises:
deleting the backup table; and
continuing to update data to a synchronization table in the master database, the synchronization table being used to store the first newly added data, and synchronizing the updated data to a slave database.
13. An electronic device, comprising:
a memory for storing a computer program;
a processor for implementing the method steps of any one of claims 1-6 when executing the computer program stored on the memory.
14. A computer-readable storage medium, characterized in that a computer program is stored in the computer-readable storage medium, which computer program, when being executed by a processor, carries out the method steps of any one of claims 1-6.
15. A computer program product, characterized in that, when the computer program product is run on a computer, it causes the computer to perform the method according to any of claims 1-6.
CN202111399746.0A 2021-11-24 2021-11-24 Data synchronization method and device and electronic equipment Pending CN114090690A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111399746.0A CN114090690A (en) 2021-11-24 2021-11-24 Data synchronization method and device and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111399746.0A CN114090690A (en) 2021-11-24 2021-11-24 Data synchronization method and device and electronic equipment

Publications (1)

Publication Number Publication Date
CN114090690A true CN114090690A (en) 2022-02-25

Family

ID=80303690

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111399746.0A Pending CN114090690A (en) 2021-11-24 2021-11-24 Data synchronization method and device and electronic equipment

Country Status (1)

Country Link
CN (1) CN114090690A (en)

Similar Documents

Publication Publication Date Title
CN107590207B (en) Data synchronization method and device and electronic equipment
CN108256113B (en) Data blood relationship mining method and device
CN110321339B (en) Data migration method, device, equipment and storage medium
CN110347545A (en) A kind of test method and device of business platform cache policy
CN108536745B (en) Shell-based data table extraction method, terminal, equipment and storage medium
CN105808653A (en) User label system-based data processing method and device
CN111290813B (en) Software interface field data standardization method, device, equipment and medium
CN112308727A (en) Insurance claim settlement service processing method and device
CN107153680B (en) Method and system for on-line node expansion of distributed memory database
CN111125067A (en) Data maintenance method and device
CN112148713B (en) Method and device for data migration between heterogeneous databases
CN107391539B (en) Transaction processing method, server and storage medium
CN111143463B (en) Construction method and device of bank data warehouse based on topic model
CN110209534B (en) System and method for automatically backing up mysql database
CN114090690A (en) Data synchronization method and device and electronic equipment
CN109710698A (en) A kind of data assemblage method, device, electronic equipment and medium
CN112749147A (en) Method and device for merging and migrating data tables in database
CN109857727A (en) A kind of local data base reconstructing method, equipment and storage medium
CN110858199A (en) Document data distributed computing method and device
CN112817931B (en) Incremental version file generation method and device
CN114116908A (en) Data management method and device and electronic equipment
CN109086279B (en) Report caching method and device
CN112287027A (en) Database synchronization method, device, equipment and storage medium
CN112000671A (en) Block chain-based database table processing method, device and system
CN110597802A (en) Message processing method and 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