Log synchronization method and apparatus, electronic device, and storage medium

By generating and transmitting differential logs in the storage system of the database system, the problem of data inconsistency between the active and standby nodes under network jitter or high pressure is solved, achieving data consistency and stability, and improving the reliability of the database system. and disaster recovery capabilities.

WO2024178935A1PCT designated stage expired Publication Date: 2024-09-06HUAWEI TECH CO LTD
View PDF 8 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2023/116212
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-02-28
Filing Date
2023-08-31
Publication Date
2024-09-06

AI Technical Summary

Technical Problem

In a database system, when the network jitters or the pressure is too high, the semi-synchronous log replication method between the primary and secondary nodes may degenerate into asynchronous replication, resulting in data inconsistency and loss, affecting the stability and reliability of the business.

Method used

By storing the logs of the primary node in the storage system and generating differential logs to send to the standby node, the primary node avoids direct copying and transmission of logs. Differential logs are used for synchronization to ensure data consistency between the primary and standby nodes, and in the storage system The node's relay logs are stored in the cache to improve reliability.

Benefits of technology

It effectively avoids the risk of data inconsistency and loss between active and standby nodes, improves the stability and reliability of the database system, reduces data transmission delay and storage delay, and enhances disaster recovery capabilities.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2023116212_06092024_PF_FP
    Figure CN2023116212_06092024_PF_FP
Patent Text Reader

Abstract

The present application relates to the technical field of databases, and provides a log synchronization method and apparatus, an electronic device, and a storage medium. The method comprises: a storage system stores a log of a master node; and the storage system receives a log synchronization request from a standby node, generates a differential log on the basis of the log synchronization request and the log, and sends the differential log to the standby node. In the method, the storage system stores the log written by the master node, the master node and the standby node access the same log, and the master node does not need to replicate and transmit the log, such that inconsistency generated in log replication can be avoided, and replication mode degradation caused by network jitter between the master and standby nodes is avoided, thereby reducing the risk of data loss.
Need to check novelty before this filing date? Find Prior Art

Description

Log synchronization method, device, electronic device and storage medium

[0001] This application claims priority to Chinese patent application number 202310232100.6, filed on February 28, 2023, entitled “Log synchronization method, device, electronic device and storage medium”, the entire contents of which are incorporated by reference into this application. Technical Field

[0002] The present application relates to the field of database technology, and in particular to a log synchronization method, device, electronic device, and storage medium. Background Art

[0003] Considering the high reliability and stability of the business, the database system can be networked in a master-slave mode. That is, the database system includes a master node and a slave node. Based on this networking mode, semi-synchronous log replication can be used when synchronizing logs between the master and slave nodes.

[0004] Among them, the semi-synchronous log replication method means that after the master node executes an operation, it copies the log and sends the copied log to multiple standby nodes; after receiving the log, the standby node synchronizes the log and sends a synchronization completion message to the master node after the synchronization is complete; after receiving the synchronization completion message sent by any standby node, the master node returns the operation result to the client.

[0005] However, in the above method, when the network jitters or the network pressure is too high, the response of the backup node may be slow. When the master node does not receive the synchronization completion message from the backup node within a certain period of time, the master node directly returns the operation result to the terminal without waiting for the response of the backup node. That is, the log replication mode is converted from semi-synchronous to asynchronous, which leads to data inconsistency between the master node and the backup node, or even data loss, thereby affecting the stability and reliability of the business.

[0006] Summary of the Invention

[0007] The embodiments of the present application provide a log synchronization method, device, electronic device, and storage medium, which can avoid data inconsistency between the master node and the backup node and improve the stability and reliability of the database system. The technical solution is as follows.

[0008] In a first aspect, a log synchronization method is provided, which is executed by a storage system in a database system, the database system including a master node, a slave node, and the storage system. The method includes:

[0009] The storage system stores the master node's log, which indicates the operations that occurred on the master node;

[0010] The storage system receives a log synchronization request from the standby node, generates a differential log based on the log synchronization request and the log, and sends the differential log to the standby node. The differential log indicates unexecuted operations on the standby node.

[0011] The storage system can be a single storage device or a storage array consisting of multiple storage devices. The storage device can be any type of storage device, such as a network attached storage (NAS) or a storage area network (SAN). The master node's log records operations performed on the master node, while the differential log is the unsynchronized log of the backup node.

[0012] In the above method, since the storage system stores the logs written by the master node, the master node and the backup node access the same log. The master node does not need to copy and transmit the log, which can avoid inconsistencies caused by the log replication process and avoid the degradation of the replication method caused by network jitter between the master node and the backup node, thereby reducing the risk of data loss.

[0013] Optionally, the storage system includes a first storage device and a second storage device belonging to different areas, and the storage system stores the log of the master node including:

[0014] The first storage device stores logs, and the first storage device and the second storage device perform log synchronization.

[0015] The first storage device and the primary node belong to the same region, and the second storage device and the backup node belong to the same region. "Belonging" can mean the device is located in that region, or it can mean that the device is bound to that region and provides services to nodes within that region. Log synchronization between the first and second storage devices can be initiated by either the first or the second storage device.

[0016] In the above method, the logs of the master node are stored by a storage device belonging to the same area as the master node, which can improve the efficiency of the master node in storing logs in the storage device, avoid storage delays and data loss caused by long-distance data transmission, and can store the logs of the master node in a timely manner, thereby improving the reliability and disaster recovery capabilities of the database system.

[0017] Optionally, the standby node and the second storage device belong to the same region. The storage system receives a log synchronization request from the standby node, generates a differential log based on the log synchronization request and the log, and sends the differential log to the standby node, including:

[0018] The second storage device receives the log synchronization request from the standby node, generates a differential log based on the log synchronization request and the log, and sends the differential log to the standby node.

