Storage method, storage device and storage system

By determining the merge layer, reorganizing data blocks and controlling their byte size in RocksDB, the write amplification problem caused by changes in data blocks during the compression process is solved, achieving more efficient storage and access performance.

CN113688096BActive Publication Date: 2024-08-23SAMSUNG (CHINA) SEMICONDUCTOR CO LTD +1
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202110799890.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-07-15
Publication Date
2024-08-23
Estimated Expiration
2041-07-15

AI Technical Summary

Technical Problem

Changes in data blocks during the compression process of RocksDB will affect the composition of subsequent data blocks, resulting in the overwriting of a large amount of existing data, increasing write amplification, and affecting performance.

Method used

By determining the layers to be merged in the database, read and reorganize the data blocks, control the byte size of the data blocks within a certain range, avoid duplication caused by fixed-size data blocks, and use variable-length data block storage methods to refine The granularity of the Compaction process.

Benefits of technology

It reduces unnecessary operations and IO consumption, reduces write amplification, improves write performance, ensures that the size of data blocks and files is within a reasonable range, and avoids performance degradation caused by changes in data blocks.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113688096B
    Figure CN113688096B
Patent Text Reader

Abstract

Disclosed are a storage method, a storage device and a storage system. The storage method comprises: determining a layer to be merged in a database; determining a data block to be modified based on a file of the layer to be merged in the database; reading a corresponding data block in a memory according to a key corresponding to the data block to be modified and reorganizing the read data block; when the byte size of the reorganized data block does not exceed a first preset value, replacing the data block to be modified in the memory with the reorganized data block; and storing the key and statistical information of the reorganized data block in a file corresponding to the database.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to data storage technology, and more particularly, to a storage method, a storage device, and a storage system. Background Art

[0002] Currently, storing and accessing hundreds of petabytes of data is a very big challenge. The open source RocksDB is a database used to store and access hundreds of petabytes of data. RocksDB is Facebook's open storage database, which is an embedded key-value (KV) database written in C++. RocksDB uses the Log Structured Merge (LSM) storage engine to store data. The data exists in the form of sorted sequence table (SST) files on the storage device.

[0003] However, in RocksDB in the related technology, if a data block changes during the compression process, it will affect the data composition of the subsequent data blocks in the SST file, and even affect the data composition of the data blocks of the next file, resulting in the duplication of a large amount of existing and unchanged data, greatly increasing the write amplification. Summary of the invention

[0004] The present disclosure provides a storage method, a storage device and a storage system to at least solve the above-mentioned problems in the related art.

[0005] According to one aspect of the present disclosure, a storage method is provided, including: determining a layer to be merged in a database; determining a data block to be modified based on a file of the layer to be merged in the database; reading a corresponding data block in a memory according to a key corresponding to the data block to be modified and reorganizing the read data block; when the byte size of the reorganized data block does not exceed a first preset value, replacing the data block to be modified in the memory with the reorganized data block; and storing the key and statistical information of the reorganized data block in a file corresponding to the database.

[0006] Optionally, the method further includes: when the byte size of the reorganized data block exceeds a first preset value, splitting the reorganized data block according to the first preset value; replacing the data block to be modified in the memory with the split data block; storing the key and statistical information of the reorganized data block in a file corresponding to the database includes: storing the key and statistical information of the split data block in a file corresponding to the database. Through this embodiment, it is ensured that the byte size of a data block will not be too large.

[0007] Optionally, after storing the keys and statistical information of the reorganized data blocks in the files corresponding to the database, the method further includes: determining whether the byte size of all data blocks of the corresponding file exceeds a second preset value; if the determination result is yes, splitting the corresponding file according to the second preset value, and storing the keys and statistical information of the reorganized data blocks and the keys and statistical information of the unmodified data blocks of the corresponding file in the split files in the order of keys; if the determination result is no, storing the keys and statistical information of the reorganized data blocks in the corresponding files. Through this embodiment, it is ensured that the byte size of the total data blocks corresponding to a file will not be too large.

[0008] Optionally, determining the layers to be merged in the database includes: detecting an increase in files in the database; obtaining the byte size of each layer in the database; taking the layer whose byte size exceeds the byte threshold of the corresponding layer as the previous layer; and determining the previous layer and the next layer as the layers to be merged, wherein the next layer is the next layer adjacent to the previous layer. Through this embodiment, the compaction operation can be triggered conveniently and quickly.

[0009] Optionally, detecting that a file in the database is increased includes: when a byte size of the written data exceeds a first predetermined threshold, determining that the file in the database is increased.

[0010] Optionally, determining the data block to be modified based on the file of the layer to be merged includes: obtaining the file with the largest file bytes and a predetermined file in the previous layer of the layer to be merged, wherein the predetermined file is a file in the previous layer containing the user key of the file with the largest file bytes, and the user key is contained in the key of the data block of the file; obtaining the user key range based on the user key of the file with the largest file bytes and the user key of the predetermined file; obtaining the data block in the next layer of the layer to be merged where the user key and the user key range overlap, and obtaining the data block in the previous layer of the layer to be merged where the user key and the user key range overlap; determining the overlapping data block as the data block to be modified. Through this embodiment, the data block to be modified is determined based on the overlap of user keys, which reduces the reorganization of irrelevant data blocks during the reorganization process.

[0011] Optionally, reading corresponding data blocks in a memory according to keys corresponding to data blocks to be modified and reorganizing the read data blocks includes: reading corresponding data blocks in a memory according to user keys corresponding to data blocks to be modified, wherein the user keys are included in the keys of the data blocks; filtering out data corresponding to the maximum sequence number corresponding to each user key from the corresponding data blocks, wherein the sequence number is included in the keys of the data blocks and is used to indicate the order in which the same user key appears; and sorting the filtered data according to the user keys as reorganized data blocks.

