Data synchronization method, device, electronic device and storage medium

By assigning unique identifiers to data update events in the database log file and verifying them in the storage unit, accurate deduplication of messages is achieved, which solves the problems of low deduplication accuracy and difficulty in idempotent processing in the existing technology. , improving the operational simplicity of the business end.

CN113760920BActive Publication Date: 2024-09-20BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202010845636.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-08-20
Publication Date
2024-09-20
Estimated Expiration
2040-08-20

AI Technical Summary

Technical Problem

The accuracy of message deduplication in the existing technology is low, and the business end needs to perform idempotent processing, which increases the difficulty of implementation.

Method used

Read data update event information from the log file of the database, parse and assign a unique identifier to each piece of data, generate a synchronization message, store and verify it in the storage unit through the unique identifier, and determine whether the message is a duplicate message, thereby Achieve accurate deduplication.

Benefits of technology

It improves the accuracy of message deduplication, reduces the operational complexity of the business end, and avoids the problem of low deduplication accuracy caused by the same binlog file name and offset.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113760920B
    Figure CN113760920B
Patent Text Reader

Abstract

The embodiment of the present invention discloses a data synchronization method, device, electronic device and storage medium. The method includes reading data update event information from a log file of a database; parsing the data update event information to obtain at least one row of data, and assigning a unique identifier to each row of data; wherein each row of data contains a data update operation data; generating at least one synchronization message containing the row of data and the unique identifier corresponding to the row of data, and sending the synchronization message to a storage unit for storage, so that the business end can determine whether the synchronization message is a duplicate message according to the unique identifier in the synchronization message after obtaining the synchronization message from the storage unit. Through the technical solution of the embodiment of the present invention, business processing can achieve accurate message deduplication without idempotent operation, reduce the complexity of business end operation, and improve the accuracy of message deduplication.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The embodiments of the present invention relate to data operation technology, and more particularly to a data synchronization method, device, electronic device and storage medium. Background Art

[0002] In some Internet business scenarios, data changes in the database (such as MySQL) need to be synchronized to the business end. Binlog-based data synchronization is a common way to synchronize data changes in MySQL in real time. The specific implementation method is that the synchronization service extracts MySQL binlog events in real time, parses them and sends the messages to a streaming storage unit such as a message queue (MQ), and downstream businesses obtain data changes by consuming messages in the streaming storage unit.

[0003] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:

[0004] For some businesses, it is necessary to ensure that a message is only processed once by the business end, so a method for message deduplication is needed. There are currently two ways to deduplicate: the first is that the business end uses an idempotent deduplication solution to achieve this. This method requires additional idempotent processing operations on the business end, which increases the difficulty of business implementation. The second is to deduplicate by binlog file name and binlog file offset. Specifically, the message sent by the synchronization service to MQ carries the binlog file name and binlog file offset. After the business end obtains each message from MQ, it can cache the binlog file name and binlog file offset carried in it. If the binlog file name and binlog file offset carried in the current message already exist in the cache, it is considered that the current message has been processed and will no longer be processed. The accuracy of message deduplication achieved in this way is low. Summary of the invention

[0005] Embodiments of the present invention provide a data synchronization method, device, electronic device and storage medium to improve the accuracy of message deduplication.

[0006] In a first aspect, an embodiment of the present invention provides a data synchronization method, the method comprising:

[0007] Read data update event information from the database log file;

[0008] Parsing the data update event information to obtain at least one row of data, and assigning a unique identifier to each row of data; wherein each row of data includes one item of data update operation data;

[0009] Generate at least one synchronization message including the row data and a unique identifier corresponding to the row data, and send the synchronization message to a storage unit for storage, so that after the service end obtains the synchronization message from the storage unit, it can determine whether the synchronization message is a duplicate message based on the unique identifier in the synchronization message.

[0010] In a second aspect, an embodiment of the present invention further provides a data synchronization method, the method comprising:

[0011] Acquire a synchronization message from a storage unit; wherein the synchronization message is generated by the server after parsing the data update event information read from the log file of the database, obtaining at least one row of data, and assigning a unique identifier to each row of data, and then generating at least one synchronization message including the row of data and the unique identifier corresponding to the row of data; each row of data includes one item of data update operation data;

[0012] Parsing the synchronization message to obtain a unique identifier, and determining whether the unique identifier is stored in the cache unit;

[0013] If so, it is determined that the synchronization message is a duplicate message, and processing of the synchronization message is abandoned; otherwise, it is determined that the synchronization message is not a duplicate message, the synchronization message is processed, and the unique identifier is saved in the cache unit.

[0014] In a third aspect, an embodiment of the present invention further provides a data synchronization device, the device comprising:

[0015] An information reading module is used to read data update event information from the log file of the database;

