Data storage method and device, equipment and storage medium

By introducing the idea of ​​dividing disk files and jump tables in the storage engine, the problem of write amplification in traditional storage engines is solved, achieving more efficient write performance and disk life extension.

CN118885137AInactive Publication Date: 2024-11-01TIANJIN NANKAI UNIV GENERAL DATA TECH
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202411390648.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-08
Publication Date
2024-11-01
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

Traditional storage engines have problems with write amplification under frequent write operations, resulting in shortening disk life and decreasing read efficiency. LSM-tree needs to frequently read and rewrite disk files during the merge process, resulting in serious write amplification.

Method used

By introducing anchor value to divide disk files into smaller compression units, only the merged files are appended to the next layer of compression units during the merge process, instead of rewriting the entire file, using the idea of ​​jump table to divide the disk files into local areas Ordered compression unit, reducing write amplification.

Benefits of technology

It effectively reduces write amplification, improves write performance, reduces the number of rewrites of disk files, extends disk life, and improves overall performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118885137A_ABST
    Figure CN118885137A_ABST
Patent Text Reader

Abstract

The invention provides a data storage method and device, equipment and a storage medium. The method comprises the steps that a first target hierarchy and a second target hierarchy with the hierarchy number larger than that of the first target hierarchy are determined from a plurality of hierarchies obtained after disk configuration is conducted according to a log structure merging tree, and the first target hierarchy comprises a plurality of compression units obtained through division according to at least one first anchor point value; the second target hierarchy comprises a plurality of compression units obtained through division according to a plurality of second anchor point values, and the number of the second anchor point values is larger than that of the first anchor point values; in response to determining that the number of the data files in the target compression unit in the first target hierarchy reaches a first threshold value, reading the data files in the target compression unit and merging the data files to obtain a merged file; and writing the combined file into a compression unit, matched with the combined file, of the second target hierarchy.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and more specifically to a data storage method, device, equipment and storage medium. Background Art

[0002] As an important part of the database, the performance of the storage engine directly affects the overall performance of the database. Most traditional storage engines mainly use the B+ tree index structure. Under frequent write operations, the traditional B+ tree requires a large amount of random disk writes. This is a very expensive operation that will consume the life of the disk. Moreover, as the data set increases, the B+ tree index structure may become too large, resulting in increased memory pressure and decreased reading efficiency, thus affecting the overall performance. LSM-tree (Log-Structured-Merge-Tree) has the problem of write amplification. Summary of the invention

[0003] In view of the above problems, the present invention provides a data storage method, apparatus, device and storage medium for reducing write amplification.

[0004] According to a first aspect of the present invention, a data storage method is provided, comprising: determining a first target level and a second target level whose level number is greater than that of the first target level from a plurality of levels obtained after configuring a disk according to a log structure merge tree, wherein the first target level comprises a plurality of compression units divided according to at least one first anchor value, the at least one first anchor value being determined according to a key value of a data file in the first target level, the second target level comprises a plurality of compression units divided according to a plurality of second anchor values, the plurality of second anchor values ​​being determined according to the key value of a data file in the second target level, the number of the second anchor values ​​being greater than the number of the first anchor values; in response to determining that the number of data files in a target compression unit in the first target level reaches a first threshold, reading the data files in the target compression unit and merging them to obtain a merged file; and writing the merged file into a compression unit of the second target level that is compatible with the merged file.

[0005] Another aspect of the present invention provides a data storage device, wherein the device includes: a target level determination module, used to determine a first target level and a second target level whose level number is greater than that of the first target level from multiple levels obtained after configuring the disk according to a log structure merge tree, wherein the first target level includes multiple compression units obtained by dividing according to at least one first anchor value, the at least one first anchor value is determined according to a key value of a data file in the first target level, and the second target level includes multiple compression units obtained by dividing according to multiple second anchor values, the multiple second anchor values ​​are determined according to the key value of the data file in the second target level, and the number of the second anchor values ​​is greater than the number of the first anchor values; a merging module, used to read the data files in the target compression unit in response to determining that the number of data files in the first target level reaches a first threshold, and merge them to obtain a merged file; and a merged file writing module, used to write the merged file into a compression unit of the second target level that is compatible with the merged file.

[0006] Another aspect of the present invention provides an electronic device, comprising: one or more processors; a memory for storing one or more computer programs, wherein the one or more processors execute the one or more computer programs to implement the steps of the data storage method.

[0007] Another aspect of the present invention further provides a computer-readable storage medium on which a computer program or instruction is stored. When the computer program or instruction is executed by a processor, the steps of the data storage method are implemented.

