Data Synchronization Method and Related Devices

By batch processing and marking the binary log, the problem of circular replication in two-way synchronization of off-site databases is solved, and the effect of data synchronization is significantly improved.

CN115104092BActive Publication Date: 2025-06-17SHENZHEN HEYTAP TECHNOLOGY CO LTD +1
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202080096693.2
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-05-29
Publication Date
2025-06-17
Estimated Expiration
2040-05-29

AI Technical Summary

Technical Problem

When performing bidirectional synchronization between off-site databases, binary logs may experience circular replication, resulting in poor data synchronization.

Method used

By batch processing and marking the binary log, the data generated by the system is identified to avoid cyclic copying. The specific steps include batch processing of the binary log into sublogs, inserting data marks into sublogs, and finally completing data synchronization between databases based on the marks.

Benefits of technology

It effectively avoids the cyclic replication of binary logs in the two databases, and improves the effect and efficiency of data synchronization.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115104092B_ABST
    Figure CN115104092B_ABST
Patent Text Reader

Abstract

A data synchronization method includes: first, batch-processing the first binary log in the first database according to a preset batch rule to obtain N sub-binary logs, where N is a positive integer (201); then, inserting data markers at preset positions in each sub-binary log to obtain a second binary log (202); finally, completing data synchronization between the first database and the second database according to the second binary log (203). It is possible to batch-process and marker-process the binary log, so that when synchronizing data between remote databases, it can be automatically recognized which data is generated by the system, avoiding continuous circular replication of the binary log between the two databases, and greatly improving the data synchronization effect.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of database storage, and in particular to a data synchronization method and related devices. Background Art

[0002] With the progress of society, the amount of data generated every day is increasing. Many application programs need to process massive amounts of data, which poses very high requirements for data storage and reading. As a tool for processing structured data, databases are facing huge challenges. Currently, independent data centers are generally established in different cities. To ensure the consistency of data in databases in various regions, two-way data synchronization is required.

[0003] In the two-way synchronization solution, since data is written into databases in both places, in some cases, if the same piece of data is updated with different values in the two places, it will cause the binary logs to continuously circulate between the databases in the two places, and the data in the two places will also be continuously replicated cyclically, affecting the effect of data synchronization. Summary of the Invention

[0004] Based on the above problems, the present application proposes a data synchronization method and related devices. By batch-processing and marking the binary logs, when data synchronization is performed between remote databases, it can be identified which data is generated by the system, avoiding the continuous cyclic replication of binary logs between the databases in the two places, and greatly improving the effect of data synchronization.

[0005] In a first aspect, an embodiment of the present application provides a data synchronization method, the method including:

[0006] Batch-processing the first binary log in the first database according to a preset batch rule to obtain N sub-binary logs, where N is a positive integer;

[0007] Inserting a data mark at a preset position in each sub-binary log to obtain a second binary log;

[0008] Completing data synchronization between the first database and the second database according to the second binary log.

[0009] In a second aspect, an embodiment of the present application provides a data synchronization device, the device including:

[0010] A batching unit, configured to batch-process the first binary log in the first database according to a preset batch rule to obtain N sub-binary logs, where N is a positive integer;

[0011] A marking unit, configured to insert a data mark at a preset position in each sub-binary log to obtain a second binary log;

[0012] A synchronization unit, configured to complete data synchronization between the first database and the second database according to the second binary log.

[0013] In a third aspect, an embodiment of the present application provides an electronic device, including an application processor, a memory, and one or more programs, where the one or more programs are stored in the memory and are configured to be executed by the application processor, and the programs include instructions for performing the steps in the method according to any one of claims 1 to 7.

[0014] In a fourth aspect, an embodiment of the present application provides a computer storage medium, where the computer storage medium stores a computer program, and the computer program includes program instructions, and when the program instructions are executed by a processor, the processor is caused to execute the method according to any one of the first aspects of the embodiments of the present application.