[0016] An information parsing module, used to parse the data update event information to obtain at least one row of data, and assign a unique identifier to each row of data; wherein each row of data includes one item of data update operation data;

[0017] An information determination module is used to generate at least one synchronization message including the row data and a unique identifier corresponding to the row data, and send the synchronization message to a storage unit for storage, so that after the service end obtains the synchronization message from the storage unit, it can determine whether the synchronization message is a duplicate message based on the unique identifier in the synchronization message.

[0018] In a fourth aspect, an embodiment of the present invention further provides an electronic device, the electronic device comprising:

[0019] one or more processors;

[0020] a storage device for storing one or more programs,

[0021] When the one or more programs are executed by the one or more processors, the one or more processors implement the data synchronization method provided by any embodiment of the present invention.

[0022] In a fifth aspect, an embodiment of the present invention further provides a computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the data synchronization method provided by any embodiment of the present invention.

[0023] In a sixth aspect, an embodiment of the present invention further provides a data synchronization system, the system comprising:

[0024] The server is used to read data update event information from a log file of a database; parse the data update event information to obtain at least one row of data, and assign a unique identifier to each row of data; generate at least one synchronization message including the row of data and the unique identifier corresponding to the row of data, and send the synchronization message to a storage unit for storage; wherein each row of data includes one item of data update operation data;

[0025] The business end is used to obtain the synchronization message from the storage unit; parse the synchronization message to obtain a unique identifier, and determine whether the unique identifier is stored in the cache unit; if so, determine that the synchronization message is a duplicate message and give up processing the synchronization message; otherwise, determine that the synchronization message is not a duplicate message, process the synchronization message, and save the unique identifier to the cache unit.

[0026] The embodiments of the above invention have the following advantages or beneficial effects:

[0027] The embodiment of the present invention reads data update event information from the log file of the database; parses the data update event information to obtain at least one row of data, and assigns a unique identifier to each row of data; wherein each row of data contains a data update operation data; generates at least one synchronization message containing the row of data and the unique identifier corresponding to the row of data, and sends the synchronization message to a storage unit for storage, so that after the business end obtains the synchronization message from the storage unit, it determines whether the synchronization message is a duplicate message according to the unique identifier in the synchronization message, thereby achieving accurate deduplication of messages. The problem of the difficulty of idempotent operation required for business processing in the prior art and the low accuracy of message deduplication due to the possibility that the same binlog file name and offset may correspond to multiple MQ messages is solved, and the complexity of business end operations is reduced, and the accuracy of message deduplication is improved. BRIEF DESCRIPTION OF THE DRAWINGS

[0028] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0029] Figure 1 is a flowchart of a data synchronization method provided in Embodiment 1 of the present invention;

[0030] Figure 2 It is a schematic diagram of the database representation of the MySQL instance provided in the first embodiment of the present invention;

[0031] Figure 3 This is a schematic diagram of service end message consumption provided by Embodiment 1 of the present invention;

[0032] Figure 4 A flowchart of a data synchronization method provided in Embodiment 2 of the present invention;

[0033] Figure 5 A flowchart of a data synchronization method provided in Embodiment 3 of the present invention;

[0034] Figure 6 A schematic diagram of the structure of a data synchronization device provided in Embodiment 4 of the present invention;

[0035] Figure 7 A schematic diagram of the structure of an electronic device provided in Embodiment 5 of the present invention;

[0036] Figure 8 This is a structural diagram of a data synchronization system provided in Embodiment 7 of the present invention. DETAILED DESCRIPTION

[0037] The present invention will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the present invention, rather than to limit the present invention. It should also be noted that, for ease of description, only parts related to the present invention, rather than all structures, are shown in the accompanying drawings.

[0038] Embodiment 1

[0039] Figure 1 Flow chart of the data synchronization method in the first embodiment of the present invention. This embodiment can be applied to the situation where the data changes in the database (such as MySQL) need to be synchronized to the business end. The method can be executed by a data synchronization device, and the data synchronization device can be implemented in software and / or hardware. Figure 1 As shown, the method specifically includes:

[0040] S110: Read data update event information from a log file of a database.

[0041] In Internet business, some business scenarios require real-time synchronization of database data operations, such as real-time backup in MySQL, business cache refresh, and important business such as price change and inventory change. Optionally, binlog-based data synchronization can be used to achieve real-time synchronization of MySQL data changes.

[0042] In an embodiment of the present invention, data update event information is read from a log file of a database, which can be specifically completed by a reader module in the database. Optionally, the database can be a MySQL database, and the log file can be a binlog log file. Optionally, the Socket programming interface provided by JDK (Java Development Kit) can be called to realize remote reading of binlog logs in a MySQL database. Among them, the binlog log is a binary log of the MySQL database, which is used to record the SQL statement (except data query statement) information of the user's operation on the database. In an embodiment of the present invention, the binlog log contains data update event information of performing update operations on the stored data in the MySQL database, that is, binlog events. Specifically, the update operation includes a data insertion operation (insert), a data deletion operation (delete), and a data modification operation (update). Optionally, the data update event information can also be obtained in a specific manner according to the actual situation, and this embodiment does not limit this.

