Log synchronization method and device, electronic equipment and storage medium

By generating and using differential logs in the storage system of the database system for log synchronization, the problem of data inconsistency between the primary node and the backup node in the case of network jitter or high pressure is solved, and the stability and reliability of the database system are improved.

CN118568166APending Publication Date: 2024-08-30HUAWEI TECH CO LTD

Patent Information

Application Number
CN202310232100.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2023-02-28
Publication Date
2024-08-30

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 node and the backup node 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 and sending them to the standby node, the primary node is prevented from directly copying and transmitting the logs. Differential logs are used for synchronization to ensure that the primary node and the standby node access the same log, reducing the risk of data loss. .

Benefits of technology

It effectively avoids data inconsistencies between the primary node and the backup node, improves the stability and reliability of the database system, reduces the risk of data loss, and improves the computing performance of the primary node and the storage resource utilization of the backup node.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118568166A
    Figure CN118568166A
Patent Text Reader

Abstract

The invention provides a log synchronization method and device, electronic equipment and a storage medium, and belongs to the technical field of databases. The method comprises the steps that a storage system stores a log of a main node; and the storage system 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. According to the method, the log written by the main node is stored in the storage system, the main node and the standby node access the same log, and the main node does not need to copy and transmit the log, so that inconsistency generated in the log copying process can be avoided, and copying mode degradation caused by network jitter between the main node and the standby node can be avoided; and the risk of data loss is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] 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

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

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

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

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

[0006] 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 backup node, and the storage system, the method including:

[0007] The storage system stores the log of the master node, which indicates the operations that occurred on the master node;

[0008] 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.

[0009] The storage system may be a separate storage device or a storage array composed of multiple storage devices, wherein the storage device may be any storage device such as a network attached storage (NAS) or a storage area network (SAN). The log of the master node is used to record the operations occurring on the master node, and the differential log is the unsynchronized log of the standby node.

[0010] 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.

[0011] 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:

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

[0013] The first storage device and the master node belong to the same region, and the second storage device and the backup node belong to the same region. Belonging to can mean that the device is located 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. The log synchronization between the first storage device and the second storage device can be initiated by the first storage device or the second storage device.

[0014] 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 store the log of the master node in a timely manner, thereby improving the reliability and disaster recovery capability of the database system.

[0015] 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:

[0016] 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.

[0017] 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 thus improve the efficiency of log synchronization. The standby node can complete the log synchronization in time, which is beneficial to improving the reliability and disaster recovery capability of the database system.

[0018] Optionally, the method further comprises:

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

[0020] The relay log is used to store the differential log of the standby node. 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, and 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.

[0021] Optionally, the method further comprises:

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

[0023] 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 realizes 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.

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

[0025] The standby node receives the differential log and writes the differential log into the relay log stored on the standby node;

[0026] 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.

[0027] 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.

[0028] 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.

[0029] In a second aspect, a log synchronization device is provided, 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 at least one functional module, and the at least one functional module is used to execute the log synchronization method provided by the first aspect or any possible implementation method of the first aspect.

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

[0031] 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.

[0032] 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;

[0033] 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.

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

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

[0036] 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 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 first aspect or any possible implementation of the first aspect.

[0037] 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 primary node or the steps executed by the backup node in the log synchronization method provided in the first aspect or any possible implementation of the first aspect.

[0038] In an eighth aspect, a computer-readable storage medium is provided, the computer-readable storage medium comprising 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 a 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.

[0039] 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 primary node in the log synchronization method provided in the first aspect or any possible implementation method of the first aspect, or the steps executed by the backup node. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] Figure 1 It is a schematic diagram of the structure of a database system provided in an embodiment of the present application;

[0041] Figure 2 This is a flow chart of a log synchronization method provided by an embodiment of the present application;

[0042] Figure 3 is a schematic diagram of a log synchronization method provided in an embodiment of the present application;

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

[0044] Figure 5 This is a flow chart of a log synchronization method provided by an embodiment of the present application;

[0045] Figure 6 is a schematic diagram of a log synchronization method provided in an embodiment of the present application;

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

[0047] Figure 8 It is a structural block diagram of a log synchronization device provided in an embodiment of the present application;

[0048] Fig. 9 is a structural schematic diagram of a storage device provided in an embodiment of the present application;

[0049] Fig.10 is a schematic diagram of a storage system provided in an embodiment of the present application;

[0050] Fig.11 It is a schematic diagram of a possible implementation method of a storage system provided in an embodiment of the present application. DETAILED DESCRIPTION

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