[0015] In a fifth aspect, an embodiment of the present application provides a computer product, where the computer program product includes a non-transitory computer-readable storage medium storing a computer program, and the computer program is operable to cause a computer to execute some or all of the steps described in any one of the methods in the first aspect of the embodiments of the present application. The computer program product may be a software installation package.

[0016] It can be seen that through the above method, first, the first binary log in the first database is batch-processed according to a preset batch rule to obtain N sub-binary logs, where N is a positive integer; then, data markers are inserted at preset positions in each sub-binary log to obtain a second binary log; finally, data synchronization between the first database and the second database is completed according to the second binary log. Batch processing and marking processing can be performed on the binary log, so that when data synchronization is performed between remote databases, it can be automatically recognized which data is generated by the system, avoiding continuous circular replication of the binary log between the two databases, and greatly improving the data synchronization effect. Description of the Drawings

[0017] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for the description of the embodiments will be briefly introduced below. Obviously, the drawings in the following description are some embodiments of the present invention, and for those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.

[0018] Figure 1 It is a system architecture diagram of a data synchronization method provided by an embodiment of the present application;

[0019] Figure 2 It is a flowchart of a data synchronization method provided by an embodiment of the present application;

[0020] Figure 3 Schematic diagram of an application scenario of a data synchronization method provided by an embodiment of the present application;

[0021] Figure 4A Schematic diagram of a truncated transaction segment provided by an embodiment of the present application;

[0022] Figure 4B Schematic diagram of another truncated transaction segment provided by an embodiment of the present application;

[0023] Figure 4C Schematic diagram of another truncated transaction segment provided by an embodiment of the present application;

[0024] Figure 5 Schematic diagram of the structure of an electronic device provided by an embodiment of the present application;

[0025] Figure 6 Block diagram of the functional units of a data synchronization device provided by an embodiment of the present application;

[0026] Figure 7 Block diagram of the functional units of another data synchronization device provided by an embodiment of the present application. Detailed implementation manners

[0027] In order to enable those skilled in the art to better understand the solutions of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.

[0028] The terms "first", "second", etc. in the specification, claims and drawings of the present application are used to distinguish different objects, rather than to describe a specific order. In addition, the terms "comprising" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally further includes steps or units not listed, or optionally further includes other steps or units inherent to these processes, methods, products or devices.

[0029] References to "embodiments" in this document mean that the specific features, structures, or characteristics described in connection with the embodiments can be included in at least one embodiment of the present application. The phrase appears at various places in the specification and does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment mutually exclusive with other embodiments. Those skilled in the art will explicitly and implicitly understand that the embodiments described herein can be combined with other embodiments.

[0030] For ease of understanding, first, the background technology and related terms involved in the embodiments of the present application are explained. Currently, for off-site database synchronization, independent data centers are generally established in different cities, and the databases in these data centers work simultaneously. Any database will accept the writing of corresponding business data and synchronize and update the data to other databases to achieve two-way data synchronization between off-site multi-active databases. The above-mentioned database can be a relational database management system, such as MySQL, and the SQL statement information for data update is stored in the binary log binlog. The above-mentioned binlog is a binary log that records all changes to the database table structure (such as CREATE, ALTER TABLE...) and table data modification (INSERT, UPDATE, DELETE...). It should be noted that binlog can represent a transaction, and a transaction is a sequence of database operations and is the smallest working unit in the database. A transaction consists of all database operations executed between the start and end of the transaction. How to solve the data loopback problem during two-way synchronization between off-site multi-active databases and ensure the efficiency of two-way synchronization has become the focus of attention in the embodiments of the present application.

[0031] The above explains the relevant background technology. Next, the system architecture of the data synchronization method in the embodiments of the present application is introduced.

[0032] As Figure 1 shown, Figure 1 FIG. 130 is a system architecture diagram of a data synchronization method provided by an embodiment of the present application. The system architecture 100 includes a first database 110, a second database 120, a replication module 130, a first terminal 141, and a second terminal 142. Among them, the first database 110 is connected to the second database 120 through the replication module 130. The first terminal 141 in the location where the first database 110 is located performs data interaction with the first database 110, and the second terminal 142 in the location where the second database 120 is located interacts with the second database 120.

