Data recovery method, data storage method, and distributed system
By selecting an appropriate starting recovery location and asynchronous write mechanism in a distributed system with storage and compute separation, the data recovery process is optimized, solving the problem of excessively long data recovery time and improving database availability.
Patent Information
- Application Number
- PCT/CN2025/089652
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-07-01
- Filing Date
- 2025-04-17
- Publication Date
- 2026-01-08
AI Technical Summary
In distributed systems with separate storage and compute, data recovery takes a long time, affecting business availability. In existing technologies, data recovery speed is limited by the persistence speed of storage nodes, resulting in excessively long recovery times.
By selecting an appropriate starting recovery position in the compute node cluster, the number of log records read and data pages recovered is reduced. An asynchronous write mechanism between memory nodes and storage nodes is adopted, and a later position is selected as the starting recovery position based on the log sequence number, thus optimizing the data recovery process.
It shortened the data recovery time, reduced the impact of data recovery on business, and improved the availability of the database.
Smart Images

Figure CN2025089652_08012026_PF_FP_ABST
Abstract
Description
Data recovery method, data storage method and distributed system
[0001] The present application claims priority to the Chinese patent application No. 202410885579.8, filed on July 1, 2024, and entitled "Data recovery method, data storage method and distributed system", the content of which is incorporated herein by reference in its entirety. TECHNICAL FIELD
[0002] The present application relates to the technical field of database, and in particular to a data recovery method, a data storage method and a distributed system. BACKGROUND
[0003] The distributed system of separation of storage and calculation includes a cluster of calculation nodes and a cluster of storage nodes deployed separately, wherein the cluster of calculation nodes can include a plurality of calculation nodes, and the cluster of storage nodes can include a plurality of storage nodes. The plurality of calculation nodes are readable and writable, and the plurality of calculation nodes share the storage resources of the plurality of storage nodes. After deploying a database in such a separation of storage and calculation system, in order to guarantee atomicity and durability, the calculation nodes can generate log records for recording corresponding write operations in a write ahead log (WAL) when performing write operations on data pages, and cache the modified data pages in the calculation nodes. Subsequently, before persistently storing the cached modified data pages to the cluster of storage nodes, the log records are first persistently stored to the cluster of storage nodes. In this way, when the calculation nodes fail subsequently, the modified data pages cached in the calculation nodes can be recovered by reading and replaying the log records in the cluster of storage nodes. The more log records read, the more data pages recovered, the longer the data recovery time, and the greater the impact on the business. Therefore, it is urgent to provide a data recovery method to reduce the impact of data recovery on the business and improve the availability of the database. SUMMARY
[0004] The present application provides a data recovery method, a data storage method and a distributed system, which can shorten the data recovery time, reduce the impact of data recovery on the business, and improve the availability of the database.
[0005] To achieve the above-mentioned purpose, the present application adopts the following technical solutions:
[0006] In a first aspect, a data recovery method is provided, which is applied to a first computing node in a distributed system, the distributed system comprising a computing node cluster and a memory node cluster, the computing node cluster comprising the first computing node and a second computing node, the memory node cluster comprising a plurality of memory nodes, the second computing node being abnormal and the plurality of memory nodes being normal, the method comprising: obtaining a first record position and a second record position of the second computing node, the first record position being a position of a first log record in which a corresponding dirty data page is not written in a log record of the memory node cluster, and the second record position being a position of a first log record in which the corresponding dirty data page is not written in a log record of the storage node cluster; determining a starting recovery position, the starting recovery position being one of the first record position and the second record position corresponding to a log record with a larger log sequence number (LSN), the LSN increasing with an increase of the log record; and performing data recovery from the starting recovery position.
[0007] In the present application, the first record position is a position of a first log record in which a corresponding dirty data page is not written in a log record of the memory node cluster, that is, log records before the first record position correspond to dirty data pages that have been written in the memory node cluster, and the second record position is a position of a first log record in which a corresponding dirty data page is not written in a log record of the storage node cluster, that is, log records before the second record position correspond to dirty data pages that have been written in the storage node cluster. On this basis, in the case that the second computing node in the computing node cluster is abnormal and each memory node in the memory node cluster is normal, the first computing node can select one of the two record positions corresponding to a log record with a larger LSN as a starting recovery position. Since the LSN increases with an increase of the log record, the present application actually selects a position of a later log record from the two record positions as a starting recovery position to perform data recovery, so as to reduce the number of log records to be read and the number of data pages to be recovered as much as possible, thereby shortening the data recovery time, reducing the impact of data recovery on business, and improving the availability of the database.
[0008] It should be noted that in the present application, the computing node cluster can communicate with the memory node cluster and the storage node cluster respectively through a network. Among them, the computing node cluster and the memory node cluster can both be distributed clusters. The memory node cluster is used to provide a shared memory pool to the computing node cluster. The computing nodes in the computing node cluster can asynchronously write the dirty data pages cached by themselves to the memory node cluster and the storage node cluster. Based on this, the starting recovery position will depend on the speed at which the computing nodes write data pages to the memory node cluster and the storage node cluster respectively. In the case where the second computing node writes data pages to the memory node cluster at a faster speed, the LSN of the log record corresponding to the first record position will be greater than the LSN of the log record corresponding to the second record position, that is, the first record position will be located after the second record position. On this basis, taking the first record position as the starting recovery position, the data pages that have been written to the memory node cluster but have not been written to the storage node cluster do not need to be recovered again, so that the number of log records required to be read and the number of data pages required to be recovered during data recovery can be reduced, thereby shortening the data recovery time, reducing the impact of data recovery on business, and improving the availability of the database. In the case where the second computing node writes data pages to the storage node cluster at a faster speed, the LSN of the log record corresponding to the first record position will be less than the LSN of the log record corresponding to the second record position, that is, the first record position will be located before the second record position. On this basis, taking the second record position as the starting recovery position, the minimum number of log records can still be read for data recovery. As can be seen, in the present application, the later position of the first record position and the second record position is always taken as the starting recovery position, so that the minimum number of log records can be read for data recovery in various scenarios, thereby shortening the data recovery time, reducing the impact of data recovery on business, and improving the availability of the database.
[0009] In addition, it should be noted that in the present application, the second record position is determined according to the last data page successfully written by the second computing node to the storage node cluster. The first record position is determined according to the last data page successfully synchronized by the second computing node to the memory node cluster. As can be seen, the second computing node writes data pages to the memory node cluster and the storage node cluster asynchronously, so that the second record position only depends on the speed of the second computing node writing data pages to the storage node cluster, and is irrelevant to the memory node cluster. On this basis, the advancement of the second record position will be independent of the advancement of the first record position, and will not be affected by the advancement speed of the first record position. For example, when the network communication between the second computing node and the memory node cluster is congested, it will only affect the advancement of the first record position, and will not affect the advancement of the second record position. In this case, once the second record position advances to the first record position, the first computing node can use the second record position as a starting recovery position to read log records for data recovery.
[0010] Optionally, the storage node cluster stores a log file of the second computing node, and the implementation process of the data recovery from the starting recovery position can include: reading each log record in sequence from the starting recovery position in the log file; based on each read log record, obtaining a dirty data page corresponding to the corresponding log record.
[0011] Optionally, the log record includes an identifier of a data page operated by a write operation; and the implementation process of obtaining a dirty data page corresponding to each read log record can include: based on the identifier of the first data page in the first log record, searching for the first data page from the memory node cluster, and if the first data page is not found in the memory node cluster, searching for the first data page from the storage node cluster; based on the first log record, performing a redo operation on the found first data page to obtain a dirty data page corresponding to the first log record.
[0012] In the present application, since the computing node will synchronize the dirty data page to the memory node cluster for caching after performing the write operation on the data page based on the write request, the memory node cluster can cache the first data page modified based on other log records before the starting recovery position. Considering that the speed of reading the data page from the memory node cluster is usually faster than that of reading the data page from the storage node cluster, the first computing node can first search for the first data page from the memory node cluster, and if the first data page is found in the memory node cluster, there is no need to search for the first data page from the storage node cluster, so that the time required is shorter compared with reading the data page from the storage node cluster. Of course, if the first data page is not found in the memory node cluster, the first computing node can read the first data page from the storage node cluster.
[0013] Optionally, the memory node cluster stores a page directory of the data page, and the page directory includes an identifier of the home computing node of the data page. On this basis, in the case where the starting recovery position is the first record position, at least one target log record from the second record position to the first record position can be read; a page directory of at least one target data page corresponding to the at least one target log record is read from the memory node cluster, and the page directory includes an identifier of the home computing node of the corresponding data page; and the home computing node of the at least one target data page is controlled to write the at least one target data page after operation to the storage node cluster.
[0014] In the present application, after the data recovery is completed through the log record after the first record position, since the data page between the first record position and the second record position has been synchronized to the memory node cluster but has not been persisted to the storage node cluster, the data page corresponding to the log record between the first record position and the second record position can also be persisted and stored to the storage node cluster, thereby improving the reliability of this part of data page.
[0015] In a second aspect, a data recovery method is provided, which is applied to a first computing node in a distributed system, the distributed system comprising a computing node cluster and a memory node cluster, the computing node cluster comprising the first computing node, the memory node cluster storing a page directory of a dirty data page in the computing node cluster, the page directory comprising an identifier of a home computing node of the dirty data page, the memory node cluster comprising a first memory node and a second memory node, and the first memory node being abnormal, the method comprising: detecting whether a page directory of a plurality of target dirty data pages cached by itself is stored in the first memory node, the target dirty data page being a dirty data page whose home computing node is the first computing node; and if a page directory of a first target dirty data page in the plurality of target dirty data pages is stored in the first memory node, sending a first message to the second memory node, the first message being used to instruct the second memory node to create the page directory of the first target dirty data page.
[0016] In the present application, for the dirty data pages cached in the computing nodes, the page directories of the data pages are remotely stored in the memory node cluster. When the memory node is abnormal, since the data pages corresponding to the page directories stored in the memory node all exist in the computing nodes, it is not necessary to read the log records to recover the data pages, but only to recover the lost page directories in the abnormal memory node according to the data pages possessed by the computing nodes, so that the recovery speed is faster, the recovery time is shorter, and the service provided to the outside can be recovered faster.
[0017] Optionally, the method further comprises: sending the second message to other computing nodes in the computing node cluster, the second message being used to instruct the page directory stored in the first memory node.
[0018] Optionally, the memory node cluster stores dirty data pages written by each of the computing node cluster, the computing node cluster further includes a second computing node and a third computing node, the second computing node corresponds to a first record position and a second record position, the first record position is a position of a first log record in a log record corresponding to a dirty data page not written to the memory node cluster, and the second record position is a position of a first log record in a log record corresponding to a dirty data page not written to the storage node cluster; the third computing node stores a dirty page identifier list of the second computing node, the dirty page identifier list includes an identifier of a dirty data page cached in the second computing node if a distance between the first record position and the second record position is greater than a first threshold; the method further includes: in the case of an exception of the second computing node, the first computing node can start data recovery from the second record position and read the dirty page identifier list from the third computing node; if an access request is received and an identifier of a second data page to be accessed by the access request exists in the dirty page identifier list, the second data page is searched in the currently recovered data page; if the second data page is not found, a log record corresponding to the second data page is obtained, and the second data page is recovered based on the log record corresponding to the second data page; and the second data page is accessed based on the access request.
[0019] Optionally, if the identifier of the second data page accessed by the access request does not exist in the dirty page identifier list, the second data page is obtained from the memory node cluster or the storage node cluster based on the identifier of the second data page, and an access operation is performed on the second data page based on the access request.
[0020] In the present application, in the case that the distance between the first record position and the second record position is greater than the first threshold, that is, in the case that the amount of log records between the first record position and the second record position is too large, the second computing node can synchronize a dirty page identifier list including the identifiers of the dirty data pages cached by itself to the third computing node for caching in advance. On this basis, in the case that both the second computing node and the first memory node are abnormal, since the data pages are to be recovered from the second record position, and the amount of log data between the second record position and the first record position is huge, more log records need to be read and more data pages need to be recovered, therefore, in order to ensure that the business can be provided as soon as possible during the data recovery process, the first computing node can read the dirty page identifier list from the third computing node. In this way, during the data recovery process, if the identifier of the data page accessed by the received access request belongs to the dirty page identifier list and the data page has not been recovered, the first computing node can recover the data page based on the log record corresponding to the data page, so as to provide the access result to the outside, if the identifier of the data page accessed by the access request is not in the dirty page identifier list, the data page can be directly read from the storage node cluster or the memory node cluster to provide the access result to the outside, further accelerating the business recovery speed in the case that both the computing node and the memory node are abnormal when the amount of log records between the first record position and the second record position is too large.
[0021] In a third aspect, a data storage method is provided, applied to a second computing node in a computing node cluster, the second computing node caches dirty data pages, and the method comprises: in the case that a write condition is met, writing the dirty data pages to a memory node cluster and a storage node cluster respectively in the order of the log sequence numbers (LSNs) of the log records corresponding to the cached dirty data pages from small to large, the LSNs increasing with the increase of the log records; after stopping writing the dirty data pages to the memory node cluster and the storage node cluster, taking the position of the next log record of the log record corresponding to the last dirty data page written to the memory node cluster as a first record position, and taking the position of the next log record of the log record corresponding to the last dirty data page written to the storage node cluster as a second record position.
[0022] In the present application, the second computing node can write the dirty data pages to the memory node cluster and the storage node cluster respectively in the order of the LSNs of the log records corresponding to the dirty data pages in the cache from small to large. Since the LSN increases with the increase of the log records, the second computing node actually writes the dirty data pages corresponding to the log records in the log file from front to back to the memory node cluster and the storage node cluster respectively. On this basis, after stopping writing the dirty data pages to the memory node cluster and the storage node cluster, the position of the next log record of the log record corresponding to the last dirty data page written to the memory node cluster can be taken as the first record position, so that the dirty data pages corresponding to the log records before the first record position in the log file have all been written to the memory node cluster. The position of the next log record of the log record corresponding to the last dirty data page written to the storage node cluster is taken as the second record position. In this way, the dirty data pages corresponding to the log records before the second record position in the log file have all been written to the storage node cluster. On this basis, when the second computing node abnormally later, one of the two record positions is selected as the starting recovery position, and the data pages are recovered from the starting recovery position, the number of log records required to be read and the number of data pages required to be recovered can be maximized, thereby shortening the recovery time, reducing the impact of data recovery on business, and improving the availability of the database.
[0023] Optionally, the implementation process of writing the dirty data pages to the memory node cluster and the storage node cluster respectively in the order of the LSNs of the log records corresponding to the dirty data pages in the cache can include: starting from the head of the dirty page queue of the second computing node, sequentially writing the dirty data pages in the dirty page queue to the storage node cluster by a first process, wherein the dirty data pages are arranged in the order of the LSNs of the corresponding log records from small to large from the head to the tail of the dirty page queue; starting from the next data page of the last data page written to the memory node cluster in the dirty page queue, sequentially writing the data pages in the dirty page queue to the memory node cluster by a second process.
[0024] Optionally, the method further includes: after stopping writing the dirty data pages to the memory node cluster and the storage node cluster, deleting the dirty data pages in the dirty page queue that have been written to the storage node cluster.
[0025] In the present application, for the dirty data pages that have been persisted to the storage node cluster, the computing node can delete the corresponding data pages. For the dirty data pages written to the memory node cluster, since these dirty data pages may not have been persisted to the storage node cluster, they can continue to be cached in the computing node.
[0026] Optionally, the cluster of computing nodes further comprises a third computing node, and the method further comprises: in a case where a distance between the first recording position and the second recording position is greater than a first threshold, caching a dirty page identification list into the third computing node, the dirty page identification list comprising an identification of a dirty data page cached in the second computing node.
[0027] In a fourth aspect, a data recovery apparatus is provided, the data recovery apparatus comprising at least one module configured to perform the data recovery method according to the first aspect or the second aspect.
[0028] In a fifth aspect, a data storage apparatus is provided, the data storage apparatus comprising at least one module configured to perform the data storage method according to the third aspect.
[0029] In a sixth aspect, a computer device is provided, the computer device comprising a processor configured to execute at least one program instruction or code stored in a memory to implement the data recovery method according to the first aspect or the second aspect or the data storage method according to the third aspect.
[0030] In a seventh aspect, a distributed system is provided, the distributed system comprising a cluster of computing nodes and a cluster of memory nodes, the cluster of computing nodes being in communication with the cluster of memory nodes via a network, the cluster of computing nodes comprising a first computing node and a second computing node, the cluster of memory nodes comprising a first memory node, the second computing node being configured to perform the data storage method according to the third aspect, the first computing node being configured to perform the data recovery method according to the first aspect in a case where the second computing node is abnormal and each memory node in the cluster of memory nodes is normal, the first computing node being configured to perform the data recovery method according to the second aspect in a case where the first memory node is abnormal.
[0031] Optionally, the cluster of computing nodes can be a distributed cluster, and the cluster of memory nodes can also be a distributed cluster.
[0032] In an eighth aspect, a computer-readable storage medium is provided, the computer-readable storage medium storing instructions, when the instructions are executed on a computer device, causing the computer device to perform the data recovery method according to the first aspect or the second aspect or to perform the data storage method according to the third aspect.
[0033] In a ninth aspect, a computer program product is provided, the computer program product comprising instructions, when the computer program product is executed on a computer device, causing the computer device to perform the data recovery method according to the first aspect or the second aspect or to perform the data storage method according to the third aspect.
[0034] The technical effects obtained by the fourth aspect to the ninth aspect are similar to the technical effects obtained by the corresponding technical means in the first aspect, the second aspect and the third aspect, and will not be described here again. BRIEF DESCRIPTION OF DRAWINGS
[0035] FIG. 1 is a structural schematic diagram of a distributed system provided by an embodiment of the present application;
[0036] FIG. 2 is a distribution schematic diagram of data involved in a data recovery method provided by an embodiment of the present application in a distributed system;
[0037] FIG. 3 is a flowchart of a process in which a computing node writes a data page to a memory node cluster and a storage node cluster provided by an embodiment of the present application;
[0038] FIG. 4 is a schematic diagram of a process in which a memory node manages a data page cached by itself provided by an embodiment of the present application;
[0039] FIG. 5 is a schematic diagram of a process in which a computing node writes a data page to a memory node cluster and a storage node cluster provided by an embodiment of the present application;
[0040] FIG. 6 is a schematic diagram of a process in which a computing node preloads a log record from a storage node cluster provided by an embodiment of the present application;
[0041] FIG. 7 is a flowchart of a data recovery method provided by an embodiment of the present application;
[0042] FIG. 8 is a schematic diagram of a process of recovering a data page in an abnormal computing node provided by an embodiment of the present application;
[0043] FIG. 9 is a flowchart of another data recovery method provided by an embodiment of the present application;
[0044] FIG. 10 is a schematic diagram of a process of recovering a page directory in an abnormal memory node provided by an embodiment of the present application;
[0045] FIG. 11 is a structural schematic diagram of a data recovery apparatus provided by an embodiment of the present application;
[0046] FIG. 12 is a structural schematic diagram of another data recovery apparatus provided by an embodiment of the present application;
[0047] FIG. 13 is a structural schematic diagram of a data storage apparatus provided by an embodiment of the present application. DETAILED DESCRIPTION
[0048] To make the purposes, technical solutions and advantages of the embodiments of the present application clearer, the embodiments of the present application will be further described in detail below with reference to the drawings.
[0049] Before the embodiments of the present application are explained in detail, the application scenarios involved in the embodiments of the present application are introduced.
[0050] The fault recovery time is very important for a database. In a distributed system in which a database is deployed under a current share everything architecture, the fault recovery time of a computing node includes three parts: a fault detection time, a fault cutting time and a data recovery time. The fault detection time refers to a time required for detecting whether the computing node is faulty. The fault cutting time refers to a time required for cutting off the connection between the faulty computing node and a client and / or cutting off the writing of data to a storage node cluster after the computing node is detected to be faulty. The data recovery time refers to a time required for reading log records in a WAL of the faulty computing node and replaying the log records to recover data pages. Among the three parts, except for the fault detection time, the longest is the data recovery time, and the length of the data recovery time will directly affect the business.
[0051] Currently, in some related technologies, a disk checkpoint mechanism can be used for data recovery. Specifically, a computing node can perform a write operation on a data page according to a write request, and generate a corresponding log record in a write ahead log (WAL) to record the corresponding write operation. The computing node can persistently store the newly added log record in the WAL to a storage node cluster in a timely manner. Then, the computing node starts a disk flushing period, and in the disk flushing period, the computing node sequentially persistently stores the dirty data pages modified by the write operations recorded by the log records to the storage node cluster in the order of the arrangement of the log records, and records the position of the log record corresponding to the next data page of the last successfully stored dirty data page in the storage node cluster at the end of the disk flushing period. The position of the log record can be referred to as a disk checkpoint. As can be seen, the dirty data pages corresponding to the log records before the disk checkpoint have been persistently stored to the storage node cluster, and the dirty data pages corresponding to the log records after the disk checkpoint are buffered in the computing node and have not been persistently stored to the storage node cluster. On this basis, since the speed of persistently storing the log records by the computing node is much faster than the speed of persistently storing the dirty data pages, when the computing node is abnormal, the log records after the disk checkpoint can be read from the storage node cluster, and the buffered dirty data pages in the abnormal computing node can be recovered by replaying the log records.
[0052] From the above data recovery method, the data recovery time in the computing node depends on the disk checkpoint, in other words, the data recovery speed in the computing node depends on the speed of the computing node persisting the data page to the storage node cluster, the slower the persistence speed is, the more log records needed to be read from the storage node cluster during the data recovery, the more data pages needed to be recovered, the longer the recovery time is, and the greater the impact on the business is.
[0053] In view of the problems in the above related technologies, the embodiment of the present application provides a data recovery method, in which, in the case that the second computing node in the computing node cluster is abnormal, the first computing node can obtain the first record position and the second record position of the second computing node. The first record position is the position of the first log record corresponding to the dirty data page which has not been written into the memory node cluster, that is, the dirty data pages corresponding to the log records before the first record position have been written into the memory node cluster by the second computing node, and the second record position is the position of the first log record corresponding to the dirty data page which has not been written into the storage node cluster, that is, the dirty data pages corresponding to the log records before the second record position have been written into the storage node cluster by the second computing node. Based on this, the first computing node can select one with a larger LSN of the corresponding log record from the two record positions as the starting recovery position. Since the LSN increases with the increase of the log record, the embodiment of the present application actually selects the position of the later log record from the two record positions as the starting recovery position, and starts data recovery from the log record at the starting recovery position. In other words, the starting recovery position in the embodiment of the present application depends on the speed of the computing node writing the data page into the storage node cluster and the memory node cluster. In the case that the second computing node writes the data page into the memory node cluster at a faster speed, the first record position will be located after the second record position, and on this basis, taking the first record position as the starting recovery position, the data page which has been written into the memory node cluster but has not been written into the storage node cluster does not need to be recovered, so that the number of log records needed to be read during data recovery and the number of data pages needed to be recovered can be reduced, thereby shortening the data recovery time, reducing the impact of data recovery on the business, and improving the availability of the database. In the case that the second computing node writes the data page into the storage node cluster at a faster speed, the first record position will be located before the second record position. On this basis, taking the second record position as the starting recovery position, the minimum log records can still be read for data recovery. As can be seen, the data recovery method provided by the present application can maximize the reduction of the number of log records needed to be read and the number of data pages needed to be recovered, thereby shortening the data recovery time, reducing the impact of data recovery on the business, and improving the availability of the database.
[0054] Next, the distributed system involved in the data recovery method and the data storage method provided by the embodiments of the present application is introduced.
[0055] FIG. 1 is a structural schematic diagram of a distributed system provided by an embodiment of the present application. As shown in FIG. 1, the distributed system can include a computing node cluster 10, a memory node cluster 11 and a storage node cluster 12. The computing node cluster 10 can communicate with the memory node cluster 11 and the storage node cluster 12 through a network respectively.
[0056] For example, referring to FIG. 1, the computing node cluster 10 can be a distributed cluster, and the computing node cluster 10 can include a plurality of computing nodes 100, three of which are shown in FIG. 1, but this does not constitute a limitation on the number of computing nodes 100. Each computing node 100 can provide services to the outside at the same time, and each computing node 100 can communicate with each other. The computing node 100 can be a computing device, such as a server, a desktop computer or a controller of a storage array, etc. Alternatively, the computing node 100 can also be a virtual instance deployed on a physical server, such as a virtual machine, a container, etc. Specifically, on the hardware, as shown in FIG. 1, the computing node 100 at least includes a processor 101, a memory 102 and a network card 103. The processor 101 is a central processing unit (CPU) for processing data access requests from the outside of the computing node 100 or requests generated inside the computing node 100. For example, when the processor 101 receives a write request sent by an application client, the processor 101 performs write operations including adding data, modifying data, deleting data, etc. on a data page according to the write request, and temporarily saves the dirty data page in the memory 102. When certain conditions are met, the processor 101 can send the dirty data page stored in the memory 102 to the memory node cluster 11 for caching, and also can send the dirty data page stored in the memory 102 to the storage node cluster 12 for persistent storage. In addition, the processor 101 is also used for computing or processing data, such as metadata management, deduplication, data compression, virtual storage space and address translation, etc. Only one processor 101 is shown in FIG. 1, but in actual applications, the number of processors 101 is often more than one, and one processor 101 can have one or more CPU cores. The number of processors and the number of CPU cores are not limited in the embodiments.
[0057] The memory 102 refers to an internal memory that exchanges data directly with the processor. The memory 102 can read and write data at any time and at a high speed, and is used as a temporary data storage for an operating system or other programs that are running. In the embodiments of the present application, the memory 102 can cache dirty data pages and data pages read from other computing nodes. In addition, the memory 102 can also store computer programs. The processor 101 can execute the computer programs to implement the data storage method described in the embodiments below. In addition, the processor 101 can also execute the computer programs to implement the data recovery method described in the embodiments below. Specifically, the memory can include at least one memory, for example, the memory can be a random access memory (RAM) or a read only memory (ROM). For example, the RAM can be a dynamic random access memory (DRAM) or a storage class memory (SCM). The DRAM is a semiconductor memory, like most RAMs, and is a kind of volatile memory device. The SCM is a composite storage technology that combines the characteristics of traditional storage devices and memories. The SCM can provide faster read and write speeds than hard disks, but the access speed is slower than the DRAM, and the cost is also cheaper than the DRAM. However, the DRAM and the SCM are only exemplary in the embodiments, and the memory can also include other random access memories, such as static random access memories (SRAM) and the like. For the read only memory, for example, it can be a programmable read only memory (PROM), an erasable programmable read only memory (EPROM), and the like. In addition, the memory 102 can also be a dual in-line memory module (DIMM), i.e., a module composed of DRAM, and can also be a solid state disk (SSD). In practical applications, the computing node 100 can be configured with multiple memories 102 and different types of memories 102. The embodiments do not limit the number and type of the memory 102. In addition, the memory 102 can be configured to have a power retention function. The power retention function refers to that when the system is powered off and then powered on again, the data stored in the memory 102 will not be lost. The memory with the power retention function is called a non-volatile memory.
[0058] The network card 103 is configured to communicate with the memory node cluster 11 and the storage node cluster 12. For example, when the total amount of data in the memory 102 reaches a certain threshold, the computing node 100 can send a request to the storage node cluster 12 through the network card 103 to perform persistent storage on the data. In addition, the computing node 100 can further include a bus for communication between the components inside the computing node 100. Functionally, since the main function of the computing node 100 in FIG. 1 is to perform computing services, when storing data, the computing node 100 can use remote memory to achieve persistent storage, and thus has less local memory than a conventional server, thereby achieving cost and space savings. However, this does not mean that the computing node 100 cannot have local memory. In actual implementation, the computing node 100 can also be internally provided with a small amount of hard disk or externally connected with a small amount of hard disk.
[0059] The memory node cluster 11 can also be a distributed cluster. The memory node cluster 11 can include a plurality of memory nodes 110, and three memory nodes 110 are shown in FIG. 1, but this does not constitute a limitation on the number of memory nodes 110. In the embodiment of the present application, any computing node 100 can access the memory nodes 110 through a network. The plurality of memory nodes 110 in the memory node cluster 11 are configured to provide a remote memory pool for the computing node cluster 10. Based on this, the memory node 110 mainly refers to a node for providing memory resources. For example, the memory node can be a server, a desktop computer or other computer device with a large memory space. In hardware, for example, as shown in FIG. 1, the memory node 110 can include a processor 111, a memory 112 and a network card 113. Compared with the computing node 100, the processor 111 of the memory node 110 can have weaker computing capability, but the memory 112 can have larger space. Specifically, the processor 111 of the memory node 110 can store the dirty data page sent by the computing node 100 in the memory 112. In addition, in the embodiment of the present application, when the processor 111 of the memory node 110 receives a message for indicating creation of a page directory from the computing node 100, the processor 111 of the memory node 110 is configured to create a page directory for the dirty data page cached in the memory 102 of the computing node 100, and store the page directory in the memory 112. The page directory is configured to record the home computing node of the data page. The home computing node of the data page refers to the computing node that owns the data page. When a certain computing node 100 wants to access a certain data page, the page directory of the corresponding data page can be queried from the memory node 110 to determine the home computing node of the data page, and then the data page is read from the home computing node of the data page. It should be noted that the home computing node of the data page can modify the content of the data page, that is, the write operation can be performed on the data page, and other computing nodes can read the data page but cannot modify the data page.
[0060] The network card 113 is used to communicate with the computing node 100. For example, the network card 113 can be used to receive the dirty data page sent by the computing node 100 and cache the dirty data page into the memory 112.
[0061] The storage node cluster 12 can include a plurality of storage nodes 120 (three storage nodes 120 are shown in FIG. 1, but not limited to three storage nodes 120). Any one of the computing nodes 100 in the computing node cluster 10 can access the storage nodes 120 through a network. Referring to FIG. 1, the storage node 120 can include one or more control units 121, a network card 122, and a plurality of hard disks 123. The network card 122 is used to communicate with the computing node 100. The hard disk 123 is used to store data and can be a magnetic disk or other types of storage media, such as a solid state disk or a shingled magnetic recording hard disk, etc. The control unit 121 is used to write data into the hard disk 123 or read data from the hard disk 105 according to the read / write data request sent by the computing node 100. In the process of reading and writing data, the control unit 121 needs to convert the address carried in the read / write data request into an address that can be recognized by the hard disk. As can be seen, the control unit 121 also has some simple computing functions.
[0062] In actual applications, the control unit 121 can have various forms. In one case, the control unit 121 includes a CPU and a memory. The CPU is used to perform address conversion and read / write data operations. The memory is used to temporarily store data to be written into the hard disk 123 or data read from the hard disk 123 to be sent to the computing node 100. In another case, the control unit 121 is a programmable electronic component, such as a data processing unit (DPU). Alternatively, the control unit 121 can also be a graphics processing unit (GPU), an embedded neural-network processing unit (NPU), etc.
[0063] In another embodiment, the functions of the control unit 121 can be offloaded to the network card 122. In other words, the storage node 120 does not have a control unit 121 inside, but the data reading and writing, address conversion, and other computing functions are completed by the network card 122. At this time, the network card 122 is a smart network card and includes a CPU and a memory. The CPU is used to perform address conversion and read / write data operations. The memory is used to temporarily store data to be written into the hard disk 123 or data read from the hard disk 123 to be sent to the computing node 100. Similarly, the CPU can also be replaced by a DPU, a GPU, an NPU, etc.
[0064] Based on the distributed system introduced above, referring to FIG. 2, the memories of the plurality of computing nodes in the computing node cluster form a distributed cache pool 20, and the memories of the plurality of memory nodes in the memory node cluster form a remote distributed cache pool 21.
[0065] In the embodiment of the present application, a database can be deployed in the distributed system. Each computing node in the computing node cluster can provide data access services such as adding, deleting, modifying, and querying to an upper-layer application client. On this basis, when the computing node receives a write request requesting to perform an adding, deleting, or modifying operation on a data page, the computing node can perform a corresponding write operation on the data page in a WAL manner. In this way, referring to FIG. 2, the computing node cluster can store log records for recording each write operation. For the log records stored in the computing node cluster, the computing node cluster can store the log records to the memory node cluster in a persistent manner according to certain rules.
[0066] The cache pool 20 can be used to cache dirty data pages obtained after the computing node modifies the data pages based on the write request. After a trigger condition is met, the computing node can synchronize the dirty data pages owned by the computing node in the cache pool 20 to the cache pool 21 for remote caching, and persist the dirty data pages owned by the computing node in the cache pool 20 to the memory node cluster, where the dirty data pages owned by the computing node refer to dirty data pages belonging to the computing node. The computing node determines a first record position of a log record of a next data page of a last successfully synchronized data page when stopping synchronization to the cache pool 21, which is also called a memory checkpoint. The computing node determines a second record position of a log record of a next data page of a last successfully persisted data page when stopping persistence to the memory node cluster, which is also called a disk checkpoint. Then, the computing node can write the memory checkpoint and the disk checkpoint to the memory node cluster.
[0067] In addition, the memory node cluster is also used to store a page directory (PD) of the data pages in the cache pool 20, where the page directory is used to record a current belonging computing node of the data page, that is, a page owner (PO) of the data page. Specifically, the page directory can include a data page identifier and an identifier of the corresponding PO. When accessing the data page, each computing node can determine the belonging computing node of the data page by accessing the page directory in the cache pool 21, and thus obtain the data page from the belonging computing node of the data page.
[0068] The data recovery method and the data storage method provided in the embodiments of the present application can be applied to the distributed system. In the embodiments of the present application, when the second computing node in the computing node cluster is abnormal and each memory node in the memory node cluster is normal, the first computing node can obtain a first record position and a second record position of the second computing node, and select a position with a larger LSN of the corresponding log record from the two record positions as a starting recovery position, and then start data recovery from the log record at the starting recovery position. The first record position is a position of a first log record in a log record corresponding to a dirty data page that is not written to the memory node cluster, and the second record position is a position of a first log record in a log record corresponding to the dirty data page that is not written to the storage node cluster. In other words, the first record position is a position of a log record corresponding to a next data page of a last data page successfully written to the memory node cluster by the second computing node before the second computing node is abnormal, and the second record position is a position of a log record corresponding to a next data page of the last data page successfully written to the storage node cluster by the second computing node before the second computing node is abnormal. Based on this, before the data recovery method provided in the embodiments of the present application is described in detail, the data storage method provided in the embodiments of the present application is first described by taking the second computing node as an example. For example, referring to FIG. 3, the method includes the following steps:
[0069] S301: When the write condition is met, the dirty data page is written to the memory node cluster and the storage node cluster in the order of the LSN of the log record corresponding to the dirty data page from small to large, and the LSN increases with the increase of the log record.
[0070] In the embodiments of the present application, the second computing node can generate a corresponding log record based on a write request, and perform a write operation on the data page cached by itself to obtain a dirty data page corresponding to the log record.
[0071] Specifically, the second computing node can generate a write request, or receive a write request from the outside, for example, receive a write request sent by another computing node or an external application client. Then, the second computing node can determine whether the home computing node of the data page to be operated by the write request is itself. If the home computing node of the data page to be operated by the write request is the second computing node, the second computing node can generate a corresponding log record based on the write request, and perform a write operation on the data page cached by itself to obtain a dirty data page corresponding to the log record.
[0072] It should be noted that the memory of the second computing node can cache a plurality of data pages, and some data pages of the plurality of data pages can belong to the second computing node, and for the data pages, the second computing node can modify, and the second computing node can store indication information indicating that the data pages are data pages owned by the second computing node. Alternatively, some data pages of the plurality of data pages can not belong to the second computing node, and for the data pages, the second computing node cannot modify. Based on this, after obtaining a write request, the second computing node can first search whether the data page to be operated by the write request is stored in the memory of the second computing node according to the write request. If the data page exists in the memory of the second computing node, the second computing node can further view whether the data page is a data page owned by the second computing node according to the indication information stored by the second computing node. If the data page is a data page owned by the second computing node, it indicates that the second computing node is the home computing node of the data page.
[0073] After determining that the second computing node is the home computing node of the data page to be operated by the write request, the second computing node can generate a corresponding log record according to the identifier of the data page to be operated by the write request and the write operation to be performed, and determine the LSN of the log record.
[0074] The log record is used to record related information of the write operation requested to be performed by the write request. For example, the log record can include the identifier of the data page operated by the write operation, the data to be operated in the data page, and the operation identifier, etc. Wherein, the write operation can include the operation of writing data, the operation of deleting data, and the operation of modifying data, etc. Correspondingly, the data to be operated in the data page can include data to be written, data to be deleted, and data to be modified, etc. In addition, the identifier of the data page can be used to uniquely identify the corresponding data page, and the identifier of the data page remains unchanged before and after the data page is operated.
[0075] It should be noted that the storage node cluster can store a log file of the second computing node, for example, the log file can be a WAL. Wherein, the log file can include a plurality of log records generated and written by the second computing node, and the plurality of log records can be written into the log file in the order of the generation time. Wherein, each log record can correspond to an LSN, and the LSN increases and increases with the increase of the log record, so that the log record with the later generation time corresponds to the larger LSN and is located at the later position in the log file. Based on this, after generating the corresponding log record based on the write request, the second computing node can first cache the log record in the memory of the second computing node, and determine the LSN of the log record according to the maximum LSN in the LSNs corresponding to all currently cached log records.
[0076] In addition, in the process of generating the log record at the second computing node, the second computing node can also perform a write operation on the data page cached in the memory according to the write request, and add the LSN of the log record in the data page, so as to obtain the dirty data page corresponding to the log record.
[0077] The above mainly introduces the process of obtaining the corresponding log record and dirty data page based on the write request. On this basis, for the log record cached in the second computing node, the second computing node can store the log record to the storage node cluster according to the first rule. For example, the first rule can be that every first time interval, the second computing node will store the log record to the log file of the second computing node stored in the storage node cluster in the order of the LSN of the cached log record from small to large, that is, in the order of the generation time of the log record. Optionally, after storing the log record to the storage node cluster, the second computing node can delete the log record cached by itself.
[0078] For the dirty data page cached in the second computing node, the second computing node can write the dirty data page to the memory node cluster and the storage node cluster in the order of the LSN of the corresponding log record from small to large when the write condition is met.
[0079] Specifically, the second computing node can maintain a dirty page queue, which is used to cache the dirty data page that has not been stored to the storage node cluster, and from the head to the tail of the dirty page queue, the dirty data pages are arranged in the order of the LSN of the corresponding log record from small to large. Based on this, when the write condition is detected, the second computing node can start from the head of the dirty page queue, sequentially write the data pages in the dirty page queue to the storage node cluster through the first process, and start from the next data page of the last data page written to the memory node cluster in the dirty page queue, sequentially write the data pages in the dirty page queue to the memory node cluster through the second process.
[0080] In a possible implementation, the second computing node can trigger data page writing every second time interval, based on which, the second computing node can determine that the write condition is met when detecting that the time difference between the current time and the time of the last time triggering data page writing before the current time is the second time interval, so as to start writing the data pages in the dirty page queue to the storage node cluster and the memory node cluster.
[0081] In another possible implementation, the second computing node can also determine that the write condition is met when detecting that the data amount of the cached dirty data page reaches a specified threshold, so as to start writing the data pages to the storage node cluster and the memory node cluster.
[0082] Specifically, the second computing node can obtain the dirty data pages from the dirty page queue in sequence by the first process starting from the head of the dirty page queue. After obtaining each dirty data page, the second computing node can check whether the LSN in the dirty data page is greater than the maximum LSN in the LSNs corresponding to the cached log records. If the LSN in the dirty data page is greater than the maximum LSN in the LSNs corresponding to the cached log records, the second computing node can send the dirty data page to the storage node cluster by the first process for persistent storage. Alternatively, if the LSN in the dirty data page is not greater than the maximum LSN in the LSNs corresponding to the cached log records, the second computing node can first persistently store the log records corresponding to the LSNs not less than the LSN in the dirty data page to the storage node cluster, and then send the dirty data page to the storage node cluster for persistent storage. As can be seen, in the embodiment of the present application, before the dirty data pages in the dirty page queue are persistently stored to the storage node cluster, the log records corresponding to the dirty data pages have been persistently stored to the storage node cluster. Therefore, when the computing node abnormally causes the dirty data pages in the cached dirty page queue to be lost, the lost dirty data pages can be recovered by the log records stored in the storage node cluster.
[0083] For the dirty data pages that have been successfully persistently stored to the storage node cluster, the second computing node can delete the cached dirty data pages in the memory of the second computing node.
[0084] In addition, the second computing node can also obtain the dirty data pages from the dirty page queue in sequence by the second process starting from the next dirty data page of the last dirty data page written to the memory node cluster last time. After obtaining each dirty data page, the second computing node can send the dirty data page to the memory node cluster for remote caching.
[0085] The second computing node can record the LSN of the last dirty data page successfully written to the memory node cluster last time when the data page was written. Based on this, the second computing node can determine the next dirty data page of the last dirty data page written to the memory node cluster last time according to the LSN by the second process, and cache the dirty data page in the memory pool provided by the memory node cluster starting from the dirty data page.
[0086] Specifically, each memory node in the memory node cluster has a corresponding hash value interval, and the hash values of the dirty data pages cached in each memory node are within the hash value interval corresponding to the memory node. On this basis, when synchronizing dirty data pages to the memory node cluster, the second computing node can determine the hash value of the dirty data page to be synchronized according to the identifier of the dirty data page to be synchronized, using a consistent hashing algorithm, and then determine a target memory node from the memory node cluster whose corresponding hash value interval contains the hash value of the dirty data page, and send the dirty data page to be synchronized to the target memory node for caching.
[0087] It should be noted that for the dirty data pages successfully synchronized to the memory node cluster, since these data pages may not have been persisted to the storage node cluster, the second computing node can continue to retain these dirty data pages in the memory.
[0088] From the moment of starting to write data pages to the memory node cluster and the storage node cluster, after a first time duration, the second computing node can stop writing data pages to the storage node cluster through the first process and stop writing data pages to the memory node cluster through the second process. That is, the operation of the second computing node to write dirty data pages to the memory node cluster and the storage node cluster through the above method can last for a first time duration. The first time duration can be preset, and the first time duration is less than the first time interval.
[0089] In addition, for each memory node in the memory node cluster, since the memory resources in each memory node are also limited, in the embodiments of the present application, each memory node can use a preset rule to manage the dirty data pages cached in its own memory, so that the memory space can be reasonably and efficiently utilized.
[0090] In some embodiments, each memory node can use a page eviction algorithm to determine the dirty data pages with lower access frequency from the dirty data pages cached in its own memory, and delete the determined dirty data pages, so as to leave free space to store other dirty data pages with higher access frequency. For example, the page eviction algorithm can be a clock sweep algorithm.
[0091] In other embodiments, the memory of each memory node can include a cache pool and an operating system input output (IO) cache. The cache pool is used to cache dirty data pages. Based on this, the memory node can also migrate the dirty data pages in the cache pool to the operating system IO cache for storage when the space of the cache pool is insufficient.
[0092] For example, FIG. 4 is a schematic diagram of management of dirty data pages in the memory of a memory node by a memory node according to an embodiment of the present application. As shown in FIG. 4, the second process in the computing node 40 writes dirty data pages in the dirty page queue to the memory node 41 in the memory node cluster. If the memory node 41 does not have enough cache pool space to cache the dirty data pages, the memory node 41 can migrate part of the dirty data pages in the cache pool to the operating system IO cache, thereby freeing up part of the space to cache the dirty data pages sent by the second process to the memory node 41.
[0093] S302: After stopping writing dirty data pages to the memory node cluster and the storage node cluster, the position of the next log record of the last log record corresponding to the dirty data page written to the memory node cluster is taken as the first record position, and the position of the next log record of the last log record corresponding to the dirty data page written to the storage node cluster is taken as the second record position.
[0094] After stopping writing data pages to the storage node cluster and the memory node cluster, the second computing node can take the position of the next log record of the last log record corresponding to the dirty data page successfully written to the storage node cluster as the second record position, and take the position of the next log record in the log record corresponding to the data page successfully written to the memory node cluster as the first record position.
[0095] Specifically, as described above, when the computing node generates a log record based on a write request and obtains a dirty data page corresponding to the log record, the dirty data page will contain the LSN of the corresponding log record. Based on this, the second computing node can obtain the LSN of the next data page of the last data page successfully written to the memory node cluster. For ease of description, this LSN is referred to as the first LSN, and the position of the log record corresponding to the first LSN is the first record position. Since the position of the log record in the log file can be represented by the LSN, the second computing node can record the first LSN in the control file of the second computing node stored in the storage node cluster, thereby recording the first record position.
[0096] It should be noted that since the second computing node writes data pages in order of the LSNs of the log records corresponding to the dirty data pages from small to large, it can be known that the dirty data pages corresponding to the log records with LSNs smaller than the first LSN have been written to the memory node cluster. That is, the dirty data pages corresponding to the log records before the first record position have been written to the memory node cluster, and the log record at the first record position is the first log record in the log file corresponding to the dirty data page that has not been written to the memory node cluster. Based on this, the first record position can be referred to as the memory checkpoint of the second computing node.
[0097] In addition, the second computing node can also acquire the LSN in the next dirty data page of the last successfully written dirty data page to the storage node cluster, for the convenience of description, the LSN is referred to as a second LSN, at this time, the position of the log record corresponding to the second LSN is a second record position, and correspondingly, the second computing node can record the second LSN to the control file of the second computing node stored by the storage node cluster, so as to realize the recording of the second record position.
[0098] It should be noted that, since the second computing node writes the data pages in the order of the LSNs of the log records corresponding to the dirty data pages from small to large, it can be known that the log records with LSNs less than the second LSN correspond to dirty data pages that have been written to the storage node cluster. That is, the dirty data pages corresponding to the log records before the second record position have been written to the storage node cluster, and the log record at the second record position is the first log record corresponding to the dirty data page that has not been written to the storage node cluster in the log file. Based on this, the second record position can be referred to as the disk checkpoint of the second computing node.
[0099] It should be noted that, since the speed of writing memory is faster than the speed of persisting data to a hard disk, in the case that the memory node cluster is running normally and the communication between the second computing node and the memory node cluster is normal, the speed of the second computing node synchronizing dirty data pages to the memory pool provided by the memory node cluster will be faster than the speed of persisting dirty data pages to the storage node cluster. On this basis, in the first time period, the number of dirty data pages synchronized by the second computing node to the memory node cluster will be more than the number of dirty data pages synchronized to the storage node cluster, so the first LSN will be greater than the second LSN, that is, the first record position is located after the second record position.
[0100] Alternatively, in some possible scenarios, such as part of the memory nodes in the memory node cluster are running abnormally, or the communication between the second computing node and the memory node cluster is abnormal, or in other scenarios, the speed of the second computing node synchronizing dirty data pages to the memory pool provided by the memory node cluster can also be equal to or less than the speed of persisting dirty data pages to the storage node cluster. On this basis, in the first time period, the number of dirty data pages synchronized by the second computing node to the memory node cluster can be equal to or less than the number of dirty data pages synchronized to the storage node cluster, so the first LSN can be not greater than the second LSN, that is, the first record position can be the same as the second record position, or the first record position can be located before the second record position.
[0101] After recording the first LSN and the second LSN in the control file, the second computing node can continue to perform S301 and S302 to update the first recording position and the second recording position and update the first LSN and the second LSN in the control file for representing the corresponding recording positions when next detecting that the write condition is met.
[0102] FIG. 5 is a schematic diagram of writing data pages into a storage node cluster and a memory node cluster according to an embodiment of the present application. As shown in FIG. 5, a dirty page queue is maintained in the second computing node. From t1, the first process starts to persistently store data pages in the storage node cluster from the head of the dirty page queue, that is, from data page 01. The second process starts to synchronize data pages in the memory node cluster from data page 04 along the direction from the head to the tail of the dirty page queue. It is assumed that at t2, the first process and the second process both stop writing data pages. At this time, the last data page successfully written by the first process in the storage node cluster is data page 05, and the next data page to be written in the storage node cluster is data page 06. Therefore, the second recording position is the position of the log record corresponding to data page 06, which can be represented by the LSN of data page 06. The last data page successfully written by the second process in the memory node cluster is data page 10, and the next data page to be written in the memory node cluster is data page 11. Therefore, the first recording position is the position of the log record corresponding to data page 11, which can be represented by the LSN of data page 11.
[0103] Optionally, after recording the first LSN and the second LSN in the control file, the second computing node can further calculate the distance between the first recording position represented by the first LSN and the second recording position represented by the second LSN. If the distance is greater than the first threshold, it indicates that the amount of data of the log records between the first recording position and the second recording position is large. In this case, the second computing node can select a computing node from the computing node cluster as a preloading computing node and synchronize the identifiers of the dirty data pages cached by the second computing node to the preloading computing node, so that in the case that the second computing node is abnormal and the memory node is also abnormal, the data recovery node can read the identifiers of the data pages cached in the preloading computing node to recover the service as soon as possible.
[0104] Specifically, taking the selected preloading computing node as the third computing node as an example, the second computing node can send a dirty page identifier list to the third computing node, the dirty page identifier list including the identifiers of the dirty data pages cached by the second computing node. After receiving the dirty page identifier list, the third computing node can cache the dirty page identifier list in the memory of the third computing node.
[0105] Optionally, in some possible cases, in a case where the distance between the first record position and the second record position is greater than the first threshold value, the second computing node can also select a computing node from the computing node cluster as a preloading computing node to pre-load the log records in the log file of the second computing node located after the second record position, so as to read the preloaded log records from the preloading computing node to recover data in a case where the second computing node is abnormal and the memory node is also abnormal, thereby accelerating log reading and shortening the length of data recovery. For example, the selected preloading computing node is the fourth computing node. The second computing node sends a preloading notification message to the fourth computing node. After receiving the preloading notification message, the fourth computing node can pre-load the log records in the log file of the second computing node located after the second record position stored in the storage node cluster into the memory of the fourth computing node.
[0106] Specifically, the second computing node can calculate the absolute value of the difference between the first LSN and the second LSN, and take the absolute value of the difference as the distance between the first record position and the second record position. In a case where the distance is greater than the first threshold value, the second computing node can send a preloading notification message carrying the second LSN to the fourth computing node. After receiving the preloading notification message, the fourth computing node can obtain each log record from the second LSN corresponding log record from the log file of the second computing node stored in the storage node cluster, and parse each obtained log record, thereby obtaining a preloaded log sub-file. As can be seen, the preloaded log sub-file is a subset of the log file of the second computing node, and includes a plurality of log records from the second record position.
[0107] For example, FIG. 6 is a schematic diagram of a second computing node notifying a fourth computing node to pre-load log records according to an embodiment of the present application. As shown in FIG. 6, the position of the log record corresponding to the data page 04 in the dirty page queue is the first record position, and the position of the log record corresponding to the data page 01 is the second record position. The log monitoring module in the second computing node can monitor the distance between the first record position and the second record position, and after monitoring that the distance is greater than the first threshold value, select a preloading computing node from the computing node cluster, that is, the fourth computing node. Then, notify the preloading module of the fourth computing node to pre-load the log. The preloading module of the fourth computing node reads each log record from the second record position in the log file of the second computing node from the storage node cluster and performs parsing, and then caches the parsed log records in the memory.
[0108] The foregoing embodiment takes the second computing node as an example to introduce the process of the computing node writing dirty data pages to the memory node cluster and the storage node cluster and recording the positions of the corresponding log records. For each computing node in the computing node cluster, the writing of data pages to the memory node cluster and the storage node cluster and the recording of the positions of the corresponding log records can be implemented through the foregoing steps. In this way, when any computing node is abnormal and each memory node in the memory node cluster is normal, the lost data pages on the corresponding computing node can be recovered through the process shown in FIG. 7. For example, the process of recovering the lost data pages of the computing node is still introduced below by taking the second computing node as an example and taking each memory node in the memory node cluster as an example. Referring to FIG. 7, the process includes the following steps.
[0109] S701: The first computing node obtains the first record position and the second record position of the second computing node.
[0110] In the embodiment of the present application, the cluster management service is deployed in the computing node cluster. When the cluster management service detects that the second computing node is abnormal, a computing node in the computing node cluster that is normal can be selected as a data recovery node, for example, the data recovery node is the first computing node. If it is detected that any memory node is abnormal at the same time that the second computing node is detected to be abnormal, the cluster management service can send a page recovery instruction to the first computing node to instruct the first computing node to recover the lost data pages on the second computing node. The abnormality of the computing node can mean that the computing node cannot normally provide services, for example, the computing node itself fails or the communication with other nodes is abnormal.
[0111] After receiving the page recovery instruction of the cluster management service, the first computing node can read the first LSN and the second LSN from the control file of the second computing node stored in the storage node cluster, where the first LSN is used to represent the first record position in the log file of the second computing node, and the second LSN is used to represent the second record position in the log file of the second computing node. As known from the foregoing embodiment, the dirty data pages corresponding to the log records before the first record position in the log file of the first computing node have been written to the memory node cluster by the second computing node, and the modified data pages corresponding to the log records before the second record position have been written to the storage node cluster by the second computing node.
[0112] S702: The first computing node determines a starting recovery position, which is the LSN of the corresponding log record that is greater in the first record position and the second record position.
[0113] As can be known from the foregoing introduction of the embodiments of the data storage method, in the log file, the larger the LSN of a log record is, the later the generation time of the log record is, and the later the position of the log record in the log file is. Based on this, the first computing node can compare the sizes of the first LSN used to represent the first record position and the second LSN used to represent the second record position. If the first LSN is larger than the second LSN, it indicates that the first record position represented by the first LSN is after the second record position represented by the second LSN, and thus the first record position indicated by the first LSN is taken as the starting recovery position; if the second LSN is larger than the first LSN, it indicates that the second record position represented by the second LSN is after the first record position represented by the first LSN, and thus the second record position represented by the second LSN is taken as the starting recovery position.
[0114] S703: The first computing node performs data recovery from the starting recovery position.
[0115] Since the starting recovery position is the later position of the first record position and the second record position, it can be seen that the dirty data pages corresponding to the log records before the starting recovery position have been cached to the in-memory node cluster or have been persisted to the storage node cluster, and thus the dirty data pages corresponding to the log records before the starting recovery position do not need to be recovered. The dirty data pages corresponding to the log records from the starting recovery position have neither been cached to the in-memory node cluster nor been persisted to the storage node cluster, but are only cached in the memory of the second computing node, and thus in the case of an exception of the second computing node, the dirty data pages corresponding to the log records from the starting recovery position are the lost data pages to be recovered. Based on this, the first computing node can read each log record in the log file of the second computing node from the starting recovery position, and based on each read log record, obtain the dirty data page corresponding to the corresponding log record, so as to realize the recovery of the cached data pages in the second computing node.
[0116] In a possible implementation, the first computing node can read each log record from the starting recovery position in the log file of the second computing node stored in the storage node cluster in sequence.
[0117] For example, the first computing node can send a log reading request to the storage node cluster, and the log reading request can carry the identifier of the log file of the second computing node and the starting LSN used to represent the starting recovery position. After receiving the log reading request, the storage node cluster can determine the log file of the second computing node based on the identifier of the log file of the second computing node. Then, the starting log record corresponding to the starting LSN is determined from the log file, and the starting log record and each log record after the starting log record are sent to the first computing node.
[0118] In another possible implementation, as known from the foregoing, in the case where the distance between the first record position and the second record position is greater than the first threshold, the third computing node preloads the log records from the second record position in the log file of the second computing node in the storage node cluster to the memory of the third computing node, thereby obtaining a log sub-file. Based on this, the first computing node can also read each log record from the start recovery position from the log sub-file cached in the memory of the third computing node in the case where the distance between the first record position and the second record position is greater than the first threshold. In this way, compared with reading the log records from the storage node cluster, the reading speed is faster, and the required log reading time is shorter.
[0119] After reading each log record from the start recovery position, the first computing node can sequentially obtain the dirty data page corresponding to each log record based on each log record.
[0120] Taking the read first log record as an example, the first computing node can first find the first data page from the memory node cluster based on the identifier of the first data page in the first log record; if the first data page is not found in the memory node cluster, the first data node is found from the storage node cluster. The first data page found is executed based on the first log record to perform a redo operation, thereby obtaining the dirty data page corresponding to the first log record.
[0121] It should be noted that, since the computing node will synchronize the dirty data page to the memory node cluster after performing the write operation on the data page based on the write request, the memory node cluster can cache the first data page modified based on other log records before the start recovery position. Considering that the speed of reading the data page from the memory node cluster is usually faster than that of reading the data page from the storage node cluster, the first computing node can first find the first data page from the memory node cluster, and if the first data page is found in the memory node cluster, there is no need to find the first data page from the storage node cluster. In this way, compared with reading the data page from the storage node cluster, the required time is shorter. Of course, if the first data page is not found in the memory node cluster, the first computing node can read the first data page from the storage node cluster.
[0122] Specifically, the computing node determines the hash value of the data page by using the consistent hashing algorithm when synchronizing the data page to the memory node cluster, and then determines the memory node for caching the data page according to the hash value of the data page. Based on this, the first computing node can calculate the hash value of the first data page by using the consistent hashing algorithm according to the identifier of the first data page, and determine the memory node corresponding to the first data page based on the hash value of the first data page. Then, the first computing node can send a read request to the memory node corresponding to the first data page, and the read request includes the identifier of the first data page. After receiving the read request, the memory node corresponding to the first data page can search for the first data page in the memory thereof according to the identifier of the first data page. If one first data page is found, the first computing node is returned the found first data page, if multiple first data pages containing different LSNs are found, the first computing node is returned the first data page containing the largest LSN. If the first data page is not found, the first computing node is returned a failure response. After receiving the failure response, the first computing node can send a read request to the memory node cluster again to read the first data page.
[0123] After the first computing node obtains the first data page, the first computing node can compare the LSN in the first data page with the LSN corresponding to the first log record. If the LSN corresponding to the first log record is equal to the LSN in the first data page, it means that the first data page is the dirty data page corresponding to the first log record, and at this time, it is not necessary to perform the redo operation on the first data page according to the first log record, and the first computing node can continue to refer to the method introduced in the foregoing to obtain the dirty data page corresponding to the next log record of the first log record. If the LSN corresponding to the first log record is greater than the LSN in the first data page, it means that the first data page is the old version of the data page, that is, the first data page is modified according to the log record before the first log record. In this case, the first computing node can re-execute the write operation recorded in the first log record on the old version of the first data page, so as to obtain the dirty data page corresponding to the first log record. Then, the first computing node can refer to the method introduced in the foregoing to obtain the dirty data page corresponding to the next log record of the first log record, until the dirty data page corresponding to the last log record of the read is obtained.
[0124] FIG. 8 is a schematic diagram of a data recovery method according to an embodiment of the present application. As shown in FIG. 8, the first computing node first determines the maximum LSN as the first LSN by comparing the first LSN and the second LSN, i.e., the first record position represented by the first LSN is the starting recovery position. Then, the first computing node reads each log record from the first record position from the storage node cluster into the memory of the first computing node. Then, the first computing node starts from the first log record at the first record position in the memory of the first computing node, and for each log record, obtains the old version of the data page corresponding to the log record from the memory node cluster and / or the storage node cluster, and then applies the log record to the old version of the data page, i.e., performs a redo operation on the old version of the data page, thereby obtaining the recovered data page.
[0125] Optionally, in the case where the starting recovery position is the first record position, the dirty data pages corresponding to the log records between the first record position and the second record position have been synchronized to the memory node cluster but have not been stored persistently to the storage node cluster. Therefore, after the data pages cached in the second computing node are recovered, the first computing node can further store persistently the dirty data pages corresponding to the log records between the second record position and the first record position to the storage node cluster.
[0126] For example, the first computing node can read at least one target log record from the second record position to the first record position, read the page directory of at least one target data page corresponding to the at least one target log record from the memory node cluster, the page directory including the identifier of the home computing node of the corresponding data page, and control the home computing node of the at least one target data page to write the at least one target data page to the storage node cluster.
[0127] It should be noted that in the embodiments of the present application, any computing node in the computing node cluster can determine the memory node corresponding to the data page based on the identifier of the data page by using the consistent hashing algorithm after performing the write operation on the data page cached by the computing node based on the write request, and then send a directory creation request to the memory node corresponding to the data page. Since only the home computing node of the data page can perform the write operation on the data page, the computing node performing the write operation on the data page is the home computing node of the data page, and accordingly, the directory creation request can include the identifier of the data page and the identifier of the computing node. After receiving the directory creation request, the memory node corresponding to the data page can create the page directory of the data page based on the directory creation request, and the page directory contains the identifier of the data page and the identifier of the home computing node of the data page. As can be seen, for the dirty data pages cached in each computing node in the computing node cluster, the memory node cluster will store the page directory of each dirty data page.
[0128] On this basis, taking any log record between the second record position and the first record position as an example, for the convenience of description, the log record is referred to as the second log record, the first computing node can determine the memory node corresponding to the corresponding data page by using the consistent hashing algorithm according to the identifier of the data page in the second log record, and obtain the home computing node of the data page from the page directory of the data page stored in the memory node. If the home computing node of the data page is neither the second computing node nor the first computing node, the first computing node can send a persistent instruction to the home computing node of the data page to instruct the home computing node of the data page to persistently store the latest version of the data page cached by the home computing node to the storage node cluster.
[0129] Optionally, if the home computing node of the data page is the first computing node, the first computing node can persistently store the latest version of the data page cached in the memory of the first computing node to the storage node cluster.
[0130] Optionally, if the home computing node of the data page is the second computing node, the first computing node can read the latest version of the data page from the memory node corresponding to the data page based on the identifier of the data page in the second log record, that is, read the data page with the identifier of the data page in the second log record and the largest LSN. Then, the read latest version of the data page is persistently stored to the storage node cluster.
[0131] In the embodiment of the present application, in the case that the second computing node in the computing node cluster is abnormal and each memory node is normal, the first computing node can obtain the first record position and the second record position of the second computing node. The first record position is the position of the first log record in the log record in which the corresponding dirty data page is not written to the memory node cluster, that is, the dirty data pages corresponding to the log records before the first record position in the log file have been written to the memory node cluster by the second computing node. The second record position is the position of the first log record in the log record in which the corresponding dirty data page is not written to the storage node cluster, that is, the dirty data pages corresponding to the log records before the second record position have been written to the storage node cluster by the second computing node. Based on this, the first computing node can select one of the two record positions as the starting recovery position, which has a larger LSN of the corresponding log record. Since the LSN increases with the increase of the log record, in fact, the position of the later log record is selected from the two record positions as the starting recovery position, and the data recovery starts from the log record at the starting recovery position. In other words, the starting recovery position in the embodiment of the present application depends on the speed at which the computing node writes the data page to the storage node cluster and the memory node cluster. In the case that the second computing node writes the data page to the memory node cluster at a faster speed, the first record position will be located after the second record position. On this basis, taking the first record position as the starting recovery position, the data page that has been written to the memory node cluster but has not been written to the storage node cluster does not need to be recovered again, so that the number of log records to be read and the number of data pages to be recovered during data recovery can be reduced, thereby shortening the data recovery time, reducing the impact of data recovery on business, and improving the availability of the database. In the case that the second computing node writes the data page to the storage node cluster at a faster speed, the first record position will be located before the second record position. On this basis, taking the second record position as the starting recovery position, the minimum log records can still be read to perform data recovery. As can be seen, in the embodiment of the present application, the later position of the first record position and the second record position is always taken as the starting recovery position, so that the minimum log records can be read to implement data page recovery during data recovery, thereby shortening the data recovery time, reducing the impact of data recovery on business, and improving the availability of the database.
[0132] In addition, it should be noted that, in the embodiments of the present application, the second record position is determined according to the last data page successfully written to the storage node cluster by the second computing node. The first record position is determined according to the last data page successfully synchronized to the memory node cluster by the second computing node. As can be seen, the second computing node writes data pages to the memory node cluster and the storage node cluster asynchronously, so that the second record position only depends on the speed of the second computing node writing data pages to the storage node cluster, and is irrelevant to the memory node cluster. On this basis, the advancement of the second record position is independent of the advancement of the first record position, and is not affected by the advancement speed of the first record position. For example, when the network communication between the second computing node and the memory node cluster is congested, it will only affect the advancement of the first record position, and will not affect the advancement of the second record position. In this case, once the second record position advances to the first record position, the first computing node can still use the second record position as the starting recovery position to read as few log records as possible for data recovery.
[0133] In the above embodiments, the process of recovering the data pages cached in the abnormal computing node is mainly introduced in the case that the computing node is abnormal and the memory node is normal. In some possible cases, as known from the foregoing embodiments, the page directory of the dirty data pages cached by each computing node is stored in the memory node cluster. Therefore, when an abnormality occurs in a memory node, the page directory stored in the memory node will be lost, which will cause the computing node to fail to determine the home computing node of the data page corresponding to the page directory accessed by the computing node through the page directory when the computing node accesses the data page, thereby affecting the business operation. Based on this, the embodiments of the present application further provide a method for recovering data in an abnormal memory node in the case that the memory node is abnormal. Specifically, next, the data recovery method is described in detail by taking the first memory node as an example and taking the first computing node in the computing node cluster as a data recovery node. Referring to FIG. 9, the method comprises the following steps:
[0134] S901: The first computing node sends a second message to other computing nodes in the computing node cluster, the second message being used to indicate the page directory stored in the first memory node.
[0135] In the embodiments of the present application, the cluster management service can be deployed in the computing node cluster. When the cluster management service detects that a first memory node in the memory node cluster is abnormal, a computing node in the computing node cluster that is normal can be selected as a data recovery node, which is referred to as a first computing node. The cluster management service can send a directory recovery instruction to the first computing node to instruct the first computing node to recover the lost page directory of the first memory node. The memory node abnormality can refer to that the memory node cannot normally provide services, for example, the memory node itself fails or the communication between the memory node and other nodes is abnormal.
[0136] After receiving the directory recovery instruction, the first computing node can send a second message to other computing nodes in the computing node cluster, so as to notify the other computing nodes of which data page directories are stored in the abnormal first memory node.
[0137] Specifically, in the embodiments of the present application, each memory node in the memory node cluster has a corresponding hash value interval, and the hash value intervals corresponding to the memory nodes do not overlap. For a data page cached in any computing node, if the hash value determined by the consistent hashing algorithm according to the identifier of the data page is in the hash value interval corresponding to a memory node, the page directory of the data page will be stored in the corresponding memory node. As can be seen, each memory node can be used to store the page directory of the data page whose hash value is in the hash value interval corresponding to the memory node. Based on this, the first computing node can obtain the first hash value interval corresponding to the first memory node. Then, the second message is sent to other computing nodes, wherein the second message can include the first hash value interval, so as to indicate which data page directories are stored in the first memory node. Optionally, the second message can be a remote procedure call (RPC) message.
[0138] S902: Each computing node detects whether the page directory of the dirty data page belonging to the computing node is stored in the first memory node.
[0139] After receiving the second message, each computing node can detect whether the page directory stored in the first memory node includes the page directory of the dirty data page owned by the computing node based on the second message, wherein the dirty data page owned by a certain computing node refers to the dirty data page cached in the computing node and taking the computing node as the home computing node.
[0140] Specifically, taking the first computing node as an example, the first computing node can scan each dirty data page cached in the memory of the first computing node to determine the target dirty data page owned by the first computing node. Taking the target dirty data page owned by the first computing node as an example, the first computing node can calculate the hash value of the first target dirty data page according to the identifier of the first target dirty data page by using the consistent hashing algorithm, and if the hash value of the first target dirty data page is in the first hash value interval, it indicates that the page directory of the first target dirty data page is stored in the first memory node. In this case, the first computing node can perform S903. For other dirty data pages owned by the first computing node, the first computing node can use the above method to detect whether the page directory of the corresponding dirty data page is stored in the first memory node, so as to determine whether to send a message to other normally running memory nodes to re-create the page directory of the corresponding dirty data page.
[0141] S903: If the first computing node detects that the page directory of the first target dirty data page owned by the first computing node is stored in the first memory node, the first computing node sends a first message to the second memory node.
[0142] After detecting that the page directory of the first target dirty data page is stored in the first memory node, the first computing node can determine that the page directory of the first target dirty data page is the page directory to be recovered. In this case, the first computing node can send a first message to the second memory node, where the first message can include the identifier of the first target dirty data page and the identifier of the home computing node of the first target dirty data page, where the home computing node of the first target dirty data page is the first computing node, that is, the first message includes the identifier of the first target dirty data page and the identifier of the first computing node. Optionally, the first message can be an RPC message.
[0143] It should be noted that in the embodiments of the present application, the cluster management service can re-allocate corresponding hash value intervals to each normally running memory node in the memory node cluster after the first memory node is abnormal, so as to re-allocate the first hash value interval corresponding to the first memory node to other normally running memory nodes. Based on this, the first computing node can determine the hash value of the first target dirty data page according to the identifier of the first target dirty data page by using the consistent hashing algorithm, and determine the memory node corresponding to the first target dirty data page, that is, the second memory node, based on the hash value of the first target dirty data page and the updated hash value interval corresponding to each memory node. The updated hash value interval corresponding to the second memory node includes the hash value of the first target dirty data page.
[0144] S904: The second memory node creates the page directory of the first target dirty data page based on the first message.
[0145] After receiving the first message, the second memory node can create and store a page directory of the first target dirty data page according to the identification of the first target dirty data page carried in the first message and the identification of the home computing node of the first target dirty data page. The page directory includes the identification of the first target dirty data page and the identification of the home computing node of the first target dirty data page.
[0146] The above S903 and S904 are only examples of detecting by the first computing node that the page directory of the first target dirty data page possessed by the first computing node is stored in the first memory node, to introduce the process of recovering the page directory of the first target dirty data page. For other computing nodes, if it is detected that the page directory stored in the first memory node includes the page directory of the data page possessed by the computing node, the page directory of the lost page can be reconstructed by sending a message to the normally running memory node in the memory node cluster, which can be referred to S903 and S904.
[0147] FIG. 10 is a diagram illustrating a method for recovering a page directory in a memory node according to an embodiment of the present application. As shown in FIG. 10, the memory node cluster includes four memory nodes, where the memory node 00 corresponds to the hash value interval [0, 30), the memory node 01 corresponds to the hash value interval [30, 60), the memory node 02 corresponds to the hash value interval [60, 90), and the memory node 03 corresponds to the hash value interval [90, 120). After the memory node 00 fails, the cluster management service updates the hash value intervals corresponding to the memory nodes, and after the update, the hash value interval corresponding to the memory node 01 is [0, 10) and [30, 60), the hash value interval corresponding to the memory node 02 is [10, 20) and [60, 90), and the hash value interval corresponding to the memory node 03 is [20, 30) and [90, 120). Based on this, after the computing nodes in the computing node cluster obtain the hash value interval corresponding to the memory node 00, the computing nodes scan their own memories to determine whether the page directory of the data page owned by the computing node is stored in the memory node 00. As shown in FIG. 10, assuming that the hash value of the data page 041 owned by the computing node 04 is 15, it is indicated that the page directory of the data page 041 is the page directory originally stored in the memory node 00, that is, the page directory to be reconstructed. In this case, the computing node 04 can determine, according to the hash value 15 of the data page 041 and the updated hash value intervals corresponding to the memory nodes, that the current memory node corresponding to the data page 041 is the memory node 02. Therefore, the computing node 04 can send a message to the memory node 02, where the message can carry the identifier of the data page 041 and the identifier of the computing node 04. After receiving the message, the memory node 02 can reconstruct the page directory of the data page 041 based on the identifier of the data page 041 and the identifier of the computing node 04. Similarly, the page directory of the data page 051 owned by the computing node 05 is also a page directory to be reconstructed, and the current memory node corresponding to the data page 051 is the memory node 01, so the computing node 05 can instruct the memory node 01 to reconstruct the page directory of the data page 051.
[0148] Optionally, as can be known from the foregoing embodiments, after the computing node operates on the data page based on the write request, the computing node can also send the dirty data page to the memory node cluster for remote caching. As can be seen, the memory node cluster not only stores the page directories of the data pages cached by the computing nodes, but also stores part of the dirty data pages cached by the computing nodes. In this case, when the first memory node is abnormal, not only the page directory on the first memory node will be lost, but also the dirty data page cached on the first memory node will be lost. Since the dirty data page cached in the first memory node has been either stored persistently in the storage node cluster by the corresponding computing node or cached in the memory of the computing node, the first computing node can not recover the lost data page in the first memory node.
[0149] However, since the data page cached in the first memory node is lost, the lost data page can contain the dirty data page corresponding to the first record position of some computing node, i.e., the log record before the memory checkpoint. In other words, the dirty data page corresponding to part of the log record before the memory checkpoint of some computing node no longer exists in the memory node cluster, so that the memory checkpoint will no longer be accurate. Based on this, if any computing node detects that the dirty data page owned by itself is cached in the first memory node, the computing node can also update the memory checkpoint corresponding to itself to the disk checkpoint, i.e., update the first record position used to indicate the dirty data page written into the memory node cluster to the second record position used to indicate the dirty data page written into the storage node cluster. For example, taking the case that the first memory node is abnormal and the second computing node is still operating normally as an example, if the second computing node detects that the data page owned by itself is cached in the first memory node, the second computing node can update the first record position of itself to the second record position, i.e., the first record position and the second record position are the same at this time.
[0150] It should be noted that when the computing node synchronizes the dirty data page to the memory node cluster, the consistent hashing algorithm is also used to determine the memory node corresponding to the dirty data page, so as to synchronize the corresponding dirty data page to the corresponding memory node. As can be seen, for any dirty data page cached in the memory node, the page directory of the dirty data page will be cached in the memory node. Therefore, in the embodiment of the present application, if a computing node detects that the page directory stored in the first memory node includes the page directory of the dirty data page owned by itself, the computing node can determine that the dirty data page owned by itself is cached in the first memory node.
[0151] The recovery process of the page directory is introduced in the above embodiments mainly taking the first computing node as an example. Alternatively, if the first computing node is not the data recovery node, for example, the data recovery node is the fifth computing node in the computing node cluster, the fifth computing node can execute S901 described above, and correspondingly, each computing node including the first computing node and the fifth computing node can execute S902, and instruct other normal memory nodes to rebuild the page directory in the first memory node based on the method introduced in S903.
[0152] In the embodiments of the present application, for the dirty data pages cached in the computing nodes, the page directories of these data pages are remotely stored in the memory node cluster. When the memory node is abnormal, since the dirty data pages corresponding to the page directories stored in the memory node all exist in the computing nodes, it is not necessary to read the log records to recover the dirty data pages, but only the data recovery node needs to notify each computing node to scan the memory and interact with the corresponding memory node to recover the page directory in the memory node, so that the data recovery speed is faster, the required recovery time is shorter, and the impact on the business is smaller.
[0153] Alternatively, in some possible cases, the computing nodes in the computing node cluster and the memory nodes in the memory node cluster may simultaneously occur abnormal, for example, when the first memory node and the second computing node are abnormal at the same time, the first computing node as the data recovery node can first recover the page directory in the first memory node through the page directory recovery method introduced above. Then, considering that there is an abnormal memory node in the memory node cluster, and the data pages written by the second computing node to the memory node cluster may be located on the first memory node, and these data pages may not have been stored persistently to the storage node cluster. Therefore, in order to avoid the loss of these data pages, the first computing node can directly take the second record position as the starting recovery position to recover the data pages cached in the second computing node.
[0154] Optionally, as can be known from the foregoing embodiments, in some possible cases, the second computing node can synchronize the identifiers of the dirty data pages cached by itself to the third computing node for caching, in a case where the distance between the first record position and the second record position is greater than the first threshold. In this way, the third computing node will cache the identifiers of the dirty data pages corresponding to the log records after the second record position in the second computing node. On this basis, in a case where the second computing node is abnormal and the first memory node is also abnormal, since the data pages are to be recovered from the second record position, the number of data pages required to be recovered by the first computing node is relatively large, and based on this, in order to ensure that the service can be provided to the outside as soon as possible in the process of recovering the data pages, the first computing node can also read the identifiers of the dirty data pages in the second computing node cached in the third computing node in the process of recovering the data by the method described above, and provide the service to the outside by using the read identifiers of the data pages.
[0155] Specifically, the memory of the third computing node can cache a dirty page identifier list of the second computing node, and the dirty page identifier list includes identifiers of dirty data pages cached in the second computing node. Based on this, after determining that the second computing node and the first memory node are both abnormal, the first computing node can also read the dirty page identifier list from the third computing node in the process of recovering the data by the method described above. Subsequently, if the first computing node receives an access request, and the identifier of a second data page accessed by the access request is an identifier in the dirty page identifier list, the first computing node can find the second data page from the currently recovered data pages based on the identifier of the second data page, and if the second data page cannot be found, it indicates that the second data page has not been recovered, in which case the first computing node can read a log record corresponding to the second data page, and then recover the second data page based on the read log record, and access the recovered second data page according to the access request.
[0156] The access request can be a read request or a write request. The method of recovering the second data page based on the read log record can refer to the implementation manner of recovering the data page based on the log record described above, which will not be described herein again. In addition, when the access request is a read request, the first computing node can return the second data page to the device sending the access request after obtaining the second data page. When the access request is a write request, the first computing node can perform a corresponding write operation on the second data page based on the write request.
[0157] Optionally, if the identification of the second data page accessed by the access request is not the identification in the dirty page identification list, it indicates that the second data page is not a dirty data page that needs to be recovered, in this case, the second data page stored in the memory node cluster or the storage node cluster is the latest version of the data page, therefore, the first computing node can read the second data page from the memory node cluster based on the identification of the second data page, and if the second data page is not read from the memory node cluster, the second data page is read from the storage node cluster based on the identification of the second data page. Then, the corresponding access operation is performed on the read second data page based on the access request.
[0158] Optionally, in some possible cases, the second computing node can notify the fourth computing node to pre-load the log records from the second record position in a case where the distance between the first record position and the second record position is greater than the first threshold. Based on this, in a case where both the second computing node and the first memory node are abnormal, the first computing node can read the pre-loaded log records from the second record position from the fourth computing node, and then restore the data page based on the log records, so that the reading speed is faster compared with reading the log records from the second record position from the storage node cluster, thereby improving the speed of data page recovery and shortening the recovery time.
[0159] Next, the data recovery apparatus and the data storage apparatus provided by the embodiments of the present application are introduced.
[0160] FIG. 11 is a structural schematic diagram of a data recovery apparatus provided by an embodiment of the present application. The data recovery apparatus can be deployed in a data recovery node, for example, can be deployed in the first computing node in the foregoing embodiments, and the data recovery apparatus can restore the dirty data page cached in the second computing node in a case where the second computing node is abnormal and each memory node is normal. As shown in FIG. 11, the data recovery apparatus 1100 includes a record position obtaining module 1101, a start position determining module 1102, and a data recovery module 1103, wherein the record position obtaining module 1101 is configured to perform S701 in the foregoing embodiments, the start position determining module 1102 is configured to perform S702 in the foregoing embodiments, and the data recovery module 1103 is configured to perform S703 in the foregoing embodiments.
[0161] Optionally, the storage node cluster stores a log file of the second computing node, and the data recovery module 1103 includes a log reading unit and a data recovery unit, wherein the log reading unit is configured to read each log record in sequence from the start recovery position in the log file; and the data recovery unit is configured to obtain a dirty data page corresponding to each read log record based on the log record.
[0162] Optionally, the log record comprises an identification of the data page operated by the write operation; and the data recovery unit is specifically configured to: find the first data page from the in-memory node cluster based on the identification of the first data page in the read first log record; if the first data page is not found from the in-memory node cluster, find the first data page from the storage node cluster; and perform a redo operation on the found first data page based on the first log record to obtain a dirty data page corresponding to the first log record.
[0163] Optionally, the in-memory node cluster stores a page directory of the data page, and the page directory comprises an identification of a home computing node of the data page; the data recovery apparatus further comprises a persistence module configured to, in a case where the starting recovery position is the first record position, read at least one target log record from the second record position to the first record position; read a page directory of at least one target data page corresponding to the at least one target log record from the in-memory node cluster, the page directory comprising an identification of a home computing node of the corresponding data page; and control the home computing node of the at least one target data page to write the operated at least one target data page to the storage node cluster.
[0164] In the embodiment of the present application, in the case that the second computing node in the computing node cluster is abnormal and each memory node is normal, the first computing node can obtain the first record position and the second record position of the second computing node. The first record position is the position of the first log record in the log record in which the corresponding dirty data page is not written to the memory node cluster, that is, the dirty data pages corresponding to the log records before the first record position in the log file have been written to the memory node cluster by the second computing node. The second record position is the position of the first log record in the log record in which the corresponding dirty data page is not written to the storage node cluster, that is, the dirty data pages corresponding to the log records before the second record position have been written to the storage node cluster by the second computing node. Based on this, the first computing node can select one of the two record positions as the starting recovery position, which has a larger LSN of the corresponding log record. Since the LSN increases with the increase of the log record, in fact, the position of the later log record is selected from the two record positions as the starting recovery position, and the data recovery is started from the log record at the starting recovery position. In other words, the starting recovery position in the embodiment of the present application depends on the speed at which the computing node writes the data page to the storage node cluster and the memory node cluster. In the case that the second computing node writes the data page to the memory node cluster at a faster speed, the first record position will be located after the second record position. On this basis, taking the first record position as the starting recovery position, the data page that has been written to the memory node cluster but has not been written to the storage node cluster does not need to be recovered again, so that the number of log records to be read and the number of data pages to be recovered during data recovery can be reduced, thereby shortening the data recovery time, reducing the impact of data recovery on business, and improving the availability of the database. In the case that the second computing node writes the data page to the storage node cluster at a faster speed, the first record position will be located before the second record position. On this basis, taking the second record position as the starting recovery position, the minimum log records can still be read to perform data recovery. As can be seen, in the embodiment of the present application, the later position of the first record position and the second record position is always taken as the starting recovery position, so that the minimum log records can be read to implement data page recovery during data recovery, thereby shortening the data recovery time, reducing the impact of data recovery on business, and improving the availability of the database.
[0165] FIG. 12 is a structural schematic diagram of another data recovery apparatus provided in an embodiment of the present application. The data recovery apparatus can be deployed in a data recovery node, for example, the first computing node as described above. Moreover, the data recovery apparatus can be used for data recovery in the scenario that the first memory node is abnormal. Referring to FIG. 12, the data recovery apparatus 1200 can include a detection module 1201 and a sending module 1202. The detection module 1201 is configured to perform S902 in the foregoing embodiment, and the sending module 1202 is configured to perform S903 in the foregoing embodiment.
[0166] Optionally, the sending module 1202 is further configured to send a second message to other computing nodes in the computing node cluster, where the second message is used to indicate the page directory stored in the first memory node.
[0167] Optionally, the memory node cluster stores dirty data pages written by each computing node in the computing node cluster, and the computing node cluster further includes a second computing node and a third computing node. The second computing node corresponds to a first record position and a second record position. The first record position is a position of a first log record in which the corresponding dirty data page is not written in the log record of the memory node cluster. The second record position is a position of a first log record in which the corresponding dirty data page is not written in the log record of the memory node cluster. The third computing node stores a dirty page identifier list of the second computing node. The dirty page identifier list includes an identifier of a dirty data page cached in the second computing node in a case that a distance between the first record position and the second record position is greater than a first threshold. The apparatus 1200 is further configured to: in a case that the second computing node is abnormal, start data recovery from the second record position, and in a case that the distance between the first record position and the second record position is greater than the first threshold, read the dirty page identifier list from the third computing node; if an access request is received and an identifier of a second data page to be accessed by the access request exists in the dirty page identifier list, search for the second data page in the currently recovered data page; if the second data page is not found, obtain a log record corresponding to the second data page, and recover the second data page based on the log record corresponding to the second data page; and access the second data page based on the access request.
[0168] In the embodiment of the present application, for the dirty data pages cached in the computing node, the page directories of the data pages are remotely stored in the memory node cluster. When the memory node is abnormal, since the data pages corresponding to the page directories stored in the memory node all exist in the computing node, it is not necessary to read the log record to recover the data page, but only to recover the lost page directory of the abnormal memory node according to the data page possessed by the computing node, so that the recovery speed is faster, the recovery time is shorter, and the service provided to the outside can be recovered faster.
[0169] FIG. 13 is a structural schematic diagram of a data storage device provided in an embodiment of the present application. The data storage device can be deployed in each computing node. Referring to FIG. 13, the data storage device 1300 can include a data writing module 1301 and a position recording module 1302.
[0170] The data writing module 1301 is configured to perform S301 in the foregoing embodiments, and the position recording module 1302 is configured to perform S302 in the foregoing embodiments.
[0171] Optionally, the data writing module 1301 is specifically configured to sequentially write, by the first process, the dirty data pages in the dirty page queue to the storage node cluster in sequence, starting from the head of the dirty page queue of the second computing node, wherein the dirty data pages are arranged in ascending order of the LSN of the corresponding log record from small to large from the head to the tail of the dirty page queue.
[0172] Optionally, the data writing module 1301 is specifically configured to sequentially write, by the second process, the data pages in the dirty page queue to the memory node cluster, starting from the next data page of the last data page written from the dirty page queue to the memory node cluster.
[0173] Optionally, the apparatus 1300 is further configured to, after stopping writing the dirty data pages to the memory node cluster and the storage node cluster, delete the dirty data pages in the dirty page queue that have been written to the storage node cluster.
[0174] Optionally, the computing node cluster further includes a third computing node, and the apparatus 1300 further includes a log monitoring module and a preloading module. The log monitoring module is configured to, in a case where the distance between the first record position and the second record position is greater than a first threshold, trigger the preloading module to cache the dirty page identifier list to the third computing node, the dirty page identifier list including the identifier of the dirty data page cached in the second computing node.
[0175] In the embodiments of the present application, the second computing node can write the dirty data pages to the memory node cluster and the storage node cluster respectively in the order of the LSNs of the log records corresponding to the dirty data pages in the cache from small to large. Since the LSNs increase with the increase of the log records, the second computing node actually writes the dirty data pages corresponding to the log records in the log file from front to back to the memory node cluster and the storage node cluster respectively. On this basis, after stopping writing the dirty data pages to the memory node cluster and the storage node cluster, the position of the next log record of the log record corresponding to the last dirty data page written to the memory node cluster can be taken as the first record position, so that the dirty data pages corresponding to the log records before the first record position in the log file have all been written to the memory node cluster. The position of the next log record of the log record corresponding to the last dirty data page written to the storage node cluster can be taken as the second record position. In this way, the dirty data pages corresponding to the log records before the second record position in the log file have all been written to the storage node cluster. On this basis, when the second computing node is abnormal subsequently, one of the two record positions is selected as the starting recovery position, and the data pages are recovered from the starting recovery position, which can maximize the number of log records required to be read and the number of data pages required to be recovered, thereby shortening the recovery time, reducing the impact of data recovery on business, and improving the availability of the database.
[0176] It should be noted that the division of the modules in the data recovery device and the data storage device provided by the above embodiments is illustrative, and is only a logical functional division. In actual implementation, another division manner can be used. In addition, each functional module in each embodiment of the present application can be integrated in one processor, or can be physically separated, or two or more modules can be integrated into one module. The above integrated module can be realized in the form of hardware or in the form of a software functional module.
[0177] The integrated module, if implemented in the form of a software function module and sold or used as an independent product, can be stored in a computer readable storage medium. Based on such an understanding, the technical solutions of the embodiments of the present application essentially or say the parts that make contributions to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes a plurality of instructions for causing a computer device (which can be a server, etc.) or a processor to perform all or part of the steps of the methods of the embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, and various media that can store program codes.
[0178] In addition, the data recovery device and the data recovery method provided by the above-mentioned embodiments belong to the same concept, and the data storage device and the data storage method belong to the same concept. For details of the implementation process, see the method embodiments, which will not be described here.
[0179] In the above embodiments, all or part of the embodiments can be realized by software, hardware, firmware or any combination thereof. When realized by software, all or part of the embodiments can be realized in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network or other programmable devices. The computer instructions can be stored in a computer readable storage medium or transferred from one computer readable storage medium to another, for example, the computer instructions can be transmitted from one website, computer, server or data center to another website, computer, server or data center through wired (for example: coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (for example: infrared, wireless, microwave, etc.) mode. The computer readable storage medium can be any available medium that can be accessed by a computer or a data storage device such as a server, data center, etc. integrated with one or more available media. The available media can be magnetic media (for example: floppy disk, hard disk, magnetic tape), optical media (for example: digital versatile disc (DVD)) or semiconductor media (for example: solid state disk (SSD)) and the like.
[0180] In the various embodiments of the present application, the terms and / or descriptions between different embodiments are consistent and can be referred to each other if there is no special description and logical conflict, and the technical features in different embodiments can be combined to form new embodiments according to their inherent logical relationship. In the embodiments of the present application, "at least one" means one or more, and "multiple" means two or more. The "and / or" describes the relationship between the associated objects, which means that there can be three kinds of relationships, for example, A and / or B can represent: A exists alone, A and B exist together, and B exists alone, where A and B can be singular or plural. In the textual description of the embodiments of the present application, the character " / ", generally indicates that the associated objects before and after are in an "or" relationship. In the present application, "first", "second", and various numerical designations are only for the convenience of description and do not limit the scope of the embodiments of the present application. For example, to distinguish different messages, etc., rather than to describe a specific order or sequence.
[0181] It can be understood that the various numerical designations involved in the embodiments of the present application are only for the convenience of description and do not limit the scope of the embodiments of the present application. The size of the serial number of the above processes does not mean the order of execution, and the execution order of the processes should be determined by their functions and inherent logic.
[0182] Finally, it should be noted that the above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto, any change or replacement within the technical scope disclosed in the present application should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A data recovery method, characterized by, A first computing node applied to a distributed system, the distributed system comprising a computing node cluster and a memory node cluster, the computing node cluster comprising the first computing node and a second computing node, the memory node cluster comprising a plurality of memory nodes, the second computing node being abnormal and the plurality of memory nodes being normal, the method comprising: obtaining a first record position and a second record position of the second computing node, the first record position being a position of a first log record in log records corresponding to a dirty data page not written to the memory node cluster, and the second record position being a position of a first log record in log records corresponding to the dirty data page not written to the storage node cluster; determining a starting recovery position, the starting recovery position being one of the first record position and the second record position corresponding to a log record with a larger log sequence number (LSN), the LSN increasing with an increase in the log record; performing data recovery from the starting recovery position.
2. The method of claim 1, wherein, The storage node cluster stores a log file of the second computing node, and the performing data recovery from the starting recovery position comprises: reading each log record in sequence from the starting recovery position in the log file; based on each read log record, obtaining a dirty data page corresponding to the log record.
3. The method according to claim 1 or 2, characterized in that, The log record comprises an identifier of a data page operated by a write operation, and the obtaining the dirty data page corresponding to the log record based on each read log record comprises: based on an identifier of a first data page in the first log record, searching for the first data page in the memory node cluster, and if the first data page is not found in the memory node cluster, searching for the first data page in the storage node cluster; based on the first log record, performing a redo operation on the found first data page to obtain the dirty data page corresponding to the first log record.
4. The method according to any one of claims 1 to 3, characterized in that, The memory node cluster stores a page directory of the data page, the page directory comprising an identifier of a home computing node of the data page, and the method further comprises: in a case where the starting recovery position is the first record position, reading at least one target log record from the second record position to the first record position; reading a page directory of at least one target data page corresponding to the at least one target log record from the memory node cluster, the page directory comprising an identifier of a home computing node of the corresponding data page; controlling the home computing node of the at least one target data page to write the at least one target data page to the storage node cluster.
5. The method according to any one of claims 1 to 4, characterized in that, The computing node cluster and the memory node cluster are both distributed clusters.
6. A data recovery method characterized by comprising: The method is applied to a first computing node in a distributed system, the distributed system comprising a computing node cluster and a memory node cluster, the computing node cluster comprising the first computing node, the memory node cluster storing a page directory of dirty data pages in the computing node cluster, the page directory comprising an identifier of a home computing node of a dirty data page, the memory node cluster comprising a first memory node and a second memory node, and the first memory node being abnormal, the method comprising: detecting whether a page directory of a plurality of target dirty data pages cached by the first computing node is stored in the first memory node, the target dirty data page being a dirty data page whose home computing node is the first computing node; if a page directory of a first target dirty data page in the plurality of target dirty data pages is stored in the first memory node, sending a first message to the second memory node, the first message being used to instruct the second memory node to create the page directory of the first target dirty data page.
7. The method of claim 6, wherein, The method further comprises: sending a second message to other computing nodes in the computing node cluster, the second message being used to instruct the page directory stored in the first memory node.
8. The method according to claim 6 or 7, characterized in that, The memory node cluster stores dirty data pages written by each computing node in the computing node cluster, and the computing node cluster further comprises a second computing node and a third computing node, the second computing node corresponding to a first record position and a second record position, the first record position being a position of a first log record in a log record corresponding to a dirty data page not written into the memory node cluster, and the second record position being a position of a first log record in a log record corresponding to a dirty data page not written into the memory node cluster; The third computing node stores a dirty page identifier list of the second computing node, the dirty page identifier list comprising an identifier of a dirty data page cached by the second computing node in a case where a distance between the first record position and the second record position is greater than a first threshold; and the method further comprises: in a case where the second computing node is abnormal, starting data recovery from the second record position, and in a case where the distance between the first record position and the second record position is greater than the first threshold, reading the dirty page identifier list from the third computing node; if an access request is received, and an identifier of a second data page to be accessed by the access request exists in the dirty page identifier list, searching for the second data page in currently recovered data pages; if the second data page is not found, obtaining a log record corresponding to the second data page, and recovering the second data page based on the log record corresponding to the second data page; accessing the second data page based on the access request.
9. A data storage method, characterized by, The method is applied to a second computing node in a computing node cluster, the second computing node caching a dirty data page, and the method comprising: In the case of meeting the write condition, the dirty data pages are written to the memory node cluster and the storage node cluster in the order of the log sequence number LSN of the log record corresponding to the cached dirty data page from small to large, the LSN increasing with the increase of the log record; After stopping writing the dirty data pages to the memory node cluster and the storage node cluster, the position of the next log record of the log record corresponding to the last dirty data page written to the memory node cluster is taken as the first record position, and the position of the next log record of the log record corresponding to the last dirty data page written to the storage node cluster is taken as the second record position.
10. The method of claim 9, wherein, The writing of the dirty data pages to the memory node cluster and the storage node cluster in the order of the log sequence number LSN of the log record corresponding to the cached dirty data page from small to large comprises: The dirty data pages in the dirty page queue of the second computing node are sequentially written to the storage node cluster by the first process from the head of the dirty page queue, wherein the dirty data pages are arranged in the order of the LSN of the corresponding log record from small to large from the head to the tail of the dirty page queue; The data pages in the dirty page queue are sequentially written to the memory node cluster by the second process from the next data page of the last data page written to the memory node cluster in the dirty page queue.
11. The method of claim 10, wherein, The method further comprises: After stopping writing the dirty data pages to the memory node cluster and the storage node cluster, the dirty data pages written to the storage node cluster in the dirty page queue are deleted.
12. The method according to any one of claims 9 to 11, characterized in that, The computing node cluster further comprises a third computing node, and the method further comprises: In the case that the distance between the first record position and the second record position is greater than a first threshold, a dirty page identification list is cached in the third computing node, the dirty page identification list comprising the identification of the dirty data page cached in the second computing node.
13. A data recovery apparatus, characterized by comprising: The data recovery apparatus comprises at least one module for executing the data recovery method of any one of claims 1 to 8.
14. A data storage device, characterized by The data storage apparatus comprises at least one module for executing the data storage method of any one of claims 9 to 12.
15. A distributed system, characterized by The distributed system comprises a computing node cluster and a memory node cluster, the computing node cluster communicating with the memory node cluster through a network, the computing node cluster comprising a first computing node and a second computing node, the memory node cluster comprising a first memory node, the second computing node being configured to execute the data storage method of any one of claims 9 to 12, in the case that the second computing node is abnormal and each memory node in the memory node cluster is normal, the first computing node being configured to execute the data recovery method of any one of claims 1 to 5, in the case that the first memory node is abnormal, the first computing node being configured to execute the data recovery method of any one of claims 6 to 8.
16. The distributed system of claim 15, wherein, The computing node cluster and the memory node cluster are both distributed clusters.
17. A computer device, comprising: The computer device comprises a processor and a memory, the memory is used for storing a computer program and a data page, and the processor is used for executing the computer program to realize the data recovery method in any one of claims 1 to 8 or the data storage method in any one of claims 9 to 12.
18. A computer-readable storage medium, characterized in that, The computer readable storage medium stores instructions, and when the instructions run on the computer device, the computer device executes the data recovery method in any one of claims 1 to 8 or the data storage method in any one of claims 9 to 12.
19. A computer program product comprising instructions, characterized in that, The instructions are run on the computer device, and the computer device executes the data recovery method in any one of claims 1 to 8 or the data storage method in any one of claims 9 to 12.
Citation Information
Patent Citations
Managing database recovery time
CN102682069A
Data processing method and device, electronic equipment and storage medium
CN114785807A
Data recovery method and device
CN116266175A
Data recovery method and device, computer equipment and storage medium
CN117076197A
Write-behind optimization of covering cache
US20220414015A1