[0043] S120, parsing the data update event information to obtain at least one row of data, and assigning a unique identifier to each row of data; wherein each row of data includes one item of data update operation data.

[0044] In an embodiment of the present invention, a binlog event is read remotely, and the binlog event is parsed according to a preset parsing protocol to parse the binlog event into specific row data. Each row of data contains data of an operation on a record in a data table, that is, contains data of a data update operation. Optionally, a unique identifier is assigned to each row of data, such as a unique serial number MID (Message ID). MID is a positive integer, and each row of data has a corresponding unique serial number MID. Specifically, whenever a row of data is parsed, a unique serial number MID is assigned to the row of data according to a preset sorting rule. Optionally, any row of data parsed from a binlog event contains a data insertion operation (insert), a data deletion operation (delete), or a data modification operation (update). Optionally, a binlog event contains at least one data update operation, so parsing a binlog event can obtain at least one row of data. Specifically, if Figure 2 As shown, the data between BEGIN and COMMIT is a binlog transaction data, which contains at least one binlog event, and each binlog event can contain at least one row of data. In the embodiment of the present invention, only the insert operation (insert), data deletion operation (delete), and data modification operation (update) in data operations are discussed. Specifically, Figure 2 The first column is the binlog file name, the second column is the binlog offset start position, the third column is the binlog event type, the fourth column is the server ID, the fifth column is the binlog offset end position, the sixth column is the binlog event information, and xid is the transaction id. Figure 2 It can be seen that: the first data update operation is insert, which contains two rows of data, and the MIDs are 0 and 1; the second data update operation is insert, which contains 4 rows of data, and the MIDs are 2, 3, 4, and 5; the third data update operation is update, which contains 1 row of data, and the MID is 6; the fourth data update operation is insert, which contains 3 rows of data, and the MIDs are 7, 8, and 9. Because the reader module is a single-threaded sequential operation, the allocation of MIDs is consistent with the binlog event sequence of MySQL. Of course, the above embodiment is only an optional embodiment, and this embodiment does not limit the other implementation methods.

[0045] S130: Generate at least one synchronization message including the row data and a unique identifier corresponding to the row data, and send the synchronization message to a storage unit for storage.

[0046] In an embodiment of the present invention, the binlog event is parsed by the reader module, and a unique sequence number MID is assigned to each row of data in the binlog event. The sender module converts the number of row data in the binlog event into one or more synchronization messages, namely, MQ (Message Queue) messages, and sends them to a storage unit such as MQ for storage. Among them, any synchronization message converted from a row of data has a unique identifier MID corresponding to each row of data. Optionally, a message queue middleware can be used to send a synchronization message with a unique identifier to MQ. Specifically, the message queue middleware is an important component in a distributed system, and the synchronization message with a unique identifier converted from each row of data to be transmitted is sent to MQ, and a queue mechanism is used to implement the sending of the synchronization message to MQ. Optionally, when the synchronization message is sent successfully, MQ will return a confirmation (ack) message to the sender module, wherein the ack message contains information that the synchronization message is successfully sent. Optionally, the sender module will send the synchronization message to MQ in a parallel sending manner. Specifically, the messages of a MySQL instance are sent by multiple threads. Since the MID is parsed by the reader module, even if the sender module uses multi-threaded sending, the order and uniqueness of the MID in the synchronous message can be guaranteed while improving the synchronous message sending rate.

[0047] S140: After acquiring the synchronization message from the storage unit, the service end determines whether the synchronization message is a duplicate message according to the unique identifier in the synchronization message.