[0008] According to the data storage method, apparatus, device and storage medium provided by the present invention, a first target level and a second target level whose number of levels is greater than that of the first target level are determined from multiple levels obtained after configuring the disk according to a log structure merge tree, wherein the first target level includes multiple compression units divided according to at least one first anchor value, and the second target level includes multiple compression units divided according to multiple second anchor values, and the number of second anchor values ​​is greater than the number of first anchor values; in response to determining that the number of data files in the target compression unit in the first target level reaches a first threshold, the data files in the target compression unit are read and merged to obtain a merged file; and a technical means of writing the merged file into a compression unit of the second target level that is compatible with the merged file, by introducing anchor values ​​as an aid, the disk file is divided into smaller compression units, and in the actual merging process, only the final merged file needs to be appended to the compression unit of the next layer in units of compression units, without continuing to read and rewrite the entire files of each level, which can effectively reduce write amplification. BRIEF DESCRIPTION OF THE DRAWINGS

[0009] The above and other objects, features and advantages of the present invention will become more apparent through the following description of the embodiments of the present invention with reference to the accompanying drawings, in which:

[0010] Figure 1 A comparison diagram of an in-situ update structure and a remote update structure according to an embodiment of the present invention is shown;

[0011] Figure 2 The following is an architecture diagram of an LSM-tree according to an embodiment of the present invention;

[0012] Figure 3 The following is an architecture diagram of leveldb according to an embodiment of the present invention;

[0013] Figure 4 A schematic diagram showing merging level 0 and level 1 according to an embodiment of the present invention is shown;

[0014] Figure 5 A schematic diagram showing a merged file after being rewritten into level 1 according to an embodiment of the present invention is shown;

[0015] Figure 6 An application scenario diagram of a data storage method according to an embodiment of the present invention is shown;

[0016] Figure 7 A flow chart of a data storage method according to an embodiment of the present invention is shown;

[0017] Figure 8 A schematic diagram showing the introduction of sentinels to divide the levels in a disk according to an embodiment of the present invention is shown;

[0018] Fig. 9 A schematic diagram showing writing a new data file in memory to level 0 according to an embodiment of the present invention is shown;

[0019] Fig.10 A schematic diagram showing the results of merging data files according to an embodiment of the present invention is shown;

[0020] Fig.11 A schematic diagram showing segmenting a merged file to obtain segmented files according to an embodiment of the present invention is shown;

[0021] Fig.12 A schematic diagram showing the result of writing split files into level 1 according to an embodiment of the present invention;

[0022] Fig.13 A schematic diagram showing writing a data file in a second compression unit in level 1 to level 2 according to an embodiment of the present invention is shown;

[0023] Fig.14 A structural block diagram of a data storage device according to an embodiment of the present invention is shown; and

[0024] Fig.15 A block diagram of an electronic device suitable for implementing a data storage method according to an embodiment of the present invention is shown. DETAILED DESCRIPTION

[0025] Below, embodiments of the present invention will be described with reference to the accompanying drawings. However, it should be understood that these descriptions are exemplary only and are not intended to limit the scope of the present invention. In the following detailed description, for ease of explanation, many specific details are set forth to provide a comprehensive understanding of embodiments of the present invention. However, it is apparent that one or more embodiments may also be implemented without these specific details. In addition, in the following description, descriptions of known structures and technologies are omitted to avoid unnecessary confusion of concepts of the present invention.

[0026] The terms used herein are only for describing specific embodiments and are not intended to limit the present invention. The terms "comprise", "include", etc. used herein indicate the existence of the features, steps, operations and / or components, but do not exclude the existence or addition of one or more other features, steps, operations or components.

[0027] All terms (including technical and scientific terms) used herein have the meanings commonly understood by those skilled in the art unless otherwise defined. It should be noted that the terms used herein should be interpreted as having a meaning consistent with the context of this specification and should not be interpreted in an idealized or overly rigid manner.

[0028] When using expressions such as "at least one of A, B, and C, etc.", they should generally be interpreted according to the meaning of the expression commonly understood by those skilled in the art (for example, "a system having at least one of A, B, and C" should include but is not limited to a system having A alone, B alone, C alone, A and B, A and C, B and C, and / or A, B, C, etc.).

[0029] Before describing the present invention in detail, the following description is given of the relevant contents about LSM-tree.

[0030] LSM-tree uses an out-of-place update writing method, which is different from the in-place update method of B+ tree. This method can avoid the space loss caused by the splitting of B+ tree in update and deletion scenarios.

[0031] Figure 1A comparison diagram of an in-place update structure and a remote update structure according to an embodiment of the present invention is shown.

[0032] like Figure 1 As shown in (a), in the in-place update structure, when the in-place update structure implements data update, the new data (k1, v4) will directly overwrite the old data (k1, v1). Figure 1 As shown in (b), when the out-of-place update structure implements data update, a new space will be created for storing the new data (k1, v4) and the old data (k1, v1) will not be deleted.

[0033] This out-of-place update method was just a prototype and was therefore not widely adopted until the LSM-tree architecture was formally proposed.

[0034] Figure 2 The figure shows an architecture diagram of an LSM-tree according to an embodiment of the present invention.

[0035] From C0, C1, ..., C k Each component is implemented using B±tree. Among them, C0 is in memory, and the other C1,…,C k On disk, when C i When it is full, the merge process will be triggered to merge the leaf nodes of the B±tree within a range into C i+1 However, since each component of the architecture is implemented by B±tree, the complexity is very high. Therefore, the current LSM-tree architecture is different from it, but it is still based on out-of-place update and improves write performance through sequential IO. Take leveldb (an efficient key-value database) as an example. Its architecture is as follows Figure 3 shown.