[0019] In the above method, the standby node sends a log synchronization request to the storage device belonging to the same area as the standby node, which can shorten the transmission time of the request and thereby improve the efficiency of log synchronization. The standby node can complete log synchronization in a timely manner, which is beneficial to improving the reliability and disaster recovery capability of the database system.

[0020] Optionally, the method further includes:

[0021] The storage system writes the differential log to the relay log of the standby node based on the write operation of the differential log on the standby node.

[0022] The relay log is used to store the differential log of the standby node. In the above method, since the standby node's relay log is stored in the storage system, it can conserve the standby node's storage resources. Furthermore, since the storage system is highly reliable, the possibility of data corruption or loss is reduced when the relay log is stored in the storage system, thereby improving the reliability of log synchronization.

[0023] Optionally, the method further includes:

[0024] The master node stores logs in the storage system.

[0025] In the above method, since the master node is used to perform read and write operations and store logs in the storage system, the master node achieves storage and computing separation, which can save the storage resources of the master node and is conducive to improving the computing performance of the master node.

[0026] Optionally, the method further includes any of the following methods:

[0027] The standby node receives the differential log and writes the differential log to the relay log stored on the standby node;

[0028] The standby node receives the differential log and writes the differential log into the relay log of the standby node stored in the storage system.

[0029] Among them, when the primary node and the standby node belong to the same area, the standby node can write the differential log to the relay log stored locally on the device, or to the relay log in the storage system; when the primary node and the standby node belong to different areas, the standby node can write the differential log to the relay log local to the device, or to the relay log in the storage device associated with the standby node.

[0030] In the above method, the relay log of the standby node is stored in the storage system, which can save the storage resources of the standby node; the relay log of the standby node is stored locally on the device, which can be easily read, thereby improving the efficiency of log synchronization based on the relay log of the standby node.

[0031] In a second aspect, a log synchronization device is provided, which is applied to a storage system in a database system, wherein the database system includes a master node, a backup node, and a storage system. The device includes at least one functional module, and the at least one functional module is used to execute the log synchronization method provided in the first aspect or any possible implementation method of the first aspect.

[0032] In a third aspect, a storage device is provided, the storage device comprising a memory and a processor;

[0033] The processor is used to execute instructions stored in the memory, so that the storage device executes the steps performed by the storage system in the log synchronization method provided by the aforementioned first aspect or any possible implementation of the first aspect.

[0034] In a fourth aspect, a storage system is provided, the storage system comprising at least one storage device, each storage device comprising a memory and a processor;

[0035] The processor of at least one storage device is used to execute instructions stored in the memory of at least one storage device, so that the storage device performs the steps performed by the storage system in the log synchronization method provided by the first aspect or any possible implementation of the first aspect.

[0036] In a fifth aspect, an electronic device is provided, the electronic device including a processor and a memory;

[0037] The processor is used to execute instructions stored in the memory so that the electronic device performs the steps performed by the master node, or the steps performed by the backup node, in the log synchronization method provided in the aforementioned first aspect or any possible implementation of the first aspect.

[0038] In a sixth aspect, a computer program product comprising instructions is provided, which, when executed by a storage device, causes the storage device to execute the steps executed by the storage system in the log synchronization method provided in the aforementioned first aspect or any possible implementation of the first aspect, or, when executed by a storage system, causes the storage system to execute the steps executed by the storage system in the log synchronization method provided in the aforementioned first aspect or any possible implementation of the first aspect.

[0039] In the seventh aspect, a computer program product comprising instructions is provided. When the instructions are executed by an electronic device, the electronic device executes the steps executed by the master node or the backup node in the log synchronization method provided in the first aspect or any possible implementation of the first aspect.

[0040] In an eighth aspect, a computer-readable storage medium is provided, which includes computer program instructions. When the computer program instructions are executed by a storage device, the storage device executes the steps performed by the storage system in the log synchronization method provided in the aforementioned first aspect or any possible implementation of the first aspect, or, when the computer program instructions are executed by the storage system, the storage system executes the steps performed by the storage system in the log synchronization method provided in the aforementioned first aspect or any possible implementation of the first aspect.

[0041] In the ninth aspect, a computer-readable storage medium is provided, which includes computer program instructions. When the computer program instructions are executed by an electronic device, the electronic device executes the steps executed by the master node or the backup node in the log synchronization method provided in the first aspect or any possible implementation of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] FIG1 is a schematic diagram of the structure of a database system provided in an embodiment of the present application;

[0043] FIG2 is a flow chart of a log synchronization method provided by an embodiment of the present application;

[0044] FIG3 is a schematic diagram of a log synchronization method provided in an embodiment of the present application;

[0045] FIG4 is a flow chart of a log synchronization method provided by an embodiment of the present application;

[0046] FIG5 is a flow chart of a log synchronization method provided by an embodiment of the present application;

[0047] FIG6 is a schematic diagram of a log synchronization method provided in an embodiment of the present application;

[0048] FIG7 is a flow chart of a log synchronization method provided by an embodiment of the present application;

[0049] FIG8 is a structural block diagram of a log synchronization device provided in an embodiment of the present application;

[0050] FIG9 is a schematic structural diagram of a storage device provided in an embodiment of the present application;

[0051] FIG10 is a schematic diagram of a storage system provided in an embodiment of the present application;

[0052] FIG11 is a schematic diagram of a possible implementation of a storage system provided in an embodiment of the present application. DETAILED DESCRIPTION

[0053] In order to make the objectives, technical solutions and advantages of this application clearer, the implementation methods of this application will be further described in detail below with reference to the accompanying drawings.

[0054] First, the implementation environment of the embodiment of the present application is introduced.