[0048] In an embodiment of the present invention, different business ends obtain the data of synchronized MySQL by consuming the synchronization messages stored in MQ. Because MQ guarantees the semantics of at least once, the same synchronization message may be received multiple times, but the MID in the same synchronization message is the same, so only the MID that has been processed needs to be cached for deduplication. Optionally, the consumer module of the business end obtains the synchronization message sent by the sender to MQ and consumes it. Optionally, the consumer module can pull messages from the specified queue, and the consumer module can also subscribe to the corresponding queue, and the MQ server pushes messages to the consumer module. Specifically, when the consumer module consumes any synchronization message in MQ, the preset parsing protocol is used to parse the synchronization message to obtain the data of the binlog event and the unique identifier MID corresponding to the synchronization message. Optionally, according to the unique identifier MID corresponding to the synchronization message, it is determined whether the unique identifier is stored in the preset cache unit; if so, it is determined that the synchronization message is a duplicate message and the synchronization message is abandoned for processing; otherwise, it is determined that the synchronization message is not a duplicate message, the synchronization message is processed, and the unique identifier is saved to the cache unit. The unique identifier MID of the processed synchronization message is stored in the preset cache unit. Optionally, in order to ensure that the cache data in the cache unit does not overflow, the cache is cleared within a preset time. Optionally, the cache can be cleared according to time, such as clearing the cache data before the preset time. It is also possible to clear all cache data in the cache unit. Of course, the above embodiment is only an optional embodiment, and specific settings can also be made according to actual conditions. The embodiment of the present invention does not limit this. For example, Figure 3 As shown in the figure, when the business end consumes msg8 for the first time, it parses and obtains MID 7. When the query cache cannot find the MID, MID 7 is added to the cache; when the business end consumes msg8 for the second time, it parses and obtains MID 7. Because the message with MID 7 has been processed, this message is ignored and not processed. Optionally, the business end can have multiple consumer modules at the same time to consume synchronous messages.

[0049] The embodiment of the present invention reads data update event information from the log file of the database; parses the data update event information to obtain at least one row of data, and assigns a unique identifier to each row of data; generates at least one synchronization message including the row of data and the unique identifier corresponding to the row of data, and sends the synchronization message to a storage unit for storage, so that after the business end obtains the synchronization message from the storage unit, it determines whether the synchronization message is a duplicate message according to the unique identifier in the synchronization message, thereby achieving accurate deduplication of messages. The problem of the difficulty of idempotent operation required for business processing in the prior art and the low accuracy of message deduplication due to the fact that the same binlog file name and offset may correspond to multiple MQ messages is solved, and the complexity of business end operations is reduced, and the accuracy of message deduplication is improved.

[0050] Embodiment 2

[0051] Figure 4 This is a flow chart of the data synchronization method provided in the second embodiment of the present invention. Based on the above embodiments, this embodiment further adds the step of periodically saving the position identification information of the row data in the log file contained in the synchronization message currently sent to the storage unit and the unique identification corresponding to the row data as a snapshot information in the snapshot file. The explanations of the terms that are the same or corresponding to the above embodiments are not repeated here. Figure 4 , the data synchronization method provided in this embodiment includes:

[0052] S210: Read data update event information from a log file of a database.

[0053] S220, parsing the data update event information to obtain at least one row of data, and assigning a unique identifier to each row of data; wherein each row of data includes one item of data update operation data.

[0054] S230. Generate at least one synchronization message including the row data and a unique identifier corresponding to the row data, and send the synchronization message to a storage unit for storage, so that after the service end obtains the synchronization message from the storage unit, it can determine whether the synchronization message is a duplicate message based on the unique identifier in the synchronization message.

[0055] S240: regularly save the position identification information of the row data in the log file contained in the synchronization message currently sent to the storage unit and the unique identification corresponding to the row data as a piece of snapshot information in a snapshot file.

[0056] In an embodiment of the present invention, in order to ensure that data is not lost in the case of task restart or active rollback, and to ensure continued synchronization from the restart or rollback location, a snapshot file can be pre-set, and the snapshot file periodically saves the snapshot information in the synchronization message stored in MQ. Optionally, the snapshot information can be saved at a preset timing interval. Specifically, the preset timing interval can be 100ms, 500ms or 1s, etc. Among them, the snapshot information includes the location identification information of the row data in the synchronization message in the log file, and the unique identifier MID corresponding to the data. Specifically, the location identification information includes but is not limited to the host address of the database, the name of the database, the name of the data table, the name of the binlog log file, and the position offset value of the row data in the currently sent synchronization message in the binlog log file.

[0057] S250. When a task restart request is received, read the last saved snapshot information from a preset snapshot file; determine the corresponding position of the position identification information in the last snapshot information in the binlog log file, continue to read the binlog time in the binlog log file from the corresponding position, and assign a unique identifier to the row data corresponding to the binlog event to be continued to be read according to the unique identifier MID in the last snapshot information.

[0058] In an embodiment of the present invention, snapshot information is saved in a snapshot file at preset time intervals. Exemplarily, when it is determined that the received request is a request for restarting a task, the last snapshot information is read from a preset snapshot file, and the unique identifier MID and location identifier information in the snapshot information are matched with the data information in the binlog log file to determine the corresponding position of the data in the binlog log file, and a unique identifier is assigned to the row data corresponding to the binlog event to be continued to be read according to the unique identifier MID in the last snapshot information; for example, when it is determined that the unique identifier MID in the last snapshot information is 7, the unique identifier assigned to the row data corresponding to the binlog event to be continued to be read can be assigned as 8 according to the sorting.

