A method, apparatus, and storage medium for data recovery of an operating system.

By combining non-volatile memory and a consistent state machine in the operating system, the problem of data loss caused by data caching mechanisms is solved, enabling fast and reliable data recovery and improving system performance and the reliability of data recovery.

CN121433583BActive Publication Date: 2026-06-02CHANGSHA JINYAN TECHNOLOGY CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
CHANGSHA JINYAN TECHNOLOGY CO LTD
Filing Date
2025-11-13
Publication Date
2026-06-02

AI Technical Summary

Technical Problem

In existing technologies, due to the data caching mechanism, there is a risk of data loss during the data recovery process after an abnormal operating system restart.

Method used

Non-volatile memory is divided into multiple logically contiguous log slots. Log records with unique global sequence numbers are generated by the main thread and written atomically. The asynchronous persistence thread writes them to the persistent storage device in batches in sequence. A consistent state machine is used to maintain the persistent offset pointer. The difference log range is checked periodically. After the operating system restarts, the log records in the difference log range that are not marked as reclaimable are scanned and replayed to complete the data recovery.

Benefits of technology

It enables fast and reliable data recovery after an abnormal operating system restart, eliminating the risk of data loss after being written to the memory cache but not to the disk, and improving system write performance and data recovery reliability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121433583B_ABST
    Figure CN121433583B_ABST
Patent Text Reader

Abstract

This invention relates to the field of operating system data recovery technology, and discloses a method, apparatus, and storage medium for operating system data recovery. Non-volatile memory is divided into multiple log slots. Log records carrying global sequence numbers are generated in the main thread, and atomic write operations are performed on these log records. An acknowledgment signal carrying the global sequence number is returned to the requesting terminal via the main thread. Log records are written sequentially in batches to persistent storage. Log slots corresponding to persisted log records in non-volatile memory are marked as reclaimable. A persistent offset pointer is maintained through a consistency state machine. Consistency check events are periodically triggered to determine the difference log interval. After the operating system restarts, the non-volatile memory is scanned, and log records not marked as reclaimable within the difference log interval are loaded and replayed to complete data recovery. This invention avoids the risk of data loss after an abnormal operating system restart due to data caching mechanisms.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of operating system data recovery technology, and in particular to an operating system data recovery method, a data recovery device, and a storage medium. Background Technology

[0002] With the rapid development of IoT technology, hundreds of millions of IoT terminals have been deployed in key areas such as industrial control, smart homes, and connected vehicles. These terminals continuously generate massive amounts of environmental sensing data and control commands. Much of this data (such as the operating status logs of industrial equipment, real-time readings of smart meters, and sensor data from vehicles) possesses tamper-proof and non-lossable security attributes, forming the basis for status monitoring, big data analysis, and security auditing.

[0003] Operating systems are used to ensure data security, and one of their responsibilities is to ensure that data is not lost or damaged due to various accidents. Data recovery mechanisms are an important way to fulfill this responsibility.

[0004] Data recovery is not a routine operation that can be performed casually. It is usually a remedial measure triggered after an anomaly or specific event occurs. It is generally triggered only under special events such as abnormal system crashes or power outages, application or user misoperation, or storage media failure.

[0005] One key challenge in operating system data recovery lies in the unpredictability of what data operations the system is performing at the moment an abnormal event triggers data recovery. With the rapid development of computer technology, computers perform massive tasks in many scenarios, generating vast amounts of data to write. For this massive amount of data, the safest data writing method is synchronous writing—meaning each data write must actually be written to the disk before the program can continue. However, disk I / O is slow, so synchronous writing severely limits computer performance and leads to a significant degraded user experience. Therefore, to maximize computer performance, operating systems widely use caching to implement delayed writing, where data is temporarily stored in memory and then written to the disk in batches at predetermined times. While this delayed writing method brings significant performance improvements, it also introduces risks: a large amount of data in memory that has not been written to disk for storage risks being completely lost during a system crash.

[0006] Data verification mechanisms can be used for data recovery after an abnormal operating system restart. Data verification calculates a short, unique checksum for each piece of written data and stores this checksum along with the data itself. In an abnormal recovery scenario, after an abnormal restart, the database performs data recovery operations to verify the integrity of each piece of data. If the verification passes, it means the data storage is intact, and the recovery process can safely use this data; if the verification fails, it means the data is corrupted.

[0007] However, data verification mechanisms require data fragments and checksums for data recovery. Therefore, they can only perform data recovery after an abnormal system restart, provided that the data fragments and their checksums have been successfully stored on the disk. If the abnormal restart occurs before the data and its checksum have been written to the disk, the data verification mechanism cannot be used to recover the data source, resulting in data loss after the operating system restarts.

[0008] Therefore, existing data caching mechanisms pose a risk of data loss during the data recovery process after an abnormal operating system restart. Summary of the Invention

[0009] The main objective of this invention is to provide a data recovery method, system, and medium for an operating system, aiming to solve the problem of data loss risk during the data recovery process after an abnormal restart of the operating system due to the existence of a data caching mechanism in the prior art.

[0010] To achieve the above objectives, the present invention provides a data recovery method for an operating system, comprising the following steps:

[0011] The non-volatile memory is divided into multiple logically contiguous log slots. In response to a data write request from a requesting terminal, a log record carrying a unique global sequence number is generated in the main thread, and an atomic write operation is performed on the log record in the log slot in the non-volatile memory.

[0012] After a successful atomic write, the main thread returns an acknowledgment signal carrying the global serial number to the requesting terminal.

[0013] An asynchronous persistence thread, independent of the main thread, writes the log records in the non-volatile memory into the persistent storage device in a batch in sequence. After the log records are persisted, the log slots corresponding to the persisted log records are marked as recyclable in the non-volatile memory.

[0014] A persistent offset pointer is maintained through a consistent state machine, so that the persistent offset pointer dynamically points to the global sequence number position of the latest log record in the non-volatile memory that has been confirmed to be persisted to the persistent storage device;

[0015] A consistency check event is periodically triggered. The current persistent offset pointer is locked through the consistency state machine, and the difference log range is determined based on the pointer position of the persistent offset pointer and the global sequence number position of the latest log record in the non-volatile memory.

[0016] After the operating system restarts, the non-volatile memory is scanned, and log records that were not marked as reclaimable within the differential log range are loaded and replayed to complete data recovery.

[0017] Optionally, the step of determining the difference log interval based on the pointer position of the persistent offset pointer and the global sequence number position of the latest log record in the non-volatile memory includes:

[0018] The next global sequence number corresponding to the pointer position currently pointed to by the persistent offset pointer is determined as the starting sequence number of the differential log interval;

[0019] The global sequence number corresponding to the most recently written log record in the non-volatile memory is determined as the termination sequence number of the differential log interval;

[0020] The difference log range is defined by the start sequence number and the end sequence number.

[0021] Optionally, the step of dividing non-volatile memory into a logically contiguous plurality of log slots, generating a log record carrying a unique global sequence number in the main thread in response to a data write request from a requesting terminal, and performing an atomic write operation on the log record to the log slot in the non-volatile memory includes:

[0022] Allocate a contiguous memory address space for the non-volatile memory;

[0023] The memory address space is evenly divided into multiple log slots of fixed size;

[0024] Each log slot is divided into an information unit for storing metadata and a data unit for storing data bodies.

[0025] Optionally, the step of dividing the non-volatile memory into a logically contiguous plurality of log slots, generating a log record carrying a unique global sequence number in the main thread in response to a data write request from a requesting terminal, and performing an atomic write operation on the log record to the log slot in the non-volatile memory, further includes:

[0026] The free log slots are dynamically updated to the first-level log area through the first-level dynamic index pool. The free log slots include unoccupied log slots and log slots marked for reclamation.

[0027] In response to the data write request from the requesting terminal, the log record with a unique global sequence number generated according to the data write request is atomically written to the free log slot of the first-level log area.

[0028] The secondary dynamic index pool dynamically updates the occupied log slots in the primary log area to the corresponding occupied log slots in the secondary log area, so that the asynchronous persistence thread can read log records from the secondary log area in order of global sequence number and write them to the persistent storage device in batches.

[0029] Optionally, the step of responding to the data write request from the requesting terminal and atomically writing the log record carrying a unique global sequence number generated according to the data write request to an idle log slot in the first-level log area further includes:

[0030] The primary dynamic index pool responds to data write requests from the requesting terminal, and allocates free log slots in the primary log area from the primary dynamic index pool according to the index order for the data write requests.

[0031] The log record with a unique global sequence number generated according to the data write request is atomically written to an empty log slot allocated from the first-level log area.

[0032] Optionally, the step of periodically triggering a consistency check event and locking the current persistent offset pointer through the consistency state machine includes:

[0033] Obtain the timing period, and when the current time reaches the timing period, trigger a consistency check event and generate an atomic read instruction;

[0034] According to the atomic read instruction, the current consistent pointer value of the persistent offset pointer is read from the non-volatile memory;

[0035] The lock identifier is stored in association with the consistency pointer value to prevent the asynchronous persistence thread from modifying the persistence offset pointer during the read process.

[0036] Optionally, the step of scanning the non-volatile memory, loading and replaying the log records not marked as reclaimable within the difference log interval after the operating system restarts to complete data recovery includes:

[0037] After the operating system restarts, the non-volatile memory is rescanned to form a verification difference log range;

[0038] Perform a consistency comparison between the verification difference log interval and the difference log interval;

[0039] When the comparison passes, the log records in the difference log range are loaded and replayed, and the log records in the difference log range are written to the persistent storage device in order in batches. After the log records are persisted, the corresponding log slots are marked as recyclable in the non-volatile memory to complete the data recovery.

[0040] If the comparison fails, the log records of the verification difference log interval are loaded and replayed. The log records in the verification difference log interval are written to the persistent storage device in sequence. After the log records are persisted, the corresponding log slots are marked as recyclable in the non-volatile memory to complete the data recovery.

[0041] Optionally, the step of scanning the non-volatile memory, loading and replaying the log records not marked as reclaimable within the difference log interval after the operating system restarts to complete data recovery further includes:

[0042] After the operating system restarts, the non-volatile memory is scanned to determine whether the persistent offset pointer is corrupted;

[0043] If so, reconstruct a new persistent offset pointer based on the last global sequence number stored in the persistent storage device;

[0044] Determining the differential log range and recovering data based on the reconstructed pointers.

[0045] To achieve the above objectives, the present invention also proposes a data recovery device, wherein the data recovery device applies the data recovery method of the operating system; the data recovery device includes:

[0046] The cache management module is used to divide non-volatile memory into multiple logically contiguous log slots. In response to a data write request from the requesting terminal, it generates a log record carrying a unique global sequence number in the main thread and performs an atomic write operation on the log record in the log slot in the non-volatile memory.

[0047] The confirmation module is used to return a confirmation signal carrying the global serial number to the requesting terminal through the main thread after the atomic write is successful.

[0048] The write management module is used to write log records in the non-volatile memory to the persistent storage device in a batch and in sequence by an asynchronous persistent thread independent of the main thread, and to mark the log slots corresponding to the persisted log records in the non-volatile memory as recyclable after the log records have been persisted.

[0049] A consistent state machine module is used to maintain a persistent offset pointer so that the persistent offset pointer dynamically points to the global sequence number position of the latest log record in the non-volatile memory that has been confirmed to be persisted to the persistent storage device;

[0050] The locking management module is used to periodically trigger consistency check events, lock the current persistent offset pointer through the consistency state machine, and determine the difference log range based on the pointer position of the persistent offset pointer and the global sequence number position of the latest log record in the non-volatile memory.

[0051] The data recovery module is used to scan the non-volatile memory after the operating system restarts, load and replay the log records in the differential log range that were not marked as reclaimable, so as to complete the data recovery.

[0052] To achieve the above objectives, the present invention also proposes a storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the steps of the data recovery method of the operating system.

[0053] The technical solution of this invention helps to solve the problem in existing technologies where data loss is a risk during data recovery after an abnormal operating system restart due to the existence of a data caching mechanism. Specifically, this invention utilizes non-volatile memory for high-speed non-volatile caching. Because of its extremely fast read / write speed and non-volatile nature, data can be safely stored in non-volatile memory. This allows the main thread to quickly generate a log record carrying a global sequence number after responding to a data write request from the requesting terminal, atomically write the log record to non-volatile memory, and return an acknowledgment signal to the requesting terminal very quickly. Therefore, by atomically writing the log record to non-volatile memory through the main thread, the invention achieves persistent writing of data while it is cached in non-volatile memory due to the low data loss rate and fast storage speed of non-volatile memory, thus achieving an effect similar to synchronous writing. This allows the system to quickly return an acknowledgment signal to the requesting terminal, giving the user a noticeable improvement in system write performance.

[0054] Furthermore, an asynchronous persistent thread, independent of the main thread, writes data from high-speed non-volatile memory to persistent storage at a relatively slower speed. Because non-volatile memory is characterized by its low data loss rate, even after an operating system crash leading to a restart, the pointer positions of the persistent offset pointers in each log slot within the non-volatile memory still exist. The difference log interval, determined by the pointer positions and the global sequence number position of the latest log record in the non-volatile memory, also remains. Therefore, based on the difference log interval, data that has not been persistently written to the persistent storage device can be identified, and data recovery can continue based on this interval, thus completing the writing of incomplete data from non-volatile memory to persistent storage and achieving data recovery. Therefore, the asynchronous persistent thread, while ensuring system write performance, combined with the log slots and pointers in non-volatile memory, significantly improves the reliability of data recovery, eliminating the risk of data loss during the time window after data is written to the memory cache but before it is written to disk due to a system crash. Thus, this invention helps solve the problem in existing technologies where the existence of a data caching mechanism leads to a risk of data loss during data recovery after an abnormal operating system restart. Attached Figure Description

[0055] Figure 1 This is a flowchart illustrating the data recovery method for the operating system in the first embodiment of the present invention;

[0056] Figure 2 This is a schematic diagram of the module framework of the data recovery device in this invention;

[0057] Figure 3 This is a schematic diagram illustrating the division of non-volatile memory into multiple log slots in this invention;

[0058] Figure 4 This is a schematic diagram of the differential log range in this invention;

[0059] Figure 5 This is a schematic diagram illustrating the dynamic maintenance of the primary dynamic index pool and the secondary dynamic index pool in this invention.

[0060] The objectives, features, and advantages of this invention will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation

[0061] It should be understood that the specific embodiments described herein are for illustrative purposes only and are not intended to limit the scope of the invention.

[0062] In the following description, the use of suffixes such as "unit," "component," or "element" to denote elements is solely for the purpose of illustrative purposes and has no specific meaning in itself. Therefore, "unit," "component," or "element" may be used interchangeably.

[0063] Please see Figures 1 to 5 The first embodiment of the present invention provides a data recovery method for an operating system, comprising the following steps:

[0064] Step S10: Divide the non-volatile memory into multiple logically contiguous log slots. In response to a data write request from the requesting terminal, generate a log record carrying a unique global sequence number in the main thread, and perform an atomic write operation on the log record in the log slot in the non-volatile memory.