[0012] According to another aspect of the exemplary embodiment of the present disclosure, there is provided a storage device, including: a first determination unit, for determining a layer to be merged in a database; a second determination unit, for determining a data block to be modified based on a file of the layer to be merged; a reorganization unit, for reading a corresponding data block in a memory according to a key corresponding to the data block to be modified and reorganizing the read data block; a replacement unit, for replacing the data block to be modified in the memory with the reorganized data block when the byte size of the reorganized data block does not exceed a first preset value; and a writing unit, for storing the key and statistical information of the reorganized data block into a file corresponding to the database.

[0013] Optionally, the replacement unit is also used to split the reorganized data block according to the first preset value when the byte size of the reorganized data block exceeds the first preset value; replace the data block to be modified in the memory with the split data block; the writing unit is also used to store the key and statistical information of the split data block into the file corresponding to the database.

[0014] Optionally, the writing unit is also used to determine whether the byte size of all data blocks of the corresponding file exceeds a second preset value after storing the keys and statistical information of the reorganized data blocks in the file corresponding to the database; when the judgment result is yes, split the corresponding file according to the second preset value, and store the keys and statistical information of the reorganized data blocks and the keys and statistical information of the unmodified data blocks of the corresponding file in the split files in the order of the keys; when the judgment result is no, store the keys and statistical information of the reorganized data blocks in the corresponding files.

[0015] Optionally, the first determination unit is also used to detect the increase of files in the database; obtain the byte size of each layer in the database; take the layer in each layer whose byte size exceeds the byte threshold of the corresponding layer as the previous layer; determine the previous layer and the next layer as the layers to be merged, wherein the next layer is the next layer adjacent to the previous layer.

[0016] Optionally, the first determining unit is further configured to determine that a file in the database is increased when the byte size of the written data exceeds a first predetermined threshold.

[0017] Optionally, the second determination unit is further used to obtain the file with the largest file bytes and a predetermined file in the previous layer of the layer to be merged, wherein the predetermined file is a file in the previous layer containing the user key of the file with the largest file bytes, and the user key is contained in the key of the data block in the file; based on the user key of the file with the largest file bytes and the user key of the predetermined file, a user key range is obtained; data blocks in the next layer of the layer to be merged where the user key overlaps with the user key range, and data blocks in the previous layer of the layer to be merged where the user key overlaps with the user key range; and the overlapping data blocks are determined as the data blocks to be modified.

[0018] Optionally, the reorganization unit is further used to read a corresponding data block in the memory according to a user key corresponding to the data block to be modified, wherein the user key is included in the key of the data block; filter out data corresponding to the maximum sequence number corresponding to each user key from the corresponding data block, wherein the sequence number is included in the key of the data block and is used to indicate the order in which the same user key appears; and sort the filtered data according to the user key as the reorganized data block.

[0019] According to another aspect of the exemplary embodiment of the present disclosure, a storage system is provided, comprising: a memory, a database, and a storage device as described in the above embodiments, wherein the memory is used to store data blocks and reorganized data blocks, and the database is used to store keys and statistical information of data blocks, and keys and statistical information of reorganized data blocks.

[0020] According to another aspect of the present disclosure, a computer-readable storage medium storing a computer program is provided, wherein when the computer program is executed by a processor, part or all of the storage method described in the present disclosure is implemented.

[0021] According to another aspect of the present disclosure, an electronic device is provided, comprising: at least one processor; and at least one memory storing computer-executable instructions, wherein when the computer-executable instructions are executed by the at least one processor, the at least one processor is prompted to execute part or all of the storage method described in the present disclosure.

[0022] The technical solution disclosed in the present invention provides a storage method and a storage device, which stores data blocks originally stored in files in a database in a memory, and only stores information related to the data blocks in the files in the database for subsequent calling and reorganization. Since the size of the data blocks stored in the memory is variable, unlike the size of the data blocks stored in the database which is fixed, the byte size of the data blocks can be varied within a certain range, so that the data blocks corresponding to the files in the database can be variable in length.

[0023] Additional aspects and / or advantages of the present general inventive concept will be set forth in part in the following description and in part will be apparent from the description or may be learned through practice of the present general inventive concept. BRIEF DESCRIPTION OF THE DRAWINGS

[0024] The above and other objects and features of the exemplary embodiments of the present disclosure will become more apparent through the following description in conjunction with the accompanying drawings which exemplarily illustrate the embodiments, in which:

[0025] Figure 1 is a schematic diagram showing the insertion of data in the Compaction process of RocksDB in the related art;

[0026] Figure 2 It is a schematic diagram showing the distribution comparison of write operation types at each layer of the LSM-based database system;

[0027] Figure 3 is a flowchart illustrating a storage method according to an exemplary embodiment of the present disclosure;

[0028] Figure 4 is a schematic diagram showing the comparison between Block SSD and KV SSD architectures;

[0029] Figure 5 is a schematic diagram showing the format of a variable-length SST file according to an exemplary embodiment of the present disclosure. Figure 1 ;

[0030] Figure 6 is a schematic diagram showing the format of a variable-length SST file according to an exemplary embodiment of the present disclosure. Figure 2 ;

[0031] Figure 7 is a schematic diagram showing data insertion in a compaction process of a variable-length SST file according to an exemplary embodiment of the present disclosure;

[0032] Figure 8 is a flowchart showing the compaction of a variable-length SST file based on a KV SSD according to an exemplary embodiment of the present disclosure;

[0033] Fig. 9 is a schematic diagram showing a worst-case compaction process of an LSM-based database system according to an exemplary embodiment of the present disclosure;

[0034] Fig.10 is a block diagram illustrating a storage device according to an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION

[0035] The following specific embodiments are provided to help the reader obtain a comprehensive understanding of the methods, devices and / or systems described herein. However, after understanding the disclosure of the present application, various changes, modifications and equivalents of the methods, devices and / or systems described herein will be clear. For example, the order of operations described herein is only an example and is not limited to those orders set forth herein, but can be changed as will be clear after understanding the disclosure of the present application, except for operations that must occur in a specific order. In addition, for greater clarity and simplicity, the description of features known in the art may be omitted.