[0059] S260. When a rollback site request is received, the target snapshot information corresponding to the rollback time is read from the preset snapshot file according to the rollback time in the rollback site request; the corresponding position of the position identification information in the target snapshot information in the log file is determined, and the binlog time in the bonlog log file continues to be read from the corresponding position, and a unique identifier is assigned to the row data corresponding to the binlog event to be continued to be read according to the unique identifier MID in the target snapshot information.

[0060] In an embodiment of the present invention, the snapshot information is saved in a snapshot file at a preset timing interval. Exemplarily, when it is determined that a request for a fallback site is received, the fallback time of the fallback site is determined, and the target snapshot information corresponding to the fallback time is read from the preset snapshot file according to the fallback time in the fallback site request; and the unique identifier MID and the position identifier information in the snapshot information are matched with the data information in the binlog log file to determine the corresponding position of the data in the binlog log file, and a unique identifier is assigned to the row data corresponding to the binlog event to be continued to be read according to the unique identifier MID in the target snapshot information; for example, when it is determined that the unique identifier MID in the target snapshot information is 7, the unique identifier assigned to the row data corresponding to the binlog event to be continued to be read can be assigned as 8 according to the sorting.

[0061] It should be noted that the execution order of step S260 is not limited here. For example, when step S260 is executed, it can be executed sequentially after step 250 or before step 250.

[0062] The embodiment of the present invention reads data update event information from the log file of the database; parses the data update event information to obtain at least one row of data, and assigns a unique identifier to each row of data; generates at least one synchronization message containing the row of data and the unique identifier corresponding to the row of data, and sends the synchronization message to the storage unit for storage, so that the service end determines whether the synchronization message is a duplicate message according to the unique identifier in the synchronization message after obtaining the synchronization message from the storage unit, thereby realizing accurate deduplication of the synchronization message. In the process of deduplication of synchronization messages, it is also necessary to regularly save the location identification information and MID of the binlog event in the snapshot file to ensure that when the task is restarted or the active rollback site is actively restored from the storage, the location identification information of the binlog event to be processed is restored, and the processing is continued from this position. In solving the problem that the idempotent operation required for business processing in the prior art is difficult and the accuracy of message deduplication is low because the same binlog file name and offset may correspond to multiple MQ messages, the complexity of the business end operation is reduced, and the accuracy of message deduplication is improved. On the basis of the effect, it is possible to restore to the consistent position before the accident to continue processing the synchronization message when an accident occurs.

[0063] Embodiment 3

[0064] Figure 5 : is a flow chart of a data synchronization method in Embodiment 3 of the present invention. This embodiment can be executed by a data synchronization device, and the data synchronization device can be implemented in software and / or hardware, such as Figure 5 As shown, the method specifically includes:

[0065] S310. Obtain a synchronization message from a storage unit; wherein, the synchronization message is generated by the server after parsing the data update event information read from the log file of the database, obtaining at least one row of data, and assigning a unique identifier to each row of data, and then generating at least one synchronization message containing the row of data and a unique identifier corresponding to the row of data; wherein, each row of data respectively contains an item of data update operation data.

[0066] In the embodiment of the present invention, different business terminals obtain the data of synchronized MySQL by consuming the synchronization messages stored in MQ. Optionally, the consumer module of the business terminal obtains the synchronization message sent by the sender to MQ and consumes it. Optionally, the consumer module can pull messages from the specified queue, and the consumer module can also subscribe to the corresponding queue, and the MQ server pushes messages to the consumer module.

[0067] S320, parse the synchronization message to obtain a unique identifier, and determine whether the unique identifier is stored in the cache unit; if so, execute step S330; if not, execute step S340.

[0068] In the embodiment of the present invention, when the consumer module of the business end consumes any synchronization message in MQ, the synchronization message is parsed using a preset parsing protocol to obtain the data of the binlog event and the unique identifier MID corresponding to the synchronization message. Optionally, it is determined whether the unique identifier MID corresponding to the synchronization message is stored in the preset cache unit.

[0069] S330: Determine that the synchronization message is a duplicate message, and give up processing the synchronization message.

[0070] S340: Determine that the synchronization message is not a duplicate message, process the synchronization message, and save the unique identifier to the cache unit.

[0071] The embodiment of the present invention obtains a synchronization message from a storage unit, parses the synchronization message, obtains a unique identifier, and determines whether the unique identifier is stored in the cache unit; if so, determines that the synchronization message is a duplicate message, and abandons processing the synchronization message; otherwise, determines that the synchronization message is not a duplicate message, processes the synchronization message, and saves the unique identifier to the cache unit. The problem of the difficulty of processing data synchronization messages in the prior art due to the need for idempotent operations and the low accuracy of message deduplication due to the fact that the same binlog file name and offset may correspond to multiple MQ messages is solved, and the complexity of business-side operations is reduced, and the accuracy of message deduplication is improved.

