WO2022033099A1 - Index construction method and apparatus - Google Patents

Index construction method and apparatus Download PDF

Info

Publication number
WO2022033099A1
WO2022033099A1 PCT/CN2021/094068 CN2021094068W WO2022033099A1 WO 2022033099 A1 WO2022033099 A1 WO 2022033099A1 CN 2021094068 W CN2021094068 W CN 2021094068W WO 2022033099 A1 WO2022033099 A1 WO 2022033099A1
Authority
WO
WIPO (PCT)
Prior art keywords
physical block
keyword
key
prediction model
location
Prior art date
Application number
PCT/CN2021/094068
Other languages
French (fr)
Chinese (zh)
Inventor
任仁
王晨
Original Assignee
华为技术有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2022033099A1 publication Critical patent/WO2022033099A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • G06F3/0601Interfaces specially adapted for storage systems
    • G06F3/0628Interfaces specially adapted for storage systems making use of a particular technique
    • G06F3/0638Organizing or formatting or addressing of data
    • G06F3/064Management of blocks
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/17Details of further file system functions
    • G06F16/176Support for shared access to files; File sharing support
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/22Indexing; Data structures therefor; Storage structures
    • G06F16/2228Indexing structures
    • G06F16/2246Trees, e.g. B+trees
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2453Query optimisation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F3/00Input arrangements for transferring data to be processed into a form capable of being handled by the computer; Output arrangements for transferring data from processing unit to output unit, e.g. interface arrangements
    • G06F3/06Digital input from, or digital output to, record carriers, e.g. RAID, emulated record carriers or networked record carriers
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q10/00Administration; Management
    • G06Q10/04Forecasting or optimisation specially adapted for administrative or management purposes, e.g. linear programming or "cutting stock problem"

