Data storage method, apparatus, device, storage medium and program product
By creating pages corresponding to the data and mounting them to the index tree, the problem of frequent splitting of target pages due to big data is solved, resource overhead is reduced, and storage efficiency is improved.
Patent Information
- Application Number
- PCT/IB2025/051587
- Authority / Receiving Office
- WO · WO
- Patent Type
- Applications
- Current Assignee / Owner
- Priority Date
- 2024-03-20
- Filing Date
- 2025-02-14
- Publication Date
- 2025-09-25
AI Technical Summary
In the prior art, when large data needs to be stored in a target page, the target page becomes too large and requires frequent splitting operations, resulting in a large overhead of data storage resources.
Create pages corresponding to the data and mount them to the index tree to avoid storing large data in the target pages in the index tree. Manage pages through the Bwe-tree index tree and optimize the storage process using page mapping tables and operation records.
It reduces the resource overhead of data storage, avoids frequent splitting operations, and improves storage efficiency.
Smart Images

Figure IB2025051587_25092025_PF_FP_ABST
Abstract
Description
[0001] Data Storage Method, Apparatus, Device, Storage Medium, and Program Product This disclosure claims priority to Chinese patent application No. 202410326283.2, filed with the China Patent Office on March 20, 2024, entitled "Data Storage Method, Apparatus, Device, Storage Medium, and Program Product," the entire contents of which are incorporated herein by reference. Technical Field This disclosure relates to the field of computers, and more particularly to a data storage method, apparatus, device, storage medium, and program product. Background: An electronic device may include a storage device and an index tree corresponding to the storage device. The electronic device can read and write data in the storage device based on the index tree. The index tree may include multiple pages, each of which can be used to index or store data. In related art, an electronic device can determine a target page to be stored in the index tree corresponding to the storage device based on a data storage request and store data in the target page. However, when the data to be stored in the target page is large, the target page becomes very large, requiring frequent splitting operations on the target page, resulting in high resource overhead for data storage. Various aspects of the present disclosure provide a data storage method, apparatus, device, storage medium, and program product for reducing data storage resource overhead. In a first aspect, embodiments of the present disclosure provide a data storage method, comprising: receiving a data storage request for storing first data on a disk; creating a first page corresponding to the first data if the data size of the first data is greater than or equal to a preset threshold; storing the first data on the first page, and mounting the first page in an index tree corresponding to the disk. In one possible implementation, mounting the first page in the index tree corresponding to the disk includes: determining a first master page corresponding to the first page in the index tree; updating index-related information of the first page, updating page content of the first master page, and updating index-related information of the first master page to mount the first page in the index tree. In a possible implementation, updating index-related information of the first page includes: determining a storage address of the first page on the disk and a first key value corresponding to the first data; generating a first memory record corresponding to the first page, the first memory record including the first key value and the storage address of the first page on the disk; storing a first page identifier of the first page and a memory address of the first memory record in a page mapping table corresponding to the disk; and updating a status corresponding to the first page in the page mapping table to a pending allocation status, where the pending allocation status indicates that the first page is not mounted to the index tree.In one possible embodiment, updating the page content of the first master page includes: generating a first index record based on a first key value corresponding to the first data and a first page identifier of the first page, the first index record including the first key value and the first page identifier; and adding the first index record to the first master page. In one possible embodiment, updating index-related information of the first master page includes: generating a first disk write record corresponding to the first master page, the first disk write record including a memory address of the first master page and a storage address of the first master page on the disk; updating the memory address of the first master page in a page mapping table corresponding to the disk to the memory address of the first disk write record. In one possible embodiment, the method further includes: writing the first master page to the disk based on the first disk write record; updating the status corresponding to the first page in the first master page to a confirmed allocation status on the disk, the confirmed allocation status indicating that the first page has been mounted to the index tree; and updating the status corresponding to the first page in the page mapping table to the confirmed allocation status. In one possible embodiment, the method further includes: receiving a data deletion request, the data deletion request requesting deletion of second data corresponding to a second key value; determining a second page corresponding to the second data in the index tree; and deleting the second page and index-related information in the index tree to delete the second data. In one possible embodiment, deleting the second page and index-related information in the index tree includes: deleting the second page; determining a second main page corresponding to the second page in the index tree; and updating the page content and index-related information of the second main page. In one possible embodiment, deleting the second page includes: if the second page has not been written to the disk, deleting the second page and a second memory record corresponding to the second page in a memory corresponding to the disk; if the second page has been written to the disk, deleting the second page in the memory and on the disk, respectively, and deleting the second memory record in the memory; and deleting the memory address of the second memory record in a page mapping table corresponding to the disk, and updating the status corresponding to the second page to a pending deletion status. In one possible implementation, updating the page content of the second main page includes: determining a second index record corresponding to the second page, the second index record including the second key value and a second page identifier of the second page; and updating, on the second main page, a status corresponding to the second index record to a confirmed deletion status.In one possible embodiment, updating the index-related information of the second master page includes: generating a second disk-written record corresponding to the second master page, the second disk-written record including the storage address of the second master page on the disk; and updating the memory address of the second master page in a page mapping table corresponding to the disk to the memory address of the second disk-written record. In one possible embodiment, the method further includes: updating the status corresponding to the second page in the page mapping table to a confirmed deletion status. In one possible embodiment, the method further includes: receiving a data merge request, the data merge request being used to request a merge of a third page and at least one update record of the third page; generating a merge record corresponding to the third page based on the data merge request, and mounting the merge record on the third page, the merge record being used to mount the next update record of the third page; and merging the third page and the at least one update record to obtain a merged page. In one possible embodiment, mounting the merged record on the third page includes: determining a second update record in the at least one update record, the second update record being the last update record in the at least one update record; adding the memory address of the second update record to the merged record; and updating the mapping corresponding to the third page identifier of the third page in a page mapping table corresponding to the disk with the memory address of the merged record. In one possible embodiment, after merging the third page and the at least one update record to obtain a merged page, the process further includes: determining the memory address of the merged page; and updating the memory address of the second update record in the merged record with the memory address of the merged page. In one possible embodiment, after generating the merged record corresponding to the third page according to the data merge request, the process further includes: determining a first record quantity of the at least one update record; and increasing the first record quantity in the merged record. In one possible embodiment, after merging the third page and the at least one update record to obtain a merged page, the process further includes: updating the first record quantity in the merged record to 0. In one possible implementation, the method further includes: receiving an update request corresponding to the third page; generating a target update record corresponding to the third page; adding a memory address of a merge record to the target update record; and updating the memory address of the merge record to the memory address of the target update record in a page mapping table corresponding to the disk.In one possible embodiment, the method further includes: determining at least one target data block for garbage collection on the disk, the target data block including multiple page fragments; determining valid page fragments in the at least one target data block and storing the valid page fragments in a buffer; and deleting the at least one target data block from the disk. In one possible embodiment, determining at least one target data block for garbage collection on the disk includes: determining a first data block on the disk, the first data block being the last data block of a previous garbage collection; determining a second data block on the disk undergoing a data operation; and determining a data block between the first data block and the second data block on the disk as the at least one target data block. In one possible embodiment, determining valid page fragments in the at least one target data block includes: determining a fragment status of each page fragment in the at least one target data block, the fragment status being either valid or invalid; and determining a page fragment in the at least one target data block in a valid state as the valid page fragment. In one possible implementation, for any page fragment; determining the fragment status of the page fragment in the at least one target data block includes: determining the fourth page corresponding to the page fragment, the page fragment being obtained after the fourth page is flushed to disk; determining the latest flush record corresponding to the fourth page, the latest flush record including the first storage address corresponding to the fourth page, the first storage address being the earliest valid flush address of the fourth page in the disk; if the storage address of the page fragment is greater than or equal to the first storage address, determining that the fragment status is the valid status; if the storage address of the page fragment is less than the first storage address, determining that the fragment status is the invalid status. In one possible embodiment, the method further includes: determining the number of data blocks on the disk; storing a page mapping table corresponding to the disk when the number of data blocks is greater than or equal to a preset number; determining a maximum page identifier in the page mapping table, the third data block that was most recently flushed to disk when storage of the page mapping table began, and a fourth data block that was undergoing data operations when storage of the page mapping table was completed; generating and storing check information based on the maximum page identifier, the third data block, and the fourth data block, the check information including the maximum page identifier, the identifier of the third data block, and the identifier of the fourth data block. In another possible embodiment, the method further includes: obtaining the page mapping table and the check information when a disk failure is determined; and performing fault recovery on the disk based on the page mapping table and the check information.In a second aspect, embodiments of the present disclosure provide a data storage device comprising: a receiving module, a creating module, a storing module, and a mounting module. The receiving module is configured to receive a data storage request requesting storage of first data on a disk; the creating module is configured to create a first page corresponding to the first data if the data size of the first data is greater than or equal to a preset threshold; the storing module is configured to store the first data on the first page; and the mounting module is configured to mount the first page in an index tree corresponding to the disk. In one possible implementation, the mounting module is specifically configured to: determine a first master page corresponding to the first page in the index tree; update index-related information of the first page, update page content of the first master page, and update index-related information of the first master page, so as to mount the first page in the index tree. In one possible embodiment, the mounting module is specifically configured to: determine the storage address of the first page on the disk and the first key value corresponding to the first data; generate a first memory record corresponding to the first page, the first memory record including the first key value and the storage address of the first page on the disk; store a first page identifier of the first page and the memory address of the first memory record in a page mapping table corresponding to the disk; and update the status of the first page in the page mapping table to a pending allocation state, where the pending allocation state indicates that the first page is not mounted to the index tree. In one possible embodiment, the mounting module is specifically configured to: generate a first index record based on the first key value corresponding to the first data and the first page identifier of the first page, the first index record including the first key value and the first page identifier; and add the first index record to the first master page. In one possible embodiment, the mounting module is specifically configured to: generate a first disk write record corresponding to the first master page, the first disk write record including the memory address of the first master page and the storage address of the first master page on the disk; and update the memory address of the first master page in the page mapping table corresponding to the disk to the memory address of the first disk write record.In one possible embodiment, the apparatus further includes: a processing module and an updating module, wherein the processing module is configured to flush the first master page to the disk based on the first flush record; the updating module is configured to update the status corresponding to the first page in the first master page to a confirmed allocation status on the disk, wherein the confirmed allocation status indicates that the first page has been mounted to the index tree; and the updating module is configured to update the status corresponding to the first page in the page mapping table to the confirmed allocation status. In one possible embodiment, the apparatus further includes: a first determining module and a deleting module, wherein the receiving module is further configured to receive a data deletion request requesting the deletion of second data corresponding to a second key value; the first determining module is configured to determine a second page corresponding to the second data in the index tree; and the deleting module is configured to delete the second page and index-related information from the index tree to delete the second data. In one possible embodiment, the deleting module is specifically configured to: delete the second page; determine a second master page corresponding to the second page in the index tree; and update the page content and index-related information of the second master page. In one possible embodiment, the deletion module is specifically configured to: if the second page has not been flushed to the disk, delete the second page and the second memory record corresponding to the second page from the memory corresponding to the disk; if the second page has been flushed to the disk, delete the second page from the memory and disk, respectively, and delete the second memory record from the memory; delete the memory address of the second memory record from the page mapping table corresponding to the disk, and update the status corresponding to the second page to a pending deletion state. In one possible embodiment, the deletion module is specifically configured to: determine a second index record corresponding to the second page, the second index record including the second key value and the second page identifier of the second page; update the status corresponding to the second index record in the second main page to a confirmed deletion state. In one possible embodiment, the deletion module is specifically configured to: generate a second flush record corresponding to the second main page, the second flush record including the storage address of the second main page on the disk; and update the memory address of the second main page in the page mapping table corresponding to the disk to the memory address of the second flush record. In one possible embodiment, the update module is further configured to: update the status corresponding to the second page in the page mapping table to a confirmed deletion state.In one possible embodiment, the apparatus further includes: a first generation module and a merging module, wherein the receiving module is further configured to receive a data merge request, the data merge request being configured to merge a third page and at least one update record of the third page; the first generation module is configured to generate a merge record corresponding to the third page based on the data merge request; the mounting module is further configured to mount the merge record on the third page, the merge record being configured to mount the next update record of the third page; and the merging module is configured to merge the third page and the at least one update record to obtain a merged page. In one possible embodiment, the mounting module is specifically configured to: determine a second update record in the at least one update record, the second update record being the last update record in the at least one update record; add the memory address of the second update record to the merge record; and update the mapping corresponding to the third page identifier of the third page to the memory address of the merge record in a page mapping table corresponding to the disk. In one possible implementation, the first determination module is further configured to determine the memory address of the merged page; the update module is further configured to update the memory address of the second update record in the merged record to the memory address of the merged page. In one possible implementation, the first generation module is further configured to determine a first record quantity of the at least one update record; and increment the first record quantity in the merged record. In one possible implementation, the update module is further configured to update the first record quantity in the merged record to 0. In one possible implementation, the receiving module is further configured to receive an update request corresponding to the third page; the first generation module is further configured to generate a target update record corresponding to the third page; the update module is further configured to increment the memory address of the merged record in the target update record, and to update the memory address of the merged record in the page mapping table corresponding to the disk to the memory address of the target update record. In one possible implementation, the device further includes: a second determination module, the second determination module being used to determine at least one target data block to be garbage collected in the disk, wherein the target data block includes multiple page fragments; the second determination module being used to determine valid page fragments in the at least one target data block; the storage module being used to store the valid page fragments in a buffer; and the deletion module being further used to delete the at least one target data block in the disk.In one possible embodiment, the second determination module is specifically configured to: determine a first data block on the disk, where the first data block is the last data block to be garbage collected; determine a second data block on the disk on which a data operation is being performed; and determine a data block between the first data block and the second data block on the disk as the at least one target data block. In one possible embodiment, the second determination module is specifically configured to: determine a fragment status of each page fragment in the at least one target data block, where the fragment status is either valid or invalid; and determine a page fragment in the at least one target data block that is in a valid state as the valid page fragment. In one possible implementation, for any page fragment; the second determination module is specifically used to: determine the fourth page corresponding to the page fragment, and the page fragment is obtained after the fourth page is written to disk; determine the latest disk write record corresponding to the fourth page, and the latest disk write record includes the first storage address corresponding to the fourth page, and the first storage address is the earliest disk write address of the fourth page that is currently valid in the disk; if the storage address of the page fragment is greater than or equal to the first storage address, then determine that the fragment state is the valid state; if the storage address of the page fragment is less than the first storage address, then determine that the fragment state is the invalid state. In one possible embodiment, the apparatus further includes: a third determination module and a second generation module, wherein the third determination module is configured to determine the number of data blocks in the disk; the storage module is further configured to, when the number of data blocks is greater than or equal to a preset number, store a page mapping table corresponding to the disk; the third determination module is further configured to determine a maximum page identifier in the page mapping table, the third data block that was most recently flushed to disk when storage of the page mapping table began, and a fourth data block that was undergoing data operations when storage of the page mapping table was completed; the second generation module is configured to generate and store check information based on the maximum page identifier, the third data block, and the fourth data block, the check information including the maximum page identifier, the identifier of the third data block, and the identifier of the fourth data block. In one possible embodiment, the apparatus further includes: an acquisition module and a recovery module, wherein the acquisition module is configured to, when determining that the disk has failed, acquire the page mapping table and the check information; and the recovery module is configured to perform fault recovery on the disk based on the page mapping table and the check information.In a third aspect, embodiments of the present disclosure provide an electronic device, comprising: a memory and a processor; the memory storing computer-executable instructions; and the processor executing the computer-executable instructions stored in the memory, causing the electronic device to perform any of the methods described in the first aspect. In a fourth aspect, embodiments of the present disclosure provide a computer-readable storage medium storing computer-executable instructions, which, when executed by the processor, implement any of the methods described in the first aspect. In a fifth aspect, embodiments of the present disclosure provide a computer program product, comprising a computer program, which, when executed by the processor, implements any of the methods described in the first aspect. Embodiments of the present disclosure provide a data storage method, apparatus, device, storage medium, and program product. An electronic device may receive a data storage request. If the size of first data is greater than or equal to a preset threshold, the electronic device may create a first page corresponding to the first data, store the first data in the first page, and mount the first page in an index tree corresponding to the disk. Because the electronic device can store the first data separately in the first page and then mount the first page in the index tree, there is no need to store the first data in a target page in the index tree. This avoids frequent splitting of the target page due to the large size of the first data, thereby reducing resource overhead for data storage. BRIEF DESCRIPTION OF THE DRAWINGS The drawings described herein are used to provide a further understanding of the present disclosure and constitute a part of the present disclosure. The illustrative embodiments of the present disclosure and their descriptions are used to explain the present disclosure and do not constitute an improper limitation on the present disclosure.In the accompanying drawings: Figure 1 is a scenario diagram provided by an exemplary embodiment of the present disclosure; Figure 2 is a schematic diagram of a Bwe-tree working principle provided by an exemplary embodiment of the present disclosure; Figure 3 is a flow chart of a data storage method provided by an exemplary embodiment of the present disclosure; Figure 4 is a flow chart of another data storage process provided by an exemplary embodiment of the present disclosure; Figure 5 is a process diagram of a data storage method provided by an exemplary embodiment of the present disclosure; Figure 6 is a flow chart of a data deletion method provided by an exemplary embodiment of the present disclosure; Figure 7 is a flow chart of another data deletion method provided by an exemplary embodiment of the present disclosure; Figure 8 is a process diagram of a data deletion method provided by an exemplary embodiment of the present disclosure; Figure 9 is a flow chart of an update link mechanism provided by an exemplary embodiment of the present disclosure; Figure 10 is a process diagram of an update link mechanism provided by an exemplary embodiment of the present disclosure; Figure 11 is a flow chart of a garbage collection method provided by an exemplary embodiment of the present disclosure; Figure 12 is a flow chart of a data recovery method provided by an exemplary embodiment of the present disclosure; Figure 13 is a schematic diagram of a page life cycle provided by an exemplary embodiment of the present disclosure; Figure 14 is a structural schematic diagram 1 of a data storage device provided by an exemplary embodiment of the present disclosure; Figure 15 is a structural schematic diagram 2 of a data storage device provided by an exemplary embodiment of the present disclosure; Figure 16 is a structural schematic diagram of an electronic device provided by an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION OF THE PREFERRED EMBODIMENTS: It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, storage, and display) involved in this disclosure are all authorized by the user or fully authorized by all parties. The collection, use, and processing of the relevant data must comply with relevant laws, regulations, and standards, and corresponding operation portals are provided for users to choose to authorize or reject. To further clarify the objectives, technical solutions, and advantages of this disclosure, the technical solutions of this disclosure will be described clearly and completely below in conjunction with specific embodiments of this disclosure and the corresponding drawings. Obviously, the described embodiments are only some of the embodiments of this disclosure, and are not exhaustive. All other embodiments derived by persons of ordinary skill in the art based on the embodiments of this disclosure without inventive effort are within the scope of protection of this disclosure. Figure 1 is a schematic diagram of a scenario provided by an exemplary embodiment of this disclosure. Referring to Figure 1, an electronic device may include an index tree. The index tree may include multiple pages.For example, the index tree may include page 1, to which page 2, ..., page n (n is an integer greater than or equal to 1) may correspond; page 2 may correspond to page 2-1, page 2-2, and page 2-3; and page n may correspond to page n-1 and page n-2. When the size of the first data is greater than or equal to a preset threshold, the electronic device may, in response to a data storage request, store the first data in a first page and mount the first page to the index tree. In related art, the electronic device may, in response to a data storage request, determine a target page to be stored in the index tree corresponding to the storage device and store the data in the target page. However, when the data to be stored in the target page is large, the target page becomes large, requiring frequent splitting operations on the target page, resulting in high resource overhead for data storage. In embodiments of the present disclosure, when the size of the first data is greater than a preset threshold, the electronic device may create a first page corresponding to the first data. The electronic device may store the first data in the first page and then mount the first page to the index tree. Because the electronic device can store the first data separately on a first page and then mount the first page to the index tree, there is no need to store the first data on the target page in the index tree. This avoids frequent splitting of the target page due to the large size of the first data, and reduces data storage resource overhead. In the technical solution disclosed herein, a method named Bw is provided. e -tree index tree. In order to facilitate understanding of the technical solution of the present disclosure, the working principle of the index tree Bwe-tree is first explained in conjunction with Figure 2. Figure 2 is a schematic diagram of the working principle of a Bwe-tree provided by an exemplary embodiment of the present disclosure. Referring to Figure 2, the electronic device may include a disk and a memory. A page mapping table may be provided in the memory, and the page mapping table may be used to manage the index tree. The page mapping table may include page identifiers and mapping items. For example, in the page mapping table, 0, 1, 2, 9 are page identifiers, and each page identifier corresponds to a mapping item. A mapping item may store a corresponding memory address or storage address. Among them, the memory address refers to the address in the memory, and the storage address refers to the address in the disk. For Bwe eAny page (also called a node) in the tree can be identified by P. For example, page 2 can be represented as P2. It should be noted that different pages corresponding to the same page identifier can be distinguished by key value range. For example, the page corresponding to page identifier 2 may be page P2[400,500]. After updating, the page corresponding to page identifier 2 may be page P2[400,700).
[0002] Bw e -tree can include multiple index pages and multiple leaf pages. For example, Bw eIn a -tree, pages P3 and P8 can be index pages, and pages P2 and P4 can be leaf pages. Page P3 can be the parent page of pages P2 and P4. Each index page can have a corresponding key value range. An index page can store index records corresponding to multiple child pages, pointers to each child page, and pointers to right sibling pages. Alternatively, the pointers can be the memory addresses or storage addresses of the corresponding pages. For example, as shown in Figure 2, the key value range corresponding to page P3 can be (-8, 1000). Page P3 can store: the index record corresponding to page P1 (P1, 400), the index record corresponding to page P2 (P2, 700), the index record corresponding to page P4 (P4, 1000), and a pointer to right sibling page P8. Each leaf page has a corresponding key value range [low key, high key). The leaf page stores multiple key-value pairs within the key value range and a pointer to the right sibling page. Each value has a corresponding log sequence number (LSN). For example, in a Bwe-tree, the key value range of page P2 can be [400, 700). Page P2 then stores the values corresponding to keys 400 to 700, and a pointer to its right sibling page P4. For example, key 400 may have corresponding values 1-LSN1 and value 2-LSN2. Value 1 is the historical data corresponding to key 400, and value 2 is the current data corresponding to key 400. An electronic device can perform page processing on pages in an index tree through a structural modification operation (SMO). When performing an operation on a page in the BWE-tree, an operation record corresponding to the page can be generated and linked to the page, rather than directly modifying the page. Operation records may include data delta records (data-delta), flush records (flush-delta), and stub records (stub-delta). Any operation record may include the memory address of the corresponding page or the memory address of the previous operation record, a data delta count, a page fragment count, and a page size. If the operation record is a flush record, the flush record may also include the storage address of the page fragment on disk. The page size refers to the total size of multiple key-value pairs and LSNs in the page. That is, the size of the logical page.For any page, each time an operation record corresponding to that page is generated, the mapping entry corresponding to that page can be updated with the memory address of the operation record, so that the mapping entry corresponding to that page can point to the operation record for that page. For example, as shown in Figure 2, when page P2 is flushed to disk, that is, when page P2 is stored to disk as P2 page fragment 1, a flush record a corresponding to page P2 can be generated. Flush record a can include the memory address of page P2 in memory, a data increment count of 0, a page fragment count of 1, a page size of 4 KB (kilobytes), and the storage address 1 of P2 page fragment 1 on disk. In the page mapping table, the mapping entry corresponding to page ID 2 can be updated with the memory address of flush record a. When new data is added to page P2, a data increment record 1 corresponding to P2 can be generated. Incremental data record 1 may include: the newly added data for page P2, i.e., the value corresponding to key value 515, etc.; the memory address of disk-written record a; a data increment count of 1; a page fragment count of 2; and a page size of 6 KB. In the page mapping table, the memory address of disk-written record a can be updated to the memory address of incremental data record 1 in the mapping entry corresponding to page ID 2. Similarly, when the value corresponding to key value 455 is updated for page P2, incremental data record 2 can be generated. Incremental data record 2 may include: the newly added data for page P2, i.e., the value corresponding to key value 455, etc.; the memory address of incremental data record 1; a data increment count of 2; a page fragment count of 2; and a page size of 7 KB. In the page mapping table, the memory address of incremental data record 1 can be updated to the memory address of incremental data record 2 in the mapping entry corresponding to page ID 2. When page P2 is flushed again, that is, the newly added data of page P2 is stored on disk as P2 page fragment 2, a flush record b corresponding to page P2 is generated. Flush record b may include the memory address of data increment record 2, a data increment count of 2, a page fragment count of 2, a page size of 7 KB, and the storage address 2 of P2 page fragment 2 on disk. In the page mapping table, the memory address of data increment record 2 can be updated to the memory address of flush record b in the mapping entry corresponding to page identifier 2. It should be noted that, on disk, P2 page fragment 2 may include the storage address of P2 page fragment 1.When page P2 is flushed to disk again, incremental storage can be performed, storing only the incremental data (515...) and (455...) for page P2. This helps reduce storage write amplification. When memory is insufficient, pages in memory can be stored to disk, deleted from memory, and the corresponding stub record stored in memory to reduce memory usage. For example, when memory is insufficient, page P4 can be stored to disk, and stub record 1 corresponding to page P4 can be stored in memory. Stub record 1 includes the disk address of page P4. In the page mapping table, the mapping entry corresponding to page ID 4 can be updated with the memory address of stub record 1. For any page, if the page is deleted, the corresponding page ID can be recycled and linked to the IDs of other free pages. For example, as shown in Figure 2, if pages 0, 9, 7, and 6 are free pages, page ID 0 can point to page ID 9, page ID 9 can point to page ID 7, page ID 7 can point to page ID 6, and page ID 6 can point to page ID 0, thus linking the page IDs of these four free pages together. It should be noted that when flushing any page to disk, the following procedures are performed: If the page is linked to multiple operation records, when the data increment count in the operation record reaches a threshold, the page can be updated based on the multiple operation records to obtain a new page, and this new page can be stored as a page fragment in the buffer. If the data increment count in the operation record does not reach the threshold and flushing to disk is still required, the page and the multiple operation records can be stored as a page fragment in the buffer. The buffer can store page fragments corresponding to multiple pages. When the buffer is full, the multiple page fragments in the buffer can be encapsulated into a data block, and a corresponding logical block number is assigned to the data block. This data block is then stored to disk, i.e., flushed to disk. The logical block number refers to the sequence number corresponding to the data block. Any data block can have a corresponding logical block number. Logical block numbers are continuously and monotonically increasing. For example, on a disk, the first data block stored may have logical block number 001, and the second data block may have logical block number 002. It should be noted that if the logical block number of the latest data block on the disk is 1000, this does not mean that there are 1000 data blocks on the disk. This is because some data blocks before the latest data block with logical block number 1000 may have been deleted from the disk.For example, if the logical block number of the latest data block on the current disk is 1000, but the 100 data blocks corresponding to logical block numbers 1 to 100 have been deleted, the current disk may contain 900 data blocks, with the logical block number of the latest data block being 1000. The technical solutions presented in this disclosure are described in detail below through specific embodiments. It should be noted that the following embodiments may exist independently or in combination, and that identical or similar content will not be repeated in different embodiments. Figure 3 is a schematic flow chart of a data storage method provided by an exemplary embodiment of the present disclosure. Referring to Figure 3, the method may include:
[0003] S301. Receive a data storage request. The execution subject of the embodiments of the present disclosure may be an electronic device or a data storage device provided in the electronic device. The data storage device may be implemented via software or a combination of software and hardware. The data storage device may be a processor in the electronic device. For ease of understanding, the following description uses the execution subject as an electronic device as an example. The electronic device may include a disk. The data storage request may be used to request storage of first data on the disk. The data storage request may include a first key value and the first data corresponding to the first key value. Optionally, the data storage request may also include an LSN corresponding to the first data. For example, the electronic device may receive data storage request 1, which may include the first key value 910, data 1, and LSN 1. Data storage request 1 may be used to request the electronic device to store data 1 on the disk.
[0004] S302. If the data size of the first data is greater than or equal to a preset threshold, create a first page corresponding to the first data. The preset threshold can be manually preset. For example, the preset threshold can be 4 KB. Since the data storage request includes the first data, the electronic device can obtain the first data after receiving the data storage request. The electronic device can determine whether the data size of the first data is greater than or equal to the preset threshold. If so, the electronic device can create a first page corresponding to the first data in the memory. The first page can be a page outside the index tree. For example, if data storage request 1 includes data 1 and the size of data 1 is 8 KB, the electronic device can create a first page, assuming that the first page is page P30. It should be noted that if the data size of the first data is less than the preset threshold, the electronic device can determine a target page in the index tree corresponding to the disk and store the first data in the target page. For example, if the data size of the first data is 1 KB, the electronic device can determine a target page in the index tree, assuming that the target page is page P2, and then store the first data in page P2.
[0005] S303: Store the first data in the first page and mount the first page in the index tree corresponding to the disk. After the electronic device creates the first page, it can store the first data in the first page. For example, if the electronic device creates the first page as page P30, the electronic device can store data 1 in page P30. In an optional embodiment, the first page can be mounted in the index tree corresponding to the disk in the following manner: determine the first main page corresponding to the first page in the index tree; update the index-related information of the first page, update the page content of the first main page, and update the index-related information of the first main page to mount the first page in the index tree. The index tree can be the Bw described in FIG. e-tree» The first main page can be an index page in the index tree. For example, if the first page is page P30 and the corresponding first main page is page P15, the electronic device can update the index-related information of page P30 and update the page content and index-related information of page P15 to mount page P30 in the index tree. In an embodiment of the present disclosure, the electronic device can receive a data storage request. If the data size of the first data is greater than or equal to a preset threshold, the electronic device can create a first page corresponding to the first data, store the first data in the first page, and mount the first page in the corresponding index tree on the disk. Because the electronic device can store the first data separately in the first page and then mount the first page in the index tree, it is not necessary to store the first data in the target page in the index tree. This avoids frequent splitting operations on the target page due to the large size of the first data and reduces data storage resource overhead. The following describes the data storage process in detail based on the embodiment shown in FIG. 3 and in conjunction with FIG. 4 . FIG. 4 is a flow chart of another data storage process provided by an exemplary embodiment of the present disclosure. Referring to FIG. 4 , the method may include:
[0006] 5401. Receive a data storage request.
[0007] S402: If the data size of the first data is greater than or equal to the preset threshold, create a first page corresponding to the first data. It should be noted that the specific execution process of steps S401-S402 can refer to the specific execution process of steps S301-S302, and will not be repeated here.
[0008] S403. Store the first data in the first page. After the electronic device creates the first page, it can store the first data in the first page. Since the data storage request can also include the first key value and LSN number corresponding to the first data, the electronic device can also store the first key value and LSN number in the first page. For example, if the electronic device creates page P30 as the first page, the electronic device can store the first key value 910, data 1, and LSN 1 in page P30.
[0009] S404. Update the index-related information of the first page. In an optional embodiment, the index-related information of the first page can be updated in the following manner: determine the storage address of the first page on disk and the first key value corresponding to the first data; generate a first memory record corresponding to the first page; store the first page identifier of the first page and the memory address of the first memory record in a page mapping table corresponding to the disk; and update the status of the first page in the page mapping table to a pending allocation state. Optionally, the electronic device can determine the storage address of the first page on disk and store the first page on disk. Optionally, the electronic device can also set a pending allocation (Pending Alloc) flag on the disk and in the first page. The pending allocation flag can be used to indicate that the first page is not mounted to the index tree. The electronic device can generate a first memory record corresponding to the first page in memory. Since the first page only stores the first data, the electronic device can use the first key value corresponding to the first data as the first key value corresponding to the first page. The first memory record corresponding to the first page can include the first key value and the storage address of the first page on disk. Optionally, the first memory record may also include a first page identifier of the first page and the memory address of the first page. For example, if the first page is page P30, the first page identifier of the first page may be 30. If the first key value corresponding to data 1 is 910, the electronic device may generate a memory record 1 corresponding to page P30 in memory. Memory record 1 may include the first page identifier 30, the first key value 910, the memory address of page P30, and the storage address of page P30 on the disk. The electronic device's memory may store a page mapping table corresponding to the disk. The electronic device may determine the memory address of the first memory record corresponding to the first page in the memory, store the first page identifier of the first page in the page mapping table, and store the memory address of the first memory record in the mapping entry corresponding to the first page identifier, so that the first page identifier in the page mapping table points to the memory address of the first memory record. The electronic device may store a pending allocation identifier in the mapping entry corresponding to the first page identifier in the page mapping table to update the state corresponding to the first page to the pending allocation state. The pending allocation state may indicate that the first page is not mounted to the index tree. For example, if the first page is page P30, and page P30 corresponds to memory record 1, the electronic device may store the first page identifier 30 in the page mapping table, and store the memory address of memory record 1 and the identifier to be allocated in the mapping entry corresponding to the first page identifier 30.
[0010] S405. Determine the first main page corresponding to the first page in the index tree. Since the first page only stores the first data, the electronic device may use the first key value corresponding to the first data as the first key value corresponding to the first page. Optionally, the electronic device may determine the target key value range within which the first key value falls based on the first key value corresponding to the first page, and further determine the index page corresponding to the target key value range as the first main page. For example, if the first key value corresponding to data 1 is 910, and data 1 is stored in the first page, i.e., page P30, the electronic device may determine that the first key value corresponding to page P30 is 910, and further determine that the first key value 910 falls within the target key value range [800, 950] based on the index tree. If the index page corresponding to the target key value range [800, 950] is page P15, the electronic device may determine that the first main page corresponding to page P30 is page P15.
[0011] S406. Update the page content of the first main page. In an optional embodiment, the page content of the first main page can be updated in the following manner: generate a first index record based on the first key value corresponding to the first data and the first page identifier of the first page; and add the first index record to the first main page. The first index record includes the first key value and the first page identifier corresponding to the first data. For example, if the first page is page P30, the first page identifier is 30, and the first key value is 910, the electronic device can generate a first index record (910, P30) based on the first page identifier 30 and the first key value 910. If the first main page is page P15, and page P15 includes the index records (810, P28), (840, P27), and (880, P29), the electronic device can add the first index record (910, P30) to page P15. Page P15 may include index records as: (810, P28) (840, P27), (880, P29), (910, P30).
[0012] S407. Update the index-related information of the first master page. In an optional embodiment, the index-related information of the first master page can be updated in the following manner: generate a first disk write record corresponding to the first master page; and update the memory address corresponding to the first master page in the page mapping table corresponding to the disk to the address of the first disk write record in the memory. The electronic device can determine the storage address of the first master page on the disk, generate a first disk write record corresponding to the first master page in the memory, and link the first disk write record to the target page. The first disk write record can include the memory address of the first master page and the storage address of the first master page on the disk. Optionally, the first disk write record can also include at least one of the following: the memory address of the first master page, a data increment count, a page fragment count, and the page size of the first master page. For example, if the first master page is page P15, the electronic device can determine the storage address of page P15 on the disk and generate disk write record 1 corresponding to page P15. Disk write record 1 can include the memory address of page P15, a data increment count of 1, a page fragment count of 1, a page size of 7 KB, and the storage address of page P15 on the disk. Before the first disk write record is generated, the mapping entry corresponding to the first master page identifier in the page mapping table stores the memory address of the first master page. After generating the first disk write record corresponding to the first master page in the memory, the electronic device can update the memory address of the first master page in the mapping entry corresponding to the first master page identifier in the page mapping table to the memory address of the first disk write record, so that the first master page identifier in the page mapping table can point to the first disk write record. For example, if the first master page is page P15 and page P15 has a corresponding disk write record 1, the memory address of page P15 can be updated to the memory address of disk write record 1 in the mapping entry corresponding to the first master page identifier 15 in the page mapping table.
[0013] S408. Write the first master page to the disk according to the first disk write record. For example, if the first master page is page P15, and disk write record 1 corresponding to page P15 includes the storage address of page P15 on the disk, the electronic device may store page P15 on the disk according to the storage address of page P15 on the disk, i.e., write page P15 to the disk.
[0014] S409. On the disk, update the state corresponding to the first page in the first master page to a confirmed allocation state. The electronic device may set a validating allocation flag corresponding to the first page in the first master page on the disk. The validating allocation flag is used to indicate that the first page has been mounted to the index tree. For example, if the first page is page P30 and the first master page is page P15, after the electronic device stores page P15 on the disk, it may set a validating allocation flag corresponding to page P30 in page P15 to indicate that page P30 has been mounted to the index tree.
[0015] S410. In the page mapping table, update the status corresponding to the first page to the confirmed allocation state. Optionally, the electronic device may delete the pending allocation identifier in the mapping entry corresponding to the first page identifier in the page mapping table to update the status corresponding to the first page to the confirmed allocation state. For example, if the first page is page P30, the electronic device may delete the pending allocation identifier in the mapping entry corresponding to the first page identifier 30 in the page mapping table to update the status corresponding to page P30 to the confirmed allocation state. In an embodiment of the present disclosure, the electronic device may receive a data storage request. If the data size of the first data is greater than or equal to a preset threshold, the electronic device may create a first page corresponding to the first data, store the first data in the first page, and update the index-related information of the first page. The electronic device may determine the first main page corresponding to the first page in the index tree, update the page content of the first main page and update the index-related information of the first main page to mount the first page in the index tree. The electronic device may write the first main page to disk based on the first disk write record and update the status corresponding to the first page in the first main page to the confirmed allocation state. The electronic device can update the status corresponding to the first page in the page mapping table to the confirmed allocation state. Because the electronic device can store the first data separately on the first page and then mount the first page to the index tree, there is no need to store the first data on the target page in the index tree. This avoids frequent splitting of the target page due to the large size of the first data, reducing data storage resource overhead. The following further describes the above-described data storage method based on the embodiment shown in FIG4 and in conjunction with FIG5. FIG5 is a process diagram of a data storage method provided by an exemplary embodiment of the present disclosure. Referring to FIG5, steps ①, ②, ③, ④, ⑤, and ⑦ are included. An electronic device may receive a data storage request 1, which may include a first key value 910, data 1, and LSN1. The electronic device may determine whether the data size of data 1 is greater than a preset threshold. If the data size of data 1 is greater than the preset threshold, then in step ①, the electronic device may create a page P30 in the memory and store the first key value 910, data 1, and LSN1 in page P30. In step ②, the electronic device may store page P30 to the disk and set an identifier to be allocated in page P30. The electronic device may generate a memory record 1 corresponding to page P30. The memory record 1 may include a first page identifier 30, a first key value 910, a memory address of page P30, and a storage address of page P30 on the disk.In step 3, the electronic device may store the first page identifier 30 in the page mapping table and, in the mapping entry corresponding to the first page identifier 30, store the memory address of memory record 1 and the identifier to be allocated. In step 4, the electronic device may determine that the first primary page corresponding to page P30 is page P15 and update the page content of page P15. Specifically, the electronic device may generate a first index record (910, P30) based on the first page identifier 30 and the first key value 910, and add the first index record (910, P30) to page P15. In step 5, the electronic device may generate a disk write record 1 corresponding to page P15 and store page P15 to disk based on disk write record 1. Disk write record 1 may include the memory address of page P15, a data increment count of 1, a page fragment count of 1, a page size of 7 KB, and the storage address of page P15 on disk. After the electronic device stores page P15 to disk, it may also set a confirmed allocation flag corresponding to page P30 in page P15 to indicate that page P30 has been mounted to the index tree. In step (i), the electronic device may update the memory address of page P15 in the mapping entry corresponding to the first master page identifier 15 in the page mapping table to the memory address of disk record 1. In step (ii), the electronic device may delete the pending allocation flag in the mapping entry corresponding to the first page identifier 30 in the page mapping table and also delete the pending allocation flag in page P30. In an embodiment of the present disclosure, the electronic device may receive a data storage request. If the data size of the first data is greater than or equal to a preset threshold, the electronic device may create a first page corresponding to the first data, store the first data in the first page, and update the index-related information of the first page. The electronic device may then determine the first master page corresponding to the first page in the index tree and update the page content and index-related information of the first master page to mount the first page in the index tree. The electronic device can write the first master page to disk based on the first write record and update the status corresponding to the first page in the first master page to the confirmed allocation state on the disk. The electronic device can also update the status corresponding to the first page in the page mapping table to the confirmed allocation state. Because the electronic device can store the first data separately on the first page and then mount the first page to the index tree, there is no need to store the first data on the target page in the index tree. This avoids frequent splitting of the target page due to the large size of the first data, reducing data storage resource overhead. Figures 3 through 5 above illustrate the data storage method. The technical solution of this disclosure also provides a corresponding data deletion method.The data deletion method is described below with reference to FIG6-FIG8. FIG6 is a flow chart of a data deletion method provided by an exemplary embodiment of the present disclosure. Referring to FIG6, the method may include:
[0016] S601. Receive a data deletion request. The data deletion request may be used to request deletion of second data corresponding to a second key value. The second data may be data greater than or equal to a preset threshold. The data deletion request may include the second key value. Optionally, the data deletion request may also include the LSN corresponding to the second data. For example, an electronic device may receive data deletion request 1, which may include the second key value 810 corresponding to data 2 and LSN 1. Data storage request 1 may be used to request deletion of data 2.
[0017] S602. Determine the second page corresponding to the second data in the index tree. Since the data deletion request may include a second key value, and the key value corresponding to the page storing the second data is the second key value, after obtaining the second key value, the electronic device may search the index tree for the page containing the second key value and determine the page containing the second key value as the second page corresponding to the second data. The second page may be a page that solely stores the second data. For example, if data deletion request 1 includes the second key value 810, and if the key value corresponding to page P28 is 810, the electronic device may determine, based on the second key value 810, that the second page corresponding to data 2 is page P28.
[0018] S603. Delete the second page and index-related information from the index tree to delete the second data. In an optional embodiment, the second page and index-related information can be deleted from the index tree in the following manner: delete the second page; determine the second main page corresponding to the second page in the index tree; and update the page content and index-related information of the second main page. For example, if the second page is page P28, the electronic device can delete page P28. Because the electronic device finds the second page by searching the second main page corresponding to the second page, the electronic device has already determined the second main page corresponding to the second page when determining the second page in the index tree. For example, if the second page is page P28, the electronic device can determine that the second main page corresponding to page P28 is page P15. The electronic device can update the page content and index-related information of page P15 to delete data 2. In an embodiment of the present disclosure, the electronic device can receive a data deletion request, determine the second page corresponding to the second data in the index tree, and then delete the second page and index-related information from the index tree to delete the second data. Because the electronic device can delete the second page that stores the second data independently without incurring frequent page merging operations, the resource overhead of deleting data is reduced. The data deletion method described above is described in detail below, based on the embodiment shown in FIG6 and in conjunction with FIG7 . FIG7 is a flow chart of another data deletion method provided by an exemplary embodiment of the present disclosure. Referring to FIG7 , the method may include:
[0019] 5701. Receive a data deletion request.
[0020] S702. Determine the second page corresponding to the second data in the index tree. It should be noted that the specific execution process of steps S701-S702 can refer to the specific execution process of steps S601-S602, and will not be repeated here.
[0021] S703. Delete the second page. Optionally, deleting the second page may include the following two scenarios: Scenario 1: If the second page has not been written to disk. In this scenario, since the second page has not been written to disk, the second page and the second memory record are both in memory. The electronic device may delete the second page and the second memory record corresponding to the second page from the memory corresponding to the disk. The second memory record may include the second key value and the storage address of the second page on disk. Optionally, the second memory record may also include the second page identifier of the second page and the memory address of the second page. For example, if the second page is page P28, the memory record 2 corresponding to page P28 may include the second page identifier 30, the second key value 810, the memory address of page P28, and the storage address of page P28 on disk. For example, if the second page is page P28, page P28 has not been written to disk, and page P28 has a corresponding memory record 2, the electronic device may delete page P28 and memory record 2 from the memory. Case 2: If the second page has been flushed to disk, the second page is deleted from both the memory and disk, and the second memory record is deleted from the memory. In this case, since the second page has been flushed to disk, it is possible that the second page exists in both the disk and memory, and the second memory record exists in the memory. Therefore, the electronic device can delete the second page from both the memory and disk, and delete the second memory record from the memory. For example, if the second page is page P28, and page P28 has been flushed to disk, it is possible that page P28 exists in both the disk and memory. If memory record 2 exists for page P28, the electronic device can delete page P28 from both the disk and memory, and delete memory record 2 from the memory. Since, in the process of generating the second page, the memory address of the second memory record is stored in the mapping entry corresponding to the second page identifier in the page mapping table, in the above two cases, after the electronic device deletes the second page and the second memory record, it can delete the memory address of the second memory record in the mapping entry corresponding to the second page identifier in the page mapping table; but since the second index record corresponding to the second page has not been deleted in the second main page corresponding to the second page, the electronic device can set a pending dealloc flag in the mapping entry corresponding to the second page identifier in the page mapping table corresponding to the disk, so as to update the state corresponding to the second page to a pending dealloc state.For example, if the second page is page P28, the electronic device may delete the memory address of memory record 2 in the mapping entry corresponding to the second page identifier 28 in the page mapping table, and set a pending deletion identifier to update the state of page P28 to a pending deletion state.
[0022] S704. Determine the second main page corresponding to the second page in the index tree. For example, if the second page is page P28, the electronic device may determine that the second main page corresponding to page P28 is page P15.
[0023] S705. Update the page content of the second main page. In an optional embodiment, the page content of the second main page can be updated in the following manner: determine a second index record corresponding to the second page; and update the status corresponding to the second index record on the second main page to a confirmed deletion state. The second index record can include a second key value and a second page identifier corresponding to the second page. For example, if the second page is page P28 and the second key value is 810, the electronic device can determine that the second index record can be (810, P28). The second main page can include multiple index records, including the second index record. Optionally, the electronic device can set a confirmed deletion (ValidatingDeallo) flag for the second index record on the second main page to update the status corresponding to the second index record to a confirmed deletion state. For example, if the second main page is page P15, page P15 may include multiple index records: (810, P28), (840, P27), (880, P29), (910, P30). If the second index record is (810, P28), the electronic device may set a pending deletion flag for the second index record (810, P28) on page P15 to update the status corresponding to the second index record (810, P28) to a confirmed deletion state. After the update, page P15 may include multiple index records: (810, P28, pending deletion flag), (840, P27), (880, P29), (910, P30).
[0024] S706. Update the index-related information of the second master page. In an optional embodiment, the index-related information of the second master page can be updated in the following manner: generate a second disk-write record corresponding to the second master page; and update the memory address of the second master page in the page mapping table corresponding to the disk to the memory address of the second disk-write record. The electronic device can determine the storage address of the second master page on the disk, write the second master page to the disk, and generate a second disk-write record. The second disk-write record can include the storage address of the second master page on the disk. Optionally, the second disk-write record can also include at least one of the following: the memory address of the second master page, a data increment count, a page fragment count, and the page size of the second master page. For example, if the second master page is page P15, the electronic device can generate disk-write record 2 corresponding to page P15. Disk-write record 2 can include the memory address of page P15, a data increment count of 0, a page fragment count of 1, a page size of 7 KB, and the storage address of page P15 on the disk. Because the memory address of the second master page is stored in the mapping entry corresponding to the second master page identifier in the page mapping table before the second disk flush record is generated, after the electronic device generates the second disk flush record corresponding to the second master page in memory, it can update the memory address of the second master page in the mapping entry corresponding to the second master page identifier in the page mapping table to the memory address of the second disk flush record, so that the second master page identifier in the page mapping table can point to the second disk flush record. For example, if the second master page is page P15, and page P15 has a corresponding disk flush record 2, the memory address of page P15 can be updated to the memory address of disk flush record 2 in the mapping entry corresponding to the second master page identifier 15 in the page mapping table.
[0025] S707. In the page mapping table, the status corresponding to the second page is updated to a confirmed deletion state. Since, in step S703, the electronic device set a pending deletion flag in the mapping entry corresponding to the second page identifier in the page mapping table, the electronic device can delete the pending deletion flag to update the status corresponding to the second page to the confirmed deletion state. Optionally, the electronic device can also delete the second page identifier or reclaim the second page identifier as a free page identifier. For example, if the second page is page P28 and a corresponding memory record 2 exists for page P28, the electronic device can delete the pending deletion flag in the page mapping table to update the status corresponding to page P28 to a confirmed deletion state. In an embodiment of the present disclosure, the electronic device can receive a data deletion request, determine the second page corresponding to the second data in the index tree, and delete the second page. The electronic device can determine the second main page corresponding to the second page in the index tree, update the page content and index-related information of the second main page, and delete the mapping information corresponding to the second page in the page mapping table. Because the electronic device can delete the second page that stores the second data independently without incurring frequent page merging operations, the resource overhead of deleting data is reduced. The data deletion process described above is further described below, based on the embodiments shown in FIG. 6 or FIG. 7 , in conjunction with FIG. 8 . FIG. 8 is a schematic diagram of a data deletion method provided by an exemplary embodiment of the present disclosure. Referring to FIG. 8 , steps ①, ②, ③, ④, ⑤, and ③ are included. An electronic device may receive a data deletion request 1, which may include a second key value 810 and LSN 1. Data deletion request 1 is for data 2 corresponding to the second key value 810 and LSN 1. In step ①, the electronic device may determine, based on the second key value 810, that the second page corresponding to data 2 is page P28. In step ②, if page P28 exists in both memory and disk, the electronic device may delete page P28 from both disk and memory, and delete memory record 2 from memory. Memory record 2 may include a second page identifier 28, a second key value 810, the memory address of page P28, and the storage address of page P28 on disk. In step 3, the electronic device may delete the memory address of memory record 2 from the mapping entry corresponding to second page identifier 28 in the page mapping table and set the pending deletion flag to update the status of page P28 to the pending deletion state. In step 4, the electronic device may determine that the second primary page corresponding to page P28 is page P15 and update the page content of page P15.Specifically, the electronic device may set a pending deletion flag for the second index record (810, P28) in page P15 to update the status corresponding to the second index record (810, P28) to the confirmed deletion state. In step 5, the electronic device may generate a disk write record 2 corresponding to page P15 and write page P15 to disk. Disk write record 2 may include the memory address of page P15, a data increment count of 0, a page fragment count of 1, a page size of 7KB, and the storage address of page P15 on disk. In step 7, the electronic device may update the memory address of page P15 to the memory address of disk write record 2 in the mapping entry corresponding to the second primary page identifier 15 in the page mapping table. In step 7, the electronic device may delete the pending deletion flag in the page mapping table to update the status corresponding to page P28 to the confirmed deletion state, thereby releasing the second page identifier 28. In an embodiment of the present disclosure, an electronic device can receive a data deletion request, determine the second page corresponding to the second data in an index tree, and delete the second page. The electronic device can determine the second main page corresponding to the second page in the index tree, update the page content and index-related information of the second main page, and delete the mapping information corresponding to the second page in the page mapping table. Because the electronic device can delete the second page that independently stores the second data without incurring frequent page merging operations, the resource overhead of deleting data is reduced. When the electronic device merges pages in the index tree, the pages may be updated concurrently. The technical solution of the present disclosure also provides an update link mechanism to enable merging without affecting page updates. The update link mechanism is described below with reference to FIG9 . FIG9 is a schematic flow diagram of an update link mechanism provided in an exemplary embodiment of the present disclosure. Referring to FIG9 , the mechanism may include:
[0026] S901. Receive a data merge request. The data merge request may be used to request the merging of a third page and at least one update record for the third page. The update record may be the data increment record described in the embodiment of FIG. 2 . Any update record may include: the updated data for the third page, the memory address of the previous update record or the third page, a data increment count, a page fragment count, and a page size. Optionally, when the first record count of at least one update record for the third page is greater than or equal to a first threshold, the electronic device may generate a data merge request; or, alternatively, the electronic device may receive the data merge request in response to a user operation. The first threshold may be preset. For example, the first threshold may be 2. For example, when the first record count of at least one update record for page P2[400,700) is 2, which is equal to the first threshold 2, the electronic device may generate data merge request 1; or, alternatively, the electronic device may receive data merge request 1 in response to a user operation. Data merge request 1 may be used to request the merging of page P2[400,700) and the corresponding update records 1 and 2.
[0027] S902. Generate a merge record corresponding to the third page based on the data merge request, and mount the merge record on the third page. The merge record can be used to mount the next update record for the third page. The next update record refers to an update record generated after at least one existing update record. The electronic device can generate a merge record corresponding to the third page in memory based on the data merge request. For example, if the third page is page P2[400,700), the electronic device can generate merge record 1 corresponding to page P2[400,700] in memory based on data merge request 1. In an optional embodiment, the merge record can be mounted on the third page in the following manner: determine a second update record in at least one update record; add the memory address of the second update record to the merge record; and update the mapping corresponding to the third page identifier of the third page to the memory address of the merge record in the corresponding page mapping table on disk. The second update record is the last update record in the at least one update record. For example, if the third page is page P2[400,700), corresponding to update record 1 and update record 2, and if update record 2 is the last update record, the electronic device may determine that the second update record in update record 1 and update record 2 is update record 2. The electronic device may add memory address 2 of update record 2 to merged record 1. Optionally, the electronic device may further determine a first record quantity of at least one update record and add the first record quantity to the merged record. The first record quantity indicates the number of update records corresponding to the third page at this time. For example, if the third page is page P2[400,700), corresponding to update record 1 and update record 2, the first record quantity is 2. The electronic device may add the first record quantity 2 to merged record 1. The electronic device may determine a third page identifier for the third page and, in the mapping entry corresponding to the third page identifier in the page mapping table, update the mapping content corresponding to the third page identifier to the memory address of the merged record in memory. For example, if the third page is page P2[400,700), the electronic device may determine that the third page identifier is 2. If the mapping entry corresponding to the third page identifier (i.e., page identifier 2) in the page mapping table stores memory address 2 of update record 2, the electronic device may update the mapping content corresponding to the third page identifier (i.e., page identifier 2) in the page mapping table, i.e., memory address 2 of update record 2, to the memory address of merge record 1.
[0028] S903. Merge the third page and the at least one update record to obtain a merged page. Optionally, the electronic device may modify the page content of the third page based on the at least one update record to merge the third page and the at least one update record to obtain a merged page. For example, if the third page is page P2[400,700), update record 1 is data corresponding to key value 515 added to page P2[400,700), and update record 2 is data corresponding to key value 455 added to page P2[400,700), the electronic device may add data corresponding to key value 515 to page P2[400,700] based on update record 1 and data corresponding to key value 455 to page P2[400,700] based on update record 2, thereby obtaining the updated page P2[400,700), i.e., the merged page.
[0029] S904. Determine the memory address of the merged page. For example, if the merged page is the updated page P2[400,700), the electronic device may determine the memory address of the updated page P2[400,700).
[0030] S905. In the merge record, update the memory address of the second update record to the memory address of the merged page. Since the electronic device added the memory address of the second update record to the merge record when generating the merge record (i.e., before performing the page merge), after merging the third page and at least one update record to obtain the merged page, the memory address of the second update record can be updated in the merge record to the memory address of the merged page, so that the merged record is mounted on the merged page. For example, if merge record 1 includes memory address 2 of update record 2, and the merged page is the updated page P2[400,700), the electronic device can update memory address 2 of update record 2 in merge record 1 to the memory address of the updated page P2[400,700).
[0031] S906. Update the number of first records in the merged record to 0. Since the merged page is obtained by merging the third page and at least one update record, there is no corresponding update record for the merged page. Therefore, the electronic device may update the number of first records in the merged record to 0 to indicate that there are no update records between the merged record and the merged page. For example, if the number of first records in merged record 1 is 2, then after the merged page is obtained, the number of first records in merged record 1 may be updated from 2 to 0.
[0032] S907. Receive an update request corresponding to the third page. It should be noted that there are two scenarios for executing steps S907-S909: Scenario 1: While executing steps S903-S905, the electronic device concurrently executes steps S907-S909; Scenario 2: After executing steps S903-S906, the electronic device sequentially executes steps S907-S909. In either scenario 1 or 2, the electronic device can receive an update request corresponding to the third page. For example, if the third page is page P2[400,700), the electronic device can receive update request 3 corresponding to page P2[400,700]. Update request 3 can be a request to add data corresponding to key value 650 to page P2[400,700].
[0033] S908. Generate a target update record corresponding to the third page. After receiving the update request corresponding to the third page, the electronic device may generate a target update record corresponding to the third page in memory based on the update request. The target update record may be the data increment record described in the embodiment of FIG. 2 . The target update record may include updated data for the third page. Optionally, the target update record may further include at least one of the following: a data increment count, a page fragment count, and a page size. It should be noted that the data increment count in the target update record is equal to the number of first records in the merged record plus one, as follows:
[0034] (1) If the number of the first record in the merged record has not yet been updated to 0 when the target update record corresponding to the third page is generated (i.e., Case 1), the data increment count in the target update record is the number of the first record + 1. For example, if the number of the first record in merged record 1 is 2, the data increment count in the target update record is 3.
[0035] (2) If the number of first records in the merged record has been updated to 0 when the target update record corresponding to the third page is generated (i.e., case 2), then the data increment count in the target update record is 1, i.e., the number of first records (0) + 1. » For example, if the third page is page P2[400,700), the electronic device may receive update request 3 corresponding to page P2[400,700), which is a request to add data corresponding to key value 650 to page P2[400,700). Then, the electronic device may generate update record 3, i.e., the target update record, according to update request 3. Update record 3 may include the updated data of the third page, i.e., the data corresponding to key value 650, a data increment count of 3, a page fragment count of 1, and a page size of 8KB.
[0036] S909. Add the memory address of the merged record to the target update record, and update the memory address corresponding to the merged record in the page mapping table corresponding to the disk to the memory address of the target update record. After generating the target update record corresponding to the third page, the electronic device may add the memory address of the merged record to the target update record so that the target update record is linked to the merged record. For example, if the electronic device generates update record 3 as the target update record, it may add the memory address of merged record 1 to update record 3 so that update record 3 is linked to merged record 1. Because in step S902, the electronic device has already updated the mapping corresponding to the third page identifier of the third page in the page mapping table corresponding to the disk to the memory address of the merged record in memory, after generating the target update record, it may update the memory address corresponding to the merged record in the page mapping table corresponding to the disk to the memory address of the target update record. For example, if the third page is page P2[400,700), and if the target update record is update record 3, the electronic device may update the memory address of merge record 1 to the memory address of update record 3 in the mapping entry corresponding to the third page identifier (i.e., page identifier 2) in the page mapping table. It should be noted that, in case 1, when S903-S905 and S907-S909 are executed concurrently and S906 is then executed sequentially, there is a case where step S908 is executed before S906. That is, there is a case where the first record quantity in merge record 1 is 2 and the data increment count in the target update record is 3. Therefore, after executing step S906 and updating the first record quantity in merge record 1 to 0, the data increment count in the target update record may be updated to 1, i.e., the first record quantity (0) + 1. In the embodiment of the present disclosure, the electronic device may receive a data merge request. Based on the data merge request, the electronic device may generate a merge record corresponding to the third page and mount the merge record on the third page. The electronic device may merge the third page and at least one update record to obtain a merged page, determine the memory address of the merged page, and then update the memory address of the second update record in the merged record to the memory address of the merged page. The electronic device may update the number of first records in the merged record to 0. The electronic device may receive an update request corresponding to the third page and generate a target update record corresponding to the third page. The electronic device may then add the memory address of the merged record to the target update record and update the memory address corresponding to the merged record in a page mapping table corresponding to the disk to the memory address of the target update record.Because a merge record can be generated and attached to the third page before merging the third page and the at least one update record, when the third page and the at least one update record are merged and concurrently updated, the newly generated target update record can be linked to the merge record. This prevents delays in updating the third page during the merge process, improving page processing efficiency. The update linking mechanism described above will be further described below using a specific example, based on the embodiment shown in FIG9 and in conjunction with FIG10. FIG10 is a schematic diagram of the update linking mechanism provided by an exemplary embodiment of the present disclosure. Referring to FIG10 , steps ①, ②, ③, ④, ⑤, and ⑦ are included. An electronic device may receive a data merge request 1. Data merge request 1 can be used to request the merging of page P2[400,700) and the corresponding update record 1 and update record 2. In step 1, the electronic device can generate a merge record 1 corresponding to page P2[400,700) in memory based on data merge request 1, and add the memory address 2 of update record 2 and the number of first records as 2 to merge record 1. In step 2, the electronic device can update the mapping content corresponding to the third page identifier (i.e., page identifier 2) in the page mapping table to the memory address of merge record 1. In step 3, the electronic device can merge page P2[400,700), update record 1, and update record 2 to obtain a merged page. Specifically, the electronic device can add data corresponding to key value 515 to page P2[400,700) based on update record 1, and add data corresponding to key value 455 to page P2[400,700) based on update record 2, to obtain a merged page. In step ④, the electronic device may determine the memory address of the merged page (i.e., the updated page P2[400,700)) and update the memory address 2 of update record 2 in merged record 1 to the memory address of the merged page. In step ⑤, the electronic device may update the first record quantity in merged record 1 from 2 to 0. If an update request corresponding to page P2[400,700) exists during steps ③, ④, and ⑤, the electronic device may execute steps ③ and ⑦ in parallel.In step ©, the electronic device may receive update request 3 corresponding to page P2[400,700), generate a target update record corresponding to page P2[400,700) according to update request 3, namely update record 3, and add the memory address of merge record 1 to update record 3. Update record 3 may include: the updated data for the third page, i.e., the data corresponding to key value 650, the memory address of merge record 1, a data increment count of 3, a page fragment count of 1, and a page size of 8KB. In step 7, the electronic device may update the memory address of merge record 1 to the memory address of update record 3 in the mapping entry corresponding to the third page identifier (i.e., page identifier 2) in the page mapping table. In an embodiment of the present disclosure, the electronic device may receive a data merge request. Based on the data merge request, the electronic device may generate a merge record corresponding to the third page and mount the merge record on the third page. The electronic device may merge the third page and at least one update record to obtain a merged page, determine the memory address of the merged page, and then update the memory address of the second update record to the memory address of the merged page in the merge record. The electronic device may update the number of first records to 0 in the merge record. The electronic device may receive an update request corresponding to the third page and generate a target update record corresponding to the third page. The electronic device may add the memory address of the merge record to the target update record, and in the page mapping table corresponding to the disk, The memory address corresponding to the merge record is updated to the memory address of the target update record. Because the merge record can be generated and mounted on the third page before merging the third page and the at least one update record, when the third page and the at least one update record are merged and concurrently updated, the newly generated target update record can be linked to the merge record. This ensures that the update to the third page is not delayed during the merge process, improving page processing efficiency. The technical solution of the present disclosure also provides a garbage collection method. The following describes the garbage collection method in conjunction with FIG11 . FIG11 is a schematic flow chart of a garbage collection method provided in an exemplary embodiment of the present disclosure. Referring to FIG11 , the method may include:
[0037] S1101. Determine at least one target data block to be garbage collected on the disk. Optionally, the electronic device may maintain a current garbage collection point (GCP). The GCP is the logical block number of the next data block to be collected, as recorded in the previous garbage collection, that is, the logical block number of the first data block to be garbage collected in this garbage collection. The first data block refers to the first data block to be collected in this garbage collection. It should be noted that during any garbage collection process, the GCP changes dynamically as the garbage collection progresses. Optionally, when the amount of free storage space on the disk is less than or equal to a first threshold, or when the garbage percentage on the disk is greater than or equal to a second threshold, the electronic device may execute the steps shown in FIG. 11 . Both the first and second thresholds may be preset. In an optional embodiment, the electronic device may determine the garbage percentage on the disk by: determining the valid data size V on the disk; determining the garbage size G on the disk; and determining the ratio of the garbage size G to the valid data size V as the garbage percentage K. Wherein, V and G are integers greater than or equal to 0, and K is a decimal between 0 and 1. Optionally, the electronic formula (1) is: Wherein, T represents the magnetic Represents the total size of historical invalid data. The total size of historical invalid data refers to the total size of all invalid data in multiple data blocks from the first data block stored on the disk to the latest data block currently flushed to disk. Formula (1) indicates that the logical block number of the latest data block flushed to disk * the size of a data block equals the total size of all data blocks previously stored on the disk. Subtracting the total size of historical invalid data gives the size of the valid data currently on the disk. For example, if the logical block number T of the latest data block flushed to the disk is 1000, the size B of a data block is 2 MB (megabytes), the current disk stores 750 data blocks corresponding to logical block numbers 251 to 1000, and the total size I of historical invalid data (i.e., the total size of all invalid data in the 1000 data blocks corresponding to logical block numbers 1 to 1000) is 1500 MB, then the size of valid data in the 750 data blocks currently on the disk can be determined to be 1000*2-1500=500 MB. Optionally, the electronic device can determine the garbage size G using the following formula (2):
[0038] G = I - (H - 1) * B Formula (2) Where I represents the total size of historical invalid data; H represents the logical block number of the first data block; and B represents the size of a data block. In Formula (2), (H - 1) * B represents the size of the multiple invalid data blocks preceding the first data block currently undergoing garbage collection. Formula (2) indicates that the total size of historical invalid data minus the size of the multiple invalid data blocks preceding the first data block equals the total size of garbage on the disk from the first data block to the latest flushed data block. The multiple data blocks preceding the first data block are all invalid data blocks (regardless of whether these multiple data blocks are currently on the disk). For example, if the logical block number T of the latest data block flushed to the disk is 1000, the size B of a data block is 2 MB, the total size I of historical invalid data (i.e., the total size of all invalid data in the 1000 data blocks corresponding to logical block numbers 1 to 1000) is 1500 MB, and the disk currently stores 750 data blocks corresponding to logical block numbers 251 to 1000, with the first data block having a logical block number of 280, then the garbage size G in the 720 data blocks with logical block numbers 280 to 1000 on the disk can be determined to be 1500-(280-1)*2=942 MB. Alternatively, the electronic device can determine the garbage percentage K using the following formula (3):
[0039] K = G / (V + G) Formula (3) Where G is the size of garbage on the disk; V is the size of valid data on the disk. For example, if G is 942MB and V is 500MB, then the garbage percentage K = 942 / (942 + 500) = 65%. For any data block, the data block may include multiple page fragments. For any data block, the data block has a corresponding logical block number. For example, if the logical block number of a data block is 005, the data block may be represented as data block 005. In an optional embodiment, at least one target data block to be garbage collected may be determined on the disk in the following manner: determining a first data block on the disk; determining a second data block on which data operations are being performed on the disk; and determining a data block between the first data block and the second data block on the disk as at least one target data block. It should be noted that the at least one target data block includes the first data block but does not include the second data block. Optionally, the electronic device may determine a garbage collection point and determine the first data block on the disk based on the garbage collection point. For example, if the garbage collection point is 280, data block 280 corresponding to logical block number 280 may be determined as the first data block on the disk. For example, the electronic device may determine that the second data block undergoing a data operation on the disk is data block 1001. If the first data block is data block 280, the electronic device may determine that the 720 data blocks between data blocks 280 and data block 1001 (i.e., data blocks 280, data block 281, ..., data block 1000) on the disk are the 720 target data blocks.
[0040] S1102: Determine valid page fragments in at least one target data block and store the valid page fragments in a buffer. In an optional embodiment, valid page fragments may be determined in at least one target data block in the following manner: determine the fragment status of each page fragment in the at least one target data block; and determine a page fragment in the at least one target data block that is in a valid state as a valid page fragment. For any page fragment, the fragment status of the page fragment may be either valid or invalid. On a disk, any page may correspond to multiple page fragments. Among these multiple page fragments, a later stored page fragment may include the storage address of an earlier stored page fragment. These multiple page fragments may form a page fragment chain corresponding to the page. Therefore, in an optional embodiment, for any page fragment, the electronic device may determine whether the page fragment is in the corresponding page fragment chain. If so, the fragment status of the page fragment is valid; if not, the fragment status of the page fragment is invalid. For example, assume that page P2 corresponds to P2 page fragment 0, P2 page fragment 1, and P2 page fragment 2. P2 page fragment 1 includes the storage address of P2 page fragment 0, and P2 page fragment 2 includes the storage address of P2 page fragment 1. Therefore, page fragment chain 1 corresponding to page P2 includes P2 page fragment 0, P2 page fragment 1, and P2 page fragment 2. For P2 page fragment 0, the electronic device can determine whether P2 page fragment 0 is in page fragment chain 1. If so, the fragment status of P2 page fragment 0 is valid; if not, the fragment status of P2 page fragment 0 is invalid. Optionally, the fragment status of the page fragments can be determined based on a page mapping table, which may include the following three cases: Case 1: If the mapping entry corresponding to the page identifier is empty, then the multiple page fragments corresponding to the page identifier are all invalid page fragments. Case 2: For a page that stores large data (this page can also be considered a page fragment), if the storage address in the mapping entry corresponding to the page identifier differs from the storage address of the page, the page is an invalid page fragment. If they are the same, the page is a valid page fragment. Case 3: For any page fragment, the fragment status of the page fragment is determined based on the storage address of the page fragment and the first storage address of the corresponding fourth page fragment.For any page fragment, the fragment status of the page fragment can be determined as follows: determining the fourth page corresponding to the page fragment, where the page fragment is obtained after flushing the fourth page to disk; determining the latest flush record corresponding to the fourth page, where the first storage address is the earliest flush address of the fourth page on disk; if the storage address of the page fragment is greater than or equal to the first storage address, determining the fragment status as valid; if the storage address of the page fragment is less than the first storage address, determining the fragment status as invalid. Since any page on a disk can correspond to multiple page fragments, the electronic device can determine the fourth page corresponding to the page fragment. Optionally, any flush record, data increment record, or stub record corresponding to the fourth page can include the first storage address corresponding to the fourth page, so the earliest flush record can include the first storage address corresponding to the fourth page. The first storage address is the earliest flush address of a currently valid fragment of the fourth page on disk. The electronic device can determine the latest flush record corresponding to the fourth page and determine the first storage address in the latest flush record. If the storage address of a page fragment is greater than or equal to the first storage address, it indicates that the page fragment was stored after the valid page fragment corresponding to the earliest valid first storage address, and the fragment status of the page fragment can be determined to be valid. If the storage address of a page fragment is less than the first storage address, it indicates that the page fragment was stored before the valid page fragment corresponding to the earliest valid first storage address, and the fragment status is determined to be invalid. For example, if the electronic device can determine that the fourth page corresponding to page fragment 0 is page P2, assuming that page P2 corresponds to P2 page fragment 0, P2 page fragment 1, and P2 page fragment 2, and if the latest disk flush record corresponding to page P2 is disk flush record 2, the electronic device can determine that the first storage address corresponding to page P2 in disk flush record 2 is storage address 1, assuming that storage address 1 is the storage address of P2 page fragment 1. For P2 page fragment 2, if the storage address of P2 page fragment 2 is greater than or equal to storage address 1, the fragment status of P2 page fragment 2 can be determined to be valid, and P2 page fragment 2 can be determined to be a valid page fragment. If the storage address of page fragment 0 is less than storage address 1, the fragment status of page fragment 0 can be determined to be invalid. For any target data block, the electronic device can determine a valid page fragment in the target data block and store the valid page fragment in the buffer.For example, if there are 720 target data blocks between data block 280 and data block 1001, the electronic device may determine two valid page fragments in data block 280 and copy the two valid page fragments to the buffer; may determine zero valid page fragments in data block 281; ...; may determine one valid page fragment in data block 1000 and copy the one valid page fragment to the buffer.
[0041] S1103: Delete at least one target data block from the disk. When the buffer is full, multiple page fragments in the buffer can be repackaged into a data block and stored on the disk. This data block can record the total size of historical invalid data and the corresponding logical block number. This data block can also record a data start point (DSP), which is the logical block number of the next data block to be recycled. After all valid page fragments in the at least one target data block are restored to the disk, the at least one target data block can be deleted. Specifically, when the data start point recorded in the most recently written data block on the disk is the logical block number of the last target data block, the at least one target data block can be deleted. For example, if the latest data block written to the disk is data block 1300, and the data starting point recorded in data block 1300 is 1001, this indicates that during this garbage collection, all valid page fragments in the 720 target data blocks between data blocks 280 and 1001 have been restored to the disk. Therefore, the electronic device can delete the 720 target data blocks between data blocks 280 and 1001 from the disk. It should be noted that the data starting point recorded in the data block is the current garbage collection point. For example, if during this garbage collection process, the data starting point recorded in data block 1300 is 1001, then during the next garbage collection, the electronic device can determine that the current garbage starting point is 1001 based on the data starting point 1001 and begin garbage collection from data block 1001. In an embodiment of the present disclosure, an electronic device can identify at least one target data block on a disk for garbage collection, identify valid page fragments within the at least one target data block, store the valid page fragments in a buffer, and delete the at least one target data block from the disk. The technical solution of the present disclosure eliminates the need to read metadata from all data blocks to determine invalid data to be deleted and valid data to be retained during garbage collection, thereby improving garbage collection efficiency. During operation, an electronic device may malfunction, resulting in an inability to read or write data according to an index tree, necessitating recovery processing. The technical solution of the present disclosure also provides a data recovery method. The data recovery method is described below with reference to FIG12 . FIG12 is a flow chart illustrating a data recovery method provided by an exemplary embodiment of the present disclosure. Referring to FIG12 , the method may include:
[0042] S1201: Determine the number of data blocks in the disk. For example, the electronic device may determine that the number of data blocks in the disk is 2000.
[0043] S1202: When the number of data blocks is greater than or equal to a preset number, store the page mapping table corresponding to the disk. Optionally, the preset number can be manually preset. For example, the preset number can be 1900. When the number of data blocks is greater than or equal to the preset number, the electronic device can store the page mapping table corresponding to the disk in a dedicated buffer. For example, if the number of data blocks is 2000 and the preset number is 1900, the electronic device can determine the currently used page mapping table in memory and store this page mapping table in the dedicated buffer. It should be noted that when storing the page mapping table in the dedicated buffer, the current page mapping table in memory is not stopped and may be continuously updated. Therefore, when the page mapping table stored in the dedicated buffer is completely stored, it may differ from some of the contents in the current page mapping table in memory. That is, the page mapping table stored in the dedicated buffer is a historical version of the current page mapping table in memory. When storing the page mapping table in the dedicated buffer based on the current page mapping table, the mapping contents included in the mapping entries in the current page mapping table are stored intact. The mapping content may include a pending allocation identifier, a pending deletion identifier, a confirmed allocation identifier, a confirmed deletion identifier, and a storage address, etc.
[0044] S1203: Determine the maximum page identifier in the page mapping table, the third data block that was most recently flushed to disk when the page mapping table was initially stored, and the fourth data block that was currently being operated on when the page mapping table was stored. For example, the electronic device may scan the page mapping table and determine that the maximum page identifier in the page mapping table is 30; determine that the third data block that was most recently flushed to disk when the page mapping table was initially stored on disk is data block 50; and determine that the fourth data block that was currently being operated on when the page mapping table was stored on disk is data block 60.
[0045] S1204: Generate and store check information based on the maximum page identifier, the third data block, and the fourth data block. The check information may include the maximum page identifier, the identifier of the third data block, and the identifier of the fourth data block. The identifiers of the third data block and the fourth data block both refer to logical block numbers. Optionally, in the check information, the identifier of the third data block may be determined as the recovery starting point, indicating that recovery should begin from the recovery starting point when fault recovery is required. The identifier of the fourth data block may be used as the maximum checkpoint block number, i.e., the recovery ending point when fault recovery is performed. Optionally, the electronic device may store the check information in a page mapping table already stored in the dedicated buffer. For example, based on the maximum page identifier of 30, the third data block being data block 50, and the fourth data block being data block 60, the electronic device may generate check information 1. Check information 1 may include the maximum page identifier of 30, the identifier of the third data block 50, and the identifier of the fourth data block 60. The electronic device may store check information 1 in page mapping table 1 already stored in the dedicated buffer. Optionally, the electronic device may save the page mapping table and the corresponding check information at different historical moments, and the page mapping table and the corresponding check information may have multiple versions. Generally, the latest version and the next latest version of the page mapping table and the corresponding check information may be retained.
[0046] S1205: When a disk failure is determined, obtain a page mapping table and check information. Optionally, since the electronic device can store the latest and second-latest versions of the page mapping table and check information, the electronic device can first obtain the latest version of the page mapping table and check information and perform disk failure recovery based on the latest version of the page mapping table and check information. If recovery fails, the electronic device can obtain the second-latest version of the page mapping table and check information and perform disk failure recovery based on the second-latest version of the page mapping table and check information. For example, the electronic device can obtain the latest version of page mapping table 1 and check information 1. Check information 1 may include a maximum page identifier 30, an identifier of the third data block 50, and an identifier of the fourth data block 60.
[0047] S1206: Perform disk failure recovery based on the page mapping table and the check information. Optionally, disk failure recovery can be performed in the following manner: determining the identifier of the third data block and the identifier of the fourth data block in the check information; determining, on the disk, the third data based on the identifier of the third data block and the fourth data based on the identifier of the fourth data block; loading at least one data block between the third data block and the fourth data block into a buffer, and updating the current page mapping table in the memory based on the multiple page fragments in the at least one data block. Optionally, there can be at least two buffers, and the at least two buffers can be used alternately. For example, if the electronic device determines, after checking information 1, that the identifier of the third data block is 50 and the identifier of the fourth data block is 60, the electronic device may determine that the third data block is data block 50 based on the identifier 50 of the third data block, and may determine that the fourth data block is data block 60 based on the identifier 60 of the fourth data block. The electronic device may load the 10 data blocks between data block 50 and data block 60 into a buffer and update the current page mapping table in the memory based on the multiple page fragments in the 10 data blocks. Optionally, for any page fragment, each page fragment has a corresponding page identifier. The electronic device may scan the page fragment and update the page mapping table based on the page fragment. This may include the following three cases: Case 1: If the page fragment includes a pending allocation identifier or a pending deletion identifier. In this case, since the page fragment includes the pending allocation identifier or the pending deletion identifier, it indicates that the page fragment has not yet been allocated or deleted. Therefore, the pending allocation identifier or the pending deletion identifier may be set in the mapping entry corresponding to the page identifier in the current page mapping table. Case 2: If the page fragment includes an allocation confirmation flag, and the mapping entry corresponding to the page identifier in the current page mapping table contains a pending allocation flag. In this case, since the page fragment already includes the allocation confirmation flag, the page fragment has already been allocated. Therefore, the pending allocation flag can be deleted from the mapping entry corresponding to the page identifier in the current page mapping table. Case 3: If the page fragment includes a deletion confirmation flag, and the mapping entry corresponding to the page identifier in the current page mapping table contains a pending deletion flag. In this case, since the page fragment already includes the deletion confirmation flag, the page fragment has already been marked with the deletion confirmation flag. Therefore, the pending deletion flag can be deleted from the mapping entry corresponding to the page identifier in the current page mapping table. It should be noted that each page in the index tree follows the page lifecycle shown in FIG. 13 , which is a schematic diagram of a page lifecycle provided by an exemplary embodiment of the present disclosure.Referring to Figure 13 , a page fragment containing a pending allocation or pending deletion flag typically precedes a page fragment containing the corresponding confirmed allocation or confirmed deletion flag. However, during garbage collection, a page fragment containing a pending allocation or pending deletion flag may be restored after the page fragment containing the corresponding confirmed allocation or confirmed deletion flag. Therefore, the following cases 4 and 5 are supplemented for updating the page mapping table: Case 4: If the page fragment contains a pending allocation flag, but the mapping content in the mapping entry corresponding to the page flag in the current page mapping table is not empty, the mapping content in the mapping entry corresponding to the page flag in the current page mapping table can be updated to the storage address of the page fragment, and the pending allocation flag can be ignored. Case 5: If the page fragment contains a pending deletion flag, but the mapping entry corresponding to the page flag in the current page mapping table is empty. In this case, no further processing is required. This is because when the page fragment contains a pending deletion flag, the mapping entry corresponding to the page flag in the current page mapping table is already set to empty. Optionally, after scanning multiple page fragments in at least one data block, the current mapping table in memory can be checked and updated again. This can include the following three cases: Case 1: If the mapping entry corresponding to the page identifier in the current mapping table is empty, this indicates that the page identifier is an idle page identifier, and the page identifier can be recycled. Case 2: If the mapping entry corresponding to the page identifier in the current mapping table includes a pending allocation flag. In this case, a pending deletion flag is set in the mapping entry corresponding to the page identifier. This is because, during fault recovery, data from a historical moment was restored, and the page's corresponding state was pending allocation at that moment. However, at the current moment, the page may no longer need to be allocated, so the pending deletion flag is set in the mapping entry corresponding to the page identifier. Case 3: If the mapping entry corresponding to the page identifier in the current mapping table includes a pending deletion flag, this indicates that the page fragment corresponding to the page identifier is ready for deletion. Therefore, the remaining page deletion operations can be performed on the page fragment. After the page deletion operations are completed and the page fragment is deleted, the page identifier is recycled. It should be noted that disk reading is also in progress during the fault recovery process. If the page fragment includes an index record, the index record can be loaded into memory for easy retrieval. If the page fragment includes a key-value pair, the stub record corresponding to the page fragment can be retained in memory to save memory space. Optionally, after successful fault recovery, the electronic device can reprocess the storage request. The electronic device can determine, among multiple storage requests, the first and second storage requests with duplicate LSNs.Since the first and second storage requests have duplicate content when the LSN numbers are duplicated, the electronic device can discard one of the storage requests and process the other. Optionally, when deleting a free page corresponding to a page identifier that exists in the page mapping table but is not referenced by the index tree, the electronic device can create a page fragment that records the total size of historical invalid data. Each time a free page is deleted, the electronic device can accumulate the total size of invalid data in the page fragment based on the size of the free page. In an embodiment of the present disclosure, the electronic device can determine the number of data blocks on the disk and, when the number of data blocks is greater than or equal to a preset number, store the corresponding page mapping table. The electronic device can determine the maximum page identifier in the page mapping table, the third data block that was most recently flushed to disk when the page mapping table began to be stored, and the fourth data block that was currently undergoing data operations when the page mapping table was stored. Based on the maximum page identifier, the third data block, and the fourth data block, the electronic device can generate and store check information. Upon determining a disk failure, the electronic device can retrieve the page mapping table and the check information and perform disk recovery based on the page mapping table and the check information. Because the electronic device can store the page mapping table and check information and perform fault recovery based on the page mapping table and check information, the success rate of fault recovery is improved. It should be noted that in the present disclosure, the various processing steps shown in any of the above embodiments do not constitute specific limitations on the method. Other embodiments of the present disclosure may include more or fewer steps than those in the corresponding embodiments. For example, the data storage process may include some of the steps in the embodiment of FIG. 4 , or some steps in the embodiment of FIG. 4 may be replaced by steps with the same functionality, or some steps in the embodiment of FIG. 4 may be split into multiple steps, etc. FIG. 14 is a first structural diagram of a data storage device provided in an exemplary embodiment of the present disclosure. Referring to Figure 14 , the data storage device 1400 may include a receiving module 1401, a creating module 1402, a storing module 1403, and a mounting module 1404. The receiving module 1401 is configured to receive a data storage request requesting storage of first data on a disk; the creating module 1402 is configured to create a first page corresponding to the first data if the data size of the first data is greater than or equal to a preset threshold; the storing module 1403 is configured to store the first data on the first page; and the mounting module 1404 is configured to mount the first page in an index tree corresponding to the disk. The data storage device provided in the embodiments of the present disclosure can implement the technical solutions shown in the above-described method embodiments. The implementation principles and beneficial effects thereof are similar and are not further described here.In one possible implementation, the mounting module 1404 is specifically configured to: determine a first main page corresponding to the first page in the index tree; update index-related information of the first page, update the page content of the first main page, and update index-related information of the first main page, so as to mount the first page in the index tree. In one possible implementation, the mounting module 1404 is specifically configured to: determine the storage address of the first page on the disk and a first key value corresponding to the first data; generate a first memory record corresponding to the first page, the first memory record including the first key value and the storage address of the first page on the disk; store a first page identifier of the first page and the memory address of the first memory record in a page mapping table corresponding to the disk; update the status of the first page in the page mapping table to a pending allocation status, the pending allocation status indicating that the first page is not mounted in the index tree. In one possible implementation, the mounting module 1404 is specifically configured to: generate a first index record based on the first key value corresponding to the first data and the first page identifier of the first page, the first index record including the first key value and the first page identifier; and add the first index record to the first main page. In one possible implementation, the mounting module 1404 is specifically configured to: generate a first disk write record corresponding to the first master page, the first disk write record including the memory address of the first master page and the storage address of the first master page on the disk; and update the memory address of the first master page to the memory address of the first disk write record in a page mapping table corresponding to the disk. The data storage device provided in the embodiments of the present disclosure can implement the technical solutions shown in the above-described method embodiments, and its implementation principles and beneficial effects are similar and will not be further described here. Figure 15 is a second structural schematic diagram of a data storage device provided in an exemplary embodiment of the present disclosure. Please refer to Figure 15. Based on the embodiment shown in Figure 14, the data storage device 1400 may further include: a processing module 1405 and an update module 1406, wherein the processing module 1405 is used to write the first master page to the disk according to the first disk write record; the update module 1406 is used to update the status corresponding to the first page in the first master page to a confirmed allocation status on the disk, wherein the confirmed allocation status is used to indicate that the first page has been mounted to the index tree; and the update module 1406 is used to update the status corresponding to the first page in the page mapping table to the confirmed allocation status.In one possible implementation, the data storage device 1400 may further include: a first determination module 1407 and a deletion module 1408, wherein the receiving module 1401 is further configured to receive a data deletion request requesting the deletion of second data corresponding to a second key value; the first determination module 1407 is configured to determine, in the index tree, a second page corresponding to the second data; and the deletion module 1408 is configured to delete the second page and index-related information from the index tree to delete the second data. In one possible implementation, the deletion module 1408 is specifically configured to: delete the second page; determine, in the index tree, a second main page corresponding to the second page; and update the page content and index-related information of the second main page. In one possible implementation, the deletion module 1408 is specifically configured to: if the second page has not been flushed to the disk, delete the second page and the second memory record corresponding to the second page from the memory corresponding to the disk; if the second page has been flushed to the disk, delete the second page from the memory and disk, respectively, and delete the second memory record from the memory; delete the memory address of the second memory record from the page mapping table corresponding to the disk, and update the status corresponding to the second page to a pending deletion state. In one possible implementation, the deletion module 1408 is specifically configured to: determine a second index record corresponding to the second page, the second index record including the second key value and the second page identifier of the second page; update the status corresponding to the second index record in the second main page to a confirmed deletion state. In one possible implementation, the deletion module 1408 is specifically configured to: generate a second flush record corresponding to the second main page, the second flush record including the storage address of the second main page on the disk; and update the memory address of the second main page in the page mapping table corresponding to the disk to the memory address of the second flush record. In a possible implementation, the updating module 1406 is further configured to: update, in the page mapping table, a state corresponding to the second page to a deletion confirmed state.In one possible embodiment, the data storage device 1400 may further include: a first generation module 1409 and a merging module 1410, wherein the receiving module 1401 is further configured to receive a data merge request, the data merge request being configured to merge a third page and at least one update record of the third page; the first generation module 1409 is configured to generate a merge record corresponding to the third page based on the data merge request; the mounting module 1404 is further configured to mount the merge record on the third page, the merge record being configured to mount the next update record of the third page; and the merging module 1410 is configured to merge the third page and the at least one update record to obtain a merged page. In one possible embodiment, the mounting module 1404 is specifically configured to: determine a second update record in the at least one update record, the second update record being the last update record in the at least one update record; add the memory address of the second update record to the merge record; and update the mapping corresponding to the third page identifier of the third page to the memory address of the merge record in a page mapping table corresponding to the disk. In one possible implementation, the first determination module 1407 is further configured to determine the memory address of the merged page; the update module 1406 is further configured to update the memory address of the second update record in the merged record to the memory address of the merged page. In one possible implementation, the first generation module 1409 is further configured to determine a first record quantity of the at least one update record; and increment the first record quantity in the merged record. In one possible implementation, the update module 1406 is further configured to update the first record quantity in the merged record to 0. In one possible implementation, the receiving module 1401 is further configured to receive an update request corresponding to the third page; the first generation module 1409 is further configured to generate a target update record corresponding to the third page; and the update module 1406 is further configured to increment the memory address of the merged record in the target update record, and to update the memory address of the merged record in the page mapping table corresponding to the disk to the memory address of the target update record.In one possible embodiment, the apparatus further includes: a second determination module 1411, configured to determine, on the disk, at least one target data block to be garbage collected, the target data block including multiple page fragments; the second determination module 1411 configured to determine valid page fragments in the at least one target data block; the storage module 1403 configured to store the valid page fragments in a buffer; and the deletion module 1408 configured to delete the at least one target data block from the disk. In one possible embodiment, the second determination module 1411 is specifically configured to: determine, on the disk, a first data block, the last data block of the last garbage collection; determine, on the disk, a second data block undergoing a data operation; and determine, on the disk, a data block between the first data block and the second data block as the at least one target data block. In one possible embodiment, the second determination module 1411 is specifically configured to: determine the fragment status of each page fragment in the at least one target data block, the fragment status being a valid state or an invalid state; and determine the page fragment in the at least one target data block in a valid state as the valid page fragment. In one possible embodiment, for any page fragment; the second determination module 1411 is specifically configured to: determine the fourth page corresponding to the page fragment, the page fragment being obtained after the fourth page is flushed to disk; determine the latest flush record corresponding to the fourth page, the latest flush record including the first storage address corresponding to the fourth page, the first storage address being the earliest valid flush address of the fourth page on the disk; if the storage address of the page fragment is greater than or equal to the first storage address, determine the fragment status as the valid state; if the storage address of the page fragment is less than the first storage address, determine the fragment status as the invalid state.In a possible implementation, the data storage device 1400 may further include: a third determination module 1412 and a second generation module 1413, wherein the third determination module 1412 is used to determine the number of data blocks in the disk; the storage module 1403 is further used to store a page mapping table corresponding to the disk when the number of data blocks is greater than or equal to a preset number; the third determination module 1412 is further used to determine a maximum page identifier in the page mapping table, a third data block that has been most recently flushed to the disk when storage of the page mapping table begins, and a fourth data block that is undergoing data operation when storage of the page mapping table is completed; the second generation module 1413 is used to generate, based on the maximum page identifier, the third data block, and the fourth data block, check information and store the check information, the check information including the maximum page identifier, the identifier of the third data block, and the identifier of the fourth data block. In one possible implementation, the data storage device 1400 may further include: an acquisition module 1414 and a recovery module 1415. The acquisition module 1414 is configured to, upon determining that the disk has failed, acquire the page mapping table and the check information; and the recovery module 1415 is configured to perform fault recovery on the disk based on the page mapping table and the check information. The data storage device provided in the embodiments of the present disclosure can implement the technical solutions described in the above-mentioned method embodiments. The implementation principles and beneficial effects are similar and will not be further described here. Figure 16 is a schematic diagram of the structure of an electronic device provided in an exemplary embodiment of the present disclosure. Referring to Figure 16, the electronic device 1600 may include a processor 1601 and a memory 1602. Exemplarily, the processor 1601 and the memory 1602 are interconnected via a bus 1603. The memory 1602 stores computer-executable instructions; the processor 1601 executes the computer-executable instructions stored in the memory 1602, causing the processor 1601 to perform the method described in the above-mentioned method embodiments. Accordingly, embodiments of the present disclosure provide a computer-readable storage medium storing computer-executable instructions. When executed by a processor, the computer-executable instructions are used to implement the methods described in the above method embodiments. Accordingly, embodiments of the present disclosure may also provide a computer program product, including a computer program. When executed by a processor, the computer program is used to implement the methods described in the above method embodiments. Those skilled in the art will appreciate that embodiments of the present disclosure may be provided as methods, systems, or computer program products.Therefore, the present disclosure may take the form of an entirely hardware embodiment, an entirely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present disclosure may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROMs, optical storage, etc.) containing computer-usable program code. The present disclosure is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present disclosure. It should be understood that each process and / or block in the flowcharts and / or block diagrams, as well as combinations of processes and / or blocks in the flowcharts and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, such that the instructions, executed by the processor of the computer or other programmable data processing device, produce means for implementing the functions specified in one or more processes in the flowcharts and / or one or more blocks in the block diagrams. These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means that implement the functions specified in one or more flow charts and / or one or more blocks in a block diagram. These computer program instructions may also be loaded onto a computer or other programmable data processing device, causing the computer or other programmable device to execute a series of operational steps to produce a computer-implemented process, whereby the instructions executed on the computer or other programmable device provide steps for implementing the functions specified in one or more flow charts and / or one or more blocks in a block diagram. In a typical configuration, a computing device includes one or more processors (CPUs), input / output interfaces, network interfaces, and memory. Memory may include non-permanent storage in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of a computer-readable medium. Computer-readable media include both permanent and non-permanent, removable and non-removable media, and may be implemented using any method or technology for information storage. The information may be computer-readable instructions, data structures, program modules, or other data.Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital versatile disc (DVD) or other optical storage, magnetic cassettes, magnetic disk storage or other magnetic storage devices, or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer-readable media does not include transitory media such as modulated data signals and carrier waves. It should also be noted that the terms "comprises," "comprising," or any other variations thereof are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that includes a list of elements may include not only those elements but also other elements not expressly listed or inherent to such process, method, article, or apparatus. In the absence of further restrictions, an element defined by the phrase "comprising a . . . . " does not preclude the presence of other identical elements in the process, method, commodity, or device comprising the element. The foregoing description is merely an embodiment of the present disclosure and is not intended to limit the present disclosure. Various modifications and variations are possible for those skilled in the art. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present disclosure shall be included within the scope of the claims of the present disclosure.
Claims
Claims 1. A data storage method, comprising: receiving a data storage request, wherein the data storage request is used to request to store first data in a disk; If the data size of the first data is greater than or equal to a preset threshold, creating a first page corresponding to the first data; storing the first data in the first page, and mounting the first page in an index tree corresponding to the disk.
2. The method according to claim 1, wherein mounting the first page in the index tree corresponding to the disk comprises: Determining a first main page corresponding to the first page in the index tree; The index-related information of the first page is updated, the page content of the first main page is updated, and the index-related information of the first main page is updated to mount the first page in the index tree.
3. The method according to claim 2, wherein updating the index-related information of the first page comprises: Determine a storage address of the first page in the disk and a first key value corresponding to the first data; generating a first memory record corresponding to the first page, wherein the first memory record includes the first key value and a storage address of the first page in the disk; The first page identifier of the first page and the memory address of the first memory record are correspondingly stored in the page mapping table corresponding to the disk; in the page mapping table, the state corresponding to the first page is updated to a pending allocation state, where the pending allocation state is used to indicate that the first page is not mounted to the index tree.
4. The method according to claim 2, wherein updating the page content of the first main page comprises: Generate a first index record according to a first key value corresponding to the first data and a first page identifier of the first page, where the first index record includes the first key value and the first page identifier; and add the first index record to the first main page.
5. The method according to any one of claims 2 to 4, wherein updating index-related information of the first home page comprises: Generate a first disk write record corresponding to the first master page, where the first disk write record includes a memory address of the first master page and a storage address of the first master page in the disk; In the page mapping table corresponding to the disk, the memory address of the first main page is updated to the memory address of the first disk-written record.
6. The method according to claim 5, further comprising: Writing the first master page to the disk according to the first write-to-disk record; In the disk, updating the state corresponding to the first page in the first main page to a confirmed allocation state, where the confirmed allocation state is used to indicate that the first page has been mounted to the index tree; In the page mapping table, the state corresponding to the first page is updated to the confirmed allocation state.
7. The method according to any one of claims 1 to 6, further comprising: receiving a data deletion request, the data deletion request being used to request deletion of second data corresponding to the second key value; Determining a second page corresponding to the second data in the index tree; The second page and index related information are deleted in the index tree to delete the second data.
8. The method according to claim 7, wherein deleting the second page and index-related information in the index tree comprises: Deleting the second page; Determining, in the index tree, a second main page corresponding to the second page; Update the page content and index-related information of the second main page.
9. The method according to claim 8, wherein deleting the second page comprises: If the second page is not written to the disk, deleting the second page and the second memory record corresponding to the second page in the memory corresponding to the disk; If the second page has been written to the disk, deleting the second page from the memory and the disk respectively, and deleting the second memory record from the memory; In the page mapping table corresponding to the disk, the memory address of the second memory record is deleted, and the state corresponding to the second page is updated to a pending deletion state.
10. The method according to claim 8 or 9, wherein updating the page content of the second main page comprises: Determine a second index record corresponding to the second page, wherein the second index record includes the second key value and the second page 26 Second page logo; In the second main page, the status corresponding to the second index record is updated to a deletion confirmation status.
11. The method according to claim 8 or 9, wherein updating index-related information of the second main page comprises: generating a second disk-written record corresponding to the second master page, wherein the second disk-written record includes a storage address of the second master page in the disk; In the page mapping table corresponding to the disk, the memory address of the second main page is updated to the memory address of the second disk-written record.
12. The method according to claim 10, further comprising: In the page mapping table, the state corresponding to the second page is updated to a deletion confirmation state.
13. The method according to any one of claims 1 to 12, further comprising: receiving a data merging request, the data merging request being used to request merging a third page and at least one updated record of the third page; generating a merge record corresponding to the third page according to the data merge request, and mounting the merge record on the third page, where the merge record is used to mount the next updated record of the third page; The third page and the at least one update record are merged to obtain a merged page.
14. The method according to claim 13, wherein mounting the merged record on the third page comprises: Determining a second update record in the at least one update record, where the second update record is the last update record in the at least one update record; Add the memory address of the second update record to the merge record; In the page mapping table corresponding to the disk, the mapping content corresponding to the third page identifier of the third page is updated to the memory address of the merged record.
15. The method according to claim 14, further comprising: merging the third page and the at least one update record to obtain a merged page; Determining the memory address of the merged page; In the merge record, the memory address of the second update record is updated to the memory address of the merged page.
16. The method according to any one of claims 13 to 15, after generating the merge record corresponding to the third page according to the data merge request, further comprising: Determining a first record quantity of the at least one updated record; The first record quantity is increased in the merged record.
17. The method according to claim 16, after merging the third page and the at least one update record to obtain a merged page, further comprising: In the merged record, the first record quantity is updated to 0.
18. The method according to any one of claims 13 to 17, further comprising: receiving an update request corresponding to the third page; Generating a target update record corresponding to the third page; The memory address of the merge record is added to the target update record, and in the page mapping table corresponding to the disk, the memory address of the merge record is updated to the memory address of the target update record.
19. The method according to any one of claims 1 to 18, further comprising: determining at least one target data block to be garbage collected in the disk, wherein the target data block includes a plurality of page fragments; determining valid page fragments in the at least one target data block, and storing the valid page fragments in a buffer; The at least one target data block is deleted from the disk.
20. The method according to claim 19, wherein determining at least one target data block to be garbage collected in the disk comprises: determining a first data block in the disk, wherein the first data block is the last data block of the last garbage collection; determining a second data block on which a data operation is being performed in the disk; and determining a data block between the first data block and the second data block in the disk as the at least one target data block.
21. The method according to claim 19 or 20, wherein determining a valid page fragment in the at least one target data block comprises: determining a fragment status of each page fragment in the at least one target data block, wherein the fragment status is a valid state or an invalid state; and determining a page fragment in a valid state in the at least one target data block as the valid page fragment.
22. The method according to claim 21, wherein for any page fragment, determining a fragment status of the page fragment in the at least one target data block comprises: determining a fourth page corresponding to the page fragment, where the page fragment is obtained after the fourth page is flushed to a disk; Determine the latest disk-written record corresponding to the fourth page, where the latest disk-written record includes a first storage address corresponding to the fourth page, and the first storage address is the earliest valid disk-written address of the fourth page in the disk; if the storage address of the page fragment is greater than or equal to the first storage address, determine that the fragment status is the valid state; if the storage address of the page fragment is less than the first storage address, determine that the fragment status is the invalid state.
23. The method according to any one of claims 1 to 22, further comprising: determining the number of data blocks in the disk; When the number of data blocks is greater than or equal to a preset number, storing a page mapping table corresponding to the disk; Determine the maximum page identifier in the page mapping table, the third data block that has been flushed to disk most recently when the page mapping table begins to be stored, and the fourth data block that is undergoing data operation when the page mapping table is stored; According to the maximum page identifier, the third data block, and the fourth data block, check information is generated and stored, where the check information includes the maximum page identifier, an identifier of the third data block, and an identifier of the fourth data block.
24. The method according to claim 23, further comprising: When determining that the disk fails, obtaining the page mapping table and the inspection information; Performing fault recovery processing on the disk according to the page mapping table and the check information.
25. A data storage device, comprising: A receiving module, a creating module, a storing module and a mounting module, wherein the receiving module is used to receive a data storage request, wherein the data storage request is used to request storage of first data in a disk; the creating module is used to create a first page corresponding to the first data if the data size of the first data is greater than or equal to a preset threshold; the storing module is used to store the first data in the first page; and the mounting module is used to mount the first page in an index tree corresponding to the disk.
26. An electronic device, comprising: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor to enable the electronic device to perform the method according to any one of claims 1 to 24.
27. A computer-readable storage medium storing computer-executable instructions, wherein when a processor executes the computer-executable instructions, the method according to any one of claims 1 to 24 is implemented.
28. A computer program product, comprising a computer program, wherein when the computer program is executed by a processor, the computer program implements the method according to any one of claims 1 to 24.
Citation Information
Patent Citations
Latch-free, log-structured storage for multiple access methods
CN105408895A
Metadata storage method and equipment thereof
CN113625938A
Data writing method and device and data reading method and device
CN114691612A
Tree data writing method and device, machine readable medium and memory
CN116880780A