[0072] The following is an embodiment of a data synchronization device provided in an embodiment of the present invention. The device and the data synchronization methods of the above embodiments belong to the same inventive concept. For details not described in detail in the embodiment of the data synchronization device, reference can be made to the embodiment of the above data synchronization method.

[0073] Embodiment 4

[0074] Figure 6 This is a schematic diagram of the structure of a data synchronization device provided in Embodiment 4 of the present invention. This embodiment is applicable to the situation where data changes in a database (such as MySQL) need to be synchronized to a business end. The specific structure of the device is as follows:

[0075] The information reading module 410 is used to read the data update event information from the log file of the database;

[0076] The information parsing module 420 is used to parse the data update event information to obtain at least one row of data, and assign a unique identifier to each row of data; wherein each row of data includes one item of data update operation data;

[0077] The information determination module 430 is used to generate at least one synchronization message including the row data and a unique identifier corresponding to the row data, and send the synchronization message to a storage unit for storage, so that the business end can determine whether the synchronization message is a duplicate message based on the unique identifier in the synchronization message after obtaining the synchronization message from the storage unit.

[0078] Optionally, the information determination module 430 includes:

[0079] A synchronization message acquisition unit, used for the service end to acquire the synchronization message from the storage unit;

[0080] A unique identifier determination unit is used to parse the synchronization message, obtain the unique identifier, and determine whether the unique identifier is stored in the cache unit; if so, determine that the synchronization message is a duplicate message and give up processing the synchronization message; otherwise, determine that the synchronization message is not a duplicate message, process the synchronization message, and save the unique identifier to the cache unit.

[0081] Optionally, the information determination module 430 includes:

[0082] The synchronization message sending unit is used to send at least one generated synchronization message to the storage unit in parallel through multiple threads for storage.

[0083] Optionally, the data synchronization device further includes:

[0084] The snapshot information saving module is used to regularly save the position identification information of the row data in the log file contained in the synchronization message currently sent to the storage unit and the unique identification corresponding to the row data as a piece of snapshot information in the snapshot file.

[0085] Optionally, the location identification information includes: a host address of the database, a name of the database, a name of a data table, a name of the log file, and a position offset value of the row data in the currently sent synchronization message in the log file.

[0086] Optionally, the snapshot information saving module includes:

[0087] A first snapshot information reading unit, configured to read the last saved snapshot information from the snapshot file upon receiving a task restart request;

[0088] The first snapshot information application unit is used to determine the corresponding position of the position identification information in the last snapshot information in the log file, continue to read the data update event information in the log file from the corresponding position, and assign a unique identifier to the row data corresponding to the data update event information to be continued to be read according to the unique identifier in the last snapshot information.

[0089] Optionally, the snapshot information saving module includes:

[0090] A second snapshot information reading unit is configured to read target snapshot information corresponding to the fallback time from the snapshot file according to the fallback time in the fallback location request when a fallback location request is received;

[0091] The second snapshot information application unit is used to determine the corresponding position of the position identification information in the target snapshot information in the log file, continue to read the data update event information in the log file from the corresponding position, and assign a unique identifier to the row data corresponding to the data update event information continued to be read according to the unique identifier in the target snapshot information.

[0092] The data synchronization device provided in the embodiment of the present invention can execute the method provided in any embodiment of the present invention, and has the corresponding functional modules and beneficial effects of the execution method.

[0093] It is worth noting that in the embodiment of the above-mentioned data synchronization device, the various units and modules included are only divided according to functional logic, but are not limited to the above-mentioned division, as long as the corresponding functions can be achieved; in addition, the specific name of each functional unit is only for the convenience of distinguishing each other, and is not used to limit the scope of protection of the present invention.

[0094] Embodiment 5

[0095] Figure 7 It is a schematic diagram of the structure of an electronic device in Embodiment 5 of the present invention. Figure 7 A block diagram of an exemplary electronic device 512 suitable for implementing embodiments of the present invention is shown. Figure 7 The electronic device 512 shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0096] like Figure 7 As shown, the electronic device 512 is in the form of a general purpose computing electronic device. The components of the electronic device 512 may include, but are not limited to: one or more processors or processing units 516, a system memory 528, and a bus 518 connecting different system components (including the system memory 528 and the processing unit 516).

[0097] Bus 518 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. By way of example, these architectures include, but are not limited to, an Industry Standard Architecture (ISA) bus, a Micro Channel Architecture (MAC) bus, an Enhanced ISA bus, a Video Electronics Standards Association (VESA) local bus, and a Peripheral Component Interconnect (PCI) bus.

[0098] The electronic device 512 typically includes a variety of computer system readable media. These media can be any available media that can be accessed by the electronic device 512, including volatile and non-volatile media, removable and non-removable media.