[0036] Figure 3 The figure shows an architecture diagram of leveldb according to an embodiment of the present invention.

[0037] like Figure 3As shown in the figure, data exists in two components, one is the memory component and the other is the disk component. The memory component is called the memory table (MemTable), while the disk component is an ordered sorted table. The disk component is layered. Since the out-of-place update method will bring redundant data, there may be multiple values ​​corresponding to the same key. Therefore, in order to clean up redundant data and improve reading efficiency, LSM-tree introduces the concept of compaction. For memory files, compaction is to refresh the memory data to the disk. For disk files, compaction is to merge data files with overlapping key-ranges. However, compaction brings about the problem of write amplification, as shown in the following figure. Figure 4 .

[0038] Figure 4 FIG. 4 is a schematic diagram showing a merging of level 0 and level 1 according to an embodiment of the present invention.

[0039] like Figure 4 As shown, the selected part 410 is the file that needs to participate in the compaction, three of which are from level 0 and three from level 1. The level 0 file is flushed from the memory of level 0, and the number of rewrites of the level 1 file is already 1. Figure 4 It can be known that the data range of level 0 + level 1 files is [1..68]. The data file is read into the memory for merging, and then written to level 1 again, such as Figure 5 .

[0040] Figure 5 A schematic diagram showing a merged file after being rewritten into level 1 according to an embodiment of the present invention is shown.

[0041] At this time, the number of key-value rewrites in level 1 is 2. Later, as the upper-layer IO continues to write, level 0 reaches the threshold for compaction and starts to compact with level 1 again. This will cause the key-value of level 1 to be repeatedly read into the memory and repeatedly written, resulting in high write amplification. Taking leveldb as an example, its normal write amplification is up to ten times, which will seriously reduce the life of the disk.

[0042] Many studies in related technologies have attempted to reduce the write amplification of LSM-tree, such as Wisckey (a persistent key-value storage engine based on LSM-tree), which stores key-value separately, with the key stored in the LSM-tree and the value stored in a separate value log file VLOG. Its LSM-tree also stores the address of the value in the value. At this time, only the key and value-index participate in the compaction process. For large values, it can reduce write amplification very well, but it does not have a good advantage for ordinary values. Therefore, it is particularly important to design a universal technology to reduce the write amplification of LSM-tree.

[0043] LSM-tree causes write amplification due to the rewriting of disk files caused by compaction. The root cause is the need to maintain the global order of each layer of disk files, while skipList can be locally ordered. Therefore, the ideas of LSM and SkipList can be combined to reduce write amplification and improve write performance. Its implementation concept is similar to that of skip list. The main idea is to introduce sentinels as an auxiliary to divide disk files into smaller compaction units. During the actual merging process, the final merged files are appended to the next layer instead of being rewritten to the current layer as in the original design. This ensures that the kv pairs in each disk file are only rewritten once in the current layer.

[0044] In view of this, an embodiment of the present invention provides a data storage method, apparatus, device and storage medium, including: determining a first target level and a second target level whose number of levels is greater than that of the first target level from multiple levels obtained after configuring the disk according to a log structure merge tree, wherein the first target level includes multiple compression units obtained by dividing according to at least one first anchor value, at least one first anchor value is determined according to a key value of a data file in the first target level, and the second target level includes multiple compression units obtained by dividing according to multiple second anchor values, multiple second anchor values ​​are determined according to the key value of the data file in the second target level, and the number of second anchor values ​​is greater than the number of first anchor values; in response to determining that the number of data files in a target compression unit in the first target level reaches a first threshold, reading the data files in the target compression unit and merging them to obtain a merged file; and writing the merged file into a compression unit of the second target level that is compatible with the merged file.

[0045] Figure 6 An application scenario diagram of the data storage method according to an embodiment of the present invention is shown.

[0046] like Figure 6As shown, the application scenario 600 according to this embodiment may include a first terminal device 601, a second terminal device 602, a third terminal device 603, a network 604, and a server 605. The network 604 is used to provide a medium for a communication link between the first terminal device 601, the second terminal device 602, the third terminal device 603, and the server 605. The network 604 may include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.

[0047] The user can use the first terminal device 601, the second terminal device 602, and the third terminal device 603 to interact with the server 605 through the network 604 to receive or send messages, etc. The first terminal device 601, the second terminal device 602, and the third terminal device 603 can be deployed with hardware facilities such as memory and disk (only for example).

[0048] The first terminal device 601, the second terminal device 602, and the third terminal device 603 may be various electronic devices having display screens and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.

[0049] The server 605 may be a server that provides various services, such as a background management server (only as an example) that provides support for data processed by the user using the first terminal device 601, the second terminal device 602, and the third terminal device 603. The background management server may analyze and process the received data processing request, etc., and feed back the processing instruction to the terminal device.