[0055] FIG1 is a schematic diagram of the structure of a database system provided by an embodiment of the present application. As shown in FIG1 , the database system includes multiple master nodes 101, standby nodes 102, and a storage system 103. Among them, the master node 101 provides external data read-write (read-write, RW) services, that is, the client can perform read and write operations on the data in the database system through the master node, and the master node records the operations that occur in the log (binlog); the standby node 102 provides external data read (read, R) services, and synchronizes the log of the master node 101 to synchronize the data of the master node 101, and then after the master node 101 fails, the standby node 102 can take over the master node 101 to provide external data read and write services. Among them, the standby node 102 has its own relay log (relay log), which is used to store the log of the master node to be synchronized by the standby node 102 (that is, differential log). The storage system 103 can provide data storage services for the database system, for example, storing the log of the master node 101 and storing the relay log of the standby node 102. The storage system 103 includes at least one storage device.

[0056] Among them, the master node 101 and the backup node 102 can be independent physical servers, or a server cluster composed of multiple physical servers, or cloud servers that provide basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, distribution networks (content delivery networks, CDNs), and big data and artificial intelligence platforms. The storage system 103 can be a network attached storage (NAS) or a storage area network (SAN), etc., which is not limited in the embodiments of the present application.

[0057] The master node 101 and the backup node 102 can be connected to the storage system 103 via a wired network or a wireless network. In some embodiments, the wireless network or wired network uses standard communication technologies and / or protocols. The network is typically the Internet, but can also be any network, including but not limited to a local area network (LAN), a metropolitan area network (MAN), a wide area network (WAN), a mobile, wired or wireless network, a private network, or any combination of a virtual private network. In some embodiments, peer-to-peer (P2P) communication is implemented between the master node 101, the backup node 102, and the storage system 103 based on a remote procedure call protocol (RPC). In some embodiments, the master node 101, the backup node 102, and the storage system 103 use technologies and / or formats including hypertext markup language (HTML), extensible markup language (XML), etc. to represent data blocks exchanged over the network. In addition, all or some links can be encrypted using conventional encryption technologies such as secure socket layer (SSL), transport layer security (TLS), virtual private network (VPN), internet protocol security (IPsec), etc. In other embodiments, customized and / or dedicated data communication technologies can be used instead of or in addition to the above data communication technologies.

[0058] The above describes the implementation environment of the embodiment of the present application. The following describes a log synchronization method provided by the embodiment of the present application. The method is executed by the database system shown in Figure 1 above, and the database system includes a master node, a standby node, and a storage system. In this method, the master node stores the log in the storage system, and the standby node sends a log synchronization request to the storage system; after receiving the log synchronization request, the storage system generates a differential log for the standby node and sends the differential log to the standby node. This process can be understood as the storage system providing a log synchronization service to the standby node; after receiving the differential log, the standby node writes the differential log to the relay log of the standby node to complete the log synchronization.

[0059] The above describes the basic process of the embodiment of the present application, and the following describes the specific process of the embodiment of the present application. In different scenarios, the specific process of the embodiment of the present application is different.

[0060] If the primary and standby nodes belong to the same availability zone (AZ), they share storage devices. The standby node's relay log can be stored on the shared storage device to conserve storage resources. Alternatively, the standby node's relay log can be stored locally on the device for easy access, improving the efficiency of relay log synchronization on the standby node.

[0061] In the scenario where the master node and the standby node do not belong to the same region, the master node and the standby node are each associated with a storage device in the storage system, and the nodes and the associated devices belong to the same region. Log synchronization is first completed between the storage devices associated with the master node and the standby node, and the storage device associated with the standby node then provides log synchronization services to the standby node. Furthermore, in this scenario, the relay log of the standby node can be stored on the storage device associated with the standby node, or it can be stored locally on the device. In the above content, belonging can mean that the location of the device is in the region, or it can mean that the device has a binding relationship with the region, and the device provides services for the nodes in the region.

[0062] The following is a detailed introduction to the four embodiments in the above two scenarios.

[0063] First, let's take the example of a master node and a backup node belonging to the same region, with the backup node's relay log stored in a storage system. Figure 2 is a flow chart of a log synchronization method provided by an embodiment of the present application. As shown in Figure 2, the method is executed by a database system that includes a master node, a backup node, and a storage system. The method includes steps 201 to 206.

[0064] 201. The master node stores a log in a storage system, where the log indicates operations performed on the master node.

[0065] The log is used to record operations on the master node that change the database table structure and modify the table data. The log can be a binlog log or a write-ahead log, etc., and the embodiments of the present application do not limit this. The storage system can be a separate storage device or a storage array composed of multiple storage devices, wherein the storage device can be a network attached storage (NAS) or a storage area network (SAN), etc. The embodiments of the present application do not limit the number and type of storage devices.

[0066] Among them, the master node links the file system of the storage system to the file system of the master node. The master node can access the data stored in the storage system by accessing the file system of the master node to read and write the logs stored in the storage system. This process is that the master node mounts the logs to the storage system.

[0067] In the above method, since the master node is used to perform read and write operations and store logs in the storage system, the master node achieves storage and computing separation, which can save the storage resources of the master node and is conducive to improving the computing performance of the master node.

[0068] 202. The standby node sends a log synchronization request to the storage system.

[0069] The log synchronization request carries the identifier of the standby node and the location of the standby node's synchronized log. The synchronized log location, i.e., the location synchronized during the previous log synchronization process, indicates which logs have not yet been synchronized. The log synchronization request is used to request the storage system for unsynchronized logs, i.e., the differential logs of the standby node. The standby node starts an I / O thread and sends a log synchronization request to the storage system through the I / O thread.

[0070] In some embodiments, the backup node periodically or regularly sends log synchronization requests to the storage system, where the time between two adjacent synchronization requests can be set according to actual needs. When the time between two adjacent synchronization requests is short, the backup node can complete the synchronization with the primary node in a timely manner, thereby improving the reliability and availability of the system.