[0036] The features described herein can be implemented in different forms and should not be construed as being limited to the examples described herein. Rather, the examples described herein have been provided to illustrate only some of the many possible ways to implement the methods, devices, and / or systems described herein, which will be clear after understanding the disclosure of the present application.

[0037] The terms used herein are only used to describe various examples and are not intended to limit the disclosure. Unless the context clearly indicates otherwise, the singular form is also intended to include the plural form. The terms "comprise", "include" and "have" indicate the presence of the described features, quantities, operations, components, elements and / or combinations thereof, but do not exclude the presence or addition of one or more other features, quantities, operations, components, elements and / or combinations thereof.

[0038] Unless otherwise defined, all terms (including technical and scientific terms) used herein have the same meaning as those generally understood by a person of ordinary skill in the art to which the present disclosure belongs after understanding the present disclosure. Unless explicitly defined as such herein, terms (such as those defined in a general dictionary) should be interpreted as having a meaning consistent with their meaning in the context of the relevant art and the present disclosure, and should not be interpreted too formally.

[0039] Furthermore, in the description of examples, when it is considered that a detailed description of a well-known related structure or function may cause vague interpretation of the present disclosure, such a detailed description may be omitted.

[0040] In the related art, the data blocks of RocksDB's SST files are of fixed size, generally 4K. If a data block in an SST file changes during the compaction process, it will affect the data structure of the following data blocks in the SST file, and even affect the data structure of the data blocks of the next file. Figure 1As shown in the figure, the i-th and i+1-th files of layer Li+1 are selected to participate in compaction. The data blocks in the i-th file are [1 2 4 5], [6 7 8 9], [10 11 12 13]... [50 51 52 53], and the data blocks in the i+1-th file are [54 55 56 57], [58 59 60 61], [62 63 64 65]... [94 95 96 97]. SST files are ordered, and data 3 should be inserted into the first data block of the i-th file. The first data block of the i-th file becomes [1 2 3 4]. Since the blocks of SST files are of fixed size, the reorganized data 5 appears in the second data block of the i-th file. By analogy, the last data of the i-th file may appear in the first data block of the i+1-th file, resulting in changes in the data of the i+1-th file. Moreover, the compaction process is based on SST files, that is, all files in the Li layer and Li+1 layer participating in the compaction will be read, parsed, sorted, reorganized and copied.

[0041] Figure 2 It is a schematic diagram showing the distribution comparison of write operation types at each layer of the LSM-based database system. Figure 2 The LSM-based database system in includes three database systems labeled S1, S2, and S3.

[0042] like Figure 2 As shown in the figure, by analyzing the write operations of each layer of disks in three database systems based on log structured merge trees (LSM), the data in the files of the L0 layer comes from the main memory, and only new data is written; the files of the L1 to L4 layers are generated by compaction operations. It can be seen that the consumption of write operations in the compaction of the L1 to L4 layers of the LSM-based database system mainly comes from the copying of a large amount of existing and unchanged data, which greatly increases the write amplification.

[0043] In view of the above problem, according to one aspect of an exemplary embodiment of the present disclosure, a storage method is provided. Figure 3 is a flowchart showing a storage method according to an exemplary embodiment of the present disclosure. The storage method is applied to the storage device in the above embodiment, and any storage method can be executed as a storage process partially or completely implemented by the electronic device:

[0044] In step S301, the layers to be merged in the database are determined. The above database may be a key-value KV database, for example, RocksDB. It should be noted that Figure 3 The database used in the storage method is not limited to the above database.

[0045] In an embodiment of the present disclosure, determining the layers to be merged in a database may include: detecting an increase in the byte size of a file in the database; obtaining the byte size of each layer in the database; treating the layer in each layer whose byte size exceeds the byte threshold of the corresponding layer as the previous layer; determining the previous layer and the next layer as the layers to be merged, wherein the next layer is the next layer adjacent to the previous layer. By addressing and / or by creating a timing sequence of the next layer and the previous layer, the next layer may be logically adjacent to the previous layer, and / or the next layer may be physically adjacent in the storage location of the database. Through this embodiment, the compression operation Compaction may be triggered conveniently and quickly. It should be noted that the above-mentioned byte threshold may be stored in the statistical information of the data block of each layer.

[0046] For example, if it is detected that the written data reaches a certain value (such as the first predetermined threshold), it is necessary to add an SST file in the database to store the written data. At this time, the byte size of each layer in the database can be obtained from the statistical information. Each layer can have a byte threshold specific to the layer. When the byte size of any layer exceeds the byte threshold of the corresponding layer, the layer whose byte size exceeds the byte threshold of the corresponding layer is the Li layer, and the next layer adjacent to the layer is the Li+1 layer. Optionally, the layer corresponding to the file of the written data can be first determined, that is, the 0th layer of the logical tree, and the current total number of bytes of the 0th layer is compared with the byte threshold of the layer. If the current total number of bytes is greater than the byte threshold of the layer, the 0th layer is the Li layer, and the next layer adjacent to the layer is, that is, the 1st layer is the Li+1 layer. After completing a compaction, the current total number of bytes of the 1st layer and the byte threshold of the layer can be continued to be determined. If the current total number of bytes is greater than the byte threshold of the layer, the 1st layer is the Li layer, and the next layer adjacent to the layer is, that is, the 2nd layer is the Li+1 layer. If the current total number of bytes is not greater than the byte threshold of the layer, the compaction can be stopped.

[0047] In this embodiment, all files in layer Li and layer Li+1 that participate in the merge will be deleted by the background thread at an appropriate time. The order of deletion can be the order of compaction or the order set as needed.

[0048] In addition, after the first merge, the merged layer can also be determined according to the following method: when deleting some SST files, the Li layer and Li+1 layer to be merged can also be determined according to the current total number of bytes of the layer corresponding to the deleted file and the byte threshold of the corresponding layer. It should be noted that each layer in the database has its own byte threshold, and the byte threshold can be dynamically set according to actual needs.