[0050] It should be noted that the data storage method provided in the embodiment of the present invention can generally be executed by the server 605. Accordingly, the data storage device provided in the embodiment of the present invention can generally be set in the server 605. The data storage method provided in the embodiment of the present invention can also be executed by a server or server cluster that is different from the server 605 and can communicate with the first terminal device 601, the second terminal device 602, the third terminal device 603 and / or the server 605. Correspondingly, the data storage device provided in the embodiment of the present invention can also be set in a server or server cluster that is different from the server 605 and can communicate with the first terminal device 601, the second terminal device 602, the third terminal device 603 and / or the server 605.

[0051] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0052] The following will be based on Figure 6 The scene described by Figure 7 to Figure 13The data storage method of the disclosed embodiment is described in detail.

[0053] Figure 7 A flow chart of a data storage method according to an embodiment of the present invention is shown.

[0054] like Figure 7 As shown, the data storage method of this embodiment includes operations S710 to S730.

[0055] In operation S710, a first target level and a second target level having a larger number of levels than the first target level are determined from a plurality of levels obtained after configuring the disk according to a log structure merge tree, wherein the first target level includes a plurality of compression units divided according to at least one first anchor value, the at least one first anchor value is determined according to a key value of a data file in the first target level, the second target level includes a plurality of compression units divided according to a plurality of second anchor values, the plurality of second anchor values ​​are determined according to the key value of the data file in the second target level, and the number of the second anchor values ​​is greater than the number of the first anchor values.

[0056] According to an embodiment of the present invention, after configuring the disk according to the LSM-tree, the disk space may include N+1 levels, such as level 0, level 1, ..., level N. The first target level may represent any level of the N levels, such as level n, 0≤n<N, and the second target level may represent level n+j, 1≤j≤Nn.

[0057] According to an embodiment of the present invention, sentinels for dividing each level into smaller compaction units can be determined based on anchor values. The first anchor value configured for the first target level and the second anchor value configured for the second target level can be completely different or partially the same, that is, the multiple second anchor values ​​can include the same anchor value as the first anchor value, which is not limited here.

[0058] Figure 8 A schematic diagram showing the introduction of sentinels to divide the levels in a disk according to an embodiment of the present invention is shown.

[0059] like Figure 8 As shown, the disk space includes at least three levels: level 0, level 1, and level 2. Level 1 can be divided into three compression units by anchor values ​​such as 15 and 70. Level 2 can be divided into five compression units by anchor values ​​such as 15, 40, 70, and 95. The anchor values ​​15, 40, 70, and 95 used as sentinels in level 2 can include the anchor values ​​15 and 70 used as sentinels in level 1.

[0060] According to an embodiment of the present invention, the following Figure 8 The hierarchical structures shown are configured with the following preset conditions: In the same level, the key ranges of different sentinel areas do not overlap. Taking level 1 as an example, the key range of data files before sentinel 15 does not overlap with the key range of data files between sentinels 15-70. In the same level, the key ranges of data files in the same sentinel area may overlap. For example, in level 2, there are two data files between sentinels 15 and 40, and the key ranges of the two data files may overlap. As the number of levels increases, the sentinel granularity becomes more detailed. Restrictions based on these preset conditions can effectively reduce write amplification during the compaction process.

[0061] According to an embodiment of the present invention, Figure 8 As shown, since level 0 is used to receive data flushed from the memory, level 0 may not be divided by anchor value, so that multiple data files can overlap at level 0. Based on this, level 0 of the multiple levels can directly constitute a compression unit. In response to determining that the size of the data written to the memory reaches the second threshold, the data written to the memory can be directly written to level 0 as a new data file.

[0062] According to an embodiment of the present invention, the second threshold value may be determined according to the amount of data that can be stored in the memory. For example, the second threshold value may be one quarter of the memory size, or may be other values ​​according to business requirements, etc., which are not limited here.

[0063] Fig. 9 A schematic diagram showing writing a new data file in the memory into level 0 according to an embodiment of the present invention is shown.

[0064] like Fig. 9 As shown, at a certain moment, some data [30..68] is written into the memory, and its data size reaches the second threshold and will be refreshed to level 0.

[0065] In this way, the 0th level can quickly receive the data flushed from the memory, reducing some additional time-consuming operations required to keep the disk data files strictly ordered.

[0066] In operation S720, in response to determining that the number of data files in the target compression unit in the first target level reaches a first threshold, the data files in the target compression unit are read and merged to obtain a merged file.

[0067] According to an embodiment of the present invention, a data file may represent files written synchronously in batches at various levels, such as Fig. 9[2..37] or [23..48] etc. in level 0 of the structure shown, or Fig. 9 [77..87] or [82..95], etc. in level 1 of the structure shown.

[0068] According to an embodiment of the present invention, the first threshold may be determined based on the maximum number of data files that may have overlapping key ranges in the same sentinel region at the same level.

[0069] According to an embodiment of the present invention, the data files in the target compression unit that reaches the first threshold may include at least a first data file and a second data file. The above operation S720 may include: after reading the first data file and the second data file, if it is determined that there is no overlapping key value between the two, the first data file and the second data file may be directly combined to obtain a merged file.