[0071] In other embodiments, after an operation occurs, the master node proactively sends a message to the standby node to prompt the standby node to perform log synchronization. The master node may send a message to the standby node each time an operation occurs, thereby ensuring real-time synchronization between the master and standby nodes and preventing the standby node from sending a log synchronization request to the storage system when no operation occurs on the master node. This can reduce ineffective log synchronization operations on the standby node, thereby alleviating pressure on the standby node and saving data transmission resources. The master node may also send a message to the standby node after a target number of operations occur, thereby avoiding frequent log synchronization operations on the standby node and improving the efficiency of log synchronization on the standby node.

[0072] In the above method, since the process of the standby node sending a log synchronization request to the storage system for log synchronization is consistent with the process of the standby node sending a log synchronization request to the master node, the standby node can obtain differential logs from the storage system directly through simple configuration without modifying the standby node, which can save the deployment cost of the solution and improve the practicality of the solution.

[0073] 203. The storage system receives the log synchronization request sent by the standby node, and generates a differential log based on the log synchronization request of the standby node and the log of the primary node. The differential log indicates the operations that have not been executed on the standby node.

[0074] The differential log is the unsynchronized log of the standby node. Based on the log position carried in the standby node's log synchronization request, the storage system locates the log position in the master node's log and reads the logs after the log position to generate the differential log.

[0075] 204. The storage system sends the differential log to the standby node.

[0076] 205. The standby node receives the differential log.

[0077] 206. The standby node writes the differential log to the relay log of the standby node stored in the storage system.

[0078] The relay log of the standby node is used to store the differential log of the standby node. The standby node links the storage system's file system to the standby node's file system. The standby node can access the data stored in the storage system by accessing the standby node's file system to read and write the relay log stored in the storage system. This process is the standby node mounting the relay log to the storage system. After the standby node receives the differential log, the standby node's I / O thread reads the differential log and performs a write operation on the differential log. Based on the standby node's write operation on the differential log, the storage system writes the differential log to the standby node's relay log stored in the storage system. The standby node records the location of the log synchronized this time as a reference location for the next log synchronization.

[0079] In the above method, since the relay log of the standby node is stored in the storage system, the storage resources of the standby node can be saved. In addition, since the reliability of the storage system is high, the relay log is stored in the storage system, and the possibility of data damage or loss is small, which can improve the reliability of log synchronization.

[0080] In some embodiments, after writing the differential log to the relay log, the standby node starts an SQL thread, which reads the differential log from the relay log and executes the operations corresponding to the read differential log, that is, replays the differential log to synchronize the operations occurring on the master node, thereby achieving the purpose of master-standby node synchronization.

[0081] In some embodiments, the master node and the backup node belonging to the same area can switch with each other, that is, the embodiments of the present application support master-backup switching within AZ. When the master node fails, the backup node can take over the work of the master node in time, thereby improving the disaster recovery capability of the database system, and further improving the stability and reliability of the database system.

[0082] The process shown in steps 201 to 205 above is illustrated below by way of example in FIG3 . FIG3 is a schematic diagram of a log synchronization method provided by an embodiment of the present application. As shown in FIG3 , taking a MySQL database as an example, a MySQL master database is running on the master node, a MySQL slave database is running on the standby node, and the master node and the standby node share a storage system. The master node writes the log (binlog) to the storage system, which can provide a log synchronization service (binlog service). The standby node sends a log synchronization request to the storage system through an I / O thread to obtain a differential log, and writes the obtained differential log to the relay log (relay log) of the standby node in the storage system. The standby node reads the differential log from the relay log through an SQL thread, and replays the read differential log to synchronize the operations occurring on the master node. It should be noted that the example of the MySQL database in FIG3 is merely exemplary, and the log synchronization method provided by the embodiment of the present application is also applicable to any database such as openGauss and PostgreSQL, and the embodiment of the present application does not limit this.

[0083] In the above method, the master node writes the log to the storage system shared with the standby node. After receiving the log synchronization request from the standby node, the storage system can send the differential log to the standby node to complete the log synchronization. Since the master node directly writes the log to the storage system, the master node and the standby node access the same log, and the master node does not need to copy and transmit the log. This process can be understood as the log synchronization service being unloaded from the node side to the storage side, which can avoid the inconsistencies generated during the log replication process and the degradation of the replication method caused by the network jitter between the master node and the standby node, thereby reducing the risk of data loss. In addition, the relay log of the standby node is stored in the storage system, which can save the storage resources of the standby node. Moreover, since the reliability of the storage system is relatively high, the relay log is stored in the storage system, and the possibility of data damage or loss is relatively low, which can improve the reliability of log synchronization and the stability of the database system.

[0084] The following example illustrates a situation where the master node and the backup node belong to the same region, and the backup node's relay log is stored locally on the device. FIG4 is a flow chart of a log synchronization method provided by an embodiment of the present application. As shown in FIG4 , the method is executed by a database system comprising a master node, a backup node, and a storage system. The method comprises steps 401 to 406.

[0085] 401. The master node stores a log in a storage system. The log indicates operations performed on the master node.

[0086] 402. The standby node sends a log synchronization request to the storage system.

[0087] 403. The storage system receives the log synchronization request sent by the standby node, and generates a differential log based on the log synchronization request of the standby node and the log of the primary node. The differential log indicates the operations that have not been executed on the standby node.

[0088] 404. The storage system sends the differential log to the standby node.

[0089] 405. The standby node receives the differential log.

[0090] 406. The standby node writes the differential log into the relay log stored on the standby node.

[0091] The above steps 401 to 406 are similar to the above steps 201 to 206, except that in step 406, the relay log of the standby node is stored on the standby node. The similarities are not repeated here.

[0092] In the above method, the master node writes the log to a storage system shared with the standby node. After receiving the log synchronization request from the standby node, the storage system can send the differential log to the standby node to complete the log synchronization. Since the master node directly writes the log to the storage system, the master node and the standby node access the same log. The master node does not need to copy and transmit the log, which can avoid inconsistencies caused by the log replication process and the degradation of the replication method caused by network jitter between the master node and the standby node, thereby avoiding the risk of data loss. In addition, the relay log of the standby node is stored in the standby node, which can improve the efficiency of the standby node in reading the differential log from the relay log, thereby reducing the synchronization delay between the master and standby nodes and improving the efficiency of the master and standby node synchronization.