[0049] In the embodiment of the present disclosure, when the byte size of the data written in any layer exceeds the first predetermined threshold of the layer, the increase in the number of files in the database can be detected. That is, when the byte size of the data written in the layer exceeds the first predetermined threshold of the layer, the increase in the data of the files in the database can be detected. In step S302, the data blocks to be modified are determined based on the files of the layer to be merged in the database.

[0050] In an embodiment of the present disclosure, determining the data block to be modified based on the file of the layer to be merged may include: obtaining the file with the largest file bytes in the previous layer of the layer to be merged and a predetermined file, wherein the predetermined file is a file in the previous layer containing the user key of the file with the largest file bytes, and the user key is contained in the key corresponding to the data block in the file. The user key range can be obtained based on the user key of the file with the largest file bytes and the user key of the predetermined file. Data blocks in the next layer of the layer to be merged where the user key and the user key range overlap, and data blocks in the previous layer of the layer to be merged where the user key and the user key range overlap. The overlapping data blocks can be determined as the data blocks to be modified. Through this embodiment, the data blocks to be modified are determined based on the overlap of user keys, which reduces the reorganization of irrelevant data blocks during the reorganization process.

[0051] For example, after determining the Li layer and Li+1 layer to be merged, the files of the Li layer can be sorted by byte size to obtain the first-ranked file, and the first-ranked file can be compared with other files of the Li layer to obtain a file containing the user key of the first-ranked file, that is, the above-mentioned predetermined file. Then, based on the user key of the first-ranked file and the user key of the predetermined file, a user key range is obtained, and the data blocks whose user keys overlap with the user key range are searched in the files of the Li+1 layer, and the data blocks whose user keys overlap with the user key range are searched in the files of the Li layer. The overlapping data blocks are the data blocks to be modified.

[0052] In step S303, Figure 3 The method shown includes reading the corresponding data block in the memory according to the key corresponding to the data block to be modified and reorganizing the read data block. The above-mentioned memory can be a solid-state hard disk that directly supports KV storage. For example, the solid-state hard disk can be a key-value solid-state hard disk KV SSD. The memory is not limited to the solid-state hard disk mentioned above. As long as it can store data blocks and the byte size of the stored data blocks is variable, it can be applied in the present disclosure. The above-mentioned keys may include but are not limited to: user keys and serial numbers of data blocks. The serial number is used to indicate the order in which the same user key appears. The user key is user-oriented and is the key that the user needs to use when calling the data block.

[0053] In an embodiment of the present disclosure, the corresponding data block can be read from the memory according to the key corresponding to the data block to be modified and the read data block can be reorganized as follows: The corresponding data block can be read from the memory according to the user key corresponding to the data block to be modified. The user key is included in the key corresponding to the data block. The data corresponding to the maximum sequence number corresponding to each user key can be filtered out from the corresponding data block. The sequence number is included in the key of the data block and is used to indicate the order in which the same user key appears. The filtered data is sorted according to the user key as the reorganized data block.

[0054] For example, for the data block to be modified, it can be read from the KV SSD according to the user key of the data block, and the data corresponding to the same user key can be queried from the read data block. Only the data corresponding to the largest sequence number in the data corresponding to the same user key is retained. The data corresponding to other sequence numbers are deleted, and then the retained data is sorted by user key to form a reorganized data block.

[0055] In step S304, when the byte size of the reorganized data block does not exceed the first preset value, the data block to be modified in the memory is replaced with the reorganized data block. Since the byte size of the data block is variable within a certain range, if the reorganized data block does not exceed the data block length threshold (such as the first preset value below), the data block to be modified can be directly stored in the corresponding position of the memory after reorganization. The data block that does not need to be changed can be retained as is in the KV SSD, and only the metadata of the data block is stored in the variable-length SST file. The above-mentioned first preset value can be dynamically set according to actual needs.

[0056] In step S305, the key and statistical information of the reorganized data block are stored in the corresponding file of the database.

[0057] In these embodiments of the present disclosure, when the byte size of the reorganized data block exceeds a first preset value, the reorganized data block is split according to the first preset value. The data block to be modified in the memory is replaced with the split data block. In other words, the reorganized data block is split according to the first preset value based on (for example, the above condition) that the byte size of the reorganized data block exceeds the first preset value. Storing the key and statistical information of the reorganized data block in a file corresponding to the database includes: storing the key and statistical information of the split data block in a file corresponding to the database. Through this embodiment, it is ensured that the byte size of a data block will not be too large.

[0058] For example, if the reorganized data block exceeds the data block length threshold (i.e., the first preset value), the reorganized data block will be divided into multiple data blocks according to the length threshold, and the multiple data blocks will be written to the KV SSD respectively, and their corresponding metadata will be stored in the variable-length SST file. For data blocks that do not need to be changed, they can be retained as they are in the KV SSD, and only the metadata of the data block is stored in the variable-length SST file. The above splitting process is based on the first preset value and the byte size of the reorganized data block, which can be as follows: Assuming that the first preset value is 16, the byte size of the reorganized data block is 33, the reorganized data block can be split into three sizes of data blocks: 16, 16, and 1.

[0059] In an embodiment of the present disclosure, after storing the keys and statistical information of the reorganized data blocks in the file corresponding to the database, it is also possible to determine whether the byte size of all data blocks of the corresponding file exceeds a second preset value; when the judgment result is yes, the corresponding file is split according to the second preset value, and the keys and statistical information of the reorganized data blocks and the keys and statistical information of the unmodified data blocks of the corresponding file are stored in the split files in the order of the keys; when the judgment result is no, the keys and statistical information of the reorganized data blocks are stored in the corresponding files. The above-mentioned second preset value can be dynamically set according to actual needs. Therefore, the processing method changes according to the judgment result. Through this embodiment, it is guaranteed that the byte size of the total data blocks corresponding to a file will not be too large.