[0070] According to an embodiment of the present invention, the data file includes at least one data record, and the data record is assigned a serial number when it is written into the memory, and the value of the serial number assigned to the data record written into the memory later is greater than the value of the serial number assigned to the data record written into the memory earlier.

[0071] According to an embodiment of the present invention, the sequence number can be used to locate which data record is the latest data record written into the memory.

[0072] According to an embodiment of the present invention, a serial number may be assigned to a data record in units of a preset time period, and the serial numbers of all data records in each preset time period may be the same, and the serial number of a data record in a subsequent preset time period may be greater than the serial number of a data record in a previous preset time period. This situation may be applicable to a data storage situation where updating of data is prohibited in a preset time period.

[0073] According to an embodiment of the present invention, the data record may be used as a unit, and the value of the sequence number assigned to the data record written into the memory later is greater than the value of the sequence number assigned to the data record written into the memory earlier. This situation is applicable to various data storage situations. The allocation method of the sequence number is not limited to this.

[0074] It should be noted that the sequence number may not be set, and this situation is only applicable to the case where data can only be written but not updated. In this corresponding situation, by reading the data files in the target compression unit, the merged file can be directly obtained.

[0075] According to an embodiment of the present invention, the above operation S720 may further include: reading the first data file and the second data file. When the key value of the first data record in the first data file is consistent with the key value of the second data record in the second data file, determining the target data record with a larger sequence number according to the first sequence number of the first data record and the second sequence number of the second data record. Determine the merged file according to the target data record, the first other data record except the first data record in the first data file, and the second other data record except the second data record in the second data file.

[0076] For example, assume that the first threshold value set for the compression unit corresponding to level 0 is 3. Fig. 9 After the process shown, the data files in level 0 include [2..37], [23..48], and [30..68], reaching the first threshold of 3. Then, these data files are merged. Each value in the three data files represents a key value. Since the same key value exists in the three data files, and since [30..68] is the latest data written into the memory, it can be determined that the serial number of the data record corresponding to each key value in [30..68] is greater than the serial number of the data record corresponding to each key value in [2..37] and [23..48]. In the merging process, based on the principle that for the same key value, the data record corresponding to the key value with a higher serial number covers the data record corresponding to the key value with a lower serial number, [2..37], [23..48], and [30..68] can be merged to obtain the merged file [2..68].

[0077] Fig.10 A schematic diagram after merging data files according to an embodiment of the present invention is shown.

[0078] like Fig.10 As shown, the memory can read the data files [2..37], [23..48], and [30..68] in level 0, perform the above merging process, and record the merged file [2..68].

[0079] In operation S730, the merged file is written into a compression unit of the second target level that is compatible with the merged file.

[0080] According to an embodiment of the present invention, a merged file may include multiple data records. When the key value of each data record in the merged file is within the range determined by two adjacent second anchor point values ​​in the second target level, the merged file can be directly written into the compression unit determined by the two adjacent second anchor point values.

[0081] According to an embodiment of the present invention, when the key values ​​of the data records in the merged file are respectively located in different ranges determined by different second anchor point values ​​in the second target level, the operation S730 may further include: comparing the key values ​​of the plurality of data records with at least one second anchor point value to obtain a comparison result, and writing each of the plurality of data records into a compression unit of the second target level adapted to each data record according to the comparison result.

[0082] According to an embodiment of the present invention, the comparison result may be characterized as the key value being less than the second anchor value, or the key value being greater than or equal to the second anchor value, etc. In the case where it is determined that the key value is less than the second anchor value, the key value may be compared with the anchor value on the left side of the second anchor value used for comparison to further determine the range to which the data record corresponding to the key value should be allocated, and the data record may be directly written into the range. In the case where it is determined that the key value is greater than or equal to the second anchor value, the key value may be compared with the anchor value on the right side of the second anchor value used for comparison to further determine the range to which the data record corresponding to the key value should be allocated, and the data record may be directly written into the range.

[0083] According to an embodiment of the present invention, the operation S730 may further include: segmenting the data records in the merged file according to at least one second anchor value to obtain segmented files, and writing the segmented files into compression units of the second target level that are compatible with the segmented files.

[0084] Fig.11 A schematic diagram showing segmentation of a merged file to obtain segmented files according to an embodiment of the present invention is shown.

[0085] According to an embodiment of the present invention, in the memory based on Fig.10 In the case where the process shown obtains the merged file [2..68] from level 0, the merged file [2..68] is to be written to level 1. Based on the principle that each layer must meet the above preset conditions, such as Fig.11 As shown, the second anchor value 15 as a sentinel in level 1 can be read, and the merged file can be split to obtain split files [2..14] and [15..68]. Afterwards, the split files [2..14] and [15..68] can be written into the compression unit adapted to level 1.

[0086] Fig.12 A schematic diagram showing the result of writing split files into level 1 according to an embodiment of the present invention.

