A method, device, equipment and medium for handling exceptions
By setting the target strip in the solid-state drive and using the exclusive OR operation of metadata and verification data, the data recovery problem in double abnormal situations is solved, and the logical address and P2L table of user data are quickly restored, improving hard disk performance and data consistency.
Patent Information
- Application Number
- CN202510059217.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-15
- Publication Date
- 2025-03-14
- Estimated Expiration
- 2045-01-15
AI Technical Summary
When the P2L table reading of the solid-state drive fails and the user data reading fails, the existing technology is difficult to quickly resolve the dual abnormality, resulting in long data recovery time and degradation of hard disk performance.
By setting the target strip in the hard disk, including a physical page for storing user data and metadata, a P2L table and a physical page for storing user data, and using the second metadata all 1 and verification data for XOR operation, quickly recover the logical address of the target user data, and reconstruct the P2L table to recover the user data.
In the case of dual abnormalities, the logical address and P2L table of the target user data can be quickly restored, the data recovery time can be reduced, the hard disk performance can be improved, and the data consistency and hard disk stability can be ensured.
Smart Images

Figure CN119473731B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of hard disk technology, and in particular to an exception handling method, device, equipment and medium. Background Art
[0002] Since the NAND (Not AND, a flash memory technology) in the SSD (Solid State Disk) does not support overwrite, it can only be erased before writing. The overwrite operation on the host will be written on the new physical page of NAND, and the original old data will become garbage data on its physical block, resulting in insufficient user space on the SSD. Therefore, the garbage collection process is required to move the valid data in the physical block, and then erase the physical block to obtain a new physical block that can be written with data.
[0003] Before garbage collection moves valid data in physical blocks, it needs to determine which data is valid, so it needs to read the physical to logical mapping table (Physical to Logical Mapping Table, or P2L table) first. Due to the continuous use of the disk, some data may become invalid. If the P2L reading fails and cannot be restored through the XOR technology, it means that some user data has also failed to read. In this case, the existing solution is to obtain the physical address and logical address of all user data to reconstruct. Then, for the user data that failed to read the current stripe, the logical to physical mapping table (Logical to PhysicalMapping Table, or L2P table) can only be traversed through the physical address. However, the L2P table is extremely large. If it is an 8T disk, the L2P table is theoretically 8G in size, so it takes a very long time, which greatly reduces the performance of the hard disk.
[0004] In summary, when a stripe encounters a double abnormality of both a P2L table read failure and a user data read failure, how to quickly resolve the double abnormality and recover the data to ensure data consistency and hard disk stability is a problem that needs to be solved. Summary of the invention
[0005] In view of this, the purpose of the present invention is to provide an exception handling method, device, equipment and medium, which can quickly solve the double abnormal situation and restore data when a stripe fails to read both the P2L table and the user data, so as to ensure the consistency of data and the stability of the hard disk. The specific scheme is as follows:
[0006] In a first aspect, the present application discloses an exception handling method, comprising:
[0007] Determine a target stripe in a hard disk to be subjected to a garbage collection process; the target stripe includes a first physical page for storing user data and first metadata, a second physical page for storing a P2L table and second metadata, and a third physical page for storing check data and third metadata; the first metadata is a logical address of the user data, each bit of the second metadata is 1, the third metadata is an XOR result of the first metadata and the second metadata, and the check data is an XOR result of the user data and the P2L table;
[0008] When garbage collection is performed on each of the first physical pages, if the P2L table fails to be read and there is a target user data that fails to be read, the first metadata corresponding to the target user data is restored based on the second metadata, the third metadata, and the first metadata corresponding to the remaining user data;
[0009] Whether the target user data is valid is determined based on the first metadata corresponding to the target user data and the L2P table; if the target user data is valid, the P2L table is reconstructed based on the first metadata corresponding to the target user data and the first metadata corresponding to the remaining user data, so as to restore the target user data by using the reconstructed P2L table, the remaining user data and the verification data.
[0010] Optionally, the exception handling method further includes:
[0011] When performing garbage collection on each of the first physical pages, reading the P2L table to determine the validity of the user data stored in each of the first physical pages;
[0012] If the reading of the P2L table fails, reading the check data and all the user data to restore the P2L table using the check data and all the user data, and then jumping to the step of reading the P2L table to determine the validity of the user data stored in each of the first physical pages;
[0013] If there is a target user data reading failure, jump to the step of restoring the first metadata corresponding to the target user data based on the second metadata, the third metadata and the first metadata corresponding to the remaining user data.
[0014] Optionally, the P2L table is used to store a mapping relationship between an initial physical address of each user data and a logical address, and the L2P table is used to store a mapping relationship between a logical address of each user data and a latest physical address;
[0015] Accordingly, reading the P2L table to determine the validity of the user data stored in each of the first physical pages includes:
[0016] Acquire a logical address and a first physical address corresponding to each user data stored in the first physical page from the P2L table;
[0017] Searching the corresponding second physical address from the L2P table according to the logical address corresponding to each of the user data;
[0018] If the first physical address is the same as the second physical address, it is determined that the user data stored in the first physical page is valid; otherwise, it is determined that the user data stored in the first physical page is invalid.
[0019] Optionally, after reading the P2L table to determine the validity of the user data stored in each of the first physical pages, the method further includes:
[0020] If the user data stored in any of the physical pages is valid, performing data migration processing on the corresponding user data;
[0021] If the user data stored in any of the physical pages is invalid, data discard processing is performed on the corresponding user data.
[0022] Optionally, the determining whether the target user data is valid based on the first metadata corresponding to the target user data and the L2P table includes:
[0023] Determine a target logical address of the target user data based on first metadata corresponding to the target user data, and search the L2P table for a target physical address corresponding to the target logical address;
[0024] Determining whether the target physical address is the same as the current physical address of the target user data;
[0025] If the target physical address is the same as the current physical address, determining that the target user data is valid;
[0026] If the target physical address is different from the current physical address, the target user data is determined to be invalid, and data discarding processing is performed on the target user data.
[0027] Optionally, after reconstructing the P2L table based on the first metadata corresponding to the target user data and the first metadata corresponding to the remaining user data, the method further includes:
[0028] reading the reconstructed P2L table to determine the validity of the remaining user data;
[0029] If it is determined that the remaining user data is valid, data migration processing is performed on the remaining user data; if it is determined that the remaining user data is invalid, data discard processing is performed on the remaining user data.
[0030] Optionally, the exception handling method further includes:
[0031] Performing a bit-by-bit XOR operation on each of the first metadata and each of the second metadata to obtain the third metadata, and performing a bit-by-bit XOR operation on each of the user data and each of the P2L tables to obtain the verification data;
[0032] Accordingly, restoring the first metadata corresponding to the target user data based on the second metadata, the third metadata, and the first metadata corresponding to the remaining user data includes:
[0033] Performing bit-wise XOR operation on the second metadata, the third metadata, and the first metadata corresponding to the remaining user data to restore the first metadata corresponding to the target user data;
[0034] Accordingly, the use of the reconstructed P2L table, the remaining user data and the verification data to restore the target user data includes:
[0035] The reconstructed P2L table, the remaining user data and the check data are subjected to bit-by-bit XOR operation to restore the target user data.
[0036] In a second aspect, the present application discloses an exception handling device, comprising:
[0037] a stripe determination module, configured to determine a target stripe in a hard disk to be subjected to a garbage collection process; the target stripe comprises a first physical page for storing user data and first metadata, a second physical page for storing a P2L table and second metadata, and a third physical page for storing check data and third metadata; the first metadata is a logical address of user data, each bit of the second metadata is 1, the third metadata is an XOR result of the first metadata and the second metadata, and the check data is an XOR result of the user data and the P2L table;
[0038] a metadata recovery module, configured to, when garbage collection is performed on each of the first physical pages, if the P2L table fails to be read and there is a target user data that fails to be read, recover the first metadata corresponding to the target user data based on the second metadata, the third metadata, and the first metadata corresponding to the remaining user data;
[0039] a user data recovery module, configured to determine whether the target user data is valid based on the first metadata corresponding to the target user data and the L2P table; if the target user data is valid, reconstructing the P2L table based on the first metadata corresponding to the target user data and the first metadata corresponding to the remaining user data, so as to recover the target user data by using the reconstructed P2L table, the remaining user data and the verification data.
[0040] In a third aspect, the present application discloses an electronic device, comprising:
[0041] Memory, used to store computer programs;
[0042] The processor is used to execute the computer program to implement the steps of the above-disclosed exception handling method.
[0043] In a fourth aspect, the present application discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the steps of the above-disclosed exception handling method are implemented.
[0044] It can be seen that the present application first determines the target stripe in the hard disk for executing the garbage collection process; the target stripe includes a first physical page for storing user data and first metadata, a second physical page for storing a P2L table and second metadata, and a third physical page for storing verification data and third metadata; the first metadata is a logical address of the user data, each bit of the second metadata is 1, the third metadata is an XOR result of the first metadata and the second metadata, and the verification data is an XOR result of the user data and the P2L table; when garbage collection is performed on each of the first physical pages, if the P2L table fails to read and there is a target user data read failure, the first metadata corresponding to the target user data is restored based on the second metadata, the third metadata, and the first metadata corresponding to the remaining user data; based on the first metadata corresponding to the target user data and the L2P table, it is determined whether the target user data is valid; if the target user data is valid, the P2L table is reconstructed based on the first metadata corresponding to the target user data and the first metadata corresponding to the remaining user data, so as to restore the target user data using the reconstructed P2L table, the remaining user data, and the verification data.
[0045] Beneficial effect: When storing data in a hard disk, each stripe of the present application includes a first physical page for storing user data and a first metadata, a second physical page for storing a P2L table and a second metadata, and a third physical page for storing verification data and a third metadata, wherein the first metadata is used to store the logical address of the user data, and the P2L table records the mapping relationship from the physical address to the logical address of each user data, and writes each bit of the corresponding second metadata as 1, and finally, the XOR result of all user data and the P2L table is used as verification data, and the XOR result of the first metadata and the second metadata is used as the third metadata corresponding to the verification data. Furthermore, when garbage collection is performed on each first physical page, if the P2L table fails to be read and there is a target user data that fails to be read, it means that a double abnormal situation has occurred at this time. Since the values of the second metadata are all 1, the present application can quickly recover the first metadata corresponding to the target user data based on the second metadata, the third metadata and the first metadata corresponding to the remaining user data, that is, recover the logical address of the target user data, and then determine whether the target user data is valid data by reading the L2P table. If it is valid, since all the metadata in the target stripe are known at this time, the present application can reconstruct the P2L table based on the first metadata corresponding to the target user data and the first metadata corresponding to the remaining user data, and finally use the reconstructed P2L table, the remaining user data and the verification data to restore the target user data. In this way, the present application fixes the metadata of the P2L data to 1, so that in the event of a double exception, there is no need to use the physical address of the target user data to globally traverse the L2P table. Instead, the metadata of the target user data can be quickly recovered and the P2L table can be quickly rebuilt, thereby restoring the double exception scenario of read failure to a single exception scenario, and finally recovering the target user data of the read failure, ensuring data consistency and hard disk stability. BRIEF DESCRIPTION OF THE DRAWINGS
[0046] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying any creative work.
[0047] Figure 1 A flow chart of an exception handling method disclosed in this application;
[0048] Figure 2 A schematic diagram of an IO data sector format disclosed in this application;
[0049] Figure 3A schematic diagram of a stripe storage structure disclosed in this application;
[0050] Figure 4 A schematic diagram of a double abnormal situation of a strip disclosed in this application;
[0051] Figure 5 A specific exception handling method flow chart disclosed in this application;
[0052] Figure 6 This is a schematic diagram of the structure of an exception handling device disclosed in this application;
[0053] Figure 7 This is a structural diagram of an electronic device disclosed in this application. DETAILED DESCRIPTION
[0054] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative work are within the scope of protection of the present invention.
[0055] When a stripe fails to read both the P2L table and the user data, the existing solution is to obtain the physical and logical addresses of all user data to rebuild it. For the user data that failed to read the current stripe, the mapping table of logical addresses to physical addresses (i.e., L2P table) can only be traversed through the physical address. However, the L2P table is very large. If it is an 8T disk, the L2P table is theoretically 8G in size, so it takes a very long time, which greatly reduces the performance of the hard disk.
[0056] To this end, the embodiments of the present application disclose an exception handling method, apparatus, device and medium, which can quickly resolve the dual abnormal situation and recover data when a stripe has a dual abnormal situation of both P2L table reading failure and user data reading failure, so as to ensure data consistency and hard disk stability.
[0057] See also Figure 1 As shown, the embodiment of the present application discloses an exception handling method, which includes:
[0058] Step S11: determining a target stripe in the hard disk for executing a garbage collection process; the target stripe includes a first physical page for storing user data and first metadata, a second physical page for storing a P2L table and second metadata, and a third physical page for storing verification data and third metadata; the first metadata is a logical address of the user data, each bit of the second metadata is 1, the third metadata is an XOR result of the first metadata and the second metadata, and the verification data is an XOR result of the user data and the P2L table.
[0059] In this embodiment, the target stripe for the garbage collection process to be executed in the solid-state hard disk is first determined. It should be pointed out that when the present application stores data in the hard disk, each stripe includes a first physical page for storing user data and first metadata, a second physical page for storing the P2L table and the second metadata, and a third physical page for storing verification data and third metadata, wherein the first metadata is used to store the logical address of the user data, and the P2L table records the mapping relationship from the physical address of each user data to the logical address, and writes each bit of the corresponding second metadata as 1, and finally, the XOR result of all user data and the P2L table is used as verification data, and the XOR result of the first metadata and the second metadata is used as the third metadata corresponding to the verification data.
[0060] It is understandable that different hard disks have different sector formats. Figure 2 For example, each IO (Input / Output) data sent by the host has 4K user data and a total of 80 bytes of reserved bytes and metadata bytes, where FMD (Flash Meta Data) represents metadata, and each IO data records the logical address (LBA, Logical Block Address) of the data in the first 4 bytes of its FMD. It should be noted that disks of different sizes may have different LBA sizes. This embodiment only takes 4 bytes as an example and does not limit the size of LBA.
[0061] In this embodiment, each IO data will be stored using a physical page, and this type of physical page is recorded as the first physical page, that is, it is mainly used to store user data and the corresponding first metadata, and the first metadata is used to store the logical address of the user data. Further, each IO data will generate a mapping relationship table from physical address to logical address (i.e., P2L table), and store it in the P2L Buffer cache. When the write stripe is written to the P2L position, the P2L Buffer cache will be written to the corresponding P2L position, such as Figure 3 IO P2LAs shown, before writing, all metadata in the P2L data is written as a fixed value of 1. It can be understood that the sector format used by the P2L data is also the same as Figure 2 The sector format shown in FIG. 1 is consistent with that shown in FIG. 1 , that is, it also includes a data area for storing a P2L table and corresponding metadata. Here, the P2L table and the second metadata are collectively referred to as IO P2L , and this application writes each bit of the second metadata corresponding to the P2L table as a fixed value of 1, and then writes it into the physical page of the stripe, and records this type of physical page as the second physical page. It should be noted that the number of the second physical page can be one or more, which mainly depends on the size of the hard disk and the number of the first physical pages.
[0062] After the P2L data is written to the disk, all the user data in the first physical page and all the P2L tables in the second physical page are XORed to generate the check data. Similarly, all the first metadata and all the second metadata are XORed to generate the third metadata. Then the check data and the third metadata are written to the last position IO of the stripe. XOR , that is, use one physical page to store it, and record this type of physical page as the third physical page. A complete stripe storage structure is as follows Figure 3 As shown in , multiple stripes constitute a complete physical block (ie, Block).
[0063] In a specific implementation, during the XOR operation, it specifically includes: performing bit-wise XOR operation on each of the first metadata and each of the second metadata to obtain the third metadata, and performing bit-wise XOR operation on each of the user data and each of the P2L tables to obtain the verification data. That is, during the XOR operation, each data is operated bit-wise, for example, performing bit-wise XOR operation on the first bit of each of the first metadata and the first bit of each of the second metadata to obtain the first bit of the third metadata; similarly, performing bit-wise XOR operation on the first bit of each of the user data and the first bit of each of the P2L tables to obtain the first bit of the verification data; and so on, to obtain the complete third metadata and verification data.
[0064] Step S12: when performing garbage collection on each of the first physical pages, if the P2L table fails to be read and there is a target user data that fails to be read, the first metadata corresponding to the target user data is restored based on the second metadata, the third metadata and the first metadata corresponding to the remaining user data.
[0065] In this embodiment, when garbage collection is performed on each first physical page, if the P2L table fails to be read and there is a target user data read failure, it means that a double abnormal situation has occurred at this time. Since the values of the second metadata are all 1, the present application can quickly recover the first metadata corresponding to the target user data based on the second metadata, the third metadata and the first metadata corresponding to the remaining user data, that is, recover the logical address of the target user data.
[0066] Specifically, the restoring the first metadata corresponding to the target user data based on the second metadata, the third metadata, and the first metadata corresponding to the remaining user data includes: performing bit-by-bit XOR operations on the second metadata, the third metadata, and the first metadata corresponding to the remaining user data to restore the first metadata corresponding to the target user data. It can be understood that when restoring the first metadata corresponding to the target user data, this embodiment also needs to perform bit-by-bit XOR operations on the second metadata, the third metadata, and the first metadata corresponding to the remaining user data.
[0067] That is, this embodiment needs to separate out the metadata corresponding to all the successfully read user data and verification data, and it is known that the metadata corresponding to the P2L table is fixed to all 1s, so performing XOR on all the metadata can restore the metadata of the target data that failed to be read, and thus the logical address of the target user data can be obtained. Figure 4 For example, the first metadata corresponding to the target user data is recorded as FMD2, and the first metadata corresponding to the other successfully read user data are recorded as FMD1, FMD3, ..., FMD n , the third metadata corresponding to the verification data is recorded as FMD xor Then, according to the characteristics of the XOR operation, each bit is calculated. Since the second metadata corresponding to the P2L table is all 1, then for each bit b in FMD2 2i , there is b 2i =1 XOR b 1i XOR b 3i XOR…XOR b ni ; Among them, b 1i 、b 3i …b ni They are FMD1, FMD3, ..., FMD n The corresponding bit in , i represents the i-th bit in the metadata, and by performing the above calculation on each bit in the metadata in turn, the complete metadata of the target user data can be obtained.
[0068] The complete garbage collection process is described below, and the process specifically includes: when performing garbage collection on each of the first physical pages, reading the P2L table to determine the validity of the user data stored in each of the first physical pages; if the reading of the P2L table fails, reading the verification data and all of the user data, so as to restore the P2L table using the verification data and all of the user data, and then jumping to the step of reading the P2L table to determine the validity of the user data stored in each of the first physical pages; if there is a target user data reading failure, jumping to the step of restoring the first metadata corresponding to the target user data based on the second metadata, the third metadata and the first metadata corresponding to the remaining user data.
[0069] Among them, after reading the P2L table to determine the validity of the user data stored in each of the first physical pages, it also includes: if the user data stored in any of the physical pages is valid, then the corresponding user data is moved; if the user data stored in any of the physical pages is invalid, then the corresponding user data is discarded.
[0070] That is, in a normal process, the P2L table needs to be read to determine the validity of the user data stored in each first physical page. If the user data stored in any physical page is determined to be valid according to the P2L table, the corresponding user data is moved, that is, the valid data is transferred from the old storage location to the new storage location to erase the original physical block, thereby obtaining a new physical block in which data can be written. If the user data stored in any physical page is determined to be invalid according to the P2L table, the corresponding user data is discarded and no further movement is required.
[0071] In a specific embodiment, if the P2L table fails to be read, the validity of the user data stored in the first physical page cannot be determined at this time. Therefore, it is necessary to first read the verification data and all user data, and use the verification data and all user data to perform an XOR operation to restore the P2L table. If the P2L table is restored successfully, continue to perform subsequent steps according to the garbage collection process, that is, re-read the P2L table to determine the validity of the user data stored in each first physical page.
[0072] Further, such as Figure 4 As shown, if it is found that a target user data fails to be read during the process of restoring the P2L table, then the P2L table cannot be restored, and the target user data cannot be restored, thus forming a double abnormality. At this time, the process jumps to the step of restoring the first metadata corresponding to the target user data based on the second metadata, the third metadata, and the first metadata corresponding to the remaining user data.
[0073] In addition, in a specific implementation, the P2L table is used to store the mapping relationship between the initial physical address of each user data and the logical address, and the L2P table is used to store the mapping relationship between the logical address of each user data and the latest physical address; accordingly, reading the P2L table to determine the validity of the user data stored in each first physical page includes: obtaining the logical address and the first physical address corresponding to each user data stored in the first physical page from the P2L table; searching the corresponding second physical address from the L2P table according to the logical address corresponding to each user data; if the first physical address is the same as the second physical address, then determining that the user data stored in the first physical page is valid, otherwise determining that the user data stored in the first physical page is invalid.
[0074] It is understandable that the present application sets up two different mapping tables, one is a P2L table for storing the mapping relationship between the initial physical address of each user data and the logical address, and the P2L table only records the relevant data in a single stripe; the other is an L2P table for storing the mapping relationship between the logical address of each user data and the latest physical address, and the L2P table records the relevant data of the entire hard disk. That is, considering that the physical address of the data may change during use, the P2L table records the initial physical address corresponding to the user data when it was first written, and the L2P table records the latest physical address of the user data. Therefore, when determining the validity of the user data stored in each first physical page, the present application first needs to obtain the logical address and the first physical address corresponding to the user data from the P2L table, and then use the obtained logical address of the user data to search the corresponding second physical address from the L2P table, that is, search for the latest physical address. If the first physical address is the same as the second physical address, it means that the physical address storing the user data has not changed, so it is determined that the user data stored in the first physical page is still valid. If the first physical address is different from the second physical address, it means that the user data has been stored at a new physical address, and then it is determined that the user data stored in the first physical page is invalid.
[0075] Step S13: judging whether the target user data is valid based on the first metadata corresponding to the target user data and the L2P table; if the target user data is valid, reconstructing the P2L table based on the first metadata corresponding to the target user data and the first metadata corresponding to the remaining user data, so as to restore the target user data by using the reconstructed P2L table, the remaining user data and the verification data.
[0076] In this embodiment, after the first metadata corresponding to the target user data is recovered, the L2P table is read to determine whether the target user data is valid data. In the case of validity, since all metadata in the target stripe are known at this time, that is, the logical address of each user data is known, the present application can reconstruct the P2L table based on the first metadata corresponding to the target user data and the first metadata corresponding to the remaining user data, and finally use the reconstructed P2L table and verification data to restore the target user data. In this way, the present application fixes the metadata of the P2L data to 1, so that in the case of double anomalies, there is no need to use the physical data of the target user data to globally traverse the L2P table, but can quickly restore the metadata of the target user data, and quickly rebuild the P2L table, thereby restoring the double anomaly scenario of read failure to a single anomaly scenario, and finally recovering the target user data of the read failure, ensuring data consistency and hard disk stability.
[0077] In a specific implementation, the above-mentioned use of the reconstructed P2L table, the remaining user data and the verification data to restore the target user data includes: performing an XOR operation on the reconstructed P2L table, the remaining user data and the verification data bit by bit to restore the target user data. It can be understood that when restoring the target user data, this embodiment also needs to perform an XOR operation on the reconstructed P2L table, the remaining user data and the verification data bit by bit.
[0078] It can be seen that when the present application stores data in a hard disk, each stripe includes a first physical page for storing user data and a first metadata, a second physical page for storing a P2L table and a second metadata, and a third physical page for storing verification data and a third metadata, wherein the first metadata is used to store the logical address of the user data, and the P2L table records the mapping relationship from the physical address to the logical address of each user data, and writes each bit of the corresponding second metadata as 1, and finally, the XOR result of all user data and the P2L table is used as verification data, and the XOR result of the first metadata and the second metadata is used as the third metadata corresponding to the verification data. Furthermore, when garbage collection is performed on each first physical page, if the P2L table fails to be read and there is a target user data read failure, it means that a double abnormal situation has occurred at this time. Since the values of the second metadata are all 1, the present application can quickly recover the first metadata corresponding to the target user data based on the second metadata, the third metadata and the first metadata corresponding to the remaining user data, that is, recover the logical address of the target user data, and then determine whether the target user data is valid data by reading the L2P table. If it is valid, since all the metadata in the target stripe are known at this time, the present application can reconstruct the P2L table based on the first metadata corresponding to the target user data and the first metadata corresponding to the remaining user data, and finally use the reconstructed P2L table and verification data to restore the target user data. In this way, the present application fixes the metadata of the P2L data to 1, so that in the event of a double exception, there is no need to use the physical address of the target user data to globally traverse the L2P table. Instead, the metadata of the target user data can be quickly recovered and the P2L table can be quickly rebuilt, thereby restoring the double exception scenario of read failure to a single exception scenario, and finally recovering the target user data of the read failure, ensuring data consistency and hard disk stability.
[0079] See also Figure 5 As shown, the embodiment of the present application discloses a specific exception handling method. Compared with the previous embodiment, this embodiment further illustrates and optimizes the technical solution. Specifically, it includes:
[0080] Step S21: determine the target stripe in the hard disk for executing the garbage collection process; the target stripe includes a first physical page for storing user data and first metadata, a second physical page for storing a P2L table and second metadata, and a third physical page for storing verification data and third metadata; the first metadata is a logical address of the user data, each bit of the second metadata is 1, the third metadata is an XOR result of the first metadata and the second metadata, and the verification data is an XOR result of the user data and the P2L table.
[0081] Step S22: when performing garbage collection on each of the first physical pages, if the P2L table fails to be read and there is a target user data that fails to be read, the first metadata corresponding to the target user data is restored based on the second metadata, the third metadata and the first metadata corresponding to the remaining user data.
[0082] Step S23: determining a target logical address of the target user data based on the first metadata corresponding to the target user data, and searching the L2P table for a target physical address corresponding to the target logical address.
[0083] In this embodiment, after the first metadata corresponding to the target user data is recovered, the target logical address of the target user data can be determined based on the first metadata corresponding to the target user data, and then the target physical address corresponding to the target logical address can be searched from the L2P table.
[0084] Step S24: Determine whether the target physical address is the same as the current physical address of the target user data. If the target physical address is the same as the current physical address, the target user data is determined to be valid. If the target physical address is not the same as the current physical address, the target user data is determined to be invalid and the target user data is discarded.
[0085] In this embodiment, it is determined whether the target physical address found from the L2P table is the same as the current physical address of the target user data. If they are the same, it means that the physical address storing the target user data has not changed, so the target user data is determined to be valid. If they are not the same, it means that the target user data has been stored at a new physical address, so the target user data is determined to be invalid, and the target user data is discarded. And since the first metadata corresponding to all user data of the current stripe is known at this time, its logical address is also known, and the validity of each user data of the current stripe can be directly determined without restoring the P2L table.
[0086] Step S25: If the target user data is valid, reconstructing the P2L table based on the first metadata corresponding to the target user data and the first metadata corresponding to the remaining user data, so as to restore the target user data using the reconstructed P2L table, the remaining user data and the verification data.
[0087] In this embodiment, if the target user data is valid, the data needs to be restored. First, the P2L table needs to be restored to construct a single abnormal phenomenon from the double abnormal phenomenon. Because both the first metadata corresponding to the target user data and the first metadata corresponding to the remaining user data in the current stripe are known, the P2L table can be rebuilt, that is, the mapping relationship from the physical address to the logical address of each user data is used to reorganize the P2L table, and the double abnormality is restored to a single abnormality scenario. Finally, the target user data is restored using the reconstructed P2L table, the remaining user data and the verification data, and the data migration process is performed later.
[0088] Furthermore, after the above-mentioned reconstructing the P2L table based on the first metadata corresponding to the target user data and the first metadata corresponding to the remaining user data, it also includes: reading the reconstructed P2L table to determine the validity of the remaining user data; if the remaining user data is determined to be valid, performing data migration processing on the remaining user data; if the remaining user data is determined to be invalid, performing data discarding processing on the remaining user data.
[0089] That is, after the P2L table is reconstructed, the reconstructed P2L table can be read to determine the validity of the remaining user data, thereby deciding whether to move or discard the data according to the validity of the remaining user data.
[0090] For more specific processing procedures of the above steps S21 and S22, reference may be made to the corresponding contents disclosed in the above embodiments, which will not be described in detail here.
[0091] It can be seen that the present application writes the metadata of the P2L table to a fixed value of all 1s, and saves the metadata of the user data with the logical address of the user data. When the P2L table reading fails and there is also a user data reading failure in the same strip, the metadata of the P2L table, the verification data, and the metadata of other normal user data are stripped out for metadata XOR. Because the metadata of the P2L table is known to be a fixed value, the double abnormality phenomenon is constructed as a single abnormality, and the metadata of the user data that failed to read is restored, which is used to judge the validity of the user data that failed to read and to restore the P2L table and the user data. The above scheme does not need to globally traverse the entire disk L2P table, which greatly improves the speed of valid data screening in the case of double abnormality reading, thereby improving the time to resolve the abnormality, while ensuring the stability of the hard disk and the consistency of the data.
[0092] See also Figure 6 As shown, the embodiment of the present application discloses an exception handling device, which includes:
[0093] The stripe determination module 11 is used to determine the target stripe in the hard disk to be executed with the garbage collection process; the target stripe includes a first physical page for storing user data and first metadata, a second physical page for storing the P2L table and the second metadata, and a third physical page for storing check data and third metadata; the first metadata is the logical address of the user data, each bit of the second metadata is 1, the third metadata is the XOR result of the first metadata and the second metadata, and the check data is the XOR result of the user data and the P2L table;
[0094] a metadata recovery module 12, configured to, when garbage collection is performed on each of the first physical pages, if the P2L table fails to be read and there is a target user data that fails to be read, recover the first metadata corresponding to the target user data based on the second metadata, the third metadata, and the first metadata corresponding to the remaining user data;
[0095] The user data recovery module 13 is used to determine whether the target user data is valid based on the first metadata corresponding to the target user data and the L2P table. If the target user data is valid, the P2L table is reconstructed based on the first metadata corresponding to the target user data and the first metadata corresponding to the remaining user data, so as to restore the target user data using the reconstructed P2L table, the remaining user data and the verification data.
[0096] It can be seen that when the present application stores data in a hard disk, each stripe includes a first physical page for storing user data and a first metadata, a second physical page for storing a P2L table and a second metadata, and a third physical page for storing verification data and a third metadata, wherein the first metadata is used to store the logical address of the user data, and the P2L table records the mapping relationship from the physical address to the logical address of each user data, and writes each bit of the corresponding second metadata as 1, and finally, the XOR result of all user data and the P2L table is used as verification data, and the XOR result of the first metadata and the second metadata is used as the third metadata corresponding to the verification data. Furthermore, when garbage collection is performed on each first physical page, if the P2L table fails to be read and there is a target user data read failure, it means that a double abnormal situation has occurred at this time. Since the values of the second metadata are all 1, the present application can quickly recover the first metadata corresponding to the target user data based on the second metadata, the third metadata and the first metadata corresponding to the remaining user data, that is, recover the logical address of the target user data, and then determine whether the target user data is valid data by reading the L2P table. If it is valid, since all the metadata in the target stripe are known at this time, the present application can reconstruct the P2L table based on the first metadata corresponding to the target user data and the first metadata corresponding to the remaining user data, and finally use the reconstructed P2L table and verification data to restore the target user data. In this way, the present application fixes the metadata of the P2L data to 1, so that in the event of a double exception, there is no need to use the physical address of the target user data to globally traverse the L2P table. Instead, the metadata of the target user data can be quickly recovered and the P2L table can be quickly rebuilt, thereby restoring the double exception scenario of read failure to a single exception scenario, and finally recovering the target user data of the read failure, ensuring data consistency and hard disk stability.
[0097] Since the embodiments of the device part correspond to the embodiments of the method part, the embodiments of the device part refer to the description of the embodiments of the method part, which will not be described here. In addition, the invention has the same beneficial effects as the above-mentioned exception handling method.
[0098] Figure 7 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Specifically, it may include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the exception handling method performed by the electronic device disclosed in any of the aforementioned embodiments.
[0099] In this embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.
[0100] Among them, the processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 can be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). The processor 21 may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state. In some embodiments, the processor 21 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 21 may also include an AI (Artificial Intelligence) processor, which is used to process computing operations related to machine learning.
[0101] In addition, the memory 22, as a carrier for storing resources, can be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon include an operating system 221, a computer program 222 and data 223, etc. The storage method can be temporary storage or permanent storage.
[0102] Among them, the operating system 221 is used to manage and control the hardware devices and computer programs 222 on the electronic device 20, so as to realize the operation and processing of the massive data 223 in the memory 22 by the processor 21, which can be Windows, Unix, Linux, etc. In addition to including a computer program that can be used to complete the exception handling method performed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program that can be used to complete other specific tasks. In addition to data received by the electronic device and transmitted from an external device, the data 223 can also include data collected by its own input and output interface 25, etc.
[0103] Furthermore, an embodiment of the present application also discloses a computer-readable storage medium, in which a computer program is stored. When the computer program is loaded and executed by a processor, the steps of the exception handling method disclosed in any of the aforementioned embodiments are implemented.
[0104] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.
[0105] Those skilled in the art may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented with electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in terms of function in the above description. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.
[0106] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a compact disc read-only memory (CD-ROM), or any other form of storage medium known in the art.
[0107] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0108] The above is a detailed introduction to an exception handling method, device, equipment and storage medium provided by the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea; at the same time, for a person skilled in the art, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. An exception handling method, characterized in that: include: Determine the target stripe in the hard disk to be executed for the garbage collection process; The target stripe includes a first physical page for storing user data and first metadata, a second physical page for storing a P2L table and second metadata, and a third physical page for storing check data and third metadata; The first metadata is a logical address of the user data, each bit of the second metadata is 1, the third metadata is an XOR result of the first metadata and the second metadata, and the check data is an XOR result of the user data and the P2L table; When garbage collection is performed on each of the first physical pages, if the P2L table fails to be read and there is a target user data that fails to be read, the first metadata corresponding to the target user data is restored based on the second metadata, the third metadata, and the first metadata corresponding to the remaining user data; Whether the target user data is valid is determined based on the first metadata corresponding to the target user data and the L2P table; if the target user data is valid, the P2L table is reconstructed based on the first metadata corresponding to the target user data and the first metadata corresponding to the remaining user data, so as to restore the target user data by using the reconstructed P2L table, the remaining user data and the verification data.
2. The exception handling method according to claim 1, characterized in that: Also includes: When performing garbage collection on each of the first physical pages, reading the P2L table to determine validity of user data stored in each of the first physical pages; If the reading of the P2L table fails, reading the check data and all the user data to restore the P2L table using the check data and all the user data, and then jumping to the step of reading the P2L table to determine the validity of the user data stored in each of the first physical pages; If there is a target user data reading failure, jump to the step of restoring the first metadata corresponding to the target user data based on the second metadata, the third metadata and the first metadata corresponding to the remaining user data.
3. The exception handling method according to claim 2, characterized in that: The P2L table is used to store the mapping relationship between the initial physical address of each user data and the logical address, and the L2P table is used to store the mapping relationship between the logical address of each user data and the latest physical address; Accordingly, reading the P2L table to determine the validity of the user data stored in each of the first physical pages includes: Acquire a logical address and a first physical address corresponding to each user data stored in the first physical page from the P2L table; According to the logical address corresponding to each of the user data, searching the L2P table for the corresponding second physical address; If the first physical address is the same as the second physical address, it is determined that the user data stored in the first physical page is valid; otherwise, it is determined that the user data stored in the first physical page is invalid.
4. The exception handling method according to claim 2, characterized in that: After reading the P2L table to determine the validity of the user data stored in each of the first physical pages, the method further includes: If the user data stored in any of the physical pages is valid, performing data migration processing on the corresponding user data; If the user data stored in any of the physical pages is invalid, data discard processing is performed on the corresponding user data.
5. The exception handling method according to claim 1, characterized in that: The determining whether the target user data is valid based on the first metadata corresponding to the target user data and the L2P table includes: Determine a target logical address of the target user data based on first metadata corresponding to the target user data, and search the L2P table for a target physical address corresponding to the target logical address; Determining whether the target physical address is the same as the current physical address of the target user data; If the target physical address is the same as the current physical address, determining that the target user data is valid; If the target physical address is different from the current physical address, the target user data is determined to be invalid, and data discarding processing is performed on the target user data.
6. The exception handling method according to claim 1, characterized in that: After the P2L table is reconstructed based on the first metadata corresponding to the target user data and the first metadata corresponding to the remaining user data, the method further includes: reading the reconstructed P2L table to determine the validity of the remaining user data; If it is determined that the remaining user data is valid, data migration processing is performed on the remaining user data; if it is determined that the remaining user data is invalid, data discard processing is performed on the remaining user data.
7. The exception handling method according to any one of claims 1 to 6, characterized in that: Also includes: Performing a bit-by-bit XOR operation on each of the first metadata and each of the second metadata to obtain the third metadata, and performing a bit-by-bit XOR operation on each of the user data and each of the P2L tables to obtain the verification data; Accordingly, restoring the first metadata corresponding to the target user data based on the second metadata, the third metadata, and the first metadata corresponding to the remaining user data includes: Performing bit-wise XOR operation on the second metadata, the third metadata, and the first metadata corresponding to the remaining user data to restore the first metadata corresponding to the target user data; Accordingly, the use of the reconstructed P2L table, the remaining user data and the verification data to restore the target user data includes: The reconstructed P2L table, the remaining user data and the check data are subjected to bit-by-bit XOR operation to restore the target user data.
8. An exception handling device, characterized in that: include: A stripe determination module, used to determine a target stripe in the hard disk to be executed for the garbage collection process; The target stripe includes a first physical page for storing user data and first metadata, a second physical page for storing a P2L table and second metadata, and a third physical page for storing check data and third metadata; The first metadata is a logical address of the user data, each bit of the second metadata is 1, the third metadata is an XOR result of the first metadata and the second metadata, and the check data is an XOR result of the user data and the P2L table; a metadata recovery module, configured to, when garbage collection is performed on each of the first physical pages, if the P2L table fails to be read and there is a target user data that fails to be read, recover the first metadata corresponding to the target user data based on the second metadata, the third metadata, and the first metadata corresponding to the remaining user data; a user data recovery module, configured to determine whether the target user data is valid based on the first metadata corresponding to the target user data and the L2P table; if the target user data is valid, reconstructing the P2L table based on the first metadata corresponding to the target user data and the first metadata corresponding to the remaining user data, so as to recover the target user data by using the reconstructed P2L table, the remaining user data and the verification data.
9. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the steps of the exception handling method according to any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: Used to store computer programs; wherein, when the computer program is executed by a processor, the steps of the exception handling method according to any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Flash memory-based garbage disposal method, solid-state hard disk, and storage device
CN109542800A
Solid state disk garbage collection method and device based on multi-core CPU
CN111045956A