[0033] Among them, the first database 110 and the second database 120 can be MySQL databases, and the data is stored in the first database 110 and the second database 120 in the form of tables.

[0034] Among them, the above replication module 130 can be installed on the server to read data from the first database 110 and synchronize it to the second database 120, and also read data from the second database 120 and synchronize it to the first database 110. The replication module 130 can also batch-process the read data, so that the data synchronization between the first database 110 and the second database 120 is carried out in batches.

[0035] The above user terminal 140 can be installed with various communication client applications, such as database management applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc. The user terminal 140 can be various electronic devices with a display screen, including but not limited to smart phones, tablet computers, portable computers, desktop computers, and so on. No specific limitation is made here.

[0036] It should be noted that the first database 110 and the second database 120 in the above system architecture only represent different databases, and do not mean that the embodiments of the present application can only be applied to two databases. Similarly, there can be one or multiple of the above replication modules 130 and user terminals 140.

[0037] Through the above system architecture, binary logs can be batch-processed and marked, so that when data synchronization is performed between remote databases, it can be automatically recognized which data is generated by the system, avoiding the continuous circular replication of binary logs between the two databases, and greatly improving the data synchronization effect.

[0038] The system architecture of a data synchronization method in the embodiments of the present application is introduced above. Next, in combination with Figure 2 A data synchronization method in the embodiments of the present application will be described in detail. Figure 2 It is a schematic flowchart of a data synchronization method provided by an embodiment of the present application, which specifically includes the following steps:

[0039] Step 201, batch-process the first binary log in the first database according to a preset batching rule to obtain N sub-binary logs.

[0040] Among them, N is a positive integer, and the above first binary log records the database operation sequence in the first database.

[0041] Specifically, the size of the first binary log is the first data volume, and the above-mentioned first data volume can be set according to user requirements. First, read the first binary log of the first data volume from the first database through the replication module in the system architecture. Then, obtain the second data volume corresponding to the second database. Since there is two-way synchronization between the first database and the second database, the second data volume can be used as a data reference for subsequent batch processing of the first binary log. Finally, batch process the first binary log according to the first data volume and the second data volume to obtain N sub-binary logs.

[0042] Further, in combination with Figure 3 A detailed description is given on how to batch process the first binary log according to the first data volume and the second data volume to obtain N sub-binary logs. Figure 3 The figure is an application scenario diagram of a data synchronization method provided by an embodiment of the present application, including a first database, a second database, a replication module. a_select_size represents the first data volume, b_select_size represents the second data volume, and a_split_size represents the batch processing data volume. The size of a_split_size can be determined through the following pseudocode:

[0043] If(a_select_size>b_select_size){

[0044] a_split_size = b_select_size - 2; / / 2 represents a header flag and a tail flag

[0045] }Else{

[0046] a_split_size = b_select_size;

[0047] }

[0048] It can be seen that the replication module reads the first binary log of the first data volume from the first database, batch processes the first binary log and synchronizes it to the second database, and at the same time reads the binary log of the second data volume from the second database and synchronizes it to the first database. It should be noted that Figure 3 only shows the specific batch processing steps for the first database to synchronize data to the second database. The same processing steps are used for the second database to synchronize data to the first database, which will not be elaborated here.

[0049] When the above first data volume is greater than the above second data volume, since the number of data markers per batch is 2, that is, one head marker and one tail marker, the batched data volume can be determined to be the above second data volume minus 2 at this time. That is, the size of each sub-binary log is the above second data volume minus 2. For ease of distinction, the batched data volume when the first data volume is greater than the second data volume is named the first batched data volume; when the above first data volume is less than or equal to the above second data volume, the batched data volume can be determined to be the above second data volume, that is, the size of each sub-binary log is the above second data volume. For ease of distinction, the batched data volume when the above first data volume is less than or equal to the above second data volume is named the second batched data volume.