[0065] Step S20: After the atomic write is successful, the main thread returns an acknowledgment signal carrying the global serial number to the requesting terminal.

[0066] Step S30: An asynchronous persistence thread, independent of the main thread, writes the log records in the non-volatile memory into the persistent storage device in a batch in sequence. After the log records are persisted, the log slots corresponding to the persisted log records are marked as recyclable in the non-volatile memory.

[0067] Step S40: Maintain the persistent offset pointer through a consistent state machine so that the persistent offset pointer dynamically points to the global sequence number position of the latest log record in the non-volatile memory that has been confirmed to be persisted to the persistent storage device;

[0068] Step S50: Periodically trigger a consistency check event, lock the current persistent offset pointer through the consistency state machine, and determine the difference log range based on the pointer position of the persistent offset pointer and the global sequence number position of the latest log record in the non-volatile memory.

[0069] Step S60: After the operating system restarts, scan the non-volatile memory, load and replay the log records in the differential log range that were not recorded as recyclable, in order to complete data recovery.

[0070] The technical solution of this invention helps to solve the problem in existing technologies where data loss is a risk during data recovery after an abnormal operating system restart due to the existence of a data caching mechanism. Specifically, this invention utilizes non-volatile memory for high-speed non-volatile caching. Because of its extremely fast read / write speed and non-volatile nature, data can be safely stored in non-volatile memory. This allows the main thread to quickly generate a log record carrying a global sequence number after responding to a data write request from the requesting terminal, atomically write the log record to non-volatile memory, and return an acknowledgment signal to the requesting terminal very quickly. Therefore, by atomically writing the log record to non-volatile memory through the main thread, the invention achieves persistent writing of data while it is cached in non-volatile memory due to the low data loss rate and fast storage speed of non-volatile memory, thus achieving an effect similar to synchronous writing. This allows the system to quickly return an acknowledgment signal to the requesting terminal, giving the user a noticeable improvement in system write performance.

[0071] Furthermore, an asynchronous persistent thread, independent of the main thread, writes data from high-speed non-volatile memory to persistent storage at a relatively slower speed. Because non-volatile memory is characterized by its low data loss rate, even after an operating system crash leading to a restart, the pointer positions of the persistent offset pointers in each log slot within the non-volatile memory still exist. The difference log interval, determined by the pointer positions and the global sequence number position of the latest log record in the non-volatile memory, also remains. Therefore, based on the difference log interval, data that has not been persistently written to the persistent storage device can be identified, and data recovery can continue based on this interval, thus completing the writing of incomplete data from non-volatile memory to persistent storage and achieving data recovery. Therefore, the asynchronous persistent thread, while ensuring system write performance, combined with the log slots and pointers in non-volatile memory, significantly improves the reliability of data recovery, eliminating the risk of data loss during the time window after data is written to the memory cache but before it is written to disk due to a system crash. Thus, this invention helps solve the problem in existing technologies where the existence of a data caching mechanism leads to a risk of data loss during data recovery after an abnormal operating system restart.

[0072] Specifically, each log slot stores one log record. This log slot approach enables fragmented updates to both the log record and the stored data (each log slot essentially stores a log fragment and a data fragment). When data recovery is needed using log records, the system no longer needs to read the entire log record to find the data written at the moment of the system's abnormal startup. Instead, it only needs to read the difference log range maintained by the system through log slots and persistent offset pointers. This avoids the tedious and error-prone data recovery task caused by reading the entire log record and searching for a specific data write task within it, making the entire data recovery process shorter, more accurate, and with a lower error rate.

[0073] In traditional technical solutions, to ensure data integrity, an acknowledgment signal can only be sent to the application after the data has been actually written to the persistent storage disk. However, disk I / O is slow, so the waiting period for the acknowledgment signal is lengthy, becoming a major bottleneck for system performance.

[0074] This invention employs non-volatile memory. Because it is a type of memory with extremely fast read / write speeds and the characteristic of non-volatile data, the data cached in non-volatile memory has very high stability. Writing data to non-volatile memory achieves an effect similar to synchronous disk writing. Therefore, this characteristic allows the main thread to return an acknowledgment signal to the application extremely quickly, thus improving the system's data write performance.

[0075] Meanwhile, a background thread asynchronously transfers data from high-speed non-volatile memory to a relatively slower persistent storage device, which can be done at a time set by the system.

[0076] In this invention, each log record is cached in non-volatile memory using a unique global sequence number. This ensures that, in the event of an abnormal operating system restart, the order of the cached logs in non-volatile memory remains clear and traceable. Therefore, the non-volatile memory in this invention serves as a safe buffer area, preventing data loss during asynchronous operations and achieving a balance between high performance and high reliability.

[0077] In the technical solution of this invention, after the operating system restarts abnormally, the data recovery speed is fast and the reliability is high. Specifically, after a crash, only a very small, well-defined log interval segment needs to be recovered, instead of all log files. Through state machine and pointer locking mechanism, the boundaries of consistent log segments are clearly defined, avoiding ambiguity in the recovery process.

