A database log synchronization method, device, equipment and medium

By obtaining and comparing the serial number of the database log, determining the target log sequence number, and storing the log when receiving the log synchronization request, the problem of not storing the logs between databases after copying is solved, and the strong consistency of data between databases is achieved.

CN114077593BActive Publication Date: 2025-04-25BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

When synchronizing logs between databases, there may be no storage after log replication, resulting in inconsistent data.

Method used

By obtaining the first type of log sequence number that was successfully copied between database instances and the second type of log sequence number stored in the database corresponding to the consistency component, the target log sequence number is determined, and upon receiving a log synchronization request, the database log that was successfully copied between database instances is stored in the database.

Benefits of technology

It solves the problem that log replication is not stored after database replication due to database downtime, ensuring strong consistency of data between master and slave databases.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114077593B_ABST
    Figure CN114077593B_ABST
Patent Text Reader

Abstract

The disclosed embodiments relate to a method, device, equipment and medium for database log synchronization, wherein the method is applied to a consistency component in a master database instance or a slave database instance, including: obtaining a first-class log sequence number of a database log that is successfully replicated between database instances, and a second-class log sequence number stored in a database corresponding to the consistency component; determining a target log sequence number based on the first-class log sequence number and the second-class log sequence number; if a log synchronization request is received, storing the database log that is successfully replicated between database instances in the database based on the target log sequence number. The above technical solution solves the problem of no storage after log replication that may be caused by database downtime, thereby ensuring strong consistency of data between master and slave databases.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of database technology, and in particular to a database log synchronization method, device, equipment and medium. Background Art

[0002] To ensure data security, you can create multiple databases. The data in each database is exactly the same. When one database becomes unavailable due to a failure, other databases can continue to provide services.

[0003] In order to ensure data consistency between databases, log synchronization is required between databases. However, since the replication and storage of logs between databases are not atomic operations, log loss may occur, that is, logs may not be stored after replication. Summary of the invention

[0004] In order to solve the above technical problem or at least partially solve the above technical problem, the present disclosure provides a database log synchronization method, device, equipment and medium.

[0005] The present disclosure provides a method for synchronizing a database log, which is applied to a consistency component in a master database instance or a slave database instance, and includes:

[0006] Obtaining a first-class log sequence number of a database log that is successfully replicated between database instances, and a second-class log sequence number stored in a database corresponding to the consistency component;

[0007] Determine a target log sequence number based on the first type of log sequence number and the second type of log sequence number;

[0008] If a log synchronization request is received, the database logs that are successfully replicated between database instances are stored in the database based on the target log sequence number.

[0009] The embodiment of the present disclosure further provides a log synchronization device for a database, wherein the device is configured in a consistency component in a master database instance or a slave database instance, and includes:

[0010] A log sequence number acquisition module, used to obtain a first type of log sequence number of a database log that is successfully replicated between database instances, and a second type of log sequence number stored in a database corresponding to the consistency component;

[0011] A target log sequence number module, used to determine a target log sequence number based on the first type of log sequence number and the second type of log sequence number;

[0012] The log synchronization module is used for storing the database logs successfully copied between database instances in the database based on the target log sequence number if a log synchronization request is received.

[0013] An embodiment of the present disclosure also provides an electronic device, which includes: a processor; a memory for storing executable instructions of the processor; the processor is used to read the executable instructions from the memory and execute the instructions to implement the database log synchronization method provided by the embodiment of the present disclosure.

[0014] The embodiment of the present disclosure further provides a computer-readable storage medium, wherein the storage medium stores a computer program, and the computer program is used to execute the database log synchronization method provided by the embodiment of the present disclosure.

