Data synchronization method, device, storage medium and electronic device

By obtaining the data before and after the change in the first database, determine the change value and update the second database, solve the problem that can only be synchronized in the existing technology, and achieve accurate data synchronization and efficient database operations.

CN114969201BActive Publication Date: 2025-01-24PEOPLE'S INSURANCE COMPANY OF CHINA
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202210411735.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2022-04-19
Publication Date
2025-01-24
Estimated Expiration
2042-04-19

AI Technical Summary

Technical Problem

The existing data synchronization method can only synchronize the changed data of the database, and cannot obtain the data before the change, resulting in the inability to know the data changes and the inability to achieve accurate data synchronization.

Method used

Obtain change data in the first database, including pre-change data and post-change data, determine the change value through these data, and update the second database.

Benefits of technology

By obtaining data before and after changes, we can accurately know the data changes, simplify the database operation process, and improve the efficiency of data synchronization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114969201B_ABST
    Figure CN114969201B_ABST
Patent Text Reader

Abstract

The present application discloses a data synchronization method and device, a storage medium and an electronic device, the method comprising: obtaining change data in a first database, wherein the change data comprises data before the change and data after the change; determining a change value according to the data before the change and the data after the change; and updating a second database according to the change value. The method of the present application is applicable to a scenario where the final data needs to be calculated based on basic data and changed process data, and the calculation is simple and the efficiency is high.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of data synchronization, and in particular to a data synchronization method, device, storage medium and electronic device. Background Art

[0002] The data of business systems are all stored in their own databases. The systems and data are "siloed" and independent of each other. In the context of the digital age, all businesses are online. The database stores a large amount of data of various dimensions such as customers, policies, and businesses. Previously, these data could each support their own systems, such as customer systems, underwriting systems, etc., but now with the advancement and development of science and technology, if these data can be integrated, they can tap into greater and more important value. Therefore, each system wants to break this data "island" and realize data aggregation and integration. Data synchronization technology has come into being. It is used to synchronize data in one database to another data storage medium of possibly different types in real time and accurately.

[0003] In the existing data synchronization method, since the database only records the currently changed data, during data synchronization, only the new data after the change is synchronized to the computing platform. The computing platform cannot know the data before the change, and therefore cannot know the data change situation. Summary of the invention

[0004] In view of this, the present application provides a data synchronization method, device, medium and equipment, which are suitable for scenarios where final data needs to be calculated based on basic data and changed process data, with simple calculation and high efficiency.

[0005] According to one aspect of the present application, a data synchronization method is provided, comprising:

[0006] Acquire change data in the first database, wherein the change data includes data before the change and data after the change;

[0007] Determine a change value according to the data before the change and the data after the change;

[0008] The second database is updated according to the changed value.

[0009] Optionally, before determining the change value according to the data before the change and the data after the change, the method further includes:

[0010] Splicing the changed data to obtain a changed message, and adding the changed message to a message queue;

[0011] If it is identified that there is a change message in the message queue, the change message in the message queue is read and parsed to obtain the change data.

[0012] Optionally, the splicing the changed data to obtain a change message specifically includes:

[0013] Determine the change type according to the change data, and write the change type into the type field, wherein the change type is one of the following: add, delete, modify;

[0014] Writing the pre-change data into the pre-change field, and writing the post-change data into the post-change field;

[0015] The type field, the field before change, and the field after change are concatenated to obtain the change message.

[0016] Optionally, acquiring the change data in the first database specifically includes:

[0017] Monitoring the data log of the first database;

[0018] If it is monitored that a data change record is written into the data log, the change data corresponding to the data change record is extracted from the data log.

[0019] Optionally, the data log is configured to record the data change record and data historical version;

[0020] Extracting the change data corresponding to the data change record in the data log specifically includes:

[0021] Determine the data history version corresponding to the data change record, wherein the data history version includes a version before the change and a version after the change;

[0022] The changed data is determined according to the historical version of the data.

[0023] Optionally, before determining the change value according to the pre-change data and the post-change data, the method further includes:

[0024] Read the unique identifier carried by the changed data, and determine whether the changed data has been processed according to the unique identifier and the historical processing record;

[0025] If not, updating the historical processing record according to the unique identifier;

