Data synchronization method and device, electronic equipment and computer readable storage medium

By setting the first source indication information in the source database to record the data operation time and issuing synchronization instructions to the target side when incremental change information is detected, the data loss caused by data synchronization is solved, and the final consistency and reliability of data synchronization are achieved.

CN120162382APending Publication Date: 2025-06-17SHENZHEN JIUNIU YIMAO INTELLIGENT IOT TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510251939.3
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-03-03
Publication Date
2025-06-17

AI Technical Summary

Technical Problem

During the data synchronization process, network jitter, synchronization link abnormalities and other factors may lead to data synchronization loss, which will lead to differences in data between the target and the source, causing data out of control.

Method used

By setting the first source indication information in the source database, recording the time information of each data operation, and issuing synchronization instructions to the target end when the incremental change information is detected to ensure the repeatability and consistency of data synchronization.

Benefits of technology

It effectively avoids data out of control when there is a difference between the target and source data, ensures the ultimate consistency of data synchronization, and improves the reliability and stability of data synchronization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120162382A_ABST
    Figure CN120162382A_ABST
Patent Text Reader

Abstract

The invention provides a data synchronization method and device, electronic equipment and a computer readable storage medium. The data synchronization method comprises the steps that a control source end responds to a received instruction for executing first data operation, the first data operation is carried out on a source database according to a preset rule, first source indication information is set, and the first source indication information is time information for executing the first data operation; in response to the detected first incremental change information, a first synchronization instruction is sent to a target end, the first synchronization instruction is an instruction for synchronizing the first data operation to a target database, and the first incremental change information is information that the source database is changed; the first incremental change information comprises change information of the first source indication information. The problem of data out-of-control generated when the data of the target end and the data of the source end are different can be avoided.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of database technology, and in particular, to a method and device for data synchronization, an electronic device, and a computer-readable storage medium. Background Art

[0002] With the continuous development of database technology, more and more databases are applied in various industries. Multiple databases may be used simultaneously in applications. To ensure business continuity, in many cases, data synchronization operations need to be performed on data tables in different databases. Due to factors such as network jitter and abnormal synchronization links, there is a possibility of data loss during data synchronization. When data synchronization is accidentally lost, the user writes data at the source end and reads data at the target end. Since the synchronization is not successful, the query will find that this data is incorrect. Before the external data verification and data compensation are successful, the user performs an update operation again. Since the source end information has changed, this update operation has no data change for the source end, so the incremental parsing of data synchronization cannot be triggered, and thus data synchronization to the target end cannot be performed, resulting in a problem of data out of control. Summary of the Invention

[0003] This application provides a method and device for data synchronization, an electronic device, and a computer-readable storage medium, which helps to avoid the problem of data out of control when there are differences between the target end and the source end data. The following introduces each aspect involved in this application.

[0004] In a first aspect, this application provides a method for data synchronization, including: controlling the source end to respond to an instruction to execute a first data operation, performing the first data operation on the source database according to a preset rule, and setting first source indication information. A field representing the first source indication information is configured in the data table structure of the source database, and the first source indication information is time information for executing the first data operation; in response to detecting first incremental change information, sending a first synchronization instruction to the target end, where the first synchronization instruction is an instruction to synchronize the first data operation to the target database, the first incremental change information is information indicating a change in the source database, and the first incremental change information includes change information of the first source indication information.

[0005] In a second aspect, the present application provides a data synchronization device, including: a first control module, configured to control the source end to perform the first data operation on the source database according to a preset rule and set first source indication information in response to receiving an instruction to perform the first data operation, where a field representing the first source indication information is configured in the data table structure of the source database, and the first source indication information is time information indicating that the data of the target row in the source database has changed due to the execution of the first data operation; a sending module, configured to send a first synchronization instruction to the target end in response to detecting first incremental change information, where the first synchronization instruction is an instruction to synchronize the first data operation to the target database, the first incremental change information is information indicating that the source database has changed, and the first incremental change information includes change information of the first source indication information.

[0006] In a third aspect, the present application provides an electronic device, including: a memory, configured to store code; a processor, connected to the memory, configured to execute the code stored in the memory, so that the electronic device executes the method described in the first aspect.

[0007] In a fourth aspect, an embodiment of the present application provides a non-volatile computer-readable storage medium, on which a computer program is stored, and the computer program is used to implement the method described in the first aspect when executed.

[0008] In a fifth aspect, an embodiment of the present application provides a computer program product, which, when running on an electronic device, causes the electronic device to execute the method described in the first aspect.

[0009] In the embodiments of the present application, with the help of the first source indication information, when the user performs data operations (insertion, deletion, modification) on the source database, and when repeating data operations, the first source indication information can record the time information of executing the data operation. The times of different data operations are different. Therefore, in the embodiments of the present application, each time a data operation is performed on the source database, it can trigger a change in the source database. The synchronization component can parse the incremental change from the source end, detect the incremental information, and trigger data synchronization. When data synchronization is lost, it can adaptively and repeatedly trigger the lost data synchronization, which helps to avoid the problem of data out of control caused by differences between the target end and the source end data. BRIEF DESCRIPTION OF THE DRAWINGS

[0010] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for the description in the embodiments of the present application.

[0011] Figure 1 is a schematic diagram of data synchronization provided by the related art.

[0012] Figure 2It is a schematic diagram of data synchronization loss provided by the related art.

[0013] Figure 3 It is a schematic flowchart of the data synchronization method provided by the embodiments of the present application.

[0014] Figure 4 It is Figure 3 a schematic diagram of a possible implementation manner of the method shown.

[0015] Figure 5 It is Figure 3 a schematic diagram of another possible implementation manner of the method shown.

[0016] Figure 6 It is Figure 3 a schematic diagram of still another possible implementation manner of the method shown.

[0017] Figure 7 It is a schematic diagram of the data synchronization device provided by the embodiments of the present application.

[0018] Figure 8 It is a schematic diagram of the component unit / partial component unit of the electronic device provided by the embodiments of the present application. Detailed implementation manners

[0019] Next, the technical solutions in the embodiments of the present application will be clearly and completely described in conjunction with the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all of the embodiments. The same or similar reference numerals are used to represent the same or similar modules in the drawings. It should be understood that the drawings are only schematic, and the protection scope of the present application is not limited thereto.

[0020] First, the application scenarios involved in the embodiments of the present application will be introduced.