[0015] The technical solution provided by the embodiments of the present disclosure has the following advantages over the prior art: the database log synchronization solution provided by the embodiments of the present disclosure, the consistency component in the master database instance or the slave database instance can obtain the first type of log sequence number of the database log that is successfully copied between database instances, and the second type of log sequence number stored in the database corresponding to the consistency component; determine the target log sequence number based on the first type of log sequence number and the second type of log sequence number; if a log synchronization request is received, the database log that is successfully copied between database instances is stored in the database based on the target log sequence number. Using the above technical solution, the consistency component in the master database instance or the slave database instance can determine the target log sequence number, and when the log that is successfully copied between database instances is inconsistent with the log stored in the database, the most recently successfully copied database log can be stored in the database based on the target log sequence number, which solves the problem that the log is not stored after copying due to database crash, thereby ensuring the strong consistency of data between the master and slave databases. BRIEF DESCRIPTION OF THE DRAWINGS

[0016] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present disclosure and, together with the description, serve to explain the principles of the present disclosure.

[0017] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0018] Figure 1 A schematic diagram of log synchronization of a database provided by an embodiment of the present disclosure;

[0019] Figure 2 A flowchart of a database log synchronization method provided by an embodiment of the present disclosure;

[0020] Figure 3 A flowchart of another database log synchronization method provided by an embodiment of the present disclosure;

[0021] Figure 4 A schematic diagram of a log sequence number provided in an embodiment of the present disclosure;

[0022] Figure 5 A schematic diagram of the structure of a database log synchronization device provided by an embodiment of the present disclosure;

[0023] Figure 6 A schematic diagram of the structure of an electronic device provided in an embodiment of the present disclosure. DETAILED DESCRIPTION

[0024] In order to more clearly understand the above-mentioned objectives, features and advantages of the present disclosure, the scheme of the present disclosure will be further described below. It should be noted that the embodiments of the present disclosure and the features in the embodiments can be combined with each other without conflict.

[0025] In the following description, many specific details are set forth to facilitate a full understanding of the present disclosure, but the present disclosure may also be implemented in other ways different from those described herein; it is obvious that the embodiments in the specification are only part of the embodiments of the present disclosure, rather than all of the embodiments.

[0026] In order to ensure the consistency of data between databases, log synchronization is required between databases. In the embodiments of the present disclosure, log synchronization can be achieved through a common consistency component, thereby achieving strong consistency of data.

[0027] Figure 1 A schematic diagram of log synchronization of a database provided in an embodiment of the present disclosure is shown in FIG. Figure 1, two slave database instances, slave database instance 1 and slave database instance 2, are shown, and the arrows represent the specific process of log synchronization, which may include: the database in the master database instance generates a database log in the log memory and passes the database log to the consistency component; the consistency component sends the database log to the first data replication module; the first data replication module writes the database log to the local disk based on the consistency protocol, such as the log file in the figure, and transmits the database log to the second data replication module of the slave database instance 1 and the slave database instance 2; after the slave database instance 1 and the second data replication module of the slave database instance 1 receive the database log, the database log can be stored in the corresponding database, such as the database log file in the slave database instance 1 and the slave database instance 2 in the figure, and a log replication success message is replied to the first data replication module; the first data replication module sends the received log replication success message to the consistency component of the master database instance, and after the consistency component receives the log replication success information of all the slave database instances (i.e., the slave database instance 1 and the slave database instance 2 in the figure), it determines that the log replication is successful and sends information to the database so that the database writes the database log to the disk.

[0028] However, in the process of implementing the database log transmission from the master database instance to the slave database instance through the consistency component, a problem may arise. Between the time when the consistency component receives the successful log replication information of all slave database instances and notifies the database and the database writes the database log to the disk, if an abnormality occurs in the database, such as a crash or failure, the database log exists in the data replication module and has been successfully replicated, but the database does not store the database log and does not exist, resulting in inconsistency between the logs in the data replication module and the database. In addition, since the database log has been successfully replicated, the data replication module will not send the log to the database again, resulting in inconsistency between the database log in the data replication module and the database. In order to solve the above problem, the embodiments of the present disclosure provide a database log synchronization method.