[0052] First, the implementation environment of the embodiments of the present application is introduced.

[0053] Figure 1 Schematic diagram of the structure of a database system provided in the embodiment of the present application. Figure 1 As shown, the database system includes multiple master nodes 101, standby nodes 102 and storage system 103. Among them, the master node 101 provides data read-write (RW) services to the outside, that is, the client can read and write data in the database system through the master node, and the master node records the operations in the log (binlog); the standby node 102 provides data read (R) services to the outside, 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 data read and write services to the outside. 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. Among them, the storage system 103 includes at least one storage device.

[0054] Among them, the master node 101 and the standby node 102 can be independent physical servers, or a server cluster composed of multiple physical servers, or a cloud server that provides 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, CDN), 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.

[0055] Among them, the master node 101 and the standby node 102 can be connected to the storage system 103 by wired network or wireless network. In some embodiments, the wireless network or wired network uses standard communication technology and / or protocol. The network is usually the Internet, but it can also be any network, including but not limited to any combination of local area network (LAN), metropolitan area network (MAN), wide area network (WAN), mobile, wired or wireless network, private network or virtual private network. In some embodiments, the master node 101, the standby node 102 and the storage system 103 implement peer-to-peer (P2P) communication based on remote procedure call protocol (RPC). In some embodiments, the master node 101, the standby 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 through the network. In addition, conventional encryption technologies such as secure socket layer (SSL), transport layer security (TLS), virtual private network (VPN), Internet protocol security (IPsec), etc. can be used to encrypt all or some links. In other embodiments, customized and / or dedicated data communication technologies can be used to replace or supplement the above data communication technologies.

[0056] The implementation environment of the embodiment of the present application is introduced above. The following is a log synchronization method provided by the embodiment of the present application. Figure 1 The database system shown is executed, 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 of 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 into the relay log of the standby node to complete the log synchronization.

[0057] 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.

[0058] In the scenario where the master node and the standby node belong to the same availability zone (AZ), the master node and the standby node share a storage device. The relay log of the standby node can be stored in the shared storage device to save the storage resources of the standby node; the relay log of the standby node can also be stored locally on the device for easy reading, thereby improving the efficiency of log synchronization based on the relay log of the standby node.

[0059] In the scenario where the master node and the standby node do not belong to the same area, the master node and the standby node are each associated with a storage device in the storage system, and the node and the associated device belong to the same area. The 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 to can mean that the location of the device is in the area, or it can mean that the device has a binding relationship with the area, and the device provides services for the nodes in the area.

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

[0061] First, take the example that the master node and the standby node belong to the same region and the relay log of the standby node is stored in the storage system. Figure 2 is a flow chart of a log synchronization method provided by an embodiment of the present application, such as Figure 2 As shown, the method is executed by a database system, the database system includes a master node, a backup node and a storage system, and the method includes the following steps 201 to 206.

[0062] 201. The master node stores a log in a storage system, where the log indicates operations occurring at the master node.

[0063] The log is used to record the operations of changing the database table structure and modifying the table data on the master node. The log can be a binlog log or a write-ahead log, etc., which is not limited in the embodiments of the present application. 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.

[0064] 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 logs stored in the storage system. This process is that the master node mounts the logs to the storage system.

[0065] 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 realizes 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.

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

[0067] The log synchronization request carries the identifier of the standby node and the synchronized log position of the standby node. The synchronized log position, that is, the log position synchronized during the last log synchronization process, is used to indicate which part of the log has not been synchronized. The log synchronization request is used to request the storage system for the unsynchronized log, that is, the differential log of the standby node. The standby node starts the I / O thread and sends the log synchronization request to the storage system through the I / O thread.

[0068] In some embodiments, the backup node periodically or regularly sends a log synchronization request to the storage system, wherein 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.

[0069] In other embodiments, after an operation occurs, the master node actively 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 every time an operation occurs, thereby ensuring real-time synchronization between the master node and the standby node, and avoiding the standby node from sending a log synchronization request to the storage system when no operation occurs on the master node, thereby reducing invalid log synchronization operations on the standby node, thereby alleviating the pressure on the standby node and saving data transmission resources. The master node may also send a message to the standby node once 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.

[0070] 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 the differential log 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.

[0071] 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, where the differential log indicates the operations that have not been executed on the standby node.

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

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

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

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