[0078] Each log record has a unique global sequence number that changes in ascending order over time. Therefore, a larger sequence number indicates a later event in which the log record was generated. By comparing the sequence numbers of different log records, the order in which the log records were generated can be determined.

[0079] Please refer to Figure 4 According to the first embodiment of the data recovery method for the operating system of the present invention, and the second embodiment of the data recovery method for the operating system of the present invention, the step of determining the difference log interval based on the pointer position of the persistent offset pointer and the global sequence number position of the latest log record in the non-volatile memory in step S50 includes:

[0080] Step S51: Determine the next global sequence number corresponding to the pointer position currently pointed to by the persistent offset pointer as the starting sequence number of the differential log interval;

[0081] Step S52: Determine the global sequence number corresponding to the latest log record written in the non-volatile memory as the termination sequence number of the differential log interval;

[0082] Step S53: Define the difference log range using the start sequence number and the end sequence number.

[0083] By using the persistent offset pointer, the global sequence number position of the latest log record in the non-volatile memory that has been confirmed to be persisted to the persistent storage device can be clearly and accurately defined.

[0084] Furthermore, the logically contiguous log slots in the non-volatile memory are also assigned sequence numbers to ensure that log records are stored in order. This order means that the first log record generated is stored in the log slot with the smaller sequence number, and the later log records are stored in the log slot with the larger sequence number, until the log slots are full. Log records can continue to be stored in order in log slots marked as reclaimable.

[0085] Please refer to Figure 3 In a first embodiment of the data recovery method for the operating system of the present invention, and in a third embodiment of the data recovery method for the operating system of the present invention, step S10 includes:

[0086] Step S11: Allocate a contiguous memory address space for the non-volatile memory;

[0087] Step S12: Divide the memory address space evenly into multiple log slots of fixed size;

[0088] Step S13: Divide each log slot into an information unit for storing metadata and a data unit for storing data bodies.

[0089] Specifically, the metadata area includes several fields:

[0090] The global sequence number field is used to store the unique global sequence number of the corresponding log record, which defines the global order of log records stored in the current log slot;

[0091] The validity flag field is used to indicate whether the data in the current log slot is valid;

[0092] The commit flag field is used to indicate whether the main thread has successfully completed the atomic write operation;

[0093] The reclaimable flag field is used to mark whether the current log slot is in a reclaimable state.

[0094] The data unit is used to store log data from the requesting terminal.

[0095] Log slots separate metadata from the data body, allowing for efficient reading and modification of metadata without altering the actual data. This facilitates quick assessment of data status and log slot availability.

[0096] Furthermore, after performing an atomic write operation on the log slot, the valid bit flag field and the commit bit flag field can be modified accordingly to update the data write status through the information unit of the log slot.

[0097] Please refer to Figure 5 In the third embodiment of the data recovery method for the operating system of the present invention, and in the fourth embodiment of the data recovery method for the operating system of the present invention, step S10 further includes:

[0098] Step S14: Through the first-level dynamic index pool, the free log slots are dynamically updated to the first-level log area. The free log slots include unoccupied log slots and log slots marked for recycling.

[0099] Step S15: In response to the data write request from the requesting terminal, the log record with a unique global sequence number generated according to the data write request is atomically written to the free log slot of the first-level log area.

[0100] Step S16: The log slots in the occupied state in the primary log area are dynamically updated to the corresponding occupied log slots in the secondary log area through the secondary dynamic index pool, so that the asynchronous persistence thread reads log records from the secondary log area in the order of global sequence number and writes them to the persistent storage device in batches in order.

[0101] Specifically, this invention partitions idle log slots into primary and secondary partitions and manages the dynamic management of different partitions through corresponding index pools. The hierarchical design of the index pool enables efficient state isolation of log slots, allowing the primary dynamic index pool to focus on log slot allocation efficiency and improve the write response speed of external data. The secondary dynamic index pool maintains the write order of log records in the log slots to the persistent storage device to ensure persistence order.

[0102] Furthermore, this invention clarifies the dynamic allocation and state transition mechanism of log slots by dynamically managing the primary and secondary log areas.

[0103] Therefore, the above scheme constructs a logical hierarchy within the non-volatile memory, using a faster cache (level 1 log area) to ensure extremely low-latency writes by the main thread, while using another large-capacity buffer (level 2 log area) to handle short-term lags in persistent threads. This effectively expands the logically reclaimable space, greatly enhancing the ability to absorb write spikes.

[0104] In a fourth embodiment of the data recovery method for the operating system based on the present invention, and in a fifth embodiment of the data recovery method for the operating system based on the present invention, step S15 includes:

[0105] Step S151: Respond to the data write request from the requesting terminal through the first-level dynamic index pool, and allocate free log slots in the first-level log area from the first-level dynamic index pool according to the index order for the data write request;

[0106] Step S152: The log record with a unique global sequence number generated according to the data writing request is atomically written to the free log slot allocated from the first-level log area.

[0107] Specifically, when the technical solution of Embodiment 5 is not adopted, it is easy to understand that each time a log slot is allocated for a data write request, the availability status of each log slot needs to be scanned one by one, and log slots are allocated for the data write request according to the order of available log slots. This will lead to write latency, which will be exacerbated when the amount of data written is large, thus reducing the user experience.