[0029] Figure 2 The present invention provides a flow chart of a method for synchronizing a database log according to an embodiment of the present invention. The method can be executed by a database log synchronization device, wherein the device can be implemented by software and / or hardware and can generally be integrated in an electronic device. Figure 2 As shown, the method is applied to a consistency component in a master database instance or a slave database instance, including:

[0030] Step 101: Obtain the first type of log sequence number of the database log successfully replicated between database instances, and the second type of log sequence number stored in the database corresponding to the consistency component.

[0031] The database log may be a log that records all transactions in the database and the modifications made to the database by each transaction. Data replication may be achieved by redoing the database log. A database instance is a memory structure used to manage database files. The disclosed embodiment may adopt multiple databases of a master-slave architecture, and each database corresponds to a database instance for illustration. Specifically, it may include a master database instance and at least one slave database instance. The master database instance may be responsible for providing normal database access functions, and may synchronize data to the slave database instance through a data replication protocol to ensure strong data consistency.

[0032] The log sequence number is an identifier used to distinguish database logs. Each database log can correspond to a log sequence number, and the log sequence number is unique. The number of database logs successfully copied between database instances is at least one, the number of database logs stored in the database corresponding to the consistency component is at least one, and each database log corresponds to a unique log sequence number. The first type of log sequence number refers to the log sequence number corresponding to the database log successfully copied between database instances stored in the data replication module. The number of log sequence numbers included in the first type of log sequence number is at least one, and the second type of log sequence number represents the log sequence number corresponding to the latest stored database log in the database corresponding to the consistency component. The second type of log sequence number is continuously updated as the database log in the database is updated.

[0033] In the disclosed embodiment, obtaining the first type of log sequence number of the database log that is successfully replicated between database instances, and the second type of log sequence number stored in the database corresponding to the consistency component, may include: obtaining the first type of log sequence number of the database log that is successfully replicated between database instances at a first time interval, and obtaining the second type of log sequence number of the database log that is stored in the database corresponding to the consistency component at a second time interval, wherein the first time interval and the second time interval are different. The consistency component in the master database instance or the slave database instance can periodically obtain the first type of log sequence number of the database log that is successfully replicated between database instances and the second type of log sequence number of the database log that is stored in the database corresponding to the consistency component. The first type of log sequence number can be stored in a memory queue and arranged in order from small to large, and the first time interval and the second time interval can be set according to actual conditions, and can be the same or different.

[0034] Step 102: Determine a target log sequence number based on the first type log sequence number and the second type log sequence number.

[0035] The target log sequence number may be a log sequence number stored in a checkpoint file set in the consistency component, which is used to implement data consistency between the data replication module and the database. In the disclosed embodiment, a new Checkpoint function may be added to the consistency component. Checkpoint is an internal event of the database. After the event is activated, it triggers the database to write the data in the data cache into the data file.

[0036] In the disclosed embodiment, the number of log sequence numbers included in the first type of log sequence number is at least one, and the second type of log sequence number only stores the latest value and is updated regularly. Determining the target log sequence number based on the first type of log sequence number and the second type of log sequence number includes: comparing the second type of log sequence number with each log sequence number in the first type of log sequence number in turn, and determining the first type of log sequence number that is smaller than the second type of log sequence number and has the smallest difference with the second type of log sequence number as the target log sequence number. After the consistency component obtains the second type of log sequence number, it can compare the second type of log sequence number with each log sequence number in the first type of log sequence number in turn, and determine that the first type of log sequence number that is smaller than the largest one in the second type of log sequence number is the target log sequence number, that is, the target log sequence number is smaller than the second type of log sequence number but has the smallest difference with the second type of log sequence number. Afterwards, the consistency component can write the target log sequence number into the Checkpoint file for later use.

[0037] Step 103: If a log synchronization request is received, the database logs that are successfully copied between database instances are stored in the database based on the target log sequence number.