[0050] By batch-processing the first binary log in the first database according to a preset batching rule to obtain N sub-binary logs, the size of the data synchronized at one time can be reduced, the data volume pressure during synchronization is reduced, and the occurrence of deadlocks is reduced.

[0051] Step 202, insert data markers at preset positions in each sub-binary log to obtain a second binary log.

[0052] Among them, the above data markers include a head marker and a tail marker. Inserting data markers at preset positions means inserting the above head marker at the head of each sub-binary log and inserting the above tail marker at the tail of each sub-binary log. The size of each sub-binary log with data markers inserted is equal to the above second data volume. In this way, when the second database synchronizes data to the above first database, at least one head marker or tail marker can be read.

[0053] Specifically, there is a specified table in each of the above first database and the above second database. This specified table stores the binary log of the operation of generating data markers. By operating this specified table, a head marker can be inserted after each transaction head, and a tail marker can be inserted before each transaction tail.

[0054] By inserting data markers at preset positions in each sub-binary log to obtain a second binary log, the visibility of the data markers can be ensured.

[0055] Step 203, complete data synchronization between the first database and the second database according to the second binary log.

[0056] Among them, the system input segment and the service input segment of the second binary log can be determined according to the head marker and the tail marker, that is, the segment between the head marker and the tail marker is determined as the system input segment, and the segment outside the system input segment is determined as the service input segment. The above system input segment represents the data generated by the system. Identifying the system input segment during synchronization can avoid data loopback. The above service input segment represents the data input into the database by external terminals. Finally, the data synchronization between the first database and the second database is completed according to the system input segment and the service input segment.

[0057] Specifically, due to batch processing, when writing the batched data into the second database, the data may be truncated. Taking Figure 4A 、 Figure 4B and Figure 4C as examples, Figure 4A is a schematic diagram of a truncated transaction segment. DML represents the operation sequence command for operating the database. Transaction_begin represents the transaction head, transaction_end represents the transaction tail, flag_begin represents the head marker, and flag_end represents the tail marker. Figure 4A Only one head marker is read, so the DML sequence after the head marker belongs to the system input segment, and the DML sequence before the head marker belongs to the service input segment; Figure 4B Only one tail marker is read, so the DML sequence before the tail marker belongs to the system input segment, and the DML sequence after the tail marker belongs to the service input segment; Figure 4C Both the complete head marker and tail marker are read, so the DML sequence between the head marker and the tail marker belongs to the system input segment. It should be noted that the above only exemplarily illustrates the possible truncation situations and does not represent a limitation on the embodiments of the present application.

[0058] By completing the data synchronization between the first database and the second database according to the second binary log, batch processing and marker processing can be performed on the binary log, reducing the data volume pressure of data synchronization. When data synchronization is performed between remote databases, it can automatically identify which data is generated by the system, avoiding the continuous circular replication of binary logs between the two databases, and greatly improving the data synchronization effect.

[0059] The above mainly introduces the solution of the embodiment of the present application from the perspective of the execution process on the method side. It can be understood that the above methods can be implemented independently or in combination. In order for an electronic device to implement the above functions, it includes the corresponding hardware structures and / or software modules for executing each function. Those skilled in the art should easily realize that, combining the units and algorithm steps of each example described in the embodiments provided in this article, the present application can be implemented in the form of hardware or a combination of hardware and computer software. Whether a certain function is executed in the way of hardware or computer software driving hardware depends on the specific application and design constraints of the technical solution. Professional technicians can use different methods to implement the described functions for each specific application, but such implementation should not be considered to exceed the scope of the present application.

[0060] Next, the hardware device applying the data synchronization method in the embodiment of the present application will be described.