[0099] The system memory 528 may include computer system readable media in the form of volatile memory, such as random access memory (RAM) 530 and / or cache memory 532. The electronic device 512 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 543 may be used to read and write non-removable, non-volatile magnetic media ( Figure 7 not shown, usually called a "hard drive"). Although Figure 7Not shown, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, DVD-ROM, or other optical medium) may be provided. In these cases, each drive may be connected to the bus 518 via one or more data medium interfaces. The system memory 528 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the embodiments of the present invention.

[0100] A program / utility 540 having a set (at least one) of program modules 542 may be stored, for example, in system memory 528, such program modules 542 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. Program modules 542 generally perform the functions and / or methods of the embodiments described herein.

[0101] The electronic device 512 may also communicate with one or more external electronic devices 514 (e.g., keyboards, pointing electronic devices, displays 524, etc.), may communicate with one or more devices that enable a user to interact with the electronic device 512, and / or communicate with any device that enables the electronic device 512 to communicate with one or more other computing devices (e.g., a network card, a modem, etc.). Such communication may be performed through an input / output (I / O) interface 522. Furthermore, the electronic device 512 may also communicate with one or more networks (e.g., a local area network (LAN), a wide area network (WAN), and / or a public network, such as the Internet) through a network adapter 520. As shown, the network adapter 520 communicates with other modules of the electronic device 512 through a bus 518. It should be understood that although Figure 7 Not shown, other hardware and / or software modules may be used in conjunction with electronic device 512, including but not limited to microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0102] The processing unit 516 executes various functional applications and data processing by running the programs stored in the system memory 528, for example, implementing the data synchronization method provided in the embodiment of the present invention, which includes:

[0103] Read data update event information from the database log file;

[0104] Parsing the data update event information to obtain at least one row of data, and assigning a unique identifier to each row of data; wherein each row of data includes one item of data update operation data;

[0105] Generate at least one synchronization message including the row data and a unique identifier corresponding to the row data, and send the synchronization message to a storage unit for storage, so that after the service end obtains the synchronization message from the storage unit, it can determine whether the synchronization message is a duplicate message based on the unique identifier in the synchronization message.

[0106] Embodiment 6

[0107] Embodiment 6 of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the data synchronization method provided in the embodiment of the present invention is implemented. The method includes:

[0108] Read data update event information from the database log file;

[0109] Parsing the data update event information to obtain at least one row of data, and assigning a unique identifier to each row of data; wherein each row of data includes one item of data update operation data;

[0110] Generate at least one synchronization message including the row data and a unique identifier corresponding to the row data, and send the synchronization message to a storage unit for storage, so that after the service end obtains the synchronization message from the storage unit, it can determine whether the synchronization message is a duplicate message based on the unique identifier in the synchronization message.

[0111] The computer storage medium of the embodiment of the present invention can adopt any combination of one or more computer-readable media. The computer-readable medium can be a computer-readable signal medium or a computer-readable storage medium. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples (non-exhaustive list) of computer-readable storage media include: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In this document, a computer-readable storage medium can be any tangible medium containing or storing a program, which can be used by an instruction execution system, device or device or used in combination with it.

[0112] Computer-readable signal media may include data signals propagated in baseband or as part of a carrier wave, which carry computer-readable program code. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.

[0113] Program code embodied on a computer readable medium may be transmitted using any appropriate medium, including but not limited to wireless, wireline, optical fiber cable, RF, etc., or any suitable combination of the foregoing.

[0114] Computer program code for performing the operations of the present invention may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages ​​such as Java, Smalltalk, C++, and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or device. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., through the Internet using an Internet service provider).

[0115] Embodiment 7

[0116] Figure 8 Schematic diagram of the structure of the data synchronization system in the seventh embodiment of the present invention. This embodiment can be applied to the situation where the data changes in the database (such as MySQL) need to be synchronized to the business end, such as Figure 8 As shown, the system includes a server 710 and a business end 720, wherein:

[0117] The server 710 is used to read data update event information from the log file of the database; parse the data update event information to obtain at least one row of data, and assign a unique identifier to each row of data; wherein each row of data contains one data update operation data; generate at least one synchronization message containing the row of data and the unique identifier corresponding to the row of data, and send the synchronization message to the storage unit for storage.

[0118] The business end 720 is used to obtain the synchronization message from the storage unit; parse the synchronization message to obtain a unique identifier, and determine whether the unique identifier is stored in the cache unit; if so, determine that the synchronization message is a duplicate message, and give up processing the synchronization message; otherwise, determine that the synchronization message is not a duplicate message, process the synchronization message, and save the unique identifier to the cache unit.

[0119] The data synchronization system provided by the embodiment of the present invention can execute the method provided by any embodiment of the present invention, and thus has the corresponding functional modules and beneficial effects of the execution method.

