Database system recovery, index file generation method, and database system
By generating log index files and indexing them based on data page identifiers, the inefficiency of replaying log files in complex failure scenarios of database systems is solved, and efficient database recovery is achieved.
Patent Information
- Application Number
- CN202510686459.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-26
- Publication Date
- 2026-11-27
AI Technical Summary
When database systems face complex failure scenarios, log replay requires a full scan and replay of the log file, which leads to repeated loading of the same data page for line-by-line modification operations, resulting in low read and write efficiency, excessively long recovery time, and a complex process.
By generating a log index file, the replay log file is indexed and arranged based on the page identifier of the data page. The replay operation is then performed in the order of the data pages, avoiding loading the same data page multiple times and skipping the already persisted modification operations.
It significantly reduces the complexity of log scanning and data page operations, improves recovery efficiency, shortens recovery time, and provides a better database system user experience.
Smart Images

Figure CN123178164A_ABST
Abstract
Description
Technical Field
[0001] This specification relates to the technical fields of big data and databases, and in particular to a database system recovery method, an index file generation method, and a database system. Background Technology
[0002] With the rapid development of information technology, database systems have become an indispensable core infrastructure in internet services, undertaking the tasks of storing, managing, and analyzing massive amounts of data. The accuracy and availability of data in a database system directly determine service continuity and service quality.
[0003] Currently, in actual operation, database systems often face the need for data restoration. For example, in scenarios where a server unexpectedly loses power and transactions are interrupted, it is necessary to roll back uncommitted operations. Another example is the need for partial data repair when data synchronization between distributed database nodes fails. Yet another example is the need for full data recovery after dealing with ransomware attacks.
[0004] However, when faced with complex and ever-changing failure scenarios, the fault tolerance and recovery mechanisms of database systems often suffer from low read / write efficiency and the inability to effectively skip persistent modifications. This is because log replay requires a full scan of the replay log file, and replay log entries record multiple modifications to the same data page. During the replay operation, the same data page needs to be loaded repeatedly for each modification, leading to excessively long recovery times and complex recovery processes. Therefore, there is an urgent need for an efficient and simple database system recovery method. Summary of the Invention
[0005] In view of this, embodiments of this specification provide a database system recovery method. One or more embodiments of this specification also relate to an index file generation method, a database system, a computing device, a computer-readable storage medium, and a computer program product, to address the technical deficiencies existing in the prior art.
[0006] According to a first aspect of the embodiments of this specification, a database system recovery method is provided, comprising: Based on the checkpoints of the database system, obtain the log index file corresponding to the replay log file. The replay log entries in the replay log file are generated after the data page in the database system is modified. Any log index entry in the log index file records the page identifier of the modified data page. Parse the log index file and arrange multiple log index entries in the log index file according to the page identifier of the data page; According to the order of multiple log index entries, the corresponding replay log entries are read from the replay log file, and the replay operation is performed on the data pages based on the replay log entries until the recovered database system is obtained.
[0007] According to a second aspect of the embodiments of this specification, an index file generation method is provided, comprising: After performing modification operations on data pages in the database system, the corresponding replay log entries are generated and written to the replay log file; Create a corresponding log index entry for each replay log entry, where the log index entry records the page identifier of the modified data page; Based on the generation order of each replay log entry, the log index entries corresponding to each replay log entry are sequentially written into the log index file corresponding to the replay log file. The log index file and the replay log file are used in the above database system recovery method.
[0008] According to a third aspect of the embodiments of this specification, a database system is provided, including a database recovery module; the database recovery module is configured to: Based on the checkpoints of the database system, obtain the log index file corresponding to the replay log file. The replay log entries in the replay log file are generated after the data page in the database system is modified. Any log index entry in the log index file records the page identifier of the modified data page. Parse the log index file and arrange multiple log index entries in the log index file according to the page identifier of the data page; According to the order of multiple log index entries, the corresponding replay log entries are read from the replay log file, and the replay operation is performed on the data pages based on the replay log entries until the recovered database system is obtained.
[0009] According to a fourth aspect of the embodiments of this specification, a computing device is provided, comprising: Memory and processor; The memory is used to store computer programs / instructions, and the processor is used to execute the computer programs / instructions, which implement the steps of the above method when executed by the processor.
[0010] According to a fifth aspect of the embodiments of this specification, a computer-readable storage medium is provided that stores a computer program / instructions that, when executed by a processor, implement the steps of the above-described method.
[0011] According to a sixth aspect of the embodiments of this specification, a computer program product is provided, including a computer program / instructions that, when executed by a processor, implement the steps of the above-described method.
[0012] This specification provides a database system recovery method according to one embodiment, comprising: obtaining a log index file corresponding to a replay log file based on a checkpoint of the database system, wherein the replay log entries in the replay log file are generated after a modification operation is completed on a data page in the database system, and any log index entry in the log index file records the page identifier of the modified data page; parsing the log index file, arranging multiple log index entries in the log index file according to the page identifier of the data page; reading the corresponding replay log entries from the replay log file according to the arrangement order of the multiple log index entries, and performing a replay operation on the data page based on the replay log entries, until the recovered database system is obtained.
[0013] The log index file obtained based on checkpoints records the data page identifiers corresponding to each log entry. By parsing and arranging log index entries according to page identifiers, multiple modification operations on the same data page are aggregated. During replay, all modifications can be executed sequentially by loading the data page only once, avoiding the redundant read and write overhead of loading the same data page multiple times. Simultaneously, persistent log entries can be skipped based on checkpoint information, reducing the amount of data to be processed. Through structured indexing and ordered replay mechanisms, the complexity of log scanning and data page operations is significantly reduced, improving recovery efficiency and shortening recovery time. Attached Figure Description
[0014] Figure 1 This is a flowchart illustrating a database system recovery method provided in one embodiment of this specification; Figure 2 This is a schematic diagram of the architecture of a database system recovery method provided in one embodiment of this specification; Figure 3 This is a flowchart illustrating an index file generation method provided in one embodiment of this specification; Figure 4 This is a schematic diagram illustrating a method for generating an index file according to one embodiment of this specification. Figure 5 This is a schematic diagram of logical segmentation in an index file generation method provided in one embodiment of this specification; Figure 6 This is a schematic diagram of the structure of a database system provided in one embodiment of this specification; Figure 7 This is a structural block diagram of a computing device provided in one embodiment of this specification. Detailed Implementation
[0015] Many specific details are set forth in the following description to provide a full understanding of this specification. However, this specification can be implemented in many other ways than those described herein, and those skilled in the art can make similar extensions without departing from the spirit of this specification. Therefore, this specification is not limited to the specific implementations disclosed below.
[0016] The terminology used in one or more embodiments of this specification is for the purpose of describing particular embodiments only and is not intended to be limiting of the one or more embodiments of this specification. The singular forms “a,” “described,” and “the” as used in one or more embodiments of this specification and the appended claims are also intended to include the plural forms unless the context clearly indicates otherwise. It should also be understood that the term “and / or” as used in one or more embodiments of this specification refers to and includes any or all possible combinations of one or more associated listed items.
[0017] It should be understood that although the terms first, second, etc., may be used to describe various information in one or more embodiments of this specification, such information should not be limited to these terms. These terms are only used to distinguish information of the same type from one another. For example, first may also be referred to as second without departing from the scope of one or more embodiments of this specification, and similarly, second may also be referred to as first. Depending on the context, the word "if" as used herein may be interpreted as "when," "when," or "in response to a determination."
[0018] Furthermore, it should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in one or more embodiments of this specification are all information and data authorized by the user or fully authorized by all parties. Moreover, the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.
[0019] First, the terms and concepts used in one or more embodiments of this specification will be explained.
[0020] MySQL, an open-source relational database management system, is based on Structured Query Language (SQL) for data storage, querying, and management. It employs a client-server architecture, supports multi-threaded and multi-user concurrent access, and provides ACID (Atomicity, Consistency, Isolation, Durability) transaction properties. It is suitable for web applications, online transaction processing (OLTP), and other scenarios. MySQL achieves data persistence, index optimization, and transaction support through its storage engine, possessing high availability, scalability, and cross-platform compatibility, making it one of the core database technologies widely used in the internet industry.
[0021] Redo Log: A log file in a database system used to record physical layer data modification operations, ensuring the durability of transactions. When a database system crashes or experiences an abnormal interruption, data pages can be restored to their state before the crash by replaying each entry in the redo log file. Its contents are written sequentially, including data page identifiers, modification offsets, and specific data changes. Through checkpointing mechanisms and working in conjunction with a buffer pool, it reduces the log scan scope during recovery, ensuring data integrity and recovery efficiency.
[0022] A data page is the basic physical storage unit for managing data in a database system. It typically ranges in size from 4KB to 16KB and is used to store table data, index structures, and metadata. Each data page is located by a unique page ID and contains a page header (record metadata), row records or index nodes, and free space. Databases achieve efficient data access through page-level locking, cache management (such as buffer pools), and page splitting / merging operations. Its physical structure design directly affects disk read / write performance and storage space utilization.
[0023] Log Index: A secondary index structure for replay logs, using the page ID as the key to quickly locate all log entries related to a given page. By creating a page-level index, a full scan of the log file can be avoided, allowing direct extraction of modification records for specific pages during data recovery or node synchronization, reducing redundant read and write overhead. It is typically implemented using hash tables or B-tree structures, supporting efficient range queries and batch retrieval, optimizing log processing efficiency in distributed database fault recovery and incremental backup scenarios.
[0024] Buffer Pool: A memory cache area in a database system used to temporarily store frequently accessed data pages, reducing disk read / write operations. It manages page loading and eviction using algorithms such as LRU (Least Recently Used), maintains a dirty page (modifying unpersisted pages) marker, and periodically flushes the buffer to disk using a checkpoint mechanism. The size of the buffer pool directly affects query performance; proper configuration can significantly improve the speed of accessing hot data, while also optimizing the throughput of sequential scans and transaction commits through prefetching and batch writing.
[0025] Backup: The process by which a database system creates copies of its data using full or incremental methods to mitigate data loss caused by hardware failures, human error, or malicious attacks. Physical backups directly copy data files and logs, resulting in fast recovery; logical backups export the logical structure (such as tables and records), offering strong compatibility.
[0026] Mini-Transaction (MTR): A basic transaction unit within a database system that guarantees the atomicity of operations and data consistency. It is used to manage atomic modifications to a single data page or cross-page operations (such as B-tree splitting). A mini-transaction contains multiple log records, and concurrent access is controlled through global locks or latches, ensuring that operations are either fully committed (generating continuous logs and flushing them to disk) or fully rolled back. Its design avoids data corruption caused by partial writes and, combined with replay log files, provides precise log replay boundaries for crash recovery.
[0027] Red-black tree: A self-balancing binary search tree that maintains approximate balance through color marking (red / black) and rotation operations, ensuring that the time complexity of insertion, deletion and search operations is O(log n).
[0028] With the rapid development of information technology, database systems have become an indispensable core infrastructure in internet services, undertaking the tasks of storing, managing, and analyzing massive amounts of data. The accuracy and availability of data in a database system directly determine service continuity and service quality. In actual operation, database systems often face the need for data restoration, such as when user errors lead to data corruption in tables or the entire database, or when users need to sample and compare historical data in game rollback scenarios.
[0029] However, when faced with complex and ever-changing fault scenarios, the fault tolerance and recovery mechanisms of database systems often suffer from problems such as long recovery times and complex recovery processes. This is because log replay requires a full scan of the replay log file, and the replay log entries record multiple modifications to the same data page. During the replay operation, the same data page needs to be loaded repeatedly for each modification, resulting in low read and write efficiency and the inability to effectively skip persistent modifications.
[0030] To address the aforementioned issues, this specification provides a database system recovery method in one embodiment. This method generates and persists a log index file by indexing and organizing the replay log file, thereby providing the database with the ability to index the replay log file on demand. In this way, during database restoration, all replay log entries for a specific data page can be quickly located and retrieved. This allows for database restoration to be completed in the order of data pages, rather than the traditional order of replay log entries. This effectively avoids repeated read and write operations on data pages on disk, significantly reduces the complexity of log scanning and data page operations, improves recovery efficiency, shortens recovery time, and provides users with a better user experience.
[0031] This specification provides a database system recovery method, and also relates to an index file generation method, a database system, a computing device, a computer-readable storage medium, and a computer program product, which will be described in detail in the following embodiments.
[0032] See Figure 1 , Figure 1 This specification shows a flowchart of a database system recovery method according to an embodiment, including the following specific steps: Step 102: Based on the checkpoints of the database system, obtain the log index file corresponding to the replay log file. The replay log entries in the replay log file are generated after the data pages in the database system have been modified. Any log index entry in the log index file records the page identifier of the modified data page.
[0033] A database system is a software system used to store, manage, and retrieve data. It consists of a database engine, storage engine, query processor, and transaction management module, supporting the persistence and concurrent access of structured or semi-structured data. Database systems ensure data consistency through transaction mechanisms (such as ACID) and use replay log files for fault recovery. Examples include relational databases such as MySQL and PostgreSQL, and non-relational database systems such as MongoDB.
[0034] In a database system, a data page is the basic physical storage unit for managing data. It consists of a fixed-size contiguous block of disk space and is used to store table data, index structures, and metadata. Data pages are addressed by a unique page ID and contain a page header (storing metadata such as checksums and log sequence numbers), row records or index nodes, and free space.
[0035] The page identifier is a unique code used to identify a data page. It consists of the tablespace identifier, page number, and possibly segment identifier, and serves as the basis for locating the target page in the log entry. Optionally, the page identifier is usually represented as a 64-bit integer, with the high-order bits representing the tablespace identifier and the low-order bits representing the page number, ensuring global uniqueness. For example, in MySQL, the page identifier format is (space_id, page_no), such as (0x001, 0x1A3B) representing page 6715 of tablespace 1.
[0036] In a database system, a checkpoint is a periodically recorded persistent state marker used to identify all log entries that have been successfully flushed to disk up to a specific point in time, along with their corresponding data page versions. Optionally, checkpoints use Log Sequence Numbers (LSNs) to record the persistence progress of log files, so that during crash recovery, only log entries after the checkpoint need to be processed. For example, checkpoints in a database engine record the range of log sequence numbers for dirty pages in the buffer pool.
[0037] Replay log files are sequentially recorded sets of physical layer data modification operations, used to reapply non-persistent modifications to restore data consistency after a system crash. Optionally, replay log files are written append-only, and each replay log entry includes the target page identifier, modification offset, new data, and log sequence number, with persistence ensured through a log write-ahead mechanism. For example, MySQL's Redo Log 1 and Redo Log 2 files cyclically write replay log entries.
[0038] A replay log entry is the basic record unit in the replay log file, describing an atomic modification operation on a single data page. Optionally, a replay log entry includes a header (log sequence number, page identifier, operation type) and a payload (modification location, data length, specific value). For example, a replay log entry that writes 8 bytes of data 0x12345678 at offset 0x100 of data page with page identifier 0x1A3B would have Redo Record 1 in Redo Log 1 as: { lsn: 0x1000, / / Log Sequence Number page_id: (0x001, 0x1A3B), / / Target page identifier (tablespace 1, page 6715) operation_type: "WRITE_DATA", / / Operation type (write data) offset: 0x100, / / Modify the offset within the page (at byte 256). data_length: 8, / / Data length (8 bytes) data: 0x12345678ABCDEF00, / / The specific data value written checksum: 0x9A7B3C21 / / Checksum (CRC32) } The log index file corresponding to the replay log file is an auxiliary index structure generated based on the replay log file, mapping data page identifiers to the physical location or log sequence number range of the relevant replay log entries. Optionally, the log index file is organized using a data structure (such as a red-black tree, B-tree, or hash table) to support fast retrieval of replay log entries by page identifier, avoiding full scans. For example, the log index file LogIndex has page identifiers as keys and an array of file offsets for all replay log entries on that data page as values.
[0039] A log index entry is the basic record unit in the log index file, associated with a specific data page identifier and one or more modification records in the replay log file. Optionally, a log index entry includes a page identifier, a log sequence number range, and a log file offset, supporting range queries. For example, a log index entry { page_id: 0x1A3B, / / Data page identifier start_lsn: 0x1000, / / Starting log sequence number end_lsn: 0x1200, / / End log sequence number offset: 0x5000, / / Physical offset in the replay log file related_Redo Records: [ / / Metadata of associated log entries] {lsn: 0x1000, length: 64}, / / First log entry (LSN=0x1000, 64 bytes) {lsn: 0x1100, length: 48}, / / Second log entry (LSN=0x1100, 48 bytes) {lsn: 0x1200, length: 72} / / Third log entry (LSN=0x1200, 72 bytes) ] } Based on the checkpoints of the database system, the log index file corresponding to the replay log file can be obtained. One possible method is to load the log index file corresponding to the replay log file from the disk based on the checkpoints of the database system. Another possible method is to read the log index file corresponding to the replay log file through memory mapping based on the checkpoints of the database system. No particular method is specified here.
[0040] For example, during the recovery process of a database system, checkpoints are recorded in the header information of the ibdata1 file. When the system starts recovery, starting from checkpoint LSN=0x5000, the log index file LogIndex corresponding to the Redo Log file is loaded from disk. "page_id": 1: LogIndex 1: {Redo Record 2}, "page_id": 2: LogIndex 2: {Redo Record 5}, "page_id": 2: LogIndex 3: {Redo Record 6}, "page_id": 1: LogIndex 4: {Redo Record 1}, "page_id": 2: LogIndex 5: {Redo Record 4}, "page_id": 1: LogIndex 6: {Redo Record 3}.
[0041] In step 102, the recovery scope is limited by checkpoints, reducing the amount of log scanning and improving recovery efficiency.
[0042] Step 104: Parse the log index file and arrange multiple log index entries in the log index file according to the page identifier of the data page.
[0043] Arranging multiple log index entries in the log index file according to the page identifier of the data page can be done in two ways: one is to arrange the multiple log index entries in the log index file in descending order according to the page identifier of the data page, and the other is to use a red-black tree to dynamically sort the multiple log index entries in the log index file according to the page identifier of the data page. No particular method is specified here.
[0044] For example, the log index file LogIndex is parsed, and multiple log index entries in the log index file are arranged according to the page identifier "page_id" of the data page: {"page_id": 1:} LogIndex 4: {Redo Record 1}, LogIndex 1: {Redo Record 2}, LogIndex 6: {Redo Record 3}}, {"page_id": 2:} LogIndex 5: {Redo Record 4}, LogIndex 2: {Redo Record 5}, LogIndex 3: {Redo Record 6}}.
[0045] In step 104, the log entries are aggregated by page identifiers to avoid repeated loading of the same data page in the future.
[0046] Step 106: Read the corresponding replay log entries from the replay log file according to the order of the multiple log index entries, and perform replay operations on the data pages based on the replay log entries until the recovered database system is obtained.
[0047] Multiple log index entries are sorted in ascending or descending order based on the numerical value of the data page identifier. Replay log entries with the same page identifier are sorted by log sequence number. For example, in MySQL, log entries with page identifiers (0x001, 0x1A3B) are processed before those with (0x002, 0x0F1C).
[0048] The recovered database system is a database instance that has reached a consistent state with the state before the crash after log replay, and its data page content is consistent with the result of the last successfully committed transaction. For example, after MySQL recovery, the checksum of the data pages of all InnoDB tablespace files matches the final log sequence number of the replayed log.
[0049] The corresponding replay log entries are read from the replay log file according to the order of the multiple log index entries. One option is to read the corresponding replay log entries from the replay log file asynchronously according to the order of the multiple log index entries. Another option is to read the corresponding replay log entries from the replay log file sequentially according to the order of the multiple log index entries. No particular method is specified here.
[0050] For example, the replay log entry with page_id=1 is processed first. The replay log file RedoLog is loaded from disk. Redo Record 4 (writing data 0x1234 to page 1 offset 0x100) is read asynchronously from offset 0x5000, Redo Record 1 (deleting data at page 1 offset 0x200) is read from offset 0x5200, and Redo Record 6 (writing data 0x4567 to page 1 offset 0x100) is read from offset 0x5300. Data page 1 is loaded into memory in a single batch. The modifications to Redo Records 4, 1, and 6 are applied sequentially, and the final page version is generated and then flushed to disk. RedoRecords 5, 2, and 3 are processed in a similar batch manner.
[0051] In the embodiments described in this specification, the log index file obtained based on checkpoints records the data page identifiers corresponding to each log entry. By parsing and arranging the log index entries according to the page identifiers, multiple modification operations on the same data page are aggregated. During replay, only a single data page load is needed to sequentially execute all modifications, avoiding redundant read and write overhead from loading the same data page multiple times. Simultaneously, persistent log entries can be skipped based on checkpoint information, reducing the amount of data to be processed. Through structured indexing and ordered replay mechanisms, the complexity of log scanning and data page operations is significantly reduced, recovery efficiency is improved, and recovery time is shortened.
[0052] In one optional embodiment of this specification, step 104, which arranges multiple log index entries in the log index file according to the page identifier of the data page, includes the following specific steps: Arrange multiple log index entries in the log index file from largest to smallest according to the page identifier of the data page.
[0053] For example, when parsing the log index file LogIndex, the log index entries are sorted in descending order by page identifier value, forming the following structure: {"page_id":2:LogIndex 5,LogIndex 2,LogIndex 3}, {"page_id":1:LogIndex 4, LogIndex 1, LogIndex 6}.
[0054] Entries on the same page are organized in ascending order of log sequence number to ensure that the order in which modification operations are applied is consistent with the order in which transactions are committed. By reducing the log scan complexity from O(n) to O(logn) and improving read / write throughput through read-ahead optimization, recovery time increases linearly with the size of the data page.
[0055] In the embodiments described in this specification, efficient merge sorting of log entries is achieved by arranging page identifiers in descending order and combining them with the priority rules of a min-heap. By utilizing the local ordering of the log index file, data pages with higher page identifiers are processed first to reduce random access. At the same time, the global order among multiple files is dynamically maintained to avoid the read and write overhead of full sorting.
[0056] In one optional embodiment of this specification, there are multiple log index files, each with a file identifier; the multiple log index entries in the log index files are arranged from largest to smallest according to the page identifier of the data page, including the following specific steps: If the page identifiers of data pages are the same size, the log index entries in multiple log index files are arranged from largest to smallest according to the log index entries.
[0057] For example, for three log index files LogIndex_A, LogIndex_B, and LogIndex_C, when they contain entries with the same page identifier 1, they are arranged in reverse order by file identifier as follows: Redo Record 3 of LogIndex_C, Redo Record 2 of LogIndex_B, and Redo Record 1 of LogIndex_A, ensuring that higher version logs are processed first.
[0058] In the embodiments described in this specification, a secondary sorting strategy based on file identifiers is used to maintain the version priority of modification operations in scenarios with multiple log files.
[0059] In one optional embodiment of this specification, the following specific steps are included before step 106: The sorted log index files are then sequentially placed into a top-heap structure. Step 106 involves reading the corresponding replay log entries from the replay log file according to the order of the multiple log index entries, including the following specific steps: Multiple log index entries are retrieved sequentially from the top heap structure, and the corresponding replay log entries are read from the replay log file.
[0060] Since all log index entries in the log index files are stored in order of page identifiers, this means that when you need to retrieve all log index entries with the smallest page identifier, you only need to read the corresponding log index entries from the beginning of the log index file. For example, to retrieve all log index entries with page identifier Pageno=0, you only need to read the log index entries at the beginning of the log index file. If the page identifier Pageno at the beginning of the file is not 0, it means that the page identifier Pageno must be greater than 0, because the file is organized in order of page identifier Pageno.
[0061] The min-heap structure is a priority queue data structure implemented based on a complete binary tree. The sorting key of the parent node is always less than that of the child nodes, thus supporting efficient insertion and extreme value extraction operations. Using a min-heap structure with page identifiers as the sorting key, the global order of log index entries is dynamically maintained. For example, during initialization, the first entry of each log index file is inserted into the heap. After each extraction of the entry with the smallest page identifier, the next entry of the file to which that entry belongs is added, ensuring that the heap always contains the current smallest candidate entry.
[0062] Multiple log index entries are sequentially retrieved from the top heap structure, and the corresponding replay log entries are read from the replay log file. One possible approach is to sequentially retrieve multiple log index entries from the top heap structure and asynchronously read the corresponding replay log entries from the replay log file. Another possible approach is to sequentially retrieve multiple log index entries from the top heap structure and synchronously read the corresponding replay log entries from the replay log file. No particular method is specified here.
[0063] For example, for the first entries (page identifiers 3, 1, and 2) of three log index files LogIndex_A, LogIndex_B, and LogIndex_C, after constructing a min-heap, the entries are output sequentially as follows: page 1 entry of LogIndex_B → page 2 entry of LogIndex_C → page 3 entry of LogIndex_A. Each time an entry is output, the next entry (e.g., the second log entry on page 1) is read from the corresponding file and inserted into the heap, repeating this process until all entries have been processed.
[0064] In the embodiments of this specification, a top-heap structure is used to implement streaming merge sort of multi-source log index entries. Only a fixed space overhead is required to maintain the global order, avoiding the disk read and write consumption generated during the full sorting process.
[0065] In one optional embodiment of this specification, multiple log index entries are sequentially retrieved from the top heap structure, and the corresponding replay log entries are read from the replay log file, including the following specific steps: Multiple log index entries are retrieved sequentially from the top heap structure, and an asynchronous read thread is scheduled to read the corresponding replay log entries from the replay log file.
[0066] An asynchronous read thread is an execution unit that performs multiple asynchronous recovery processes. It is used to perform disk I / O operations in parallel, reading log entries from the replay log file in a non-blocking manner, avoiding blocking while waiting for input / output from other asynchronous read threads. Optionally, asynchronous read threads are managed through event-driven or thread pool mechanisms, triggering callbacks to notify the main thread to process the data upon completion of the read operation. For example, in a MySQL recovery process, one asynchronous read thread prefetches log entries from the Redo Log file up to page 2, while another asynchronous read thread simultaneously processes the log entries from the current page up to page 1, achieving overlap between computation and input / output.
[0067] For example, in a MySQL recovery scenario, an asynchronous read thread retrieves the log index entry for page identifier 1 (Redo Record 1 of LogIndex_B) from a min-heap and immediately schedules another asynchronous read thread to load Redo Record 2 (offset 0x5200) for the subsequent page identifier 1 from disk, avoiding waiting for disk I / O.
[0068] In the embodiments described in this specification, the parallelization of computation and input / output is achieved through an asynchronous read thread, eliminating the input / output waiting delay of traditional serial recovery.
[0069] In one optional embodiment of this specification, scheduling an asynchronous read thread to read the corresponding replay log entry from the replay log file includes the following specific steps: An asynchronous read thread is scheduled to access the disk and read the corresponding replay log entries from the replay log file stored on the disk.
[0070] A hard disk is a non-volatile storage device used for persistent storage of data files, log files, and index files in a database system. It achieves data reading and writing through mechanical addressing of the read / write head on a rotating disk platter, offering advantages such as large capacity and low cost, but suffers from performance bottlenecks such as seek time and rotational latency. In database recovery scenarios, the hard disk stores replay log files and log index files. Asynchronous read threads directly access the physical blocks of the disk through the file system interface, bypassing the operating system's page cache to reduce data copy overhead. For example, during MySQL recovery, the Redo Log file is read from the disk partition.
[0071] For example, during MySQL crash recovery, while one asynchronous read thread processes Redo Record 1 (modifying data at offset 0x100 of page 1) for page identifier 1, another asynchronous read thread calls a batch loading function from the RedoLog file (ib_logfile0) of disk partition / dev / sdb1 to load Redo Record 2 (offset 0x5200) and Redo Record 3 (offset 0x5300) for subsequent page identifier 1 into a memory buffer.
[0072] In the embodiments described in this specification, a parallel pipeline is adopted through direct disk input / output and asynchronous prefetching mechanism to reduce disk waiting time. Combined with a batch loading strategy, multiple replay log entries can be read in a single input / output operation, which significantly shortens the recovery time of large-scale databases.
[0073] In one optional embodiment of this specification, after scheduling an asynchronous read thread to access the disk and read the corresponding replay log entry from the replay log file stored on the disk, the following specific steps are further included: Using the page identifier of the data page as an index, the corresponding replay log entries are stored in the replay buffer. Among them, the replay log entries corresponding to the same page identifier are stored in the replay buffer consecutively in the order of generation. Step 106 involves performing a replay operation on the data page based on the replay log entries, including the following specific steps: Use the page identifier of the data page as the key to read the corresponding replay log entry from the replay buffer; According to the generation order of replay log entries, replay log entries under the same page identifier are merged to generate replay operation instructions; Run the replay operation command to perform batch replay operations on data pages in the database system.
[0074] The replay buffer is a temporary, in-memory storage area used to aggregate replay log entries read from the replay log file, page-based. The replay buffer organizes data using a key-value pair structure, where the key is the page identifier of the data page, and the values are all replay log entries corresponding to that page, sorted in ascending order of log sequence number. For example, in MySQL recovery, the replay buffer is implemented as a hash table, with keys being combinations of (space_id, page_no) and values being linked lists of Redo Records, supporting fast page-based retrieval and sequential merge operations.
[0075] The key is an index value used to uniquely identify a data entry in the replay buffer; in this embodiment, it specifically refers to the page identifier of the data page. It consists of a tablespace representation and a page number, such as a (space_id, page_no) tuple in MySQL. The key design must satisfy global uniqueness and efficient comparison characteristics, and is typically implemented using 64-bit integer encoding or a structure.
[0076] For example, in a MySQL recovery scenario, the asynchronous read thread loads the following log entries from disk and then stores them in the replay buffer: Redo Record 1 {page_id: (1, 10), lsn: 1000, data: "A"} Redo Record 2 {page_id: (1, 20), lsn: 1100, data: "B"} Redo Record 3 {page_id: (1, 10), lsn: 1200, data: "C"} The replay buffer eventually forms the following structure: (1, 10) ->[Redo Record 1, Redo Record 3] (1, 20) ->[Redo Record 2] When the main thread processes page (1, 10), it directly retrieves the two corresponding log entries and merges them in log sequence number order.
[0077] In the embodiments described in this specification, memory-level aggregation and sorting of log entries are achieved through a replay buffer, ensuring that all modifications can be completed in a single data page load, thereby reducing random disk reads and writes.
[0078] In one optional embodiment of this specification, before running the replay operation instruction to perform a batch replay operation on the data pages in the database system, the following specific steps are further included: Based on the page identifier, access the disk to read the target data pages in batches and store the target data pages into memory in batches. Running the replay operation command performs a batch replay operation on data pages in the database system, including the following specific steps: Run the replay operation instructions to read target data pages in batches from memory and perform batch replay operations on the target data pages.
[0079] For example, in a MySQL recovery scenario, when it is necessary to process data pages (1, 10) and (1, 20): Retrieve all log entries (Redo Record 1 and Redo Record 3) from data page (1, 10) in the replay buffer. Based on the page identifier (1, 10), read the data page from disk in batches into memory. Apply changes in log sequence number order: First, apply Redo Record 1 with LSN=1000 (write "A"); Then apply Redo Record 3 with LSN=1200 (change it to "C"); Flush the final state data page (1, 10) to disk; Similarly, Redo Record 2 for data page (1, 20) is processed.
[0080] In the embodiments described in this specification, a replay buffer and batch processing mechanism is used, and a batch preloading mechanism is adopted to merge multiple discrete read and write operations on the same data page into a single sequential read, thereby shortening the recovery time of large-scale databases.
[0081] Refer to the above Figure 1 Method Implementation Examples Figure 2 This specification illustrates a schematic diagram of the architecture of a database system recovery method according to one embodiment. Figure 2 As shown: To retrieve all log index entries with page identifier 0, simply read the beginning of all log index files. If the page identifier at the beginning of the file is not 0, it means that the page identifier must be greater than 0, because the file is organized in order according to page identifiers.
[0082] Read the first batch of log index entries from the log index files corresponding to all replay log files, and insert them into the top heap structure in order of page identifier and file number. Take the log index entries corresponding to a page identifier (let's say i) from the top of the top heap structure. Load the data page with page identifier i into the buffer pool. Apply these log index entries to the corresponding data pages to complete the recovery operation for those pages.
[0083] If there are more log index entries available to read in the current file, continue reading. At this point, the page identifier corresponding to the log index entry being read will definitely not be 'i'. Insert the newly read log index entries into the top heap structure.
[0084] If the min-heap is not empty, return to continue execution and retrieve the batch of log index entries corresponding to a page identifier (let's say i) from the top of the min-heap until all log index entries have been processed and applied to the corresponding data pages. It's important to note that during the application of log index entries, if the current page identifier differs from the previous page identifier, it indicates that all log index entries for the previous page identifier have been fully applied. Therefore, this process ensures that the log index entries for the next data page are only processed after all log index entries for one data page have been applied. In this way, the recovery process for each data page only requires reading from disk once and writing once after recovery, significantly reducing the number of read / write operations and improving recovery efficiency.
[0085] Thanks to the min-heap design, replay log entries on the same data page are read and applied sequentially. Furthermore, to further improve the efficiency of reading the log index file, the task of reading the next batch of replay log entries is delegated to a background read / write thread for asynchronous execution. This design not only effectively improves disk read bandwidth utilization but also significantly accelerates the process of applying replay log entries to data pages, thereby greatly enhancing the overall efficiency of data recovery.
[0086] See Figure 3 , Figure 3 A flowchart of an index file generation method according to an embodiment of this specification is shown, including the following specific steps: Step 302: After performing modification operations on data pages in the database system, generate corresponding replay log entries and write the replay log entries to the replay log file.
[0087] Generating replay log entries is the process of encoding physical modification operations on data pages into log records, which include the target page identifier, modification location, new data, and metadata.
[0088] Writing replay log entries to the replay log file is the action of persisting log entries to the disk log file, and it is usually done by appending.
[0089] After performing modification operations on data pages in the database system, corresponding replay log entries are generated. One possible approach is to call the transaction thread to generate the corresponding replay log entries after performing modification operations on data pages in the database system. Another possible approach is to call the transaction thread to collect the modification records of mini-transactions in batches after performing modification operations on data pages in the database system and then generate the corresponding replay log entries. No particular method is specified here.
[0090] One option for writing replay log entries to the replay log file is to write the replay log entries from the log buffer to the replay log file. Another option is to use a memory-mapped file to write the replay log entries to the replay log file. No particular method is specified here.
[0091] For example, in MySQL, transaction T1 modifies the data "ABC" at offset 0x100 on page (0x001, 0x1A3B), generating a replay log entry: { "lsn": 0x2000, "page_id": (0x001, 0x1A3B), "offset": 0x100, "data": "ABC", "checksum": 0x8E3D } Write the replay log entry from the log buffer to the replay log file LogIndex and update the log sequence number.
[0092] In step 302, the atomicity and durability of transaction modifications are ensured, providing a foundation for crash recovery.
[0093] Step 304: Create a corresponding log index entry for the replay log entry, wherein the log index entry records the page identifier of the modified data page.
[0094] To create corresponding log index entries for replay log entries, one option is to call the index building thread to generate log index entries based on the page identifier and log sequence number of the replay log entry. Another option is to use a red-black tree structure in memory to create corresponding log index entries for replay log entries by page identifier. Yet another option is to use a batch processing mechanism to merge log index entries of multiple mini-transactions into log index entries with the same page identifier. This option is not limited here.
[0095] For example, create an index entry for the log entry of T1 above: { "page_id": (0x001, 0x1A3B), "start_lsn": 0x2000, "end_lsn": 0x2000, "file_offset": 0x8000 } A red-black tree index structure stored in memory.
[0096] In step 304, corresponding log index entries are created for the replay log entries, providing index support for accelerating page-by-page retrieval of log entries and avoiding full scans.
[0097] Step 306: According to the generation order of each replay log entry, write the log index entries corresponding to each replay log entry into the log index file corresponding to the replay log file in sequence. The log index file and the replay log file are used in the above database system recovery method.
[0098] For example, MySQL's LogIndex_Flusher thread sorts the index entries in memory by page identifier and writes them to the log index file LogIndex, in the following format: (0x001,0x1A3B) | 0x2000-0x2000 | 0x8000 (0x002,0x0F1C) | 0x2100-0x2200 | 0x8100.
[0099] In the embodiments described in this specification, by parsing and arranging log index entries according to page identifiers, multiple modification operations on the same data page are aggregated. During replay, all modifications can be executed sequentially by loading the data page only once, avoiding redundant read and write overhead from loading the same data page multiple times.
[0100] In one optional embodiment of this specification, step 306 includes the following specific steps: The scheduling index refresh thread organizes the log index entries corresponding to each replay log entry into multiple batches according to the page identifier of the data page, and writes the log index entries of each batch sequentially to the log index file corresponding to the replay log file on the disk according to the log sequence number. The log sequence number is marked according to the generation order of the replay log entries.
[0101] The index flushing thread is a background thread in the database system responsible for batch persisting log index entries from memory to disk. It ensures the real-time performance of the log index files through periodic disk flushing or threshold-triggered mechanisms. For example, MySQL's LogIndex_Flusher thread performs a disk flush every 100ms or when 1000 index entries have accumulated.
[0102] Multiple batches consist of index entries containing consecutive page identifiers (e.g., entries from pages 1-100 constitute a batch), reducing random writes by pre-allocating disk blocks.
[0103] The log sequence number is a monotonically increasing 64-bit integer that uniquely identifies the order in which log entries are generated (e.g., MySQL's log_sys->lsn increments from 0x2000 to 0x2100).
[0104] For example, the index refresh thread extracts the index entries for pages (0x001, 0x1A3B) and (0x002, 0x0F1C) from the red-black tree, sorts them by LSN, and writes them to the log index file LogIndex, in the following format: (0x001,0x1A3B) | 0x2000-0x2000 | 0x8000 (0x002,0x0F1C) | 0x2100-0x2200 | 0x8100.
[0105] In the embodiments described in this specification, batch processing and sequential writing are used to reduce the number of disk read / write operations and improve the efficiency of log index file generation.
[0106] In one optional embodiment of this specification, a scheduling index refresh thread organizes the log index entries corresponding to each replay log entry into multiple batches according to the page identifier of the data page, and sequentially writes the log index entries of each batch into the log index file corresponding to the replay log file on the disk according to the log sequence number, including the following specific steps: The scheduled index refresh thread uses the page identifier of the data page as the key to organize the log index entries corresponding to each replay log entry into multiple batches and write them into the replay buffer. Read the log index entries for each batch from the replay buffer and write them sequentially to the log index file corresponding to the replay log file on disk according to the log sequence number.
[0107] For example, the index refresh thread extracts the page identifiers (0x001, 0x1A3B) and (0x002, 0x0F1C) of the data page from the red-black tree as keys, sorts them by LSN, and writes them to the log index file LogIndex, in the following format: (0x001,0x1A3B) | 0x2000-0x2000 | 0x8000 (0x002,0x0F1C) | 0x2100-0x2200 | 0x8100. In the embodiments described in this specification, scattered index entries are merged into batch processing to reduce disk seeks and operations, thereby improving throughput. Log index files are written sequentially according to log sequence numbers, fully utilizing the high-performance characteristics of sequential disk writes and avoiding latency issues associated with random writes.
[0108] In one optional embodiment of this specification, the database system has multiple data pages; step 302 includes the following specific steps: After performing modification operations on multiple data pages in the database system, multiple parallel threads are scheduled to generate corresponding replay log entries, and the replay log entries are written to the replay log file.
[0109] Parallel threads are independent execution units that perform tasks concurrently in a database system, used to accelerate the log generation or parsing process. For example, during MySQL recovery, four redo_parser threads are started to parse different sections of the log file in parallel.
[0110] For example, thread 1 processes the update of page (0x001, 0x1A3B) and generates a replay log entry with LSN=0x2000; thread 2 processes the update of page (0x002, 0x0F1C) and generates an entry with LSN=0x2100. Both threads compete for global LSN allocation through atomic operations, ensuring the global ordering of log sequence numbers.
[0111] In the embodiments described in this specification, multiple parallel threads are scheduled to parallelize the replay log generation, thereby improving the throughput in high-concurrency transaction scenarios.
[0112] In one optional embodiment of this specification, step 302, generating the corresponding replay log entry, includes the following specific steps: Based on the basic transaction unit, the operation record of the modification operation is logically divided and stored in multiple buffer blocks; Based on the operation records of modification operations after splitting multiple buffer blocks, corresponding replay log entries are generated.
[0113] A basic transaction unit is the fundamental unit within a database that guarantees the atomicity of single-page or multi-page operations. It contains a set of indivisible physical modification operations. For example, the atomicity of a B-tree node splitting operation in MySQL is guaranteed by an MTR (Mean Transmission Principle).
[0114] Multiple buffer blocks are contiguous storage areas of fixed size in memory used to temporarily store log or index data to be processed. For example, MySQL's redo_buf caches log entries in 16KB blocks.
[0115] For example, the B-tree insertion operation of transaction T1 triggers a page split, generating three physical log records, which are split into buffer blocks Block1 and Block2. The asynchronous parsing thread parses the first two log records from Block1 and merges them into a single MTR log entry.
[0116] In the embodiments described in this specification, fine-grained log segmentation and parallel parsing are used to reduce the latency of log generation.
[0117] In one optional embodiment of this specification, based on the operation records of modification operations after segmentation in multiple buffer blocks, corresponding replay log entries are generated, including the following specific steps: Multiple asynchronous parsing threads are scheduled to generate corresponding replay log entries based on the operation records of the modified operations after being split in multiple buffer blocks. The generated replay log entries are sorted according to the log sequence number, and multiple buffer blocks are updated. The log sequence number is marked according to the generation order of the replay log entries.
[0118] Asynchronous parsing threads are log parsing units independent of the main thread, processing log data in buffer blocks asynchronously through an event-driven mechanism. For example, MySQL's redo_parser thread pool notifies the main thread to complete parsing via callbacks.
[0119] The operation log for modification operations represents the specific physical modifications made to the data page, including the target page identifier, modification offset, data length, and new data value. For example, MySQL's mlog_write_string record writes 8 bytes of data "ABC" at offset 0x100 within the page.
[0120] For example, the parsing thread reads the log block from Block1 and parses out two modification records (LSN=0x2000 and 0x2008) of page (0x001, 0x1A3B); then updates the log index red-black tree in memory after sorting by LSN.
[0121] In the embodiments of this specification, multiple asynchronous parsing threads are scheduled to generate corresponding replay log entries based on the operation records of modification operations after being segmented in multiple buffer blocks. The generated replay log entries are then sorted according to the log sequence number to update multiple buffer blocks, thereby achieving overlap between computation and read / write operations and avoiding thread blocking.
[0122] Refer to the above Figure 3 Method Implementation Examples Figure 4 This specification illustrates a thread diagram of an index file generation method according to an embodiment of the present invention, such as... Figure 4 As shown: First, multiple replay log reading threads (redoreaders) are started, simultaneously reading a segment of the replay log file into a replay buffer (redobuf) in memory. Once the replay log is successfully read, it is segmented according to the basic transaction unit (MTR) granularity. The replay buffers, segmented according to the basic transaction unit (MTR), are distributed to multiple redoParser threads. Each redoParser thread parses its own replay buffer into an independent replay log entry (redorecord). After parsing is complete, the redoParser thread hands over the generated replay log entries (redorecords) to the ParseLogManager log parsing management unit. The ParseLogManager then organizes these records according to page identifiers, ensuring that the replay log entries (redorecords) corresponding to each page identifier are arranged in LSN order. This ordering prevents errors when recovering data pages. When the ParseLogManager unit detects that the current replay log file has been completely parsed, it passes all the organized content to the LogindexFlusher thread. The LogindexFlusher thread is responsible for writing these replay log entries, organized by page identifier and ordered by Log Sequence Number (LSN), to disk, generating the corresponding log index file LogIndex. Through the above process, all replay log files will be parsed one by one, and the corresponding log index file LogIndex will eventually be generated.
[0123] The above steps efficiently generated the log index file LogIndex.
[0124] Method logic as follows Figure 5 As shown, Figure 5 This specification illustrates a schematic diagram of logical segmentation in an index file generation method according to an embodiment of the present specification: First, the replay log file is read and parsed, and then stored in a red-black tree Map structure in memory. Then, the contents of the red-black tree Map are flushed to disk in an orderly manner according to the file granularity, and finally the log index file LogIndex is generated by dividing the basic transaction unit MTR.
[0125] The above steps provide a detailed analysis of the overall process overhead, further breaking down the overhead of each step into I / O overhead and CPU overhead. The specific analysis is as follows: Generate log index files: IO overhead: The overhead of reading the replay log file is controllable because it can be read once in the order of the replay log file.
[0126] The I / O overhead of generating the log index file: After all the replay log entries in a replay log file are organized in page order and stored in a red-black tree, the contents of the red-black tree need to be written to disk. The amount of I / O writing at this point is comparable to the amount of data read from the replay log file. CPU overhead: Parsing replay log entries: Replay log entries are parsed sequentially according to the order they are read, with a time complexity of O(n), where n represents the total number of replay log entries. Storing replay log entries into a red-black tree: In the key-value pair structure of the red-black tree, the key is the page identifier (PageNo), and the value is all the replay log entries for that page in this replay log file. Because a red-black tree is used as the underlying data structure, the insertion operation has a time complexity of O(logn), where n represents the total number of pages involved in this replay log file.
[0127] Retrieve all replay log entries for each data page from the generated log index file: IO overhead: IO overhead mainly manifests in opening all generated log index files and reading the replay log entries for the target data page. Since it is necessary to traverse all replay log entries, the IO overhead is equivalent to the total number of these files read, and the overall overhead is controllable.
[0128] CPU overhead: The main CPU overhead lies in using the heap structure to locate the position of the target replay log entry to be read. The time complexity of this operation is O(logn), where n represents the total number of replay log entries.
[0129] Loading the target data page into memory and applying the replay incurs I / O overhead: I / O overhead depends on the amount of data that needs to be recovered. For example, if the database size is 10GB and all data pages have been modified, then all 10GB of data needs to be read from disk and rewritten. CPU overhead: CPU overhead is related to the total number of replay log entries that need to be applied. Each replay log entry only needs to be applied once, so the time complexity is O(n), where n represents the total number of replay log entries.
[0130] Corresponding to the above method embodiments, this specification also provides database system embodiments. Figure 6 A schematic diagram of the structure of a database system provided in one embodiment of this specification is shown. Figure 6 As shown, the database system 600 includes a database recovery module 610; the database recovery module 610 is used for: Based on the checkpoints of the database system, obtain the log index file corresponding to the replay log file. The replay log entries in the replay log file are generated after the data page in the database system is modified. Any log index entry in the log index file records the page identifier of the modified data page. Parse the log index file and arrange multiple log index entries in the log index file according to the page identifier of the data page; According to the order of multiple log index entries, the corresponding replay log entries are read from the replay log file, and the replay operation is performed on the data pages based on the replay log entries until the recovered database system is obtained.
[0131] Optionally, the database system 600 further includes an index generation module 620; the index generation module 620 is used for: After performing modification operations on data pages in the database system, the corresponding replay log entries are generated and written to the replay log file; Create a corresponding log index entry for each replay log entry, where the log index entry records the page identifier of the modified data page; Based on the generation order of each replay log entry, the log index entries corresponding to each replay log entry are sequentially written into the log index file corresponding to the replay log file.
[0132] In the embodiments described in this specification, the log index file obtained based on checkpoints records the data page identifiers corresponding to each log entry. By parsing and arranging the log index entries according to the page identifiers, multiple modification operations on the same data page are aggregated. During replay, only a single data page load is needed to sequentially execute all modifications, avoiding redundant read and write overhead from loading the same data page multiple times. Simultaneously, persistent log entries can be skipped based on checkpoint information, reducing the amount of data to be processed. Through structured indexing and ordered replay mechanisms, the complexity of log scanning and data page operations is significantly reduced, recovery efficiency is improved, and recovery time is shortened.
[0133] The above is an illustrative scheme of a database system according to this embodiment. It should be noted that the technical solution of this database system belongs to the same concept as the technical solutions of the database system recovery method and the index file generation method described above. For details not described in detail in the technical solution of the database system, please refer to the description of the technical solutions of the database system recovery method or the index file generation method described above.
[0134] Figure 7 A structural block diagram of a computing device according to one embodiment of this specification is shown. The components of the computing device 700 include, but are not limited to, a memory 710 and a processor 720. The processor 720 is connected to the memory 710 via a bus 730, and a database 750 is used to store data.
[0135] The computing device 700 also includes an access device 740, which enables the computing device 700 to communicate via one or more networks 760. Examples of these networks include a Public Switched Telephone Network (PSTN), a Local Area Network (LAN), a Wide Area Network (WAN), a Personal Area Network (PAN), or a combination of communication networks such as the Internet. The access device 740 may include one or more of any type of wired or wireless network interface (e.g., a Network Interface Controller (NIC)), such as an IEEE 802.11 Wireless Local Area Network (WLAN) interface, a Worldwide Interoperability for Microwave Access (Wi-MAX) interface, an Ethernet interface, a Universal Serial Bus (USB) interface, a cellular network interface, a Bluetooth interface, or a Near Field Communication (NFC) interface.
[0136] In one embodiment of this specification, the above-described components of the computing device 700 and Figure 7 Other components, not shown, can also be connected to each other, for example, via a bus. It should be understood that... Figure 7 The block diagram of the computing device shown is for illustrative purposes only and is not intended to limit the scope of this specification. Those skilled in the art can add or replace other components as needed.
[0137] The computing device 700 can be any type of stationary or mobile computing device, including mobile computers or mobile computing devices (e.g., tablet computers, personal digital assistants, laptop computers, notebook computers, netbooks, etc.), mobile phones (e.g., smartphones), wearable computing devices (e.g., smartwatches, smart glasses, etc.) or other types of mobile devices, or stationary computing devices such as desktop computers or personal computers (PCs). The computing device 700 can also be a mobile or stationary server.
[0138] The processor 720 is used to execute the following computer program / instruction, which, when executed by the processor, implements the steps of the above-mentioned database system recovery method or index file generation method.
[0139] The above is an illustrative scheme of a computing device according to this embodiment. It should be noted that the technical solution of this computing device belongs to the same concept as the technical solutions of the database system recovery method and the index file generation method described above. For details not described in detail in the technical solution of the computing device, please refer to the description of the technical solutions of the database system recovery method or the index file generation method described above.
[0140] An embodiment of this specification also provides a computer-readable storage medium storing a computer program / instructions that, when executed by a processor, implement the steps of the database system recovery method or index file generation method described above.
[0141] The above is an illustrative scheme of a computer-readable storage medium according to this embodiment. It should be noted that the technical solution of this storage medium belongs to the same concept as the technical solutions of the database system recovery method and the index file generation method described above. Details not described in detail in the technical solution of the storage medium can be found in the descriptions of the technical solutions of the database system recovery method or the index file generation method described above.
[0142] An embodiment of this specification also provides a computer program product, including a computer program / instructions that, when executed by a processor, implement the steps of the above-described database system recovery method or index file generation method.
[0143] The above is an illustrative scheme of a computer program product according to this embodiment. It should be noted that the technical solution of this computer program product belongs to the same concept as the technical solutions of the database system recovery method and the index file generation method described above. For details not described in detail in the technical solution of the computer program product, please refer to the description of the technical solutions of the database system recovery method or the index file generation method described above.
[0144] The foregoing has described specific embodiments of this specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recited in the claims may be performed in a different order than that shown in the embodiments and may still achieve the desired result. Furthermore, the processes depicted in the drawings do not necessarily require the specific or sequential order shown to achieve the desired result. In some embodiments, multitasking and parallel processing are possible or may be advantageous.
[0145] The computer instructions include computer program code, which may be in the form of source code, object code, executable file, or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium may be appropriately added or removed according to the requirements of patent practice. For example, in some regions, according to patent practice, computer-readable media may not include electrical carrier signals and telecommunication signals.
[0146] It should be noted that, for the sake of simplicity, the foregoing method embodiments are all described as a series of actions. However, those skilled in the art should understand that the embodiments in this specification are not limited to the described order of actions, because according to the embodiments in this specification, some steps can be performed in other orders or simultaneously. Furthermore, those skilled in the art should also understand that the embodiments described in this specification are all preferred embodiments, and the actions and modules involved are not necessarily essential to the embodiments in this specification.
[0147] In the above embodiments, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0148] The preferred embodiments disclosed above are merely illustrative of this specification. The optional embodiments do not exhaustively describe all details, nor do they limit the invention to the specific implementations described. Clearly, many modifications and variations can be made based on the embodiments described herein. These embodiments are selected and specifically described in this specification to better explain the principles and practical applications of the embodiments, thereby enabling those skilled in the art to better understand and utilize this specification. This specification is limited only by the claims and their full scope and equivalents.
Claims
1. A database system recovery method, comprising: Based on the checkpoints of the database system, obtain the log index file corresponding to the replay log file. The replay log entries in the replay log file are generated after the data page in the database system is modified. Any log index entry in the log index file records the page identifier of the modified data page. The log index file is parsed, and multiple log index entries in the log index file are arranged according to the page identifier of the data page; According to the order of the multiple log index entries, the corresponding replay log entries are read from the replay log file, and the data pages are replayed based on the replay log entries until the recovered database system is obtained.
2. The method according to claim 1, wherein arranging multiple log index entries in the log index file according to the page identifier of the data page includes: The log index entries in the log index file are arranged from largest to smallest according to the page identifier of the data page.
3. The method according to claim 2, wherein there are multiple log index files, and each log index file has a file identifier; The step of arranging multiple log index entries in the log index file from largest to smallest according to the page identifier of the data page includes: If the page identifiers of the data pages are the same size, the log index entries in the multiple log index files are arranged from largest to smallest according to the log index entries.
4. The method according to any one of claims 1-3, further comprising, before reading the corresponding replay log entry from the replay log file according to the order of the plurality of log index entries: The multiple log index entries in the sorted log index file are sequentially placed into a top-heap structure; The step of reading the corresponding replay log entry from the replay log file according to the order of the plurality of log index entries includes: The multiple log index entries are sequentially retrieved from the top heap structure, and the corresponding replay log entries are read from the replay log file.
5. The method according to claim 4, wherein sequentially retrieving the plurality of log index entries from the top heap structure and reading the corresponding replay log entries from the replay log file comprises: The multiple log index entries are sequentially retrieved from the top heap structure, and an asynchronous reading thread is scheduled to read the corresponding replay log entries from the replay log file.
6. The method according to claim 5, wherein scheduling the asynchronous reading thread to read the corresponding replay log entry from the replay log file includes: An asynchronous read thread is scheduled to access the disk and read the corresponding replay log entry from the replay log file stored on the disk.
7. The method according to claim 6, after the asynchronous read thread accesses the disk and reads the corresponding replay log entry from the replay log file stored on the disk, it further includes: Using the page identifier of the data page as an index, the corresponding replay log entries are stored in the replay buffer. Among them, the replay log entries corresponding to the same page identifier are stored in the replay buffer consecutively in the order of generation. The step of performing a replay operation on the data page based on the replay log entry includes: Using the page identifier of the data page as the key, read the corresponding replay log entry from the replay buffer; According to the generation order of the replay log entries, the replay log entries under the same page identifier are merged to generate a replay operation instruction; The replay operation instruction is executed to perform a batch replay operation on the data pages in the database system.
8. The method according to claim 7, further comprising, before executing the replay operation instruction and performing a batch replay operation on the data pages in the database system: Based on the page identifier, access the disk to read target data pages in batches, and store the target data pages in batches into memory; The execution of the replay operation instruction to perform batch replay operations on data pages in the database system includes: The replay operation instruction is executed to read target data pages in batches from the memory and perform batch replay operations on the target data pages.
9. A method for generating an index file, comprising: After performing a modification operation on a data page in the database system, a corresponding replay log entry is generated and the replay log entry is written to the replay log file; Create a corresponding log index entry for each replay log entry, wherein the log index entry records the page identifier of the modified data page; According to the generation order of each replay log entry, the log index entries corresponding to each replay log entry are sequentially written into the log index file corresponding to the replay log file, wherein the log index file and the replay log file are used in the method described in any one of claims 1-8.
10. The method according to claim 9, wherein the step of sequentially writing the log index entries corresponding to each replay log entry into the log index file corresponding to the replay log file according to the generation order of each replay log entry comprises: The scheduling index refresh thread organizes the log index entries corresponding to each replay log entry into multiple batches according to the page identifier of the data page, and writes the log index entries of each batch sequentially into the log index file corresponding to the replay log file on the disk according to the log sequence number, wherein the log sequence number is marked according to the generation order of the replay log entries.
11. The method according to claim 10, wherein the scheduling index refresh thread organizes the log index entries corresponding to each replay log entry into multiple batches according to the page identifier of the data page, and sequentially writes the log index entries of each batch into the log index file corresponding to the replay log file on the disk according to the log sequence number, comprising: The scheduling index refresh thread, using the page identifier of the data page as the key, organizes the log index entries corresponding to each replay log entry into multiple batches and writes them into the replay buffer; Log index entries for each batch are read from the replay buffer and written sequentially to the log index file corresponding to the replay log file on the disk according to the log sequence number.
12. The method according to any one of claims 9-11, wherein the database system comprises multiple data pages; After performing a modification operation on a data page in the database system, generating a corresponding replay log entry and writing the replay log entry to the replay log file includes: After performing modification operations on multiple data pages in the database system, multiple parallel threads are scheduled to generate corresponding replay log entries, and the replay log entries are written to the replay log file.
13. The method according to claim 12, wherein generating the corresponding replay log entry comprises: The operation records of the modification operation are logically segmented according to the basic transaction unit and stored in multiple buffer blocks; Based on the operation records of the modification operations after being segmented in the multiple buffer blocks, corresponding replay log entries are generated.
14. The method according to claim 13, wherein generating corresponding replay log entries based on the operation records of the modified operations after being segmented in the plurality of buffer blocks includes: Multiple asynchronous parsing threads are scheduled to generate corresponding replay log entries based on the operation records of the modified operations after being segmented in the multiple buffer blocks. The generated replay log entries are sorted according to the log sequence number, and the multiple buffer blocks are updated. The log sequence number is marked according to the generation order of the replay log entries.
15. A database system, comprising a database recovery module; said database recovery module being used for: Based on the checkpoints of the database system, obtain the log index file corresponding to the replay log file. The replay log entries in the replay log file are generated after the data page in the database system has been modified. Any log index entry in the log index file records the page identifier of the modified data page. The log index file is parsed, and multiple log index entries in the log index file are arranged according to the page identifier of the data page; According to the order of the multiple log index entries, the corresponding replay log entries are read from the replay log file, and the data pages are replayed based on the replay log entries until the recovered database system is obtained.
16. The database system according to claim 15, further comprising an index generation module; the index generation module being configured to: After performing a modification operation on a data page in the database system, a corresponding replay log entry is generated and the replay log entry is written to the replay log file; Create corresponding log index entries for each replay log entry, where, The log index entries record the page identifiers of the modified data pages; Based on the generation order of each replay log entry, the log index entries corresponding to each replay log entry are sequentially written into the log index file corresponding to the replay log file.
17. A computing device, comprising: Memory and processor; The memory is used to store computer programs / instructions, and the processor is used to execute the computer programs / instructions, which, when executed by the processor, implement the steps of the method according to any one of claims 1 to 14.
18. A computer-readable storage medium storing a computer program / instructions that, when executed by a processor, implement the steps of the method according to any one of claims 1 to 14.
19. A computer program product comprising a computer program / instructions that, when executed by a processor, implement the steps of the method according to any one of claims 1 to 14.
