Disclosure of Invention
Accordingly, the present invention is directed to an exception handling method, apparatus, device, and medium, which can quickly solve the double exception condition and recover data when a stripe has a double exception condition, i.e. a P2L table read failure and a user data read failure, so as to ensure the consistency of data and the stability of a hard disk. The specific scheme is as follows:
in a first aspect, the present application discloses an exception handling method, including:
Determining a target stripe of a garbage collection flow to be executed in a hard disk, wherein the target stripe comprises a first physical page used for storing user data and first metadata, a second physical page used for storing a P2L table and second metadata and a third physical page used 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 exclusive-or result of the first metadata and the second metadata, and the check data is an exclusive-or result of the user data and the P2L table;
When garbage collection is carried out on each first physical page, if the P2L table fails to read and one target user data fails to read, recovering the first metadata corresponding to the target user data based on the first metadata corresponding to the second metadata, the third metadata and the rest user data;
Judging whether the target user data is valid or not based on the first metadata corresponding to the target user data and an L2P table, and 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 rest of user data so as to recover the target user data by using the reconstructed P2L table, the rest of user data and the verification data.
Optionally, the exception handling method further includes:
Reading the P2L table to determine the validity of user data stored in each of the first physical pages when garbage collection is performed on each of the first physical pages;
If the P2L table fails to be read, reading the check data and all the user data to restore the P2L table by 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 first physical page;
if there is a failure in reading the target user data, the method jumps to the step of recovering the first metadata corresponding to the target user data based on the first metadata corresponding to the second metadata, the third metadata and the rest of the user data.
Optionally, the P2L table is configured to store a mapping relationship from an initial physical address to a logical address of each user data, and the L2P table is configured to store a mapping relationship from a logical address to a latest physical address of each user data;
accordingly, the reading the P2L table to determine the validity of the user data stored in each of the first physical pages includes:
obtaining a logical address and a first physical address corresponding to user data stored in each first physical page from the P2L table;
Searching a corresponding second physical address from the L2P table according to the logical address corresponding to each piece of user data;
and if the first physical address is the same as the second physical address, judging that the user data stored in the first physical page is valid, otherwise, judging that the user data stored in the first physical page is invalid.
Optionally, after the 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 physical page is valid, carrying out data moving processing on the corresponding user data;
And if the user data stored in any physical page is invalid, performing data discarding processing on the corresponding user data.
Optionally, the determining whether the target user data is valid based on the first metadata and the L2P table corresponding to the target user data includes:
Determining a target logical address of the target user data based on first metadata corresponding to the target user data, and searching a target physical address corresponding to the target logical address from the L2P table;
judging 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, judging that the target user data is valid;
And if the target physical address is different from the current physical address, judging that the target user data is invalid, and carrying out data discarding processing on the target user data.
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:
reading the reconstructed P2L table to determine the validity of the rest of the user data;
And if the rest of the user data is judged to be valid, carrying out data migration processing on the rest of the user data, and if the rest of the user data is judged to be invalid, carrying out data discarding processing on the rest of the user data.
Optionally, the exception handling method further includes:
performing exclusive-or operation on each first metadata and each second metadata according to bits to obtain third metadata, and performing exclusive-or operation on each user data and each P2L table according to bits to obtain check data;
correspondingly, 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 rest user data includes:
Performing exclusive OR operation on the first metadata corresponding to the second metadata, the third metadata and the rest user data according to bits to restore the first metadata corresponding to the target user data;
correspondingly, the recovering the target user data by using the reconstructed P2L table, the rest user data and the verification data includes:
And carrying out exclusive OR operation on the reconstructed P2L table, the rest user data and the verification data according to bits to restore the target user data.
In a second aspect, the present application discloses an exception handling apparatus, comprising:
The system comprises a stripe determining module, a stripe determining module and a data processing module, wherein the stripe determining module is used for determining a target stripe of a garbage collection flow to be executed in a hard disk, the target stripe comprises a first physical page used for storing user data and first metadata, a second physical page used for storing a P2L table and second metadata and a third physical page used 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 exclusive-OR result of the first metadata and the second metadata, and the check data is an exclusive-OR result of the user data and the P2L table;
The metadata recovery module is configured to, when garbage collection is performed on each of the first physical pages, if the P2L table fails to read and there is a failure in reading the target user data, recover first metadata corresponding to the target user data based on the second metadata, the third metadata, and first metadata corresponding to the rest user data;
And the user data recovery module is used for judging whether the target user data is valid or not based on the first metadata corresponding to the target user data and the L2P table, and reconstructing the P2L table based on the first metadata corresponding to the target user data and the first metadata corresponding to the rest of user data if the target user data is valid, so as to recover the target user data by using the reconstructed P2L table, the rest of user data and the verification data.
In a third aspect, the present application discloses an electronic device, comprising:
a memory for storing a computer program;
And a processor for executing the computer program to implement the steps of the foregoing disclosed exception handling method.
In a fourth aspect, the present application discloses a computer readable storage medium storing a computer program, wherein the computer program when executed by a processor implements the steps of the previously disclosed exception handling method.
The method comprises the steps of determining a target stripe of a garbage collection flow to be executed in a hard disk, determining whether the target stripe comprises a first physical page for storing user data and first metadata, a second physical page for storing P2L table and second metadata and a third physical page for storing check data and third metadata, wherein the first metadata is a logical address of the user data, each bit of the second metadata is 1, the third metadata is an exclusive OR result of the first metadata and the second metadata, the check data is an exclusive OR result of the user data and the P2L table, and if garbage collection is carried out on each first physical page, the P2L table is failed to read and one target user data is failed to 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 other user data, judging whether the target user data is valid or not based on the first metadata and the L2P table corresponding to the target user data, and reconstructing the rest of the check data by using the first metadata and the rest of the first metadata and the rest user data if the target user data is valid.
The method has the advantages that when data are stored in the hard disk, each stripe comprises a first physical page used for storing user data and first metadata, a second physical page used for storing P2L table and second metadata and a third physical page used for storing check data and third metadata, wherein the first metadata is used for storing logical addresses of the user data, the P2L table records the mapping relation from the physical addresses of the user data to the logical addresses, each bit of the corresponding second metadata is written as 1, finally, the exclusive OR result of all the user data and the P2L table is used as the check data, and the exclusive OR result of the first metadata and the second metadata is used as the third metadata corresponding to the check data. Further, when garbage collection is performed on each first physical page, if the P2L table fails to read and there is a failure to read the target user data, this indicates that a double exception condition occurs at this time, and because the value of the second metadata is 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 rest of the user data, that is, recover to obtain the logical address of the target user data, and then determine whether the target user data is valid data by reading the L2P table, and under the valid condition, because all metadata in the target stripe are known at this time, the present application can reconstruct to obtain the P2L table again based on the first metadata corresponding to the target user data and the first metadata corresponding to the rest of the user data, and finally recover the target user data by using the reconstructed P2L table, the rest of the user data and the verification data. In this way, the metadata of the P2L data is fixed to be 1, so that under the condition of double anomalies, the L2P table is not required to be traversed globally by using the physical address of the target user data, the metadata of the target user data can be quickly recovered, and the P2L table is quickly reconstructed, thereby recovering the double anomalies of the read failure to be single anomalies, finally recovering the target user data of the read failure, and ensuring the consistency of the data and the stability of the hard disk.
Detailed Description
The following description of the embodiments of the present application will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present application, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the application without making any inventive effort, are intended to be within the scope of the application.
When a stripe fails to read the P2L table and a user data fails to read the user data, the existing scheme is that only the physical addresses and the logical addresses of all user data can be reconstructed, and then for the user data which fails to read the current stripe, the mapping relation table (i.e. the L2P table) from the logical address to the physical address can be traversed only through the physical address. However, the L2P table is very large, and if it is an 8T disk, the L2P table is theoretically 8G in size, so that it takes a very long time, which greatly reduces the performance of the hard disk.
Therefore, the embodiment of the application discloses an exception handling method, an exception handling device, exception handling equipment and an exception handling medium, which can quickly solve double exception conditions and recover data when double exception conditions such as P2L table reading failure and user data reading failure occur in one strip so as to ensure the consistency of the data and the stability of a hard disk.
Referring to fig. 1, an embodiment of the present application discloses an exception handling method, which includes:
The method comprises the step S11 of determining a target stripe of a garbage collection flow to be executed in a hard disk, wherein the target stripe comprises a first physical page used for storing user data and first metadata, a second physical page used for storing a P2L table and second metadata and a third physical page used 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 exclusive OR result of the first metadata and the second metadata, and the check data is an exclusive OR result of the user data and the P2L table.
In this embodiment, first, a target stripe of a garbage collection process to be executed in a solid state disk is determined. It should be noted that, when storing data in a hard disk, each stripe includes a first physical page for storing user data and first metadata, a second physical page for storing P2L table and second metadata, and a third physical page for storing check data and third metadata, where the first metadata is used to store a logical address of the user data, the P2L table records a mapping relationship from the physical address to the logical address of each user data, each bit of the corresponding second metadata is written as 1, finally, an exclusive or result of all the user data and the P2L table is used as check data, and an exclusive or result of the first metadata and the second metadata is used as third metadata corresponding to the check data.
It will be appreciated that different hard disks have different sector formats, and taking the sector format in fig. 2 as an example, in this embodiment of the present application, each IO (Input/Output) data issued by the host has 4K of 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, the sizes of possible LBAs of different disks are different, and the present embodiment only takes 4 bytes as an example, and the size of the LBAs is not limited.
In this embodiment, each IO data is stored using one physical page, and the physical page is denoted as a first physical page, i.e. is mainly used for storing user data and corresponding first metadata, where the first metadata is used for storing a logical address of the user data. Further, each IO data generates a mapping table (i.e. a P2L table) from a physical address to a logical address, and the mapping table is stored in a P2L Buffer, when the write stripe is written to a P2L position, the P2L Buffer is written to a corresponding P2L position, as shown by IO P2L in FIG. 3, and before writing, metadata in the P2L data is written to a fixed value of 1. It will be appreciated that the used sector format of the P2L data also corresponds to the sector format shown in fig. 2, i.e. the data area for storing the P2L table and the corresponding metadata are also included, here the P2L table and the second metadata are denoted as a whole as IO P2L, whereas the present application writes each bit of the second metadata corresponding to the P2L table as a fixed value of 1 and then also writes such physical pages as second physical pages in the physical pages of the stripe. It should be noted that the number of second physical pages may be one or more, which mainly depends on the size of the hard disk and the number of first physical pages.
After the P2L data is written to the disk, the user data in all the first physical pages and the P2L table in all the second physical pages are xored finally to generate check data, all the first metadata and all the second metadata are xored equally to generate third metadata, and then the check data and the third metadata are written to the last location IO XOR of the stripe, i.e. one physical page is used to store it as well, and this type of physical page is denoted as a third physical page, and a complete stripe storage structure is shown in fig. 3, where a plurality of stripes form a complete physical Block (i.e. Block).
In the specific embodiment, the method specifically comprises the steps of carrying out exclusive-or operation on each first metadata and each second metadata according to bits to obtain third metadata, and carrying out exclusive-or operation on each user data and each P2L table according to bits to obtain the verification data. That is, in the exclusive-or operation, each data is operated according to a bit, for example, the first bit of each first metadata and the first bit of each second metadata are operated by exclusive-or according to a bit to obtain the first bit of the third metadata, and similarly, the first bit of each user data and the first bit of each P2L table are operated by exclusive-or according to a bit to obtain the first bit of the check data, and so on to obtain the complete third metadata and the check data.
And step S12, when garbage collection is carried out on each first physical page, if the P2L table fails to read and one target user data fails to read, recovering the first metadata corresponding to the target user data based on the second metadata, the third metadata and the first metadata corresponding to the rest user data.
In this embodiment, when garbage collection is performed on each first physical page, if the P2L table fails to read and there is a failure to read the target user data, this indicates that a double exception condition occurs at this time, and 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 rest of the user data, that is, recover the logical address of the target user data.
The method for recovering the first metadata corresponding to the target user data based on the first metadata corresponding to the second metadata, the third metadata and the rest user data comprises the step of performing exclusive-or operation on the first metadata corresponding to the second metadata, the third metadata and the rest user data according to bits to recover the first metadata corresponding to the target user data. It can be understood that, in this embodiment, when the first metadata corresponding to the target user data is restored, the second metadata, the third metadata, and the first metadata corresponding to the rest of the user data need to be xored according to bits.
That is, in this embodiment, metadata corresponding to all user data and check data that are successfully read needs to be stripped, and metadata corresponding to the P2L table is known to be all 1, so that metadata of target data that are failed to read can be recovered by performing XOR on all metadata, and thus a logical address of the target user data can be obtained. Taking fig. 4 as an example, the first metadata corresponding to the target user data is denoted as FMD 2, the first metadata corresponding to the user data with the rest of successfully read are denoted as FMD 1、FMD3、…、FMDn, and the third metadata corresponding to the verification data are denoted as FMD xor. Then, according to the characteristics of exclusive or operation, each bit is calculated, and since the second metadata corresponding to the P2L table is all 1, b 2i=1 XOR b1i XOR b3i XOR…XOR bni exists for each bit b 2i in the FMD 2, wherein b 1i、b3i…bni is the corresponding bit in the FMD 1、FMD3、…、FMDn, i represents the ith bit in the metadata, and the complete metadata of the target user data can be obtained by sequentially performing the above calculation on each bit in the metadata.
The process specifically includes the steps of reading the P2L table to determine validity of user data stored in each first physical page when garbage is recovered from each first physical page, reading the check data and all the user data if the P2L table fails to be read to recover the P2L table by using the check data and all the user data, then jumping to the step of reading the P2L table to determine validity of the user data stored in each first physical page, and jumping to the step of recovering the first metadata corresponding to the target user data based on the first metadata corresponding to the second metadata, the third metadata and the rest of the user data if there is a failure to read the target user data.
After the validity of the user data stored in each first physical page is determined by reading the P2L table, the method further comprises the steps of carrying out data moving processing on the corresponding user data if the user data stored in any physical page is valid, and carrying out data discarding processing on the corresponding user data if the user data stored in any physical page is invalid.
That is, in the normal flow, the P2L table needs to be read to determine the validity of the user data stored in each first physical page, and if the user data stored in any physical page is determined to be valid according to the P2L table, the data migration process is performed on the corresponding user data, that is, the data determined to be valid is transferred from the old storage location to the new storage location, so as to perform the erase operation on the original physical block, thereby obtaining the physical block of the new writable data. If the user data stored in any physical page is invalid according to the P2L table, the corresponding user data is subjected to data discarding processing without moving.
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, so that the check data and all the user data need to be read first, an exclusive or operation is performed by using the check data and all the user data to restore the P2L table, and if the P2L table is restored successfully, the subsequent steps are performed according to the garbage collection procedure, that is, the P2L table is read again to determine the validity of the user data stored in each first physical page.
Further, as shown in fig. 4, if it is found that there is a failure in reading the target user data during the process of recovering the P2L table, the P2L table cannot be recovered, and the target user data cannot be recovered, thereby forming a double abnormal situation. 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.
In addition, in a specific embodiment, the P2L table is configured to store a mapping relationship from an initial physical address to a logical address of each user data, the L2P table is configured to store a mapping relationship from a logical address to a latest physical address of each user data, and correspondingly, the reading the P2L table to determine validity of the user data stored in each first physical page includes obtaining, from the P2L table, a logical address and a first physical address corresponding to the user data stored in each first physical page, searching, from the L2P table, a corresponding second physical address according to the logical address corresponding to each user data, and if the first physical address is the same as the second physical address, 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.
It can be understood that the application sets two different mapping tables, namely a P2L table for storing the mapping relation from the initial physical address to the logical address of each user data, wherein the P2L table only records the related data in a single strip, and a L2P table for storing the mapping relation from the logical address to the latest physical address of each user data, wherein the L2P table records the related data of the whole hard disk. That is, considering that the physical address of the data may change during the use process, the P2L table records the initial physical address corresponding to the user data when the user data is initially written, and uses the current latest physical address of the user data recorded by the L2P table. Therefore, when determining the validity of the user data stored in each first physical page, the application firstly needs to acquire the logical address and the first physical address corresponding to the user data from the P2L table, then searches the corresponding second physical address from the L2P table by utilizing the acquired logical address of the user data, namely searches the latest physical address, if the first physical address is the same as the second physical address, the physical address for storing the user data is unchanged, so that the user data stored in the first physical page is still valid, and if the first physical address is different from the second physical address, the user data stored in the first physical page is invalid.
And S13, judging whether the target user data is valid or not based on the first metadata corresponding to the target user data and an L2P table, and reconstructing the P2L table based on the first metadata corresponding to the target user data and the first metadata corresponding to the rest of user data if the target user data is valid, so as to restore the target user data by using the reconstructed P2L table, the rest of user data and the verification data.
In this embodiment, after the first metadata corresponding to the target user data is recovered, whether the target user data is valid data is then determined by reading the L2P table. Under the effective condition, because all metadata in the target stripe are known at this time, namely the logical address of each user data is known, the application can reconstruct the P2L table based on the first metadata corresponding to the target user data and the first metadata corresponding to the rest user data, and finally, the reconstructed P2L table and the verification data are used for recovering the target user data. In this way, the metadata of the P2L data is fixed to be 1, so that under the condition of double anomalies, the physical data of the target user data is not required to be utilized to globally traverse the L2P table, the metadata of the target user data can be quickly recovered, the P2L table is quickly reconstructed, the double anomalies with failed reading are recovered to be single anomalies, the target user data with failed reading is finally recovered, and the consistency of the data and the stability of the hard disk are ensured.
In a specific embodiment, the recovering the target user data by using the reconstructed P2L table, the rest of the user data and the check data includes performing an exclusive-or operation on the reconstructed P2L table, the rest of the user data and the check data according to bits to recover the target user data. It will be appreciated that, in this embodiment, when recovering the target user data, the reconstructed P2L table, the remaining user data and the check data also need to be xored according to bits.
It can be seen that when data is stored in a hard disk, each stripe includes a first physical page for storing user data and first metadata, a second physical page for storing P2L table and second metadata, and a third physical page for storing check data and third metadata, where the first metadata is used to store a logical address of the user data, the P2L table records a mapping relationship from the physical address to the logical address of each user data, each bit of the corresponding second metadata is written as 1, finally, an exclusive-or result of all the user data and the P2L table is used as check data, and an exclusive-or result of the first metadata and the second metadata is used as third metadata corresponding to the check data. Further, when garbage collection is performed on each first physical page, if the P2L table fails to read and there is a failure to read the target user data, this indicates that a double exception condition occurs at this time, and because the value of the second metadata is 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 rest of the user data, that is, recover to obtain the logical address of the target user data, and then determine whether the target user data is valid data by reading the L2P table, and under the valid condition, because all metadata in the target stripe are known at this time, the present application can reconstruct to obtain the P2L table again based on the first metadata corresponding to the target user data and the first metadata corresponding to the rest of the user data, and finally recover the target user data by using the reconstructed P2L table and the verification data. In this way, the metadata of the P2L data is fixed to be 1, so that under the condition of double anomalies, the L2P table is not required to be traversed globally by using the physical address of the target user data, the metadata of the target user data can be quickly recovered, and the P2L table is quickly reconstructed, thereby recovering the double anomalies of the read failure to be single anomalies, finally recovering the target user data of the read failure, and ensuring the consistency of the data and the stability of the hard disk.
Referring to fig. 5, an embodiment of the present application discloses a specific exception handling method, and compared with the previous embodiment, the present embodiment further describes and optimizes a technical solution. The method specifically comprises the following steps:
The method comprises the step S21 of determining a target stripe of a garbage collection flow to be executed in a hard disk, wherein the target stripe comprises a first physical page used for storing user data and first metadata, a second physical page used for storing a P2L table and second metadata and a third physical page used 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 exclusive OR result of the first metadata and the second metadata, and the check data is an exclusive OR result of the user data and the P2L table.
And S22, when garbage collection is carried out on each first physical page, if the P2L table fails to read and one target user data fails to read, recovering the first metadata corresponding to the target user data based on the second metadata, the third metadata and the first metadata corresponding to the rest user data.
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 a target physical address corresponding to the target logical address from the L2P table.
In this embodiment, after the first metadata corresponding to the target user data is recovered, the target logical address of the target user data may 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 may be searched for from the L2P table.
And S24, judging 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, judging that the target user data is valid, and if the target physical address is different from the current physical address, judging that the target user data is invalid, and performing data discarding processing on the target user data.
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 so, it is determined that the target user data is valid because the physical address storing the target user data is unchanged, and if not, it is determined that the target user data is invalid because the target user data is stored at a new physical address, and data discarding processing is performed on the target user data. And because the first metadata corresponding to all user data of the current stripe are known at the moment, the logical address is also known, and the validity of each user data of the current stripe can be directly judged without recovering the P2L table.
And 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 rest of user data, so as to recover the target user data by using the reconstructed P2L table, the rest of user data and the verification data.
In this embodiment, if the target user data is valid, the data needs to be restored, and the P2L table needs to be restored first to construct the double anomaly into the single anomaly. Because the first metadata corresponding to the target user data or the first metadata corresponding to the rest user data in the current stripe are known, the P2L table can be rebuilt, namely, the P2L table is rebuilt by using the mapping relation from the physical address to the logical address of each user data, and at the moment, the double anomalies are restored to a single anomaly scene. And finally, recovering the target user data by using the reconstructed P2L table, the rest user data and the verification data, and then carrying out data moving processing.
Further, 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 reading the reconstructed P2L table to determine validity of the remaining user data, if the remaining user data is determined to be valid, performing data moving processing on the remaining user data, and if the remaining user data is determined to be invalid, performing data discarding processing on the remaining user data.
That is, after reconstructing the P2L table, the reconstructed P2L table may 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.
For more specific processing procedures in the steps S21 and S22, reference may be made to the corresponding contents disclosed in the foregoing embodiments, and no detailed description is given here.
Therefore, the application writes the metadata of the P2L table into the fixed value of 1, saves the metadata of the user data in the logical address of the user data, and when the same band fails to read the P2L table and one user data is also failed to read, strips the metadata of the P2L table, the check data and the metadata of other user data which are read normally out to carry out metadata exclusive OR, because the metadata of the P2L table is known to be the fixed value, the double anomaly phenomenon is constructed as single anomaly, and the metadata of the user data which fails to read are recovered, thereby being used for judging the validity of the user data which fails to read later and recovering the P2L table and recovering the user data. According to the scheme, the whole disk L2P table does not need to be traversed globally, so that the speed of screening effective data under the condition of double abnormal reading is greatly improved, the abnormal solving time is prolonged, and meanwhile, the stability of a hard disk and the consistency of data are ensured.
Referring to fig. 6, an embodiment of the present application discloses an exception handling apparatus, which includes:
The system comprises a stripe determining module 11, a stripe determining module and a data processing module, wherein the stripe determining module is used for determining a target stripe of a garbage collection flow to be executed in a hard disk, the target stripe comprises a first physical page used for storing user data and first metadata, a second physical page used for storing a P2L table and second metadata and a third physical page used 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 exclusive-OR result of the first metadata and the second metadata, and the check data is an exclusive-OR result of the user data and the P2L table;
the metadata recovery module 12 is configured to, when garbage collection is performed on each of the first physical pages, if the P2L table fails to read and there is a failure to read the target user data, recover the first metadata corresponding to the target user data based on the first metadata corresponding to the second metadata, the third metadata, and the rest of the user data;
And a user data recovery module 13, 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, and if the target user data is valid, reconstruct the P2L table based on the first metadata corresponding to the target user data and the first metadata corresponding to the rest of the user data, so as to recover the target user data by using the reconstructed P2L table, the rest of the user data, and the verification data.
It can be seen that when data is stored in a hard disk, each stripe includes a first physical page for storing user data and first metadata, a second physical page for storing P2L table and second metadata, and a third physical page for storing check data and third metadata, where the first metadata is used to store a logical address of the user data, the P2L table records a mapping relationship from the physical address to the logical address of each user data, each bit of the corresponding second metadata is written as 1, finally, an exclusive-or result of all the user data and the P2L table is used as check data, and an exclusive-or result of the first metadata and the second metadata is used as third metadata corresponding to the check data. Further, when garbage collection is performed on each first physical page, if the P2L table fails to read and there is a failure to read the target user data, this indicates that a double exception condition occurs at this time, and because the value of the second metadata is 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 rest of the user data, that is, recover to obtain the logical address of the target user data, and then determine whether the target user data is valid data by reading the L2P table, and under the valid condition, because all metadata in the target stripe are known at this time, the present application can reconstruct to obtain the P2L table again based on the first metadata corresponding to the target user data and the first metadata corresponding to the rest of the user data, and finally recover the target user data by using the reconstructed P2L table and the verification data. In this way, the metadata of the P2L data is fixed to be 1, so that under the condition of double anomalies, the L2P table is not required to be traversed globally by using the physical address of the target user data, the metadata of the target user data can be quickly recovered, and the P2L table is quickly reconstructed, thereby recovering the double anomalies of the read failure to be single anomalies, finally recovering the target user data of the read failure, and ensuring the consistency of the data and the stability of the hard disk.
Since the embodiments of the apparatus portion and the embodiments of the method portion correspond to each other, the embodiments of the apparatus portion are described with reference to the embodiments of the method portion, which are not repeated herein. And, has the same advantageous effects as the above-mentioned exception handling method.
Fig. 7 is a schematic structural diagram of an electronic device according to an embodiment of the present application. Specifically, the system comprises 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. Wherein the memory 22 is configured to store a computer program that is loaded and executed by the processor 21 to implement relevant steps in the exception handling method performed by the electronic device as disclosed in any of the foregoing embodiments.
In this embodiment, the power supply 23 is configured to provide working voltages for each hardware device on the electronic device 20, the communication interface 24 is capable of creating a data transmission channel with an external device for the electronic device 20, and the communication protocol to be followed is any communication protocol applicable to the technical solution of the present application, which is not specifically limited herein, and the input/output interface 25 is configured to obtain external input data or output data to the external device, and the specific interface type of the input/output interface may be selected according to the specific application needs and is not specifically limited herein.
Processor 21 may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor 21 may be implemented in at least one hardware form of DSP (DIGITAL SIGNAL Processing), FPGA (Field-Programmable gate array), PLA (Programmable Logic Array ). The processor 21 may also include a main processor, which is a processor for processing data in a wake-up state, also called a CPU (Central Processing Unit ), and a coprocessor, which is a low-power processor for processing data in a standby state. In some embodiments, the processor 21 may integrate a GPU (Graphics Processing Unit, image processor) for rendering and drawing of content required to be displayed by the display screen. In some embodiments, the processor 21 may also include an AI (ARTIFICIAL INTELLIGENCE ) processor for processing computing operations related to machine learning.
The memory 22 may be a carrier for storing resources, such as a read-only memory, a random access memory, a magnetic disk, or an optical disk, and the resources stored thereon include an operating system 221, a computer program 222, and data 223, and the storage may be temporary storage or permanent storage.
The operating system 221 is used for managing and controlling various hardware devices on the electronic device 20 and the computer program 222, so as to implement the operation and processing of the processor 21 on the mass data 223 in the memory 22, which may be Windows, unix, linux. The computer program 222 may further include a computer program that can be used to perform other specific tasks in addition to the computer program that can be used to perform the exception handling method performed by the electronic device 20 as disclosed in any of the foregoing embodiments. The data 223 may include, in addition to data received by the electronic device and transmitted by the external device, data collected by the input/output interface 25 itself, and so on.
Further, the embodiment of the application also discloses a computer readable storage medium, wherein the storage medium stores a computer program, and when the computer program is loaded and executed by a processor, the steps of the exception handling method disclosed in any embodiment are realized.
In this specification, each embodiment is described in a progressive manner, and each embodiment is mainly described in a different point from other embodiments, so that the same or similar parts between the embodiments are 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 points refer to the description of the method section.
Those of skill would further appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative elements and steps are described above generally in terms of functionality in order to clearly illustrate the interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the solution. Those skilled in the art may implement the described functionality using different approaches for each particular application, but such implementation is not intended to be limiting.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied directly in hardware, in a software module executed by a processor, or in a combination of the two. The software modules may be disposed in random access Memory (Random Access Memory, i.e., RAM), memory, read-Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a compact disc Read-Only Memory (Compact Disc Read-Only Memory, i.e., CD-ROM), or any other form of storage medium known in the art.
Finally, it is further noted that relational terms such as first and second, and the like are used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Moreover, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises an element.
While the foregoing describes the method, apparatus, device and storage medium for exception handling provided by the present invention, specific examples are set forth herein to illustrate the principles and embodiments of the present invention, the above examples are provided to assist in understanding the method and core ideas of the present invention, and meanwhile, to those skilled in the art, according to the ideas of the present invention, there are variations in the specific embodiments and application scope, and in summary, the disclosure should not be construed as limiting the present invention.