[0093] It should be noted that the embodiments shown in Figures 2 and 4 above are introduced by taking the storage system to store relay logs and the standby node to store relay logs as examples, respectively. In some embodiments, the standby node and the storage system both store the relay log of the standby node. After the standby node receives the differential log, it writes the differential log to the local relay log of the device and the relay log in the storage system, respectively. When performing log synchronization, the standby node can quickly read the differential log in the relay log from the local device to ensure reading efficiency. Moreover, since there is a backup on the storage system, on the basis of ensuring that the standby node can complete data synchronization, the reliability of relay log storage can also be guaranteed.

[0094] The following example illustrates a case where the master node and the backup node do not belong to the same region, and the backup node's relay log is stored in a storage device associated with the backup node. FIG5 is a flow chart of a log synchronization method provided by an embodiment of the present application. As shown in FIG5 , the method is executed by a database system comprising a master node, a backup node, and a storage system comprising a first storage device and a second storage device. The method includes steps 501 to 507.

[0095] 501. A master node stores a log in a first storage device, where the log indicates operations performed by the master node. The first storage device and the master node belong to the same region.

[0096] This step 501 is similar to the above step 201 and will not be described in detail.

[0097] 502. The first storage device synchronizes the log of the master node to the second storage device, where the second storage device and the standby node belong to the same region.

[0098] Among them, the first storage device periodically or regularly copies the log of the master node and sends the copied log to the second storage device. The time between two adjacent log copies can be set according to actual needs. When the time between two adjacent log copies is short, the second storage device can complete the synchronization with the first storage device in a timely manner, thereby improving the reliability and stability of the database system. In some embodiments, each time the master node stores a log in the storage system, the first storage device copies the updated log once and sends it to the second storage device, thereby ensuring real-time synchronization of the logs stored in the first storage device and the second storage device, and then ensuring that both the master node and the backup node can provide online services to the outside world, that is, realizing dual-active master and backup nodes.

[0099] It should be noted that the above step 502 is described using the example of the first storage device initiating log synchronization. In some embodiments, the second storage device initiates log synchronization, and the second storage device periodically or regularly sends a synchronization request to the second storage device. After receiving the synchronization request, the first storage device copies the log and sends the copied log to the second storage device. In other embodiments, when a backup node sends a log synchronization request to the second storage device, the second storage device sends a synchronization request to the first storage device to synchronize the log of the master node stored on the first storage device. This ensures that the differential log received by the backup node each time is the latest, thereby improving the effectiveness of log synchronization.

[0100] 503. The standby node sends a log synchronization request to the second storage device.

[0101] 504. The second storage device receives the log synchronization request sent by the standby node, and generates a differential log based on the log synchronization request of the standby node and the log of the master node. The differential log indicates the operations that have not been executed on the standby node.

[0102] 505. The second storage device sends the differential log to the standby node.

[0103] 506. The standby node receives the differential log.

[0104] 507. The standby node writes the differential log into the relay log of the standby node stored on the second storage device.

[0105] The above steps 503 to 507 are similar to the above steps 202 to 206 and are not described in detail.

[0106] The process shown in steps 501 to 506 above is illustrated below with reference to FIG6 . FIG6 is a schematic diagram of a log synchronization method provided in an embodiment of the present application. As shown in FIG6 , a MySQL master database is running on the master node, and a MySQL slave database is running on the standby node. The master node and the standby node belong to the same region as the first storage device and the second storage device, respectively. The master node writes the log (binlog) to the first storage device, and log synchronization is performed between the first storage device and the second storage device. The second storage device can provide a log synchronization service (binlog service). The standby node sends a log synchronization request to the second storage device via an I / O thread to obtain a differential log, and writes the obtained differential log to a relay log in the second storage device. The standby node reads the differential log from the relay log via an SQL thread, and replays the read differential log to synchronize operations occurring on the master node. It should be noted that the example of the MySQL database in FIG3 is merely exemplary. The log synchronization method provided in the embodiment of the present application is also applicable to any database such as openGauss and PostgreSQL, and the embodiment of the present application does not limit this.

[0107] In the above method, the log of the master node is stored by a storage device belonging to the same area as the master node, which can improve the efficiency of the master node in storing the log to the storage device, avoid storage delays and data loss caused by long-distance data transmission, and can store the log of the master node in a timely manner. In addition, the backup node sends a log synchronization request to the storage device belonging to the same area as the backup node, which can shorten the transmission time of the request, thereby improving the efficiency of log synchronization. The backup node can complete log synchronization in a timely manner, which is conducive to improving the reliability and disaster recovery capabilities of the database system. In addition, because the relay log of the backup node is stored in the storage system, the storage resources of the backup node can be saved. Since the reliability of the storage system is high, the relay log is stored in the storage system, and the possibility of data damage or loss is low, which can improve the reliability of log synchronization and the stability of the database system.

[0108] The following example illustrates a situation where the master node and the backup node do not belong to the same region, and the backup node's relay log is stored locally on the device. FIG7 is a flow chart of a log synchronization method provided by an embodiment of the present application. As shown in FIG7 , the method is executed by a database system comprising a master node, a backup node, and a storage system comprising a first storage device and a second storage device. The method includes steps 701 to 707.

[0109] 701. The master node stores a log in a first storage device, where the log indicates operations performed by the master node. The first storage device and the master node belong to the same region.

[0110] 702. The first storage device synchronizes the log of the master node to the second storage device.

[0111] 703. The standby node sends a log synchronization request to the second storage device. The standby node and the second storage device belong to the same region.

[0112] 704. The second storage device receives the log synchronization request sent by the standby node, and generates a differential log based on the log synchronization request of the standby node and the log of the master node. The differential log indicates the operations that have not been executed on the standby node.