[0076] Among them, the relay log of the standby node is used to store the differential log of the standby node. The standby node links the file system of the storage system to the file system of the standby node. The standby node can access the data stored in the storage system by accessing the file system of the standby node to read and write the relay log stored in the storage system. This process is that the standby node mounts the relay log to the storage system. After the standby node receives the differential log, the I / O thread of the standby node reads the differential log and performs a write operation on the differential log; the storage system writes the differential log to the relay log of the standby node stored in the storage system based on the write operation of the standby node on the differential log; the standby node records the log position synchronized this time as a reference position for the next log synchronization.

[0077] 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.

[0078] In some embodiments, after the standby node writes the differential log to the relay log, it 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 primary node, thereby achieving the purpose of synchronization between the primary and standby nodes.

[0079] 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.

[0080] Below through Figure 3 The process shown in the above steps 201 to 205 is described with an example. Figure 3 is a schematic diagram of a log synchronization method provided by an embodiment of the present application, such as Figure 3As shown, taking MySQL database as an example, a MySQL master database runs on the master node, a MySQL slave database runs 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 log synchronization service (binlog service). The standby node sends a log synchronization request to the storage system through the I / O thread to obtain the 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 the SQL thread, and replays the read differential log to synchronize the operations of the master node. It should be noted that the above Figure 3 The example of MySQL database is merely illustrative. 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.

[0081] 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 inconsistency generated during the log replication process, and avoid 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, and because 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 and the stability of the database system.

[0082] The following example uses the case where the master node and the standby node belong to the same region and the relay log of the standby node is stored locally on the device. Figure 4 is a flow chart of a log synchronization method provided by an embodiment of the present application, such as Figure 4 As shown, the method is executed by a database system, the database system includes a master node, a backup node and a storage system, and the method includes the following steps 401 to 406.

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

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

[0085] 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, where the differential log indicates the operations that have not been executed on the standby node.

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

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

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

[0089] 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, and similarities are not repeated here.

[0090] 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, which can avoid the inconsistency generated during the log replication process, and avoid the degradation of the replication method caused by the 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 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.

[0091] It should be noted that the above Figure 2 and Figure 4 The illustrated embodiments are introduced by taking a storage system to store relay logs and a standby node to store relay logs as examples. In some embodiments, both the standby node and the storage system store the relay log of the standby node. After receiving the differential log, the standby node 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, the reliability of the relay log storage can be guaranteed while ensuring that the standby node can complete data synchronization.

[0092] The following example is taken as an example where the primary node and the standby node do not belong to the same zone, and the relay log of the standby node is stored in the storage device associated with the standby node. Figure 5 is a flow chart of a log synchronization method provided by an embodiment of the present application, such as Figure 5As shown, the method is executed by a database system, the database system includes a master node, a backup node and a storage system, the storage system includes a first storage device and a second storage device, and the method includes the following steps 501 to 507.

[0093] 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.

[0094] The step 501 is the same as the above step 201 and will not be described in detail.

[0095] 502. The first storage device synchronizes the log of the primary node to the second storage device, where the second storage device and the backup node belong to the same region.

[0096] 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 time, 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 the 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, that is, to achieve dual-active master and backup nodes.

[0097] It should be noted that the above step 502 is explained by taking the first storage device initiating log synchronization as an example. 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, which can ensure that the differential log received by the backup node each time is the latest, thereby improving the effectiveness of log synchronization.

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

[0099] 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 primary node, where the differential log indicates the operations that have not been executed on the standby node.

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

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

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

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

[0104] Below through Figure 6 The process shown in the above steps 501 to 506 is described with an example. Figure 6 is a schematic diagram of a log synchronization method provided by an embodiment of the present application, such as Figure 6 As shown, a MySQL master library is running on the master node and a MySQL slave library is running on the standby node. The master node and the standby node belong to the same area as the first storage device and the second storage device, respectively. The master node writes the log (binlog) to the first storage device, and the log is synchronized between the first storage device and the second storage device. The second storage device can provide log synchronization service (binlog service). The standby node sends a log synchronization request to the second storage device through the I / O thread to obtain the differential log, and writes the obtained differential log to the relay log (relay log) in the second storage device. The standby node reads the differential log from the relay log through the SQL thread, and replays the read differential log to synchronize the operations of the master node. It should be noted that the above Figure 3 The example of MySQL database is merely illustrative. 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.