Definitions

  • the present application relates to the field of storage technologies, and in particular, to a method and apparatus for constructing an index.
  • the storage device creates a corresponding index for the data, and the index provides a pointer to the data. In this way, during data retrieval, the storage device can quickly find corresponding data based on the index, thereby realizing fast data access.
  • Embodiments of the present application provide a method and apparatus for constructing an index, so as to construct an index for quickly searching data.
  • an embodiment of the present application provides a method for constructing an index, and the method can be applied to a storage device.
  • the storage device may associate a first physical block with a second logical segment, where the first physical block stores a first keyword and a first value corresponding to the first keyword, where the first keyword is associated with The first storage position of the first keyword in the first physical block satisfies the first position prediction model corresponding to the first logical segment.
  • the first position prediction model can be used to predict the key The position of the word on the first physical block.
  • the storage device may determine the second key stored in the second physical block and the second storage location of the second key in the second physical block Whether the first position prediction model is satisfied, the second physical block also stores a second value corresponding to the second keyword.
  • the second keyword and the second storage location do not satisfy the first location prediction model, it means that the location of the keyword on the second physical block cannot be more accurately predicted by using the first location prediction model.
  • the storage device can The second physical block is associated with the second logical segment, and the second key and the second storage location satisfy the second location prediction model corresponding to the second logical segment.
  • the keywords stored on each physical block and the storage location of the keywords in the physical blocks satisfy the corresponding position prediction model, in this way, when retrieving data based on the index, it is possible to search for
  • the keyword and the corresponding position prediction model are used to determine the physical block where the keyword is located, so that the value corresponding to the keyword can be found in the physical block.
  • the storage device associates logical segments with physical blocks as a unit, the different keywords in each physical block and the storage location of the keyword in the physical block satisfy the same location prediction model.
  • the physical block where the keyword is located can usually be predicted, and the value corresponding to the keyword can be found in the physical block, instead of searching for the value corresponding to the keyword from multiple physical blocks, Thereby, the number of accesses to physical blocks can be reduced.
  • the storage device minimizes the number of physical blocks accessed each time, that is, the location prediction model of each physical block in the constructed index can accurately predict the location of each key on the physical block, or If one location prediction model can at least predict the physical block corresponding to any known keyword, a larger number of location prediction models need to be recorded in the constructed index (for example, one location prediction model is recorded for each physical block, etc.) , which makes the storage device need more storage space to store the index.
  • the number of location prediction models is reduced, the accuracy of the location corresponding to the keyword predicted by the storage device may not be high. Therefore, in practical applications, the balance between storage space and retrieval performance can be achieved by controlling the maximum number of physical blocks that are allowed to be accessed each time the storage device performs index retrieval.
  • the storage device can continue to associate the second physical block with the first logical segment. In this way, the position of each keyword on the two physical blocks can be predicted by using a position prediction model.
  • the second keyword and the second storage location of the second keyword on the second physical block satisfy the first location prediction model
  • the second keyword calculates the predicted position of the second key in the second physical block by using the first position prediction wear resistance, and compare the predicted position with the actual second storage position of the second key in the second physical block.
  • the error is within the preset error range, if it does not exceed the preset error range, it can be determined that the second keyword and the second storage location of the second keyword on the second physical block satisfy the first location prediction model, and if it exceeds If the error range is preset, it can be determined that the second key and the second storage location of the second key on the second physical block do not satisfy the first location prediction model.
  • the storage device can also build an upper-level index for the first logical segment and the second logical segment. , the storage device may write a third keyword and a third value corresponding to the third keyword into the index block, where the third keyword may include a keyword in a physical block associated with the first logical segment, and, The third value includes the model description value of the first location prediction model and the first address of the first physical block.
  • the storage device can determine the location prediction model of the lower-level index corresponding to the keyword to be retrieved according to the location prediction model of the upper-level index, so as to further predict the keyword to be retrieved according to the location prediction model of the lower-level index
  • the physical block or the location on the physical block.
  • the first position prediction model includes a linear fitting function
  • the model description value of the first position prediction model includes the inverse slope of the linear fitting function.
  • the position prediction model may also be a nonlinear fitting function, such as a neural network, etc., which can predict the physical block corresponding to the keyword or the position on the physical block.
  • the reciprocal slope corresponding to the first position prediction model may be determined by rounding the average value of the difference between two adjacent keywords on the first physical block.
  • the association between the first logical segment and the first physical block, and the association between the second logical segment and the second physical block may be located in a subtree index structure of the LSM tree.
  • the subtrees in the LSM tree can include learning indexes and index structures that support data modification, insertion, and update, and the index structure that supports data modification, insertion, and update accommodates a small amount of data, which is much smaller than that of learning indexes.
  • the amount of data contained in the index allows the LSM tree to take advantage of the performance and cost of the learning index, and the LSM can also support data modification, insertion and update.
  • an embodiment of the present application further provides a device for constructing an index, configured to execute the method described in any one of the implementation manners of the first aspect.
  • an embodiment of the present application further provides a device for constructing an index.
  • the device includes a memory and a processor, where the processor is configured to execute instructions stored in the memory to execute any one of the implementations of the first aspect. the described method.
  • a fourth aspect of the present application provides a computer-readable medium, where instructions are stored in the computer-readable medium, which, when executed on a computer, cause the computer to execute the methods described in the above aspects.
  • a fifth aspect of the present application provides a computer program product, which, when run on a computer, causes the computer to execute the methods described in the above aspects.
  • FIG. 1 is a schematic flowchart of a method for constructing an index in an embodiment of the present application
  • FIG. 2 is a schematic diagram of writing a key-value pair to a physical block
  • FIG. 3 is a schematic diagram of a physical block associated with a first logical segment or a second logical segment
  • FIG. 4 is a schematic diagram of a four-layer index structure constructed in an embodiment of the present application.
  • Fig. 5 is the structural representation of LSM tree
  • Fig. 6 is the data scale schematic diagram of each layer subtree of LSM tree
  • FIG. 7 is a schematic structural diagram of an indexing device provided by an embodiment of the present application.
  • FIG. 8 is a schematic structural diagram of an apparatus for constructing an index provided by an embodiment of the present application.
  • the embodiments of the present application propose a method and apparatus for constructing an index, so as to construct an index for quickly searching data.
  • the storage device can be a server or a controller in a storage array.
  • the storage device can not only store data, but also store an index corresponding to the data at the same time, so that the data can be quickly accessed based on the index.
  • the method may include:
  • the storage device associates a first physical block with a first logical segment, the first physical block stores a first keyword and a first value corresponding to the first keyword, and the first keyword and the first keyword The first storage location in the first physical block satisfies the first location prediction model corresponding to the first logical segment.
  • a storage device can index data in a database based on key-value pairs.
  • a key-value pair which can also be called a name-value pair or an attribute-value pair, includes a key and a value corresponding to the key, and the value can usually be metadata.
  • the keyword is used to identify the metadata (value)
  • the metadata is the data describing the data, and is used to describe the attribute (feature) information of the data stored in the database.
  • the metadata can be a file of the data stored in the database. name, or the storage address pointer of the data, etc.
  • multiple key-value pairs may be sorted in sequence according to the value of the keyword (key value), and the multiple key-value pairs may be written into the first physical block according to the sorting order.
  • the first physical block may have a size of 4K or 8K bytes, which is a friendly granularity of the persistent layer data to the disk (of course, the first physical block may also be of other sizes, which is not limited in this embodiment).
  • the key written in the first physical block is referred to as the first key
  • the value written in the first physical block is referred to as the first value.
  • the first keyword may be one or more keywords, and correspondingly, the first value may also be one or more values.
  • the key-value pair may be written into the first physical block based on the writing manner shown in FIG. 2 .
  • the key1 in the first key-value pair can be written from the position where the block header of the first physical block ends, and the first key-value pair can be written from the end of the first physical block value1 in .
  • the type of the value1 (value type1) can also be written at the same time. Then, continue to write key2 in the second key-value pair from the position where key1 ends, and write value2 in the second key-value pair and the type of value2 (value type2) from the previous position of value1.
  • multiple keys such as key1, key2, key3, and key4 can be written into the first physical block in sequence (that is, the first key above), and value1, value2, value3, and value4 can be written in sequence. value (that is, the above-mentioned first value), until the remaining storage space in the first physical block cannot continue to write new key-value pairs, it can be considered that the first physical block is filled with data.
  • the block header in the first physical block can record the relevant information of the first physical block, for example, can include the cyclic redundancy check (cyclic redundancy check, CRC) code of the first physical block, the number of key-value pairs, Information such as the type of the first physical block (for example, it may be a fixed-length type or a variable-length type, etc.), the location of the first physical block in the logical segment, and the like.
  • CRC cyclic redundancy check
  • the key-value pair writing method shown in FIG. 2 is only used as an exemplary description, and is not used to limit the writing method of the key-value pair.
  • the first physical block can be associated with a first logical segment.
  • the first logical block corresponds to a first position prediction model, and the first position prediction model can predict the position of the keyword on the physical block associated with the first logical block according to the input keyword.
  • the first location prediction model may be determined based on the first key stored in the first physical block and the first storage location of the first key in the first physical block.
  • the first position prediction model may be, for example, a monotonic fitting function
  • the storage device may be based on the value of each keyword in the first physical block and the value of each keyword in the first physical block Perform function fitting to obtain a fitting function that represents a monotonically increasing or monotonically decreasing value of the storage location as the key value increases, that is, the above-mentioned first position prediction model.
  • the monotonic fitting function may be a linear fitting function as shown in the following formula (1):
  • the slot of the keyword to be retrieved (the keyword to be retrieved – the starting keyword) / the reciprocal slope + the starting slot position (1)
  • the keyword to be retrieved refers to the keyword to be searched;
  • the starting keyword refers to the first keyword stored in the first physical block, such as key1 shown in Figure 2;
  • the starting slot position It refers to the slot where the first key is stored in the first physical block, and its value can be 0 (of course, it can also be other values such as 1);
  • the reciprocal slope can be calculated by calculating two adjacent keywords in the first physical block. The average of the differences between the values is rounded up. Since the reciprocal slope is rounded, floating-point operations can be omitted when calculating the slot positions of keywords based on formula (1), which can reduce the computational overhead required for predicting keyword operations. At the same time, it can also flexibly support keys of different lengths.
  • the monotonic fitting function can also be other linear fitting functions, for example, it can be suitable for the transformation of formula (1); Or the monotonically decreasing transformation principle.
  • the specific presentation form of the monotonic fitting function is not limited.
  • the value of the keyword stored in the first physical block may have uneven local distribution in space, and the monotonic fitting function obtained by fitting may not be able to accurately predict the slot corresponding to each keyword. Therefore, there may be a certain error in predicting the slot position of the keyword to be retrieved in the first physical block based on the monotonic fitting function.
  • function fitting it is possible to verify the relationship between the position of each keyword on the first physical block predicted by the function obtained by fitting and the actual position of the keyword on the first physical block.
  • the function can be used as the above-mentioned monotonic fitting function, and if not, the function can be re-fitted , until a monotonic fitting function that meets the conditions is fitted.
  • the storage device may be to associate the keyword to be retrieved with one or more slots near the predicted slot. The stored keywords are compared to determine the actual location where the keyword to be retrieved is stored in the first physical block.
  • the storage device may determine the position of the value corresponding to the keyword to be retrieved in the first physical block based on the keyword and the writing manner of the value corresponding to the keyword in the first physical block. Taking the writing method shown in Figure 2 as an example, if it is determined that the keyword to be retrieved is located in the third slot of the first physical block, it can be read from the third-to-last position where the value is stored in the first physical block. to the value3 corresponding to the keyword to be retrieved.
  • the first position prediction model takes the first position prediction model as an example of a monotonic fitting function.
  • the first position prediction model may also be in other forms, such as a non-monotonic function, Or it could be a machine learning model, etc.
  • the first position prediction model may be any model that can be used to predict the position of a keyword on a physical block, and is not limited to the above monotonic fitting function.
  • the storage device may continue to write other keywords and values corresponding to the other keywords to the second physical block, and continue to perform step S102 to determine whether to add the second physical block to the second physical block.
  • the block is also associated with the second logical segment.
  • the storage device may also write the key-value pair into the first physical block and the second physical block in advance, and then associate each physical block with the corresponding logical segment, which is not limited in this embodiment.
  • the key written in the second physical block is referred to as the second key
  • the value written in the second physical block is referred to as the second value.
  • the storage device determines whether the second keyword stored in the second physical block and the second storage location of the second keyword in the second physical block satisfy the first position prediction model, wherein the second physical block also A second value corresponding to the second key is stored, and the second physical block is adjacent to the first physical block.
  • the storage device may include a plurality of consecutive physical blocks for storing key-value pairs, and the first physical block and the second physical block are two adjacent physical blocks in the plurality of physical blocks. Normally, the tail address of the first physical block is continuous with the head address of the second physical block.
  • the storage device may use the first position prediction model to predict the position of each key in the first physical block, and the prediction error is small or the prediction accuracy rate is high. Further, the storage device may also check whether the first location prediction model can be used to predict the location of each key in the second physical block. If the deviation between the position of each keyword on the second physical block predicted by the first position prediction model and the actual position of the keyword on the second physical block is within a preset error range, or If the prediction error rate of the key position on the second physical block is less than the preset value, the storage device may associate the second physical block with the first logical segment, as shown in the upper part of FIG. 3 .
  • the storage device can associate the second physical block with other logical segments, hereinafter referred to as the second logical segment, as shown in the lower part of FIG. 3 .
  • the second logic segment may correspond to the second position prediction model.
  • the second location prediction model may be determined based on the second key stored in the second physical block and the second storage location of the second key in the second physical block, for example, it may be is a monotonic fitting function or a machine learning model for predicting the position of a keyword; correspondingly, the storage device uses the second position prediction model to predict the deviation between the predicted position of each keyword on the second physical block and its actual position They may all be within the preset range, or the prediction error rate may be less than the preset value.
  • a corresponding index can be constructed.
  • the keyword stored on each physical block and the storage location of the keyword in the physical block satisfy the corresponding position prediction model.
  • the keyword and the corresponding position prediction model are determined to determine the physical block where the keyword is located, so that the value corresponding to the keyword can be found in the physical block.
  • the storage device associates logical segments with physical blocks as a unit, the different keywords in each physical block and the storage location of the keyword in the physical block satisfy the same location prediction model.
  • the physical block where the keyword is located can usually be predicted, and the value corresponding to the keyword can be found in the physical block, instead of searching for the value corresponding to the keyword from multiple physical blocks, Thereby, the number of accesses to physical blocks can be reduced.
  • the storage device Since there are many physical blocks in which key-value pairs are written in the storage device, after associating the physical blocks with the logical segments, the storage device needs to predict a model for a larger number of locations for more logical segments. In order to facilitate searching for the location prediction model applicable to the keyword to be retrieved, in a further possible implementation manner, the storage device may further establish a layer of indexes for each logical segment.
  • the first keyword in the first physical block associated with the logical segment and the first address in the first physical block can be extracted, and at the same time, the logical segment can also be extracted
  • the corresponding model describes the value, constructs a new key-value pair based on this information, and stores the new key-value pair in a new physical block.
  • the storage device may extract, for the first logical segment, the first keyword in the first physical block, the first address of the first physical block, and the first logical segment
  • the corresponding model description value of the first position prediction model may specifically be the inverse of the slope of the linear fitting function.
  • the storage device can use the extracted first keyword as the key in the new key-value pair (hereinafter referred to as the third keyword), and splices the extracted first address and model description value into a new key value The value in the pair (hereinafter referred to as the third value), thereby forming a new key-value pair (key-value). Finally, the storage device can write the new key-value pair into the index block.
  • the index block may be a physical block. However, different from the first physical block and the second physical block for storing keywords and metadata, the index block is used to store data such as model description values and physical block addresses of lower-level indexes.
  • a new key-value pair can also be formed based on, and the key-value pair is also written into the index block.
  • the first keyword in the first physical block is used as an example for description. In other embodiments, any key in the first physical block may be used as an example.
  • the word is used as the third key, such as the last key in the first physical block, which is not limited in this embodiment.
  • each key-value pair is sorted according to the value of the key and then written into the index block in sequence. It can be understood that when the remaining storage space in the index block is not enough to support the writing of key-value pairs corresponding to more logical segments, the next index block adjacent to the index block can be used to store unwritten key-value pairs whose keys For the writing method of the value pair, reference may be made to the aforementioned method of writing the key-value pair into the first physical block, which will not be repeated here.
  • the storage device may associate the index block with the third logical segment, and based on the third key stored in the index block and the corresponding third key The third value of , fits a third position prediction model.
  • the third position prediction model by fitting reference may be made to the description of the above-mentioned description of the fitting and obtaining the first position prediction model, which will not be repeated here.
  • the third storage position of the keyword to be retrieved on the index block can be predicted, so that the keyword to be retrieved can be compared with the keyword in the third storage position .
  • the following assumes that the index blocks are written in ascending order of the value of the third keyword, and that the third position prediction model is specifically a monotonic fitting function as an example for illustrative illustration, and the value of the third keyword is as follows: For the specific implementation of writing index blocks in order from large to small, you can refer to the understanding.
  • the storage device may determine the value corresponding to the key according to the key at the predicted position, where the value includes the first address of the first physical block associated with a certain logical segment of the next layer and the function description value, so that the storage device can determine the monotonic fitting function corresponding to the logical segment according to the function description value, and further predict the storage location of the keyword to be retrieved on the physical block based on the monotonic fitting function, so that the storage device can The value corresponding to the key to be retrieved is determined based on the predicted storage location and the first address of the first physical block, and the retrieval process is completed.
  • the storage device may search backward from the physical block associated with the third logical segment to determine the first
  • the third keyword is greater than or equal to the value of the keyword to be retrieved, and the value corresponding to the third keyword is determined according to the position of the third keyword on the index block, and the value includes a certain logic of the next layer
  • the first address and function description value of the first physical block associated with the segment can be referred to the above retrieval process, and the value corresponding to the keyword to be retrieved can be retrieved based on the first address and the function description value to complete the retrieval process.
  • the storage device may search forward from the physical block associated with the third logical segment to determine the first A third keyword that is less than or equal to the value of the keyword to be retrieved, and the value corresponding to the third keyword is determined according to the position of the third keyword on the index block, and the value includes a certain logic of the next layer
  • the first address and function description value of the first physical block associated with the segment can be referred to the above retrieval process, and the value corresponding to the keyword to be retrieved can be retrieved based on the first address and the function description value to complete the retrieval process.
  • the storage device can traverse the For each third keyword on the index block, the third keyword on the index block that has the same value as the keyword to be searched is determined. If the traversal fails, the storage device may continue to perform keyword traversal on other index blocks adjacent to the index block to determine the keywords stored in other index blocks that have the same value as the to-be-retrieved keyword.
  • the storage device may also extract the first keyword in the first physical block (that is, the above-mentioned index block) associated with the third logical segment and the first address in the first physical block, and at the same time, also The model description value corresponding to the third logical segment can be extracted, and a new key-value pair can be constructed based on the information, and the new key-value pair can be stored in a new physical block, and according to the above-mentioned similar process, for the first Three logical segments and then build a layer of index.
  • the storage device can form a multi-layer index structure through multiple iterations, for example, the index structure shown in FIG. 4 can be formed.
  • Figure 4 shows the 4-layer index structure, including layers 1 to 4.
  • the physical block in the first layer may be the physical block associated with the logical segment serving as the root node
  • the physical blocks in the second layer and the third layer may be the physical block associated with the logical segment serving as the intermediate node
  • the first Physical blocks in layers to layer 3 may also be referred to as index blocks in this embodiment
  • physical blocks in layer 4 may be physical blocks associated with logical segments that are leaf nodes
  • each layer of A logical segment has a location prediction model corresponding to it.
  • the value corresponding to the keyword stored in the physical block of layer 4 is metadata
  • the keyword stored in the physical block of each layer from layer 1 to layer 3 is the first one associated with the logical segment of the next layer.
  • the first keyword stored in the physical block, the value corresponding to the keyword stored in the physical block of each layer is the first address of the first physical block associated with the logical segment of the next layer and the model description value corresponding to the logical segment.
  • the index structure shown in FIG. 4 is only an example. In practical applications, a logical segment serving as a root node may be associated with multiple physical blocks, or the index structure may also be a structure with three layers or five layers.
  • the location prediction model corresponding to the logical segment of the first layer can be used to predict the storage of the keyword to be retrieved in the physical block associated with the logical segment. location, and by comparing the value between the keyword at the storage location and the keyword to be retrieved, determine the value (value) corresponding to the keyword to be retrieved in the first layer, so as to describe the value based on the model in the value, A logical segment corresponding to the model description value is determined from a plurality of logical segments in the second layer, and a position prediction model corresponding to the logical segment is determined based on the model description value.
  • the storage device can predict the storage location of the keyword to be retrieved in the physical block associated with the logical segment based on the location prediction model, and compare the value between the keyword obtained from the storage location and the keyword to be retrieved size, determine the value corresponding to the keyword to be retrieved in layer 2, so based on the model description value in the value, determine the logical segment corresponding to the model description value from multiple logical segments in layer 3, and based on the model description value in the value, determine the logical segment corresponding to the model description value
  • the model description value determines the position prediction model corresponding to the logic segment.
  • a corresponding logical segment can be determined from multiple logical segments in the fourth layer, and a location prediction model corresponding to the logical segment can be determined based on the model description value; then, the storage device can predict the location based on the location prediction model.
  • the storage location of the keyword to be retrieved on the physical block in layer 4, and the keyword at the storage location is compared with the keyword to be retrieved. If the two keywords are the same, according to the storage location of the to-be-retrieved keyword on the physical block, determine the value corresponding to the to-be-retrieved keyword stored on the physical block to complete the data retrieval.
  • the keywords can be read forward or backward based on the storage location on the physical block associated with the logical segment, and the keywords read each time and the keywords to be retrieved are compared to obtain A keyword that is the same as the keyword to be retrieved is found on the physical block, and then the value corresponding to the keyword to be retrieved stored on the physical block is determined to complete the data retrieval.
  • the storage device may prompt the user that the query fails or the storage device may perform the retrieval again.
  • the location prediction model can accurately predict the location of each keyword on the physical block, so that the storage device can accurately predict the value corresponding to the keyword to be retrieved stored on the lowest physical block, thereby The number of physical blocks that the storage device needs to access can be reduced, but at the same time, due to the need to additionally store a large number of location prediction models, the storage space occupied by the intermediate nodes is larger (the number of physical blocks in the intermediate nodes is larger).
  • the location prediction model in the index is reduced, for example, the original two location prediction models are fitted into one model, the accuracy of the storage device in predicting the location of the keyword on the physical block may not be high, which may easily lead to the storage device It usually requires additional access to multiple physical blocks to find the value corresponding to the keyword to be retrieved.
  • the overhead and delay of accessing physical blocks are often high, which is relatively low compared to accessing physical blocks. In other words, the overhead and delay required to compare the key on the same physical block with the key to be retrieved are usually small or even negligible.
  • the number of location prediction models can be determined by controlling the deviation of the storage device to access physical blocks based on the location prediction model, so as to balance the storage space occupied by the intermediate nodes and the storage device.
  • the retrieval performance, wherein, the deviation of accessing physical blocks based on the location prediction model can be, for example, the deviation ratio between the physical blocks accessed based on the prediction results of the location prediction model and the physical blocks that actually need to be accessed (or the correct rate/error rate, etc.).
  • the storage device may also determine the number of location prediction models by limiting the maximum number of physical blocks that are allowed to be accessed in one retrieval process.
  • the storage device fits multiple location prediction models into one model, etc. , reducing the number of location prediction models, so that the memory space occupied by the intermediate nodes is reduced to 15MB.
  • the deviation rate of the storage device accessing the physical block is 5%; if it continues, the memory space occupied by the intermediate nodes will be reduced to 10MB, then the deviation rate of the storage device accessing the physical block continues to increase to 20%, then the memory space occupied by the intermediate node (that is, the location number of predictive models).
  • the maximum deviation rate allowed in an actual application is 5%
  • it can be determined that the memory space occupied by the intermediate nodes in the constructed index is 15MB.
  • this embodiment does not limit the specific implementation of how to balance the memory space occupied by the intermediate nodes and the deviation existing in the storage device accessing physical blocks.
  • the above-mentioned implementation process of constructing an index may be applied to a merging process of an index structure of a hierarchical mechanism.
  • the LSM tree can be divided into N+1 layers (N is a positive integer), which are L0 layer, L1 layer, ..., LN layer respectively.
  • N is a positive integer
  • the data scale of the L0 layer is usually small, and the L1 layer to the LN layer may have a large data scale.
  • Each of the L0 to LN layers may have one or more subtrees of the LSM tree.
  • the L0 layer includes 4 subtrees as an example.
  • the L0 layer may also be based on practical applications. Requirements include any number of other subtrees.
  • the new metadata and its corresponding keywords can be written into the subtree of the L0 layer in the form of key-value pairs, as shown in Figure 5.
  • Write to subtree 1 in the L0 layer When data is written to subtree 1, other subtrees of the L0 layer can be configured to be in a state where data cannot be written, that is, data can be written to only one subtree at the same time.
  • the subtree 1 may adopt an index structure that supports data modification, insertion and update, such as B+ tree, ARTree and other data structures.
  • the other subtrees in the L0 layer and the subtrees in the L1 to LN layers can be learning indexes that support the merge operation.
  • the space occupied by the learning index is smaller, and the intermediate nodes are smaller Less, faster operation, but does not support data modification, insertion and update.
  • the index structure of the LSM tree includes not only an index structure that supports data modification, insertion and update, but also a learning index, so that the index structure of the LSM tree can support data modification, insertion and update operations.
  • the index structure that supports data modification, insertion and update holds a small amount of data, usually less than 1% of the LSM tree. More than 99% of the data in the LSM tree can be stored by the learning index, which makes the LSM Trees can take advantage of the performance and cost of learned indexes.
  • the data model of subtree 1 continues to expand, which makes it impossible for subtree 1 to continue to support the writing of more new data.
  • the scale of data in the L0 layer will also continue to expand.
  • a preset threshold such as 256MB size, etc.
  • the data in subtree 1 can be merged (merge), or, when the amount of data in the L0 layer exceeds a certain threshold (such as 1GB, etc.), the data in the L0 layer can be merged, and the merged data can be written to the subtree in the L1 layer.
  • the data scale of the subtree in the L1 layer can be larger than the data scale of the subtree in the L0 layer.
  • the data size in the L1 layer exceeds a preset threshold (such as 10G size, etc.)
  • the data in the L1 layer can be merged, and the merged data can be written to the subtree in the L2 layer. And so on.
  • the data scale of the subtree of the next level is usually larger and larger, as shown in Figure 6.
  • the value corresponding to the same key can be merged into a new value, and a new key-value pair is constructed based on the new value and the original key.
  • the new key The key of the value pair remains unchanged, and the value of the new key-value pair is the new value obtained after merging, so that redundant and invalid information in the LSM tree can be eliminated to achieve the purpose of reducing storage overhead.
  • the storage device can serialize the obtained new key-value pair, that is, it can be written into the subtree of the current layer or the subtree of the next layer according to the value of the keys in descending order or in descending order. middle.
  • the index can be constructed based on the method of constructing an index shown in FIG. 1 to form subtrees of each layer in the LSM tree, so that the first logical segment and the first physical block are separated from each other.
  • the association relationship and the association relationship between the second logical segment and the second physical block are located in the index structure of the subtree.
  • the device 700 may include at least one memory 701 and at least one processor 702 .
  • the processor 702 may be a central processing unit (central processing unit, CPU).
  • the memory 701 may include volatile memory, such as RAM or the like.
  • RAM can be Dynamic Random Access Memory (DRAM) or Storage Class Memory (SCM).
  • DRAM is a semiconductor memory, and like most RAMs, it is a volatile memory device.
  • SCM is a composite storage technology that combines the characteristics of traditional storage devices and memory. SCM can provide faster read and write speeds than hard disks, but is slower than DRAM in terms of operation speed and cheaper than DRAM in cost.
  • DRAM and SCM are only illustrative in this embodiment, and the memory may also include other random access memories, such as Static Random Access Memory (SRAM), synchronous dynamic random access memory (synchronous dynamic random access memory).
  • SRAM Static Random Access Memory
  • synchronous dynamic random access memory synchronous dynamic random access memory
  • the memory 701 may also include a non-volatile memory (non-volatile memory), such as a programmable read only memory (Programmable Read Only Memory, PROM), an erasable programmable read only memory (Erasable Programmable Read Only Memory, EPROM) ), flash memory (Flash Memory), etc., flash memory, HDD, SSD, etc.
  • a non-volatile memory such as a programmable read only memory (Programmable Read Only Memory, PROM), an erasable programmable read only memory (Erasable Programmable Read Only Memory, EPROM) ), flash memory (Flash Memory), etc., flash memory, HDD, SSD, etc.
  • the memory 701 can be used to store instructions, the processor 702 is connected to the memory 701, for example, it can be connected through various interfaces, transmission lines or buses, and the processor 702 can read and execute the instructions stored in the memory 701 based on the connection, to perform the following steps:
  • the second key and the second storage location do not satisfy the first location prediction model, associating the second physical block with a second logical segment, the second key and the second The storage location satisfies the second location prediction model corresponding to the second logic segment.
  • the processor 702 executes the instructions stored in the memory 701, and may also execute the following steps:
  • the second physical block is associated with the first logical segment when the second key and the second storage location satisfy the first location prediction model.
  • the processor 702 executes the instructions stored in the memory 701, and may specifically perform the following steps:
  • the second keyword and the second storage location do not satisfy the first location prediction model, specifically, the error between the predicted location and the second storage location exceeds the preset error range.
  • the processor 702 executes the instructions stored in the memory 701, and may also execute the following steps:
  • the third key includes a key in the physical block associated with the first logical segment
  • the value includes the model description value of the first location prediction model and the first address of the first physical block.
  • the first position prediction model includes a linear fitting function
  • the model description value of the first position prediction model includes the reciprocal slope of the linear fitting function
  • the reciprocal slope of the linear fitting function is determined by rounding the average value of the difference between two adjacent keywords in the first physical block.
  • association relationship between the first logical segment and the first physical block, and the association relationship between the second logical segment and the second physical block are located in a sub-tree of the log structure merge tree in a tree index structure.
  • the embodiments of the present application also provide an apparatus for constructing an index.
  • the apparatus 800 may be located in a storage device.
  • the apparatus 800 may specifically include:
  • the association module 801 associates a first physical block with a first logical segment, the first physical block stores a first keyword and a first value corresponding to the first keyword, and the first keyword is associated with all The first storage location of the first keyword in the first physical block satisfies the first location prediction model corresponding to the first logical segment;
  • the judgment module 802 is configured to judge whether the second keyword stored in the second physical block and the second storage location of the second keyword in the second physical block satisfy the first position prediction model, the A second value corresponding to the second keyword is also stored in the second physical block, and the second physical block is adjacent to the first physical block;
  • the associating module 801 is further configured to associate the second physical block with the second logical segment when the second keyword and the second storage location do not satisfy the first location prediction model, the The second keyword and the second storage location satisfy the second location prediction model corresponding to the second logic segment.
  • association module 801 is further configured to:
  • the second physical block is associated with the first logical segment when the second key and the second storage location satisfy the first location prediction model.
  • the judging module 802 is specifically configured to:
  • the second keyword and the second storage location do not satisfy the first location prediction model, specifically, the error between the predicted location and the second storage location exceeds the preset error range.
  • the apparatus 800 further includes:
  • the writing module 803 is configured to write a third keyword and a third value corresponding to the third keyword into the index block, where the third keyword includes a physical block associated with the first logical segment. keyword, and the third value includes a model description value of the first position prediction model and the first address of the first physical block.
  • the first position prediction model includes a linear fitting function
  • the model description value of the first position prediction model includes the reciprocal slope of the linear fitting function
  • the reciprocal slope of the linear fitting function is determined by rounding the average value of the difference between two adjacent keywords in the first physical block.
  • the association between the first logical segment and the first physical block, and the association between the second logical segment and the second physical block are located in a subtree index of the LSM tree in the structure.
  • the apparatuses of the embodiments of the present application may correspond to executing the methods described in the embodiments of the present application.
  • the above-mentioned and other operations and/or functions of each module in the metadata storage device 800 are respectively used to implement the corresponding flow of each method in FIG. 1 .
  • the function of each module in the apparatus 800 can be executed by the processor 702 in the above-mentioned apparatus 700 for building an index by calling the program in the memory 701 .
  • Embodiments of the present application further provide a computer-readable medium, where instructions are stored in the computer-readable medium, when the computer-readable medium runs on a computer, the computer causes the computer to execute the methods described in the above aspects.
  • Embodiments of the present application also provide a computer program product, which, when running on a computer, enables the computer to execute the methods described in the above aspects.
  • connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines.
  • the aforementioned storage medium includes: U disk, mobile hard disk, magnetic disk, optical disk, random-access memory (Random-Access Memory, RAM), solid state disk (Solid State Disk, SSD) or non-volatile Various non-transitory machine-readable media that can store program code, such as memory (non-volatile memory).

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Business, Economics & Management (AREA)
  • Economics (AREA)
  • Strategic Management (AREA)
  • Human Resources & Organizations (AREA)
  • Computational Linguistics (AREA)
  • Software Systems (AREA)
  • Development Economics (AREA)
  • Game Theory and Decision Science (AREA)
  • Human Computer Interaction (AREA)
  • Entrepreneurship & Innovation (AREA)
  • Marketing (AREA)
  • Operations Research (AREA)
  • Quality & Reliability (AREA)
  • Tourism & Hospitality (AREA)
  • General Business, Economics & Management (AREA)
  • Mathematical Physics (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

An index construction method and apparatus. The index construction method comprises: a storage device associating a first physical block with a first logical segment, wherein a first keyword and a first value corresponding to the first keyword are stored in the first physical block, and the first keyword and a first storage position, in the first physical block, of the first keyword satisfy a first position prediction model corresponding to the first logical segment (S101); the storage device determining whether a second keyword stored in a second physical block and a second storage position, in the second physical block, of the second keyword satisfy the first position prediction model, wherein a second value corresponding to the second keyword is also stored in the second physical block, and the second physical block is adjacent to the first physical block (S102); and when the second keyword and the second storage position, in the second physical block, of the second keyword do not satisfy the first position prediction model, the storage device associating the second physical block with a second logical segment, wherein at this time, the second keyword and the second storage position, in the second physical block, of the second keyword satisfy a second position prediction model corresponding to the second logical segment (S103). In this way, an index for quickly looking up data can be constructed, and the number of times that physical blocks need to be accessed is relatively small.

Description

一种构建索引方法及装置A method and device for building an index
本申请要求于2020年8月13日递交中国国家知识产权局、申请号为202010812177.7,发明名称为“一种构建索引方法及装置”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of a Chinese patent application with an application number of 202010812177.7 and an invention title of "A Method and Device for Constructing Indexes", which was submitted to the State Intellectual Property Office of China on August 13, 2020, the entire contents of which are incorporated herein by reference. Applying.
技术领域technical field
本申请涉及存储技术领域,尤其涉及一种构建索引方法及装置。The present application relates to the field of storage technologies, and in particular, to a method and apparatus for constructing an index.
背景技术Background technique
在互联网大数据应用以及云计算大数据应用等场景中,通常要求对大规模数据进行快速访问。为此,存储设备在存储数据的同时,通过会为该数据创建相应的索引,该索引提供了指向数据的指针。这样,存储设备在进行数据检索时,可以基于该索引快速查找到相应数据,从而实现数据的快速访问。In scenarios such as Internet big data applications and cloud computing big data applications, fast access to large-scale data is usually required. To this end, while storing data, the storage device creates a corresponding index for the data, and the index provides a pointer to the data. In this way, during data retrieval, the storage device can quickly find corresponding data based on the index, thereby realizing fast data access.
因此,如何构建出用于快速查找数据的索引,是目前亟需解决的重要问题。Therefore, how to construct an index for quickly searching data is an important problem that needs to be solved urgently at present.
发明内容SUMMARY OF THE INVENTION
本申请实施例提供了一种构建索引方法及装置,以构建出用于快速查找数据的索引。Embodiments of the present application provide a method and apparatus for constructing an index, so as to construct an index for quickly searching data.
第一方面,本申请实施例提供了一种构建索引方法,该方法可以应用于存储设备。具体的,存储设备可以将第一物理块与第二逻辑段关联,该第一物理块中存储有第一关键字以及该第一关键字对应的第一值,其中,该第一关键字与该第一关键字在第一物理块中的第一存储位置满足第一逻辑段对应的第一位置预测模型,这样,当关键字已知时,可以利用该第一位置预测模型预测出该关键字在第一物理块上的位置。然后,对于与该第一物理块相邻的第二物理块,存储设备可以判断该第二物理块中存储的第二关键字以及该第二关键字在第二物理块中的第二存储位置是否满足第一位置预测模型,该第二物理块中还存储有第二关键字对应的第二值。当第二关键字以及该第二存储位置不满足第一位置预测模型时,说明利用第一位置预测模型无法较为准确的预测出第二物理块上关键字的位置,此时,存储设备可以将该第二物理块与第二逻辑段关联,该第二关键字以及第二存储位置满足第二逻辑段对应的第二位置预测模型。In a first aspect, an embodiment of the present application provides a method for constructing an index, and the method can be applied to a storage device. Specifically, the storage device may associate a first physical block with a second logical segment, where the first physical block stores a first keyword and a first value corresponding to the first keyword, where the first keyword is associated with The first storage position of the first keyword in the first physical block satisfies the first position prediction model corresponding to the first logical segment. In this way, when the keyword is known, the first position prediction model can be used to predict the key The position of the word on the first physical block. Then, for the second physical block adjacent to the first physical block, the storage device may determine the second key stored in the second physical block and the second storage location of the second key in the second physical block Whether the first position prediction model is satisfied, the second physical block also stores a second value corresponding to the second keyword. When the second keyword and the second storage location do not satisfy the first location prediction model, it means that the location of the keyword on the second physical block cannot be more accurately predicted by using the first location prediction model. At this time, the storage device can The second physical block is associated with the second logical segment, and the second key and the second storage location satisfy the second location prediction model corresponding to the second logical segment.
在构建索引的过程中,由于各个物理块上存储的关键字以及该关键字在物理块中的存储位置满足相应的位置预测模型,这样,在基于该索引进行数据检索时,可以通过所要查找的关键字以及相应的位置预测模型,确定该关键字所在的物理块,从而可以在该物理块中查找出该关键字对应的值。并且,由于存储设备是以物理块为单位关联逻辑段,这使得每个物理块中的不同关键字以及该关键字在物理块中的存储位置满足同一位置预测模型,因此,在进行数据检索时,基于该位置预测模型通常可以预测出该关键字所在的物理块,并在该物理块中查找出该关键字对应的值,而可以不用从多个物理块中查找该关键字对应的值,从而可以减少访问物理块的次数。In the process of building an index, since the keywords stored on each physical block and the storage location of the keywords in the physical blocks satisfy the corresponding position prediction model, in this way, when retrieving data based on the index, it is possible to search for The keyword and the corresponding position prediction model are used to determine the physical block where the keyword is located, so that the value corresponding to the keyword can be found in the physical block. In addition, since the storage device associates logical segments with physical blocks as a unit, the different keywords in each physical block and the storage location of the keyword in the physical block satisfy the same location prediction model. Therefore, when data retrieval is performed , based on the location prediction model, the physical block where the keyword is located can usually be predicted, and the value corresponding to the keyword can be found in the physical block, instead of searching for the value corresponding to the keyword from multiple physical blocks, Thereby, the number of accesses to physical blocks can be reduced.
另外,如果存储设备为了使得每次所访问的物理块的数量达到最小,即所构建的索引中每个物理块的位置预测模型能够精确预测出每个关键字在物理块上的位置,或者每个位置预测模型至少能够预测出任意已知关键字所对应的物理块,则所构建的索引中需要记录有较多数量的位置预测模型(如为每个物理块记录有一个位置预测模型等),这就使得存储设备需要较多的存储空间来存储索引。反之,若减少位置预测模型的数量,则存储设备所预测关键字所对应位置的准确性可能不高。因此,实际应用中,可以通过控制存储设备每次进行索引检索时允许访问物理块的最大数量,来达到存储空间与检索性能的平衡。In addition, if the storage device minimizes the number of physical blocks accessed each time, that is, the location prediction model of each physical block in the constructed index can accurately predict the location of each key on the physical block, or If one location prediction model can at least predict the physical block corresponding to any known keyword, a larger number of location prediction models need to be recorded in the constructed index (for example, one location prediction model is recorded for each physical block, etc.) , which makes the storage device need more storage space to store the index. On the contrary, if the number of location prediction models is reduced, the accuracy of the location corresponding to the keyword predicted by the storage device may not be high. Therefore, in practical applications, the balance between storage space and retrieval performance can be achieved by controlling the maximum number of physical blocks that are allowed to be accessed each time the storage device performs index retrieval.
在一种可能的实施方式中,当第二关键字以及该第二存储位置满足第一位置预测模型时,说明利用第一位置预测模型可以较为准确的预测出第二物理块上各个关键字的位置,此时,存储设备可以将该第二物理块继续与第一逻辑段关联。这样,利用一个位置预测模型可以预测出两个物理块上各个关键字的位置。In a possible implementation manner, when the second keyword and the second storage location satisfy the first location prediction model, it means that the first location prediction model can more accurately predict the value of each keyword on the second physical block. At this time, the storage device can continue to associate the second physical block with the first logical segment. In this way, the position of each keyword on the two physical blocks can be predicted by using a position prediction model.
在一种可能的实施方式中,在判断第二关键字以及第二关键字在第二物理块上的第二存储位置是否满足第一位置预测模型时,具体可以是将根据第二关键字,利用第一位置预测耐磨性计算出第二关键字在第二物理块中的预测位置,并比较该预测位置与该第二关键字在第二物理块上实际的第二存储位置之间的误差是否在预设误差范围内,若没有超出预设误差范围,则可以确定第二关键字以及第二关键字在第二物理块上的第二存储位置满足第一位置预测模型,而若超出预设误差范围,则可以确定第二关键字以及第二关键字在第二物理块上的第二存储位置不满足第一位置预测模型。In a possible implementation manner, when judging whether the second keyword and the second storage location of the second keyword on the second physical block satisfy the first location prediction model, specifically, according to the second keyword, Calculate the predicted position of the second key in the second physical block by using the first position prediction wear resistance, and compare the predicted position with the actual second storage position of the second key in the second physical block. Whether the error is within the preset error range, if it does not exceed the preset error range, it can be determined that the second keyword and the second storage location of the second keyword on the second physical block satisfy the first location prediction model, and if it exceeds If the error range is preset, it can be determined that the second key and the second storage location of the second key on the second physical block do not satisfy the first location prediction model.
在一种可能的实施方式中,当存储有键值对的物理块的数量较多时,通常物理块所关联的逻辑段的数量也较多,相应的,存储设备所需的存储的位置预测数量也较多,为便于在进行索引检索时可以快速确定出存储有待检索关键字的物理块所对应的位置预测模型,存储设备还可以针对于第一逻辑段以及第二逻辑段构建上层索引,具体的,存储设备可以向索引块中写入第三关键字以及该第三关键字对应的第三值,该第三关键字可以包括与第一逻辑段关联的物理块中的关键字,并且,该第三值包括第一位置预测模型的模型描述值以及与该第一物理块的首地址。这样,存储设备在进行检索时,可以根据上层索引的位置预测模型,确定待检索关键字所对应的下层索引的位置预测模型,从而根据该下层索引的位置预测模型进一步预测出该待检索关键字所在物理块(或者在该物理块上的位置)。In a possible implementation, when the number of physical blocks storing key-value pairs is large, usually the number of logical segments associated with the physical blocks is also large. Correspondingly, the predicted number of storage locations required by the storage device There are also many. In order to quickly determine the location prediction model corresponding to the physical block storing the keyword to be retrieved during index retrieval, the storage device can also build an upper-level index for the first logical segment and the second logical segment. , the storage device may write a third keyword and a third value corresponding to the third keyword into the index block, where the third keyword may include a keyword in a physical block associated with the first logical segment, and, The third value includes the model description value of the first location prediction model and the first address of the first physical block. In this way, when performing retrieval, the storage device can determine the location prediction model of the lower-level index corresponding to the keyword to be retrieved according to the location prediction model of the upper-level index, so as to further predict the keyword to be retrieved according to the location prediction model of the lower-level index The physical block (or the location on the physical block).
在一种可能的实施方式中,上述第一位置预测模型包括线性拟合函数,该第一位置预测模型的模型描述值包括线性拟合函数的斜率倒数。当然,在其它可能的实施方式中,位置预测模型也可以是非线性拟合函数,如可以是神经网络等,能够预测出关键字所对应的物理块或者在该物理块上的位置。In a possible implementation, the first position prediction model includes a linear fitting function, and the model description value of the first position prediction model includes the inverse slope of the linear fitting function. Of course, in other possible implementations, the position prediction model may also be a nonlinear fitting function, such as a neural network, etc., which can predict the physical block corresponding to the keyword or the position on the physical block.
在一种可能的实施方式中,上述第一位置预测模型所对应的斜率倒数,可以是通过对第一物理块上相邻两个关键字的差值的平均值进行取整确定的。这样,存储设备在进行关键字的位置预测时,可以不用进行浮点运算,从而可以降低存储设备预测关键字操作所需的计算开销,同时,也可以灵活支持不同长度的key。In a possible implementation manner, the reciprocal slope corresponding to the first position prediction model may be determined by rounding the average value of the difference between two adjacent keywords on the first physical block. In this way, the storage device does not need to perform floating-point operations when predicting the position of a key, thereby reducing the computational overhead required for the storage device to predict the key operation, and at the same time, it can flexibly support keys of different lengths.
在一种可能的实施方式中,第一逻辑段与第一物理块的关联关系,以及第二逻辑段与第二物理块的关联关系,可以位于LSM树的子树索引结构中。其中,LSM树中的子树,可以包括学习型索引以及支持数据修改、插入和更新的索引结构,并且,支持数据修改、插 入和更新的索引结构所容纳的数据量较少,远小于学习型索引所容纳的数据量,这使得LSM树可以发挥出学习型索引在性能和成本上的优势,并且,LSM还能支持对数据的修改、插入和更新。In a possible implementation manner, the association between the first logical segment and the first physical block, and the association between the second logical segment and the second physical block may be located in a subtree index structure of the LSM tree. Among them, the subtrees in the LSM tree can include learning indexes and index structures that support data modification, insertion, and update, and the index structure that supports data modification, insertion, and update accommodates a small amount of data, which is much smaller than that of learning indexes. The amount of data contained in the index allows the LSM tree to take advantage of the performance and cost of the learning index, and the LSM can also support data modification, insertion and update.
第二方面,本申请实施例还提供了一种构建索引装置,用于执行第一方面中任意一种实现方式所描述的方法。In a second aspect, an embodiment of the present application further provides a device for constructing an index, configured to execute the method described in any one of the implementation manners of the first aspect.
第三方面,本申请实施例还提供了一种构建索引设备,该设备包括存储器和处理器,所述处理器用于执行所述存储器中存储的指令,以执行第一方面中任意一种实现方式所描述的方法。In a third aspect, an embodiment of the present application further provides a device for constructing an index. The device includes a memory and a processor, where the processor is configured to execute instructions stored in the memory to execute any one of the implementations of the first aspect. the described method.
本申请第四方面提供一种计算机可读介质,所述计算机可读介质中存储有指令,当其在计算机上运行时,使得计算机执行上述各方面所述的方法。A fourth aspect of the present application provides a computer-readable medium, where instructions are stored in the computer-readable medium, which, when executed on a computer, cause the computer to execute the methods described in the above aspects.
本申请第五方面提供一种计算机程序产品,当其在计算机上运行时,使得计算机执行上述各方面所述的方法。A fifth aspect of the present application provides a computer program product, which, when run on a computer, causes the computer to execute the methods described in the above aspects.
附图说明Description of drawings
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请中记载的一些实施例,对于本领域普通技术人员来讲,还可以根据这些附图获得其他的附图。In order to illustrate the technical solutions in the embodiments of the present application more clearly, the following briefly introduces the accompanying drawings that need to be used in the description of the embodiments. Obviously, the drawings in the following description are only some implementations described in the present application. For example, for those skilled in the art, other drawings can also be obtained from these drawings.
图1为本申请实施例中一种构建索引的方法流程示意图;1 is a schematic flowchart of a method for constructing an index in an embodiment of the present application;
图2为向物理块写入键值对的示意图;2 is a schematic diagram of writing a key-value pair to a physical block;
图3为与第一逻辑段或者第二逻辑段关联物理块的示意图;3 is a schematic diagram of a physical block associated with a first logical segment or a second logical segment;
图4为本申请实施例构建的4层索引结构示意图;4 is a schematic diagram of a four-layer index structure constructed in an embodiment of the present application;
图5为LSM树的结构示意图;Fig. 5 is the structural representation of LSM tree;
图6为LSM树的各层子树的数据规模示意图;Fig. 6 is the data scale schematic diagram of each layer subtree of LSM tree;
图7为本申请实施例提供的构建索引设备结构示意图;7 is a schematic structural diagram of an indexing device provided by an embodiment of the present application;
图8为本申请实施例提供的构建索引装置结构示意图。FIG. 8 is a schematic structural diagram of an apparatus for constructing an index provided by an embodiment of the present application.
具体实施方式detailed description
本申请实施例提出了一种构建索引方法及装置,以构建出用于快速查找数据的索引。The embodiments of the present application propose a method and apparatus for constructing an index, so as to construct an index for quickly searching data.
参阅图1,示出了一种构建索引方法的流程示意图,该方法可以应用于存储设备。存储设备可以是服务器,也可以是存储阵列中的控制器等。该存储设备不仅可以存储有数据,还可以同时存储有该数据对应的索引,以便基于该索引快速访问数据。该方法具体可以包括:Referring to FIG. 1 , a schematic flowchart of a method for constructing an index is shown, and the method can be applied to a storage device. The storage device can be a server or a controller in a storage array. The storage device can not only store data, but also store an index corresponding to the data at the same time, so that the data can be quickly accessed based on the index. Specifically, the method may include:
S101:存储设备将第一物理块与第一逻辑段关联,该第一物理块中存储有第一关键字以及该第一关键字对应的第一值,该第一关键字与第一关键字在第一物理块中的第一存储位置满足第一逻辑段对应的第一位置预测模型。S101: The storage device associates a first physical block with a first logical segment, the first physical block stores a first keyword and a first value corresponding to the first keyword, and the first keyword and the first keyword The first storage location in the first physical block satisfies the first location prediction model corresponding to the first logical segment.
通常情况下,存储设备可以基于键值对来为数据库中的数据建立索引。键值对,也可被称之为名值对或者属性值对,包括关键字(key)以及该关键字对应的值(value),该值通常可以是元数据。其中,关键字用于对元数据(值)进行标识,元数据为描述数据的数 据,用于描述数据库中所存储数据的属性(特征)信息,如元数据可以是数据库中所存储数据的文件名、或者该数据的存储地址指针等。Typically, a storage device can index data in a database based on key-value pairs. A key-value pair, which can also be called a name-value pair or an attribute-value pair, includes a key and a value corresponding to the key, and the value can usually be metadata. Among them, the keyword is used to identify the metadata (value), the metadata is the data describing the data, and is used to describe the attribute (feature) information of the data stored in the database. For example, the metadata can be a file of the data stored in the database. name, or the storage address pointer of the data, etc.
本实施例中,在建立索引时,可以将多个键值对按照关键字的值(key值)大小进行依次排序,并按照排序顺序将多个键值对写入第一物理块中。其中,第一物理块可以具有4K或者8K字节大小,是持久化层数据下盘的友好粒度(当然,第一物理块也可以是其它大小,本实施例对此并不进行限定)。为便于描述,以下将写入第一物理块的关键字称之为第一关键字,将写入第一物理块的值称之为第一值。应当理解,该第一关键字可以是一个或者多个关键字,相应的,第一值也可以是一个或者多个值。In this embodiment, when establishing an index, multiple key-value pairs may be sorted in sequence according to the value of the keyword (key value), and the multiple key-value pairs may be written into the first physical block according to the sorting order. The first physical block may have a size of 4K or 8K bytes, which is a friendly granularity of the persistent layer data to the disk (of course, the first physical block may also be of other sizes, which is not limited in this embodiment). For convenience of description, the key written in the first physical block is referred to as the first key, and the value written in the first physical block is referred to as the first value. It should be understood that the first keyword may be one or more keywords, and correspondingly, the first value may also be one or more values.
作为一种示例,可以是基于如图2所示的写入方式将键值对写入第一物理块中。如图2所示,可以从第一物理块的块头(block header)结束的位置开始写入第一个键值对中的key1,从第一物理块的尾部开始写入第一个键值对中的value1。其中,在写入value1的同时,还可以同时写入该value1的类型(value type1)。然后,从key1结束的位置继续写入第二个键值对中的key2,并从value1的前一个位置处写入第二个键值对中的value2以及该value2的类型(value type2)。以此类推,可以向该第一物理块中依次写入key1、key2、key3、key4等多个key(也即为上述第一关键字),以及依次写入value1、value2、value3以及value4等多个value(也即为上述第一值),直至该第一物理块中的剩余存储空间无法继续写入新的键值对,则可以认为该第一物理块被填满数据。As an example, the key-value pair may be written into the first physical block based on the writing manner shown in FIG. 2 . As shown in Figure 2, the key1 in the first key-value pair can be written from the position where the block header of the first physical block ends, and the first key-value pair can be written from the end of the first physical block value1 in . Among them, when the value1 is written, the type of the value1 (value type1) can also be written at the same time. Then, continue to write key2 in the second key-value pair from the position where key1 ends, and write value2 in the second key-value pair and the type of value2 (value type2) from the previous position of value1. By analogy, multiple keys such as key1, key2, key3, and key4 can be written into the first physical block in sequence (that is, the first key above), and value1, value2, value3, and value4 can be written in sequence. value (that is, the above-mentioned first value), until the remaining storage space in the first physical block cannot continue to write new key-value pairs, it can be considered that the first physical block is filled with data.
其中,第一物理块中的块头,可以记录该第一物理块的相关信息,例如可以包括该第一物理块的循环冗余校验(cyclic redundancy check,CRC)码、键值对的数量、第一物理块的类型(如可以是定长类型、或者变长类型等)、第一物理块在逻辑段中的位置等信息。Wherein, the block header in the first physical block can record the relevant information of the first physical block, for example, can include the cyclic redundancy check (cyclic redundancy check, CRC) code of the first physical block, the number of key-value pairs, Information such as the type of the first physical block (for example, it may be a fixed-length type or a variable-length type, etc.), the location of the first physical block in the logical segment, and the like.
应当理解,图2所示的键值对写入方式仅作为一种示例性说明,并不用于对键值对的写入方式进行限定。比如,在其它可能的写入方式中,在写入第一个键值对中的key1后,可以在该key1的结束位置处继续写入value1,然后在value1的结束位置处继续依次写入第二个键值对中的key2以及value2等。It should be understood that the key-value pair writing method shown in FIG. 2 is only used as an exemplary description, and is not used to limit the writing method of the key-value pair. For example, in other possible writing methods, after writing key1 in the first key-value pair, you can continue to write value1 at the end of the key1, and then continue to write the first at the end of value1. The key2 and value2 in the two key-value pairs, etc.
第一物理块被填满后,可以将该第一物理块与第一逻辑段(segment)进行关联。其中,该第一逻辑块对应于第一位置预测模型,该第一位置预测模型可以根据输入的关键字预测出与第一逻辑块关联的物理块上该关键字的位置。本实施例中,该第一位置预测模型可以是基于第一物理块中存储的第一关键字以及该第一关键字在第一物理块中的第一存储位置进行确定的。After the first physical block is filled, the first physical block can be associated with a first logical segment. The first logical block corresponds to a first position prediction model, and the first position prediction model can predict the position of the keyword on the physical block associated with the first logical block according to the input keyword. In this embodiment, the first location prediction model may be determined based on the first key stored in the first physical block and the first storage location of the first key in the first physical block.
在一种可能的实施方式中,该第一位置预测模型例如可以是单调拟合函数,则,存储设备可以是基于第一物理块中各个关键字的值以及各个关键字子第一物理块中的存储位置,进行函数拟合,得到随着key值的增加,表征存储位置的数值单调递增或者单调递减的拟合函数,也即为上述第一位置预测模型。In a possible implementation manner, the first position prediction model may be, for example, a monotonic fitting function, then, the storage device may be based on the value of each keyword in the first physical block and the value of each keyword in the first physical block Perform function fitting to obtain a fitting function that represents a monotonically increasing or monotonically decreasing value of the storage location as the key value increases, that is, the above-mentioned first position prediction model.
进一步的,该单调拟合函数可以是如下述公式(1)所示的线性拟合函数:Further, the monotonic fitting function may be a linear fitting function as shown in the following formula (1):
待检索关键字的槽位=(待检索关键字–起始关键字)/斜率倒数+起始槽位位置(1)The slot of the keyword to be retrieved = (the keyword to be retrieved – the starting keyword) / the reciprocal slope + the starting slot position (1)
其中,待检索关键字,是指所需查找的关键字;起始关键字,是指第一物理块中存储的第一个关键字,例如图2所示的key1;起始槽位位置,是指第一物理块中存储第一个key的槽位,其数值可以为0(当然也可以是1等其它数值);斜率倒数,可以是通过计算第一物 理块中相邻两个关键字的值之间的差值的平均值并进行取整得到。由于斜率倒数进行了取整,这样,基于公式(1)进行关键字的槽位计算时,可以不用进行浮点运算,从而可以降低预测关键字操作所需的计算开销,同时,也可以灵活支持不同长度的key。Among them, the keyword to be retrieved refers to the keyword to be searched; the starting keyword refers to the first keyword stored in the first physical block, such as key1 shown in Figure 2; the starting slot position, It refers to the slot where the first key is stored in the first physical block, and its value can be 0 (of course, it can also be other values such as 1); the reciprocal slope can be calculated by calculating two adjacent keywords in the first physical block. The average of the differences between the values is rounded up. Since the reciprocal slope is rounded, floating-point operations can be omitted when calculating the slot positions of keywords based on formula (1), which can reduce the computational overhead required for predicting keyword operations. At the same time, it can also flexibly support keys of different lengths.
当然,单调拟合函数也可以是其它线性拟合函数,比如,可以是针对于公式(1)进行适当的变换等;或者单调拟合函数,也可以是非线性拟合函数,但是其满足单调递增或者单调递减的变换原则。本实施例中,对于单调拟合函数的具体呈现形式并不进行限定。Of course, the monotonic fitting function can also be other linear fitting functions, for example, it can be suitable for the transformation of formula (1); Or the monotonically decreasing transformation principle. In this embodiment, the specific presentation form of the monotonic fitting function is not limited.
可以理解,第一物理块中存储的关键字的值,在空间上存在局部分布不均匀的可能,由此拟合得到的单调拟合函数可能无法准确的预测出每个关键字所对应的槽位,因此,基于单调拟合函数预测待检索关键字在第一物理块中的槽位,可能存在一定的误差。本实施例中,在进行函数拟合时,可以验证拟合得到的函数所预测的各个关键字在第一物理块上的位置,与该关键字在第一物理块上的实际位置之间的偏差是否均在预设的误差范围内(或者可以是验证预测错误率是否小于预设值),若是,则可以将该函数作为上述单调拟合函数,而若不是,则可以重新进行函数拟合,直至拟合出符合条件的单调拟合函数。进一步的,当单调拟合函数所预测的槽位上存储的关键字并非是待检索的关键字时,存储设备可以是将待检索的关键字与该预测槽位附近的一个或者多个槽位上存储的关键字进行比对,以确定待检索的关键字在第一物理块中存储的实际位置。然后,存储设备可以基于关键字以及该关键字对应的值在第一物理块中的写入方式,确定待检索的关键字所对应的值在第一物理块中的位置。以图2所示的写入方式为例,若确定待检索的关键字位于第一物理块的第3个槽位,则可以从第一物理块中存放value的倒数第三个位置处读取到该待检索的关键字所对应的value3。It can be understood that the value of the keyword stored in the first physical block may have uneven local distribution in space, and the monotonic fitting function obtained by fitting may not be able to accurately predict the slot corresponding to each keyword. Therefore, there may be a certain error in predicting the slot position of the keyword to be retrieved in the first physical block based on the monotonic fitting function. In this embodiment, when performing function fitting, it is possible to verify the relationship between the position of each keyword on the first physical block predicted by the function obtained by fitting and the actual position of the keyword on the first physical block. Whether the deviations are all within the preset error range (or whether the verification prediction error rate is less than the preset value), if so, the function can be used as the above-mentioned monotonic fitting function, and if not, the function can be re-fitted , until a monotonic fitting function that meets the conditions is fitted. Further, when the keyword stored in the slot predicted by the monotonic fitting function is not the keyword to be retrieved, the storage device may be to associate the keyword to be retrieved with one or more slots near the predicted slot. The stored keywords are compared to determine the actual location where the keyword to be retrieved is stored in the first physical block. Then, the storage device may determine the position of the value corresponding to the keyword to be retrieved in the first physical block based on the keyword and the writing manner of the value corresponding to the keyword in the first physical block. Taking the writing method shown in Figure 2 as an example, if it is determined that the keyword to be retrieved is located in the third slot of the first physical block, it can be read from the third-to-last position where the value is stored in the first physical block. to the value3 corresponding to the keyword to be retrieved.
值得注意的是,上述是以第一位置预测模型为单调拟合函数为例进行说明,在其它可能的实施例中,该第一位置预测模型也可以是其它表现形式,如可以是非单调函数,或者可以是机器学习模型等。总之,第一位置预测模型,可以是能够用于实现预测关键字在物理块上的位置的任意模型,不局限于上述单调拟合函数。It is worth noting that the above description takes the first position prediction model as an example of a monotonic fitting function. In other possible embodiments, the first position prediction model may also be in other forms, such as a non-monotonic function, Or it could be a machine learning model, etc. In conclusion, the first position prediction model may be any model that can be used to predict the position of a keyword on a physical block, and is not limited to the above monotonic fitting function.
存储设备在将第一物理块与第一逻辑段关联后,可以继续向第二物理块写入其它关键字以及该其它关键字对应的值,并继续执行步骤S102,以确定是否将第二物理块也与第二逻辑段建立关联。其中,存储设备也可以是预先将键值对写入第一物理块以及第二物理块,然后再将各个物理块与相应的逻辑段关联,本实施例对此并不进行限定。为便于描述,以下将写入第二物理块的关键字称之为第二关键字,将写入第二物理块的值称之为第二值。After associating the first physical block with the first logical segment, the storage device may continue to write other keywords and values corresponding to the other keywords to the second physical block, and continue to perform step S102 to determine whether to add the second physical block to the second physical block. The block is also associated with the second logical segment. The storage device may also write the key-value pair into the first physical block and the second physical block in advance, and then associate each physical block with the corresponding logical segment, which is not limited in this embodiment. For convenience of description, the key written in the second physical block is referred to as the second key, and the value written in the second physical block is referred to as the second value.
S102:存储设备判断第二物理块中存储的第二关键字以及该第二关键字在第二物理块中的第二存储位置是否满足第一位置预测模型,其中,该第二物理块中还存储有第二关键字对应的第二值,该第二物理块与第一物理块相邻。S102: The storage device determines whether the second keyword stored in the second physical block and the second storage location of the second keyword in the second physical block satisfy the first position prediction model, wherein the second physical block also A second value corresponding to the second key is stored, and the second physical block is adjacent to the first physical block.
S103:当第二关键字以及第二关键字在第二物理块中的第二存储位置不满足第一位置预测模型时,存储设备将第二物理块与第二逻辑段关联,此时,第二关键字以及第二关键字在第二物理块中的第二存储位置满足第二逻辑段对应的第二位置预测模型。S103: When the second key and the second storage position of the second key in the second physical block do not satisfy the first position prediction model, the storage device associates the second physical block with the second logical segment. The second key and the second storage position of the second key in the second physical block satisfy the second position prediction model corresponding to the second logical segment.
实际应用中,存储设备可以包括多个连续的、用于存储键值对的物理块,而上述第一物理块以及第二物理块即为该多个物理块中两个相邻的物理块。通常情况下,该第一物理块的尾地址与第二物理块的首地址连续。In practical applications, the storage device may include a plurality of consecutive physical blocks for storing key-value pairs, and the first physical block and the second physical block are two adjacent physical blocks in the plurality of physical blocks. Normally, the tail address of the first physical block is continuous with the head address of the second physical block.
存储设备可以利用第一位置预测模型预测第一物理块中各个关键字的位置,并且预测误差较小或者预测准确率较高。进一步的,存储设备还可以校验该第一位置预测模型,是否可以用于预测第二物理块中各个关键字的位置。如果第一位置预测模型所预测的各个关键字在第二物理块上的位置,与该关键字在第二物理块上的实际位置之间的偏差均在预设的误差范围内,或者针对于第二物理块上关键字位置的预测错误率小于预设值,则存储设备可以将该第二物理块与第一逻辑段关联,如图3上方所示。这样,基于第一逻辑段对应的第一位置预测模型可以预测出第一物理块以及第二物理块中各个关键字在物理块上的位置。而若第一位置预测模型所预测的各个关键字在第二物理块上的位置,与该关键字在第二物理块上的实际位置之间的偏差较大,超出预设的误差范围,或者针对于第二物理块上关键字位置的预测错误率小于预设值,则存储设备可以将该第二物理块关联至其它的逻辑段,以下称之为第二逻辑段,如图3下方所示。其中,第二逻辑段可以对应于第二位置预测模型。The storage device may use the first position prediction model to predict the position of each key in the first physical block, and the prediction error is small or the prediction accuracy rate is high. Further, the storage device may also check whether the first location prediction model can be used to predict the location of each key in the second physical block. If the deviation between the position of each keyword on the second physical block predicted by the first position prediction model and the actual position of the keyword on the second physical block is within a preset error range, or If the prediction error rate of the key position on the second physical block is less than the preset value, the storage device may associate the second physical block with the first logical segment, as shown in the upper part of FIG. 3 . In this way, the position of each key in the first physical block and the second physical block on the physical block can be predicted based on the first position prediction model corresponding to the first logical segment. However, if the position of each keyword on the second physical block predicted by the first position prediction model has a large deviation from the actual position of the keyword on the second physical block, which exceeds the preset error range, or For the prediction error rate of the key position on the second physical block is less than the preset value, the storage device can associate the second physical block with other logical segments, hereinafter referred to as the second logical segment, as shown in the lower part of FIG. 3 . Show. Wherein, the second logic segment may correspond to the second position prediction model.
与第一位置预测模型类似,第二位置预测模型可以是基于第二物理块中存储的第二关键字以及该第二关键字在第二物理块中的第二存储位置进行确定的,例如可以是用于预测关键字位置的单调拟合函数或者机器学习模型等;相应的,存储设备利用该第二位置预测模型预测的第二物理块上各个关键字的预测位置与其实际位置之间的偏差可以均在预设范围内,或者预测错误率小于预设值。Similar to the first location prediction model, the second location prediction model may be determined based on the second key stored in the second physical block and the second storage location of the second key in the second physical block, for example, it may be is a monotonic fitting function or a machine learning model for predicting the position of a keyword; correspondingly, the storage device uses the second position prediction model to predict the deviation between the predicted position of each keyword on the second physical block and its actual position They may all be within the preset range, or the prediction error rate may be less than the preset value.
上述过程,是以两个物理块关联相同或者不同逻辑段作为示例进行描述,实际应用中,对于存储设备中与第二物理块连接的下一个物理块以及更多其它的物理块,均可以采用上述类似的方式与相应的逻辑段建立关联。值得注意的是,一个物理块可以仅关联一个逻辑段,而一个逻辑段可以关联一个物理块,或者关联多个连续的物理块。The above process is described by taking two physical blocks associating the same or different logical segments as an example. In practical applications, for the next physical block and more other physical blocks connected to the second physical block in the storage device, the following steps can be used. A similar way as described above is associated with the corresponding logical segment. It is worth noting that a physical block can be associated with only one logical segment, and a logical segment can be associated with one physical block, or with multiple consecutive physical blocks.
这样,通过将各个物理块与相应逻辑段建立关联,可以构建出相应的索引。并且,在构建索引的过程中,各个物理块上存储的关键字以及该关键字在物理块中的存储位置满足相应的位置预测模型,这样,在基于该索引进行数据检索时,可以通过所要查找的关键字以及相应的位置预测模型,确定该关键字所在的物理块,从而可以在该物理块中查找出该关键字对应的值。并且,由于存储设备是以物理块为单位关联逻辑段,这使得每个物理块中的不同关键字以及该关键字在物理块中的存储位置满足同一位置预测模型,因此,在进行数据检索时,基于该位置预测模型通常可以预测出该关键字所在的物理块,并在该物理块中查找出该关键字对应的值,而可以不用从多个物理块中查找该关键字对应的值,从而可以减少访问物理块的次数。In this way, by associating each physical block with a corresponding logical segment, a corresponding index can be constructed. In addition, in the process of constructing the index, the keyword stored on each physical block and the storage location of the keyword in the physical block satisfy the corresponding position prediction model. In this way, when retrieving data based on the index, you can The keyword and the corresponding position prediction model are determined to determine the physical block where the keyword is located, so that the value corresponding to the keyword can be found in the physical block. In addition, since the storage device associates logical segments with physical blocks as a unit, the different keywords in each physical block and the storage location of the keyword in the physical block satisfy the same location prediction model. Therefore, when data retrieval is performed , based on the location prediction model, the physical block where the keyword is located can usually be predicted, and the value corresponding to the keyword can be found in the physical block, instead of searching for the value corresponding to the keyword from multiple physical blocks, Thereby, the number of accesses to physical blocks can be reduced.
由于存储设备中写入键值对的物理块较多,这使得将物理块与逻辑段关联后,从而存储设备需要为较多的逻辑段较多数量的位置预测模型。为便于查找待检索关键字所适用的位置预测模型,在进一步可能的实施方式中,存储设备还可以为各个逻辑段再建立一层索引。Since there are many physical blocks in which key-value pairs are written in the storage device, after associating the physical blocks with the logical segments, the storage device needs to predict a model for a larger number of locations for more logical segments. In order to facilitate searching for the location prediction model applicable to the keyword to be retrieved, in a further possible implementation manner, the storage device may further establish a layer of indexes for each logical segment.
在一种示例性的具体实施方式中,可以提取与逻辑段关联的第一个物理块中的第一个关键字以及该第一个物理块中的首地址,同时,还可以提取该逻辑段对应的模型描述值,并基于这些信息构建出新的键值对,并将该新的键值对存储于新的物理块中。假设第一逻辑段仅关联了第一物理块,则存储设备可以针对于第一逻辑段,提取第一物理块中第一个 关键字、该第一物理块的首地址、该第一逻辑段对应的第一位置预测模型的模型描述值,示例性的,当第一位置预测模型为线性拟合函数时,该模型描述值具体可以是该线性拟合函数的斜率倒数。然后,存储设备可以将提取出的该第一个关键字作为新键值对中的key(以下称之为第三关键字),并将提取出的首地址以及模型描述值拼接成新键值对中的value(以下称之为第三值),从而形成新的键值对(key-value)。最后,存储设备可以将该新的键值对写入索引块中。其中,该索引块可以是物理块,但是,区别于第一物理块以及第二物理块存储关键字与元数据,索引块用于存储下层索引的模型描述值、物理块地址等数据。类似的,针对于第二逻辑段同样可以基于形成新的键值对,并将该键值对也写入该索引块中。当然,本实施例中,是以将第一物理块中的第一个关键字作为第三关键字为例进行说明,在其它实施例中,也可以是将第一物理块中的任意一个关键字作为该第三关键字,如第一物理块中的最后一个关键字等,本实施例对此并不进行限定。In an exemplary specific implementation, the first keyword in the first physical block associated with the logical segment and the first address in the first physical block can be extracted, and at the same time, the logical segment can also be extracted The corresponding model describes the value, constructs a new key-value pair based on this information, and stores the new key-value pair in a new physical block. Assuming that the first logical segment is only associated with the first physical block, the storage device may extract, for the first logical segment, the first keyword in the first physical block, the first address of the first physical block, and the first logical segment The corresponding model description value of the first position prediction model. Exemplarily, when the first position prediction model is a linear fitting function, the model description value may specifically be the inverse of the slope of the linear fitting function. Then, the storage device can use the extracted first keyword as the key in the new key-value pair (hereinafter referred to as the third keyword), and splices the extracted first address and model description value into a new key value The value in the pair (hereinafter referred to as the third value), thereby forming a new key-value pair (key-value). Finally, the storage device can write the new key-value pair into the index block. The index block may be a physical block. However, different from the first physical block and the second physical block for storing keywords and metadata, the index block is used to store data such as model description values and physical block addresses of lower-level indexes. Similarly, for the second logical segment, a new key-value pair can also be formed based on, and the key-value pair is also written into the index block. Of course, in this embodiment, the first keyword in the first physical block is used as an example for description. In other embodiments, any key in the first physical block may be used as an example. The word is used as the third key, such as the last key in the first physical block, which is not limited in this embodiment.
实际应用中,针对于每个逻辑段,均可以形成与其对应的键值对,并将各个键值对按照关键字的值进行排序后依次写入索引块中。可以理解,当索引块中剩余存储空间不足以支持更多逻辑段对应的键值对写入时,可以利用与该索引块相邻的下一索引块存储未写入的键值对,其键值对的写入方式可以参照前述向第一物理块中写入键值对的方式,在此不做赘述。In practical applications, for each logical segment, a corresponding key-value pair can be formed, and each key-value pair is sorted according to the value of the key and then written into the index block in sequence. It can be understood that when the remaining storage space in the index block is not enough to support the writing of key-value pairs corresponding to more logical segments, the next index block adjacent to the index block can be used to store unwritten key-value pairs whose keys For the writing method of the value pair, reference may be made to the aforementioned method of writing the key-value pair into the first physical block, which will not be repeated here.
与第一物理块以及第二物理块关联逻辑段的实现方式类似,存储设备可以将索引块与第三逻辑段关联,并基于该索引块中存储的第三关键字以及该第三关键字对应的第三值,拟合出第三位置预测模型。其中,拟合得到第三位置预测模型的具体实现过程,可以参见前述拟合得到第一位置预测模型的相关之处描述,在此不做赘述。这样,基于第三逻辑段对应的第三位置预测模型,可以预测出待检索关键字在索引块上的第三存储位置,从而可以将待检索关键字与第三存储位置处的关键字进行比较。为便于描述,以下假设按照第三关键字的值从小到大的顺序写入索引块,并且第三位置预测模型具体为单调拟合函数为例进行示例性说明,对于第三关键字的值按照从大到小的顺序写入索引块时的具体实现,可以参照理解。Similar to the implementation manner in which the first physical block and the second physical block are associated with the logical segment, the storage device may associate the index block with the third logical segment, and based on the third key stored in the index block and the corresponding third key The third value of , fits a third position prediction model. For the specific implementation process of obtaining the third position prediction model by fitting, reference may be made to the description of the above-mentioned description of the fitting and obtaining the first position prediction model, which will not be repeated here. In this way, based on the third position prediction model corresponding to the third logical segment, the third storage position of the keyword to be retrieved on the index block can be predicted, so that the keyword to be retrieved can be compared with the keyword in the third storage position . For ease of description, the following assumes that the index blocks are written in ascending order of the value of the third keyword, and that the third position prediction model is specifically a monotonic fitting function as an example for illustrative illustration, and the value of the third keyword is as follows: For the specific implementation of writing index blocks in order from large to small, you can refer to the understanding.
如果两个关键字的值相同,则存储设备可以根据预测位置处的关键字确定该关键字对应的值,该值包括了下一层的某个逻辑段关联的第一个物理块的首地址以及函数描述值,从而存储设备可以根据该函数描述值确定该逻辑段对应的单调拟合函数,并基于单调拟合函数进一步预测出待检索关键字在物理块上的存储位置,从而存储设备可以基于该预测出的存储位置以及第一个物理块的首地址确定该待检索关键字对应的值,完成检索过程。If the values of the two keys are the same, the storage device may determine the value corresponding to the key according to the key at the predicted position, where the value includes the first address of the first physical block associated with a certain logical segment of the next layer and the function description value, so that the storage device can determine the monotonic fitting function corresponding to the logical segment according to the function description value, and further predict the storage location of the keyword to be retrieved on the physical block based on the monotonic fitting function, so that the storage device can The value corresponding to the key to be retrieved is determined based on the predicted storage location and the first address of the first physical block, and the retrieval process is completed.
如果待检索关键字在索引块上的第三存储位置处的关键字的值小于待检索关键字的值,则存储设备可以从第三逻辑段关联的物理块上向后查找,确定第一个大于或者等于该待检索关键字的值的第三关键字,并根据该第三关键字在索引块上的位置确定该第三关键字对应的值,该值包括了下一层的某个逻辑段关联的第一个物理块的首地址以及函数描述值,从而可以参照上述检索过程,基于该首地址以及函数描述值检索出待检索关键字对应的值,完成检索过程。If the value of the keyword to be retrieved at the third storage location on the index block is smaller than the value of the keyword to be retrieved, the storage device may search backward from the physical block associated with the third logical segment to determine the first The third keyword is greater than or equal to the value of the keyword to be retrieved, and the value corresponding to the third keyword is determined according to the position of the third keyword on the index block, and the value includes a certain logic of the next layer The first address and function description value of the first physical block associated with the segment can be referred to the above retrieval process, and the value corresponding to the keyword to be retrieved can be retrieved based on the first address and the function description value to complete the retrieval process.
如果待检索关键字在索引块上的第三存储位置处的关键字的值大于待检索关键字的值,则存储设备可以从第三逻辑段关联的物理块上向前查找,确定第一个小于或者等于该 待检索关键字的值的第三关键字,并根据该第三关键字在索引块上的位置确定该第三关键字对应的值,该值包括了下一层的某个逻辑段关联的第一个物理块的首地址以及函数描述值,从而可以参照上述检索过程,基于该首地址以及函数描述值检索出待检索关键字对应的值,完成检索过程。If the value of the keyword to be retrieved at the third storage location on the index block is greater than the value of the keyword to be retrieved, the storage device may search forward from the physical block associated with the third logical segment to determine the first A third keyword that is less than or equal to the value of the keyword to be retrieved, and the value corresponding to the third keyword is determined according to the position of the third keyword on the index block, and the value includes a certain logic of the next layer The first address and function description value of the first physical block associated with the segment can be referred to the above retrieval process, and the value corresponding to the keyword to be retrieved can be retrieved based on the first address and the function description value to complete the retrieval process.
当然,如果索引块上存储的各个关键字并未按照关键字的值递增或者递减的顺序进行存储,并且,待检索关键字与第三存储位置处的关键字的值不同,则存储设备可以遍历该索引块上各个第三关键字,以确定出索引块上与该待检索关键字具有相同值的第三关键字。而若遍历失败,则存储设备可以在与该索引块相邻的其它索引块上继续进行关键字遍历,以确定出其它索引块上存储的与该待检索关键字具有相同值的关键字。Of course, if the keywords stored in the index block are not stored in the order of increasing or decreasing the value of the keywords, and the value of the keyword to be retrieved is different from the value of the keyword at the third storage location, the storage device can traverse the For each third keyword on the index block, the third keyword on the index block that has the same value as the keyword to be searched is determined. If the traversal fails, the storage device may continue to perform keyword traversal on other index blocks adjacent to the index block to determine the keywords stored in other index blocks that have the same value as the to-be-retrieved keyword.
如上述过程,可以形成两层索引。实际应用中,存储设备还可以提取与第三逻辑段关联的第一个物理块(也即上述索引块)中的第一个关键字以及该第一个物理块中的首地址,同时,还可以提取该第三逻辑段对应的模型描述值,并基于这些信息构建出新的键值对,并将该新的键值对存储于新的物理块中,并按照上述类似过程,为该第三逻辑段再建立一层索引。如此,存储设备可以通过多次迭代,可以形成多层索引结构,例如可以是形成如图4所示的索引结构。As described above, a two-level index can be formed. In practical applications, the storage device may also extract the first keyword in the first physical block (that is, the above-mentioned index block) associated with the third logical segment and the first address in the first physical block, and at the same time, also The model description value corresponding to the third logical segment can be extracted, and a new key-value pair can be constructed based on the information, and the new key-value pair can be stored in a new physical block, and according to the above-mentioned similar process, for the first Three logical segments and then build a layer of index. In this way, the storage device can form a multi-layer index structure through multiple iterations, for example, the index structure shown in FIG. 4 can be formed.
图4体现了4层索引结构,包括第1层至第4层。其中,第1层中的物理块可以是与作为根节点的逻辑段关联的物理块,第2层以及第3层中的物理块可以是与作为中间节点的逻辑段关联的物理块(第1层至第3层中的物理块在本实施例中也可被称为索引块),第4层中的物理块可以是与作为叶子节点的逻辑段关联的物理块,并且,每一层的逻辑段具有与其对应的位置预测模型。第4层的物理块中所存储的关键字对应的值为元数据,而第1层至第3层中各层物理块所存储的关键字均为其下一层逻辑段关联的第一个物理块中存储的第一个关键字,各层物理块所存储的关键字对应的值均为其下一层逻辑段关联的第一个物理块的首地址以及该逻辑段对应的模型描述值。当然,图4所示的索引结构仅作为一种示例,实际应用中,作为根节点的逻辑段可以关联多个物理块,或者,索引结构也可以是具有3层或者5层的结构。Figure 4 shows the 4-layer index structure, including layers 1 to 4. Among them, the physical block in the first layer may be the physical block associated with the logical segment serving as the root node, and the physical blocks in the second layer and the third layer may be the physical block associated with the logical segment serving as the intermediate node (the first Physical blocks in layers to layer 3 may also be referred to as index blocks in this embodiment), physical blocks in layer 4 may be physical blocks associated with logical segments that are leaf nodes, and each layer of A logical segment has a location prediction model corresponding to it. The value corresponding to the keyword stored in the physical block of layer 4 is metadata, and the keyword stored in the physical block of each layer from layer 1 to layer 3 is the first one associated with the logical segment of the next layer. The first keyword stored in the physical block, the value corresponding to the keyword stored in the physical block of each layer is the first address of the first physical block associated with the logical segment of the next layer and the model description value corresponding to the logical segment. . Of course, the index structure shown in FIG. 4 is only an example. In practical applications, a logical segment serving as a root node may be associated with multiple physical blocks, or the index structure may also be a structure with three layers or five layers.
在进行数据检索时,以图4所示的索引结构为例,可以先利用第1层的逻辑段对应的位置预测模型,预测出待检索关键字在与该逻辑段关联的物理块中的存储位置,并通过比较该存储位置处的关键字与待检索关键字之间的值大小,确定待检索关键字在第1层中对应的值(value),从而基于该值中的模型描述值,从第2层的多个逻辑段中确定与该模型描述值对应的逻辑段,并基于该模型描述值确定该逻辑段对应的位置预测模型。然后,存储设备可以基于该位置预测模型,预测出待检索关键字在与该逻辑段关联的物理块中的存储位置,并通过比较该存储位置出的关键字与待检索关键字之间的值大小,确定待检索关键字在第2层中对应的值,从而基于该值中的模型描述值,从第3层的多个逻辑段中确定与该模型描述值对应的逻辑段,并基于该模型描述值确定该逻辑段对应的位置预测模型。以此类推,可以从第4层的多个逻辑段中确定出相应的逻辑段,并基于该模型描述值确定该逻辑段对应的位置预测模型;然后,存储设备可以基于该位置预测模型,预测待检索关键字在第4层中物理块上的存储位置,并将该存储位置处的关键字与待检索关键字进行比较。若两个关键字相同,则根据待检索关键字在该物理块上的存储位置,确定该物理块上存储的待检索关键 字所对应的值,完成数据检索。而当两个关键字不相同,则可以在与该逻辑段关联的物理块上基于存储位置向前或者向后读取关键字,并比较每次读取的关键字与待检索关键字,以在物理块上查找出与待检索关键字相同的关键字,进而确定出该物理块上存储的该待检索关键字所对应的值,完成数据检索。当然,若通过遍历该逻辑段关联的所有物理块上的关键字,确定没有与待检索关键字相同的关键字,则存储设备可以提示用户查询失败或者存储设备可以重新进行检索。When performing data retrieval, taking the index structure shown in Figure 4 as an example, the location prediction model corresponding to the logical segment of the first layer can be used to predict the storage of the keyword to be retrieved in the physical block associated with the logical segment. location, and by comparing the value between the keyword at the storage location and the keyword to be retrieved, determine the value (value) corresponding to the keyword to be retrieved in the first layer, so as to describe the value based on the model in the value, A logical segment corresponding to the model description value is determined from a plurality of logical segments in the second layer, and a position prediction model corresponding to the logical segment is determined based on the model description value. Then, the storage device can predict the storage location of the keyword to be retrieved in the physical block associated with the logical segment based on the location prediction model, and compare the value between the keyword obtained from the storage location and the keyword to be retrieved size, determine the value corresponding to the keyword to be retrieved in layer 2, so based on the model description value in the value, determine the logical segment corresponding to the model description value from multiple logical segments in layer 3, and based on the model description value in the value, determine the logical segment corresponding to the model description value The model description value determines the position prediction model corresponding to the logic segment. By analogy, a corresponding logical segment can be determined from multiple logical segments in the fourth layer, and a location prediction model corresponding to the logical segment can be determined based on the model description value; then, the storage device can predict the location based on the location prediction model. The storage location of the keyword to be retrieved on the physical block in layer 4, and the keyword at the storage location is compared with the keyword to be retrieved. If the two keywords are the same, according to the storage location of the to-be-retrieved keyword on the physical block, determine the value corresponding to the to-be-retrieved keyword stored on the physical block to complete the data retrieval. When the two keywords are not the same, the keywords can be read forward or backward based on the storage location on the physical block associated with the logical segment, and the keywords read each time and the keywords to be retrieved are compared to obtain A keyword that is the same as the keyword to be retrieved is found on the physical block, and then the value corresponding to the keyword to be retrieved stored on the physical block is determined to complete the data retrieval. Of course, if it is determined by traversing the keywords on all physical blocks associated with the logical segment that there is no keyword identical to the keyword to be retrieved, the storage device may prompt the user that the query fails or the storage device may perform the retrieval again.
值得注意的是,在构建索引时,如果中间节点的逻辑段所关联的物理块数量越多,表征所构建的索引中包含的位置预测模型越多,从而对于待检索关键字的预测通常会越准确,理想情况下,位置预测模型能够准确的预测出每个关键字在物理块上的位置,从而存储设备可以精确预测出最底层的物理块上存储的待检索关键字所对应的值,从而存储设备所需访问的物理块的数量可以得到减少,但是,与此同时,由于需要额外存储大量的位置预测模型,这使得中间节点所占用的存储空间较多(中间节点的物理块数量较多),从而使得索引所需的存储空间较大,存储开销较高。而若减少索引中的位置预测模型,比如将原有的两个位置预测模型拟合成一个模型,则存储设备预测关键字在物理块上的位置的准确性可能不高,从而容易导致存储设备通常需要额外访问多个物理块才能查找到待检索关键字所对应的值,而在当前的存储设备中,访问物理块所存在的开销和时延往往是较高的,相对于访问物理块而言,比较同一物理块上的关键字与待检索关键字所需的开销和时延通常较小,甚至可以忽略不计。因此,实际应用中,在构建索引的过程中,可以通过控制存储设备基于位置预测模型访问物理块所存在的偏差来确定位置预测模型的数量,以此平衡中间节点所占用的存储空间以及存储设备的检索性能,其中,基于位置预测模型访问物理块所存在的偏差,例如可以是基于位置预测模型的预测结果访问的物理块与实际需要访问的物理块之间的偏差比例(或者正确率/错误率等)。当然,存储设备也可以是通过限制一次检索过程中所允许访问物理块的最大数量来确定位置预测模型的数量等。It is worth noting that when constructing an index, if the number of physical blocks associated with the logical segment of the intermediate node is greater, the more location prediction models are included in the constructed index, so the prediction of the keyword to be retrieved will usually be better. Accurate, ideally, the location prediction model can accurately predict the location of each keyword on the physical block, so that the storage device can accurately predict the value corresponding to the keyword to be retrieved stored on the lowest physical block, thereby The number of physical blocks that the storage device needs to access can be reduced, but at the same time, due to the need to additionally store a large number of location prediction models, the storage space occupied by the intermediate nodes is larger (the number of physical blocks in the intermediate nodes is larger). ), so that the storage space required for the index is larger and the storage cost is higher. However, if the location prediction model in the index is reduced, for example, the original two location prediction models are fitted into one model, the accuracy of the storage device in predicting the location of the keyword on the physical block may not be high, which may easily lead to the storage device It usually requires additional access to multiple physical blocks to find the value corresponding to the keyword to be retrieved. However, in current storage devices, the overhead and delay of accessing physical blocks are often high, which is relatively low compared to accessing physical blocks. In other words, the overhead and delay required to compare the key on the same physical block with the key to be retrieved are usually small or even negligible. Therefore, in practical applications, in the process of index building, the number of location prediction models can be determined by controlling the deviation of the storage device to access physical blocks based on the location prediction model, so as to balance the storage space occupied by the intermediate nodes and the storage device. The retrieval performance, wherein, the deviation of accessing physical blocks based on the location prediction model can be, for example, the deviation ratio between the physical blocks accessed based on the prediction results of the location prediction model and the physical blocks that actually need to be accessed (or the correct rate/error rate, etc.). Of course, the storage device may also determine the number of location prediction models by limiting the maximum number of physical blocks that are allowed to be accessed in one retrieval process.
距离来说,假设存储设备访问物理块所存在的偏差为0时中间节点所需占用的内存空间为20MB(兆字节),则存储设备通过将多个位置预测模型拟合成一个模型等方式,减少位置预测模型的数量,从而使得中间节点占用的内存空间减少为15MB,相应的,存储设备访问物理块所存在的偏差率为5%;而若继续将减少中间节点所占用的内存空间至10MB,则存储设备访问物理块所存在的偏差率继续增加至20%,则可以根据实际应用中对于存储设备访问物理块所存在的最大偏差率来确定中间节点所占用的内存空间(也即位置预测模型的数量)。比如,若实际应用中所允许的最大偏差率为5%,则可以确定所构建的索引中中间节点所占用的内存空间为15MB。当然,此处仅作为一种示例,本实施例对于如何平衡中间节点所占用的内存空间以及存储设备访问物理块上所存在的偏差的具体实现并不进行限定。In terms of distance, assuming that the memory space occupied by the intermediate node is 20MB (megabytes) when the deviation of the storage device accessing the physical block is 0, the storage device fits multiple location prediction models into one model, etc. , reducing the number of location prediction models, so that the memory space occupied by the intermediate nodes is reduced to 15MB. Correspondingly, the deviation rate of the storage device accessing the physical block is 5%; if it continues, the memory space occupied by the intermediate nodes will be reduced to 10MB, then the deviation rate of the storage device accessing the physical block continues to increase to 20%, then the memory space occupied by the intermediate node (that is, the location number of predictive models). For example, if the maximum deviation rate allowed in an actual application is 5%, it can be determined that the memory space occupied by the intermediate nodes in the constructed index is 15MB. Of course, this is only an example, and this embodiment does not limit the specific implementation of how to balance the memory space occupied by the intermediate nodes and the deviation existing in the storage device accessing physical blocks.
在进一步可能的实施方式中,上述构建索引的实现过程可以应用于分层机制的索引结构的合并过程。In a further possible implementation manner, the above-mentioned implementation process of constructing an index may be applied to a merging process of an index structure of a hierarchical mechanism.
以日志结构合并(log-structured merge,LSM)树这种广泛应用的数据索引结构为例。如图5所示,LSM树可以划分成N+1层(N为正整数),分别为L0层、L1层、……、LN层。 其中,L0层的数据规模通常较小,L1层至LN层可以具有较大的数据规模。L0至LN层中的每一层,可以具有一个或者多个LSM树的子树,图5中以L0层包括4个子树为例,当然,实际应用中,L0层也可以是根据实际应用的需求包括其它任意数量的子树。Take the widely used data index structure of log-structured merge (LSM) tree as an example. As shown in Fig. 5, the LSM tree can be divided into N+1 layers (N is a positive integer), which are L0 layer, L1 layer, ..., LN layer respectively. Among them, the data scale of the L0 layer is usually small, and the L1 layer to the LN layer may have a large data scale. Each of the L0 to LN layers may have one or more subtrees of the LSM tree. In FIG. 5, the L0 layer includes 4 subtrees as an example. Of course, in practical applications, the L0 layer may also be based on practical applications. Requirements include any number of other subtrees.
在向LSM树中写入新数据时,可以将新的元数据以及其对应的关键字以键值对(key-value)的形式写入L0层的子树中,如图5中将新数据写入L0层中的子树1中。在向子树1中写入数据时,该L0层的其它子树可以被配置为不可写入数据的状态,即同一时刻可以仅向一个子树中写入数据。在一些示例中,该子树1可以采用支持数据修改、插入和更新的索引结构,如B+树,ARTree等数据结构。而L0层中的其它子树以及L1至LN层中的子树,其可以是支持合并(merge)操作的学习型索引,通常情况下,学习型索引所需占用的空间较小,中间节点较少,运算速度较快,但是不支持数据修改、插入和更新。这样,LSM树这种索引结构中不仅包括支持数据修改、插入和更新的索引结构,还包括学习型索引,从而可以使得LSM树这种索引结构可以支持数据的修改、插入和更新操作。同时,支持数据修改、插入和更新的索引结构所容纳的数据量较少,占比通常不到LSM树的1%,LSM树中99%以上的数据可以由学习型索引进行存储,这使得LSM树可以发挥出学习型索引在性能和成本上的优势。When writing new data into the LSM tree, the new metadata and its corresponding keywords can be written into the subtree of the L0 layer in the form of key-value pairs, as shown in Figure 5. Write to subtree 1 in the L0 layer. When data is written to subtree 1, other subtrees of the L0 layer can be configured to be in a state where data cannot be written, that is, data can be written to only one subtree at the same time. In some examples, the subtree 1 may adopt an index structure that supports data modification, insertion and update, such as B+ tree, ARTree and other data structures. The other subtrees in the L0 layer and the subtrees in the L1 to LN layers can be learning indexes that support the merge operation. Generally, the space occupied by the learning index is smaller, and the intermediate nodes are smaller Less, faster operation, but does not support data modification, insertion and update. In this way, the index structure of the LSM tree includes not only an index structure that supports data modification, insertion and update, but also a learning index, so that the index structure of the LSM tree can support data modification, insertion and update operations. At the same time, the index structure that supports data modification, insertion and update holds a small amount of data, usually less than 1% of the LSM tree. More than 99% of the data in the LSM tree can be stored by the learning index, which makes the LSM Trees can take advantage of the performance and cost of learned indexes.
随着新的数据的不断写入,子树1的数据模不断扩大,这使得子树1无法继续支持更多新数据的写入,同时,L0层中的数据规模也会随之不断扩大。为此,当子树1的数据量超出预设阈值(如256MB大小等)时,可以对子树1中的数据进行合并(merge),或者,当L0层中的数据量超出一定阈值(比如1GB大小等)时,可以对L0层中的数据进行合并,并将合并后所得到的数据写入至L1层中的子树。通常情况下,L1层中的子树的数据规模可以大于L0层中子树的数据规模。类似的,当L1层中的数据规模超出预设阈值(比如10G大小等),则可以对L1层中的数据进行合并,并将合并后所得到的数据写入至L2层中的子树,以此类推。在不断的合并以及写入过程中,下一层子树的数据规模通常越来越大,如图6所示。With the continuous writing of new data, the data model of subtree 1 continues to expand, which makes it impossible for subtree 1 to continue to support the writing of more new data. At the same time, the scale of data in the L0 layer will also continue to expand. To this end, when the amount of data in subtree 1 exceeds a preset threshold (such as 256MB size, etc.), the data in subtree 1 can be merged (merge), or, when the amount of data in the L0 layer exceeds a certain threshold (such as 1GB, etc.), the data in the L0 layer can be merged, and the merged data can be written to the subtree in the L1 layer. In general, the data scale of the subtree in the L1 layer can be larger than the data scale of the subtree in the L0 layer. Similarly, when the data size in the L1 layer exceeds a preset threshold (such as 10G size, etc.), the data in the L1 layer can be merged, and the merged data can be written to the subtree in the L2 layer. And so on. In the process of continuous merging and writing, the data scale of the subtree of the next level is usually larger and larger, as shown in Figure 6.
每一层中的数据在进行合并的过程中,可以是将对应于相同key的value合并成新的value,并基于新的value与原有的key构建成新的键值对,该新的键值对的key不变,新的键值对的value为经过合并后所得到的新的value,以此可以淘汰LSM树中冗余的无效信息,以实现降低存储开销的目的。然后,存储设备可以将得到的新键值对进行序列化,即可以是按照关键字的值由小到大的顺序或者由大到小顺序写入当前层的子树或者下一层的子树中。在基于序列化后的键值对构建索引时,可以基于图1所示的构建索引的方式进行构建,以形成LSM树中各层的子树,从而上述第一逻辑段与第一物理块的关联关系以及第二逻辑段与第二物理块的关联关系(或者第一逻辑段分别与第一物理块以及第二物理块的关联关系),位于该子树的索引结构中。In the process of merging the data in each layer, the value corresponding to the same key can be merged into a new value, and a new key-value pair is constructed based on the new value and the original key. The new key The key of the value pair remains unchanged, and the value of the new key-value pair is the new value obtained after merging, so that redundant and invalid information in the LSM tree can be eliminated to achieve the purpose of reducing storage overhead. Then, the storage device can serialize the obtained new key-value pair, that is, it can be written into the subtree of the current layer or the subtree of the next layer according to the value of the keys in descending order or in descending order. middle. When constructing an index based on the serialized key-value pair, the index can be constructed based on the method of constructing an index shown in FIG. 1 to form subtrees of each layer in the LSM tree, so that the first logical segment and the first physical block are separated from each other. The association relationship and the association relationship between the second logical segment and the second physical block (or the association relationship between the first logical segment and the first physical block and the second physical block respectively) are located in the index structure of the subtree.
以上结合图1至图6对本申请中存储元数据的方法进行介绍,接下来结合附图对本申请的设备、装置进行介绍。The method for storing metadata in the present application is described above with reference to FIGS. 1 to 6 , and next, the device and apparatus of the present application are described with reference to the accompanying drawings.
参见图7所示的存储设备700的硬件结构示意图,该设备700可以包括至少一个存储器701和至少一个处理器702。Referring to the schematic diagram of the hardware structure of the storage device 700 shown in FIG. 7 , the device 700 may include at least one memory 701 and at least one processor 702 .
其中,处理器702可以为中央处理器(central processing unit,CPU)。存储器701可以包括 易失性存储器(volatile memory),例如RAM等。举例来说,RAM可以是动态随机存取存储器(Dynamic Random Access Memory,DRAM),也可以是储存级存储器(Storage Class Memory,SCM)。DRAM是一种半导体存储器,与大部分RAM一样,属于一种易失性存储器(volatile memory)设备。SCM是一种同时结合传统储存装置与存储器特性的复合型储存技术,SCM能够提供比硬盘更快速的读写速度,但运算速度上比DRAM慢,在成本上也比DRAM更为便宜。然而,DRAM和SCM在本实施例中只是示例性的说明,内存还可以包括其他随机存取存储器,例如静态随机存取存储器(Static Random Access Memory,SRAM)、同步动态随机存取内存(synchronous dynamic random-access memory,SDRAM)等。存储器701还可以包括非易失性存储器(non-volatile memory),例如可以是可编程只读存储器(Programmable Read Only Memory,PROM)、可抹除可编程只读存储器(Erasable Programmable Read Only Memory,EPROM)、闪存(Flash Memory)等、快闪存储器、HDD、SSD等。The processor 702 may be a central processing unit (central processing unit, CPU). The memory 701 may include volatile memory, such as RAM or the like. For example, RAM can be Dynamic Random Access Memory (DRAM) or Storage Class Memory (SCM). DRAM is a semiconductor memory, and like most RAMs, it is a volatile memory device. SCM is a composite storage technology that combines the characteristics of traditional storage devices and memory. SCM can provide faster read and write speeds than hard disks, but is slower than DRAM in terms of operation speed and cheaper than DRAM in cost. However, DRAM and SCM are only illustrative in this embodiment, and the memory may also include other random access memories, such as Static Random Access Memory (SRAM), synchronous dynamic random access memory (synchronous dynamic random access memory). random-access memory, SDRAM), etc. The memory 701 may also include a non-volatile memory (non-volatile memory), such as a programmable read only memory (Programmable Read Only Memory, PROM), an erasable programmable read only memory (Erasable Programmable Read Only Memory, EPROM) ), flash memory (Flash Memory), etc., flash memory, HDD, SSD, etc.
存储器701可以用于存储指令,处理器702与存储器701连接,例如可以是通过各类接口、传输线或总线等进行连接,处理器702基于所述连接可以读取存储器701中存储的指令并执行,以执行如下步骤:The memory 701 can be used to store instructions, the processor 702 is connected to the memory 701, for example, it can be connected through various interfaces, transmission lines or buses, and the processor 702 can read and execute the instructions stored in the memory 701 based on the connection, to perform the following steps:
将第一物理块与第一逻辑段关联,所述第一物理块中存储有第一关键字以及所述第一关键字对应的第一值,所述第一关键字与所述第一关键字在所述第一物理块中的第一存储位置满足所述第一逻辑段对应的第一位置预测模型;Associating a first physical block with a first logical segment, where a first key and a first value corresponding to the first key are stored in the first physical block, and the first key and the first key The first storage position of the word in the first physical block satisfies the first position prediction model corresponding to the first logical segment;
判断第二物理块中存储的第二关键字以及所述第二关键字在所述第二物理块中的第二存储位置是否满足所述第一位置预测模型,所述第二物理块中还存储有所述第二关键字对应的第二值,所述第二物理块与所述第一物理块相邻;Judging whether the second key stored in the second physical block and the second storage position of the second key in the second physical block satisfy the first position prediction model, and the second physical block also A second value corresponding to the second keyword is stored, and the second physical block is adjacent to the first physical block;
当所述第二关键字以及所述第二存储位置不满足所述第一位置预测模型时,将所述第二物理块与第二逻辑段关联,所述第二关键字以及所述第二存储位置满足所述第二逻辑段对应的第二位置预测模型。When the second key and the second storage location do not satisfy the first location prediction model, associating the second physical block with a second logical segment, the second key and the second The storage location satisfies the second location prediction model corresponding to the second logic segment.
在一种可能的实施方式中,处理器702执行存储器701中存储的指令,还可以执行如下步骤:In a possible implementation manner, the processor 702 executes the instructions stored in the memory 701, and may also execute the following steps:
当所述第二关键字与所述第二存储位置满足所述第一位置预测模型时,将所述第二物理块与所述第一逻辑段关联。The second physical block is associated with the first logical segment when the second key and the second storage location satisfy the first location prediction model.
在一种可能的实施方式中,处理器702执行存储器701中存储的指令,具体可以执行如下步骤:In a possible implementation manner, the processor 702 executes the instructions stored in the memory 701, and may specifically perform the following steps:
根据所述第二关键字,利用所述第一位置预测模型计算出所述第二关键字在所述第二物理块中的预测位置;According to the second key, using the first position prediction model to calculate the predicted position of the second key in the second physical block;
比较所述预测位置与所述第二存储位置之间的误差是否在预设误差范围内;comparing whether the error between the predicted location and the second storage location is within a preset error range;
则,所述第二关键字以及所述第二存储位置不满足所述第一位置预测模型,具体为所述预测位置与所述第二存储位置之间的误差超出所述预设误差范围。Then, the second keyword and the second storage location do not satisfy the first location prediction model, specifically, the error between the predicted location and the second storage location exceeds the preset error range.
在一种可能的实施方式中,处理器702执行存储器701中存储的指令,还可以执行如下步骤:In a possible implementation manner, the processor 702 executes the instructions stored in the memory 701, and may also execute the following steps:
向索引块中写入第三关键字以及所述第三关键字对应的第三值,所述第三关键字包括 与所述第一逻辑段关联的物理块中的关键字,所述第三值包括所述第一位置预测模型的模型描述值以及与所述第一物理块的首地址。Writing a third key and a third value corresponding to the third key into the index block, where the third key includes a key in the physical block associated with the first logical segment, the third key The value includes the model description value of the first location prediction model and the first address of the first physical block.
在一种可能的实施方式中,所述第一位置预测模型包括线性拟合函数,所述第一位置预测模型的模型描述值包括所述线性拟合函数的斜率倒数。In a possible implementation, the first position prediction model includes a linear fitting function, and the model description value of the first position prediction model includes the reciprocal slope of the linear fitting function.
在一种可能的实施方式中,所述线性拟合函数的斜率倒数是对所述第一物理块中相邻两个关键字的差值的平均值进行取整确定的。In a possible implementation manner, the reciprocal slope of the linear fitting function is determined by rounding the average value of the difference between two adjacent keywords in the first physical block.
在一种可能的实施方式中,所述第一逻辑段与所述第一物理块的关联关系,以及所述第二逻辑段与所述第二物理块的关联关系位于日志结构合并树的子树索引结构中。In a possible implementation manner, the association relationship between the first logical segment and the first physical block, and the association relationship between the second logical segment and the second physical block are located in a sub-tree of the log structure merge tree in a tree index structure.
另外,本申请实施例还提供了一种构建索引装置。参见图8所示的构建索引装置的结构示意图,该装置800可以位于存储设备中。该装置800具体可以包括:In addition, the embodiments of the present application also provide an apparatus for constructing an index. Referring to the schematic structural diagram of the index building apparatus shown in FIG. 8 , the apparatus 800 may be located in a storage device. The apparatus 800 may specifically include:
关联模块801,将第一物理块与第一逻辑段关联,所述第一物理块中存储有第一关键字以及所述第一关键字对应的第一值,所述第一关键字与所述第一关键字在所述第一物理块中的第一存储位置满足所述第一逻辑段对应的第一位置预测模型;The association module 801 associates a first physical block with a first logical segment, the first physical block stores a first keyword and a first value corresponding to the first keyword, and the first keyword is associated with all The first storage location of the first keyword in the first physical block satisfies the first location prediction model corresponding to the first logical segment;
判断模块802,用于判断第二物理块中存储的第二关键字以及所述第二关键字在所述第二物理块中的第二存储位置是否满足所述第一位置预测模型,所述第二物理块中还存储有所述第二关键字对应的第二值,所述第二物理块与所述第一物理块相邻;The judgment module 802 is configured to judge whether the second keyword stored in the second physical block and the second storage location of the second keyword in the second physical block satisfy the first position prediction model, the A second value corresponding to the second keyword is also stored in the second physical block, and the second physical block is adjacent to the first physical block;
所述关联模块801,还用于当所述第二关键字以及所述第二存储位置不满足所述第一位置预测模型时,将所述第二物理块与第二逻辑段关联,所述第二关键字以及所述第二存储位置满足所述第二逻辑段对应的第二位置预测模型。The associating module 801 is further configured to associate the second physical block with the second logical segment when the second keyword and the second storage location do not satisfy the first location prediction model, the The second keyword and the second storage location satisfy the second location prediction model corresponding to the second logic segment.
在一种可能的实施方式中,所述关联模块801,还用于:In a possible implementation manner, the association module 801 is further configured to:
当所述第二关键字与所述第二存储位置满足所述第一位置预测模型时,将所述第二物理块与所述第一逻辑段关联。The second physical block is associated with the first logical segment when the second key and the second storage location satisfy the first location prediction model.
在一种可能的实施方式中,所述判断模块802,具体用于:In a possible implementation manner, the judging module 802 is specifically configured to:
利用所述第一位置预测模型计算出所述第二关键字在所述第二物理块中的预测位置;using the first position prediction model to calculate the predicted position of the second keyword in the second physical block;
比较所述预测位置与所述第二存储位置之间的误差是否在预设误差范围内;comparing whether the error between the predicted location and the second storage location is within a preset error range;
则,所述第二关键字以及所述第二存储位置不满足所述第一位置预测模型,具体为所述预测位置与所述第二存储位置之间的误差超出所述预设误差范围。Then, the second keyword and the second storage location do not satisfy the first location prediction model, specifically, the error between the predicted location and the second storage location exceeds the preset error range.
在一种可能的实施方式中,所述装置800还包括:In a possible implementation manner, the apparatus 800 further includes:
写入模块803,用于向索引块中写入第三关键字以及所述第三关键字对应的第三值,所述第三关键字包括与所述第一逻辑段关联的物理块中的关键字,所述第三值包括所述第一位置预测模型的模型描述值以及与所述第一物理块的首地址。The writing module 803 is configured to write a third keyword and a third value corresponding to the third keyword into the index block, where the third keyword includes a physical block associated with the first logical segment. keyword, and the third value includes a model description value of the first position prediction model and the first address of the first physical block.
在一种可能的实施方式中,所述第一位置预测模型包括线性拟合函数,所述第一位置预测模型的模型描述值包括所述线性拟合函数的斜率倒数。In a possible implementation, the first position prediction model includes a linear fitting function, and the model description value of the first position prediction model includes the reciprocal slope of the linear fitting function.
在一种可能的实施方式中,所述线性拟合函数的斜率倒数是对所述第一物理块中相邻两个关键字的差值的平均值进行取整确定的。In a possible implementation manner, the reciprocal slope of the linear fitting function is determined by rounding the average value of the difference between two adjacent keywords in the first physical block.
在一种可能的实施方式中,所述第一逻辑段与所述第一物理块的关联关系,以及所述第二逻辑段与所述第二物理块的关联关系位于LSM树的子树索引结构中。In a possible implementation manner, the association between the first logical segment and the first physical block, and the association between the second logical segment and the second physical block are located in a subtree index of the LSM tree in the structure.
本申请实施例的装置可对应于执行本申请实施例中描述的方法。并且,将元数据存储装置800中的各个模块的上述和其它操作和/或功能分别为了实现图1中的各个方法的相应流程。以上各个模块的功能可参考图1所示的方法实施例中的描述。装置800中每个模块的功能均可由上述用于构建索引的设备700中的处理器702调用存储器701中的程序执行。The apparatuses of the embodiments of the present application may correspond to executing the methods described in the embodiments of the present application. Moreover, the above-mentioned and other operations and/or functions of each module in the metadata storage device 800 are respectively used to implement the corresponding flow of each method in FIG. 1 . For the functions of the above modules, reference may be made to the description in the method embodiment shown in FIG. 1 . The function of each module in the apparatus 800 can be executed by the processor 702 in the above-mentioned apparatus 700 for building an index by calling the program in the memory 701 .
本申请实施例还提供一种计算机可读介质,所述计算机可读介质中存储有指令,当其在计算机上运行时,使得计算机执行上述各方面所述的方法。Embodiments of the present application further provide a computer-readable medium, where instructions are stored in the computer-readable medium, when the computer-readable medium runs on a computer, the computer causes the computer to execute the methods described in the above aspects.
本申请实施例还提供一种计算机程序产品,当其在计算机上运行时,使得计算机执行上述各方面所述的方法。Embodiments of the present application also provide a computer program product, which, when running on a computer, enables the computer to execute the methods described in the above aspects.
另外需说明的是,以上所描述的实施例仅仅是示意性的,其中所述作为分离部件说明的模块可以是或者也可以不是物理上分开的,作为模块显示的部件可以是或者也可以不是物理模块,即可以位于一个地方,或者也可以分布到多个网络模块上。可以根据实际的需要选择其中的部分或者全部模块来实现本实施例方案的目的。另外,本申请提供的装置实施例附图中,模块之间的连接关系表示它们之间具有通信连接,具体可以实现为一条或多条通信总线或信号线。In addition, it should be noted that the above-described embodiments are only illustrative, wherein the modules described as separate components may or may not be physically separated, and the components displayed as modules may or may not be physical Modules can be located in one place or distributed over multiple network modules. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution in this embodiment. In addition, in the drawings of the device embodiments provided in the present application, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines.
本领域普通技术人员可以理解,前述的存储介质包括:U盘、移动硬盘、磁碟、光盘、随机存储器(Random-Access Memory,RAM)、固态硬盘(Solid State Disk,SSD)或者非易失性存储器(non-volatile memory)等各种可以存储程序代码的非短暂性的(non-transitory)机器可读介质。Those of ordinary skill in the art can understand that the aforementioned storage medium includes: U disk, mobile hard disk, magnetic disk, optical disk, random-access memory (Random-Access Memory, RAM), solid state disk (Solid State Disk, SSD) or non-volatile Various non-transitory machine-readable media that can store program code, such as memory (non-volatile memory).
最后应说明的是:以上各实施例仅用以说明本申请的技术方案,而非对其限制。Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, but not to limit them.