[0060] For example, if the total byte size of the data blocks corresponding to the variable-length SST file exceeds a certain range after the relevant information of the reorganized data blocks is stored in the SST file, the variable-length SST file can be divided into multiple files. For example, assuming that the second preset value is 100 and the byte size of the corresponding file is 103, the corresponding file can be split into two files of size 100 and 3. In this way, it can be ensured that the byte size of the total data blocks corresponding to each file will not be too large.

[0061] Through the above-mentioned embodiments of the present disclosure, the granularity is refined during the compaction process, and the compaction is performed in units of data blocks instead of SST files. For data blocks that have changed during the compaction process, the data blocks are read, parsed, sorted, reorganized, and copied, so that the size of the data blocks can be changed within a certain range. For data blocks that have not changed during the compaction process, they are stored in the KV SSD as they are and are not affected by the changed data blocks. This can reduce unnecessary operations and IO consumption, thereby reducing write amplification and improving write performance.

[0062] The following example uses RocksDB as the database and KV SSD as the storage. Figure 4 , Figure 5 , Figure 6 , Figure 7 and Figure 8 Describe the compaction process in detail.

[0063] Figure 4 is a schematic diagram showing the comparison between Block SSD and KV SSD architectures. Figure 4 As shown on the left side of the figure, the KV SSD architecture is as follows Figure 4 As shown on the right side of the figure, the KV SSD mentioned above is a new type of SSD that can directly support KV storage devices. Compared with the Block-type SSD in the related art, the writing and reading of its KV database requires the completion of data conversion from KV to file, file to logical block address (Logical Block Address, abbreviated as LBA), and then from LBA to physical block address (Physics Block Address, abbreviated as PBA). The KV SSD uses an enhanced Flash Translation Layer (FTL) to implement some core functions of KV storage. It provides a KV interface to the outside world and can directly respond to the KV request of the host application, simplifying the data reading and writing process, which not only improves the efficiency of data reading and writing, but also greatly reduces the consumption of host CPU and memory.

[0064] Using KV SSD with KV storage engine or KV database (such as RocksDB) will bring great improvements in many aspects. Therefore, the data blocks of RocksDB's SST files can be stored in KV SSD. First, it takes advantage of KV SSD, that is, when the data block size changes within a certain range, the random read and write performance of KV SSD is stable, which can ensure the read and write performance of RocksDB. Figure 5 As shown in the figure, KV SSD is used to store data blocks with variable byte lengths, thus realizing variable-length SST files. Second, KV SSD is used to store data blocks with variable byte lengths, so that each data block in the SST file is independent of each other, and reading and writing do not affect each other, which facilitates the refinement of granularity in the subsequent compaction process.

[0065] In this embodiment, the key of the data block and the statistical information of the data block can be stored in the index block of the file's meta information. That is, the data structure of the index block in the meta information can be expanded, and the key and the statistical information of the data block are added. On the basis of using the original structure, the statistical information of the key and the data block can be stored conveniently and quickly. Specifically, Figure 6As shown in the figure, the data structure of the data index block in the metadata of the SST file is expanded. On the basis of the original, the key-related fields in KVSSD (the file number of the SST file and the serial number of the data block in the SST file) and data block statistical information are added, and the key-related fields and data block statistical information in the added KV SSD are used in the reading and writing of KV SSD and the Compaction process respectively.

[0066] Figure 7 is a schematic diagram showing the insertion of data in the compaction process of a variable-length SST file according to an exemplary embodiment of the present disclosure, as shown in Figure 7 As shown in the figure, during the compaction process, when data 3 needs to be inserted, data block [1 2 4 5] becomes [1 2 3 4 5], and other data blocks remain unchanged.

[0067] Figure 8 is a flowchart showing a compaction of a variable-length SST file based on a KV SSD according to an exemplary embodiment of the present disclosure, as shown in FIG. Figure 8 As shown, the compaction process is as follows:

[0068] In step S810, the SST files of the Li layer and Li+1 layer to be merged are selected. In this process, the byte size of the written data can be detected first. When the byte size reaches a certain value (the first preset threshold mentioned above), it is determined that an SST file has been added to the database. At this time, the layer where the data is written and the next layer adjacent to the layer can be determined as the Li layer and Li+1 layer to be merged; the relationship between the current byte size of the layer corresponding to the added file and the byte threshold of the layer can also be monitored. When the current byte size of the layer corresponding to the added file is greater than the byte threshold of the layer, the layer corresponding to the added file and the next layer adjacent to the layer are used as the layers Li and Li+1 to be merged;

[0069] In step S820, it is determined whether the data block in the SST file needs to be modified. In this process, the files in the Li layer are sorted by byte size to obtain the first-ranked file and the file in the Li layer whose user key overlaps with the user key of the first-ranked file (i.e., the above-mentioned predetermined file). Based on the user key of the first-ranked file and the user key of the predetermined file, a user key range is obtained, and the data blocks that overlap with the user key range are searched in the Li+1 layer and the data blocks that overlap with the user key range are searched in the Li layer, and the overlapping data blocks are determined as the data blocks to be modified;

[0070] Furthermore, in step S830, the data blocks to be modified are read from the KV SSD, and are parsed, sorted, and reorganized.

[0071] Then, in step S840, it is determined whether the byte size of the reorganized data block exceeds a data block threshold (the first preset value mentioned above), and the data block threshold may be stored in the statistical information of the data block;

[0072] Then, in step S850, when the byte size of the reorganized data block exceeds the data block threshold (i.e., when the result of the judgment in S840 is yes), the reorganized data block is split into a plurality of data blocks according to the data block threshold, and then, in step S860, the plurality of data blocks are stored in the KV SSD and the related information of the plurality of data blocks is written into a variable-length SST file; when the byte size of the reorganized data block does not exceed the threshold (i.e., when the result of the judgment in S840 is no), step S860 is directly executed, i.e., the reorganized data block is directly stored in the KV SSD and the related information of the reorganized data block is written into a variable-length SST file;