[0113] 705. The second storage device sends the differential log to the standby node.

[0114] 706. The standby node receives the differential log.

[0115] 707. The standby node writes the differential log into the relay log stored on the standby node.

[0116] The above steps 701 to 707 are similar to the above steps 501 to 507, except that in step 707, the relay log of the standby node is stored on the standby node. The similarities are not repeated here.

[0117] In the above method, the log of the master node is stored by a storage device belonging to the same area as the master node, which can improve the efficiency of the master node in storing the log in the storage device, avoid storage delays and data loss caused by long-distance data transmission, and can store the log of the master node in a timely manner. In addition, the backup node sends a log synchronization request to the storage device belonging to the same area as the backup node, which can shorten the transmission time of the request, thereby improving the efficiency of log synchronization. The backup node can complete log synchronization in a timely manner, which is conducive to improving the reliability and disaster recovery capabilities of the database system. In addition, since the relay log of the backup node is stored in the backup node, it can improve the efficiency of the backup node in reading the differential log from the relay log, thereby reducing the synchronization delay between the master and backup nodes and improving the efficiency of master and backup node synchronization.

[0118] It should be noted that the embodiments shown in Figures 2 and 4 above are described by taking the example that the master node and the standby node belong to the same area, that is, the master node and the standby node are networked in a single AZ master-standby mode. The embodiments shown in Figures 5 and 7 above are described by taking the example that the master node and the standby node belong to different areas, that is, the master node and the standby node are networked in a cross-AZ disaster recovery mode. In some embodiments, the master node and the standby node are networked in a mixed mode, that is, the master node and some standby nodes belong to the same area, and some standby nodes do not belong to the same area. In this scenario, the log synchronization between the master and standby nodes is a combination of the above two scenarios. The specific process is the same as the above embodiment and will not be repeated.

[0119] FIG8 is a structural block diagram of a log synchronization device provided in an embodiment of the present application, which is applied to a storage system in a database system. The database system includes a master node, a backup node, and a storage system. The device includes a storage module 801 and a sending module 802 .

[0120] Storage module 801, used to store the log of the master node, which indicates the operations performed on the master node;

[0121] The sending module 802 is configured to receive a log synchronization request from a standby node, generate a differential log based on the log synchronization request and the log, and send the differential log to the standby node. The differential log indicates unexecuted operations on the standby node.

[0122] Optionally, the storage system includes a first storage device and a second storage device belonging to different areas, and the storage module 801 is configured to:

[0123] The log is stored in the first storage device, and the log is synchronized between the first storage device and the second storage device.

[0124] Optionally, the standby node and the second storage device belong to the same region, and the sending module 802, applied to the second storage device, includes:

[0125] A receiving unit, configured to receive a log synchronization request from a standby node;

[0126] A generation unit, configured to generate a differential log based on the log synchronization request and the log;

[0127] The sending unit is used to send differential logs to the standby node.

[0128] Optionally, the device is further used to:

[0129] Based on the write operation of the standby node on the differential log, the differential log is written to the relay log of the standby node.

[0130] Optionally, the device is also applied to a master node, for:

[0131] Store logs in a storage system.

[0132] Optionally, the device is also applied to a standby node for any of the following:

[0133] Receive the differential log and write the differential log to the relay log stored on the standby node;

[0134] Receive the differential log, and write the differential log to the relay log of the standby node stored in the storage system.

[0135] The storage module 801 and the sending module 802 can be implemented by software or hardware. For example, the implementation of the sending module 802 is described below using the sending module 802 as an example. Similarly, the implementation of the storage module 801 can refer to the implementation of the sending module 802.

[0136] As an example of a software functional unit, the sending module 802 may include code running on a computing instance. The computing instance may include at least one of a physical host (computing device), a virtual machine, and a container. Furthermore, the computing instance may be one or more. For example, the sending module 802 may include code running on multiple hosts / virtual machines / containers. It should be noted that the multiple hosts / virtual machines / containers used to run the code may be distributed in the same region or in different regions. Furthermore, the multiple hosts / virtual machines / containers used to run the code may be distributed in the same availability zone (AZ) or in different AZs, each AZ including one data center or multiple geographically close data centers. Typically, a region may include multiple AZs.

[0137] Similarly, multiple hosts / virtual machines / containers running the code can be distributed within the same virtual private cloud (VPC) or across multiple VPCs. Typically, a VPC is set up within a region. Cross-region communication between two VPCs within the same region, or between VPCs in different regions, requires a communication gateway within each VPC to interconnect the VPCs.

[0138] As an example of a hardware functional unit, the sending module 802 may include at least one computing device, such as a server. Alternatively, the sending module 802 may be implemented using an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The PLD may be a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL), or any combination thereof.

[0139] The multiple computing devices included in the sending module 802 can be distributed in the same region or in different regions. The multiple computing devices included in the sending module 802 can be distributed in the same AZ or in different AZs. Similarly, the multiple computing devices included in the storage module 801 can be distributed in the same VPC or in multiple VPCs. The multiple computing devices can be any combination of servers, ASICs, PLDs, CPLDs, FPGAs, GALs, and other computing devices.

[0140] It should be noted that, in other embodiments, the steps that the above modules are responsible for implementing can be specified as needed, and all the functions of the above device can be realized by respectively implementing different steps in the above log synchronization method through the above modules. That is, the log synchronization device provided by the above embodiment only uses the division of the above functional modules as an example to illustrate when implementing the log synchronization method. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the device provided by the above embodiment and the corresponding method embodiment belong to the same concept, and its specific implementation process is detailed in the method embodiment, which will not be repeated here.