Claims (14)

  1. 一种构建索引的方法,其特征在于,所述方法应用于存储设备,所述方法包括:A method for building an index, wherein the method is applied to a storage device, and the method includes:
    将第一物理块与第一逻辑段关联,所述第一物理块中存储有第一关键字以及所述第一关键字对应的第一值,所述第一关键字与所述第一关键字在所述第一物理块中的第一存储位置满足所述第一逻辑段对应的第一位置预测模型;Associating a first physical block with a first logical segment, where a first key and a first value corresponding to the first key are stored in the first physical block, and the first key and the first key The first storage position of the word in the first physical block satisfies the first position prediction model corresponding to the first logical segment;
    判断第二物理块中存储的第二关键字以及所述第二关键字在所述第二物理块中的第二存储位置是否满足所述第一位置预测模型,所述第二物理块中还存储有所述第二关键字对应的第二值,所述第二物理块与所述第一物理块相邻;Judging whether the second key stored in the second physical block and the second storage position of the second key in the second physical block satisfy the first position prediction model, and the second physical block also A second value corresponding to the second keyword is stored, and the second physical block is adjacent to the first physical block;
    当所述第二关键字以及所述第二存储位置不满足所述第一位置预测模型时,将所述第二物理块与第二逻辑段关联,所述第二关键字以及所述第二存储位置满足所述第二逻辑段对应的第二位置预测模型。When the second key and the second storage location do not satisfy the first location prediction model, associating the second physical block with a second logical segment, the second key and the second The storage location satisfies the second location prediction model corresponding to the second logic segment.
  2. 根据权利要求1所述的方法,其特征在于,所述方法还包括:The method according to claim 1, wherein the method further comprises:
    当所述第二关键字与所述第二存储位置满足所述第一位置预测模型时,将所述第二物理块与所述第一逻辑段关联。The second physical block is associated with the first logical segment when the second key and the second storage location satisfy the first location prediction model.
  3. 根据权利要求1或2所述的方法,其特征在于,所述判断第二物理块中存储的第二关键字以及所述第二关键字在所述第二物理块中的第二存储位置是否满足所述第一位置预测模型,包括:The method according to claim 1 or 2, wherein the judging whether the second key stored in the second physical block and the second storage location of the second key in the second physical block is not Satisfying the first position prediction model includes:
    利用所述第一位置预测模型计算出所述第二关键字在所述第二物理块中的预测位置;using the first position prediction model to calculate the predicted position of the second keyword in the second physical block;
    比较所述预测位置与所述第二存储位置之间的误差是否在预设误差范围内;comparing whether the error between the predicted location and the second storage location is within a preset error range;
    则,所述第二关键字以及所述第二存储位置不满足所述第一位置预测模型,具体为所述预测位置与所述第二存储位置之间的误差超出所述预设误差范围。Then, the second keyword and the second storage location do not satisfy the first location prediction model, specifically, the error between the predicted location and the second storage location exceeds the preset error range.
  4. 根据权利要求1至3任一项所述的方法,其特征在于,所述方法还包括:The method according to any one of claims 1 to 3, wherein the method further comprises:
    向索引块中写入第三关键字以及所述第三关键字对应的第三值,所述第三关键字包括与所述第一逻辑段关联的物理块中的关键字,所述第三值包括所述第一位置预测模型的模型描述值以及与所述第一物理块的首地址。Writing a third key and a third value corresponding to the third key into the index block, where the third key includes a key in the physical block associated with the first logical segment, the third key The value includes the model description value of the first location prediction model and the first address of the first physical block.
  5. 根据权利要求4所述的方法,其特征在于,所述第一位置预测模型包括线性拟合函数,所述第一位置预测模型的模型描述值包括所述线性拟合函数的斜率倒数。The method according to claim 4, wherein the first position prediction model comprises a linear fitting function, and the model description value of the first position prediction model comprises an inverse slope of the linear fitting function.
  6. 根据权利要求5所述的方法,其特征在于,所述线性拟合函数的斜率倒数是对所述第一物理块中相邻两个关键字的差值的平均值进行取整确定的。The method according to claim 5, wherein the reciprocal slope of the linear fitting function is determined by rounding the average value of the difference between two adjacent keywords in the first physical block.
  7. 根据权利要求1至6任一项所述的方法,其特征在于,所述第一逻辑段与所述第一物理块的关联关系,以及所述第二逻辑段与所述第二物理块的关联关系位于日志结构合并树的子树索引结构中。The method according to any one of claims 1 to 6, wherein the association relationship between the first logical segment and the first physical block, and the relationship between the second logical segment and the second physical block The association is in the subtree index structure of the log-structured merge tree.
  8. 一种构建索引的装置,其特征在于,所述装置位于存储设备中,所述装置包括:An apparatus for building an index, wherein the apparatus is located in a storage device, and the apparatus includes:
    关联模块,将第一物理块与第一逻辑段关联,所述第一物理块中存储有第一关键字以及所述第一关键字对应的第一值,所述第一关键字与所述第一关键字在所述第一物理块中的第一存储位置满足所述第一逻辑段对应的第一位置预测模型;an associating module, which associates a first physical block with a first logical segment, where a first keyword and a first value corresponding to the first keyword are stored in the first physical block, and the first keyword is associated with the first keyword. The first storage location of the first keyword in the first physical block satisfies the first location prediction model corresponding to the first logical segment;
    判断模块,用于判断第二物理块中存储的第二关键字以及所述第二关键字在所述第二物理块中的第二存储位置是否满足所述第一位置预测模型,所述第二物理块中还存储有所 述第二关键字对应的第二值,所述第二物理块与所述第一物理块相邻;A judgment module for judging whether the second keyword stored in the second physical block and the second storage location of the second keyword in the second physical block satisfy the first position prediction model, the first The second value corresponding to the second keyword is also stored in the two physical blocks, and the second physical block is adjacent to the first physical block;
    所述关联模块,还用于当所述第二关键字以及所述第二存储位置不满足所述第一位置预测模型时,将所述第二物理块与第二逻辑段关联,所述第二关键字以及所述第二存储位置满足所述第二逻辑段对应的第二位置预测模型。The associating module is further configured to associate the second physical block with a second logical segment when the second key and the second storage location do not satisfy the first location prediction model, the first The second key and the second storage location satisfy the second location prediction model corresponding to the second logic segment.
  9. 根据权利要求8所述的装置,其特征在于,所述关联模块,还用于:The device according to claim 8, wherein the association module is further configured to:
    当所述第二关键字与所述第二存储位置满足所述第一位置预测模型时,将所述第二物理块与所述第一逻辑段关联。The second physical block is associated with the first logical segment when the second key and the second storage location satisfy the first location prediction model.
  10. 根据权利要求8或9所述的装置,其特征在于,所述判断模块,具体用于:The device according to claim 8 or 9, wherein the judging module is specifically used for:
    利用所述第一位置预测模型计算出所述第二关键字在所述第二物理块中的预测位置;using the first position prediction model to calculate the predicted position of the second keyword in the second physical block;
    比较所述预测位置与所述第二存储位置之间的误差是否在预设误差范围内;comparing whether the error between the predicted location and the second storage location is within a preset error range;
    则,所述第二关键字以及所述第二存储位置不满足所述第一位置预测模型,具体为所述预测位置与所述第二存储位置之间的误差超出所述预设误差范围。Then, the second keyword and the second storage location do not satisfy the first location prediction model, specifically, the error between the predicted location and the second storage location exceeds the preset error range.
  11. 根据权利要求8至10任一项所述的装置,其特征在于,所述装置还包括:The device according to any one of claims 8 to 10, wherein the device further comprises:
    写入模块,用于向索引块中写入第三关键字以及所述第三关键字对应的第三值,所述第三关键字包括与所述第一逻辑段关联的物理块中的关键字,所述第三值包括所述第一位置预测模型的模型描述值以及与所述第一物理块的首地址。a writing module, configured to write a third key and a third value corresponding to the third key into the index block, where the third key includes a key in the physical block associated with the first logical segment word, and the third value includes a model description value of the first position prediction model and a first address related to the first physical block.
  12. 根据权利要求11所述的装置,其特征在于,所述第一位置预测模型包括线性拟合函数,所述第一位置预测模型的模型描述值包括所述线性拟合函数的斜率倒数。The apparatus according to claim 11, wherein the first position prediction model comprises a linear fitting function, and the model description value of the first position prediction model comprises an inverse slope of the linear fitting function.
  13. 根据权利要求12所述的装置,其特征在于,所述线性拟合函数的斜率倒数是对所述第一物理块中相邻两个关键字的差值的平均值进行取整确定的。The apparatus according to claim 12, wherein the reciprocal slope of the linear fitting function is determined by rounding the average value of the difference between two adjacent keywords in the first physical block.
  14. 根据权利要求8至13任一项所述的装置,其特征在于,所述第一逻辑段与所述第一物理块的关联关系,以及所述第二逻辑段与所述第二物理块的关联关系位于日志结构合并树的子树索引结构中。The apparatus according to any one of claims 8 to 13, characterized in that the association relationship between the first logical segment and the first physical block, and the relationship between the second logical segment and the second physical block The association is in the subtree index structure of the log-structured merge tree.