[0021] In the digital age, the amount of data that enterprises need to process is increasing, the data types and scenario requirements are becoming more and more complex, and traditional data centers are difficult to meet the data needs of modern enterprises. With the continuous development of database technology, more and more databases are applied in various industries. Multiple databases may be used simultaneously in applications. In order to ensure business continuity, in many cases, data synchronization operations need to be performed on data tables in different databases. Through data synchronization technology, data is synchronously transferred from the source end to the target end in real time to achieve data sharing and integration, break data islands, and achieve data disaster recovery, data migration, local access, data aggregation, etc.

[0022] Such as Figure 1As shown in the figure, the application on the source side can perform write operations on the source database, such as data addition (insert), deletion (delete), and update operations on the source database. The data transmission tool (Data Transmission Service, DTS) can regularly copy the full amount of data in the source database through a scheduled task, parse out the incremental changes, and synchronize the data operations to the target database.

[0023] Data consistency between the target side and the source side is very important. However, due to factors such as network jitter and abnormal synchronization links, data synchronization may be lost. Therefore, when using the DTS tool for data synchronization, it is necessary to regularly check the data on the source side and the target side to confirm whether there are differences between the data on the source side and the target side, and whether there is data loss during the data synchronization process, and then perform data compensation.

[0024] During data synchronization, it is inevitable that data synchronization is lost. It is necessary to ensure that after data synchronization is lost, data compensation can be effectively performed to make the data on the target side and the source side finally consistent. And during the process of achieving final data consistency, users cannot lose control of the data, otherwise it will seriously affect the user experience. The following is an example of data loss of control.

[0025] As Figure 2 shown in the figure, the source side changes the value of a for the data with b = 1 in the t1 table, but it is not synchronized to the target side, and this row of data in the target side has not been changed. At this time, if the target side reads the data with b = 1, it will read dirty data. If there is no guarantee of final data consistency and the value of a for the data with b = 1 in the t1 table on the target side is changed to 1, then this data will always be incorrect when read on the target side.

[0026] To ensure data consistency between the source side and the target side of data synchronization, not only external data verification and compensation are required, but also the application service needs to have the ability to correct errors to promote the final consistency of data between the source side and the target side. For example: when data synchronization is accidentally lost, the user writes data from the source side and reads data from the target side. Since the synchronization is not successful, the query will find that this data is incorrect. Before the external data verification and data compensation are successful, the user may think that the update was not successful and perform another update operation. At this time, since the data on the source side has already changed, performing another update operation will not cause data changes on the source side, and the incremental parsing of data synchronization cannot be triggered, and thus data cannot be synchronized to the target side. This will result in the inability to change this data and the loss of control of this data.

[0027] Therefore, it is necessary to design a technical solution to ensure the final consistency of data synchronization to avoid differences between the data on the target side and the source side and the problem of loss of control of the data operations when differences occur.

[0028] Based on this, an embodiment of the present application proposes a data synchronization method. The following will combine Figure 3 to introduce the data synchronization method of the embodiment of the present application in detail. As Figure 3 shown, the data synchronization method of the embodiment of the present application mainly includes steps S310 to S320, and the following will describe these steps in detail.

[0029] It should be noted that the magnitudes of the sequence numbers of the steps in the embodiment of the present application do not indicate the order of execution. The order of execution of each process should be determined by its function and internal logic, and should not constitute any limitation to the implementation process of the embodiment of the present application.

[0030] In step S310, an instruction to perform a first data operation is sent to the source end, and it is controlled that the source end, in response to receiving the instruction to perform the first data operation, performs a first data operation on the source database according to a preset rule and sets first source indication information. A field representing the first source indication information is configured in the data table structure of the source database, and the first source indication information is time information for performing the first data operation. Or rather, the first data operation corresponds to the first source indication information.

[0031] The target row is the row where the data of the first data operation is located, and it can be any row in the data table of the source database.

[0032] With the aid of the first source indication information, when the user performs the first data operation and repeats the first data operation, the time information for performing the first data operation can be recorded, and the time information for performing the first data operation changes, thereby triggering the change of the source end data, so that the synchronization component can parse the incremental change from the source end each time and trigger data synchronization.

[0033] The first data operation can be any one of multiple data operations, and the type of the first data operation can be any one of the add, delete, and update operation types.

[0034] In some implementation manners, controlling the source end in step S310 to, in response to receiving the instruction to perform the first data operation, perform a first data operation on the source database according to a preset rule and set the first source indication information may include:

[0035] If the first data operation is an update operation, the control source end responds to the instruction to execute the first data operation, updates the source database according to the data to be updated, and updates the first source indication information. If the first data operation is a deletion operation, the control source end responds to the instruction to execute the first data operation, performs a soft deletion operation on the source database, and sets the values of the first source indication information and the first deletion identifier, where the first deletion identifier is the identifier for the soft deletion operation. If the first data operation is an addition operation, the control source end responds to the instruction to execute the first data operation and determines whether a unique value check is required; if a unique value check is not required, the data to be inserted is added and the first source indication information is set, and if a unique value check is required, it is queried whether the data to be inserted already exists in the target row; if the data to be inserted does not exist, the data to be inserted is added and the first source indication information is set, and if the data to be inserted already exists, the first data operation is converted into an update operation, the source database is updated, and the first source indication information is updated.

[0036] For example, the first source indication information added in the data table structure of the source database can be represented by the logical field update_time, indicating the change time of the data in this row. The following is combined with Figure 4 for illustration.

[0037] As Figure 4 shown, the first data operation can be an update operation. When performing the update operation to update data, the updated fields include update_time, that is, the value of the first source indication information is set to the current update time. For example, the code for the update operation can be:

[0038] Update t1 set a=1,update_time=“2024-10-25 10:00:00”where b=1;

[0039] When repeating the update operation, although the specific updated data does not change, the time information of the update operation changes, from the previous update time to the current update time, so that repeated updates can also cause changes in incremental data and trigger data synchronization.

[0040] The first data operation can be an addition (insert) operation, and the addition operation is also called an insert operation. When performing the insert operation to add new data, there are two cases. The first case, if there is no field data that requires a unique value check, the data can be directly inserted, and the value of the first source indication information (i.e., the update_time parameter) is set, and the user can repeat the insert operation. For example, when a unique value check is not required for the insert data, the code for the insert operation can be:

[0041] Insert into t1(id,a,b,update_time)values(1,1,1,"2024-10-25 10:00:00");