[0087] According to an embodiment of the present invention, for example, the second threshold of the data file set for each compression unit of level 1 is 2.

[0088] like Fig.12 As shown in the figure, after the split files [2..14] and [15..68] are written to level 1, the first compression unit and the second compression unit in level 1 both reach the threshold of 2. The above method can be combined to perform compaction operations on the data files [2..14] and [1..12] in the first compression unit in level 1, and the data files [15..68] and [15..59] in the second compression unit in level 1, including merging and rewriting processes.

[0089] Fig.13 A schematic diagram showing writing a data file in a second compression unit in level 1 to level 2 according to an embodiment of the present invention is shown.

[0090] like Fig.13 As shown, the data files [15..68] and [15..59] in the second compression unit in level 1 can be first read into the memory, and combined with the above-mentioned merging method, the merged file [15..68] can be obtained. Then, the anchor point value in level 2 can be read, for example, it can be determined to be 40 by comparison, and the merged file [15..68] can be split to obtain the split files [15..39] and [40..68]. After that, the split files [15..39] and [40..68] can be written into the compression unit adapted to level 2.

[0091] Through the above embodiments of the present invention, a method for optimizing the write amplification problem of the LSM-tree engine in combination with a skip table is implemented. By introducing anchor value as an aid, the disk file is divided into smaller compaction units. In the actual merging process, it is only necessary to append the final merged file to the compression unit of the next layer in units of compression units, instead of reading the entire file of each layer and rewriting it to the current layer as in the original design. In this way, it can be ensured that the data files of each layer in the scheduled disk file are only written once each time, effectively reducing the write amplification problem.

[0092] Based on the above data storage method, the present invention also provides a data storage device. Fig.14 The device is described in detail.

[0093] Fig.14 A structural block diagram of a data storage device according to an embodiment of the present invention is shown.

[0094] like Fig.14 As shown, the data storage device 1400 includes a target level determination module 1410 , a merging module 1420 , and a writing module 1430 .

[0095] The target level determination module 1410 is used to determine a first target level and a second target level whose level number is greater than that of the first target level from multiple levels obtained after configuring the disk according to a log structure merge tree, wherein the first target level includes multiple compression units divided according to at least one first anchor value, and the at least one first anchor value is determined according to a key value of a data file in the first target level; the second target level includes multiple compression units divided according to multiple second anchor values, and the multiple second anchor values ​​are determined according to the key value of the data file in the second target level, and the number of the second anchor values ​​is greater than the number of the first anchor values.

[0096] The merging module 1420 is configured to read and merge the data files in the target compression unit in response to determining that the number of data files in the target compression unit in the first target level reaches a first threshold value to obtain a merged file.

[0097] The merged file writing module 1430 is used to write the merged file into a compression unit of the second target level that is compatible with the merged file.

[0098] According to an embodiment of the present invention, the multiple levels include level 0, and level 0 constitutes a compression unit. The data storage device also includes a new file writing module.

[0099] The new file writing module is used to write the data written into the memory as a new data file into the 0th level in response to determining that the size of the data written into the memory reaches a second threshold.

[0100] According to an embodiment of the present invention, the data file includes at least one data record, and the data record is assigned a serial number when it is written into the memory, and the value of the serial number assigned to the data record written into the memory later is greater than the value of the serial number assigned to the data record written into the memory earlier.

[0101] According to an embodiment of the present invention, the plurality of second anchor point values ​​include an anchor point value that is the same as the first anchor point value.

[0102] According to an embodiment of the present invention, the data files in the target compression unit include at least a first data file and a second data file. The merging module includes a data file reading unit, a target data record determining unit and a merge file determining unit.

[0103] The data file reading unit is used to read the first data file and the second data file.

[0104] The target data record determination unit is used to determine the target data record with a larger serial number based on the first serial number of the first data record and the second serial number of the second data record when the key value of the first data record in the first data file is consistent with the key value of the second data record in the second data file.

[0105] The merge file determining unit is used to determine the merge file according to the target data record, the first other data record except the first data record in the first data file, and the second other data record except the second data record in the second data file.

[0106] According to an embodiment of the present invention, the merged file includes multiple data records. The merged file writing module includes a comparison unit and a merged file writing unit.

[0107] The comparison unit is used to compare the key values ​​of the multiple data records with at least one second anchor point value to obtain a comparison result.

[0108] The merge file writing unit is used to write each data record of the multiple data records into a compression unit of the second target level that is adapted to each data record according to the comparison result.

[0109] According to an embodiment of the present invention, the merged file writing module includes a segmentation unit and a segmented file writing unit.

[0110] The segmentation unit is used to segment the data records in the merged file according to at least one second anchor point value to obtain segmented files.

[0111] The split file writing unit is used to write the split files into compression units of the second target level that are adapted to the split files.