[0073] After completing the above operations, in step S870, it is determined whether the total byte size of all data blocks corresponding to the variable-length SST file after writing exceeds the file threshold (the above-mentioned second preset value). If it exceeds the file threshold (the above-mentioned second preset value) (that is, when the judgment result of S870 is yes), as in step S880, the SST file is split into several files according to the file threshold. Optionally, the current variable-length SST file can also be closed, and the metadata of the reorganized data blocks is written into the next variable-length SST file. If it does not exceed the file threshold (that is, when the judgment result of S870 is no), as in step S890, the metadata of the reorganized data blocks is written into the current variable-length SST file.

[0074] All files involved in the compaction will be deleted, and the reorganized data blocks will be stored in files that do not participate in the compaction. The metadata of the reorganized data blocks mentioned above can be written into the next variable-length SST file or stored in a new SST file. After deleting the file, the current total number of bytes of the corresponding layer can be recalculated and compared with the byte threshold of the layer to obtain the comparison result for the next compaction.

[0075] In order to verify the effectiveness of the above embodiment, this disclosure calculates the write amplification of the LSM storage engine during the compaction process, and takes the worst-case compaction as an example (a file in the L0 layer that falls to the last layer through compaction) to illustrate how the above embodiment reduces the write amplification of compaction. Table 1 gives the basic definitions that need to be used. Fig. 9 The worst-case compaction process of the LSM-based database system is given.

[0076] Table 1 Basic definitions

[0077]

[0078]

[0079] When the files in the L0 layer meet the compaction triggering conditions, they are compacted with the files in the L1 layer, and the data in the L0 layer falls to the L1 layer. According to the characteristics of the LSM tree, the total capacity of the next layer is T times the total capacity of the previous layer. In the worst case, the L0 layer and the L1 layer will have to undergo T compactions before the data in the L1 layer meets the compaction conditions with the L2 layer and falls to the L2 layer. Similarly, in the worst case, the L1 layer will undergo T compactions with the data in the L2 layer before the compaction conditions with the L2 layer are triggered, causing the data to fall to the L3 layer. By analogy, when the data in the L0 layer falls to the L layer, T×L compactions have been performed, which are amortized to each data block of each file. The write amplification during the compaction process of RocksDB is:

[0080]

[0081] For variable-length SST files, only 1 / T of the data blocks will change on average during each compaction. The write amplification of this disclosure is:

[0082]

[0083] Through theoretical analysis, the write amplification of the present disclosure is reduced by T times compared with the write amplification of the original LSM-based database system.

[0084] According to another aspect of the exemplary embodiment of the present disclosure, there is provided a storage device, which is applied to the storage device of the above embodiment, referring to Fig.10 The storage device includes: a first determination unit 102, a second determination unit 104, a reorganization unit 106, a replacement unit 108 and a writing unit 1010.

[0085] Before proceeding, it should be understood that the drawings herein (including Fig.10) shows and refers to circuits with labels such as "unit", "circuit" or "block". Generally, in the field of (one or more) inventive concepts described herein, examples can be described and shown in terms of units, circuits and blocks that perform one or more functions described. These units, circuits and blocks (which may be referred to herein as first determination units, second determination units, reorganization units, replacement units, write units, etc.) are physically implemented by analog and / or digital circuits (such as logic gates, integrated circuits, microprocessors, microcontrollers, memory circuits, passive electronic components, active electronic components, optical components, hard-wired circuits, etc.), and can be optionally driven by hardware and / or software. For example, the circuits may be embodied in one or more semiconductor chips, or on a substrate support such as a printed circuit board. The circuits that constitute a unit, circuit or block may be implemented by dedicated hardware, or by a processor (e.g., one or more programmed microprocessors and associated circuits), or by a combination of dedicated hardware that performs some functions of the unit, circuit or block and a processor that performs other functions of the unit, circuit or block. Without departing from the scope of the present disclosure, each unit, circuit or block of the examples may be physically divided into two or more circuits or blocks that can interact and be separated. Likewise, without departing from the scope of the present disclosure, the units, circuits and blocks of the examples may be physically combined into more complex units, circuits and blocks.

[0086] The first determination unit 102 is used to determine the layer to be merged in the database; the second determination unit 104 is used to determine the data block to be modified based on the file of the layer to be merged; the reorganization unit 106 is used to read the corresponding data block in the memory according to the key corresponding to the data block to be modified and reorganize the read data block; the replacement unit 108 is used to replace the data block to be modified in the memory with the reorganized data block when the byte size of the reorganized data block does not exceed the first preset value; the writing unit 1010 is used to store the key and statistical information of the reorganized data block into the file corresponding to the database.

[0087] In an embodiment of the present disclosure, the replacement unit 108 is further used to split the reorganized data block according to the first preset value when the byte size of the reorganized data block exceeds the first preset value; replace the data block to be modified in the memory with the split data block; the writing unit 1010 is also used to store the key and statistical information of the split data block into the file corresponding to the database.

[0088] In an embodiment of the present disclosure, the write unit 1010 is further used to determine whether the byte size of all data blocks of the corresponding file exceeds a second preset value after storing the keys and statistical information of the reorganized data blocks in the file corresponding to the database; when the judgment result is yes, split the corresponding file according to the second preset value, and store the keys and statistical information of the reorganized data blocks and the keys and statistical information of the unmodified data blocks of the corresponding file in the split files in the order of the keys; when the judgment result is no, store the keys and statistical information of the reorganized data blocks in the corresponding files.

[0089] In an embodiment of the present disclosure, the first determination unit 102 is also used to detect the increase of files in the database; obtain the byte size of each layer in the database; take the layer in each layer whose byte size exceeds the byte threshold of the corresponding layer as the previous layer; determine the previous layer and the next layer as the layers to be merged, wherein the next layer is the next layer adjacent to the previous layer.

[0090] In an embodiment of the present disclosure, the first determining unit 102 is further configured to determine that a file in the database is increased when the byte size of the written data exceeds a first predetermined threshold.