[0042] For the data that fails to be inserted for the first time, data verification and compensation can be performed externally. In the second case, if a field needs to be verified for uniqueness, it is necessary to query whether the data to be inserted already exists before inserting the data. If it does not exist, the data can be directly inserted, and the value of the first source indication information (update_time) can be set. If the first insert operation is executed successfully but the data synchronization fails, since the inserted data already exists in the source database, an update operation is performed. The update operation does not affect the value of the update_time field of the business function, so that the data that was successfully inserted for the first time but not successfully synchronized will trigger another data synchronization.

[0043] For example, the code for verifying the uniqueness of inserted data can be:

[0044] If id = 1 does not exist:

[0045] Insert into t1(id,a,b,update_time)values(1,1,1,"2024-10-25 10:00:00");

[0046] If id = 1 exists:

[0047] Update update_time = "2024-10-25 10:00:00" where id = 1;

[0048] The first data operation can be a delete operation. When performing the delete operation to delete data, the soft delete method can be used to perform the delete operation, and the values of the first source indication information and the first delete identifier are set. For example, the first delete identifier can be represented as a boolean field is_delete. Updating is_delete = 1 means the data has been deleted, and updating is_delete = 0 means the data has not been deleted. Among them, soft delete is a data management technique that marks records as deleted in the database instead of physically deleting the data from the database. For example, the code for the delete operation can be:

[0049] Update t1 set is_delete = 1,update_time = "2024-10-25 10:00:00" where b = 1;

[0050] Convert the deletion operation into an update operation, and then follow the same procedure as the update operation to update the field update_time representing the first source indication information. If the deletion operation is successful but the data synchronization fails, an update operation can be performed, and the value of the first source indication information (update_time) field corresponding to the update operation will change, so that the synchronization component can parse the incremental change from the source end, thereby triggering the data synchronization again for the data that was successfully deleted but not successfully synchronized.

[0051] In step S320, in response to detecting the first incremental change information, a first synchronization instruction is sent to the target end. The first synchronization instruction is an instruction to synchronize the first data operation to the target database, the first incremental change information is the information of the change that occurs in the source database, and the first incremental change information includes the change information of the first source indication information.

[0052] For example, when the first data operation is a deletion operation, the first incremental change information of the source database may include the deleted data change information and the change information of the first source indication information indicating the deletion operation time.

[0053] In the embodiments of the present application, with the help of the first source indication information, when the user performs data operations (insertion, deletion, modification) on the source database, and when repeating data operations, the first source indication information can record the time information of executing the data operation. The times of different data operations are different. Therefore, in the embodiments of the present application, each time a data operation is performed on the source database, it can trigger a change in the source database. The synchronization component can parse the incremental change from the source end, detect the incremental information, and trigger data synchronization. When data synchronization is lost, the lost data synchronization can be adaptively and repeatedly triggered, which helps to avoid the problem of data out of control caused by differences between the target end and the source end data.

[0054] When synchronous data is lost, the following conflict problems will occur when writing to the target end: 1) If the deletion operation event synchronization is lost, when adding the data again, there will be a conflict that the newly added data already exists when synchronizing to the target end. 2) If the addition event synchronization is lost, when updating or deleting the data again, there will be a conflict problem that the data does not exist when synchronizing to the target end.

[0055] In some implementation manners, the target database is a database located at the target end, and the above conflict handling needs to be performed when writing to the target end. The method of the embodiments of the present application may further include: controlling the target end to perform the following operations:

[0056] According to preset rules, perform a first data operation on a target database and set first target indication information. In the data table structure of the target database, a field representing the first target indication information is configured. The first target indication information is used to record first source indication information. The first target indication information is also the time information when the data of the target row in the source database changes due to the execution of the first data operation. The first target indication information and the first source indication information have the same function, but are located in the target database and the source database respectively. It can be understood that if the data synchronization is successful, the values of the first target indication information and the first source indication information are the same; if the data synchronization is unsuccessful, the values of the first target indication information and the first source indication information are different. If the first data operation to be synchronized is an update operation and there is no data to be updated corresponding to the first data operation in the target database, then convert the first data operation into an insert operation and insert the data to be updated into the target database. In this way, the conflict problem of non-existent data when synchronizing to the target end is solved. If the first data operation to be synchronized is an insert operation and there is already data to be inserted corresponding to the first data operation in the target database, then convert the first data operation into an update operation and update the data to be inserted into the target database. In this way, the conflict problem of existing new data during the insert operation is solved. If the first data operation to be synchronized is a delete operation and there is no data to be deleted corresponding to the first data operation in the target database, then abandon the first data operation on the target database. In this way, the conflict problem of existing data to be deleted during the delete operation is solved.

[0057] Specifically, as Figure 4 shown, 1) When synchronizing an update operation, if the data to be updated already exists, perform a normal data update operation; if the data to be updated does not exist, then convert the update operation into an insert operation and write the data into the target database. In this way, the conflict problem of non-existent data when synchronizing to the target end is solved. 2) When synchronizing an insert operation event, if the data to be inserted does not exist, normally perform the insertion of new data; if the data to be inserted already exists, then convert the insert operation into an update operation and update the data to the target database. In this way, the conflict problem of existing new data during the insert operation is solved. 3) When synchronizing a delete event, if the data to be deleted exists, normally perform the data deletion operation; if the data to be deleted does not exist, discard the delete operation without processing. In this way, the conflict problem of existing data to be deleted during the delete operation is solved.

[0058] In the embodiment of the present application, through the above-mentioned write design processing at the source end and the write design processing at the target end, the synchronization component has the adaptive ability of data final consistency when data synchronization is lost, that is, the user has repeatable data operation behaviors and triggers or performs data synchronization again.

[0059] When using the DTS tool for data synchronization, it is necessary to regularly verify the data on the source side and the target side to confirm whether there is any data loss during the data synchronization process, and then perform data compensation.

[0060] There are usually two methods for verification: full - volume quantity (count) verification and full - volume content verification. Among them, full - volume quantity verification is to check whether the data volumes are consistent. It can only verify the data volume and cannot detect data loss in data synchronization of the update type. And full - volume content verification is very slow. The larger the data volume, the slower it is. By the time the different data is detected and compensated, the time span is too large and not feasible, and it will greatly consume the performance of the source side. In addition, for scenarios such as data aggregation synchronization where the synchronization is not one - to - one, the content between the source side and the target side is not absolutely equal, and full - volume content verification cannot be performed.