[0061] Figure 5 FIG. is a schematic structural diagram of an electronic device provided for an embodiment of the present application. The electronic device 500 may be an electronic device with communication capabilities. The electronic device may include various handheld devices, vehicle-mounted devices, wearable devices, computing devices, or other processing devices connected to a wireless modem with wireless communication functions, as well as various forms of user equipment (User Equipment, UE), mobile station (Mobile Station, MS), terminal device, and so on. The electronic device 500 in the present application may include one or more of the following components: a processor 510, a memory 520, and an input / output device 530.

[0062] The processor 510 may include one or more processing cores. The processor 510 uses a communication interface to connect various parts within the entire electronic device 500. By running or executing instructions, programs, code sets, or instruction sets stored in the memory 520, and by calling data stored in the memory 520, it performs various functions of the electronic device 500 and processes data. The processor 510 may include one or more processing units. For example, the processor 510 may include a Central Processing Unit (CPU), an application processor (AP), a modem processor, a graphics processing unit (GPU), an image signal processor (ISP), a controller, a video codec, a digital signal processor (DSP), a baseband processor, and / or a neural-network processing unit (NPU), etc. The CPU is mainly used to process the operating system, user interface, and application programs, etc.; the GPU is responsible for rendering and drawing the display content; the modem is used to process wireless communication. The digital signal processor is used to process digital signals. In addition to processing digital image signals, it can also process other digital signals. In the embodiments of this application, the central processor CPU is taken as an example for illustration. For example, when the electronic device 500 is running an application program, the CPU can obtain the drawing data of the UI thread and other threads for this application program, and based on this drawing data, determine whether the currently running application program has frame drops or freezes, etc. Then, based on the performance usage of the CPU itself, the frequency of the CPU can be dynamically controlled.

[0063] A memory 520 may be provided in the processor 510 for storing instructions and data. In some embodiments, the memory 520 in the processor 510 is a cache memory. This memory 520 can save the instructions or data that the processor 510 has just used or recycled. If the processor 510 needs to use this instruction or data again, it can directly call it from the memory 520. This avoids repeated access, reduces the waiting time of the processor 510, and improves system efficiency.

[0064] It can be understood that the above-mentioned processor 510 may be mapped to a System on a Chip (SOC) in an actual product. The above-mentioned processing units and / or interfaces may not be integrated into the processor 510, and the corresponding functions may be implemented separately through a communication chip or electronic component. The interface connection relationships between the above-mentioned various modules are only illustrative and do not constitute the only limitation on the structure of the electronic device 500.

[0065] The memory 520 may include a Random Access Memory (RAM), or may include a Read-Only Memory. Optionally, the memory 520 includes a non-transitory computer-readable storage medium. The memory 520 can be used to store instructions, programs, codes, code sets or instruction sets. The memory 520 may include a program storage area and a data storage area. Among them, the program storage area may store instructions for implementing an operating system, instructions for implementing at least one function (such as a touch function, a sound playback function, an image playback function, etc.), instructions for implementing the following various method embodiments, etc. The operating system may be an Android system (including a system developed based on the Android system in depth), an IOS system developed by Apple Inc. (including a system developed based on the IOS system in depth), or other systems. The data storage area may also store data created during the use of the electronic device 500.

[0066] The input / output device 530 may include a touch display screen, which is used to receive touch operations of a user using any suitable object such as a finger or a stylus on or near it, and to display the user interfaces of various application programs. The touch display screen is usually arranged on the front panel of the electronic device 500. The touch display screen can be designed as a full-screen, a curved screen or a special-shaped screen. The touch display screen can also be designed as a combination of a full-screen and a curved screen, or a combination of a special-shaped screen and a curved screen. The embodiments of the present application do not limit this.

[0067] The embodiments of the present application can divide the functional units of the electronic device according to the above method examples. For example, each functional unit can be divided corresponding to each function, or two or more functions can be integrated into one processing unit. The above integrated unit can be implemented in the form of hardware or in the form of a software functional unit. It should be noted that the division of units in the embodiments of the present application is illustrative, only a logical function division, and there may be other division methods in actual implementation.