[0141] The present application also provides a storage device 900. FIG9 is a schematic diagram of the structure of a storage device provided in an embodiment of the present application. As shown in FIG9 , the storage device 900 includes a bus 901, a processor 902, a memory 903, and a communication interface 904. The processor 902, the memory 903, and the communication interface 904 communicate with each other via the bus 901. The storage device 900 can be a server or a terminal device. It should be understood that the present application does not limit the number of processors and memories in the storage device 900.

[0142] Bus 901 may be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, for example. Buses may be classified as address buses, data buses, control buses, and the like. For ease of illustration, FIG9 shows a single line, but this does not imply a single bus or type of bus. Bus 901 may include a path for transmitting information between various components of storage device 900 (e.g., memory 903, processor 902, and communication interface 904).

[0143] The processor 902 may include any one or more processors such as a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).

[0144] The memory 903 may include volatile memory (VM), such as random access memory (RAM). The memory 903 may also include non-volatile memory (NVM), such as read-only memory (ROM), flash memory, hard disk drive (HDD), or solid state drive (SSD).

[0145] The memory 903 stores executable program codes, and the processor 902 executes the executable program codes to respectively implement the functions of the aforementioned storage module 801 and the sending module 802, thereby implementing the log synchronization method. That is, the memory 903 stores instructions for executing the log synchronization method.

[0146] Alternatively, the memory 903 stores executable program code, and the processor 902 executes the executable program code to respectively implement the functions of the aforementioned storage module 801 and sending module 802, thereby implementing the log synchronization method. That is, the memory 903 stores instructions for executing the log synchronization method.

[0147] The communication interface 904 uses a transceiver module such as, but not limited to, a network interface card or a transceiver to implement communication between the storage device 900 and other devices or a communication network.

[0148] The present application also provides a storage system. Figure 10 is a schematic diagram of a storage system provided by an embodiment of the present application. As shown in Figure 10, the storage system includes at least one storage device 900. The memory 903 in one or more storage devices 900 in the storage system may store the same instructions for executing the log synchronization method.

[0149] In some possible implementations, the memory 903 of one or more storage devices 900 in the storage system may also store partial instructions for executing the log synchronization method. In other words, the combination of one or more storage devices 900 can jointly execute the instructions for executing the log synchronization method.

[0150] It should be noted that the memory 903 in different storage devices 900 in the storage system can store different instructions, each used for part of the functions of the log synchronization device. In other words, the instructions stored in the memory 903 in different storage devices 900 can implement the functions of one or more modules in the sending module 801 and the storage module 802.

[0151] It should be understood that the functions of the storage device 900 shown in FIG. 10 may also be performed by multiple storage devices 900 .

[0152] In some possible implementations, one or more storage devices in a storage system may be connected via a network. The network may be a wide area network (WAN) or a local area network (LAN), among others. FIG. 11 illustrates one possible implementation. FIG. 11 is a schematic diagram of a possible implementation of a storage system provided by an embodiment of the present application. As shown in FIG. 11 , two storage devices 900 are connected via a network. Specifically, the connection to the network is achieved via a communication interface in each storage device.

[0153] The present application also provides another storage system. The connection relationship between the storage devices in the storage system can be similar to the connection method shown in Figures 10 or 11. The difference is that the memory 903 in one or more storage devices 900 in the storage system can store the same instructions for executing the log synchronization method.

[0154] In some possible implementations, the memory 903 of one or more storage devices 900 in the storage system may also store partial instructions for executing the log synchronization method. In other words, the combination of one or more storage devices 900 can jointly execute the instructions for executing the log synchronization method.

[0155] It should be noted that the memories 903 in different storage devices 900 in the storage system can store different instructions, each for executing a portion of the functions of the log synchronization device. In other words, the instructions stored in the memories 903 in different storage devices 900 can implement the functions of one or more modules in the storage module 801 and the sending module 802.

[0156] An embodiment of the present application provides an electronic device, which includes a processor and a memory, and the processor is used to execute instructions stored in the memory so that the electronic device executes the steps executed by the master node or the steps executed by the backup node in the log synchronization method provided in the above embodiment.

[0157] The present application implements a computer program product containing instructions. The computer program product may be software or a program product containing instructions that can be run on an electronic device or stored in any available medium. When the computer program product is run on an electronic device, the electronic device is caused to perform the steps performed by the storage system, the steps performed by the master node, or the steps performed by the backup node in the log synchronization method provided in the above embodiment.

[0158] An embodiment of the present application provides a computer-readable storage medium, which can be any available medium that a computing device can store or a data storage device such as a data center that includes one or more available media. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive). The computer-readable storage medium includes instructions, and when the instructions are executed by an electronic device, the electronic device executes the steps performed by the storage system in the log synchronization method provided in the above embodiment, or the steps performed by the master node, or the steps performed by the standby node.

[0159] It should be noted that the information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data used for analysis, storage, display, etc.), and signals involved in this application are all authorized by the user or fully authorized by all parties, and the collection, use, and processing of relevant data must comply with the relevant laws, regulations, and standards of the relevant countries and regions. For example, the logs involved in this application were obtained with full authorization.

[0160] Those skilled in the art will appreciate that the various method steps and units described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the steps and components of each embodiment have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0161] Those skilled in the art will clearly understand that, for the sake of convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0162] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of the unit is only a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, or can be electrical, mechanical or other forms of connection.

[0163] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiments of the present application.

[0164] In addition, each unit in each embodiment of the present application may be integrated into a processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The above-mentioned integrated units may be implemented in the form of hardware or software units.

[0165] If the 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 storage medium. Based on this understanding, the technical solution of the present application is essentially or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for enabling a computing device (which can be a personal computer, a server, or a computing device, etc.) to execute all or part of the steps of the method in each embodiment of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0166] In this application, the terms "first", "second", etc. are used to distinguish between identical or similar items having substantially the same effects and functions. It should be understood that there is no logical or temporal dependency between "first", "second", and "nth", nor is there a limit on quantity and execution order. It should also be understood that although the following description uses the terms first, second, etc. to describe various elements, these elements should not be limited by the terms. These terms are only used to distinguish one element from another. For example, without departing from the scope of various examples, a first storage device may be referred to as a second storage device, and similarly, a second storage device may be referred to as a first storage device. Both the first storage device and the second storage device may be storage devices, and in some cases, may be separate and different storage devices.