[0061] There is a time difference when simply verifying and then compensating. During this period, when users query this data on the target side, it is old data, and the timeliness of data ultimate consistency is poor. If all data is compared each time, it will be repetitive and time - consuming. It can be seen that the current verification method has the problem of poor timeliness of data ultimate consistency.

[0062] In some implementation manners, the method of the embodiment of the present application may further include: obtaining first incremental change information and second incremental change information within a unit time, where the second incremental change information is the information of changes generated by the target database. The duration of the unit time can be fixed or variable. For example, the unit time can be a preset fixed interval time, such as 10 seconds or 30 seconds. The unit time is also the duration from the moment of the previous verification to the moment when the current verification starts. According to the primary key identifier sets of the first incremental change information and the second incremental change information, the change amount between the target database and the source database is judged. According to the update time information of the first same - order row data, it is determined whether the first same - order row data in the target database and the source database is consistent. The first same - order row is any row with the same row number in the first incremental change information and the second incremental change information.

[0063] For timed incremental verification, only the data that has changed during the time from the previous verification time to the current verification start time needs to be verified. The amount of data to be verified is small, which can avoid repetition and redundancy. By comparing the unique primary key identifiers of the data, the differences and similarities between the data on the target side and the source side can be judged; by comparing the update time (update_time) of the same row of data, it can be judged whether the data of this row is consistent on the source side and the target side. Therefore, it is not necessary to obtain all the data of each row for one - by - one comparison verification. Only the identifier (ID) and update time of each row of data need to be obtained for comparison, which helps to simplify the data comparison time and the required storage space, and improve the timeliness of data ultimate consistency.

[0064] If the number of identifiers in the primary key identifier set of the first incremental change information is n, and the number of identifiers in the primary key identifier set of the second incremental change information is also n, generally, it is necessary to traverse the data at the target end with the data at the source end and compare n * n times to detect whether the data at the source end and the target end are consistent.

[0065] Although the consequences of data synchronization loss are serious, the probability of data synchronization loss is small, and only individual data is inconsistent when it occurs. Based on this feature, the same row data at the source end and the target end can be directly compared, so only n comparisons are needed, which helps to reduce the workload and inspection time of the comparison.

[0066] In some implementation manners, the above-mentioned method of determining the change amount between the target database and the source database according to the primary key identifier set of the first incremental change information and the primary key identifier set of the second incremental change information; and determining whether the first same-order row data in the target database and the source database is consistent according to the update time information of the first same-order row data may include: arranging the first incremental change information based on the order of the primary key identifiers in the primary key identifier set of the first incremental change information to obtain a first sequence table; arranging the second incremental change information based on the order of the primary key identifiers in the primary key identifier set of the second incremental change information to obtain a second sequence table. Or rather, according to the first incremental change information and the second incremental change information, a first sequence table and a second sequence table are determined. The first sequence table is a table in which the first incremental change information is arranged based on the primary key identifier order, and the second sequence table is a table in which the second incremental change information is arranged based on the primary key identifier order. The primary key identifier can also be referred to as a row identifier. According to the first sequence table and the second sequence table, it is determined whether the update time information of the first same-order rows in the first sequence table and the second sequence table is the same; according to the comparison result of the update time information of the first same-order rows, it is determined whether the data in the target database and the source database is consistent.

[0067] Specifically, when querying data from the source end and the target end, sort according to the primary key identifier. For example, a first sequence table and a second sequence table can be created in the source database and the target database respectively. For example, create an index idx_update_time_id (updatetime, id) to improve query efficiency. If the data at the source end and the target end is consistent, the results of the first sequence table at the source end and the results of the second sequence table at the target end will correspond and be equal one by one in sequence. Since the first sequence table is an ordered sequence table based on the primary key identifier (ID), if the IDs at a certain position are not equal, the differences and similarities between the data at the target end and the source end of this row can be directly compared based on the ID size to determine whether the target end is missing (or the source end has lost the update synchronization), or the target end has more (or there is an external update at the target end). Then, obtain the complete data of this row from the source end according to the ID, and compensate and correct the data of this row at the target end.

[0068] Perform incremental verification, and the amount of data verified each time can be effectively controlled. All data can be queried from the source end and the target end at one time. When there is a small probability of data synchronization loss, access the source database to compensate for the data, and the access volume to the database is very small, which helps to reduce the access pressure on the database.

[0069] In some implementation manners, if it is detected that the data in the target database is inconsistent with the data in the source database, data compensation is required to make the data consistent. Before determining whether the first co-sequence row data in the target database and the source database is consistent according to the update time information of the first co-sequence row data, the method of the embodiment of the present application may further include:

[0070] If the number of primary key identifiers in the first sequence table is greater than the number of primary key identifiers in the second sequence table, determine the first difference row that the first sequence table has and the second sequence table lacks, query whether the first difference row exists in the target database, if the first difference row exists, obtain the complete data of the first difference row from the source database to perform an update operation on the target database, if the first difference row does not exist, obtain the complete data of the first difference row from the source database to perform an add operation on the target database. If the number of primary key identifiers in the first sequence table is less than the number of primary key identifiers in the second sequence table, determine the second difference row that the second sequence table has and the first sequence table lacks, query whether the second difference row exists in the source database, if the second difference row does not exist in the source database, perform a delete operation on the second difference row data of the target database, if the second difference row exists in the source database, obtain the complete data of the second difference row from the source database to perform an update operation on the target database.

[0071] In some implementations, if it is detected that the data in the target database is inconsistent with the data in the source database, data compensation is required to make the data consistent. Any one of the multiple primary key identifiers in the first sequence table is the first primary key identifier, and the primary key identifier in the second sequence table that has the same sequence as the first primary key identifier in the first sequence table is the second primary key identifier. Or rather, the first primary key identifier is any one of the multiple primary key identifiers in the first sequence table, the second primary key identifier is any one of the multiple primary key identifiers in the second sequence table, and the sequence of the first primary key identifier in the first sequence table is the same as the sequence of the second primary key identifier in the second sequence table. The method according to the embodiments of the present application may further include:

[0072] If the value of the first primary key identifier in the first sequence table is greater than the value of the second primary key identifier in the second sequence table, determine the first difference row that the first sequence table has and the second sequence table lacks. Query whether the first difference row exists in the target database. If the first difference row exists, obtain the complete data of the first difference row from the source database and perform an update operation on the target database. If the first difference row does not exist, obtain the complete data of the first difference row from the source database and perform an addition operation on the target database.