[0068] In the case of dividing each functional module corresponding to each function, Figure 6 is a block diagram of the functional unit composition of a data synchronization device provided by an embodiment of the present application. As Figure 6 shown, the data synchronization device 600 includes:

[0069] A batching unit 610, configured to batch process the first binary log in the first database according to a preset batching rule to obtain N sub-binary logs, where N is a positive integer;

[0070] A marking unit 620, configured to insert a data mark at a preset position of each sub-binary log to obtain a second binary log;

[0071] A synchronization unit 630, configured to complete data synchronization between the first database and the second database according to the second binary log.

[0072] Wherein, all relevant contents of each step involved in the above method embodiments can be cited to the function descriptions of the corresponding functional modules, and will not be elaborated herein.

[0073] In the case of adopting an integrated unit, Figure 7 is a block diagram of the functional units of another central processing unit frequency control device 700 involved in the embodiments of the present application. The central processing unit frequency control device 700 is applied to an electronic device supporting a display function. The electronic device includes a processor, a display module, etc. The central processing unit frequency control device 700 includes a processing unit 701 and a communication unit 702. Among them, the processing unit 701 is configured to execute any step in the above method embodiments, and when performing data transmission such as sending, the communication unit 702 can be selectively called to complete the corresponding operation.

[0074] Wherein, the central processing unit frequency control device 700 may further include a storage unit 703, configured to store program codes and data of the electronic device. The processing unit 701 may be a central processing unit, the communication unit 702 may be a touch display screen or a transceiver, and the storage unit 703 may be a memory.

[0075] It can be understood that since the method embodiments and the device embodiments are different presentation forms of the same technical concept, therefore, the content in the method embodiment part of the present application should be synchronously adapted to the device embodiment part, and will not be elaborated herein. The above data synchronization device 600 and data control device 700 can both execute all the data synchronization methods included in the above embodiments.

[0076] The embodiments of the present application further provide a computer storage medium. Among them, the computer storage medium stores a computer program for electronic data exchange, and the computer program enables a computer to execute part or all of the steps of any method recorded in the above method embodiments. The above computer includes an electronic device.

[0077] The embodiments of the present application also provide a computer program product. The computer program product includes a non-transitory computer-readable storage medium storing a computer program. The computer program is operable to cause a computer to execute some or all of the steps of any of the methods described in the foregoing method embodiments. The computer program product may be a software installation package, and the computer includes an electronic device.

[0078] It should be noted that, for the foregoing method embodiments, for the sake of simple description, they are all expressed as a series of action combinations. However, those skilled in the art should know that the present application is not limited by the described action sequence, because according to the present application, certain steps may be performed in other sequences or simultaneously. Secondly, those skilled in the art should also know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to the present application.

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

[0080] In several embodiments provided by the present application, it should be understood that the disclosed device can be implemented in other ways. For example, the device embodiments described above are only illustrative. For example, the above division of units is only a logical function division. In actual implementation, there may be other division methods. For example, multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the displayed or discussed mutual coupling or direct coupling or communication connection may be through some interfaces. The indirect coupling or communication connection of the device or unit may be in an electrical or other form.

[0081] The units described as separate components may or may not be physically separated. The components displayed as units may or may not be physical units, that is, they may be located in one place, or may be distributed to multiple network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0082] In addition, the functional units in the various embodiments of the present application may be integrated into one processing unit, or each unit may exist physically alone, or two or more units may be integrated into one unit. The above integrated unit can be implemented in the form of hardware or in the form of a software functional unit.

[0083] If the above integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable memory. Based on such an understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of this technical solution, can be embodied in the form of a software product. This computer software product is stored in a memory and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the above methods in various embodiments of this application. The aforementioned memory includes: various media such as USB flash drives, read-only memories (ROM, Read-Only Memory), random access memories (RAM, Random Access Memory), mobile hard disks, magnetic disks, or optical discs that can store program codes.