PCT/CN2021/094068 2020-08-13 2021-05-17 Index construction method and apparatus WO2022033099A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202010812177.7 2020-08-13
CN202010812177.7A CN114077378A (en) 2020-08-13 2020-08-13 Index construction method and device

Publications (1)

Publication Number Publication Date
WO2022033099A1 true WO2022033099A1 (en) 2022-02-17

Family

ID=80247616

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2021/094068 WO2022033099A1 (en) 2020-08-13 2021-05-17 Index construction method and apparatus

Country Status (2)

Country Link
CN (1) CN114077378A (en)
WO (1) WO2022033099A1 (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101493824A (en) * 2008-12-09 2009-07-29 北京中电飞华通信股份有限公司 Data retrieval method and device for database
CN102024057A (en) * 2010-12-24 2011-04-20 中兴通讯股份有限公司 Method and device for building index of mass data record
US20170351738A1 (en) * 2016-06-06 2017-12-07 Baidu Usa Llc Automatic conversion stage discovery
CN108664509A (en) * 2017-03-31 2018-10-16 华为技术有限公司 A kind of method, apparatus and server of extemporaneous inquiry
CN110633256A (en) * 2019-10-10 2019-12-31 广东电网有限责任公司肇庆供电局 Session Session sharing method in distributed cluster system

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101493824A (en) * 2008-12-09 2009-07-29 北京中电飞华通信股份有限公司 Data retrieval method and device for database
CN102024057A (en) * 2010-12-24 2011-04-20 中兴通讯股份有限公司 Method and device for building index of mass data record
US20170351738A1 (en) * 2016-06-06 2017-12-07 Baidu Usa Llc Automatic conversion stage discovery
CN108664509A (en) * 2017-03-31 2018-10-16 华为技术有限公司 A kind of method, apparatus and server of extemporaneous inquiry
CN110633256A (en) * 2019-10-10 2019-12-31 广东电网有限责任公司肇庆供电局 Session Session sharing method in distributed cluster system

Also Published As

Publication number Publication date
CN114077378A (en) 2022-02-22

Similar Documents

Publication Publication Date Title
US9449005B2 (en) Metadata storage system and management method for cluster file system
WO2020186549A1 (en) Metadata management method, system and medium
US9495398B2 (en) Index for hybrid database
WO2013174305A1 (en) Ssd-based key-value type local storage method and system
US20170068675A1 (en) Method and system for adapting a database kernel using machine learning
WO2018205151A1 (en) Data updating method and storage device
US20220027349A1 (en) Efficient indexed data structures for persistent memory
CN113535670B (en) Virtual resource mirror image storage system and implementation method thereof
US10909091B1 (en) On-demand data schema modifications
CN111159176A (en) Method and system for storing and reading mass stream data
CN109165321A (en) A kind of consistency Hash table construction method and system based on nonvolatile memory
CN114416646A (en) Data processing method and device of hierarchical storage system
CN112732725B (en) NVM (non volatile memory) hybrid memory-based adaptive prefix tree construction method, system and medium
CN113722319A (en) Data storage method based on learning index
WO2022033099A1 (en) Index construction method and apparatus
US10762139B1 (en) Method and system for managing a document search index
JP2014130492A (en) Generation method for index and computer system
CN114896250B (en) Key value separated key value storage engine index optimization method and device
CN116382588A (en) LSM-Tree storage engine read amplification problem optimization method based on learning index
US20220050807A1 (en) Prefix probe for cursor operations associated with a key-value database system
WO2022121274A1 (en) Metadata management method and apparatus in storage system, and storage system
US11500943B2 (en) Method and system for cached early-binding document search
CN115437836A (en) Metadata processing method and related equipment
US11501202B1 (en) Querying databases with machine learning model references
US11880593B2 (en) Host, operating method of host and storage system

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 21855155

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 21855155

Country of ref document: EP

Kind code of ref document: A1