[0026] If yes, generate an exception message and end.

[0027] Optionally, the reading and parsing the change message in the message queue specifically includes:

[0028] If there are multiple change messages in the message queue, the change messages are read in a first-in-first-out order, and the read change messages are parsed.

[0029] According to another aspect of the present application, a data synchronization device is provided, comprising:

[0030] An acquisition module, configured to acquire change data in the first database, wherein the change data includes data before the change and data after the change;

[0031] A calculation module, used for determining a change value according to the data before the change and the data after the change;

[0032] An updating module is used to update the second database according to the changed value.

[0033] Optionally, the device further includes a message processing module, specifically configured to:

[0034] Splicing the changed data to obtain a changed message, and adding the changed message to a message queue;

[0035] If it is identified that there is a change message in the message queue, the change message in the message queue is read and parsed to obtain the change data.

[0036] Optionally, the message processing module is further used to:

[0037] Determine the change type according to the change data, and write the change type into the type field, wherein the change type is one of the following: add, delete, modify;

[0038] Writing the pre-change data into the pre-change field, and writing the post-change data into the post-change field;

[0039] The type field, the field before change, and the field after change are concatenated to obtain the change message.

[0040] Optionally, the acquisition module is further used to:

[0041] Monitoring the data log of the first database;

[0042] If it is monitored that a data change record is written into the data log, the change data corresponding to the data change record is extracted from the data log.

[0043] Optionally, the data log is configured to record the data change record and data historical version;

[0044] The acquisition module is further used for:

[0045] Determine the data history version corresponding to the data change record, wherein the data history version includes a version before the change and a version after the change;

[0046] The changed data is determined according to the historical version of the data.

[0047] Optionally, the device further includes a verification module, specifically configured to:

[0048] Read the unique identifier carried by the changed data, and determine whether the changed data has been processed according to the unique identifier and the historical processing record;

[0049] If not, updating the historical processing record according to the unique identifier;

[0050] If yes, generate an exception message and end.

[0051] Optionally, the message processing module is further used to:

[0052] If there are multiple change messages in the message queue, the change messages are read in a first-in-first-out order, and the read change messages are parsed.

[0053] According to another aspect of the present application, a storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the above-mentioned data synchronization method is implemented.

[0054] According to another aspect of the present application, an electronic device is provided, including a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, wherein the processor implements the above-mentioned data synchronization method when executing the computer program.

[0055] With the help of the above technical solution, the present application abandons the synchronization method of only synchronizing the data after the change, and simultaneously obtains the data before the change and the data after the change, and then determines the change value based on the data before the change and the data after the change. The update operation can be implemented according to the change value without the need to query the historical data in the first database every time, which simplifies the database operation process and improves efficiency.

[0056] The above description is only an overview of the technical solution of the present application. In order to more clearly understand the technical means of the present application, it can be implemented in accordance with the contents of the specification. In order to make the above and other purposes, features and advantages of the present application more obvious and easy to understand, the specific implementation methods of the present application are listed below. BRIEF DESCRIPTION OF THE DRAWINGS

[0057] The drawings described herein are used to provide a further understanding of the present application and constitute a part of the present application. The illustrative embodiments of the present application and their descriptions are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0058] Figure 1 A schematic diagram of a data synchronization method provided in an embodiment of the present application is shown;

[0059] Figure 2 A schematic diagram showing a flow chart of another data synchronization method provided in an embodiment of the present application is shown;

[0060] Figure 3 A schematic diagram showing a flow chart of another data synchronization method provided in an embodiment of the present application is shown;

[0061] Figure 4 A schematic diagram showing a flow chart of another data synchronization method provided in an embodiment of the present application is shown;

[0062] Figure 5 A schematic diagram showing a flow chart of another data synchronization method provided in an embodiment of the present application is shown;

[0063] Figure 6 A schematic diagram showing a flow chart of another data synchronization method provided in an embodiment of the present application is shown;

[0064] Figure 7 A data flow diagram of a data synchronization method provided by an embodiment of the present application is shown;

[0065] Figure 8 A data flow diagram of another data synchronization method provided by an embodiment of the present application is shown;