[0091] In an embodiment of the present disclosure, the second determination unit 104 is further used to obtain the file with the largest file bytes and a predetermined file in the previous layer of the layer to be merged, wherein the predetermined file is a file in the previous layer containing the user key of the file with the largest file bytes, and the user key is contained in the key of the data block in the file; based on the user key of the file with the largest file bytes and the user key of the predetermined file, a user key range is obtained; data blocks in the next layer of the layer to be merged, where the user key overlaps with the user key range, and data blocks in the previous layer of the layer to be merged, where the user key overlaps with the user key range; and the overlapping data blocks are determined as the data blocks to be modified.

[0092] In the embodiment of the present disclosure, the reorganization unit 106 is further used to read the corresponding data block in the memory according to the user key corresponding to the data block to be modified, wherein the user key is included in the key of the data block; filter out the data corresponding to the maximum sequence number corresponding to each user key from the corresponding data block, wherein the sequence number is included in the key of the data block and is used to indicate the order in which the same user key appears; and sort the filtered data according to the user key as the reorganized data block.

[0093] According to another aspect of the exemplary embodiment of the present disclosure, a storage system is provided, comprising: a memory, a database, and a storage device as described in the above embodiment, wherein the memory is used to store data blocks and reorganized data blocks, and the database is used to store keys and statistical information of data blocks, and keys and statistical information of reorganized data blocks. The statistical information includes relevant information for reorganizing data blocks, such as byte size, byte threshold, etc.

[0094] The above-mentioned embodiments of the present disclosure provide a preferred storage system and storage method. For example, the above-mentioned embodiments provide a solution for optimizing RocksDB based on the new storage hardware KV SSD. This technical solution can store data blocks in the SST file of RocksDB in the KV SSD. When the data size varies within a certain range, the performance of random reading and writing of data by the KV SSD is stable, which can ensure the read and write performance of RocksDB and realize variable-length SST files. Moreover, the granularity of the compaction process of RocksDB is refined, and the file unit is refined into the data block unit, so as to avoid reading, parsing, reorganizing and copying all data blocks due to changes in some data blocks in the SST file during the compaction process, thereby reducing unnecessary operations and IO consumption, thereby reducing write amplification and improving write performance.

[0095] In addition, this disclosure describes an optimization that can amplify writes in the RocksDB compaction process from Down to Reduce T times.

[0096] It should be understood that each unit / module in the storage method and storage device according to the exemplary embodiments of the present disclosure can be implemented as a hardware component and / or a software component. Those skilled in the art can implement each unit / module, for example, using a field programmable gate array (FPGA) or an application specific integrated circuit (ASIC), according to the processing performed by each defined unit / module.

[0097] According to still another aspect of the exemplary embodiments of the present disclosure, a computer-readable storage medium storing a computer program is provided, wherein when the computer program is executed by a processor, the storage method described in the present disclosure is implemented.

[0098] Specifically, the storage method according to the exemplary embodiment of the present disclosure can be written as a computer program, a code segment, an instruction, or any combination thereof, and any computer program, code segment, instruction, or combination thereof can be recorded, stored, or fixed in or on one or more non-transitory computer-readable storage media. The computer-readable storage medium is any data storage device that can store data read out by a computer system. Examples of computer-readable storage media include: read-only memory, random access memory, read-only optical disk, magnetic tape, floppy disk, optical data storage device, and transmission path via the Internet via wired or wireless.

[0099] According to another aspect of the exemplary embodiments of the present disclosure, there is provided an electronic device, comprising: at least one processor; and at least one memory storing computer executable instructions, wherein the computer executable instructions, when executed by the at least one processor, prompt the at least one processor to execute the storage method described in the present disclosure.

[0100] Specifically, the electronic device can be broadly a tablet computer, a smart phone, a smart watch, or any other electronic device with necessary computing and / or processing capabilities. In one embodiment, the electronic device may include a processor, a memory, a network interface, a communication interface, etc. connected via a system bus. The processor of the electronic device can be used to provide necessary computing, processing and / or control capabilities. The memory of the electronic device may include a non-volatile storage medium and an internal memory. An operating system, a computer program, etc. may be stored in or on the non-volatile storage medium. The internal memory may provide an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface and the communication interface of the electronic device can be used to connect and communicate with external devices via a network.

[0101] Exemplary embodiments of the present disclosure have been described above, and it should be understood that the foregoing description is merely exemplary and not exhaustive, and the present disclosure is not limited to the disclosed exemplary embodiments. Many modifications and changes will be apparent to those of ordinary skill in the art without departing from the scope and spirit of the present disclosure. Therefore, the scope of protection of the present disclosure should be subject to the scope of the claims.

Claims

1. A storage method, include: Determine the layers in the database to be merged; Determining the data block to be modified based on the variable-length file of the layer to be merged; Reading a corresponding data block in a memory according to a key corresponding to the data block to be modified and reorganizing the read data block, wherein the memory is used to store data blocks and the byte size of the stored data blocks is variable; When the byte size of the reorganized data block does not exceed a first preset value, replacing the data block to be modified in the memory with the reorganized data block; Storing the key and statistical information of the reorganized data block into a variable-length file corresponding to the database; The step of reading the corresponding data block in the memory according to the key corresponding to the data block to be modified and reorganizing the read data block comprises: Reading a corresponding data block in a memory according to a user key corresponding to the data block to be modified, wherein the user key is included in the key corresponding to the data block; Filtering out data corresponding to the maximum sequence number corresponding to each user key from the corresponding data block, wherein the sequence number is contained in the key corresponding to the data block and is used to indicate the order in which the same user key appears; The filtered data is sorted by user key and used as the reorganized data block.

2. The storage method according to claim 1, It is characterized in that Also includes: When the byte size of the reorganized data block exceeds the first preset value, splitting the reorganized data block according to the first preset value; Replacing the data block to be modified in the memory with the split data block; The step of storing the key and statistical information of the reorganized data block into a variable-length file corresponding to the database includes: storing the key and statistical information of the split data block into a variable-length file corresponding to the database.

