Database synchronization method and device, equipment and storage medium
By generating and distributing synchronization messages from the source device, verifying and storing data on the target device, and maintaining sequence numbers at both ends, the database synchronization achieves universality and flexibility, solving the complexity and communication interruption problems of database synchronization in existing technologies, and realizing breakpoint resume and resource optimization.
Patent Information
- Application Number
- CN202511367287.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-24
- Publication Date
- 2025-10-31
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing database synchronization methods are insufficient in terms of deployment complexity and versatility, especially for embedded databases, and cannot resume interrupted transmissions when communication is interrupted, resulting in wasted resources.
Synchronization messages are generated by periodically reading data from the source database from the source device and then distributed to the corresponding device based on the target device identifier. The target device performs verification and storage, and both ends maintain the minimum sequence number of the synchronized data to enable breakpoint resume.
It improves the versatility and flexibility of database synchronization, supports multiple database types, and enables breakpoint resumption after communication interruption, avoiding resource waste caused by repeated synchronization operations.
Smart Images

Figure CN120873088A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a database synchronization method, apparatus, device, and storage medium. Background Technology
[0002] In fields such as industrial automation, the Internet of Things (IoT), and edge computing, terminal devices typically store operational data locally in the form of databases to enable real-time data acquisition and local decision-making. If further data analysis or management is required, the terminal device can synchronize the data from its local database to a server or cloud platform database for remote analysis.
[0003] In existing technologies, when implementing database synchronization, Change Data Capture (CDC) technology is usually used in conjunction with message middleware to capture data insertion, update and deletion events from the change log (binlog) of the source database, convert these events into structured messages, and asynchronously distribute them to the target database through message queues (such as Kafka).
[0004] However, the deployment process of the above synchronization method is relatively complex. CDC technology relies on the database to support binlog function, which is not suitable for some databases, such as embedded relational database engine SQLite, low-power embedded database, etc. In addition, the operation and maintenance and configuration of the synchronization solution are relatively complex. Secondly, in the event of abnormal power failure or network interruption, it is not possible to resume interrupted transmission. Summary of the Invention
[0005] This invention provides a database synchronization method, apparatus, device, and storage medium, which can improve the versatility and flexibility of the database synchronization method. It can also enable breakpoint resumption after communication interruption during the database synchronization process, avoiding resource waste caused by repeated data synchronization operations.
[0006] According to one aspect of the present invention, a database synchronization method is provided, the method being applied to a source device, comprising:
[0007] Periodically read the data to be synchronized from the source database and generate a synchronization message for each row of data to be synchronized;
[0008] The synchronization message includes the sequence number of the historical synchronization data, the data to be synchronized, and the sequence number of the data to be synchronized.
[0009] Based on the target device identifier corresponding to each row of data to be synchronized, each synchronization message is distributed to the corresponding target device so that each target device can perform data storage operation according to the synchronization message;
[0010] Upon receiving the confirmation signal from the target device, the minimum sequence number corresponding to the synchronized data in the source database is updated.
[0011] Optionally, periodically read the data to be synchronized from the source database, including:
[0012] Data is read in batches from the source database into the message chain using a synchronous timer;
[0013] Based on the smallest sequence number corresponding to the currently synchronized data in the source database and the sequence number corresponding to each row of data in the message chain, data to be synchronized is filtered in the message chain.
[0014] Optionally, distributing each of the synchronization messages to the corresponding target device includes:
[0015] The message queue telemetry transmission protocol is used to distribute multiple synchronous messages in parallel to their respective target devices.
[0016] Receive confirmation signals sent by the target device, including:
[0017] The message queue telemetry transmission protocol is used to receive acknowledgment signals sent by the target device.
[0018] According to another aspect of the present invention, a database synchronization method is provided, the method being applied to a target device, comprising:
[0019] After receiving the synchronization message sent by the source device, the synchronization message is verified.
[0020] If the synchronization message is successfully verified, the data to be synchronized in the synchronization message is written into the target database.
[0021] The minimum sequence number corresponding to the synchronized data in the target database is updated, an acknowledgment signal is generated based on the updated minimum sequence number, and the acknowledgment signal is fed back to the source device.
[0022] Optionally, the synchronization message is validated, including:
[0023] Determine whether the sequence number of the data to be synchronized in the synchronization message is less than or equal to the smallest sequence number of the already synchronized data in the target database; or,
[0024] In the synchronization message, is the sequence number corresponding to the historical synchronization data greater than the minimum sequence number corresponding to the synchronized data in the target database?
[0025] If so, then the synchronization message verification is determined to have failed.
[0026] Optionally, after receiving the synchronization message sent by the source device, the method further includes: starting a preset timer;
[0027] After verifying the synchronization message, the process also includes:
[0028] If the synchronization message verification fails, the synchronization message is discarded, the timer is turned off, and the system waits for the source device to resend the synchronization message.
[0029] Feeding the confirmation signal back to the source device includes:
[0030] After detecting that the timer duration equals the preset duration, the confirmation signal is fed back to the source device.
[0031] According to another aspect of the present invention, a database synchronization apparatus is provided, the apparatus being applied to a source device, comprising:
[0032] The data reading module is used to periodically read the data to be synchronized from the source database and generate a synchronization message corresponding to each row of data to be synchronized.
[0033] The synchronization message includes the sequence number of the historical synchronization data, the data to be synchronized, and the sequence number of the data to be synchronized.
[0034] The synchronization message distribution module is used to distribute each synchronization message to the corresponding target device according to the target device identifier corresponding to each row of data to be synchronized, so that each target device can perform data storage operation according to the synchronization message;
[0035] The signal receiving module is used to update the minimum sequence number corresponding to the synchronized data in the source database after receiving the confirmation signal sent by the target device.
[0036] According to another aspect of the present invention, a database synchronization apparatus is provided, the apparatus being applied to a target device, comprising:
[0037] The synchronization message receiving module is used to verify the synchronization message after receiving it from the source device.
[0038] The data writing module is used to write the data to be synchronized in the synchronization message into the target database if the synchronization message verification is successful.
[0039] The signal feedback module is used to update the minimum sequence number corresponding to the synchronized data in the target database, generate an acknowledgment signal based on the updated minimum sequence number, and feed the acknowledgment signal back to the source device.
[0040] According to another aspect of the present invention, an electronic device is provided, the electronic device comprising:
[0041] At least one processor; and
[0042] A memory communicatively connected to the at least one processor; wherein,
[0043] The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the database synchronization method according to any embodiment of the present invention.
[0044] According to another aspect of the present invention, a computer-readable storage medium is provided, the computer-readable storage medium storing computer instructions for causing a processor to execute and implement the database synchronization method according to any embodiment of the present invention.
[0045] According to another aspect of the present invention, a computer program product is provided, which, when executed by a processor, implements the database synchronization method described in any embodiment of the present invention.
[0046] The technical solution provided by this invention involves a source device periodically reading data to be synchronized from a source database, generating a synchronization message corresponding to each row of data to be synchronized, and distributing each synchronization message to the corresponding target device according to the target device identifier corresponding to each row of data to be synchronized. This enables each target device to perform data storage operations based on the synchronization message. Upon receiving an acknowledgment signal from the target device, the minimum sequence number corresponding to the synchronized data in the source database is updated. This approach can improve the versatility and flexibility of the database synchronization method. It can also enable breakpoint resumption after a communication interruption during the database synchronization process, avoiding resource waste caused by repeatedly performing data synchronization operations.
[0047] It should be understood that the description in this section is not intended to identify key or essential features of the embodiments of the present invention, nor is it intended to limit the scope of the invention. Other features of the invention will become readily apparent from the following description. Attached Figure Description
[0048] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0049] Figure 1 This is a flowchart of a database synchronization method provided according to an embodiment of the present invention;
[0050] Figure 2a This is a flowchart of another database synchronization method provided according to an embodiment of the present invention;
[0051] Figure 2bThis is a schematic diagram illustrating a scenario in which a database synchronization method provided by an embodiment of the present invention is applied;
[0052] Figure 3 This is a flowchart of another database synchronization method provided according to an embodiment of the present invention;
[0053] Figure 4 This is a flowchart of another database synchronization method provided according to an embodiment of the present invention;
[0054] Figure 5 This is a schematic diagram of the structure of a database synchronization device according to an embodiment of the present invention;
[0055] Figure 6 This is a schematic diagram of another database synchronization device provided according to an embodiment of the present invention;
[0056] Figure 7 This is a schematic diagram of the structure of an electronic device that implements the database synchronization method of this invention. Detailed Implementation
[0057] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0058] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0059] Figure 1 This is a flowchart illustrating a database synchronization method provided in an embodiment of the present invention. This embodiment is applicable to situations where a source device synchronizes data from a source database to a target database on a target device. This method can be executed by a database synchronization device, which can be implemented in hardware and / or software and configured in the source device. Figure 1As shown, the method includes:
[0060] Step 110: Periodically read the data to be synchronized from the source database and generate a synchronization message corresponding to each row of data to be synchronized.
[0061] In this embodiment, the source device is an electronic device that needs to synchronize its local database to another device, and the target device is an electronic device used to receive and store the database data from the source device. Taking an energy storage system as an example, the source device can be a Battery Distribution Unit (BDU), and the target device can be a Battery Array Unit (BAU).
[0062] In this step, the source device can periodically read updated data from the source database as data to be synchronized, and then encapsulate each row of data to be synchronized to obtain a synchronization message corresponding to each row of data to be synchronized. The synchronization message includes the sequence number corresponding to the historical synchronized data, the current data to be synchronized, and the sequence number (seq) corresponding to the current data to be synchronized.
[0063] The sequence number corresponding to the historical synchronization data can be the data sequence number (last_seq) when the data synchronization operation was last completed on the source device.
[0064] Step 120: Based on the target device identifier corresponding to each row of data to be synchronized, distribute each synchronization message to the corresponding target device so that each target device can perform data storage operation according to the synchronization message.
[0065] In this step, the source device can obtain the target device identifier (e.g., device ID, target address, etc.) corresponding to each line of data to be synchronized in the source database according to a predefined configuration file. Then, based on each target device identifier, it sends each synchronization message to the corresponding target device. After receiving the corresponding synchronization message, the target device can verify the synchronization message, such as checking whether the data sequence number in the synchronization message is compliant and whether the synchronization message matches its own target device. If the synchronization message verification is successful, the data to be synchronized contained in the synchronization message is stored in the target database.
[0066] Step 130: After receiving the confirmation signal from the target device, update the minimum sequence number corresponding to the synchronized data in the source database.
[0067] In this embodiment, if the target device completes the storage operation of the data to be synchronized, it can update the minimum sequence number corresponding to the currently synchronized data in the target database, then generate an acknowledgment based on the updated minimum sequence number, and send the acknowledgment back to the target device. After receiving the acknowledgment, the target device can synchronize and update the minimum sequence number corresponding to the synchronized data in the source database.
[0068] In a specific embodiment, before step 110, it is assumed that the minimum sequence number of the synchronized data in the source database is 10 (that is, 10 data items in the source database have been synchronized). The minimum sequence number of the data to be synchronized in the synchronization message generated in step 110 is 11. After the target device receives this synchronization message and completes the data storage operation, it can update the minimum sequence number of the synchronized data in the target database to 11, and then send an acknowledgment signal back to the source device. After receiving this acknowledgment signal, the source device can also update the minimum sequence number of the synchronized data in the source database to 11.
[0069] The advantage of this setup is that by maintaining the minimum sequence number corresponding to the synchronized data on both the source and target devices, the database synchronization process can be resumed from where it was interrupted in the event of a power outage or network interruption.
[0070] The technical solution provided by this invention involves a source device periodically reading data to be synchronized from a source database, generating a synchronization message corresponding to each row of data to be synchronized, and distributing each synchronization message to the corresponding target device based on the target device identifier corresponding to each row of data to be synchronized. This allows each target device to perform data storage operations based on the synchronization messages. Upon receiving an acknowledgment signal from the target device, the minimum sequence number corresponding to the synchronized data in the source database is updated. This method does not require the target database to support binlog functionality; it only requires the source and target databases to have basic query interfaces enabled, thereby improving the versatility of the database synchronization method. Furthermore, the database synchronization method provided in this embodiment also supports targeted data synchronization, allowing users to specify specific data to be synchronized to specific target devices, thus improving the flexibility of the synchronization method. It also enables breakpoint resumption after communication interruption during the database synchronization process, avoiding resource waste caused by repeated data synchronization operations.
[0071] Figure 2a A flowchart of another database synchronization method provided in an embodiment of the present invention, applied to a source device, such as... Figure 2a As shown, the method includes:
[0072] Step 210: Use a synchronization timer to read data in batches from the source database into the message chain list.
[0073] In this embodiment, data can be periodically read from the source database into the message chain list in batches using a synchronization timer. The time interval corresponding to each trigger of the synchronization timer can be 100ms. The specific value can be adjusted according to the actual situation, and this embodiment does not impose any restrictions on it.
[0074] Step 220: Based on the smallest sequence number corresponding to the currently recorded synchronized data in the source database and the sequence number corresponding to each row of data in the message chain, filter the data to be synchronized in the message chain.
[0075] In this step, specifically, the sequence number corresponding to each row of data in the message chain can be traversed to determine whether the smallest sequence number corresponding to the synchronized data of the current record in the source database is greater than or equal to the sequence number corresponding to the current row of data. If so, the synchronization of the current row of data is completed and this row of data is deleted; otherwise, the current row of data is treated as data to be synchronized.
[0076] The advantage of this setup is that it allows for quick filtering of data to be synchronized in the source database, improving database synchronization efficiency.
[0077] Step 230: Generate the synchronization message corresponding to each row of data to be synchronized.
[0078] Step 240: Based on the target device identifier corresponding to each row of data to be synchronized, the Message Queuing Telemetry Transport (MQTT) protocol is used to distribute multiple synchronization messages in parallel to the corresponding target devices, so that each target device can perform data storage operations according to the synchronization messages.
[0079] In one specific embodiment Figure 2b This can be a schematic diagram illustrating a scenario where a database synchronization method is applied in this embodiment, such as... Figure 2b As shown, if the data to be synchronized in the source database corresponds to multiple target devices, the source device can use the MQTT protocol to distribute multiple synchronization messages in parallel to the corresponding multiple target devices, thereby improving the synchronization efficiency of the database.
[0080] In this embodiment, optionally, after generating the synchronization message corresponding to each line of data to be synchronized, a timer with a duration of 5 seconds can be set, and the synchronization of the data corresponding to the synchronization message can be monitored in real time. If the synchronization is not completed after 5 seconds, the synchronization message will be resent.
[0081] Step 250: After receiving the acknowledgment signal sent by the target device using the MQTT protocol, update the minimum sequence number corresponding to the synchronized data in the source database.
[0082] The technical solution provided by this invention uses a synchronization timer on the source device to read data in batches from the source database into a message chain. Based on the minimum sequence number corresponding to the currently synchronized data in the source database and the sequence number corresponding to each row of data in the message chain, data to be synchronized is filtered in the message chain, generating a synchronization message corresponding to each row of data to be synchronized. Based on the target device identifier corresponding to each row of data to be synchronized, multiple synchronization messages are distributed in parallel to the corresponding target devices using the MQTT protocol, enabling each target device to perform data storage operations according to the synchronization messages. The technique of updating the minimum sequence number corresponding to the synchronized data in the source database after receiving an acknowledgment signal from the target device using the MQTT protocol improves the versatility and flexibility of the database synchronization method. It also enables breakpoint resumption after a communication interruption during the database synchronization process, avoiding resource waste caused by repeatedly performing data synchronization operations.
[0083] Figure 3 This is a flowchart illustrating a database synchronization method provided in an embodiment of the present invention. This embodiment is applicable to situations where a source device synchronizes data from a source database to a target database on a target device. This method can be executed by a database synchronization device, which can be implemented in hardware and / or software and configured in the target device. Figure 3 As shown, the method includes:
[0084] Step 310: After receiving the synchronization message sent by the source device, verify the synchronization message.
[0085] Step 320: If the synchronization message verification is successful, the data to be synchronized in the synchronization message is written into the target database.
[0086] Step 330: Update the minimum sequence number corresponding to the synchronized data in the target database, generate an acknowledgment signal based on the updated minimum sequence number, and send the acknowledgment signal back to the source device.
[0087] The technical solution provided by this invention, through the following steps: after the target device receives a synchronization message sent by the source device, it verifies the synchronization message. If the synchronization message verification is successful, the data to be synchronized in the synchronization message is written into the target database. The minimum sequence number corresponding to the synchronized data in the target database is updated. An acknowledgment signal is generated based on the updated minimum sequence number, and the acknowledgment signal is fed back to the source device. This technical approach can improve the versatility and flexibility of the database synchronization method. It can also enable breakpoint resumption after a communication interruption during the database synchronization process, avoiding resource waste caused by repeatedly performing data synchronization operations.
[0088] Figure 4 A flowchart of another database synchronization method provided in an embodiment of the present invention, applied to a target device, such as... Figure 4 As shown, the method includes:
[0089] Step 410: After receiving the synchronization message sent by the source device, start the preset timer.
[0090] Step 420: Determine whether the sequence number of the currently synchronized data in the synchronization message is less than or equal to the minimum sequence number of the synchronized data in the target database; or whether the sequence number of the historical synchronized data in the synchronization message is greater than the minimum sequence number of the synchronized data in the target database. If yes, proceed to step 430; if no, proceed to steps 440-460.
[0091] In this step, specifically, the target device can determine whether the sequence number (seq) of the data to be synchronized in the current synchronization message is less than or equal to the minimum sequence number (min_seq) of the synchronized data in the target database; or, whether the sequence number (last_seq) of the data when the data synchronization operation was last completed in the synchronization message is greater than the minimum sequence number (min_seq) of the synchronized data in the target database. If so, it is determined that the synchronization message has been missed or out of order.
[0092] The advantage of this setting is that by setting double sequence numbers in the synchronization message, the accuracy of the synchronization message verification results and the robustness of the database synchronization results can be improved.
[0093] Step 430: If the synchronization message verification fails, discard the synchronization message, turn off the timer, and wait for the source device to resend the synchronization message.
[0094] Step 440: Confirm that the synchronization message verification is successful, and write the data to be synchronized in the synchronization message into the target database.
[0095] Step 450: Update the minimum sequence number corresponding to the synchronized data in the target database, and generate an acknowledgment signal based on the updated minimum sequence number.
[0096] Step 460: After detecting that the timer duration is equal to the preset duration, the confirmation signal is fed back to the source device.
[0097] In this step, optionally, the preset duration can be 2 seconds. The specific value can be adjusted according to the actual situation, and this embodiment does not limit it.
[0098] The advantage of this setup is that by providing a timed sending and timed feedback response mechanism, it can avoid frequently triggering data requests during data synchronization, thereby reducing resource overhead during data interaction between the source and target devices.
[0099] The technical solution provided by this invention improves the versatility and flexibility of database synchronization methods by starting a preset timer after the target device receives a synchronization message from the source device, determining whether the sequence number corresponding to the currently synchronized data in the synchronization message is less than or equal to the minimum sequence number corresponding to the synchronized data in the target database; or whether the sequence number corresponding to the historical synchronized data in the synchronization message is greater than the minimum sequence number corresponding to the synchronized data in the target database. If yes, the synchronization message verification is determined to have failed, the synchronization message is discarded, the timer is turned off, and the source device is waited to resend the synchronization message. If no, the synchronization message verification is determined to have succeeded, the data to be synchronized in the synchronization message is written into the target database, the minimum sequence number corresponding to the synchronized data in the target database is updated, an acknowledgment signal is generated based on the updated minimum sequence number, and the acknowledgment signal is fed back to the source device after the timer duration is detected to be equal to the preset duration. This technical approach improves the versatility and flexibility of database synchronization methods, enables breakpoint resumption after communication interruption during database synchronization, and avoids resource waste caused by repeated data synchronization operations.
[0100] Figure 5 This invention provides a schematic diagram of a database synchronization device, which is applied in a source device, such as... Figure 5 As shown, the device includes: a data reading module 510, a synchronous message distribution module 520, and a signal receiving module 530.
[0101] The data reading module 510 is used to periodically read the data to be synchronized from the source database and generate a synchronization message corresponding to each row of data to be synchronized.
[0102] The synchronization message includes the sequence number of the historical synchronization data, the data to be synchronized, and the sequence number of the data to be synchronized.
[0103] The synchronization message distribution module 520 is used to distribute each synchronization message to the corresponding target device according to the target device identifier corresponding to each row of data to be synchronized, so that each target device can perform data storage operation according to the synchronization message;
[0104] The signal receiving module 530 is used to update the minimum sequence number corresponding to the synchronized data in the source database after receiving the confirmation signal sent by the target device.
[0105] The technical solution provided by this invention involves a source device periodically reading data to be synchronized from a source database, generating a synchronization message corresponding to each row of data to be synchronized, and distributing each synchronization message to the corresponding target device based on the target device identifier corresponding to each row of data to be synchronized. This allows each target device to perform data storage operations based on the synchronization messages. Upon receiving an acknowledgment signal from the target device, the minimum sequence number corresponding to the synchronized data in the source database is updated. This method does not require the target database to support binlog functionality; it only requires the source and target databases to have basic query interfaces enabled, thereby improving the versatility of the database synchronization method. Furthermore, the database synchronization method provided in this embodiment also supports targeted data synchronization, allowing users to specify specific data to be synchronized to specific target devices, thus improving the flexibility of the synchronization method. It also enables breakpoint resumption after communication interruption during the database synchronization process, avoiding resource waste caused by repeated data synchronization operations.
[0106] Based on the above embodiments, the data reading module 510 includes:
[0107] The timed read unit is used to read data in batches from the source database into the message chain list via a synchronous timer;
[0108] The data filtering unit is used to filter the data to be synchronized in the message chain list based on the smallest sequence number corresponding to the synchronized data currently recorded in the source database and the sequence number corresponding to each row of data in the message chain list.
[0109] The synchronous message distribution module 520 includes:
[0110] The parallel processing unit is used to distribute multiple synchronous messages in parallel to their respective target devices using the MQTT protocol.
[0111] The signal receiving module 530 includes:
[0112] The MQTT protocol transmission unit is used to receive acknowledgment signals sent by the target device using the MQTT protocol.
[0113] The above-described apparatus can execute the methods provided in all the foregoing embodiments of the present invention, and has the corresponding functional modules and beneficial effects for executing the above methods. Technical details not described in detail in the embodiments of the present invention can be found in the methods provided in all the foregoing embodiments of the present invention.
[0114] Figure 6 This is a schematic diagram of a database synchronization device provided in an embodiment of the present invention. The device is applied to a target device, such as... Figure 6 As shown, the device includes: a synchronization message receiving module 610, a data writing module 620, and a signal feedback module 630.
[0115] The synchronization message receiving module 610 is used to verify the synchronization message after receiving it from the source device.
[0116] The data writing module 620 is used to write the data to be synchronized in the synchronization message into the target database if the synchronization message verification is successful.
[0117] The signal feedback module 630 is used to update the minimum sequence number corresponding to the synchronized data in the target database, generate an acknowledgment signal based on the updated minimum sequence number, and feed the acknowledgment signal back to the source device.
[0118] The technical solution provided by this invention, through the following steps: after the target device receives a synchronization message sent by the source device, it verifies the synchronization message. If the synchronization message verification is successful, the data to be synchronized in the synchronization message is written into the target database. The minimum sequence number corresponding to the synchronized data in the target database is updated. An acknowledgment signal is generated based on the updated minimum sequence number, and the acknowledgment signal is fed back to the source device. This technical approach can improve the versatility and flexibility of the database synchronization method. It can also enable breakpoint resumption after a communication interruption during the database synchronization process, avoiding resource waste caused by repeatedly performing data synchronization operations.
[0119] Based on the above embodiments, the synchronization message receiving module 610 includes:
[0120] The message verification unit is used to determine whether the sequence number corresponding to the currently synchronized data in the synchronization message is less than or equal to the minimum sequence number corresponding to the synchronized data in the target database; or whether the sequence number corresponding to the historical synchronized data in the synchronization message is greater than the minimum sequence number corresponding to the synchronized data in the target database; if so, the synchronization message verification is determined to have failed.
[0121] The timer start unit is used to start a preset timer after receiving a synchronization message sent by the source device;
[0122] The message discarding unit is used to discard the synchronization message if the synchronization message verification fails, and to turn off the timer and wait for the source device to resend the synchronization message.
[0123] The signal feedback module 630 includes:
[0124] The timing feedback unit is used to send the confirmation signal back to the source device after detecting that the timer duration is equal to the preset duration.
[0125] The above-described apparatus can execute the methods provided in all the foregoing embodiments of the present invention, and has the corresponding functional modules and beneficial effects for executing the above methods. Technical details not described in detail in the embodiments of the present invention can be found in the methods provided in all the foregoing embodiments of the present invention.
[0126] Figure 7 A schematic diagram of an electronic device 10, which can be used to implement embodiments of the present invention, is shown. The electronic device is intended to represent various forms of digital computers, such as laptop computers, desktop computers, workstations, personal digital assistants, servers, blade servers, mainframe computers, and other suitable computers. The electronic device can also represent various forms of mobile devices, such as personal digital processors, cellular phones, smartphones, wearable devices (e.g., helmets, glasses, watches, etc.), and other similar computing devices. The components shown herein, their connections and relationships, and their functions are merely illustrative and are not intended to limit the implementation of the invention described and / or claimed herein.
[0127] like Figure 7 As shown, the electronic device 10 includes at least one processor 11 and a memory, such as a read-only memory (ROM) 12 or a random access memory (RAM) 13, communicatively connected to the at least one processor 11. The memory stores computer programs executable by the at least one processor. The processor 11 can perform various appropriate actions and processes based on the computer program stored in the ROM 12 or loaded from storage unit 18 into the RAM 13. The RAM 13 can also store various programs and data required for the operation of the electronic device 10. The processor 11, ROM 12, and RAM 13 are interconnected via a bus 14. An input / output (I / O) interface 15 is also connected to the bus 14.
[0128] Multiple components in electronic device 10 are connected to I / O interface 15, including: input unit 16, such as keyboard, mouse, etc.; output unit 17, such as various types of displays, speakers, etc.; storage unit 18, such as disk, optical disk, etc.; and communication unit 19, such as network card, modem, wireless transceiver, etc. Communication unit 19 allows electronic device 10 to exchange information / data with other devices through computer networks such as the Internet and / or various telecommunications networks.
[0129] Processor 11 can be a variety of general-purpose and / or special-purpose processing components with processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various special-purpose artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any suitable processor, controller, microcontroller, etc. Processor 11 performs the various methods and processes described above, such as database synchronization methods.
[0130] In some embodiments, the database synchronization method may be implemented as a computer program tangibly contained in a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and / or installed on electronic device 10 via ROM 12 and / or communication unit 19. When the computer program is loaded into RAM 13 and executed by processor 11, one or more steps of the database synchronization method described above may be performed. Alternatively, in other embodiments, processor 11 may be configured to perform the database synchronization method by any other suitable means (e.g., by means of firmware).
[0131] Various embodiments of the systems and techniques described above herein can be implemented in digital electronic circuit systems, integrated circuit systems, field-programmable gate arrays (FPGAs), application-specific integrated circuits (ASICs), application-specific standard products (ASSPs), systems-on-a-chip (SoCs), payload-programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include implementations in one or more computer programs that can be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor, capable of receiving data and instructions from a storage system, at least one input device, and at least one output device, and transmitting data and instructions to the storage system, the at least one input device, and the at least one output device.
[0132] Computer programs used to implement the methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable data processing device, such that when executed by the processor, the computer programs cause the functions / operations specified in the flowcharts and / or block diagrams to be performed. The computer programs may be executed entirely on a machine, partially on a machine, or as a standalone software package, partially on a machine and partially on a remote machine, or entirely on a remote machine or server.
[0133] In the context of this invention, a computer-readable storage medium can be a tangible medium that may contain or store a computer program for use by or in conjunction with an instruction execution system, apparatus, or device. A computer-readable storage medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination thereof. Alternatively, a computer-readable storage medium may be a machine-readable signal medium. More specific examples of machine-readable storage media include electrical connections based on one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fibers, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof.
[0134] To provide interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user provides input to the electronic device. Other types of devices can also be used to provide interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including sound input, voice input, or tactile input).
[0135] The systems and technologies described herein can be implemented in computing systems that include backend components (e.g., as data servers), or middleware components (e.g., application servers), or frontend components (e.g., user computers with graphical user interfaces or web browsers through which users can interact with implementations of the systems and technologies described herein), or any combination of such backend, middleware, or frontend components. The components of the system can be interconnected via digital data communication of any form or medium (e.g., communication networks). Examples of communication networks include local area networks (LANs), wide area networks (WANs), blockchain networks, and the Internet.
[0136] A computing system can include clients and servers. Clients and servers are generally located far apart and typically interact through communication networks. The client-server relationship is created by computer programs running on the respective computers and having a client-server relationship with each other. The server can be a cloud server, also known as a cloud computing server or cloud host, which is a hosting product within the cloud computing service system to address the shortcomings of traditional physical hosts and VPS services, such as high management difficulty and weak business scalability.
[0137] It should be understood that the various forms of processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in this invention can be executed in parallel, sequentially, or in different orders, as long as the desired result of the technical solution of this invention can be achieved, and this is not limited herein.
[0138] The specific embodiments described above do not constitute a limitation on the scope of protection of this invention. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of this invention should be included within the scope of protection of this invention.
Claims
1. A database synchronization method, characterized in that, The method is applied to a source device and includes: Periodically read the data to be synchronized from the source database and generate a synchronization message for each row of data to be synchronized; The synchronization message includes the sequence number of the historical synchronization data, the data to be synchronized, and the sequence number of the data to be synchronized. Based on the target device identifier corresponding to each row of data to be synchronized, each synchronization message is distributed to the corresponding target device so that each target device can perform data storage operation according to the synchronization message; Upon receiving the confirmation signal from the target device, the minimum sequence number corresponding to the synchronized data in the source database is updated.
2. The method according to claim 1, characterized in that, Periodically read the data to be synchronized from the source database, including: Data is read in batches from the source database into the message chain using a synchronous timer; Based on the smallest sequence number corresponding to the currently synchronized data in the source database and the sequence number corresponding to each row of data in the message chain, data to be synchronized is filtered in the message chain.
3. The method according to claim 1, characterized in that, Distributing each of the aforementioned synchronization messages to the corresponding target devices includes: The message queue telemetry transmission protocol is used to distribute multiple synchronous messages in parallel to their respective target devices. Receive confirmation signals sent by the target device, including: The message queue telemetry transmission protocol is used to receive acknowledgment signals sent by the target device.
4. A database synchronization method, characterized in that, The method is applied to the target device and includes: After receiving the synchronization message sent by the source device, the synchronization message is verified. If the synchronization message is successfully verified, the data to be synchronized in the synchronization message is written into the target database. The minimum sequence number corresponding to the synchronized data in the target database is updated, an acknowledgment signal is generated based on the updated minimum sequence number, and the acknowledgment signal is fed back to the source device.
5. The method according to claim 4, characterized in that, Verification of the synchronization message includes: Determine whether the sequence number of the data to be synchronized in the synchronization message is less than or equal to the smallest sequence number of the already synchronized data in the target database; or, In the synchronization message, is the sequence number corresponding to the historical synchronization data greater than the minimum sequence number corresponding to the synchronized data in the target database? If so, then the synchronization message verification is determined to have failed.
6. The method according to claim 4, characterized in that, After receiving the synchronization message from the source device, the process also includes: starting a preset timer; After verifying the synchronization message, the process also includes: If the synchronization message verification fails, the synchronization message is discarded, the timer is turned off, and the system waits for the source device to resend the synchronization message. Feeding the confirmation signal back to the source device includes: After detecting that the timer duration equals the preset duration, the confirmation signal is fed back to the source device.
7. A database synchronization device, characterized in that, The device is applied to a source device and includes: The data reading module is used to periodically read the data to be synchronized from the source database and generate a synchronization message corresponding to each row of data to be synchronized. The synchronization message includes the sequence number of the historical synchronization data, the data to be synchronized, and the sequence number of the data to be synchronized. The synchronization message distribution module is used to distribute each synchronization message to the corresponding target device according to the target device identifier corresponding to each row of data to be synchronized, so that each target device can perform data storage operation according to the synchronization message; The signal receiving module is used to update the minimum sequence number corresponding to the synchronized data in the source database after receiving the confirmation signal sent by the target device.
8. A database synchronization device, characterized in that, The device is applied to the target equipment and includes: The synchronization message receiving module is used to verify the synchronization message after receiving it from the source device. The data writing module is used to write the data to be synchronized in the synchronization message into the target database if the synchronization message verification is successful. The signal feedback module is used to update the minimum sequence number corresponding to the synchronized data in the target database, generate an acknowledgment signal based on the updated minimum sequence number, and feed the acknowledgment signal back to the source device.
9. An electronic device, characterized in that, The electronic device includes: At least one processor; and A memory communicatively connected to the at least one processor; wherein, The memory stores a computer program that can be executed by the at least one processor, the computer program being executed by the at least one processor to enable the at least one processor to perform the database synchronization method according to any one of claims 1-3 or 4-6.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer instructions that cause a processor to execute the database synchronization method according to any one of claims 1-3 or 4-6.
Citation Information
Patent Citations
Method and device of synchronizing incremental data in distributed non-relational database
CN107515874A
Data synchronization method, device and system
CN110851526A
Initialization loading method and device for database synchronization, equipment and storage medium
CN112231409A
Data synchronization method and device based on serial number, computer equipment and storage medium
CN115658802A
Incremental data synchronization breakpoint resuming method and system
CN117851508A