[0066] Fig. 9 A structural block diagram of a data synchronization device provided in an embodiment of the present application is shown. DETAILED DESCRIPTION

[0067] In this embodiment, a data synchronization method is provided, such as Figure 1 As shown, the method includes:

[0068] Step 101, obtaining change data in a first database, wherein the change data includes data before the change and data after the change;

[0069] The data synchronization method provided in the embodiment of the present application is applicable to the scenario where the final data needs to be calculated based on the basic data and the changed process data. The data changes can be known through the data before and after the change, without the need to query the historical data to know the historical data or the changes in the data. Based on this, the data before and after the change are first obtained in the first database, so as to use these data to know the data changes, wherein the first database is the database of the upstream system.

[0070] Step 102, determining a change value according to the data before and after the change;

[0071] Step 103: Update the second database according to the changed value.

[0072] In this embodiment, by comprehensively analyzing the data before and after the change, the data change situation can be known, that is, the change value is determined, and then the second database is updated according to the change value. Among them, the second database is the database of the downstream system, and the change data is synchronized between the first database and the second database, that is, the data transmission of the upstream and downstream systems is realized.

[0073] By applying the technical solution of this embodiment, the synchronization method of only synchronizing the data after the change is abandoned, and the data before the change and the data after the change are obtained at the same time, and then the change value is determined according to the data before the change and the data after the change. The update operation can be implemented according to the change value without having to query the historical data in the first database every time, which simplifies the database operation process and improves efficiency.

[0074] Further, as a refinement and extension of the specific implementation of the above embodiment, in order to fully illustrate the specific implementation process of this embodiment, another data synchronization method is provided, such as Figure 2 As shown, before determining the change value based on the data before and after the change, it also includes:

[0075] Step 201, splicing the changed data to obtain a changed message, and adding the changed message to a message queue;

[0076] Step 202: If it is identified that there is a change message in the message queue, the change message in the message queue is read and parsed to obtain the change data.

[0077] In this embodiment, the data before the change, the data after the change, and other information related to the change are spliced ​​together to obtain a change message. The message is added to the message queue, and then the message is read from the message queue. The message queue is used to achieve buffering, avoiding problems such as system crashes caused by inconsistent data processing efficiency of upstream and downstream systems.

[0078] Specifically, the message queue used in this application is Kafka, which is a distributed, high-throughput, and highly scalable message queue system. Among them, the message queue is a storage container. The upstream system, as a producer, sends messages (that is, change messages) to this container and stores them. The downstream system, as a consumer, obtains messages from this storage container and performs the next step of processing according to demand or its own processing capabilities.

[0079] This solution uses Kafka message queues to achieve decoupling of upstream and downstream systems, so that they will not affect each other due to different processing capabilities. Specifically, when the upstream business volume is large, the data can be stored in the message queue and its own business processing can be quickly carried out, so as not to be dragged down by the downstream system; when the downstream system has limited processing capacity, it can slowly obtain data from the message queue, so as not to be overwhelmed by the upstream system.

[0080] Furthermore, if Figure 3 As shown, in another data synchronization method, the change data is spliced ​​to obtain a change message, which specifically includes:

[0081] Step 301, determine the change type according to the change data, and write the change type into the type field, where the change type is one of the following: add, delete, modify;

[0082] In this embodiment, conventional operations for the data in the database include adding, deleting, modifying, and checking, among which adding means inserting data into a database table, deleting means deleting data from a database table, modifying means changing the value of data in a database table, and checking means querying data in a database table. Adding, deleting, and modifying can all achieve data changes, so the corresponding change type can be determined according to the changed data.

[0083] Specifically, for example, if the change type is add, insert can be written into the type field; if the change type is delete, delete can be written into the type field; if the change type is modify, update can be written into the type field. Of course, in addition to the above insert, delete and update, other identifiers can also be set as identifiers of the change type, which are not limited here.

[0084] Step 302, write the pre-change data into the pre-change field, and write the post-change data into the post-change field;

[0085] In this embodiment, according to the aforementioned method of writing the change type into the type field, the pre-change data and the post-change data are written into the pre-change field and the post-change field respectively.

[0086] Step 303: Concatenate the type field, the field before change, and the field after change to obtain the change message.

