EP-4738142-A1 - DATA SYNCHRONIZATION METHOD AND APPARATUS BASED ON DATABASE, MEDIUM, AND DEVICE
Abstract
The present disclosure relates to a data synchronization method and apparatus based on a database, a medium, a device and a product. The method includes: executing, in the database, a target statement carrying a current data synchronization position, to write the current data synchronization position into a log file of the database through the target statement, the target statement is a statement of a data definition language type (110); searching in the log file of the database to obtain a target data synchronization position in response to data breakpoint resumption being performed, the target data synchronization position is the current data synchronization position recorded when data synchronization is interrupted last time (120); and performing data synchronization based on the target data. synchronization position (130).
Inventors
- DENG, Yun
Assignees
- Beijing Volcano Engine Technology Co., Ltd.
Dates
- Publication Date
- 20260506
- Application Date
- 20250604
Claims (9)
- A data synchronization method based on a database, comprising: executing, in the database, a target statement carrying a current data synchronization position, to write the current data synchronization position into a log file of the database through the target statement, wherein the target statement is a statement of a data definition language type (110); searching in the log file of the database to obtain a target data synchronization position in response to data breakpoint resumption being performed, wherein the target data synchronization position is the current data synchronization position recorded when data synchronization is interrupted last time (120); and performing data synchronization based on the target data synchronization position (130).
- The method according to claim 1, wherein the target statement comprises the current data synchronization position and a target table name, a table corresponding to the target table name does not belong to the database, and the target statement is used to instruct to delete a corresponding table based on the target table name; and the executing, in the database, a target statement carrying a current data synchronization position comprises: executing the target statement in the database to delete the table corresponding to the target table name.
- The method according to claim 1, wherein the target statement comprises the current data synchronization position and a specified table name, the target statement is used to instruct to create a corresponding table based on the specified table name; and the executing, in the database, a target statement carrying a current data synchronization position comprises: executing the target statement in the database to create a table corresponding to the specified table name in the database.
- The method according to claim 1, wherein the executing, in the database, a target statement carrying a current data synchronization position comprises: periodically acquiring the current data synchronization position in a data synchronization process; constructing the target statement based on a preset table name and the current data synchronization position; and executing the target statement in the database to write the target statement into the log file of the database.
- The method according to any one of claims 1 to 4, wherein the searching the log file of the database to obtain a target data synchronization position comprises: scanning respective log files of the database to obtain first data synchronization positions recorded in the respective log files; determining a target log file from the respective log files according to an order corresponding to the first data synchronization positions; and determining the target data synchronization position from respective data synchronization positions according to an order of the respective data synchronization positions recorded in the target log file.
- The method according to any one of claims 1 to 4, wherein the target statement comprises a preset table name; and the searching in the log file of the database to obtain a target data synchronization position comprises: searching in each log file of the database to obtain a first target statement recorded in each log file based on the preset table name; and determining the target data synchronization position based on a data synchronization position carried in the target statement searched.
- A data synchronization apparatus (300) based on a database, comprising: an execution module (301), configured to execute, in the database, a target statement carrying a current data synchronization position, to write the current data synchronization position into a log file of the database through the target statement, wherein the target statement is a statement of a data definition language type; a search module (302), configured to search in the log file of the database to obtain a target data synchronization position in response to data breakpoint resumption being performed, wherein the target data synchronization position is the current data synchronization position recorded when data synchronization is interrupted last time; and a synchronization module (303), configured to perform data synchronization based on the target data synchronization position.
- A computer-readable medium, storing a computer program thereon, wherein the computer program, when executed by a processing apparatus, implements the steps of the method according to any one of claims 1 to 6.
- An electronic device, comprising: a storage apparatus, storing a computer program thereon; and a processing apparatus, configured to execute the computer program in the storage apparatus, to implement the steps of the method according to any one of claims 1 to 6.
Description
CROSS-REFERENCE TO RELATED APPLICATION This application claims the priority to and benefits of the Chinese Patent Application, No. 202411535621.X, which was filed on October 30, 2024. The aforementioned patent application is hereby incorporated by reference in its entirety. TECHNICAL FIELD The present disclosure relates to a data synchronization method and apparatus based on a database, a medium, a device and a product. BACKGROUND In a data synchronization process, current synchronized position information needs to be continuously recorded. When the data synchronization is interrupted due to a network problem, a system failure or other reasons, a system needs to be able to detect this situation and save current position information. After a problem causing the interruption is solved, the system can use the previously saved position information to resume the data synchronization. Therefore, recording of the position information is very important for breakpoint resumption. In the related art, positions used in MySQL (a relational database management system) include a physical position based on a binary file name and an offset, and a logical position based on a GTID/GTIDSet. However, in a scenario of master-slave switch, physical locations of a master database and a slave database are different, and thus the physical position based on the binary file name and the offset becomes invalid when the master-slave switch is performed. Although the logical position based on the GTID/GTIDSet can solve a problem of position invalidation caused by the master-slave switch, a low version of MySQL does not support the logical position based on the GTID/GTIDSet. Therefore, it is urgently needed to provide a new data synchronization method that can adapt to various versions of MySQL and solve the problem of position invalidation caused by the master-slave switch. SUMMARY The Summary is provided to introduce concepts in a brief form, and these concepts will be described in detail in the Detailed Description section below. The Summary is not intended to identify key features or essential features of the claimed technical solution, nor is it intended to be used to limit the scope of the claimed technical solution. In a first aspect, the present disclosure provides a data synchronization method based on a database, including: executing, in the database, a target statement carrying a current data synchronization position, to write the current data synchronization position into a log file of the database through the target statement, where the target statement is a statement of a data definition language type;searching the log file of the database to obtain a target data synchronization position in response to data breakpoint resumption being performed, where the target data synchronization position is the current data synchronization position recorded when data synchronization is interrupted last time; andperforming data synchronization based on the target data synchronization position. In a second aspect, the present disclosure provides a data synchronization apparatus based on a database, including: an execution module, configured to execute, in the database, a target statement carrying a current data synchronization position, to write the current data synchronization position into a log file of the database through the target statement, where the target statement is a statement of a data definition language type;a search module, configured to search the log file of the database to obtain a target data synchronization position in response to data breakpoint resumption being performed, where the target data synchronization position is the current data synchronization position recorded when data synchronization is interrupted last time; anda synchronization module, configured to perform data synchronization based on the target data synchronization position. In a third aspect, the present disclosure provides a computer-readable medium, storing a computer program thereon, the computer program, when executed by a processing apparatus, implements the steps of the method according to the first aspect. In a fourth aspect, the present disclosure provides an electronic device, including: a storage apparatus, storing a computer program thereon; anda processing apparatus, configured to execute the computer program in the storage apparatus, to implement the steps of the method according to the first aspect. In a fifth aspect, the present disclosure provides a computer program product, including a computer program which, when executed by a processor, implements the steps of the method according to the first aspect. Other features and advantages of the present disclosure will be described in detail in the Detailed Description section below. BRIEF DESCRIPTION OF DRAWINGS The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent when taken in conjunction with the drawings and with