[0108] In this embodiment, since the dynamic index pool maintains only idle log slots, the log slots in the index pool are simply allocated sequentially to the corresponding data write requests. For example, when a data write request is generated at once, the first idle log slot in the first-level dynamic index pool is allocated to the data write request. When 10 data write requests are generated in batches, the first 10 idle log slots in the first-level dynamic index pool are allocated to each data write request in batches, thereby achieving parallel batch allocation of log slots. This allows 10 acknowledgment signals to be returned to the requesting terminal at once, effectively reducing write latency.

[0109] Furthermore, the step S30 of marking the log slots corresponding to the persisted log records in the non-volatile memory as reclaimable includes:

[0110] Step S31: Obtain the log slot corresponding to the log record that has been persistently stored in the non-volatile memory, and mark the information unit of the log slot as recyclable to indicate that the log slot can be used for new log records to be overwritten in a cyclical manner.

[0111] Specifically, before modifying the log slot state, the asynchronous persistence thread needs to read the persistence offset pointer maintained by the consistency state machine to determine the log record that has been persisted through the pointer position, so as to prevent other asynchronous persistence threads from modifying the current pointer state.

[0112] Based on the pointer position, the asynchronous persistence thread can locate all log slots that can be safely reclaimed (log slots that can be safely reclaimed are those whose global sequence number of stored log records is less than the pointer position). If the located log slots that can be safely reclaimed have not been marked as reclaimable, the asynchronous persistence thread accesses the persistent storage device to synchronize whether the global sequence number of each log record persisted to the persistent storage device includes the global sequence number of the log record in the located log slot. If so, it accesses the information unit of that log slot and atomically writes and modifies the reclaimable mark field in the information unit to mark it as reclaimable.

[0113] In the first to fifth embodiments of the data recovery method for the operating system based on the present invention, and in the sixth embodiment of the data recovery method for the operating system based on the present invention, the step of periodically triggering a consistency check event in step S50 and locking the current persistent offset pointer through the consistency state machine includes:

[0114] Step S54: Obtain the timing period. When the current time reaches the timing period, trigger a consistency check event and generate an atomic read instruction.

[0115] Step S55: According to the atomic read instruction, read the current consistent pointer value of the persistent offset pointer from the non-volatile memory;

[0116] Step S56: The locking identifier is associated with the consistency pointer value and stored to prevent the asynchronous persistence thread from modifying the persistence offset pointer during the reading process.

[0117] Specifically, consistency check events can be driven by a high-precision timer, for example, triggered every 100 milliseconds, or triggered by a set event, which can be the number of log records written to non-volatile memory but not persisted to persistent storage devices reaching a set threshold.

[0118] Specifically, the method further includes:

[0119] Step S70: When a write instruction issued by the main thread to the non-volatile memory is detected, the marker of the log slot to be written corresponding to the write instruction is obtained.

[0120] Step S80: When the marked content is a recyclable mark, check whether the global sequence number of the log slot to be written is less than the pointer position of the persistent offset pointer;

[0121] If so, execute step S90 to perform an overwrite operation on the log slot to be written (when the log slot to be written has a reclaimable mark and the global sequence number is less than the pointer position, it indicates that the log content in the log slot to be written has been persistently written).

[0122] If not, proceed to step S100 to reallocate the log slot for the main thread's write instruction (when the log slot to be written has a reclaimable mark and the global sequence number is greater than the pointer position, it indicates that the log slot may have been allocated incorrectly and needs to be reallocated).

[0123] In the first to sixth embodiments of the data recovery method for the operating system based on the present invention, and in the seventh embodiment of the data recovery method for the operating system based on the present invention, step S60 includes:

[0124] Step S61: After the operating system restarts, the non-volatile memory is rescanned to form a verification difference log range;

[0125] Step S62: Perform a consistency comparison between the verification difference log interval and the difference log interval;

[0126] Step S63: When the comparison passes, load and replay the log records in the difference log interval, write the log records in the difference log interval into the persistent storage device in order in batches, and mark the corresponding log slots in the non-volatile memory as recyclable after the log records are persisted, so as to complete the data recovery.

[0127] Step S64: When the comparison fails, load and replay the log records of the verification difference log interval, write the log records in the verification difference log interval into the persistent storage device in sequence, and mark the corresponding log slots in the non-volatile memory as recyclable after the log records are persisted, so as to complete the data recovery.

[0128] When the system crashes abnormally, it may cause errors in the generation of difference log ranges. The reasons for this may be as follows:

[0129] Corrupted persistent offset pointer: The asynchronous persistent thread may be updating the persistent offset pointer. If this update is in progress, the persistent offset pointer will be misaligned (the actual pointer position should be shifted forward). This will cause the difference log range to be the error range. If the error range is used for data recovery after the operating system restart, a section of the log range will be skipped and permanently lost.

[0130] Data corruption in the difference log range: Specifically, when the system crashes, the records of the difference log ranges calculated by the system may be corrupted, which can also lead to errors in the generation of difference log ranges.