[0087] In this embodiment, multiple fields with specific data values ​​written therein are spliced ​​together to obtain a change message, wherein in addition to the type field, the field before change and the field after change, the change time field, the order number field, the unique identification field, etc. may also be spliced ​​together, which is not limited here.

[0088] For example, if only the changed data is synchronized, the synchronized message content is as follows:

[0089]

[0090]

[0091] This synchronization method cannot meet many business scenarios. For example, if you want to calculate the premium amount cumulatively, the premium amount of a certain policy is 1,000 yuan in the first transaction. After the policy is revised for some reason, the premium amount of the policy (that is, the amount in the above synchronization message) becomes 1,800 yuan. At this time, if the downstream calculation system adds the second message to the first message to get the premium of the policy as 2,800 yuan, it is obviously incorrect. The downstream system needs to know the change in the two messages, which is 800 yuan, and then based on the 1,000 yuan of the first message, it can accumulate and calculate the correct premium amount.

[0092] If the method of this embodiment is adopted to splice the change type, data before the change, data after the change, etc. together and then synchronize them, the content of the synchronized message may be as follows:

[0093]

[0094]

[0095]

[0096]

[0097] In this synchronization message, the change type is update, which is also the change type; before{} is the data before the change, and after{} is the data after the change. For example, the name field is changed from wang before the change to zhang after the change.

[0098] Furthermore, in another data synchronization method, such as Figure 4 As shown, obtaining the changed data in the first database specifically includes:

[0099] Step 401, monitoring the data log of the first database;

[0100] Step 402: If it is monitored that a data change record is written into the data log, then the change data corresponding to the data change record is extracted from the data log.

[0101] In this embodiment, the data log of the first database is monitored to obtain the changed data in real time. Specifically, operations on the first database, such as adding, deleting, modifying, and checking, will write corresponding records in the data log. If a data change record is monitored to be written in the data log, it can be considered that a change operation has been performed on the data in the first database. Based on this, the change data corresponding to the data change record is extracted from the data log.

[0102] Furthermore, after the changed data is extracted, it can be converted into JSON format and then added to the message queue. JSON occupies less storage space and is easier to parse, thus reducing space usage while improving data synchronization efficiency.

[0103] This embodiment abandons the existing method of using a jdbc (Java Data Base Connectivity) driver to connect to a database to operate data, and obtains data changes in real time by monitoring the underlying data log. This method does not compete for resources with normal business connections and has little impact on database performance.

[0104] Further, in another data synchronization method, the data log is configured to record data change records and data historical versions;

[0105] like Figure 5 As shown, the change data corresponding to the data change record is extracted from the data log, specifically including:

[0106] Step 501, determining the data history version corresponding to the data change record, wherein the data history version includes a version before the change and a version after the change;

[0107] Step 502: determine the changed data according to the historical version of the data.

[0108] In this embodiment, the data log contains historical versions of data generated by each change. If a data change record is monitored to be written in the data log, the pre-change version and post-change version corresponding to the change are determined based on the data change record, and the pre-change data is extracted from the pre-change version, and the post-change data is extracted from the post-change version.

[0109] Further, in another data synchronization method, as shown in, before determining the change value according to the data before the change and the data after the change, the method further includes:

[0110] Step 601, read the unique identifier carried by the changed data, and determine whether the changed data has been processed based on the unique identifier and historical processing records;

[0111] Step 602, if not, update the historical processing record according to the unique identifier;

[0112] Step 603: If yes, generate exception information and end.

[0113] In this embodiment, the change data may carry a unique identifier, and the unique identifier may indicate the change operation corresponding to the change data. Before processing the change data to obtain the change value, the record related to the unique identifier may be searched in the historical processing record, and the unique identifier may be used to determine whether the change data has been processed. If it has been processed, it will not be reprocessed, and the synchronization operation for the change data will be terminated directly; if it has not been processed, the change data will continue to be processed, and the record related to the unique identifier will be inserted into the historical processing record.

[0114] This embodiment ensures that each changed data is processed and only processed once based on the unique identifier, thereby avoiding missed processing or repeated processing.

[0115] Furthermore, in another data synchronization method, reading and parsing the change message in the message queue specifically includes:

[0116] If there are multiple change messages in the message queue, the change messages are read in a first-in-first-out order and the read change messages are parsed.

[0117] In this embodiment, if the speed at which the upstream system generates change data is faster than the speed at which the downstream system synchronizes change data, then change messages will accumulate in the message queue. At this time, the change messages in the message queue can be read and processed in a first-in-first-out order to avoid data confusion during the processing.

[0118] This embodiment uses a message queue to implement streaming processing of change data, and is applicable to unbounded data sets such as server logs and sensor signal data. An unbounded data set refers to data that continuously generates new data from the beginning of its generation, so the data has no boundaries.

[0119] Further, Figure 6 The overall architecture of another data synchronization method is shown. As shown in the figure, ① is the basis for supporting the entire process flow processing. In this step, the change data is captured in real time by monitoring the data log of the first database, rather than through the jdbc connection, which has little impact on the performance of the underwriting database (i.e., the first database) itself and the underwriting system (i.e., the upstream system); the content of the change data includes both the data before the change and the data after the change, and the change data is pushed to the message queue. ② is the message queue, which is used to achieve the decoupling of the upstream and downstream systems and can ensure the order of the change data. ③ is the stream processing program, which has the following characteristics: the change content is calculated by the data before and after the change in the change message; it only connects to the statistical platform database (i.e., the second database) for operation once, and the performance is very good; it is fault-tolerant and can flexibly handle various errors to ensure high availability of the process; it has idempotence, and according to the unique identifiers such as the order number and sequence number, it ensures that each message is processed and only processed once.

[0120] Further, Figure 7 A data flow diagram of a data synchronization method that does not include pre-change data in a specific scenario is shown; Figure 8 A data flow diagram of a data synchronization method including pre-change data provided by the present application in this scenario is shown.

[0121] Specifically, Figure 7 As shown, during the underwriting process, the business system will record the premium a0 of policy A in the underwriting database (i.e., the first database) of the underwriting system (i.e., the upstream system), and the data will be synchronized to the statistics platform in real time, and the statistics platform will calculate the premium income of the entire company in real time. The whole process is as follows:

[0122] (1) The customer purchases insurance, generates policy A and pays for it. The premium amount of this transaction is a0;

[0123] (2) For some reason, the customer modifies the original policy A and adds some insurance items, so the premium increases. The new premium amount is a1. At this time, the spliced ​​change message only contains a1.

[0124] (3) For some reason, the customer made another revision and reduced some insurance items. The premium amount became a2. At this time, the spliced ​​change message only contains a2.

[0125] In the data synchronization method that does not include the data before the change, when the statistical platform (i.e., the downstream system) receives the data in step (2), it needs to first query whether there is data a0 in the statistical platform database (i.e., the second database), delete it if there is, and then use the data a1 as the standard; when receiving the data in step (3), it needs to first query whether there is data a1, delete it if there is, and then use a2 as the standard. The steps are complicated and the performance is low.

[0126] And as Figure 8 As shown in the figure, for the data synchronization method that includes the data before the change, the entire data synchronization content is as follows:

[0127] (1) The customer purchases insurance, generates policy A and pays for it. The premium amount of this transaction is a0;

[0128] (2) For some reason, the customer modifies the original policy A and adds some insurance items, so the premium increases. The new premium amount is a1. At this time, the data before the change is a0, and the data after the change is a1. Therefore, the spliced ​​change message contains both a0 and a1.

[0129] (3) For some reason, the customer made another revision and reduced some insurance items. The premium amount became a2. At this time, the data before the change was a1, and the data after the change was a2. Therefore, the spliced ​​change message contains both a1 and a2.

[0130] After the statistics platform (i.e., the downstream system) obtains the change data each time, it can know whether the record has a historical version and the difference between the historical version and the current version based on the change data itself. For example, when receiving the data in step (2), it can be determined that there is a historical version based on the data a0 before the change, and the difference between the historical version and the current version, i.e., the change value, can be determined based on the data a0 before the change and the data a1 after the change. Therefore, it is only necessary to connect to the second database once each time. The steps are simple and the performance is high.

[0131] Furthermore, as a specific implementation of the above data synchronization method, the present application embodiment provides a data synchronization device, such as Fig. 9 As shown, the data synchronization device includes: an acquisition module, a calculation module and an update module.