[0038] The log synchronization request is used to start storing database logs in the database. In the disclosed embodiment, receiving the log synchronization request may include: if a restart operation occurs after monitoring a database crash, determining that the log synchronization request is received. When the database crashes or fails, monitoring a database restart operation can be regarded as receiving a log synchronization request, triggering log re-storage.

[0039] Based on the target log sequence number, the database logs that are successfully copied between database instances are stored in the database, which may include: determining the target database log corresponding to the log sequence number that is located after the target log sequence number in the first type of log sequence number among the database logs that are successfully copied between database instances; and storing the target database log in the database. Since the target log sequence number is the log sequence number that is closest to the current moment in the first type of log sequence number, the consistency component can send the database log corresponding to the log sequence number that is located after the target log sequence number in the database logs that are successfully copied between database instances in the data replication module to the database, so that the database is stored on the disk, solving the problem of log inconsistency.

[0040] The log synchronization scheme for a database provided by the embodiment of the present disclosure is that the consistency component in the master database instance or the slave database instance can obtain the first type of log sequence number of the database log that is successfully copied between database instances, and the second type of log sequence number stored in the database corresponding to the consistency component; determine the target log sequence number based on the first type of log sequence number and the second type of log sequence number; if a log synchronization request is received, the database log that is successfully copied between database instances is stored in the database based on the target log sequence number. Using the above technical scheme, the consistency component in the master database instance or the slave database instance can determine the target log sequence number, and when the log that is successfully copied between database instances is inconsistent with the log stored in the database, the most recently successfully copied database log can be stored in the database based on the target log sequence number, which solves the problem that the log is not stored after copying due to database crash, thereby ensuring the strong consistency of data between the master and slave database instances.

[0041] Figure 3 This is a flow chart of another database log synchronization method provided by an embodiment of the present disclosure. Based on the above embodiment, this embodiment specifically describes the above database log synchronization method. Figure 3 As shown, the method includes:

[0042] Step 201: Obtain the first type of log sequence number of the database log successfully replicated between database instances, and the second type of log sequence number stored in the database corresponding to the consistency component.

[0043] Obtaining the first type of log sequence number of a database log that is successfully replicated between database instances, and the second type of log sequence number stored in the database corresponding to the consistency component, may include: obtaining the first type of log sequence number of a database log that is successfully replicated between database instances at a first time interval, and obtaining the second type of log sequence number of a database log that is stored in the database corresponding to the consistency component at a second time interval, wherein the first time interval and the second time interval are different.

[0044] For example, Figure 4 A schematic diagram of a log sequence number provided in an embodiment of the present disclosure, see Figure 4 In the figure, triangles are used to represent the first type of log sequence numbers of database logs that are successfully replicated between database instances, and pentagons are used to represent the second type of log sequence numbers of database logs stored in the database. The horizontal axis in the figure is the timeline. The consistency component can periodically obtain the first type of log sequence numbers and the second type of log sequence numbers as time changes. The first time interval and the second time interval in the figure are different.

[0045] Step 202: Determine a target log sequence number based on the first type log sequence number and the second type log sequence number.

[0046] In the disclosed embodiment, the number of database logs successfully replicated between database instances is at least one, the number of database logs stored in the database corresponding to the consistency component is at least one, and each database log corresponds to a unique log sequence number. The number of log sequence numbers included in the first type of log sequence number is at least one, the second type of log sequence number represents the log sequence number corresponding to the latest database log stored in the database corresponding to the consistency component, and the second type of log sequence number is continuously updated as the database log in the database is updated. Determining the target log sequence number based on the first type of log sequence number and the second type of log sequence number may include: comparing the second type of log sequence number with each log sequence number in the first type of log sequence number in turn, and determining the first type of log sequence number that is smaller than the second type of log sequence number and has the smallest difference with the second type of log sequence number as the target log sequence number.