[0112] According to an embodiment of the present invention, any multiple modules of the target level determination module 1410, the merging module 1420 and the writing module 1430 can be combined into one module for implementation, or any one of the modules can be split into multiple modules. Alternatively, at least part of the functions of one or more of these modules can be combined with at least part of the functions of other modules and implemented in one module. According to an embodiment of the present invention, at least one of the target level determination module 1410, the merging module 1420 and the writing module 1430 can be at least partially implemented as a hardware circuit, such as a field programmable gate array (FPGA), a programmable logic array (PLA), a system on a chip, a system on a substrate, a system on a package, an application-specific integrated circuit (ASIC), or can be implemented by hardware or firmware such as any other reasonable way of integrating or packaging the circuit, or implemented in any one of the three implementation methods of software, hardware and firmware or in any appropriate combination of any of them. Alternatively, at least one of the target level determination module 1410, the merging module 1420 and the writing module 1430 can be at least partially implemented as a computer program module, and when the computer program module is run, the corresponding function can be executed.

[0113] Fig.15 A block diagram of an electronic device suitable for implementing a data storage method according to an embodiment of the present invention is shown.

[0114] like Fig.15 As shown, the electronic device 1500 according to an embodiment of the present invention includes a processor 1501, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 1502 or the program loaded from the storage part 1508 to the random access memory (RAM) 1503. The processor 1501 may include, for example, a general-purpose microprocessor (such as a CPU), an instruction set processor and / or a related chipset and / or a special-purpose microprocessor (for example, an application-specific integrated circuit (ASIC)), etc. The processor 1501 may also include an onboard memory for caching purposes. The processor 1501 may include a single processing unit or multiple processing units for performing different actions of the method flow according to an embodiment of the present invention.

[0115] In RAM 1503, various programs and data required for the operation of electronic device 1500 are stored. Processor 1501, ROM 1502 and RAM 1503 are connected to each other via bus 1504. Processor 1501 performs various operations of the method flow according to the embodiment of the present invention by executing the programs in ROM 1502 and / or RAM 1503. It should be noted that the program can also be stored in one or more memories other than ROM 1502 and RAM 1503. Processor 1501 can also perform various operations of the method flow according to the embodiment of the present invention by executing the programs stored in the one or more memories.

[0116] According to an embodiment of the present invention, the electronic device 1500 may further include an input / output (I / O) interface 1505, which is also connected to the bus 1504. The electronic device 1500 may further include one or more of the following components connected to the input / output (I / O) interface 1505: an input portion 1506 including a keyboard, a mouse, etc.; an output portion 1507 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage portion 1508 including a hard disk, etc.; and a communication portion 1509 including a network interface card such as a LAN card, a modem, etc. The communication portion 1509 performs communication processing via a network such as the Internet. A drive 1510 is also connected to the input / output (I / O) interface 1505 as needed. A removable medium 1511, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1510 as needed, so that a computer program read therefrom is installed into the storage portion 1508 as needed.

[0117] The present invention also provides a computer-readable storage medium, which may be included in the device / apparatus / system described in the above embodiment; or may exist independently without being assembled into the device / apparatus / system. The above computer-readable storage medium carries one or more programs, and when the above one or more programs are executed, the method according to the embodiment of the present invention is implemented.

[0118] According to an embodiment of the present invention, the computer-readable storage medium may be a non-volatile computer-readable storage medium, for example, it may include but is not limited to: a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination thereof. In the present invention, the computer-readable storage medium may be any tangible medium containing or storing a program, which may be used by or in combination with an instruction execution system, an apparatus or a device. For example, according to an embodiment of the present invention, the computer-readable storage medium may include the ROM 1502 and / or RAM 1503 described above and / or one or more memories other than ROM 1502 and RAM 1503.

[0119] The embodiment of the present invention also includes a computer program product, which includes a computer program, and the computer program contains program code for executing the method shown in the flowchart. When the computer program product is run in a computer system, the program code is used to enable the computer system to implement the data storage method provided by the embodiment of the present invention.

[0120] The computer program executes the above functions defined in the system / device of the embodiment of the present invention when it is executed by the processor 1501. According to the embodiment of the present invention, the system, device, module, unit, etc. described above can be implemented by a computer program module.

[0121] In one embodiment, the computer program may rely on tangible storage media such as optical storage devices, magnetic storage devices, etc. In another embodiment, the computer program may also be transmitted and distributed in the form of signals on a network medium, and downloaded and installed through the communication part 1509, and / or installed from the removable medium 1511. The program code contained in the computer program may be transmitted using any appropriate network medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.

[0122] In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 1509, and / or installed from the removable medium 1511. When the computer program is executed by the processor 1501, the above functions defined in the system of the embodiment of the present invention are performed. According to the embodiment of the present invention, the system, device, means, module, unit, etc. described above can be implemented by a computer program module.

[0123] According to an embodiment of the present invention, the program code for executing the computer program provided by the embodiment of the present invention can be written in any combination of one or more programming languages. Specifically, these computing programs can be implemented using high-level process and / or object-oriented programming languages, and / or assembly / machine languages. Programming languages ​​include, but are not limited to, Java, C++, python, "C" language or similar programming languages. The program code can be executed entirely on the user computing device, partially on the user device, partially on the remote computing device, or entirely on the remote computing device or server. In the case of a remote computing device, the remote computing device can be connected to the user computing device through any type of network, including a local area network (LAN) or a wide area network (WAN), or can be connected to an external computing device (e.g., using an Internet service provider to connect through the Internet).