[0073] According to the comparison of the primary key identifiers, it is found that the data at the source end is more than the data at the target end. Query whether the first difference row data exists at the target end, and determine that the result set at the target end does not have this data due to the loss of update synchronization of this row of data during this incremental time. Therefore, by obtaining the complete data of this row of data from the source end, a new addition or update compensation is performed on the target end to keep the data at the target end consistent with the data at the source end.

[0074] If the value of the first primary key identifier in the first sequence table is less than the value of the second primary key identifier in the second sequence table, determine the second difference row that the second sequence table has and the first sequence table lacks. Query whether the second difference row exists in the source database. If the second difference row does not exist in the source database, perform a deletion operation on the second difference row data in the target database. If the second difference row exists in the source database, obtain the complete data of the second difference row from the source database and perform an update operation on the target database.

[0075] According to the comparison of the primary key identifiers, it is found that the data at the source end is less than the data at the target end. Query whether the second difference row data exists at the source end. Determine whether there is more data at the target end, or whether the data at the target end is directly updated externally, resulting in this row of data in the result set at the target end. Therefore, a deletion compensation for this row of data is performed on the target end, or the complete data of this row of data is obtained from the source end for update compensation to keep the data at the target end consistent with the data at the source end.

[0076] If the value of the first primary key identifier in the first sequence table is equal to the value of the second primary key identifier in the second sequence table, and the update time of the row data of the first primary key identifier is not equal to the update time of the row data of the second primary key identifier, then the complete row data corresponding to the first primary key identifier is obtained from the source database to perform an update operation on the target database.

[0077] The values of the primary key identifiers are equal, while the update times are not equal, indicating that the row data exists on both the source side and the target side, but the data is inconsistent. The log of this row data can be recorded for review, and then the complete data of this row will be obtained from the source side to perform an update compensation on the row data on the target side to keep the data on the target side consistent with the source side.

[0078] If the value of the first primary key identifier in the first sequence table is equal to the value of the second primary key identifier in the second sequence table, and the update time of the row data of the first primary key identifier is equal to the update time of the row data of the second primary key identifier, it indicates that the row data is consistent on both the source side and the target side.

[0079] In the embodiments of the present application, when data synchronization loss occurs during the data synchronization process, the target - side data can be automatically repaired to ensure the ultimate consistency of the data on the target side and the source side, and to prevent users from losing control of the synchronized - lost data.

[0080] The following further describes the embodiments of the present application in combination with some possible implementation manners of the embodiments of the present application.

[0081] Figure 6 Yes Figure 3 It is a schematic diagram of another possible implementation manner of the method shown. Specifically, as Figure 6 shown, the data synchronization method of the embodiments of the present application mainly includes steps S610 to S670, and these steps will be described in detail below.

[0082] In step S610, the first incremental change information within a unit time is obtained, and the second incremental change information within a unit time is obtained. For example, the code can be:

[0083] Select id as t_id,update_time as t_update_time from t1 where update_time>=the time of the last verification and update_time<the current verification time order by id.

[0084] In step S620, the first sequence table is established, and the second sequence table is established.

[0085] For example, according to the primary key identifier (ID) and the update time update_time of the source database in the first incremental change information, a first sequence table (s_id[n], s_update_time[n]) is established. The first sequence table is an ID-ordered table. According to the primary key ID and the update time update_time of the target database in the second incremental change information, a second sequence table (t_id[m], t_update_time[m]) is established, which is also ordered by ID.

[0086] In step S630, the row number n of the first same-order row in the first sequence table is preset to 1, and the row number m of the first same-order row in the second sequence table is preset to 1, and the comparison is performed row by row.

[0087] In step S631, it is judged whether n is less than or equal to n_max and whether m is less than or equal to m_max. Wherein, n_max is the maximum number of rows in the first sequence table, and m_max is the maximum number of rows in the second sequence table.

[0088] If n is less than or equal to n_max and m is less than or equal to m_max, then step S632 is entered; if n is greater than n_max or m is greater than m_max, then step S633 is entered.

[0089] In step S632, it is judged whether the value of the first primary key identifier of the source database corresponding to the row number n is the same as the value of the second primary key identifier corresponding to the row number m, that is, it is judged whether s_id[n]=t_id[m] holds. Wherein, the sequence of the first primary key identifier in the first sequence table is the same as the sequence of the second primary key identifier in the second sequence table.

[0090] If s_id[n] is equal to t_id[m], it means that the data of this row exists in both databases on both sides, and then step S634 is entered; if s_id[n] is not equal to t_id[m], it means that the data of this row only exists in one-sided database, and then step S635 is entered.

[0091] In step S633, it is judged whether m is greater than m_max. If m is greater than m_max, then step S650 is entered; if m is not greater than m_max, then n>n_max, which means that the source-side data has been compared, but there is still data on the target side that has not been compared. It may be that there are data in these rows from the current t_id[m] to t_id[m_max] on the target side, or there is an external update of the data in these rows from the current t_id[m] to t_id[m_max] on the target side, and then step S660 is entered.

[0092] In step S634, it is judged whether the update time of the row data of the first primary key identifier is equal to the update time of the row data of the second primary key identifier. If they are equal, it means that both sides of the row data are consistent, and then step S636 is entered; if they are not equal, it means that both sides of the row data are inconsistent, and then step S637 is entered.

[0093] In step S635, it is judged whether the value of the first primary key identifier (the nth row) of the source database is less than the value of the second primary key identifier (the mth row). If s_id[n] is less than t_id[m], it means that the row data is missing at the target end, or the update synchronization is lost, and then step S640 is entered; if s_id[n] is greater than t_id[m], it means that there is more row data at the target end, or there is an external update at the target end, and then step S639 is entered.

[0094] In step S636, the row number n of the first sequence table is incremented by 1, the row number m of the second sequence table is incremented by 1, step S631 is entered, and the comparison of the next row of the same sequence is started.

[0095] In step S637, s_id[n] in the first sequence list is recorded, and the complete data of the row corresponding to this primary key identifier is obtained from the source end.

[0096] In step S638, the target end updates the row data in the target database.

[0097] In step S639, it is queried whether the row data exists at the source end. If the row data exists, it indicates that the update synchronization may be lost, and then step S645 is entered; if the row data does not exist, it indicates that the delete synchronization may be lost, and then step S646 is entered.