[0132] An acquisition module, used for acquiring the change data in the first database, wherein the change data includes the data before the change and the data after the change;

[0133] A calculation module, used for determining a change value according to the data before and after the change;

[0134] The update module is used to update the second database according to the changed value.

[0135] In a specific application scenario, optionally, the device further includes a message processing module, which is specifically used to:

[0136] Splice the changed data to obtain the changed message, and add the changed message to the message queue;

[0137] If it is recognized that there is a change message in the message queue, the change message in the message queue is read and parsed to obtain the change data.

[0138] In a specific application scenario, optionally, the message processing module is further used to:

[0139] Determine the change type according to the change data, and write the change type into the type field, where the change type is one of the following: add, delete, modify;

[0140] Write the data before the change into the field before the change, and write the data after the change into the field after the change;

[0141] Concatenate the type field, the field before change, and the field after change to obtain a change message.

[0142] In a specific application scenario, optionally, the acquisition module is also used to:

[0143] Monitor the data log of the first database;

[0144] If a data change record is detected to be written into the data log, the change data corresponding to the data change record is extracted from the data log.

[0145] In a specific application scenario, optionally, the data log is configured to record data change records and data historical versions;

[0146] Get module, also used for:

[0147] Determine the data history version corresponding to the data change record, where the data history version includes the version before the change and the version after the change;

[0148] Determine the changed data based on the historical version of the data.

[0149] In a specific application scenario, optionally, the device further includes a verification module, which is specifically used to:

[0150] Read the unique identifier carried by the changed data, and determine whether the changed data has been processed based on the unique identifier and historical processing records;

[0151] If not, the historical processing record is updated according to the unique identifier;

[0152] If yes, generate an exception message and end.

[0153] In a specific application scenario, optionally, the message processing module is further used to:

[0154] If there are multiple change messages in the message queue, the change messages are read in a first-in-first-out order and the read change messages are parsed.

[0155] According to another aspect of the present application, a storage medium is provided, on which a computer program is stored, and the above-mentioned data synchronization method is implemented when the program or instructions are executed by a processor.

[0156] According to another aspect of the present application, an electronic device is provided, including a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, wherein the above-mentioned data synchronization method is implemented when the processor executes the program.

[0157] It should be noted that for other corresponding descriptions of the functional modules involved in the data synchronization device provided in the embodiment of the present application, reference can be made to Figures 1 to 8 The corresponding description in will not be repeated here.

[0158] Based on the above Figures 1 to 8The method shown in the embodiment of the present application accordingly provides a storage medium on which a computer program is stored, and when the program is executed by a processor, the above-mentioned Figures 1 to 8 The data synchronization method shown.

[0159] Based on this understanding, the technical solution of the present application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.), and includes a number of instructions for enabling an electronic device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each implementation scenario of the present application.

[0160] Based on the above Figures 1 to 8 The method shown, and Fig. 9 In order to achieve the above-mentioned purpose, the embodiment of the data synchronization device shown in the embodiment of the present application also provides an electronic device, which can be a personal computer, a server, a network device, etc., and the electronic device includes a storage medium and a processor; the storage medium is used to store a computer program; the processor is used to execute the computer program to achieve the above-mentioned Figures 1 to 8 The data synchronization method shown.

[0161] Optionally, the electronic device may further include a user interface, a network interface, a camera, a radio frequency (RF) circuit, a sensor, an audio circuit, a WI-FI module, etc. The user interface may include a display, an input unit such as a keyboard, etc., and the optional user interface may also include a USB interface, a card reader interface, etc. The network interface may optionally include a standard wired interface, a wireless interface (such as a Bluetooth interface, a WI-FI interface), etc.

[0162] Those skilled in the art will appreciate that the electronic device structure provided in this embodiment does not limit the electronic device, and may include more or fewer components, or a combination of certain components, or different component arrangements.

[0163] The storage medium may also include an operating device and a network communication module. The operating device is a program that manages and saves the hardware and software resources of the electronic device, and supports the operation of the information processing program and other software and / or programs. The network communication module is used to realize the communication between the various controls inside the storage medium, and the communication with other hardware and software in the physical device.