[0124] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0125] It will be appreciated by those skilled in the art that the features described in the various embodiments and / or claims of the present invention may be combined and / or combined in various ways, even if such combinations and / or combinations are not explicitly described in the present invention. In particular, the features described in the various embodiments and / or claims of the present invention may be combined and / or combined in various ways without departing from the spirit and teachings of the present invention. All of these combinations and / or combinations fall within the scope of the present invention.

[0126] The embodiments of the present invention are described above. However, these embodiments are only for the purpose of illustration, and are not intended to limit the scope of the present invention. Although each embodiment is described above, it does not mean that the measures in each embodiment cannot be used in combination. The scope of the present invention is defined by the attached claims and their equivalents. Without departing from the scope of the present invention, those skilled in the art may make various substitutions and modifications, which should all fall within the scope of the present invention.

Claims

1. A data storage method, characterized in that: The method comprises: Determine a first target level and a second target level having a number of levels greater than that of the first target level from a plurality of levels obtained after configuring the disk according to the log structure merge tree, wherein the first target level includes a plurality of compression units divided according to at least one first anchor value, the at least one first anchor value being determined according to a key value of a data file in the first target level, the second target level includes a plurality of compression units divided according to a plurality of second anchor values, the plurality of second anchor values ​​being determined according to the key value of the data file in the second target level, and the number of the second anchor values ​​being greater than the number of the first anchor values; In response to determining that the number of data files in the target compression unit in the first target level reaches a first threshold, reading and merging the data files in the target compression unit to obtain a merged file; and The merged file is written into a compression unit of the second target level that is compatible with the merged file.

2. The method according to claim 1, characterized in that: The plurality of levels include level 0, and the level 0 constitutes a compression unit; the method further includes: In response to determining that the size of the data written to the memory reaches a second threshold, the data written to the memory is written to the 0th level as a new data file.

3. The method according to claim 1 or 2, characterized in that: The data file includes at least one data record, and the data record is assigned a serial number when being written into the memory, and the serial number assigned to the data record written into the memory later is greater than the serial number assigned to the data record written into the memory earlier.

4. The method according to claim 1, characterized in that: The plurality of second anchor point values ​​include an anchor point value that is the same as the first anchor point value.

5. The method according to claim 1, characterized in that The data files in the target compression unit at least include a first data file and a second data file; and the step of reading the data files in the target compression unit and merging them to obtain a merged file includes: Reading the first data file and the second data file; If the key value of the first data record in the first data file is consistent with the key value of the second data record in the second data file, determine the target data record with a larger sequence number according to the first sequence number of the first data record and the second sequence number of the second data record; and The merged file is determined according to the target data record, a first other data record in the first data file except the first data record, and a second other data record in the second data file except the second data record.

6. The method according to claim 1, characterized in that The merged file includes a plurality of data records; the compression unit adapted to the merged file and writing the merged file to the second target level includes: Compare the key values ​​of the plurality of data records with the at least one second anchor value to obtain a comparison result; and Each data record of the plurality of data records is written into a compression unit of the second target level that is adapted to the each data record according to the comparison result.

7. The method according to claim 1, characterized in that The compression unit adapted to the merged file and writing the merged file to the second target level includes: Segmenting the data records in the merged file according to the at least one second anchor point value to obtain segmented files; and The split files are respectively written into compression units of the second target level that are adapted to the split files.

8. A data storage device, characterized in that: The device comprises: a target level determination module, configured to determine a first target level and a second target level whose level number is greater than that of the first target level from a plurality of levels obtained after configuring the disk according to a log structure merge tree, wherein the first target level includes a plurality of compression units obtained by partitioning according to at least one first anchor value, the at least one first anchor value is determined according to a key value of a data file in the first target level, the second target level includes a plurality of compression units obtained by partitioning according to a plurality of second anchor values, the plurality of second anchor values ​​are determined according to the key value of the data file in the second target level, and the number of the second anchor values ​​is greater than the number of the first anchor values; a merging module, configured to read and merge the data files in the target compression unit in response to determining that the number of data files in the target compression unit in the first target level reaches a first threshold, to obtain a merged file; and The merged file writing module is used to write the merged file into a compression unit of the second target level that is compatible with the merged file.

9. An electronic device, comprising: one or more processors; a memory for storing one or more computer programs, It is characterized in that the one or more processors execute the one or more computer programs to implement the steps of the method according to any one of claims 1 to 7.

10. A computer-readable storage medium having a computer program or instruction stored thereon, characterized in that: When the computer program or instruction is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.

Citation Information

Patent Citations

  • A data merging method and device applied to a key value storage system

    CN109271343A

  • Data deduplication method and device, equipment and storage medium

    CN114115734A

  • Data storage method, system and equipment based on log structure merging tree

    CN116301656A

  • Data storage method and device, processing equipment and storage medium

    CN116774937A