[0131] While the generated difference log ranges are highly reliable during normal system operation, they may become corrupted during abnormal system crashes, leading to errors in persistent write operations and data loss. Therefore, when the comparison fails, the difference log ranges must be corrected.

[0132] Log slots marked as recyclable are maintained at the tail of the first-level dynamic index pool according to their recycling time.

[0133] In the first embodiment of the data recovery method for the operating system based on the present invention, and in the eighth embodiment of the data recovery method for the operating system based on the present invention, step S60 further includes:

[0134] Step S65: After the operating system restarts, scan the non-volatile memory to determine whether the persistent offset pointer is corrupted;

[0135] If so, proceed to step S66, and reconstruct a new persistent offset pointer based on the last global sequence number stored in the persistent storage device;

[0136] Execute step S67 to determine the differential log range and recover data based on the reconstructed pointers.

[0137] Specifically, the persistent offset pointer is not easily damaged. Even if it is damaged, in order to ensure the normal operation of data writing after the operating system restarts, the persistent offset pointer can be reconstructed according to this embodiment.

[0138] To achieve the above objectives, the present invention also proposes a data recovery device, wherein the data recovery device applies the data recovery method of the operating system; the data recovery device includes:

[0139] The cache management module is used to divide non-volatile memory into multiple logically contiguous log slots. In response to a data write request from the requesting terminal, it generates a log record carrying a unique global sequence number in the main thread and performs an atomic write operation on the log record in the log slot in the non-volatile memory.

[0140] The confirmation module is used to return a confirmation signal carrying the global serial number to the requesting terminal through the main thread after the atomic write is successful.

[0141] The write management module is used to write log records in the non-volatile memory to the persistent storage device in a batch and in sequence by an asynchronous persistent thread independent of the main thread, and to mark the log slots corresponding to the persisted log records in the non-volatile memory as recyclable after the log records have been persisted.

[0142] A consistent state machine module is used to maintain a persistent offset pointer so that the persistent offset pointer dynamically points to the global sequence number position of the latest log record in the non-volatile memory that has been confirmed to be persisted to the persistent storage device;

[0143] The locking management module is used to periodically trigger consistency check events, lock the current persistent offset pointer through the consistency state machine, and determine the difference log range based on the pointer position of the persistent offset pointer and the global sequence number position of the latest log record in the non-volatile memory.

[0144] The data recovery module is used to scan the non-volatile memory after the operating system restarts, load and replay the log records in the differential log range that were not marked as reclaimable, so as to complete the data recovery.

[0145] To achieve the above objectives, the present invention also proposes a storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the steps of the data recovery method of the operating system.

[0146] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms, or by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) as described above, and includes several instructions to cause a terminal device to enter the methods described in the various embodiments of the present invention.

[0147] In the description of this specification, references to terms such as "one embodiment," "another embodiment," "other embodiments," or "first embodiment to Xth embodiment," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the present invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, method steps, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0148] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or system that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or system. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or system that includes that element.

[0149] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.

[0150] The above are merely preferred embodiments of the present invention and do not limit the scope of the patent. Any equivalent structural or procedural transformations made based on the description and drawings of the present invention, or direct or indirect applications in other related technical fields, are similarly included within the scope of patent protection of the present invention.

Claims

1. A data recovery method for an operating system, characterized in that, Includes the following steps: The non-volatile memory is divided into multiple logically contiguous log slots. In response to a data write request from a requesting terminal, a log record carrying a unique global sequence number is generated in the main thread, and an atomic write operation is performed on the log record in the log slot in the non-volatile memory. After a successful atomic write, the main thread returns an acknowledgment signal carrying the global serial number to the requesting terminal. An asynchronous persistence thread, independent of the main thread, writes the log records in the non-volatile memory into the persistent storage device in a batch in sequence. After the log records are persisted, the log slots corresponding to the persisted log records are marked as recyclable in the non-volatile memory. A persistent offset pointer is maintained through a consistent state machine, so that the persistent offset pointer dynamically points to the global sequence number position of the latest log record in the non-volatile memory that has been confirmed to be persisted to the persistent storage device; A consistency check event is periodically triggered. The current persistent offset pointer is locked through the consistency state machine, and the difference log range is determined based on the pointer position of the persistent offset pointer and the global sequence number position of the latest log record in the non-volatile memory. After the operating system restarts, the non-volatile memory is scanned, and log records that were not marked as reclaimable within the differential log range are loaded and replayed to complete data recovery.

2. The data recovery method for an operating system according to claim 1, characterized in that, The step of determining the differential log range based on the pointer position of the persistent offset pointer and the global sequence number position of the latest log record in the non-volatile memory includes: The next global sequence number corresponding to the pointer position currently pointed to by the persistent offset pointer is determined as the starting sequence number of the differential log interval; The global sequence number corresponding to the most recently written log record in the non-volatile memory is determined as the termination sequence number of the differential log interval; The difference log range is defined by the start sequence number and the end sequence number.