[0098] In step S640, s_id[n] in the first sequence list is recorded, and the complete data of this row is obtained from the source end.

[0099] In step S641, it is queried whether the row data exists at the target end. If the row data exists, it indicates that the update synchronization may be lost, and then step S642 is entered; if the row data does not exist, it indicates that the target end may be missing the row data, and then step S643 is entered.

[0100] In step S642, the target end updates the row data in the target database.

[0101] In step S643, the target end inserts the row data into the target database.

[0102] In step S644, the row number n in the first sequence list is incremented by 1, and it is transferred to step S631.

[0103] In step S645, record the primary key identifier t_id[m] in the second sequence list, and the target end updates the data of this row.

[0104] In step S646, record the primary key identifier t_id[m] in the second sequence list, and the target end deletes the data of this row.

[0105] In step S647, increment the row number m in the second sequence list by 1, and transfer to step S631.

[0106] In step S650, determine whether n is greater than n_max. If n is not greater than n_max and m is greater than m_max, it means that the data at the target end has been compared, but there is still data at the source end that has not been compared. This indicates that the target end is missing the data of the current rows from s_id[n] to s_id[n_max], or the target end has lost the update synchronization of the data of the current rows from s_id[n] to s_id[n_max], then enter step S652.

[0107] In step S651, record s_id[n], and obtain the data of this row from the source end.

[0108] In step S652, query whether the data of this row exists at the target end. If the data of this row exists, it indicates that the target end has lost the update synchronization of this row of data, then enter step S653; if the data of this row does not exist, then enter step S654.

[0109] In step S653, the target end updates the data of this row.

[0110] In step S654, the target end inserts the data of this row into the target database.

[0111] Traverse from the current s_id[n] to s_id[n_max], repeatedly enter step S651 until the processing of s_id[n_max] is completed, and then enter step S6670.

[0112] In step S660, query whether the data of the row t_id[m] exists at the source end. If the data of this row exists, it indicates that the target end has lost the update synchronization of this row of data, then enter step S662; if the data of this row does not exist, it means that the target end has an external update of the current t_id[m], then enter step S663.

[0113] In step S662, record t_id[m], and the target end updates the data of this row.

[0114] In step S663, record t_id[m], and the target end deletes the data of this row.

[0115] Traverse from the current t_id[m] to t_id[m_max], and repeatedly enter step S660 until after the processing of t_id[m_max] is completed, then enter step S6670.

[0116] In step S670, it ends, completing the consistency detection of data synchronization and the compensation processing for data inconsistency.

[0117] In the embodiment of the present application, with the help of the first source indication information, when the user performs data operations (insertion, deletion, modification) on the source database, and when repeating data operations, the first source indication information can record the time information of executing the data operation. The times of different data operations are different. Therefore, in the embodiment of the present application, each time a data operation is performed on the source database, it can trigger a change in the source database. The synchronization component can parse the incremental change from the source end, detect the incremental information, and trigger data synchronization. When data synchronization is lost, it can adaptively and repeatedly trigger the lost data synchronization, which helps to avoid the problem of data out of control when there are differences between the target end and the source end data.

[0118] In the embodiment of the present application, when data synchronization is lost during the data synchronization process, it can automatically repair the data at the target end, ensure the final consistency of the data between the target end and the source end, and avoid the user losing control of the synchronized lost data.

[0119] As described above in conjunction with Figures 1 - 6 The method embodiments of the present application have been described in detail. Next, in conjunction with Figures 7 to 8 The device embodiments of the present application will be described in detail. It should be understood that the description of the device embodiments corresponds to the description of the method embodiments. Therefore, for the parts not described in detail, reference can be made to the previous method embodiments.

[0120] The embodiment of the present application also provides a data synchronization device. Figure 7 It is a schematic composition diagram of the data synchronization device provided by the embodiment of the present application. As Figure 7 shown, the data synchronization device 700 includes: a first control module 710 and a sending module 720.

[0121] The first control module 710 is used to control the source end to respond to the received instruction to execute the first data operation, perform the first data operation on the source database according to a preset rule, and set the first source indication information. A field representing the first source indication information is configured in the data table structure of the source database, and the first source indication information is the time information of executing the first data operation.

[0122] The sending module 720 is configured to issue a first synchronization instruction to the target end in response to detecting the first incremental change information. The first synchronization instruction is an instruction to synchronize the first data operation to the target database. The first incremental change information is the information indicating that the source database has changed, and the first incremental change information includes the change information of the first source indication information.

[0123] Optionally, the first control module 710 is configured to perform the following operations:

[0124] If the first data operation is an update operation, control the source end to respond to the received instruction to execute the first data operation, update the data in the source database according to the data to be updated, and update the first source indication information. If the first data operation is a deletion operation, control the source end to respond to the received instruction to execute the first data operation, perform a soft deletion operation on the source database, and set the values of the first source indication information and the first deletion identifier. The first deletion identifier is the identifier of the soft deletion operation. If the first data operation is an addition operation, control the source end to respond to the received instruction to execute the first data operation, and determine whether a unique value verification is required. If a unique value verification is not required, add the data to be inserted and set the first source indication information. If a unique value verification is required, query whether the data to be inserted already exists in the target row; if the data to be inserted does not exist, add the data to be inserted and set the first source indication information. If the data to be inserted already exists, convert the first data operation into an update operation, update the data in the source database, and update the first source indication information.

[0125] Optionally, the data synchronization device 700 may further include a second control module. The second control module is configured to control the target end to perform the following operations:

[0126] According to a preset rule, perform a first data operation on the target database and set the first target indication information. A field representing the first target indication information is configured in the data table structure of the target database, and the first target indication information is used to record the first source indication information. If the synchronized first data operation is an update operation and the data to be updated corresponding to the first data operation does not exist in the target database, convert the first data operation into an addition operation and insert the data used for update into the target database. If the synchronized first data operation is an addition operation and the data to be added corresponding to the first data operation already exists in the target database, convert the first data operation into an update operation and update the data to be added to the target database. If the synchronized first data operation is a deletion operation and the data to be deleted corresponding to the first data operation does not exist in the target database, abandon the execution of the first data operation.