[0047] See also Figure 4 , assuming that xi (i = 1, 2, 3, ...) represents the first type of log sequence number, y represents the second type of log sequence number, when y in the figure is obtained, x1, x2 and x3 are smaller than y, and the largest x3 is determined as the target log sequence number.

[0048] Step 203: Whether a log synchronization request is received, if so, execute step 204; otherwise, return to execute step 201.

[0049] Step 204: Store the database logs that are successfully copied between database instances in the database based on the target log sequence number.

[0050] The database log synchronization method provided in the embodiment of the present disclosure can be applied to the master database instance or the slave database instance. Through the newly added Checkpoint function in the consistency component, the database logs successfully copied between the database instances can be stored in the database, which solves the problem of inconsistency between the logs in the data replication module and the database. In addition, the number of stored databases that need to be retransmitted is small, and the transmission speed is fast.

[0051] The log synchronization scheme for a database provided by the embodiment of the present disclosure is that the consistency component in the master database instance or the slave database instance can obtain the first type of log sequence number of the database log that is successfully copied between database instances, and the second type of log sequence number stored in the database corresponding to the consistency component; determine the target log sequence number based on the first type of log sequence number and the second type of log sequence number; if a log synchronization request is received, the database log that is successfully copied between database instances is stored in the database based on the target log sequence number. Using the above technical scheme, the consistency component in the master database instance or the slave database instance can determine the target log sequence number, and when the log that is successfully copied between database instances is inconsistent with the log stored in the database, the most recently successfully copied database log can be stored in the database based on the target log sequence number, which solves the problem that the log is not stored after copying due to database crash, thereby ensuring the strong consistency of data between the master and slave database instances.

[0052] Figure 5 This is a schematic diagram of the structure of a database log synchronization device provided by an embodiment of the present disclosure. The device can be implemented by software and / or hardware and can generally be integrated in an electronic device. Figure 5 As shown, the device is configured in a consistency component in a master database instance or a slave database instance, including:

[0053] The log sequence number acquisition module 301 is used to obtain the first type of log sequence number of the database log successfully replicated between database instances, and the second type of log sequence number stored in the database corresponding to the consistency component;

[0054] A target log sequence number module 302, configured to determine a target log sequence number based on the first type of log sequence number and the second type of log sequence number;

[0055] The log synchronization module 303 is configured to store the database logs successfully replicated between database instances in the database based on the target log sequence number if a log synchronization request is received.

[0056] The log synchronization scheme for a database provided by the embodiment of the present disclosure is that the consistency component in the master database instance or the slave database instance can obtain the first type of log sequence number of the database log that is successfully copied between database instances, and the second type of log sequence number stored in the database corresponding to the consistency component; determine the target log sequence number based on the first type of log sequence number and the second type of log sequence number; if a log synchronization request is received, the database log that is successfully copied between database instances is stored in the database based on the target log sequence number. Using the above technical scheme, the consistency component in the master database instance or the slave database instance can determine the target log sequence number, and when the log that is successfully copied between database instances is inconsistent with the log stored in the database, the most recently successfully copied database log can be stored in the database based on the target log sequence number, which solves the problem that the log is not stored after copying due to database crash, thereby ensuring the strong consistency of data between the master and slave database instances.

[0057] Optionally, the log sequence number acquisition module 301 is specifically used for:

[0058] Obtain a first type of log sequence number of a database log successfully replicated between database instances at a first time interval, and obtain a second type of log sequence number of a database log stored in a database corresponding to the consistency component at a second time interval, wherein the first time interval and the second time interval are different.

[0059] Optionally, the number of database logs successfully replicated between database instances is at least one, the number of database logs stored in the database corresponding to the consistency component is at least one, and each of the database logs corresponds to a unique log sequence number.

[0060] Optionally, the number of log sequence numbers included in the first type of log sequence numbers is at least one, and the second type of log sequence number represents the log sequence number corresponding to the most recently stored database log in the database corresponding to the consistency component.

