Data storage method and device, electronic equipment and readable storage medium
By using a tree-structured index for storage tags and valid tags in data storage devices, the problem of dirty data caused by data storage device downtime is solved, improving read/write efficiency and user experience.
Patent Information
- Application Number
- CN202211555332.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-06
- Publication Date
- 2026-08-25
- Estimated Expiration
- 2042-12-06
AI Technical Summary
Existing data storage devices are prone to data incomplete writing due to sudden downtime during storage, resulting in dirty data that affects read/write efficiency and user experience.
By optimizing the data structure and using the storage tag and valid tag in the tree index structure, the storage location of the data to be stored is determined, and the availability of the data structure is checked after the storage device is recovered from a crash, thus avoiding reading data that has not been fully written and improving read and write efficiency.
This effectively prevents incomplete data from affecting the reading and writing of other data, improves the read and write efficiency of data storage devices, and enhances the user experience.
Smart Images

Figure CN115793976B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and in particular to data storage methods, apparatus, electronic devices, and readable storage media. Background Technology
[0002] In the process of storing data, the storage structure of data storage devices has a crucial impact on data reliability, read and write performance, and crash recovery.
[0003] During the process of storing data on a disk, data storage devices often encounter situations where they suddenly crash. Poor data storage structures can lead to incomplete data writing to the disk, making the data dirty. This can cause errors in reading and writing other data on the data storage device, reducing its read and write efficiency and the user experience. Summary of the Invention
[0004] This application provides a data storage method, apparatus, electronic device, and readable storage medium. By optimizing the data structure, it avoids dirty data from affecting the reading and writing of other data in the data storage device, thereby improving the reading and writing efficiency of the data storage device and enhancing the user experience.
[0005] In a first aspect, this application provides a data storage method applied to a data storage device, the method comprising:
[0006] Retrieve the data to be stored and the index value;
[0007] Based on the index value, the target leaf node is determined from the tree index structure. The target leaf node includes storage location information. The data structure of the storage location corresponding to the storage location information includes storage flag bit, valid flag bit, first data storage bit and second data storage bit. The storage flag bit is used to indicate whether the data structure is available. The valid flag bit is used to indicate whether the currently valid data storage bit is the first data storage bit or the second data storage bit. The first data storage bit and the second data storage bit are used to store data.
[0008] Based on the storage location information, the storage location of the data to be stored is determined, and the data to be stored is stored in the first data storage bit. The storage flag bit is set to available, and the valid flag bit is set to valid in the first data storage bit.
[0009] In conjunction with the first aspect, in some implementations of the first aspect, the above method further includes, before determining the target leaf node from the tree index structure:
[0010] If there is no leaf node corresponding to the index value in the tree index structure, add a leaf node in the tree index structure;
[0011] Store the index value and storage location information in the newly added leaf node.
[0012] In conjunction with the first aspect, in some implementations of the first aspect, after storing the data to be stored in the first data storage bit, the above method further includes:
[0013] The target leaf node is determined from the tree index structure based on the index value;
[0014] Based on the target leaf node, obtain the storage location information;
[0015] Based on the storage location information, determine the storage location of the data to be stored;
[0016] Retrieve the data structure from the storage location;
[0017] Determine whether a data structure is usable based on the storage flag bits in the data structure;
[0018] If the data structure is available, determine whether the currently valid data storage bit is the first data storage bit or the second data storage bit based on the valid flag bits in the data structure;
[0019] If the currently valid data storage bit is the first data storage bit, retrieve the data stored in the first data storage bit.
[0020] In conjunction with the first aspect, in some implementations of the first aspect, the data structure further includes: a write lock bit and / or a data bit length, wherein the write lock bit is used to indicate whether the data structure can be modified, and the data bit length is used to indicate the length of the data stored in the first data storage bit or the second data storage bit.
[0021] In conjunction with the first aspect, in some implementations of the first aspect, the above method also includes:
[0022] If the data stored in the data structure corresponding to the index value needs to be modified, the target leaf node is determined based on the index value;
[0023] Based on the target leaf node, obtain the storage location information;
[0024] Based on the storage location information, determine the storage location of the data to be stored;
[0025] Retrieve the data structure from the storage location;
[0026] Determine whether the data structure can be modified based on the write lock bit in the data structure;
[0027] If the data structure can be modified, determine whether the currently valid data storage bit is the first data storage bit or the second data storage bit based on the valid flag bits in the data structure;
[0028] If the currently valid data storage bit is the first data storage bit, the modified data will be stored in the second data storage bit, and the valid flag bit will be set to be valid for the second data storage bit.
[0029] In conjunction with the first aspect, in some implementations of the first aspect, the above method also includes:
[0030] If data stored in the data structure corresponding to the index value needs to be deleted, the target leaf node is determined based on the index value;
[0031] Based on the target leaf node, obtain the storage location information;
[0032] Based on the storage location information, determine the storage location of the data to be stored;
[0033] Retrieve the data structure from the storage location;
[0034] Set the storage flag and valid flag in the data structure to their initial state, delete the data in the first data storage bit and the second data storage bit, and delete the target leaf node from the tree index structure.
[0035] In conjunction with the first aspect, in some implementations of the first aspect, the tree index structure includes a root tree index structure and multiple subtree index structures, the target leaf node is located in one of the multiple subtree index structures, and the root tree index structure and the multiple subtree index structures are stored on different disks of the data storage device.
[0036] Secondly, this application provides another data storage device, including:
[0037] The acquisition module is used to acquire the data to be stored and the index value;
[0038] The processing module is used to determine the target leaf node from the tree index structure based on the index value. The target leaf node includes storage location information. The data structure of the storage location corresponding to the storage location information includes a storage flag bit, a valid flag bit, a first data storage bit, and a second data storage bit. The storage flag bit is used to indicate whether the data structure is available. The valid flag bit is used to indicate whether the currently valid data storage bit is the first data storage bit or the second data storage bit. The first data storage bit and the second data storage bit are used to store data. The module also determines the storage location of the data to be stored based on the storage location information, stores the data to be stored in the first data storage bit, sets the storage flag bit to be available, and sets the valid flag bit to be valid for the first data storage bit.
[0039] In conjunction with the second aspect, in some implementations of the second aspect, the processing module is also used to: before determining the target leaf node from the tree index structure, if there is no leaf node corresponding to the index value in the tree index structure, add a leaf node in the tree index structure; and store the index value and storage location information in the newly added leaf node.
[0040] In conjunction with the second aspect, in some implementations of the second aspect, the processing module is further configured to: after storing the data to be stored in the first data storage bit, determine the target leaf node from the tree index structure based on the index value;
[0041] The acquisition module is also used to: obtain storage location information based on the target leaf node;
[0042] The processing module is also used to: determine the storage location of the data to be stored based on the storage location information;
[0043] The acquisition module is also used to: retrieve data structures from storage locations;
[0044] The processing module is also used to: determine whether the data structure is available based on the storage flag bits in the data structure; if the data structure is available, determine whether the currently valid data storage bit is the first data storage bit or the second data storage bit based on the valid flag bits in the data structure;
[0045] The acquisition module is also used to: acquire the data stored in the first data storage bit when the currently valid data storage bit is the first data storage bit.
[0046] In conjunction with the second aspect, in some implementations of the second aspect, the above data structure further includes: a write lock bit and / or a data bit length, wherein the write lock bit is used to indicate whether the data structure can be modified, and the data bit length is used to indicate the length of the data stored in the first data storage bit or the second data storage bit.
[0047] In conjunction with the second aspect, in some implementations of the second aspect, the processing module is also used to: determine the target leaf node based on the index value when the data stored in the data structure corresponding to the index value needs to be modified;
[0048] The acquisition module is also used to: obtain storage location information based on the target leaf node;
[0049] The processing module is also used to: determine the storage location of the data to be stored based on the storage location information;
[0050] The acquisition module is also used to: retrieve data structures from storage locations;
[0051] The processing module is also used to: determine whether the data structure can be modified based on the write lock bit in the data structure; if the data structure can be modified, determine whether the currently valid data storage bit is the first data storage bit or the second data storage bit based on the valid flag bit in the data structure; and if the currently valid data storage bit is the first data storage bit, store the modified data in the second data storage bit and set the valid flag bit to be valid for the second data storage bit.
[0052] In conjunction with the second aspect, in some implementations of the second aspect, the processing module is also used to: determine the target leaf node based on the index value when the data stored in the data structure corresponding to the index value needs to be deleted;
[0053] The acquisition module is also used to: obtain storage location information based on the target leaf node;
[0054] The processing module is also used to: determine the storage location of the data to be stored based on the storage location information;
[0055] The acquisition module is also used to: retrieve data structures from storage locations;
[0056] The processing module is also used to: set the storage tag bit and valid tag bit in the data structure to the initial state, delete the data in the first data storage bit and the second data storage bit, and delete the target leaf node from the tree index structure.
[0057] In conjunction with the second aspect, in some implementations of the second aspect, the tree index structure includes a root tree index structure and multiple subtree index structures. The target leaf node is located in one of the multiple subtree index structures, and the root tree index structure and the multiple subtree index structures are stored on different disks of the data storage device.
[0058] Thirdly, this application provides an electronic device, comprising:
[0059] At least one processor and memory;
[0060] The memory stores computer-executed instructions;
[0061] The at least one processor executes computer execution instructions stored in the memory, causing the at least one processor to perform the data storage method as described in the first aspect above.
[0062] Fourthly, this application provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the data storage method described in the first aspect above.
[0063] The data storage method provided in this application determines the target leaf node from a tree index structure based on an index value. The target leaf node includes storage location information, and the data structure corresponding to the storage location includes a storage flag bit, a valid flag bit, a first data storage bit, and a second data storage bit. Based on the storage location information, the storage location of the data to be stored is determined, and the data to be stored is stored in the first data storage bit. The storage flag bit is set to available, and the valid flag bit is set to valid for the first data storage bit. After the storage device recovers from a crash, if the data to be stored is not completely written, the storage flag bit will be unavailable, indicating that the data structure is invalid. The storage device will not read data from this invalid data structure when reading data, avoiding incomplete data from affecting the reading and writing of other data in the data storage device, thus improving the read and write efficiency of the data storage device and enhancing the user experience. Attached Figure Description
[0064] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.
[0065] Figure 1 This is a schematic diagram illustrating an application scenario of a data storage method provided in an embodiment of this application;
[0066] Figure 2 A schematic flowchart illustrating a data storage method provided in an embodiment of this application;
[0067] Figure 3 This is a schematic diagram of a tree-like index structure provided in an embodiment of this application;
[0068] Figure 4 A schematic diagram of the structure of the data storage device provided in the embodiments of this application;
[0069] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application.
[0070] The accompanying drawings illustrate specific embodiments of this application, which will be described in more detail below. These drawings and descriptions are not intended to limit the scope of the concept in any way, but rather to illustrate the concept of this application to those skilled in the art through reference to particular embodiments. Detailed Implementation
[0071] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numbers in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this application. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this application as detailed in the appended claims.
[0072] In the process of storing data, the storage structure of data storage devices has a crucial impact on data reliability, read / write performance, and crash recovery. During the process of storing data on disks, data storage devices often face the risk of sudden crashes. A poor data storage structure can lead to incomplete data writing to the disk, rendering the data "dirty," causing errors in reading and writing other data on the data storage device, reducing read / write efficiency, and negatively impacting the user experience.
[0073] In view of this, this application proposes a data storage method. Based on an index value, a target leaf node is determined from a tree-like index structure. The target leaf node includes storage location information. The data structure corresponding to the storage location information includes a storage flag bit, a valid flag bit, a first data storage bit, and a second data storage bit. Based on the storage location information, the storage location of the data to be stored is determined, and the data to be stored is stored in the first data storage bit. The storage flag bit is set to available, and the valid flag bit is set to valid for the first data storage bit. After the storage device recovers from a crash, if the data to be stored is not completely written, the storage flag bit is at its initial value, indicating that the data structure is unavailable or invalid. When reading data, the storage device will not read data from the invalid data structure, avoiding the impact of incompletely written data on the reading and writing of other data in the data storage device, improving the read and write efficiency of the data storage device, and enhancing the user experience.
[0074] Figure 1 This is a schematic diagram illustrating an application scenario of a data storage method provided in an embodiment of this application. For example... Figure 1As shown, this application scenario includes a client 101, a server 104, and a data storage device 105. The client 101 is connected to the server 104 and can exchange data; the server 104 is connected to the data storage device 105. A business application can be deployed on the client 101, and the client 101 can send business data generated by the business application to the server 104. The server 104 deploys a backend application corresponding to the business application. After receiving the business data, the server 104 can process the data and send the data that needs to be saved to the data storage device 105. Correspondingly, after receiving the data that needs to be saved, the data storage device 105 can write the data to be saved into the memory of the data storage device 105.
[0075] In another possible implementation, the backend application corresponding to the aforementioned business application deployed on server 104 can be deployed on data storage device 105. Client 101 can send business data generated by the business application to data storage device 105, where data storage device 105 stores the business data.
[0076] Optionally, Figure 1 The number of clients in the application scenario shown can be multiple. For example, the application scenario also includes client 102 and client 103. This application embodiment does not limit the number of clients.
[0077] The technical solution of this application and how the technical solution of this application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments.
[0078] Figure 2 This is a flowchart illustrating a data storage method provided in an embodiment of this application. This data storage method 200 can be applied to the above-described... Figure 1 In the application scenario shown, this method can be... Figure 1 The data storage device 105 shown can perform the corresponding steps, but other physical devices such as servers and computers can also perform them. This embodiment does not impose specific restrictions on the specific product form and quantity of the executing entity. Figure 2 As shown, the method includes:
[0079] S201. Obtain the data to be stored and the index value.
[0080] It should be understood that the data storage device can generate an index value based on the acquired data to be stored. For example, if the information to be stored is order information, the data storage device can generate an index value (e.g., index value: 25) based on the order number in the order information.
[0081] S202. Based on the index value, determine the target leaf node from the tree index structure. The target leaf node includes storage location information. The data structure of the storage location corresponding to the storage location information includes a storage flag bit, a valid flag bit, a first data storage bit, and a second data storage bit. The storage flag bit is used to indicate whether the data structure is available. The valid flag bit is used to indicate whether the currently valid data storage bit is the first data storage bit or the second data storage bit. The first data storage bit and the second data storage bit are used to store data.
[0082] For example, the tree index structure can be a B+ tree, a B tree, etc., and this application does not limit it.
[0083] It should be understood that the target leaf node is the lowest node in the tree-like index structure. Data storage devices can determine the target leaf node according to the rules of the tree structure; for example, a data storage device can determine the target leaf node according to the rules of a B+ tree structure. The target leaf node may include storage location information and an index value.
[0084] It should be understood that data storage devices can find the location where the data to be stored can be stored based on the storage location information in the target leaf node.
[0085] The data structure of the storage location is the data structure when the data to be stored is stored at that storage location. This data structure may include storage tag bits, valid tag bits, first data storage bits, and second data storage bits.
[0086] For example, the value of the storage flag can be 0 or 1, where 0 indicates that the data structure is unavailable (i.e., invalid), and 1 indicates that the data structure is available (i.e., valid). The initial value of the storage flag can be 0.
[0087] For example, the value of the valid flag bit can be 0 or 1, where 0 indicates that the first data storage bit is valid, that is, the data stored in the first data storage bit is valid, and 1 indicates that the second data storage bit is valid, that is, the data stored in the second data storage bit is valid. The initial value of the valid flag bit can be 0.
[0088] It should be understood that the data to be stored can be stored in data storage bit 1 or data storage bit 2.
[0089] S203. Based on the storage location information, determine the storage location of the data to be stored, store the data to be stored in the first data storage bit, set the storage flag bit to available, and set the valid flag bit to valid for the first data storage bit.
[0090] For example, the data storage device stores the data to be stored in the first data storage bit of the data structure. After storage is completed, the value of the storage flag bit is modified to 1, indicating that the data structure where the data to be stored is available, and the value of the valid flag bit is modified to 0, indicating that the data stored in the first data storage bit is valid.
[0091] It should be understood that if the data storage device has not completely stored the data to be stored in the first data storage bit, the data storage device has not set the storage flag bit to be available. The storage flag bit is in its initial value, indicating that the data structure is unavailable.
[0092] The data storage method provided in this application determines the target leaf node from a tree index structure based on an index value. The target leaf node includes storage location information, and the data structure corresponding to the storage location includes a storage flag bit, a valid flag bit, a first data storage bit, and a second data storage bit. Based on the storage location information, the storage location of the data to be stored is determined, and the data to be stored is stored in the first data storage bit. The storage flag bit is set to available, and the valid flag bit is set to valid for the first data storage bit. After the storage device recovers from a crash, if the data to be stored is not completely written, the storage flag bit remains at its initial value, indicating that the data structure is unavailable. The storage device will not read data from this invalid data structure when reading data, thus preventing incompletely written data from affecting the reading and writing of other data in the data storage device, improving the read and write efficiency of the data storage device, and enhancing the user experience.
[0093] Optionally, before determining the target leaf node from the tree index structure, the above method further includes:
[0094] If there is no leaf node corresponding to the index value in the tree index structure, add a leaf node in the tree index structure;
[0095] Store the index value and storage location information in the newly added leaf node.
[0096] The method provided in this application provides an index for the data to be stored by adding leaf nodes and storing index values and storage location information in the added leaf nodes, which facilitates subsequent querying after the data to be stored is stored.
[0097] There are two ways to obtain storage location information:
[0098] In one possible implementation, the storage location information can be a free location selected by the data storage device, and the location information of that free location can be used as the storage location information.
[0099] In another possible implementation, the data to be stored can be stored in a free location in the data storage device (e.g., a free location on the disk of the data storage device) in the form of the data structure described above. The data storage device saves the location information of the free location to the newly added leaf node as storage location information.
[0100] It should be understood that the newly added leaf node can be the target leaf node.
[0101] It should be understood that the tree index structure after adding leaf nodes needs to satisfy the rules of the tree index structure. If the tree structure after adding leaf nodes cannot satisfy the rules of the tree index structure, the tree structure can be partially reorganized according to the rules of the tree index structure. For example, the tree index structure needs to satisfy the rules of the B+ tree. If the order of the B+ tree is m, each node in the B+ tree has at most m-1 child nodes, each node has at most m-1 values, and the m-1 values in each node are arranged in ascending order. The arranged values divide the child nodes into m intervals, and the value of each child node is within the interval of the parent node.
[0102] The data storage device can store the data to be stored using the method described above. Furthermore, the data storage device can perform data queries. The data to be queried can be the data to be stored in the data storage device using the method 200 described above, or it can be other data already stored in the data storage device; this application embodiment does not limit this.
[0103] The following example illustrates a method for querying data using a data storage device, taking the data to be queried as stored in the data storage device via method 200 described above. This method includes the following steps:
[0104] The target leaf node is determined from the tree index structure based on the index value;
[0105] Based on the target leaf node, obtain the storage location information;
[0106] Based on the storage location information, determine the storage location of the data to be stored;
[0107] Retrieve the data structure from the storage location;
[0108] Determine whether a data structure is usable based on the storage flag bits in the data structure;
[0109] If the data structure is available, determine whether the currently valid data storage bit is the first data storage bit or the second data storage bit based on the valid flag bits in the data structure;
[0110] If the currently valid data storage bit is the first data storage bit, retrieve the data stored in the first data storage bit.
[0111] The method provided in this application embodiment, when the data structure is available, determines whether the currently valid data storage bit is the first data storage bit or the second data storage bit through the valid flag bit in the data structure, so as to facilitate accurate querying of valid data in the current data structure.
[0112] It should be understood that the data storage device can generate an index value based on the information in the data to be queried. For example, if the data to be queried is order information, the data storage device can obtain the order number from the order information and generate an index value based on the order number.
[0113] For example, if the value of the storage flag bit in the data structure is 1, the data storage device determines that the data structure is available; if the value of the valid flag bit in the data structure is 0, the data storage device determines that the currently valid data storage bit is the first data storage bit, and retrieves the data stored in the first data storage bit as the query result.
[0114] For example, if the storage flag bit in the data structure is 0, the data storage device determines that the data structure is unavailable, returns that no data can be found, and deletes the target leaf node.
[0115] Optionally, the data structure may further include: a write lock bit and / or a data bit length, wherein the write lock bit is used to indicate whether the data structure can be modified, and the data bit length is used to indicate the length of the data stored in the first data storage bit or the second data storage bit.
[0116] For example, the write lock bit can be 0 or 1, where 0 indicates that the data structure is currently modifiable, and 1 indicates that the data structure is currently not modifiable. The initial value of the write lock bit can be 0.
[0117] It should be understood that the data length stored in the first data storage bit is the same as the data length stored in the second data storage bit, and the data bit length cannot be modified after the data structure is fixed. For example, the data to be stored is stored in the first data storage bit, and the data bit length of the data to be stored is 32. The empty data with a data bit length of 32 is stored in the second data storage bit.
[0118] The data storage device can perform data storage and data retrieval using the methods described above. Furthermore, the data storage device can modify data. The data to be modified can be the data to be stored in the data storage device via method 200, or it can be other data already stored in the data storage device; this application embodiment does not limit this.
[0119] The following example, using the data to be modified that was stored in the data storage device through the above method 200, illustrates the method for modifying data in a data storage device:
[0120] In one possible implementation, if the data stored in the data structure corresponding to the index value needs to be modified, the target leaf node is determined based on the index value.
[0121] Based on the target leaf node, obtain the storage location information;
[0122] Based on the storage location information, determine the storage location of the data to be stored;
[0123] Retrieve the data structure from the storage location;
[0124] Determine whether the data structure can be modified based on the write lock bit in the data structure;
[0125] If the data structure can be modified, determine whether the currently valid data storage bit is the first data storage bit or the second data storage bit based on the valid flag bits in the data structure;
[0126] If the currently valid data storage bit is the first data storage bit, the modified data will be stored in the second data storage bit, and the valid flag bit will be set to be valid for the second data storage bit.
[0127] The above embodiment can determine whether the data structure can be modified by writing a lock bit. Only if the data structure can be modified can the data in the data structure be modified, thus preventing the data in the data structure from being tampered with.
[0128] It should be understood that a data storage device can generate an index value based on information in the data to be modified. For example, if the data to be modified is order information, the data storage device obtains the order number from the order information, and can generate an index value based on that order number.
[0129] For example, if the write lock bit in the data structure is 0, the data storage device determines that the data structure can be modified. If the valid flag bit in the data structure is 0, the data storage device determines that the currently valid data storage bit is the first data storage bit. The data storage device stores the modified data into the second data storage bit and modifies the valid flag bit in the data structure to 1. 1 indicates that the data in the second data storage bit is valid.
[0130] For example, if the write lock bit in the data structure is 1, the data storage device determines that the data structure cannot be modified at present and is in a locked state. After the write lock bit becomes 0, that is, the data structure can be modified and is in an unlocked state, the data storage device determines that the currently valid data storage bit is the first data storage bit based on the value of the valid flag bit in the data structure being 0. The data storage device stores the modified data into the second data storage bit and modifies the valid flag bit in the data structure to 1, with 1 indicating that the data in the second data storage bit is valid.
[0131] It should be understood that if the modified data is not fully stored in the second data storage location, the data storage device will not modify the valid flag bits in that data structure. In other words, the modified data is not effective, and the valid flag bits in the data structure still indicate that the first data storage location is valid, meaning the original data is valid. The next time this data is queried, the original data will still be read.
[0132] In another possible implementation, if the data stored in the data structure corresponding to the index value needs to be modified, the target leaf node is determined based on the index value.
[0133] Based on the target leaf node, obtain the storage location information;
[0134] Based on the storage location information, determine the storage location of the data to be stored;
[0135] Retrieve the data structure from the storage location;
[0136] Determine whether the data structure can be modified based on the write lock bit in the data structure;
[0137] If the data structure can be modified, set the write lock bit to prevent modification of the data structure; based on the valid flag bit in the data structure, determine whether the currently valid data storage bit is the first data storage bit or the second data storage bit;
[0138] With the first data storage bit currently valid, the modified data will be stored in the second data storage bit, the valid flag bit will be set to be valid for the second data storage bit, and the write lock bit will be set to be able to modify the data structure.
[0139] For example, if the write lock bit in the data structure is 0, the data storage device determines that the data structure can be modified at present, sets the write lock bit to 1, and the valid flag bit in the data structure is 0, the data storage device determines that the currently valid data storage bit is the first data storage bit, the data storage device stores the modified data into the second data storage bit, modifies the valid flag bit in the data structure to 1, 1 indicates that the data in the second data storage bit is valid, and sets the write lock bit to 0.
[0140] For example, if the write lock bit in the data structure is set to 1, the data storage device determines that the data structure cannot be modified at present and is in a locked state. After the write lock bit becomes 0, indicating that the data structure can be modified and is in an unlocked state, the data storage device determines that the currently valid data storage bit is the first data storage bit based on the value of the valid flag bit in the data structure being 0. The data storage device then stores the modified data in the second data storage bit, modifies the valid flag bit in the data structure to 1, indicating that the data in the second data storage bit is valid, and sets the write lock bit to 0.
[0141] The above embodiments can prevent data storage devices from making different data modifications to the same data structure at the same time by writing lock bits, thus preventing concurrent writes from causing the inability to determine the valid data in the first data storage bit and the second data storage bit.
[0142] The data storage device can perform data storage, data retrieval, and data modification using the methods described above. Furthermore, the data storage device can delete data. The data to be deleted can be the data to be stored in the data storage device via method 200, or other data already stored in the data storage device; this application embodiment does not limit this.
[0143] The following example illustrates a method for data deletion using a data storage device, taking data to be deleted that has been stored in the data storage device via method 200 as an example. This method includes the following steps:
[0144] If data stored in the data structure corresponding to the index value needs to be deleted, the target leaf node is determined based on the index value;
[0145] Based on the target leaf node, obtain the storage location information;
[0146] Based on the storage location information, determine the storage location of the data to be stored;
[0147] Retrieve the data structure from the storage location;
[0148] Set the storage flag and valid flag in the data structure to their initial state, delete the data in the first data storage bit and the second data storage bit, and delete the target leaf node from the tree index structure.
[0149] The above embodiments can quickly locate the data structure where the data to be deleted is located by using the target leaf node, delete the data in the first and second data storage bits of the data structure, and delete the target leaf node, thereby freeing up the memory space of the data storage device and improving the effective storage memory of the data storage device.
[0150] It should be understood that data storage devices can generate index values based on information in the data to be deleted.
[0151] For example, the initial state of the storage flag bit and the valid flag bit in the data structure corresponds to a value of 0.
[0152] Optionally, the tree index structure includes a root tree index structure and multiple subtree index structures, with the target leaf node located in one of the multiple subtree index structures. The root tree index structure and the multiple subtree index structures are stored on different disks of the data storage device.
[0153] It should be understood that both root tree index structures and multiple subtree index structures can consist of a root node and multiple levels of child nodes. The leaf nodes of the root tree point to the subtrees, store the location information of the subtrees, and perform subtree routing.
[0154] For example, both the root tree index structure and the multiple subtree index structures can be B+ tree structures.
[0155] It should also be understood that the root tree index structure and multiple subtree index structures can be stored in the following ways:
[0156] In one possible implementation, the root tree index structure can be on one disk of the data storage device, while the multiple subtree index structures can be on other disks of the data storage device.
[0157] In another possible implementation, the root tree index structure and a portion of the subtree index structure can reside on one disk of the data storage device, while another portion of the multiple subtree index structures can reside on other disks of the data storage device.
[0158] The above embodiments split the traditional single tree structure into a root tree index structure and multiple subtree index structures, and can store the root tree index structure and multiple subtree index structures on different disks respectively, breaking the spatial limitation of data storage, enabling simultaneous reading and writing on multiple disks, and the read and write performance of multiple disks does not affect each other, thus improving the read and write efficiency of data storage devices.
[0159] The following is combined Figure 3 This section introduces the tree-based index structure. Figure 3The tree-like index structure includes a root tree index structure, a subtree 1 index structure, and a subtree 2 index structure. The root tree index structure includes a root node, root leaf node 1, and root leaf node 2. Root leaf node 1 points to the subtree 1 index structure, and root leaf node 2 points to the subtree 2 index structure. The subtree 1 index structure is a 3-order B+ tree structure, where each node has at most two child nodes. The root node of subtree 1 has child nodes 1 and 2, child node 1 has leaf nodes 1 and 2, and child node 2 has a leaf node 3. The subtree 2 index structure is also a 3-order B+ tree structure, where each node has at most two child nodes. The root node of subtree 2 has child nodes 3 and 4, child node 3 has leaf nodes 4 and 5, and child node 4 has a leaf node 6.
[0160] Figure 4 This is a schematic diagram of a data storage device provided in an embodiment of this application. Figure 4 As shown, the data storage device 400 includes an acquisition module 401 and a processing module 402.
[0161] Module 401 is used to obtain the data to be stored and the index value;
[0162] Processing module 402 is used to determine a target leaf node from a tree index structure based on an index value. The target leaf node includes storage location information. The data structure of the storage location corresponding to the storage location information includes a storage flag bit, a valid flag bit, a first data storage bit, and a second data storage bit. The storage flag bit is used to indicate whether the data structure is available. The valid flag bit is used to indicate whether the currently valid data storage bit is the first data storage bit or the second data storage bit. The first data storage bit and the second data storage bit are used to store data. Based on the storage location information, the processing module 402 determines the storage location of the data to be stored, stores the data to be stored in the first data storage bit, sets the storage flag bit to be available, and sets the valid flag bit to be valid for the first data storage bit.
[0163] Optionally, the processing module 402 is further configured to: before determining the target leaf node from the tree index structure, if there is no leaf node corresponding to the index value in the tree index structure, add a leaf node in the tree index structure; and store the index value and storage location information in the newly added leaf node.
[0164] Optionally, the processing module 402 is further configured to: after storing the data to be stored in the first data storage location, determine the target leaf node from the tree index structure based on the index value;
[0165] The acquisition module 401 is also used to: acquire storage location information based on the target leaf node;
[0166] The processing module 402 is also used to: determine the storage location of the data to be stored based on the storage location information;
[0167] The acquisition module 401 is also used to: acquire data structures from storage locations;
[0168] The processing module 402 is also used to: determine whether the data structure is available based on the storage tag bit in the data structure; if the data structure is available, determine whether the currently valid data storage bit is the first data storage bit or the second data storage bit based on the valid tag bit in the data structure;
[0169] The acquisition module 401 is also used to: acquire the data stored in the first data storage bit when the currently valid data storage bit is the first data storage bit.
[0170] Optionally, the above data structure further includes: a write lock bit and / or a data bit length, wherein the write lock bit is used to indicate whether the data structure can be modified, and the data bit length is used to indicate the length of the data stored in the first data storage bit or the second data storage bit.
[0171] Optionally, the processing module 402 is further configured to: determine the target leaf node based on the index value when the data stored in the data structure corresponding to the index value needs to be modified;
[0172] The acquisition module 401 is also used to: acquire storage location information based on the target leaf node;
[0173] The processing module 402 is also used to: determine the storage location of the data to be stored based on the storage location information;
[0174] The acquisition module 401 is also used to: acquire data structures from storage locations;
[0175] The processing module 402 is also used to: determine whether the data structure can be modified based on the write lock bit in the data structure; if the data structure can be modified, determine whether the currently valid data storage bit is the first data storage bit or the second data storage bit based on the valid flag bit in the data structure; and if the currently valid data storage bit is the first data storage bit, store the modified data in the second data storage bit and set the valid flag bit to be valid for the second data storage bit.
[0176] Optionally, the processing module 402 is further configured to: determine the target leaf node based on the index value when the data stored in the data structure corresponding to the index value needs to be deleted;
[0177] The acquisition module 401 is also used to: acquire storage location information based on the target leaf node;
[0178] The processing module 402 is also used to: determine the storage location of the data to be stored based on the storage location information;
[0179] The acquisition module 401 is also used to: acquire data structures from storage locations;
[0180] The processing module 402 is also used to: set the storage tag bit and the valid tag bit in the data structure to the initial state, delete the data in the first data storage bit and the second data storage bit, and delete the target leaf node from the tree index structure.
[0181] Optionally, the tree index structure includes a root tree index structure and multiple subtree index structures, with the target leaf node located in one of the multiple subtree index structures. The root tree index structure and the multiple subtree index structures are stored on different disks of the data storage device.
[0182] The data storage device 400 provided in this application embodiment is applicable to the above method embodiment, and will not be described again here.
[0183] This application also provides an electronic device 500, such as... Figure 5 As shown, Figure 5 The illustrated electronic device includes a processor 501 and a memory 502. The processor 501 and the memory 502 are connected, for example, via a bus 503. Optionally, the electronic device may also include a transceiver. It should be noted that in practical applications, the transceiver is not limited to one unit, and the structure of this electronic device does not constitute a limitation on the embodiments of this application.
[0184] Processor 501 may be a CPU (Central Processing Unit), a general-purpose processor, a DSP (Digital Signal Processor), an ASIC (Application Specific Integrated Circuit), an FPGA (Field Programmable Gate Array), or other programmable logic devices, transistor logic devices, hardware components, or any combination thereof. It can implement or execute the various exemplary logic blocks, modules, and circuits described in conjunction with the disclosure of this application. Processor 501 may also be a combination that implements computational functions, such as including one or more microprocessor combinations, a combination of a DSP and a microprocessor, etc.
[0185] Bus 503 may include a pathway for transmitting information between the aforementioned components. Bus 503 may be a PCI (Peripheral Component Interconnect) bus 503 or an EISA (Extended Industry Standard Architecture) bus 503, etc. Bus 503 can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 5 The bus 503 is represented by only one thick line, but this does not mean that there is only one bus 503 or only one type of bus 503.
[0186] The memory 502 may be a ROM (Read Only Memory) or other type of static storage device capable of storing static information and instructions, RAM (Random Access Memory) or other type of dynamic storage device capable of storing information and instructions, or an EEPROM (Electrically Erasable Programmable Read Only Memory), CD-ROM (Compact Disc Read Only Memory) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital universal optical discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but not limited thereto.
[0187] The memory 502 is used to store application code that executes the solution of this application, and its execution is controlled by the processor 501. The processor 501 is used to execute the application code stored in the memory 502 to implement the content shown in the foregoing method embodiments.
[0188] Electronic devices include, but are not limited to: mobile terminals such as mobile phones, laptops, digital radio receivers, PDAs (personal digital assistants), PADs (tablet computers), PMPs (portable multimedia players), and in-vehicle terminals (such as in-vehicle navigation terminals), as well as fixed terminals such as digital TVs and desktop computers. Servers can also be included. Figure 5 The electronic device shown is merely an example and should not be construed as limiting the functionality and scope of the embodiments disclosed herein.
[0189] This application provides a computer-readable storage medium storing a computer program that, when run on a computer, enables the computer to execute the corresponding content in the foregoing method embodiments.
[0190] This application also provides a computer program product, which includes a computer program (also referred to as code or instructions) that, when run on a computer, allows the computer to execute the corresponding content in the above method embodiments.
[0191] Other embodiments of this application will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of this application that follow the general principles of this application and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this application are indicated by the claims.
[0192] It should be understood that this application is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this application is limited only by the appended claims.
Claims
1. A data storage method, characterized in that, Applied to a data storage device, the method includes: Retrieve the data to be stored and the index value; Based on the index value, a target leaf node is determined from the tree index structure. The target leaf node includes storage location information. The data structure of the storage location corresponding to the storage location information includes a storage flag bit, a valid flag bit, a first data storage bit, and a second data storage bit. The storage flag bit is used to indicate whether the data structure is available. The valid flag bit is used to indicate whether the currently valid data storage bit is the first data storage bit or the second data storage bit. The first data storage bit and the second data storage bit are used to store data. Based on the storage location information, the storage location of the data to be stored is determined, and the data to be stored is stored in the first data storage bit. After the data to be stored is completely written into the first data storage bit, the storage flag bit is set to available, and the valid flag bit is set to valid for the first data storage bit. The initial state of the storage flag bit is unavailable. If the storage flag bit is unavailable when the system recovers from a crash, the data structure is determined to be invalid, and the data in the first data storage bit and the second data storage bit are not read.
2. The method according to claim 1, characterized in that, Prior to determining the target leaf node from the tree index structure, the method further includes: If there is no leaf node corresponding to the index value in the tree index structure, a new leaf node is added to the tree index structure; The index value and the storage location information are stored in the newly added leaf node.
3. The method according to claim 1, characterized in that, After storing the data to be stored in the first data storage bit, the method further includes: Based on the index value, the target leaf node is determined from the tree index structure; Based on the target leaf node, obtain the storage location information; Based on the storage location information, the storage location of the data to be stored is determined; Obtain the data structure from the storage location; Based on the storage tag bits in the data structure, determine whether the data structure is usable; If the data structure is available, based on the valid flag bits in the data structure, determine whether the currently valid data storage bit is the first data storage bit or the second data storage bit; If the first data storage bit is currently the only valid data storage bit, retrieve the data stored in the first data storage bit.
4. The method according to claim 1, characterized in that, The data structure further includes: a write lock bit and / or a data bit length, wherein the write lock bit is used to indicate whether the data structure can be modified, and the data bit length is used to indicate the length of the data stored in the first data storage bit or the second data storage bit.
5. The method according to claim 4, characterized in that, The method further includes: If the data stored in the data structure corresponding to the index value needs to be modified, the target leaf node is determined based on the index value; Based on the target leaf node, obtain the storage location information; Based on the storage location information, the storage location of the data to be stored is determined; Obtain the data structure from the storage location; Based on the write lock bit in the data structure, determine whether the data structure can be modified; If the data structure can be modified, based on the valid flag bits in the data structure, determine whether the currently valid data storage bit is the first data storage bit or the second data storage bit; If the first data storage bit is currently the valid data storage bit, the modified data is stored in the second data storage bit, and the valid flag bit is set to be valid for the second data storage bit.
6. The method according to claim 1, characterized in that, The method further includes: If the data stored in the data structure corresponding to the index value needs to be deleted, the target leaf node is determined based on the index value; Based on the target leaf node, obtain the storage location information; Based on the storage location information, the storage location of the data to be stored is determined; Obtain the data structure from the storage location; Set the storage flag bit and valid flag bit in the data structure to the initial state, delete the data in the first data storage bit and the second data storage bit, and delete the target leaf node from the tree index structure.
7. The method according to any one of claims 1 to 6, characterized in that, The tree-like index structure includes a root tree index structure and multiple subtree index structures. The target leaf node is located in one of the multiple subtree index structures. The root tree index structure and the multiple subtree index structures are stored on different disks of the data storage device.
8. A data storage device, characterized in that, include: The acquisition module is used to acquire the data to be stored and the index value; The processing module is configured to determine a target leaf node from a tree-like index structure based on the index value. The target leaf node includes storage location information. The data structure of the storage location corresponding to the storage location information includes a storage flag bit, a valid flag bit, a first data storage bit, and a second data storage bit. The storage flag bit is used to indicate whether the data structure is available. The valid flag bit is used to indicate whether the currently valid data storage bit is the first data storage bit or the second data storage bit. The first data storage bit and the second data storage bit are used to store data. Furthermore, based on the storage location information, the module determines the storage location of the data to be stored. After the data to be stored is completely written into the first data storage bit, the module stores the data to be stored in the first data storage bit, sets the storage flag bit to be available, and sets the valid flag bit to be valid for the first data storage bit. The initial state of the storage flag bit is unavailable. If the storage flag bit is unavailable during system recovery from a crash, the data structure is determined to be invalid, and data in the first data storage bit and the second data storage bit are not read.
9. An electronic device, characterized in that, include: At least one processor and memory; The memory stores computer-executed instructions; The at least one processor executes computer execution instructions stored in the memory, causing the at least one processor to perform the data storage method as described in any one of claims 1-7.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the data storage method as described in any one of claims 1-7.
11. A computer program product, characterized in that, The computer program product includes a computer program that, when executed by a processor, implements the data storage method according to any one of claims 1-7.
Citation Information
Patent Citations
Memory space management method and device
CN107229429A
Data read-write method and device
CN111857600A