[0084] Those of ordinary skill in the art can understand that all or part of the steps in the various methods of the above embodiments can be completed by instructing relevant hardware through a program. This program can be stored in a computer-readable memory. The memory can include: flash drives, read-only memories (English: Read-Only Memory, abbreviated as: ROM), random access memories (English: Random Access Memory, abbreviated as: RAM), magnetic disks, or optical discs, etc.

[0085] The above has introduced the embodiments of this application in detail. Specific examples are used in this article to elaborate on the principle and implementation manner of this application. The description of the above embodiments is only used to help understand the method and its core idea of this application; at the same time, for those of ordinary skill in the art, according to the idea of this application, there will be changes in the specific implementation manner and application scope. In summary, the content of this specification should not be construed as a limitation to this application.

Claims

1. A data synchronization method, characterized in that, The method includes: Batch-processing the first binary log in the first database according to a preset batch rule to obtain N sub-binary logs, where N is a positive integer. Specifically, read the first binary log of the first data volume from the first database; obtain the second data volume corresponding to the second database, where the second data volume represents the capacity of data synchronized from the second database to the first database; batch-process the first binary log according to the first data volume and the second data volume to obtain N sub-binary logs. When the first data volume is greater than the second data volume, determine the first batch data volume according to the second data volume and the data marker, where the first batch data volume represents the size of each sub-binary log; batch-process the first binary log according to the first batch data volume to obtain the N sub-binary logs. Insert a data marker at a preset position in each sub-binary log to obtain a second binary log. Complete data synchronization between the first database and the second database according to the second binary log.

2. The method according to claim 1, characterized in that, The batch-processing the first binary log according to the first data volume and the second data volume to obtain N sub-binary logs includes: When the first data volume is less than or equal to the second data volume, determine the second data volume as the second batch data volume. Batch-process the first binary log according to the second batch data volume to obtain the N sub-binary logs.

3. The method according to claim 1, characterized in that, The inserting a data marker at a preset position in each sub-binary log to obtain a second binary log includes: Insert a header marker at the head of each sub-binary log, and insert a tail marker at the tail of each sub-binary log to obtain the second binary log.

4. The method according to claim 3, characterized in that, The completing data synchronization between the first database and the second database according to the second binary log includes: Determine the system input segment and the service input segment of the second binary log according to the header marker and the tail marker. Complete data synchronization between the first database and the second database according to the system input segment and the service input segment.

5. The method according to claim 4, characterized in that, The determining the system input segment and the service input segment of the second binary log according to the header marker and the tail marker includes: Determine the segment between the header marker and the tail marker as the system input segment. Determine the segment other than the system input segment as the service input segment.

6. A data synchronization device, characterized in that, The device includes: A batching unit, configured to batch the first binary log in the first database according to a preset batching rule to obtain N sub-binary logs, where N is a positive integer. Specifically, read the first binary log of a first data volume from the first database; obtain a second data volume corresponding to the second database, where the second data volume represents the capacity of data synchronized from the second database to the first database; batch the first binary log according to the first data volume and the second data volume to obtain N sub-binary logs. When the first data volume is greater than the second data volume, determine a first batching data volume according to the second data volume and a data marker, where the first batching data volume represents the size of each sub-binary log; batch the first binary log according to the first batching data volume to obtain the N sub-binary logs. A marking unit, configured to insert a data marker at a preset position of each sub-binary log to obtain a second binary log. A synchronization unit, configured to complete data synchronization between the first database and the second database according to the second binary log.

7. An electronic device, characterized in that, It includes an application processor, a memory, and one or more programs. The one or more programs are stored in the memory and are configured to be executed by the application processor. The programs include instructions for performing the steps in the method according to any one of claims 1 to 5.

8. A computer storage medium, characterized in that, The computer storage medium stores a computer program, and the computer program includes program instructions. When the program instructions are executed by a processor, the processor is caused to execute the method according to any one of claims 1 to 5.

Citation Information

Patent Citations

  • Universal multi-source heterogeneous large-scale data synchronizing system

    CN107729366A