[0061] Optionally, the target log sequence number module 302 is specifically used for:

[0062] The second-category log sequence number is compared with each log sequence number in the first-category log sequence number in turn, and the first-category log sequence number that is smaller than the second-category log sequence number and has the smallest difference with the second-category log sequence number is determined as the target log sequence number.

[0063] Optionally, the log synchronization module 303 is specifically used for:

[0064] If it is monitored that a restart operation occurs after the database crashes, it is determined that a log synchronization request is received.

[0065] Optionally, the log synchronization module 303 is specifically used for:

[0066] Determine, among the database logs that are successfully copied between database instances, a target database log corresponding to a log sequence number that is after the target log sequence number in the first type of log sequence number;

[0067] The target database log is stored in the database.

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

[0069] Figure 6 The structure diagram of an electronic device provided by the embodiment of the present disclosure is shown in FIG. Figure 6 As shown, the electronic device 400 includes one or more processors 401 and a memory 402 .

[0070] The processor 401 may be a central processing unit (CPU) or other forms of processing units having data processing capabilities and / or instruction execution capabilities, and may control other components in the electronic device 400 to perform desired functions.

[0071] The memory 402 may include one or more computer program products, which may include various forms of computer-readable storage media, such as volatile memory and / or non-volatile memory. The volatile memory may include, for example, a random access memory (RAM) and / or a cache memory (cache), etc. The non-volatile memory may include, for example, a read-only memory (ROM), a hard disk, a flash memory, etc. One or more computer program instructions may be stored on the computer-readable storage medium, and the processor 401 may run the program instructions to implement the database log synchronization method of the embodiment of the present disclosure described above and / or other desired functions. Various contents such as input signals, signal components, noise components, etc. may also be stored in the computer-readable storage medium.

[0072] In one example, the electronic device 400 may further include: an input device 403 and an output device 404, and these components are interconnected via a bus system and / or other forms of connection mechanisms (not shown).

[0073] In addition, the input device 403 may also include, for example, a keyboard, a mouse, and the like.

[0074] The output device 404 can output various information to the outside, including the determined distance information, direction information, etc. The output device 404 can include, for example, a display, a speaker, a printer, a communication network and a remote output device connected thereto, and the like.

[0075] Of course, to simplify, Figure 6 Only some of the components related to the present disclosure in the electronic device 400 are shown, and components such as a bus, an input / output interface, etc. are omitted. In addition, according to specific application situations, the electronic device 400 may also include any other appropriate components.

[0076] In addition to the above methods and devices, the embodiments of the present disclosure may also be a computer program product, which includes computer program instructions, which, when executed by a processor, enable the processor to execute the database log synchronization method provided by the embodiments of the present disclosure.

[0077] The computer program product may be written in any combination of one or more programming languages ​​to write program code for performing the operations of the disclosed embodiments, including object-oriented programming languages ​​such as Java, C++, etc., and conventional procedural programming languages ​​such as "C" or similar programming languages. The program code may be executed entirely on the user computing device, partially on the user device, as a separate software package, partially on the user computing device and partially on a remote computing device, or entirely on a remote computing device or server.

[0078] In addition, the embodiment of the present disclosure may also be a computer-readable storage medium on which computer program instructions are stored. When the computer program instructions are executed by a processor, the processor executes the database log synchronization method provided by the embodiment of the present disclosure.

[0079] The computer readable storage medium can adopt any combination of one or more readable media. The readable medium can be a readable signal medium or a readable storage medium. The readable storage medium can include, for example, but is not limited to, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples (non-exhaustive list) of readable storage media include: an electrical connection with one or more wires, a portable disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above.

[0080] It should be noted that, in this article, relational terms such as "first" and "second" are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or device including the elements.

