Method for detecting damage of data page and related device
By performing multiple verifications and checks on data pages while the database is running, the problem of low data query efficiency caused by database shutdown is solved, and efficient data page corruption detection is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- CETC JINCANG (BEIJING) TECH CO LTD
- Filing Date
- 2023-02-08
- Publication Date
- 2026-04-17
AI Technical Summary
In existing technologies, data page corruption detection in databases needs to be performed while the database is closed, which causes the database to be unable to run for a long time and results in low data query efficiency.
While the database is running, multiple checks and tests are performed on the data pages to determine if they are corrupted, thus avoiding the need to shut down the database and improving data query efficiency.
This feature enables the detection of corrupted data pages while the database is running, avoiding data query waiting time and improving data query efficiency.
Smart Images

Figure CN115981909B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of database technology, and in particular to a method and related equipment for detecting data page corruption. Background Technology
[0002] A data page is the smallest unit of management in disk storage and memory; a data page is also called a data block.
[0003] Databases use multiple data pages for data storage. If a data page in the database is corrupted, errors will occur when writing, reading, or storing data on that page, thus impacting database performance. Therefore, it is necessary to periodically check for data page corruption in the database to ensure that database performance is not affected by corrupted data pages.
[0004] In the exemplary technology, data page corruption detection needs to be performed while the database is closed. However, there are a large number of data pages in the database to be detected, which causes the database to be unable to run for a long time due to data page corruption detection. This results in long waiting times for data queries and low data query efficiency. Summary of the Invention
[0005] This application provides a method and related equipment for detecting data page corruption, in order to solve the problem of low data query efficiency.
[0006] On the one hand, this application provides a method for detecting data page corruption, including:
[0007] When the database is running and the data page is determined to be corrupt based on the first checksum of the data page in the database, the second checksum of the data page is determined based on the data currently written to the data page.
[0008] Determine whether the first checksum matches the second checksum to obtain a matching result;
[0009] The matching results are used to determine whether the data page is corrupted.
[0010] In one embodiment, the step of determining whether the data page is corrupted based on the matching result includes:
[0011] When the matching result is that the first checksum matches the second checksum, it is determined that the data page is corrupted.
[0012] In one embodiment, the step of determining whether the data page is corrupted based on the matching result includes:
[0013] When the matching result is that the first checksum and the second checksum do not match, the checksum to be compared is obtained from the data page;
[0014] When the second checksum matches the checksum to be compared, it is determined that the data page is not corrupted.
[0015] In one embodiment, after the step of obtaining the checksum to be compared from the data page, the method further includes:
[0016] An error message is output when the second checksum does not match the checksum to be compared.
[0017] In one embodiment, the step of determining the second checksum of the data page based on the data currently written to the data page includes:
[0018] Determine whether the data page is valid;
[0019] When the data page is valid, a second checksum of the data page is determined based on the data currently written to the data page.
[0020] In one embodiment, the step of determining whether the data page is valid includes:
[0021] Determine whether the data page is an empty page;
[0022] When the data page is not empty, determine whether the data page header corresponding to the data page is compliant. If the data page header is compliant, the data page is determined to be valid.
[0023] On the other hand, this application also provides a data page corruption detection device, comprising:
[0024] The determination module is used to determine a second checksum of the data page based on the data currently written to the data page when the database is in operation and the data page is determined to be corrupt based on the first checksum of the data page in the database.
[0025] The comparison module determines whether the first checksum matches the second checksum to obtain a matching result;
[0026] The determining module is further configured to determine whether the data page is corrupted based on the matching result.
[0027] On the other hand, this application also provides a data page damage detection device, including: a memory and a processor;
[0028] The memory stores computer-executed instructions;
[0029] The processor executes computer execution instructions stored in the memory, causing the data page corruption detection device to perform the data page corruption detection method described above.
[0030] On the other hand, this application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the data page corruption detection method described above.
[0031] On the other hand, this application also provides a computer program product, including a computer program, which, when executed by a processor, is used to implement the data page corruption detection method described above.
[0032] The data page corruption detection method and related equipment provided in this application determine whether a data page is corrupted by performing multiple checksum checks on the data pages in the database while the database is running. This achieves the purpose of detecting data page corruption while the database is running. Data page corruption detection does not require shutting down the database, avoids waiting for data queries, and improves data query efficiency. Attached Figure Description
[0033] The accompanying drawings, which are incorporated in and form a part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure.
[0034] Figure 1 This is a schematic diagram of a scenario for the damage detection method of the data page in this application;
[0035] Figure 2 This is a flowchart illustrating a first embodiment of the damage detection method for data pages in this application;
[0036] Figure 3 This is a flowchart illustrating the second embodiment of the data page damage detection method of this application;
[0037] Figure 4 This is a flowchart illustrating the third embodiment of the data page damage detection method of this application;
[0038] Figure 5 This is a schematic diagram of the functional modules of the damage detection device for the data page of this application.
[0039] Figure 6 This is a schematic diagram of the hardware structure of the damage detection equipment for the data page of this application.
[0040] The accompanying drawings have illustrated specific embodiments of this disclosure, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concepts of this disclosure to those skilled in the art through reference to particular embodiments. Detailed Implementation
[0041] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.
[0042] Databases use multiple data pages for data storage. If a data page in the database is corrupted, errors will occur when writing, reading, or storing data on that page, thus impacting database performance. Therefore, it is necessary to periodically check for data page corruption in the database to ensure that database performance is not affected by corrupted data pages.
[0043] The inventors of this application discovered that data page corruption detection needs to be performed with the database closed. However, there are a large number of data pages in the database to be detected, which causes the database to be unable to run for a long time due to data page corruption detection, resulting in long waiting times for data queries and low data query efficiency.
[0044] The inventors of this application therefore conceived of a method to determine whether a data page is corrupted by performing multiple checksum checks on the data pages in the database while the database is running. This achieves the purpose of detecting data page corruption while the database is running, without having to shut down the database, thus avoiding waiting for data queries and improving data query efficiency.
[0045] Reference Figure 1 , Figure 1 This is a schematic diagram illustrating an application scenario of a data page corruption detection method. For example... Figure 1 As shown, database 100 stores multiple data pages 110. During database 100 operation, the data page corruption detection device 200 acquires a first checksum of each data page 110 to perform corruption detection. If the data page corruption detection device 200 detects corruption in a data page 110, it acquires a second checksum of the data page 110 again in real time. Using both the first and second checksums, it performs corruption detection on the data pages in database 100 again to accurately determine whether a data page 110 is corrupted.
[0046] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will be described below with reference to the accompanying drawings.
[0047] Reference Figure 2 , Figure 2 This is a first embodiment of the data page damage detection method of this application. The data page damage detection method includes the following steps:
[0048] Step S201: When the database is running and the data page is determined to be corrupt based on the first checksum of the data page in the database, the second checksum of the data page is determined based on the data currently written to the data page.
[0049] In this embodiment, the execution subject is a data page corruption detection device. For ease of description, the term "device" will be used to refer to the data page corruption detection device below.
[0050] The device periodically performs corruption checks on data pages in the database, or the database requests the device to perform corruption checks on data pages. When checking a data page, the device obtains its checksum, which can be obtained from the currently written content of the data page; this checksum is defined as the first checksum. The device then obtains a preset checksum, which can be obtained from a field at a preset position in the data page. When data is written to the data page, the write module calculates the checksum based on the data in the data page and writes the checksum as a field to the preset position in the data page. The device compares the first checksum with the preset checksum. If the first checksum matches the preset checksum, the data page is considered uncorrupted, and the device performs corruption checks on the next data page. It should be noted that the device performs corruption checks on data pages while the database is running. When calculating the first checksum, the device can treat the checksum as all zeros, and then calculate the first checksum for the entire data page, including the page header.
[0051] If the first checksum does not match the preset checksum, there could be several reasons. One is that the data page is being modified; another is that the data page is corrupted. A common scenario is that when the device checks the first checksum of a data page, the file being read from the data page is in the process of being written. Because the file writing is not yet complete, the content of the data page read at this time is incomplete, which may lead to failure to pass the checksum. However, the data page that fails the checksum check at this time is not necessarily corrupted. If the standard for shutdown check is followed, it may lead to incorrect judgments. Therefore, the data page needs to be checked again. Some other possible situations include: if the database deletes the entire content of a data page during the verification process, the deleted data page is treated as an empty data page and is not included in the statistics of correct or incorrect blocks; if the database adds a new data page during the verification process, and the writing of the page header of the data page is completed before the file check is performed, the new data page will be included in the corruption detection scope, which will cause the first checksum to mismatch with the preset checksum.
[0052] To address this, the device needs to determine whether the data page is truly corrupted. Therefore, the device performs another corruption detection on the data page.
[0053] Specifically, the device can retrieve the checksum of the data page again at certain intervals. This checksum is defined as the second checksum, which is determined by the data currently written to the data page.
[0054] Step S202: Determine whether the first checksum and the second checksum match to obtain the matching result.
[0055] Step S203: Determine whether the data page is corrupted based on the matching result.
[0056] After obtaining the first checksum and the second checksum, the device determines whether the first checksum and the second checksum match to obtain a matching result, and then ultimately determines whether the data page is corrupted based on the matching result.
[0057] In one example, when the first checksum differs from the second checksum, it can be determined that the device data page is continuously being written to, and thus it can be determined that the data page may be continuously being written to, and therefore it can be determined that the data page is not corrupted.
[0058] In another example, when the first checksum matches the second checksum, it can be determined that the first checksum and the second checksum are matched. At this point, it can be determined that the data page is corrupted. That is, when the matching result is that the first checksum and the second checksum match, it is determined that the data page is corrupted.
[0059] In this embodiment, detecting data page corruption while the database is not closed can effectively avoid misjudging bad blocks due to frequent data writes to data pages. A bad block refers to a corrupted data page.
[0060] In this embodiment, when the database is running, multiple checksum checks are performed on the data pages in the database to determine whether the data pages are corrupted. This achieves the purpose of detecting data page corruption while the database is running. Data page corruption detection does not require shutting down the database, avoiding waiting for data queries and improving data query efficiency.
[0061] Reference Figure 3 , Figure 3 This is a second embodiment of the data page damage detection method of this application. Based on the first embodiment, step S203 includes:
[0062] Step S301: When the matching result is that the first checksum and the second checksum do not match, obtain the checksum to be compared from the data page.
[0063] In this embodiment, a mismatch between the first and second checksums is determined when the first checksum is inconsistent with the second checksum. There are two possibilities for this: either the data page is being modified, or the data page is corrupted. To address this, the device needs to obtain the checksum to be compared from the data page. This checksum can be obtained from the header of the data page, and it is located at a preset position within the header.
[0064] Step S302: When the second checksum matches the checksum to be compared, it is determined that the data page is not corrupted.
[0065] After obtaining the checksum to be compared, the device compares the second checksum with the checksum to be compared. If the second checksum matches the checksum to be compared, it can be determined that the second checksum matches the checksum to be compared, and it can be determined that the data page is being modified and is not damaged.
[0066] When the second checksum does not match the checksum to be compared, it can be determined that the second checksum and the checksum to be compared do not match. Therefore, it can be determined that the two checksums calculated for the data page are inconsistent, both corruption detections have passed, and the two calculated checksums are different from the checksum recorded in the header of the data page. This indicates that the data page has been affected by the running database, or that other events that caused physical file corruption occurred during the detection process. Since the device cannot distinguish whether the data page was corrupted due to database influence or other events, it will issue an alarm. That is, when the second checksum does not match the checksum to be compared, an error message is output, prompting the user to close the data and perform a shutdown test to determine whether the data page is truly corrupted. It should be noted that the checksum recorded in the header of the data page is a preset checksum and the checksum to be compared.
[0067] If the checksum to be compared matches the second checksum, it means that the data page has recovered to normal during the second check. The reason why the data page failed the first check is that the data page has not completed the writing of all data.
[0068] In this embodiment, the device can accurately determine whether a data page is corrupted based on the matching result of the first checksum and the second checksum.
[0069] Reference Figure 4 , Figure 4 This is a third embodiment of the data page damage detection method of this application. Based on the first or second embodiment, step S201 includes:
[0070] Step S401: Determine if the data page is valid.
[0071] Step S402: When the data page is valid, determine the second checksum of the data page based on the data currently written to the data page.
[0072] In this embodiment, before performing data page corruption detection, the device needs to determine whether the data page is valid. Whether the data page is valid refers to whether the device needs to perform corruption detection on the data page.
[0073] In one example, data pages that do not require detection may carry a tag, which can be added by the database. For example, if a data page is corrupted and the database has not processed it in a timely manner, the data page can be tagged. The device determines that a data page is invalid and does not require detection if it detects that a data page carries a tag. If a data page is detected without a tag, it determines that the data page is valid.
[0074] In another example, the device determines whether the data page is empty. If the data page is not empty, it then checks whether the corresponding data page header is valid. If the data page header is valid, the data page is considered valid. If the data page header is invalid, the data page is considered invalid. Additionally, if the data page is empty, it is also considered invalid.
[0075] When a data page is determined to be valid, the device determines a second checksum of the data page based on the data written to the data page, which is to say, the device performs data page corruption detection.
[0076] In this embodiment, the device determines whether the data page is valid. If the data page is valid, it determines the second checksum of the data page based on the data currently written to the data page, thereby accurately determining whether the data page is corrupted based on the first checksum and the second checksum.
[0077] Based on the above embodiments, a brief description of the data page corruption detection method is provided.
[0078] For a data page to be checked, if a data page check needs to be performed while the database is not closed, the data page is first checked using the first checksum detection method. If the first checksum passes, the next data page is then checked.
[0079] For the first checksum and the failed checksum, perform the following operations:
[0080] Move the file pointer and reread the data page from the disk;
[0081] Check whether the data page is empty and whether the data page header is valid to determine whether the data page is valid;
[0082] If the data page is valid, recalculate the checksum of the data page, that is, obtain the second checksum, and compare it with the checksum field in the data page header;
[0083] If the comparison result returns as pass, it means that the data page may have encountered interference from written data in the previous round of detection, but the writing has now been completed and the data page has not been damaged.
[0084] If the comparison result fails, and the checksums of the two data pages are consistent, it indicates that the data page has been corrupted.
[0085] If the two data page content checksums are inconsistent, it indicates that the data page may still be under modification, and a warning will be displayed.
[0086] This application also provides a data page corruption detection device, referring to... Figure 5 The data page damage detection device 500 includes:
[0087] The determination module 510 is used to determine the second checksum of the data page based on the data currently written to the data page when the database is in operation and the data page is determined to be corrupt based on the first checksum of the data page in the database.
[0088] The comparison module 520 is used to determine whether the first checksum matches the second checksum and obtain a matching result.
[0089] The determination module 510 is used to determine whether a data page is corrupted based on the matching results.
[0090] In one embodiment, the data page corruption detection device 500 includes:
[0091] The determination module 510 is used to determine that the data page is corrupted when the matching result is that the first checksum matches the second checksum.
[0092] In one embodiment, the data page corruption detection device 500 includes:
[0093] The acquisition module is used to retrieve the checksum to be compared from the data page when the matching result shows that the first checksum and the second checksum do not match.
[0094] The determination module 510 is used to determine that the data page is not corrupted when the second checksum matches the checksum to be compared.
[0095] In one embodiment, the data page corruption detection device 500 includes:
[0096] The output module is used to output error information when the second checksum does not match the checksum to be compared.
[0097] In one embodiment, the data page corruption detection device 500 includes:
[0098] The judgment module is used to determine whether a data page is valid;
[0099] The determination module 510 is used to determine the second checksum of the data page based on the data currently written to the data page when the data page is valid.
[0100] In one embodiment, the data page corruption detection device 500 includes:
[0101] The judgment module is used to determine whether a data page is empty.
[0102] The judgment module is used to determine whether the data page header corresponding to the data page is compliant when the data page is not an empty page. If the data page header is compliant, the data page is determined to be valid.
[0103] Figure 6 This is a schematic diagram of the hardware structure of a data page damage detection device according to an exemplary embodiment.
[0104] The data page damage detection device 600 may include: a processor 601, such as a CPU, a memory 602, and a transceiver 603. Those skilled in the art will understand that... Figure 6 The structure shown does not constitute a limitation on the data page damage detection device and may include more or fewer components than shown, or combine certain components, or have different component arrangements. Memory 602 may be implemented by any type of volatile or non-volatile storage device or combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0105] The processor 601 can call computer programs or computer execution instructions stored in the memory 602 to complete all or part of the steps of the above-described data page corruption detection method.
[0106] Transceiver 603 is used to receive information sent by external devices and to send information to external devices.
[0107] A non-transitory computer-readable storage medium, wherein when instructions (computer-executable instructions) in the storage medium are executed by the processor of a data page damage detection device, the data page damage detection device is able to perform the aforementioned data page damage detection method.
[0108] A computer program product includes a computer program that, when executed by a processor of a data page damage detection device, enables the data page damage detection device to perform the aforementioned data page damage detection method.
[0109] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the following claims.
[0110] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.
Claims
1. A method of detecting corruption of a data page, the method comprising: include: While the database is running, a first checksum is determined based on the data written to the data page in the database. A preset checksum for the data page is obtained from a field at a preset position in the data page, and the first checksum is compared with the preset checksum. If the first checksum matches the preset checksum, the data page is determined to be undamaged. If the first checksum does not match the preset checksum, a second checksum for the data page is obtained again after a certain time interval. The second checksum is determined based on the currently written data to the data page. A matching result is obtained by determining whether the first checksum matches the second checksum. The data page is then determined to be undamaged based on the matching result.
2. The data page corruption detection method according to claim 1, characterized in that, The step of determining whether the data page is corrupt based on the matching result includes: When the matching result is that the first checksum matches the second checksum, it is determined that the data page is corrupted.
3. The data page corruption detection method according to claim 1, characterized in that, The step of determining whether the data page is corrupt based on the matching result includes: When the matching result is that the first checksum and the second checksum do not match, the checksum to be compared is obtained from the data page; When the second checksum matches the checksum to be compared, it is determined that the data page is not corrupted.
4. The data page corruption detection method according to claim 3, characterized in that, After the step of obtaining the checksum to be compared from the data page, the method further includes: An error message is output when the second checksum does not match the checksum to be compared.
5. The method for detecting data page corruption according to any one of claims 1-4, characterized in that, The step of determining the second checksum of the data page based on the data currently written to the data page includes: Determine whether the data page is valid; When the data page is valid, a second checksum of the data page is determined based on the data currently written to the data page.
6. The data page corruption detection method according to claim 5, characterized in that, The step of determining whether the data page is valid includes: Determine whether the data page is an empty page; When the data page is not empty, determine whether the data page header corresponding to the data page is compliant. If the data page header is compliant, the data page is determined to be valid.
7. A data page damage detection device, characterized in that, include: The determination module is used to determine a first checksum based on the data written to the data page in the database when the database is running, obtain a preset checksum of the data page from a field at a preset position in the data page, and compare the first checksum with the preset checksum to see if they match; if the first checksum matches the preset checksum, it is determined that the data page is not corrupted; if the first checksum does not match the preset checksum, a second checksum of the data page is obtained again after a certain time interval, and the second checksum is determined based on the data currently written to the data page; The comparison module is used to determine whether the first checksum matches the second checksum and obtain a matching result; The determining module is further configured to determine whether the data page is corrupted based on the matching result.
8. A data page damage detection device, characterized in that, include: Memory and processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory, causing the data page corruption detection device to perform the data page corruption detection method as described in any one of claims 1 to 6.
9. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the data page corruption detection method as described in any one of claims 1 to 6.
10. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by a processor, it is used to implement the data page corruption detection method as described in any one of claims 1 to 6.
Citation Information
Patent Citations
Method For Managing A Memory Apparatus, And Associated Memory Apparatus Thereof And Associated Controller Thereof
CN106484316A
Flash memory apparatus and storage management method for flash memory
CN107403646A