[0164] Through the description of the above implementation methods, those skilled in the art can clearly understand that the present application can be implemented by means of software plus a necessary general hardware platform, or by hardware.

[0165] Those skilled in the art will appreciate that the accompanying drawings are only schematic diagrams of a preferred implementation scenario, and the units or processes in the accompanying drawings are not necessarily necessary for implementing the present application. Those skilled in the art will appreciate that the units in the devices in the implementation scenario can be distributed in the devices of the implementation scenario according to the description of the implementation scenario, or can be changed accordingly and located in one or more devices different from the present implementation scenario. The units of the above-mentioned implementation scenarios can be combined into one unit, or can be further split into multiple sub-units.

[0166] The above serial numbers of this application are only for description and do not represent the advantages and disadvantages of the implementation scenarios. The above disclosure is only a few specific implementation scenarios of this application, but this application is not limited to them, and any changes that can be thought of by technicians in this field should fall within the scope of protection of this application.

Claims

1. A data synchronization method, characterized in that: The method comprises: Acquire change data in the first database, wherein the change data includes data before the change and data after the change; Determine a change value according to the data before the change and the data after the change; updating the second database according to the changed value; Before determining the change value according to the data before the change and the data after the change, the method further includes: Splicing the changed data to obtain a changed message, and adding the changed message to a message queue; If it is identified that there is a change message in the message queue, read and parse the change message in the message queue to obtain the change data; The splicing of the changed data to obtain a changed message specifically includes: Determine a change type according to the change data, and write the change type into a type field; Writing the pre-change data into the pre-change field, and writing the post-change data into the post-change field; splicing the type field, the field before change, and the field after change to obtain the change message; Before determining the change value according to the data before the change and the data after the change, the method further includes: Read the unique identifier carried by the changed data, and determine whether the changed data has been processed according to the unique identifier and the historical processing record; If not, updating the historical processing record according to the unique identifier; If yes, generate an exception message and end.

2. The method according to claim 1, characterized in that The acquiring of the change data in the first database specifically includes: Monitoring the data log of the first database; If it is monitored that a data change record is written into the data log, the change data corresponding to the data change record is extracted from the data log.

3. The method according to claim 2, characterized in that The data log is configured to record the data change record and the data historical version; Extracting the change data corresponding to the data change record in the data log specifically includes: Determine the data history version corresponding to the data change record, wherein the data history version includes a version before the change and a version after the change; The changed data is determined according to the historical version of the data.

4. The method according to claim 1, characterized in that The reading and parsing of the change message in the message queue specifically includes: If there are multiple change messages in the message queue, the change messages are read in a first-in-first-out order, and the read change messages are parsed.

5. A data synchronization device, characterized in that: The device comprises: An acquisition module, configured to acquire change data in the first database, wherein the change data includes data before the change and data after the change; A calculation module, used for determining a change value according to the data before the change and the data after the change; An updating module, used for updating the second database according to the changed value; Before determining the change value according to the data before the change and the data after the change, the method further includes: Splicing the changed data to obtain a changed message, and adding the changed message to a message queue; If it is identified that there is a change message in the message queue, read and parse the change message in the message queue to obtain the change data; The splicing of the changed data to obtain a changed message specifically includes: Determine a change type according to the change data, and write the change type into a type field; Writing the pre-change data into the pre-change field, and writing the post-change data into the post-change field; splicing the type field, the field before change, and the field after change to obtain the change message; Before determining the change value according to the data before the change and the data after the change, the method further includes: Read the unique identifier carried by the changed data, and determine whether the changed data has been processed according to the unique identifier and the historical processing record; If not, updating the historical processing record according to the unique identifier; If yes, generate an exception message and end.

6. A storage medium having a program or instruction stored thereon, characterized in that: When the program or instruction is executed by a processor, the steps of the method according to any one of claims 1 to 4 are implemented.

7. An electronic device, characterized in that: The method comprises a storage medium, a processor, and a computer program stored on the storage medium and executable on the processor, wherein the processor implements the method according to any one of claims 1 to 4 when executing the program.

Citation Information

Patent Citations

  • Data synchronization method, device and system

    CN112765277A