[0167] In this application, the term "at least one" means one or more, and the term "plurality" means two or more. For example, "plurality of backup nodes" means two or more backup nodes. The terms "system" and "network" are often used interchangeably herein.

[0168] It should also be understood that the term "if" may be interpreted to mean "when" or "upon" or "in response to determining" or "in response to detecting." Similarly, the phrase "if it is determined that..." or "if [stated condition or event] is detected" may be interpreted to mean "upon determining that..." or "in response to determining that..." or "upon detecting [stated condition or event]" or "in response to detecting [stated condition or event]," depending on the context.

[0169] The above description is merely a specific embodiment of the present application, but the scope of protection of the present application is not limited thereto. Any person skilled in the art can easily conceive of various equivalent modifications or substitutions within the technical scope disclosed in this application, and such modifications or substitutions should be included in the scope of protection of the present application. Therefore, the scope of protection of the present application should be based on the scope of protection of the claims.

[0170] In the above embodiments, all or part of the embodiments may be implemented using software, hardware, firmware, or any combination thereof. When implemented using software, all or part of the embodiments may be implemented in the form of a computer program product. The computer program product includes one or more computer program instructions. When the computer program instructions are loaded and executed on a computer, the processes or functions described in the embodiments of the present application are generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device.

[0171] The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer program instructions may be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via a wired or wireless method. The computer-readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server or data center that includes one or more available media. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, or a magnetic tape), an optical medium (e.g., a digital video disc (DVD), or a semiconductor medium (e.g., a solid-state drive)), etc.

[0172] Those skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware, or may be accomplished by a program to instruct the relevant hardware, and the program may be stored in a computer-readable storage medium, and the above-mentioned storage medium may be a read-only memory, a disk or an optical disk, etc.

[0173] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A log synchronization method, It is characterized in that The method is executed by a storage system in a database system, wherein the database system includes a master node, a backup node, and the storage system. The method includes: The storage system stores a log of the master node, wherein the log indicates an operation occurring at the master node; The storage system receives a log synchronization request from the standby node, generates a differential log based on the log synchronization request and the log, and sends the differential log to the standby node, where the differential log indicates an operation that has not been executed on the standby node.

2. The method according to claim 1, It is characterized in that The storage system includes a first storage device and a second storage device belonging to different areas, and the storage system stores the log of the master node including: The first storage device stores the log, and the first storage device and the second storage device perform log synchronization.

3. The method according to claim 2, It is characterized in that The standby node and the second storage device belong to the same region, the storage system receives a log synchronization request from the standby node, generates a differential log based on the log synchronization request and the log, and sends the differential log to the standby node, including: The second storage device receives the log synchronization request of the standby node, generates a differential log based on the log synchronization request and the log, and sends the differential log to the standby node.

4. The method according to claim 1, It is characterized in that The method further comprises: The storage system writes the differential log into the relay log of the standby node based on the write operation of the standby node on the differential log.

5. The method according to claim 1, It is characterized in that The method further comprises: The master node stores the log in the storage system.

6. The method according to claim 1, It is characterized in that The method also includes any of the following: The standby node receives the differential log, and writes the differential log into the relay log stored on the standby node; The standby node receives the differential log, and writes the differential log into the relay log of the standby node stored in the storage system.

7. A log synchronization device, It is characterized in that A storage system applied to a database system, the database system comprising a master node, a standby node and the storage system, the device comprising: A storage module, used to store a log of the master node, wherein the log indicates an operation occurring at the master node; A sending module is used for the storage system to receive a log synchronization request from the standby node, generate a differential log based on the log synchronization request and the log, and send the differential log to the standby node, wherein the differential log indicates operations that have not been executed on the standby node.

8. A storage device, It is characterized in that The storage device includes a memory and a processor; The processor is used to execute instructions stored in the memory so that the storage device executes the log synchronization method described in any one of claims 1 to 4.

9. A storage system, It is characterized in that The storage system includes at least one storage device, each of which includes a memory and a processor; The processor of the at least one storage device is used to execute instructions stored in the memory of the at least one storage device, so that the storage system executes the log synchronization method according to any one of claims 1 to 4.

10. An electronic device, It is characterized in that The electronic device comprises a processor and a memory; The processor is used to execute the instructions stored in the memory so that the electronic device performs the method according to claim 5 or claim 6. The log synchronization method described.

11. A computer program product comprising instructions, It is characterized in that When the instruction is executed by a storage device, the storage device executes the log synchronization method as described in any one of claims 1 to 4, or, when the instruction is executed by a storage system, the storage system executes the log synchronization method as described in any one of claims 1 to 4.

12. A computer program product comprising instructions, It is characterized in that When the instructions are executed by a processor of an electronic device, the electronic device executes the log synchronization method as described in claim 5 or claim 6.

13. A computer-readable storage medium, It is characterized in that Comprising computer program instructions, when the computer program instructions are executed by a storage device, the storage device executes the log synchronization method as described in any one of claims 1 to claim 4, or, when the computer program instructions are executed by a storage system, the storage system executes the log synchronization method as described in any one of claims 1 to claim 4.

14. A computer-readable storage medium, It is characterized in that It includes computer program instructions. When the computer program instructions are executed by an electronic device, the electronic device executes the log synchronization method as claimed in claim 5 or claim 6.

Citation Information

Patent Citations

  • Log synchronization method and device, electronic equipment and storage medium

    CN118568166A

  • Memory database node copying method

    CN102609479A

  • Partition log queue synchronization management method and device

    CN104346373A

  • Data synchronizing method, device and system

    CN106817387A

  • Data writing method and device

    CN110737716A