[0120] Note that the above are only preferred embodiments of the present invention and the technical principles used. Those skilled in the art will understand that the present invention is not limited to the specific embodiments described herein, and that various obvious changes, readjustments and substitutions can be made by those skilled in the art without departing from the scope of protection of the present invention. Therefore, although the present invention has been described in more detail through the above embodiments, the present invention is not limited to the above embodiments, and may include more other equivalent embodiments without departing from the concept of the present invention, and the scope of the present invention is determined by the scope of the appended claims.

Claims

1. A data synchronization method, characterized in that: include: Read data update event information from the database log file; Parsing the data update event information to obtain at least one row of data, and assigning a unique identifier to each row of data; wherein each row of data includes one item of data update operation data; Generate at least one synchronization message including the row data and a unique identifier corresponding to the row data, and send the synchronization message to a storage unit for storage, so that after the service end obtains the synchronization message from the storage unit, it determines whether the synchronization message is a duplicate message according to the unique identifier in the synchronization message; The method further comprises: The position identification information of the row data in the log file and the unique identification corresponding to the row data contained in the synchronization message currently sent to the storage unit are periodically saved in the snapshot file as a piece of snapshot information.

2. The method according to claim 1, characterized in that Sending the synchronization message to a storage unit for storage includes: At least one synchronization message generated is sent in parallel to a storage unit through multiple threads for storage.

3. The method according to claim 1, characterized in that The method further comprises: When receiving a task restart request, reading the last saved snapshot information from the snapshot file; Determine the corresponding position of the position identification information in the last snapshot information in the log file, continue to read the data update event information in the log file from the corresponding position, and assign a unique identifier to the row data corresponding to the data update event information continued to be read according to the unique identifier in the last snapshot information.

4. The method according to claim 1, characterized in that: The snapshot information also includes time information; the method also includes: When receiving the fallback site request, reading target snapshot information corresponding to the fallback time from the snapshot file according to the fallback time in the fallback site request; Determine the corresponding position of the position identification information in the target snapshot information in the log file, continue to read the data update event information in the log file from the corresponding position, and assign a unique identifier to the row data corresponding to the data update event information continued to be read according to the unique identifier in the target snapshot information.

5. The method according to any one of claims 1 to 4, characterized in that The location identification information includes: the host address of the database, the name of the database, the name of the data table, the name of the log file, and the position offset value of the row data in the currently sent synchronization message in the log file.

6. A data synchronization method, characterized in that: include: Acquire a synchronization message from a storage unit; wherein the synchronization message is generated by the server after parsing the data update event information read from the log file of the database, obtaining at least one row of data, and assigning a unique identifier to each row of data, and then generating at least one synchronization message including the row of data and the unique identifier corresponding to the row of data; each row of data includes one item of data update operation data; Parsing the synchronization message to obtain a unique identifier, and determining whether the unique identifier is stored in the cache unit; If so, it is determined that the synchronization message is a duplicate message, and processing of the synchronization message is abandoned; otherwise, it is determined that the synchronization message is not a duplicate message, the synchronization message is processed, and the unique identifier is saved in the cache unit.

7. A data synchronization device, characterized in that: include: An information reading module is used to read data update event information from the log file of the database; An information parsing module, used to parse the data update event information to obtain at least one row of data, and assign a unique identifier to each row of data; wherein each row of data includes one item of data update operation data; An information determination module, used to generate at least one synchronization message including the row data and a unique identifier corresponding to the row data, and send the synchronization message to a storage unit for storage, so that after the service end obtains the synchronization message from the storage unit, it determines whether the synchronization message is a duplicate message according to the unique identifier in the synchronization message; The device also includes: The snapshot information saving module is used to regularly save the position identification information of the row data in the log file contained in the synchronization message currently sent to the storage unit and the unique identification corresponding to the row data as a piece of snapshot information in the snapshot file.

8. An electronic device, characterized in that: The electronic device comprises: one or more processors; A memory for storing one or more programs; When the one or more programs are executed by the one or more processors, the one or more processors implement the data synchronization method as described in any one of claims 1-6.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the data synchronization method as described in any one of claims 1 to 6 is implemented.

10. A data synchronization system, characterized in that: include: The server is used to read data update event information from the database log file; Parsing the data update event information to obtain at least one row of data, and assigning a unique identifier to each row of data; Generate at least one synchronization message including the row data and a unique identifier corresponding to the row data, and send the synchronization message to a storage unit for storage; wherein each row data includes one item of data update operation data; The business end is used to obtain the synchronization message from the storage unit; parse the synchronization message to obtain a unique identifier, and determine whether the unique identifier is stored in the cache unit; if so, determine that the synchronization message is a duplicate message and give up processing the synchronization message; otherwise, determine that the synchronization message is not a duplicate message, process the synchronization message, and save the unique identifier to the cache unit.