[0127] Optionally, the device 700 for data synchronization may further include an acquisition module, a judgment module, and a determination module. The acquisition module is configured to acquire first incremental change information and second incremental change information within a unit time. The first incremental change information is the data with changes generated by the source database, and the second incremental change information is the data with changes generated by the target database. The unit time is the time period from the last verification moment to the start of the current verification moment. The judgment module is configured to judge the change amount between the target database and the source database according to the primary key identifier sets of the first incremental change information and the second incremental change information. The determination module is configured to determine whether the first same-order row data in the target database and the source database is consistent according to the update time information of the first same-order row data. The first same-order row is a row with the same row number in the first incremental change information and the second incremental change information.

[0128] Optionally, the determination module is configured to determine a first sequence table and a second sequence table according to the first incremental change information and the second incremental change information. The first sequence table is a sequence table arranged by the first incremental change information according to the row identifier, and the second sequence table is a sequence table arranged by the second incremental change information according to the row identifier. According to the first sequence table and the second sequence table, determine whether the update time information of the first same-order row is the same; according to the comparison result of the update time information of the first same-order row, judge whether the data in the target database and the source database is consistent.

[0129] Optionally, the first primary key identifier is any one of the multiple primary key identifiers of the first sequence table, the second primary key identifier is any one of the multiple primary key identifiers of the second sequence table, and the sequence number of the first primary key identifier in the first sequence table is the same as the sequence number of the second primary key identifier in the second sequence table. The device 700 for data synchronization may further include a compensation module. The compensation module is configured to perform the following operations:

[0130] If the value of the first primary key identifier is greater than the value of the second primary key identifier, determine the first difference row that the first sequence table has and the second sequence table lacks, query whether the first difference row exists in the target database, if the first difference row exists, obtain the complete data of the first difference row from the source database and perform an update operation on the target database, if the first difference row does not exist, obtain the complete data of the first difference row from the source database and perform an addition operation on the target database. If the value of the first primary key identifier is less than the value of the second primary key identifier, determine the second difference row that the second sequence table has and the first sequence table lacks, query whether the second difference row exists in the source database, if the second difference row does not exist in the source database, perform a deletion operation on the second difference row data of the target database, if the second difference row exists in the source database, obtain the complete data of the second difference row from the source database and perform an update operation on the target database. If the value of the first primary key identifier is equal to the value of the second primary key identifier, and the update time of the row data of the first primary key identifier is not equal to the update time of the row data of the second primary key identifier, then obtain the complete row data corresponding to the first primary key identifier from the source database and perform an update operation on the target database.

[0131] Figure 8 It is a schematic diagram of a component unit / partial component unit of the electronic device provided by the embodiment of the present application. As Figure 8 shown, the electronic device 800 may include: a memory 810, at least one processor 820.

[0132] The memory 810 is used to store code or computer programs.

[0133] The processor 820 is connected to the memory 810 and is used to execute the code or computer program stored in the memory 810, so that the electronic device 800 executes the processing method described in any of the foregoing.

[0134] Exemplarily, the computer program may be divided into one or more modules / units, and one or more modules / units are stored in the memory 810 and executed by the processor 820 to complete the present application.

[0135] Those skilled in the art can understand that Figure 8 is only an example of the electronic device 800 and does not constitute a limitation on the electronic device. It may include more or fewer components than shown in the figure, or combine some components, or different components.

[0136] The processor 820 may be a central processing unit (CPU), or may also be other general-purpose processors, digital signal processors (DSPs), application specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. The general-purpose processor may be a microprocessor, or the processor may also be any conventional processor, etc.

[0137] The electronic device 800 provided in this embodiment may execute the above method embodiment, and its implementation principle and technical effects are similar, which will not be elaborated here.

[0138] This application embodiment also provides a non-volatile computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the steps in the above various method embodiments can be implemented.

[0139] This application embodiment provides a computer program product. When the computer program product runs on an electronic device, the electronic device can execute to implement the steps in the above various method embodiments.

[0140] In the above embodiments, the descriptions of the various embodiments have their own emphases. For the parts not detailed or recorded in a certain embodiment, reference may be made to the relevant descriptions of other embodiments.

[0141] When 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, to implement all or part of the processes in the above method embodiments of the present application, a computer program can be used to instruct the relevant hardware to complete. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by a processor, the steps of the above method embodiments can be implemented. Among them, the computer program includes computer program code, and the computer program code can be in the form of source code, object code, executable file or some intermediate form, etc. The computer-readable medium can at least include: any entity or device that can carry the computer program code to the photographing device / electronic device, recording medium, computer memory, read-only memory (ROM), random access memory (RAM), compact disc read-only memory (CD-ROM), magnetic tape, floppy disk and optical data storage device, etc. The computer-readable storage medium mentioned in the present application can be a non-volatile storage medium, in other words, it can be a non-transitory storage medium.

[0142] Those of ordinary skill in the art can realize that the units and algorithm steps of each example described in combination with the embodiments disclosed in this document can be implemented by electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are executed in a hardware or software manner depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present application.

[0143] In the embodiments provided in the present application, it should be understood that the disclosed device / equipment and method can be implemented in other ways. For example, the device / equipment embodiments described above are only illustrative. For example, the division of modules or units is only a logical function division. In actual implementation, there can be other division methods. For example, multiple 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 displayed or discussed coupling or direct coupling or communication connection to each other can be through some interfaces. The indirect coupling or communication connection of the device or unit can be in an electrical, mechanical or other form.

[0144] It should be understood that when used in the specification and appended claims of the present application, the term "comprising" indicates the presence of the described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or their combinations.

[0145] It should also be understood that the term "and / or" as used in the specification and appended claims of the present application refers to any combination and all possible combinations of one or more of the associated listed items, and includes such combinations.

[0146] As used in the specification and appended claims of the present application, the term "if" may be construed, depending on the context, as "when", "once", "in response to determining", or "in response to detecting". Similarly, the phrase "if determined" or "if [the described condition or event] is detected" may be construed, depending on the context, as meaning "once determined", "in response to determining", "once [the described condition or event] is detected", or "in response to detecting [the described condition or event]".

[0147] In addition, in the description of the specification and appended claims of the present application, the terms "first", "second", etc. are only used for distinguishing descriptions and should not be construed as indicating or implying relative importance.

