Data rollback methods, memory, electronic devices and storage media
By constructing a first-level snapshot mapping table and a second-level mapping table, the problem of long data rollback time in traditional storage arrays is solved, enabling fast data rollback and real-time recovery.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- BIWIN STORAGE TECH CO LTD
- Filing Date
- 2026-02-10
- Publication Date
- 2026-05-26
Smart Images

Figure CN121680751B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of storage, and more particularly to a data rollback method, a memory, an electronic device, and a storage medium. Background Technology
[0002] Traditional storage array rollback methods typically require data copying, and the rollback time is directly proportional to the amount of data scanned, ranging from several minutes to several hours. This results in the host service being blocked for a long time, failing to meet the requirements for real-time recovery.
[0003] Therefore, improving data rollback speed has become an urgent problem to be solved. Summary of the Invention
[0004] The main objective of this application is to provide a data rollback method, memory, electronic device, and storage medium, aiming to solve the technical problem of how to improve the speed of data rollback.
[0005] To achieve the above objectives, this application proposes a data rollback method applied to a memory, the method comprising:
[0006] In response to a snapshot creation command, snapshot data corresponding to the target data and a first-level snapshot mapping table for directing the snapshot data are generated;
[0007] Construct a secondary mapping table for orienting the location of the primary mapping table, wherein the primary mapping table is used to orient the target data;
[0008] In response to a data rollback command, the mapping update operation is switched from the first-level mapping table to the first-level snapshot mapping table based on the second-level mapping table, and the snapshot data is obtained for data rollback.
[0009] In addition, to achieve the above objectives, this application also proposes a memory comprising: a controller, flash memory, and a data rollback program stored on the flash memory and executable on the controller, the data rollback program being configured to implement the steps of the data rollback method mentioned above.
[0010] In addition, to achieve the above objectives, this application also proposes an electronic device, which includes the memory mentioned above.
[0011] In addition, to achieve the above objectives, this application also provides a storage medium storing a data rollback program, which is executed by a controller to implement the steps of the data rollback method mentioned above.
[0012] This application provides a data rollback method, a memory, an electronic device, and a storage medium. The method, applied to a memory, includes: in response to a snapshot creation instruction, generating snapshot data corresponding to target data and a primary snapshot mapping table for orienting the snapshot data; constructing a secondary mapping table for orienting the location of the primary mapping table, the primary mapping table being used to orient the target data; and in response to a data rollback instruction, switching the mapping update operation from the primary mapping table to the primary snapshot mapping table based on the secondary mapping table, and obtaining the snapshot data for data rollback.
[0013] This application first constructs a primary snapshot mapping table during snapshot creation to save snapshot data at the snapshot start time, and a secondary mapping table to store the location of the primary mapping table. Then, during data rollback, based on the secondary mapping table, the mapping update operation is quickly switched from the primary mapping table, which requires data scanning to obtain the data to be recovered, to the primary snapshot mapping table, which can directly locate the snapshot data. This allows for rapid acquisition of snapshot data for data rollback based on the primary snapshot mapping table, avoiding lengthy data scanning. Therefore, this application can utilize hierarchical mapping tables to achieve rapid data rollback, improve data rollback speed, and meet the needs of real-time recovery. Attached Figure Description
[0014] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0015] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.
[0016] Figure 1 This is a flowchart illustrating an embodiment of the data rollback method of this application;
[0017] Figure 2 This is a schematic diagram of the first process of Embodiment 2 of the data rollback method of this application;
[0018] Figure 3 This is a snapshot execution flow diagram of the data rollback method in this application;
[0019] Figure 4 This is a schematic diagram of the second process of the data rollback method embodiment two of this application;
[0020] Figure 5 This is a schematic diagram of the snapshot rollback process of the data rollback method in this application.
[0021] The purpose, features, and advantages of this application will be further explained in conjunction with the embodiments and with reference to the accompanying drawings. Detailed Implementation
[0022] It should be understood that the specific embodiments described herein are merely illustrative of the technical solutions of this application and are not intended to limit this application.
[0023] To better understand the technical solution of this application, a detailed description will be provided below in conjunction with the accompanying drawings and specific implementation methods.
[0024] The main solution of this application is to propose a data rollback method for use in memory. The method includes: in response to a snapshot creation instruction, generating snapshot data corresponding to the target data and a first-level snapshot mapping table for orienting the snapshot data; constructing a second-level mapping table for orienting the location of the first-level mapping table, wherein the first-level mapping table is used to orient the target data; in response to a data rollback instruction, switching the mapping update operation from the first-level mapping table to the first-level snapshot mapping table based on the second-level mapping table, and obtaining the snapshot data for data rollback.
[0025] Currently, traditional storage arrays require data copying during snapshot rollback, which results in excessively long rollback times and fails to meet the requirements for real-time recovery.
[0026] Based on this, this application proposes a hardware-based snapshot rollback scheme that improves data rollback speed by optimizing the characteristics of the FTL (Flash Translation Layer) in the memory. First, during snapshot creation, this application constructs a primary snapshot mapping table for saving snapshot data at the snapshot start time and a secondary mapping table for storing the location of the primary mapping table. Then, during data rollback, based on the secondary mapping table, the mapping update operation is quickly switched from the primary mapping table (which requires data scanning to obtain the data to be recovered) to the primary snapshot mapping table (which can directly locate the snapshot data). This allows for rapid acquisition of snapshot data for data rollback based on the primary snapshot mapping table, avoiding lengthy data scanning. Therefore, this application can utilize hierarchical mapping tables to achieve rapid data rollback, improve data rollback speed, and meet the needs of real-time recovery.
[0027] It should be noted that the execution entity in this embodiment can be a flash memory such as a solid-state drive (SSD), an embedded multimedia card (eMMC), universal flash storage (UFS), or a secure digital memory card (SD card). Its core characteristic is that it can achieve mapping management between logical and physical addresses through the FTL layer. Alternatively, it can be a computing service device equipped with memory that has data storage, data processing, and program execution functions, and needs to protect critical data (such as system data), such as a tablet computer, personal computer, or mobile phone. Or it can be any electronic device capable of performing the above functions. This embodiment does not specifically limit this. The following description uses the memory controller as the execution entity to illustrate this embodiment and the subsequent embodiments.
[0028] Based on this, embodiments of this application provide a data rollback method, referring to... Figure 1 , Figure 1 This is a flowchart illustrating an embodiment of the data rollback method of this application.
[0029] In this embodiment, the data rollback method is applied to the memory, and the method includes steps S10~S30:
[0030] Step S10: In response to the snapshot creation instruction, generate snapshot data corresponding to the target data and a first-level snapshot mapping table for directing the snapshot data;
[0031] It is easy to understand that the memory controller can monitor external command signals in real time. When it detects a snapshot creation command that conforms to the preset format, it can pause non-critical background operations (such as non-urgent garbage collection) and start the snapshot creation process to ensure the consistency of snapshot data.
[0032] Understandably, the aforementioned target data can refer to user-specified or system-default data that needs to be snapshotted and backed up in storage. This can be various types of valid stored data, such as user business data, system configuration data, and metadata. Correspondingly, the snapshot data can be backup data formed at the time the snapshot creation command is triggered, i.e., after a complete copy of the target data has been performed at the snapshot time. This snapshot data is completely consistent with the state of the target data at the snapshot time, for use in subsequent data rollback and recovery.
[0033] It is important to understand that the aforementioned first-level snapshot mapping table refers to a data structure specifically set up within the FTL layer of the memory in this embodiment to record the mapping relationship between logical block addresses (LBAs) and physical block addresses (PBAs) of snapshot data. The logical block address (LBA, hereinafter referred to as logical address) can be a unified address identifier provided externally by the memory, used for address addressing when the host accesses data, and is independent of the actual storage location of the physical storage medium. The physical block address (PBA, hereinafter referred to as physical address) can refer to the actual storage address of the flash memory chip in the memory, corresponding to a specific storage unit (such as a block or page), and is an identifier of the actual data storage location.
[0034] At this time, the aforementioned first-level snapshot mapping table can be a snapshot-specific copy of the mapping table set in the flash translation layer (FTL) in this embodiment, which can be used to accurately locate the storage location of snapshot data in the physical storage medium of the memory.
[0035] It is easy to understand that this embodiment can allocate specific SLC (Single-Level Cell) physical blocks in the physical storage medium of the memory to store the aforementioned snapshot data and first-level snapshot mapping table. In this case, the snapshot data and first-level snapshot mapping table are placed in a highly reliable, high-performance storage area. This not only enables rapid reading of the snapshot data and first-level snapshot mapping table from the SLC physical blocks during data rollback, but also ensures that the data can be fully recovered in scenarios such as system power failure and abnormal restart. Furthermore, even with frequent snapshot creation / deletion, the high durability of the SLC physical blocks can prevent premature wear of the data area, ensuring the system's lifespan.
[0036] Therefore, in one feasible implementation, in this embodiment, steps S00~S01 may be included before step S10:
[0037] Step S00: Obtain the real-time data load corresponding to the memory;
[0038] Step S01: Based on the real-time data load, create a snapshot storage area in the idle cache block pool.
[0039] It is easy to understand that, in this embodiment, the size of the SLC region allocated for snapshot data and snapshot-mapped backup data can be dynamically adjusted according to needs. In this case, the aforementioned real-time data load can be a set of parameters characterizing the real-time operating status of the memory. This real-time data load can be obtained in real time by the memory controller through its built-in monitoring module, and may include the memory's read / write operation pressure at the current moment (e.g., request queue length), the percentage of used storage capacity, the number of free storage blocks and the length of contiguous blocks, data access frequency, etc.
[0040] Accordingly, the aforementioned idle cache block pool can refer to the set of reserved but unallocated SLC physical blocks in the memory, and the SLC physical blocks in the cache block pool are in an idle state. In this case, this embodiment can dynamically allocate suitable data blocks from the cache block pool as snapshot storage areas according to demand, and set access permissions for the snapshot storage areas, allowing only snapshot creation and rollback operations to access them, for the storage and caching of the aforementioned snapshot data and first-level snapshot mapping table. For example, if the current data access pressure is low, the number of idle SLC physical blocks is sufficient, and the target data volume is large, a larger capacity (e.g., 5% of the total storage capacity) of SLC physical blocks can be allocated as snapshot storage areas; if the current data access pressure is high, the number of idle SLC physical blocks is limited, and the target data volume is small, a smaller capacity (e.g., 1% of the total storage capacity) of SLC physical blocks can be allocated as snapshot storage areas, ensuring that the snapshot storage area allocation meets the demand without wasting space.
[0041] In this embodiment, the snapshot storage area capacity can be dynamically allocated based on the real-time data load, ensuring that the allocated storage area capacity matches the snapshot data storage requirements. This avoids both snapshot creation failure and space waste, achieving rational utilization of storage resources. In addition, adjusting the allocation strategy according to the system operating status can reduce the impact on regular data read and write performance and ensure the overall stability of the storage system.
[0042] In one feasible implementation, step S10 may include steps S11 to S13:
[0043] Step S11: In response to the snapshot creation command, copy the target data corresponding to the snapshot time point to the snapshot storage area to generate snapshot data;
[0044] In essence, once the snapshot creation command is triggered, the controller can immediately freeze the current data state to ensure data consistency. Then, the controller can copy a complete data backup at the snapshot time and write it to the allocated snapshot storage area, generating snapshot data. For example, during the copying of target data, the controller can use a DMA (Direct Memory Access) engine to batch copy data blocks (including user data and metadata) contained in the snapshot data area of the corresponding target data to the snapshot storage area.
[0045] Step S12: Change the address index of the first-level mapping table used to direct the target data so that the first-level mapping table contains the address mapping relationship between the logical address of the snapshot data and the physical address of the snapshot storage area;
[0046] Step S13: Copy the modified first-level mapping table to the snapshot storage area to generate a first-level snapshot mapping table for directing the snapshot data.
[0047] It is important to understand that the aforementioned first-level mapping table can refer to the core mapping table of the FTL in memory. It is typically used to record the mapping relationship between the logical addresses and physical addresses of data in memory (including the aforementioned target data), supporting addressing access to data during normal I / O (Input / Output) operations. Therefore, this embodiment can use the first-level mapping table to orient the target data.
[0048] At this point, the address index mentioned above can refer to the index entry in the first-level mapping table used to associate logical addresses (i.e., the logical block address mentioned above) with physical addresses (i.e., the physical block address mentioned above). Each index entry can contain information such as logical address identifier, physical address identifier, and mapping validity identifier, and is the core element for implementing address translation.
[0049] It should be noted that, in this embodiment, the controller can modify the index entries in the first-level mapping table in parallel while copying data, that is, change the address index of the first-level mapping table as described above, so as to update the index of the physical address of the target data in the first-level mapping table to the physical address of the snapshot data in the snapshot storage area.
[0050] For example, the controller can traverse all index entries in the first-level mapping table and, for each logical address, use atomic operations to update the physical address it points to from the original target data storage location to the physical address of the snapshot data in the snapshot storage area. Simultaneously, during the modification of this address index, the controller can record a change log for each index (including the old physical address, new physical address, and change timestamp) before committing the index update. This allows for a rapid rollback to the original state in the event of an anomaly during the update process (such as a power outage), ensuring the consistency of the mapping table.
[0051] Therefore, the controller can copy the modified first-level mapping table to a specific area of the snapshot storage area (isolated from the snapshot data storage area) to form a first-level snapshot mapping table. This first-level snapshot mapping table not only corresponds to the actual physical storage address of the snapshot data, but the address index entries stored in the first-level snapshot mapping table (i.e., the address index relationship between the logical address of the snapshot data and the physical address of the snapshot storage area) essentially correspond to the original index entries at the time of snapshot startup. Therefore, this first-level snapshot mapping table can serve as a snapshot mapping backup of the original target data, used to ensure accurate rollback in case of data anomalies.
[0052] It should be understood that this embodiment can also update the valid count of the data block where the first-level mapping table is located during the copying of the address index relationship of the first-level mapping table to the first-level snapshot mapping table, thereby updating and ensuring that the data block corresponding to the first-level mapping table will not be mistakenly reclaimed, thus ensuring data security.
[0053] In one feasible implementation, this embodiment may further include steps S14-S15 after step S13:
[0054] Step S14: Perform a validity check on the address index entries contained in the first-level snapshot mapping table based on the physical address of the snapshot storage area;
[0055] Step S15: If the validity check result indicates that the physical address of the address index entry does not point to the snapshot storage area, the first-level snapshot mapping table is updated.
[0056] It is easy to understand that the above address index entry can refer to the correspondence record between a single logical address and a physical address in the first-level snapshot mapping table. This address index entry can be the basic unit that constitutes the first-level snapshot mapping table and can contain fields such as logical address value, physical address value, and mapping status flag (valid / invalid).
[0057] At this point, the aforementioned validity check can refer to the controller verifying whether the physical address of each address index entry in the primary snapshot mapping table accurately points to the snapshot storage area. In this embodiment, the validity check can be used to investigate mapping address deviations in the primary snapshot mapping table caused by bad block remapping, copy errors, or other reasons.
[0058] For example, the controller can traverse all address index entries in the first-level snapshot mapping table, extract the physical address of each entry, and then determine whether the physical address is within the range of the start and end addresses of the snapshot storage area. If it is within the range, the entry is considered valid; otherwise, it indicates that the physical address of the entry has an address deviation and is considered invalid.
[0059] Therefore, the aforementioned mapping update refers to the controller replacing the physical address field of address index entries with address mapping discrepancies discovered during validity checks with the physical address field of the snapshot storage area that should have been pointed to, ensuring that the entries accurately point to the snapshot storage area. After all invalid entries have been updated, the controller can then perform a secondary check by traversing the first-level snapshot mapping table again to ensure that all address index entries are valid and without any omissions or discrepancies.
[0060] In this embodiment, validity checks can promptly detect mapping address deviations, ensuring that all entries in the primary snapshot mapping table accurately point to the snapshot data in the snapshot storage area, verifying and establishing the correct address pointing relationship. This ensures that the copied primary snapshot mapping table points to the data area of the complete snapshot, avoiding rollback failures due to mapping deviations and improving the reliability and accuracy of data rollback.
[0061] Step S20: Construct a secondary mapping table for orienting the location of the primary mapping table, wherein the primary mapping table is used to orient the target data;
[0062] Step S30: In response to the data rollback command, the mapping update operation is switched from the first-level mapping table to the first-level snapshot mapping table based on the second-level mapping table, and the snapshot data is obtained for data rollback.
[0063] It should be understood that, in this embodiment, the aforementioned secondary mapping table can be a data structure used to record the storage location information of the primary mapping table, and can be stored using a hash table or a tree structure. That is, each entry in the secondary mapping table can record the storage base address of the corresponding logical address range in the primary mapping table. This embodiment can achieve fast indexing of the primary mapping table based on the secondary mapping table. The mapping hierarchy at this time can be: secondary mapping table → primary mapping table → original data block.
[0064] At this point, the aforementioned data rollback instruction can refer to an instruction signal issued by the electronic device's operating system, application, or external control module, used to trigger the memory to restore the current data state to the state at the snapshot time point. This instruction may include parameters such as the target snapshot identifier. In this embodiment, when the memory controller detects the data rollback instruction, it prioritizes processing the instruction, suspends new write requests (ensuring that the data is not tampered with during the rollback process), retains the ability to process read requests, and initiates the mapping table switching process.
[0065] In this context, the aforementioned mapping update operation can refer to the operation in the mapping table switching process where the controller updates the logical address and physical address mapping relationship of the data. For example, the controller can use atomic operations, such as CAS (Compare-And-Swap), to switch the pointer corresponding to the mapping update operation from pointing to the first-level mapping table to pointing to the first-level snapshot mapping table; this process does not require scanning the source data.
[0066] Meanwhile, this embodiment can quickly locate the storage location of the primary mapping table based on the secondary mapping table, thereby accelerating the query efficiency of the primary mapping table, reducing address translation time, and enabling rapid switching of mapping targets. After the mapping switch is completed, memory I / O operations can access snapshot data through the primary snapshot mapping table, restoring the data state currently accessed by the electronic device to the snapshot time point, completing data rollback. Therefore, this embodiment can accelerate data access during rollback based on the mapping hierarchy structure, thereby improving data rollback speed and meeting real-time recovery requirements.
[0067] In summary, this embodiment can generate a mapping backup of the original snapshot data, namely the aforementioned first-level snapshot mapping table, when creating snapshot data. The snapshot data and the first-level snapshot mapping table are written into a specific snapshot storage area for highly reliable data storage. Then, during snapshot rollback, the snapshot data can be quickly accessed based on the second-level mapping table and the first-level snapshot mapping table without scanning the source data, effectively reducing the rollback operation time and solving the problem of long snapshot rollback time in existing systems.
[0068] This embodiment provides a data rollback method, which includes: acquiring the real-time data load corresponding to the memory; creating a snapshot storage area in an idle cache block pool based on the real-time data load; in response to a snapshot creation instruction, copying the target data corresponding to the snapshot time point to the snapshot storage area to generate snapshot data; modifying the address index of the first-level mapping table used to orient the target data, so that the first-level mapping table contains the address mapping relationship between the logical address of the snapshot data and the physical address of the snapshot storage area; copying the first-level mapping table with the modified address index to the snapshot storage area to generate a first-level snapshot mapping table used to orient the snapshot data; performing a validity check on the address index entries contained in the first-level snapshot mapping table based on the physical address of the snapshot storage area; if the validity check result shows that the physical address of an address index entry does not point to the snapshot storage area, updating the mapping of the first-level snapshot mapping table; constructing a second-level mapping table to orient the location of the first-level mapping table, the first-level mapping table being used to orient the target data; in response to a data rollback instruction, switching the mapping update operation from the first-level mapping table to the first-level snapshot mapping table based on the second-level mapping table, acquiring the snapshot data, and performing data rollback.
[0069] Therefore, traditional storage array rollback methods require extensive data copying, resulting in long rollback times and difficulty in meeting real-time recovery requirements and achieving efficient data recovery. This embodiment addresses this by constructing a first-level snapshot mapping table that stores the complete original address index relationship and a second-level mapping table that stores the location of the first-level mapping table. This allows for rapid location of snapshot data during data rollback without scanning the source data or performing large-scale data copying. The snapshot data can be quickly located simply by switching from the first-level mapping table to the first-level snapshot mapping table, reducing rollback operation time and meeting real-time recovery requirements.
[0070] Based on the first embodiment of this application, in the second embodiment of this application, the same or similar content as the first embodiment described above can be referred to the above description, and will not be repeated hereafter.
[0071] It is easy to understand that, since the data rollback process is a non-atomic operation, if the rollback process is interrupted due to external factors (such as power outages), data tearing can easily occur, leading to data inconsistency and thus causing data security issues.
[0072] Therefore, based on the first embodiment, please refer to Figure 2 , Figure 2 This is a schematic diagram of the first process of the second embodiment of the data rollback method of this application. In this embodiment, step S30 includes steps S31 to S32:
[0073] Step S31: Construct a secondary snapshot mapping table based on the secondary mapping table to orient the position of the primary snapshot mapping table;
[0074] It is understood that the aforementioned secondary snapshot mapping table can refer to a cached data structure specifically used to record the storage location of the primary snapshot mapping table. In this embodiment, the structure of the secondary snapshot mapping table is consistent with that of the secondary mapping table (such as a hash table), and the secondary snapshot mapping table can be a dedicated copy of the snapshot corresponding to the secondary mapping table.
[0075] For example, the controller can use a background thread to asynchronously read the index entries of the logical address range corresponding to the snapshot in the secondary mapping table (such as the snapshot data range or the full data range specified by the user), then copy the read index entries to the specified area of the snapshot storage area, and add a version number to each entry (to distinguish the secondary mapping table of different snapshots). After the copy is completed, a secondary snapshot mapping table is generated to avoid blocking the foreground I / O operation.
[0076] Therefore, the secondary snapshot mapping table stores the storage location of the primary snapshot mapping information corresponding to the snapshot range in the secondary mapping table, which in effect also stores the storage location of the primary snapshot mapping table. At this point, the controller can quickly locate the primary snapshot mapping table during the rollback process based on the secondary snapshot mapping table, and thus quickly locate the snapshot data.
[0077] Step S32: In response to the data rollback instruction, the mapping pointer corresponding to the mapping update operation is switched from the secondary mapping table to the secondary snapshot mapping table, so as to switch from the primary mapping table to the primary snapshot mapping table and obtain the snapshot data for data rollback.
[0078] It should be understood that the aforementioned mapping pointer can refer to a pointer variable in memory used to point to the currently active mapping table (first-level mapping table or first-level snapshot mapping table) during rollback. This mapping pointer can be stored in the controller's register. In this embodiment, the mapping table switching can be achieved by modifying the pointer's pointer, thus realizing the aforementioned mapping update operation.
[0079] It should be noted that during the aforementioned pointer switching process, the controller can modify the pointer's direction using a single atomic instruction, directly switching it from pointing to the secondary mapping table to pointing to the secondary snapshot mapping table. For example, the controller can modify the pointer's direction, changing it from pointing to the base address of the secondary mapping table to pointing to the base address of the secondary snapshot mapping table. This pointer switching operation can be completed with a single hardware instruction, taking only microseconds, and without intermediate states, ensuring the atomicity of the switching process and preventing pointer corruption.
[0080] Meanwhile, since the secondary snapshot mapping table records the storage location of the primary snapshot mapping table, when the mapping pointer switches to the secondary snapshot mapping table, the memory address translation process automatically queries the location of the primary snapshot mapping table through the secondary snapshot mapping table, thereby realizing the indirect switching from the primary mapping table to the primary snapshot mapping table, and quickly addressing snapshot data for data rollback based on the switched primary snapshot mapping table.
[0081] At this point, after the mapping pointer switch is completed, the memory address translation process can be changed from the original "host I / O request → secondary mapping table → currently active primary mapping table → latest data" to "data rollback command → secondary snapshot mapping table → primary snapshot mapping table → frozen data at the snapshot time (i.e., snapshot data)". Therefore, this embodiment essentially adds a set of parallel mapping views to the memory, realizing the switching of mapping update operations from the primary mapping table to the primary snapshot mapping table. Correspondingly, the host can quickly obtain the frozen data at the snapshot time through the switched address translation process, that is, the snapshot data completes the data rollback.
[0082] For ease of understanding, please refer to Figure 3 The snapshot generation process during the rollback process in this embodiment will be illustrated with an example. Figure 3 This is a schematic diagram of the snapshot execution process of the data rollback method in this application.
[0083] It should be noted that, as Figure 3 As shown, the goal of the snapshot execution process in this embodiment is to generate an independent, complete snapshot image that can be directly used for rollback. It consists of two parts: the target data itself and a mirror backup of the target data's "map" (i.e., mapping table). The snapshot execution process may include the following steps:
[0084] Step 1, freeze and copy the target data:
[0085] First, the host data blocks that need to be mirrored in the original host data, i.e., the target data, can be copied to the snapshot storage area to form snapshot data blocks without locking. "Without locking" means that the system will not completely stop writing to the original data during the copying process, thus ensuring the storage performance of the memory.
[0086] Step 2, construct the mapping relationship of snapshot data:
[0087] This step is the core of the snapshot process. In this embodiment, the controller does not copy the entire massive global mapping table, but instead efficiently generates a dedicated, streamlined mapping table for the data within the snapshot range—the aforementioned first-level snapshot mapping table. At this point, as... Figure 3 As shown, address index entries generated based on the physical address and logical address of the snapshot data block in the snapshot storage area are stored in the first-level snapshot mapping table. Furthermore, a validity check is required to verify the correspondence between the first-level snapshot mapping table and the complete snapshot data block.
[0088] At this point, the first-level snapshot mapping table becomes an independent and complete logical-physical address mapping table, which can accurately describe the specific location of all backup target data at the snapshot time point in the "snapshot storage area".
[0089] Step 3: Integrate the complete first-level mapping relationships to generate a second-level mapping table:
[0090] The controller merges the primary snapshot mapping table with the address index entries corresponding to other regions to form a complete global mapping table, i.e., the primary mapping table after modifying the index relationships, which represents the address view of the entire memory at the snapshot time. At this point, the controller can generate a secondary mapping table based on the location information of the primary mapping table after modifying the index relationships, and generate the secondary snapshot mapping table based on the mapping information of the corresponding snapshot range, i.e., the location information of the primary snapshot mapping table.
[0091] Finally, the aforementioned primary snapshot mapping table, secondary snapshot mapping table, and corresponding snapshot data can be packaged into a final, stable snapshot image package and stored in the snapshot storage area. This allows the controller to instantly restore the storage to the state at the snapshot point in time simply by loading this snapshot image package when a rollback is needed.
[0092] In this embodiment, to address the issue that the switching process between the primary mapping table and the primary snapshot mapping table is easily affected by foreground I / O operations, which may lead to data addressing errors in intermediate states and affect the rollback effect, this embodiment can achieve rapid location of the primary snapshot mapping table through a secondary snapshot mapping table, thereby improving the mapping switching efficiency; and avoid blocking foreground services by asynchronously constructing the secondary snapshot mapping table; at the same time, this embodiment can ensure that there are no intermediate states in the switching process through atomic pointer switching, avoiding data addressing errors, and further ensuring the stability and reliability of second-level rollback.
[0093] Therefore, in a feasible implementation, in this embodiment, steps S32 may be followed by steps S40 to S50:
[0094] Step S40: Monitor the real-time status of the data rollback and obtain the rollback status identifier;
[0095] Step S50: When the rollback status identifier is detected as a rollback interruption identifier, repeat the step of switching the mapping pointer corresponding to the mapping update operation from the secondary mapping table to the secondary snapshot mapping table in response to the data rollback instruction, until the rollback status identifier is detected as a rollback completion identifier.
[0096] It is easy to understand that the aforementioned real-time status can refer to information such as the progress of the data rollback process monitored in real time by the controller. Correspondingly, the rollback status identifier can refer to a flag bit used to mark the real-time rollback status. In this embodiment, the rollback status identifier can include four status identifiers: "not started", "in progress", "interrupted", and "completed". The rollback status identifier can be stored in the metadata table of the memory, and its value is a preset status code (such as 00=not started, 01=rollback in progress, 10=rollback completed, 11=interrupted).
[0097] For example, the controller can be configured with a dual monitoring mechanism using a watchdog timer and a power failure detection circuit to monitor the rollback process in real time. In this case, the watchdog timer can check the rollback progress according to a preset detection cycle. If no progress update is detected for more than a preset time, such as 100ms, it can be determined that the rollback is interrupted. At the same time, the power failure detection circuit can monitor the power supply status in real time. If a power failure signal is detected, the rollback interruption status can be recorded immediately.
[0098] Understandably, the aforementioned rollback interruption flag can refer to the code (e.g., 11) in the rollback status flag indicating that the rollback process was interrupted due to an anomaly (such as power failure or hardware malfunction). In this case, if the controller detects a rollback interruption flag in the rollback status flag field of the periodically read metadata table, it can trigger a retry mechanism. Since the data rollback process in this embodiment, i.e., the mapping update operation, is an atomic operation, the controller only needs to wait for the system to recover and then repeat the mapping pointer switching step, i.e., automatically re-execute the step of "switching the mapping pointer from the secondary mapping table to the secondary snapshot mapping table," thus quickly achieving data rollback without the risk of data tearing. Furthermore, before each retry, the controller can first check the integrity of the snapshot storage area and the mapping table; if data corruption is found, it will be repaired before performing the switching operation.
[0099] Therefore, compared to existing snapshot rollback technologies, which are prone to interruptions due to external factors such as power outages and hardware failures during the snapshot rollback process, and which are non-atomic operations that can easily lead to data tearing, mapping disorder, and data inconsistency after interruption, making it impossible to complete the rollback normally, this embodiment can not only monitor the rollback status in real time through a dual monitoring mechanism to detect interruption anomalies in a timely manner, but also automatically resume the rollback process after an interruption by combining the atomicity of mapping pointer switching and the retry mechanism, thus avoiding data tearing and inconsistency caused by interruption and improving the robustness and security of data rollback.
[0100] It is easy to understand that after a rollback, invalid data blocks will occupy a large amount of storage space, resulting in wasted storage resources. Immediately performing the cleanup of invalid data blocks could easily block normal host operations and impact storage performance. In a feasible implementation, refer to... Figure 4 , Figure 4 This is a second flowchart illustrating the data rollback method of this application in Embodiment 2. In this embodiment, steps S40 and S70 may be included after step S60:
[0101] Step S60: When the rollback status identifier is detected as a rollback completion identifier, obtain the invalid data block in the snapshot storage area;
[0102] Step S70: If the preset clearing conditions are met, the invalid data block is cleared by an asynchronous garbage collection thread.
[0103] It is important to understand that the aforementioned invalid data blocks can be physical storage blocks pointed to by the original first-level mapping table after the rollback is completed. The data in these storage blocks is no longer referenced by the currently active first-level snapshot mapping table, and there is no other valid data stored in them. They are considered reclaimable and discarded storage blocks. For example, when the controller detects that the rollback status flag is a rollback completion flag (such as 10), it can determine that the data rollback is complete. Then, the controller can scan all physical storage blocks pointed to by the original first-level mapping table, and by comparing the reference relationships of the currently active first-level snapshot mapping table, filter out storage blocks that are not referenced and have no other valid data, mark them as invalid data blocks, and record their address, quantity, and reclamation priority information to the invalid block list.
[0104] The aforementioned asynchronous garbage collection thread refers to a low-priority garbage collection (GC) thread running in the background to reclaim invalid data blocks. In this embodiment, the asynchronous garbage collection thread runs at a lower priority than the host I / O request processing priority to ensure that valid data (if present) in invalid data blocks is migrated to other storage blocks without blocking foreground services, and then the invalid data blocks are erased to release storage space. Accordingly, the aforementioned preset clearing condition can be the triggering condition for the asynchronous garbage collection thread. For example, in this embodiment, the preset clearing condition can include two methods: one is a time condition (such as triggering once every 5 minutes); the other is a threshold condition (such as invalid data blocks accounting for more than 20% of the total storage blocks).
[0105] At this time, the controller can count the proportion of invalid data blocks to the total storage blocks in real time, and monitor the time interval. If the proportion exceeds 20% (threshold condition) or more than 5 minutes have passed since the last garbage collection (time condition), it is determined that the preset cleaning conditions are met.
[0106] Once the preset cleanup conditions are met, the controller can initiate a low-priority background garbage collection thread to read the invalid block list. Using a wear leveling algorithm (to even out the wear of storage blocks and extend the memory's lifespan), it systematically migrates any remaining valid data (such as incompletely overwritten old data) from invalid blocks to less worn free storage blocks. Then, the invalid blocks are erased, the storage block status is updated to "free," storage space is released, and the blocks are removed from the invalid block list. During garbage collection, if a new host I / O request arrives, the garbage collection thread pauses execution, prioritizing the handling of I / O requests, and resumes collection only after the request is processed.
[0107] In this implementation, an asynchronous garbage collection thread can reclaim invalid data blocks without blocking host operations, thereby freeing up storage space and improving storage resource utilization. Simultaneously, preset cleanup conditions ensure that garbage collection is performed on demand, avoiding performance degradation caused by frequent collection.
[0108] In summary, referring to Figure 5 An example is provided to illustrate the snapshot rollback process. Figure 5 This is a schematic diagram of the snapshot rollback process of the data rollback method in this application. For example... Figure 5As shown, when the memory controller receives a data rollback command from the host, it can retrieve the original snapshot mapping, i.e., the secondary snapshot mapping table, from the snapshot storage area. Then, at the flash translation layer of the memory, it performs an atomic switch of the snapshot mapping based on the secondary snapshot mapping table—an atomic-level switching of the mapping pointer—changing the mapping pointer from the original secondary mapping table to the secondary snapshot mapping table, thereby quickly switching to the primary snapshot mapping table corresponding to the secondary snapshot mapping table, and then retrieving the snapshot data for data rollback. Furthermore, after the rollback is complete, the controller can also initiate an asynchronous garbage collection thread to reclaim invalid data blocks as needed, orderly releasing storage space.
[0109] This embodiment discloses a secondary snapshot mapping table constructed based on a secondary mapping table for locating the position of the primary snapshot mapping table; in response to a data rollback instruction, the mapping pointer corresponding to the mapping update operation is switched from the secondary mapping table to the secondary snapshot mapping table, so as to switch from the primary mapping table to the primary snapshot mapping table, obtain snapshot data, and perform data rollback.
[0110] Therefore, this embodiment generates a mapping backup of the original snapshot data, namely a secondary snapshot mapping table, when creating a snapshot. During snapshot rollback, the snapshot data is directly accessed by switching from the secondary mapping table to the secondary snapshot mapping table, thereby further shortening the rollback operation time and optimizing the rollback operation time complexity from O(N) to O(1), achieving second-level rollback, effectively solving the problem of long snapshot rollback time.
[0111] This embodiment also discloses monitoring the real-time status of data rollback and obtaining the rollback status identifier. When the rollback status identifier is detected as a rollback interruption identifier, the steps of responding to the data rollback command and switching the mapping pointer corresponding to the mapping update operation from the secondary mapping table to the secondary snapshot mapping table are repeated until the rollback status identifier is detected as a rollback completion identifier. When the rollback status identifier is detected as a rollback completion identifier, invalid data blocks in the snapshot storage area are obtained. Under the condition of meeting the preset clearing conditions, the invalid data blocks are cleared through an asynchronous garbage collection thread. Since snapshot rollback is an atomic operation of direct mapping switching without intermediate states, this embodiment can also wait for the system to recover and re-perform the mapping switching to trigger rollback when rollback fails, solving the problem of non-atomicity of existing snapshot rollback and data tearing caused by abnormal interruption during rollback. In addition, this embodiment can adopt an asynchronous garbage collection mechanism to ensure that the storage service can be resumed immediately after the rollback is completed. That is, the asynchronous garbage collection mechanism can asynchronously reclaim a large number of invalid data blocks generated after rollback in the background, realizing orderly release of storage space without blocking the current service.
[0112] It should be noted that the above examples are only for understanding this application and do not constitute a limitation on the data rollback method of this application. Any simple modifications based on this technical concept are within the protection scope of this application.
[0113] This application provides a memory comprising: at least one controller; and a flash memory communicatively connected to the at least one controller; wherein the flash memory stores instructions executable by the at least one controller, the instructions being executed by the at least one controller to enable the at least one controller to perform the data rollback method described in the above embodiments.
[0114] The memory in this application embodiment includes, but is not limited to, storage devices that support flash memory, such as solid-state drives (SSDs), embedded multimedia cards (eMMCs), universal flash storage (UFS), and secure digital memory cards (SD cards).
[0115] Flash memory can refer to storage units in memory used to store information such as data rollback programs, snapshot data, mapping tables, and metadata. It can include cache (such as SRAM) and non-volatile memory (such as NAND flash memory chips (NOT-AND)).
[0116] The controller can refer to the processing unit (such as MCU or CPU core) built into the memory controller. It has the capabilities of instruction execution, data processing, and logic control. It is used to run data rollback programs and realize functions such as snapshot creation, mapping switching, rollback execution, and garbage collection.
[0117] The memory provided in this application, employing the data rollback method described in the above embodiments, can solve the technical problem of how to improve data rollback speed. Compared with the prior art, the beneficial effects of the memory provided in this application are the same as those of the data rollback method provided in the above embodiments, and other technical features of the memory are the same as those disclosed in the previous embodiment method, and will not be repeated here.
[0118] It should be understood that the various parts disclosed in this application can be implemented using hardware, software, firmware, or a combination thereof. In the description of the above embodiments, specific features, structures, materials, or characteristics can be combined in any suitable manner in one or more embodiments or examples.
[0119] The above are merely specific embodiments of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.
[0120] To achieve the above objectives, this application also proposes an electronic device that includes the memory mentioned above.
[0121] The electronic device in this application embodiment can be a computing service device equipped with memory that has data storage, data processing and program execution functions, and needs to protect critical data (such as system data). It can include, but is not limited to, mobile terminals such as mobile phones, laptops, digital broadcast receivers, PDAs (Personal Digital Assistants), PADs (Portable Application Description), PMPs (Portable Media Players), vehicle terminals (such as vehicle navigation terminals), and fixed terminals such as digital TVs and desktop computers.
[0122] Since this electronic device adopts all the technical solutions of all the above-described embodiments of the memory, it has at least all the beneficial effects brought about by the technical solutions of the above-described embodiments, which will not be repeated here.
[0123] To achieve the above objectives, this application provides a storage medium having computer-readable program instructions (i.e., a data rollback program) stored thereon, which are used to execute the data rollback method described in the above embodiments.
[0124] The storage medium provided in this application may be, for example, a USB flash drive, but is not limited to, electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, devices, or any combination thereof. More specific examples of the storage medium may include, but are not limited to: electrical connections with one or more wires, portable computer disks, hard disks, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM or flash memory), optical fiber, portable compact disk read-only memory (CD-ROM), optical storage devices, magnetic storage devices, or any suitable combination thereof. In this embodiment, the storage medium may be any tangible medium containing or storing a program that can be used by or in conjunction with an instruction execution system, system, or device. The program code contained on the storage medium may be transmitted using any suitable medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination thereof.
[0125] The aforementioned storage medium may be contained within a memory; or it may exist independently and not be assembled into a memory.
[0126] When the storage medium is flash memory, the data rollback program is stored as firmware in a specific area of the chip. The memory's main control chip (controller) automatically loads and runs the program after power-on, thus implementing the data rollback method mentioned above.
[0127] When the storage medium is an independent USB flash drive, hard drive, etc., the CPU of the electronic device can read the data rollback program in the storage medium through the interface, load it into the flash memory of the memory and run it, thereby controlling the memory of the electronic device to execute the data rollback method mentioned above (the memory needs to support FTL layer configuration and redirection functions).
[0128] The aforementioned storage medium carries one or more programs, which, when executed by the controller in the memory, enable the memory to determine how to improve the data rollback speed.
[0129] Furthermore, the data rollback program can be adapted to the characteristics of different storage media and controllers. For example, the code of the FTL parameter configuration module can be adjusted for different storage media such as SSD and eMMC, and the code of the instruction execution module can be adjusted for different controller architectures, ensuring that the program can accurately implement the technical solution of the data rollback method mentioned above in different hardware environments.
[0130] Data rollback program code for performing the operations of this application can be written in one or more programming languages or a combination thereof. These programming languages include object-oriented programming languages—such as Java, Smalltalk, and C++—and conventional procedural programming languages—such as the "C" language or similar programming languages. The program code can be executed entirely on the user's computer, partially on the user's computer, as a standalone software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In cases involving remote computers, the remote computer can be connected to the user's computer via any type of network—including a Local Area Network (LAN) or a Wide Area Network (WAN)—or can be connected to an external computer (e.g., via the Internet using an Internet service provider).
[0131] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and data rollback program products according to various embodiments of this application. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions indicated in the blocks may occur in a different order than those indicated in the drawings. For example, two consecutively indicated blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. It should also be noted that each block in the block diagrams and / or flowcharts, and combinations of blocks in the block diagrams and / or flowcharts, may be implemented using a dedicated hardware-based system that performs the specified function or operation, or using a combination of dedicated hardware and computer instructions.
[0132] The modules described in the embodiments of this application can be implemented in software or hardware. The names of the modules do not necessarily limit the functionality of the unit itself.
[0133] The above are only some embodiments of this application and do not limit the scope of the solution of this application. All equivalent structural transformations made under the technical concept of this application and using the content of this application specification and drawings, or direct / indirect applications in other related technical fields, are included within the protection scope of this application.
Claims
1. A data rollback method, characterized by, The data rollback method is applied to the memory, and the method includes: In response to a snapshot creation command, snapshot data corresponding to the target data and a first-level snapshot mapping table for directing the snapshot data are generated; Construct a secondary mapping table for orienting the location of the primary mapping table, wherein the primary mapping table is used to orient the target data; In response to a data rollback command, the mapping update operation is switched from the first-level mapping table to the first-level snapshot mapping table based on the second-level mapping table, and the snapshot data is obtained for data rollback. The step of generating snapshot data corresponding to the target data and a first-level snapshot mapping table for directing the snapshot data in response to the snapshot creation instruction includes: In response to the snapshot creation command, the target data corresponding to the snapshot time point is copied to the snapshot storage area to generate snapshot data; Change the address index of the first-level mapping table used to direct the target data so that the first-level mapping table contains the address mapping relationship between the logical address of the snapshot data and the physical address of the snapshot storage area; Copy the modified address index of the first-level mapping table to the snapshot storage area to generate a first-level snapshot mapping table for directing the snapshot data; The step of switching the mapping update operation from the first-level mapping table to the first-level snapshot mapping table based on the second-level mapping table in response to the data rollback command, and obtaining the snapshot data for data rollback, includes: A secondary snapshot mapping table is constructed based on the secondary mapping table to orient the location of the primary snapshot mapping table; In response to a data rollback command, the mapping pointer corresponding to the mapping update operation is switched from the secondary mapping table to the secondary snapshot mapping table, so as to switch from the primary mapping table to the primary snapshot mapping table, and the snapshot data is obtained for data rollback.
2. The data rollback method of claim 1, wherein, After copying the modified address indexed first-level mapping table to the snapshot storage area and generating a first-level snapshot mapping table for directing the snapshot data, the method further includes: The validity of the address index entries contained in the first-level snapshot mapping table is checked based on the physical address of the snapshot storage area. If the validity check results in that the physical address of the address index entry does not point to the snapshot storage area, the first-level snapshot mapping table is updated.
3. The data rollback method of claim 1, wherein, Before generating snapshot data corresponding to the target data and a first-level snapshot mapping table for directing the snapshot data in response to the snapshot creation instruction, the process includes: Obtain the real-time data load corresponding to the memory; Based on the real-time data load, a snapshot storage area is created in the idle cache block pool.
4. The data rollback method of claim 1, wherein, After switching the mapping pointer corresponding to the mapping update operation from the secondary mapping table to the secondary snapshot mapping table in response to the data rollback instruction, the method further includes: Monitor the real-time status of the data rollback and obtain the rollback status identifier; When the rollback status identifier is detected as a rollback interruption identifier, the step of switching the mapping pointer corresponding to the mapping update operation from the secondary mapping table to the secondary snapshot mapping table in response to the data rollback instruction is repeated until the rollback status identifier is detected as a rollback completion identifier.
5. The data rollback method of claim 4, wherein, After monitoring the real-time status of the data rollback and obtaining the rollback status identifier, the method further includes: When the rollback status identifier is detected as a rollback completion identifier, invalid data blocks in the snapshot storage area are retrieved; Under the condition that the preset clearing conditions are met, the invalid data block is cleared by an asynchronous garbage collection thread.
6. A memory, comprising: The memory includes: a controller, flash memory, and a data rollback program stored on the flash memory and executable on the controller, the data rollback program being configured to implement the steps of the data rollback method as described in any one of claims 1 to 5.
7. An electronic device, comprising: The electronic device includes: the memory as described in claim 6.
8. A storage medium, characterized by The storage medium stores a data rollback program, which, when executed by the controller, implements the steps of the data rollback method as described in any one of claims 1 to 5.