3. The storage method according to claim 2, It is characterized in that After storing the key and statistical information of the reorganized data block into the variable-length file corresponding to the database, the method further includes: Determining whether the byte size of all data blocks of the corresponding variable-length file exceeds a second preset value; When the judgment result is yes, splitting the corresponding variable-length file according to the second preset value, and storing the keys and statistical information of the reorganized data blocks and the keys and statistical information of the unmodified data blocks of the corresponding variable-length file in the split variable-length files in the order of keys; When the judgment result is no, the key and the statistical information of the reorganized data block are stored in the corresponding variable-length file.

4. The storage method according to claim 1, It is characterized in that The step of determining the layers to be merged in the database comprises: An increase in variable-length files in the database is detected; Get the byte size of each layer in the database; The layer whose byte size in each layer exceeds the byte threshold of the corresponding layer is taken as the previous layer; The previous layer and the next layer are determined as layers to be merged, wherein the next layer is a next layer adjacent to the previous layer.

5. The storage method according to claim 4, It is characterized in that The detecting that the variable-length file in the database increases includes: When the byte size of the written data exceeds a first predetermined threshold, it is determined that the variable-length file in the database is increased.

6. The storage method according to claim 1, It is characterized in that The determining of the data block to be modified based on the variable-length file of the layer to be merged comprises: Obtaining a file with the largest file bytes in a previous layer of the layer to be merged and a predetermined file, wherein the predetermined file is a file in the previous layer containing a user key of the file with the largest file bytes, and the user key is contained in a key corresponding to a data block in the file; Obtaining a user key range based on the user key of the file with the largest file bytes and the user key of the predetermined file; Acquire a data block in which a user key overlaps with the user key range in a subsequent layer of the layers to be merged, and a data block in which a user key overlaps with the user key range in a previous layer of the layers to be merged; The overlapping data blocks are determined as data blocks to be modified.

7. A storage device, include: A first determining unit, used to determine the layers to be merged in the database; A second determining unit, used for determining a data block to be modified from the variable-length file of the layer to be merged; a reorganization unit, configured to read a corresponding data block from a memory according to a key corresponding to the data block to be modified and to reorganize the read data block, wherein the memory is used to store data blocks and the byte size of the stored data blocks is variable; a replacement unit, configured to replace the data block to be modified in the memory with the reorganized data block when the byte size of the reorganized data block does not exceed a first preset value; A writing unit, used for storing the key and statistical information of the reorganized data block into a variable-length file corresponding to the database; The reorganization unit is further used to read the corresponding data block in the memory according to the user key corresponding to the data block to be modified, wherein the user key is included in the key corresponding to the data block; filter out the data corresponding to the maximum sequence number corresponding to each user key from the corresponding data block, wherein the sequence number is included in the key corresponding to the data block and is used to indicate the order in which the same user key appears; and sort the filtered data according to the user key as the reorganized data block.

8. The storage device according to claim 7, It is characterized in that The replacement unit is also used to split the reorganized data block according to the first preset value when the byte size of the reorganized data block exceeds the first preset value; replace the data block to be modified in the memory with the split data block; the writing unit is also used to store the key and statistical information of the split data block into the variable-length file corresponding to the database.

9. The storage device according to claim 8, It is characterized in that The writing unit is further used to determine whether the byte size of all data blocks of the corresponding variable-length file exceeds a second preset value after storing the key and statistical information of the reorganized data block into the variable-length file corresponding to the database; When the judgment result is yes, the corresponding variable-length file is split according to the second preset value, and the keys and statistical information of the reorganized data blocks and the keys and statistical information of the unmodified data blocks of the corresponding variable-length file are stored in the split variable-length files in the order of keys; When the judgment result is no, the key and the statistical information of the reorganized data block are stored in the corresponding variable-length file.

10. The storage device according to claim 7, It is characterized in that The first determination unit is also used to detect the increase of variable-length files in the database; obtain the byte size of each layer in the database; take the layer in each layer whose byte size exceeds the byte threshold of the corresponding layer as the previous layer; determine the previous layer and the next layer as the layers to be merged, wherein the next layer is the next layer adjacent to the previous layer.

11. The storage device according to claim 10, It is characterized in that The first determining unit is further configured to determine that the variable-length file in the database is increased when the byte size of the written data exceeds a first predetermined threshold.

12. The storage device according to claim 7, It is characterized in that The second determination unit is further used to obtain the file with the largest file bytes and a predetermined file in the previous layer of the layer to be merged, wherein the predetermined file is a file in the previous layer containing the user key of the file with the largest file bytes, and the user key is contained in the key corresponding to the data block in the file; based on the user key of the file with the largest file bytes and the user key of the predetermined file, a user key range is obtained; data blocks in the next layer of the layer to be merged, where the user key overlaps with the user key range, and data blocks in the previous layer of the layer to be merged, where the user key overlaps with the user key range; and the overlapping data blocks are determined as the data blocks to be modified.

13. A storage system, It is characterized in that It comprises a memory, a database and a storage device as claimed in claim 7, wherein the memory is used to store data blocks and reorganized data blocks, and the database is used to store keys and statistical information of the data blocks and keys and statistical information of the reorganized data blocks.

14. A computer-readable storage medium storing a computer program, It is characterized in that When the computer program is executed by a processor, the storage method according to any one of claims 1 to 6 is implemented.

15. An electronic device, It is characterized in that include: at least one processor; at least one memory storing computer executable instructions, Wherein, when the computer executable instructions are executed by the at least one processor, the at least one processor is prompted to perform the storage method according to any one of claims 1 to 6.

Citation Information

Patent Citations

  • Light-weight combination method based on log combination tree structure

    CN106682184A

  • A method and system for deleting duplicate data

    CN109522283A

  • Tape drive memory deduplication

    CN111095187A

  • Data access method, data access control device and data access system

    CN113094372A

  • Data block storage method and apparatus, and electronic device

    US20200285399A1