3. The data recovery method for an operating system according to claim 1, characterized in that, The steps of dividing non-volatile memory into logically contiguous log slots, generating log records with unique global sequence numbers in the main thread in response to data write requests from requesting terminals, and performing atomic write operations on the log records in the log slots of the non-volatile memory include: Allocate a contiguous memory address space for the non-volatile memory; The memory address space is evenly divided into multiple log slots of fixed size; Each log slot is divided into an information unit for storing metadata and a data unit for storing data bodies.

4. The data recovery method for an operating system according to claim 3, characterized in that, The steps of dividing non-volatile memory into logically contiguous log slots, generating log records with unique global sequence numbers in the main thread in response to data write requests from requesting terminals, and performing atomic write operations on the log records in the log slots of the non-volatile memory, further include: The free log slots are dynamically updated to the first-level log area through the first-level dynamic index pool. The free log slots include unoccupied log slots and log slots marked for reclamation. In response to the data write request from the requesting terminal, the log record with a unique global sequence number generated according to the data write request is atomically written to the free log slot of the first-level log area. The secondary dynamic index pool dynamically updates the occupied log slots in the primary log area to the corresponding occupied log slots in the secondary log area, so that the asynchronous persistence thread can read log records from the secondary log area in order of global sequence number and write them to the persistent storage device in batches.

5. The data recovery method for an operating system according to claim 4, characterized in that, The step of responding to the data write request from the requesting terminal and atomically writing the log record carrying a unique global sequence number generated according to the data write request to the free log slot of the first-level log area further includes: The primary dynamic index pool responds to data write requests from the requesting terminal, and allocates free log slots in the primary log area from the primary dynamic index pool according to the index order for the data write requests. The log record with a unique global sequence number generated according to the data write request is atomically written to an empty log slot allocated from the first-level log area.

6. The data recovery method for an operating system according to claim 1, characterized in that, The step of periodically triggering a consistency check event and locking the current persistent offset pointer through the consistency state machine includes: Obtain the timing period, and when the current time reaches the timing period, trigger a consistency check event and generate an atomic read instruction; According to the atomic read instruction, the current consistent pointer value of the persistent offset pointer is read from the non-volatile memory; The lock identifier is stored in association with the consistency pointer value to prevent the asynchronous persistence thread from modifying the persistence offset pointer during the read process.

7. The data recovery method for an operating system according to any one of claims 1 to 6, characterized in that, The step of scanning the non-volatile memory after the operating system restarts, loading and replaying the log records not marked as reclaimable within the differential log range to complete data recovery includes: After the operating system restarts, the non-volatile memory is rescanned to form a verification difference log range; Perform a consistency comparison between the verification difference log interval and the difference log interval; When the comparison passes, the log records in the difference log range are loaded and replayed, and the log records in the difference log range are written to the persistent storage device in order in batches. After the log records are persisted, the corresponding log slots are marked as recyclable in the non-volatile memory to complete the data recovery. If the comparison fails, the log records in the verification difference log range are loaded and replayed. The log records in the verification difference log range are written to the persistent storage device in sequence in batches. After the log records are persisted, the corresponding log slots are marked as recyclable in the non-volatile memory to complete the data recovery.

8. The data recovery method for an operating system according to any one of claims 1 to 6, characterized in that, The step of scanning the non-volatile memory after the operating system restarts, loading and replaying the log records not marked as reclaimable within the differential log range to complete data recovery, further includes: After the operating system restarts, the non-volatile memory is scanned to determine whether the persistent offset pointer is corrupted; If so, reconstruct a new persistent offset pointer based on the last global sequence number stored in the persistent storage device; Determining the differential log range and recovering data based on the reconstructed pointers.

9. A data recovery device, characterized in that, The data recovery device applies the data recovery method of the operating system according to any one of claims 1 to 8; the data recovery device comprises: The cache management module is used to divide non-volatile memory into multiple logically contiguous log slots. In response to a data write request from the requesting terminal, it generates a log record carrying a unique global sequence number in the main thread and performs an atomic write operation on the log record in the log slot in the non-volatile memory. The confirmation module is used to return a confirmation signal carrying the global serial number to the requesting terminal through the main thread after the atomic write is successful. The write management module is used to write log records in the non-volatile memory to the persistent storage device in a batch and in sequence by an asynchronous persistent thread independent of the main thread, and to mark the log slots corresponding to the persisted log records in the non-volatile memory as recyclable after the log records have been persisted. A consistent state machine module is used to maintain a persistent offset pointer so that the persistent offset pointer dynamically points to the global sequence number position of the latest log record in the non-volatile memory that has been confirmed to be persisted to the persistent storage device; The locking management module is used to periodically trigger consistency check events, lock the current persistent offset pointer through the consistency state machine, and determine the difference log range based on the pointer position of the persistent offset pointer and the global sequence number position of the latest log record in the non-volatile memory. The data recovery module is used to scan the non-volatile memory after the operating system restarts, load and replay the log records in the differential log range that were not marked as reclaimable, so as to complete the data recovery.

10. A storage medium, characterized in that, The storage medium stores a computer program, which, when executed by a processor, implements the steps of the data recovery method of the operating system as described in any one of claims 1 to 8.