[0105] 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 storing the log to the storage device, avoid storage delay and data loss caused by long-distance data transmission, and can store the log of the master node in time. 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 time, which is conducive to improving the reliability and disaster recovery capability of the database system. In addition, since the relay log of the backup node is stored in the storage system, the storage resources of the backup node can be saved, and 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 and the stability of the database system.

[0106] The following example uses the case where the primary node and the standby node do not belong to the same region and the relay log of the standby node is stored locally on the device. Figure 7 is a flow chart of a log synchronization method provided by an embodiment of the present application, such as Figure 7 As shown, the method is executed by a database system, the database system includes a master node, a backup node and a storage system, the storage system includes a first storage device and a second storage device, and the method includes the following steps 701 to 707.

[0107] 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.

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

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

[0110] 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 primary node, where the differential log indicates the operations that have not been executed on the standby node.

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

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

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

[0114] 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, and similarities are not repeated here.

[0115] 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 storing the log to the storage device, avoid storage delay and data loss caused by long-distance data transmission, and can store the log of the master node in time, and 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, thereby improving the efficiency of log synchronization, and the standby node can complete the log synchronization in time, which is conducive to improving the reliability and disaster recovery capability of the database system. In addition, since the relay log of the standby node is stored in the standby node, the efficiency of the standby node reading the differential log from the relay log can be improved, thereby reducing the synchronization delay between the master and standby nodes and improving the efficiency of the master and standby node synchronization.

[0116] It should be noted that the above Figure 2 and Figure 4 The embodiment shown is described by taking the example that the master node and the backup node belong to the same area, that is, the master node and the backup node are networked in a single AZ master-slave mode. Figure 5 and Figure 7 The illustrated embodiment is illustrated by taking the case where the master node and the standby node belong to different regions as an example, 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 hybrid mode, that is, the master node and some standby nodes belong to the same region, and some standby nodes do not belong to the same region. 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 here.

[0117] Figure 8 It 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.

[0118] Storage module 801, used to store the log of the master node, which indicates the operation occurred in the master node;

[0119] The sending module 802 is used 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, where the differential log indicates the operations that have not been executed on the standby node.

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

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

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

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

[0124] A generation unit, used for generating a differential log based on the log synchronization request and the log;

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

[0126] Optionally, the device is also used for:

[0127] 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.

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

[0129] Store logs in a storage system.

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

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

[0132] The differential log is received, and the differential log is written into the relay log of the standby node stored in the storage system.

[0133] 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 by taking 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.

[0134] As an example of a software functional unit, the sending module 802 may include code running on a computing instance. Among them, the computing instance may include at least one of a physical host (computing device), a virtual machine, and a container. Further, the above-mentioned 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 (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 a data center or multiple data centers with close geographical locations. Among them, usually a region may include multiple AZs.

[0135] Similarly, multiple hosts / virtual machines / containers used to run the code can be distributed in the same virtual private cloud (VPC) or in multiple VPCs. Usually, a VPC is set up in a region. For cross-region communication between two VPCs in the same region and between VPCs in different regions, a communication gateway needs to be set up in each VPC to achieve interconnection between VPCs through the communication gateway.

[0136] As an example of a hardware functional unit, the sending module 802 may include at least one computing device, such as a server, etc. Alternatively, the sending module 802 may also be a device 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.

[0137] 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 computing devices such as servers, ASICs, PLDs, CPLDs, FPGAs, and GALs.

[0138] 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 in the above embodiment only uses the division of the above functional modules as an example 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 in the above embodiment belongs to the same concept as the corresponding method embodiment. The specific implementation process is detailed in the method embodiment, which will not be repeated here.

[0139] The present application also provides a storage device 900 . Fig. 9 is a schematic diagram of the structure of a storage device provided in an embodiment of the present application, such as Fig. 9 As shown, 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 through 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.

[0140] The bus 901 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig. 9 The bus 901 is represented by only one line, but it does not mean that there is only one bus or one type of bus. The bus 901 may include a path for transmitting information between various components of the storage device 900 (for example, the memory 903, the processor 902, and the communication interface 904).

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

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

[0143] 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.

[0144] Alternatively, 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.

[0145] 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.

[0146] The embodiment of the present application also provides a storage system. Fig.10 is a schematic diagram of a storage system provided in an embodiment of the present application, such as Fig.10 As shown, 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.

[0147] 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 may jointly execute instructions for executing the log synchronization method.

[0148] It should be noted that the memory 903 in different storage devices 900 in the storage system can store different instructions, which are respectively used for part of the functions of the log synchronization device. That is, 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.

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

[0150] In some possible implementations, one or more storage devices in the storage system may be connected via a network, which may be a wide area network or a local area network. Fig.11 A possible implementation is shown. Fig.11 is a schematic diagram of a possible implementation of a storage system provided in an embodiment of the present application, such as Fig.11 As shown, two storage devices 900 are connected via a network. Specifically, they are connected to the network via a communication interface in each storage device.

[0151] The present application also provides another storage system. The connection relationship between the storage devices in the storage system can be similarly referred to as Fig.10 or Fig.11 The difference is that the same instruction for executing the log synchronization method may be stored in the memory 903 in one or more storage devices 900 in the storage system.

[0152] 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 may jointly execute instructions for executing the log synchronization method.

[0153] It should be noted that the memory 903 in different storage devices 900 in the storage system can store different instructions, which are respectively used to execute part of the functions of the log synchronization device. That is, the instructions stored in the memory 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.

[0154] 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 primary node or the steps executed by the backup node in the log synchronization method provided in the above embodiment.

[0155] The present application implements a computer program product including instructions, which may be software or a program product including 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 performs the steps performed by the storage system, the steps performed by the master node, or the steps performed by the standby node in the log synchronization method provided in the above embodiment.

[0156] The embodiment of the present application provides a computer-readable storage medium, which can be any available medium that can be stored by a computing device or a data storage device such as a data center containing 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 hard disk). 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.