[0081] The above description is only a specific embodiment of the present disclosure, so that those skilled in the art can understand or implement the present disclosure. Various modifications to these embodiments will be apparent to those skilled in the art, and the general principles defined herein may be implemented in other embodiments without departing from the spirit or scope of the present disclosure. Therefore, the present disclosure will not be limited to the embodiments described herein, but will conform to the widest scope consistent with the principles and novel features disclosed herein.

Claims

1. A database log synchronization method, characterized in that: The method is applied to a consistency component in a master database instance or a slave database instance, and includes: Obtaining a first-class log sequence number of a database log that is successfully replicated between database instances, and a second-class log sequence number stored in a database corresponding to the consistency component; Determining a target log sequence number based on the first type of log sequence number and the second type of log sequence number, wherein the target log sequence number is a log sequence number used to achieve data consistency between a data replication module and the database; If a log synchronization request is received, storing the database logs successfully replicated between database instances in the database based on the target log sequence number; The determining a target log sequence number based on the first type of log sequence number and the second type of log sequence number includes: The second-category log sequence number is compared with each log sequence number in the first-category log sequence number in turn, and the first-category log sequence number that is smaller than the second-category log sequence number and has the smallest difference with the second-category log sequence number is determined as the target log sequence number.

2. The method according to claim 1, characterized in that The obtaining of the first type of log sequence number of the database log successfully replicated between database instances and the second type of log sequence number stored in the database corresponding to the consistency component includes: Obtain a first type of log sequence number of a database log successfully replicated between database instances at a first time interval, and obtain a second type of log sequence number of a database log stored in a database corresponding to the consistency component at a second time interval, wherein the first time interval and the second time interval are different.

3. The method according to claim 1, characterized in that The number of database logs successfully replicated between database instances is at least one, the number of database logs stored in the database corresponding to the consistency component is at least one, and each of the database logs corresponds to a unique log sequence number.

4. The method according to claim 3, characterized in that The number of log sequence numbers included in the first type of log sequence numbers is at least one, and the second type of log sequence number represents the log sequence number corresponding to the most recently stored database log in the database corresponding to the consistency component.

5. The method according to claim 1, characterized in that Receive log synchronization requests, including: If it is monitored that a restart operation occurs after the database crashes, it is determined that a log synchronization request is received.

6. The method according to claim 1, characterized in that The database logs that are successfully copied between the database instances are stored in the database based on the target log sequence number, including: Determine, among the database logs that are successfully copied between database instances, a target database log corresponding to a log sequence number that is after the target log sequence number in the first type of log sequence number; The target database log is stored in the database.

7. A log synchronization device for a database, characterized in that: The device is configured in a consistency component in a master database instance or a slave database instance, including: A log sequence number acquisition module, used to obtain a first type of log sequence number of a database log that is successfully replicated between database instances, and a second type of log sequence number stored in a database corresponding to the consistency component; A target log sequence number module, used to determine a target log sequence number based on the first type of log sequence number and the second type of log sequence number, wherein the target log sequence number is a log sequence number used to achieve data consistency between the data replication module and the database; A log synchronization module, configured to store the database logs successfully replicated between database instances in the database based on the target log sequence number if a log synchronization request is received; The determining a target log sequence number based on the first type of log sequence number and the second type of log sequence number includes: The second-category log sequence number is compared with each log sequence number in the first-category log sequence number in turn, and the first-category log sequence number that is smaller than the second-category log sequence number and has the smallest difference with the second-category log sequence number is determined as the target log sequence number.

8. An electronic device, characterized in that: The electronic device comprises: processor; a memory for storing instructions executable by the processor; The processor is used to read the executable instructions from the memory and execute the instructions to implement the database log synchronization method described in any one of claims 1-6 above.

9. A computer-readable storage medium, characterized in that: The storage medium stores a computer program, and the computer program is used to execute the database log synchronization method described in any one of claims 1 to 6.

Citation Information

Patent Citations

  • Data use method in data backup process and data consistency component

    CN107066353A

  • Incremental multi-replica data synchronization method and system

    CN107357920A