[0148] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application and are not intended to limit them; although the present application has been described in detail with reference to the foregoing embodiments, those of ordinary skill in the art should understand that they can still modify the technical solutions described in the foregoing embodiments, or perform equivalent replacements for some or all of the technical features; and these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A method for data synchronization, characterized in that: include: In response to receiving the instruction to perform the first data operation, the control source end performs the first data operation on the source database according to a preset rule and sets first source indication information, wherein a field representing the first source indication information is configured in a data table structure of the source database, and the first source indication information is time information for performing the first data operation; In response to detecting first incremental change information, a first synchronization instruction is issued to the target end, the first synchronization instruction is an instruction to synchronize the first data operation to the target database, the first incremental change information is information about changes in the source database, and the first incremental change information includes change information of the first source indication information.

2. The method according to claim 1, characterized in that The type of the first data operation is any one of an add, delete, and update operation type. In response to receiving an instruction to perform the first data operation, the control source end performs the first data operation on the source database according to a preset rule and sets the first source indication information, including: If the first data operation is an update operation, controlling the source end to perform a data update operation on the source database according to the data to be updated in response to receiving an instruction to perform the first data operation, and updating the first source indication information; If the first data operation is a deletion operation, controlling the source end to perform a deletion operation on the source database in response to receiving an instruction to perform the first data operation, and setting values ​​of the first source indication information and a first deletion identifier, where the first deletion identifier is an identifier of a soft deletion operation; If the first data operation is an addition operation, controlling the source end to determine whether a unique value verification is required in response to receiving an instruction to perform the first data operation; If unique value verification is not required, add the data to be inserted and set the first source indication information; if unique value verification is required, query whether the data to be inserted already exists in the target row; if the data to be inserted does not exist, add the data to be inserted and set the first source indication information; if the data to be inserted already exists, convert the first data operation into an update operation, perform a data update operation on the source database, and update the first source indication information.

3. The method according to claim 2, characterized in that The method further comprises: Control the target end to perform the following operations: According to the preset rule, the first data operation is performed on the target database and first target indication information is set, wherein a field representing the first target indication information is configured in a data table structure of the target database, and the first target indication information is used to record the first source indication information; If the first data operation to be synchronized is an update operation, and the data to be updated corresponding to the first data operation does not exist in the target database, converting the first data operation into an add operation, and inserting the data for updating into the target database; If the first data operation to be synchronized is an add operation, and the data to be added corresponding to the first data operation already exists in the target database, converting the first data operation into an update operation, and updating the data to be added to the target database; If the first data operation to be synchronized is a deletion operation, and the data to be deleted corresponding to the first data operation does not exist in the target database, the execution of the first data operation is abandoned.

4. The method according to any one of claims 1 to 3, characterized in that The method further comprises: Acquire the first incremental change information and the second incremental change information within a unit time, where the second incremental change information is information about changes in the target database; Determining the amount of change between the target database and the source database according to the primary key identifier set of the first incremental change information and the primary key identifier set of the second incremental change information; According to the update time information of the first same-sequence row data, it is determined whether the first same-sequence row data in the target database is consistent with the first same-sequence row data in the source database, and the first same-sequence row is a row with the same row number in the first incremental change information and the second incremental change information.

5. The method according to claim 4, characterized in that determining the amount of change between the target database and the source database according to the primary key identifier set of the first incremental change information and the primary key identifier set of the second incremental change information; Determining whether the first same-sequence row data in the target database is consistent with the first same-sequence row data in the source database according to the update time information of the first same-sequence row data includes: Arranging the first incremental change information based on the order of primary key identifiers in the primary key identifier set of the first incremental change information to obtain a first sequence table; Arranging the second incremental change information based on the order of primary key identifiers in the primary key identifier set of the second incremental change information to obtain a second sequence table; Determine, according to the first sequence table and the second sequence table, whether the update time information of the first same-sequence rows is the same; According to the comparison result of the update time information of the first same-sequence row, it is determined whether the data of the target database is consistent with the data of the source database.

6. The method according to claim 5, characterized in that Any primary key identifier among the multiple primary key identifiers of the first sequence table is a first primary key identifier, and a primary key identifier among the multiple primary key identifiers of the second sequence table that has the same sequence as the first primary key identifier in the first sequence table is a second primary key identifier, and the method further includes: If the value of the first primary key identifier is greater than the value of the second primary key identifier, determine that the first sequence table has a first difference row that is missing from the second sequence table, query whether the target database has the first difference row, if the first difference row exists, obtain complete data of the first difference row from the source database to perform an update operation on the target database, if the first difference row does not exist, obtain complete data of the first difference row from the source database to perform an add operation on the target database; If the value of the first primary key identifier is less than the value of the second primary key identifier, determine that the second sequence table has a second difference row that is missing from the first sequence table, query whether the second difference row exists in the source database, if the second difference row does not exist in the source database, delete the data of the second difference row in the target database, if the second difference row exists in the source database, obtain complete data of the second difference row from the source database and update the target database; If the value of the first primary key identifier is equal to the value of the second primary key identifier, and the update time of the row data of the first primary key identifier is not equal to the update time of the row data of the second primary key identifier, the complete row data corresponding to the first primary key identifier is obtained from the source database to perform an update operation on the target database.

7. A data synchronization device, characterized in that: include: a first control module, configured to control the source end to perform the first data operation on the source database according to a preset rule and set first source indication information in response to receiving an instruction to perform the first data operation, wherein a field representing the first source indication information is configured in the data table structure of the source database, and the first source indication information is time information of a change in the data of a target row in the source database caused by the execution of the first data operation; A sending module is used to send a first synchronization instruction to a target end in response to detecting first incremental change information, wherein the first synchronization instruction is an instruction to synchronize the first data operation to a target database, the first incremental change information is information about changes in the source database, and the first incremental change information includes change information of the first source indication information.

8. The device according to claim 7, characterized in that Also includes: An acquisition module, configured to acquire first incremental change information and second incremental change information within a unit time, wherein the first incremental change information is data changed in the source database, and the second incremental change information is data changed in the target database; A determination module, configured to determine the amount of change between the target database and the source database according to the primary key identifier set of the first incremental change information and the primary key identifier set of the second incremental change information; A determination module is used to determine whether the first same-sequence row data in the target database is consistent with the first same-sequence row data in the source database according to the update time information of the first same-sequence row data, and the first same-sequence row is a row with the same row number in the first incremental change information and the second incremental change information.

9. An electronic device, characterized in that: include: A memory for storing codes; A processor, connected to the memory, and configured to execute the code stored in the memory so that the electronic device executes the method as described in any one of claims 1 to 6.

10. A computer-readable storage medium, characterized in that: A computer program is stored thereon, and when the computer program is executed, the computer program is used to implement the method according to any one of claims 1 to 6.