[0157] 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, stored data, displayed data, 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 relevant countries and regions. For example, the logs involved in this application are all obtained with full authorization.

[0158] Those of ordinary skill in the art will appreciate that the various method steps and units described in 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 the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Those of ordinary skill in the art can 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.

[0159] Those skilled in the art can clearly understand that, for the 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.

[0160] In the several embodiments provided in the present 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. There may be other division methods in actual implementation, 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 it can be an electrical, mechanical or other form of connection.

[0161] The unit described as a separate component may or may not be physically separated, and the component displayed as a unit may or may not be a physical unit, that is, it may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiment of the present application.

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

[0163] 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 to enable 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: U disk, mobile hard disk, read-only memory (ROM), random access memory (RAM), disk or optical disk, etc., various media that can store program codes.

[0164] In this application, the terms "first", "second", etc. are used to distinguish between identical or similar items with 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 the quantity and execution order limited. 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, the first storage device can be referred to as the second storage device, and similarly, the second storage device can be referred to as the first storage device. Both the first storage device and the second storage device can be storage devices, and in some cases, can be separate and different storage devices.

[0165] In this application, the term "at least one" means one or more, and the term "multiple" means two or more, for example, multiple standby nodes means two or more standby nodes. The terms "system" and "network" are often used interchangeably herein.

[0166] 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 [a stated condition or event] is detected" may be interpreted to mean "upon determining that ..." or "in response to determining that ..." or "upon detecting [a stated condition or event]" or "in response to detecting [a stated condition or event]," depending on the context.

[0167] The above description is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of various equivalent modifications or replacements within the technical scope disclosed in the present application, and these modifications or replacements should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0168] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part 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 process or function in accordance with the embodiment of the present application is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices.

[0169] 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 by wired or wireless means. 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 integrated therein. The available medium may be a magnetic medium (e.g., a floppy disk, a hard disk, a magnetic tape), an optical medium (e.g., a digital video disc (DVD), or a semiconductor medium (e.g., a solid-state drive)), etc.

[0170] A person skilled in the art will understand that all or part of the steps to implement the above embodiments may be accomplished by hardware or by instructing related hardware through a program, 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.

[0171] 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, a person of ordinary skill in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features thereof may be replaced by equivalents. 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, 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, 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, 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, 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, characterized in that The method further comprises: The master node stores the log in the storage system.

6. The method according to claim 1, 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, 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, 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, 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, characterized in that: The electronic device comprises a processor and a memory; The processor is used to execute instructions stored in the memory so that the electronic device executes the log synchronization method as described in claim 5 or claim 6.

11. A computer program product comprising instructions, 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, 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, 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, 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

  • Metadata information synchronization method and system of distributed file system

    CN112579550A

  • MySQL database master-slave synchronization method and device, equipment and medium

    CN115292408A

  • Database system management method, database system, database device, and backup program

    US20070233753A1

  • Database copying program and database copying device

    WO2004090726A1

Cited By

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

    EP4664316A1

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

    WO2024178935A1

  • Data synchronization method and system, and device, storage medium and computer program product

    WO2026228686A1