FIELD
[0002] The present disclosure relates to the technical field of data storage, and particularly
to a B+ tree access method and apparatus, and a computer-readable storage medium.
BACKGROUND
[0003] A plenty of B+ tree structures are used in an all-flash array storage system because
of a special structure thereof. For example, an all-flash array generally uses thin
provisioning, and a logical address of a volume is in no longer linear correspondence
but approximately random mapping with a physical address of the volume on a Redundant
Array of Independent Disks (RAID). In order to manage such mapping relationships,
B+ trees are used to store mappings from logical addresses to physical addresses of
volumes and inverse mappings from the physical address to the logical address. For
a de-duplication function of the all-flash array, B+ trees are used to store mappings
from HASH values of data blocks to physical addresses.
[0004] A Dynamic Random Access Memory (DRAM) is a relatively common system memory. Since
the DRAM is a relatively expensive component, only a relatively small number of DRAMs
are configured in a storage system to reduce the cost. In the prior art, data of a
B+ tree is usually stored in a Solid State Drive (SSD). Data in the SSD needs to be
read into the memory first and then read/written, while an Input/Output (10) path
for reading/writing the SSD is relatively long, so the speed is low. Frequently reading
a B+ tree structure into the memory and swapping the B+ tree structure out of the
memory may bring a high Central Processing Unit (CPU) overhead.
[0005] Therefore, how to improve the B+ tree read/write efficiency is a problem that needs
to be solved by those skilled in the art.
SUMMARY
[0006] An objective of embodiments of the present disclosure is to provide a B+ tree access
method and apparatus, and a computer-readable storage medium, thereby improving the
B+ tree read/write efficiency.
[0007] In order to solve the foregoing technical problem, the embodiments of the present
disclosure provide a B+ tree access method, including:
when a B+ tree creation instruction is acquired, determining whether there is an idle
underlying tree file mapped to a DRAM;
if YES, storing underlying data of a B+ tree in the underlying tree file;
if NO, creating a new target underlying tree file, and mapping the target underlying
tree file to the DRAM, so as to store the underlying data of the B+ tree in the target
underlying tree file; and
when a number of layers of the B+ tree is greater than or equal to a preset threshold,
storing, in a preset storage area, data of a layer numbered to be greater than or
equal to the preset threshold in the B+ tree.
[0008] In an embodiment, the B+ tree correspondingly includes a first layer, a second layer,
and a third layer, and data of the first layer is determined as the underlying data;
[0009] Correspondingly, when the number of layers of the B+ tree is greater than or equal
to the preset threshold, storing, in a preset storage area, data of a layer numbered
to be greater than or equal to the preset threshold in the B+ tree includes:
storing data of the second layer of the B+ tree in a Data Center Persistent Memory
Module (DCPMM); and
storing data of the third layer of the B+ tree in a preset hard disk.
[0010] In a further embodiment, before the B+ tree creation instruction is acquired, determining
whether there is an idle underlying tree file mapped to a DRAM, the method further
includes:
determining a minimum read/write granularity of the DCPMM as a node capacity of the
B+ tree.
[0011] In a further embodiment, the step of storing underlying data of the B+ tree in the
underlying tree file includes:
storing the underlying data of the B+ tree in the underlying tree file as a separate
piece of node data according to the node capacity, wherein an offset address of a
node of a next layer is stored in a key-value pair of the separate piece of node data.
[0012] In a further embodiment, the method further includes:
when a data query instruction is acquired, determining a root node according to a
logical address contained in the data query instruction; and
determining a leaf node according to an offset address in the root node, and reading
data corresponding to the leaf node.
[0013] In a further embodiment, the method further includes:
when a data modification instruction is acquired, determining whether there is node
data matched with a node identifier contained in the data modification instruction
in the DRAM;
if YES, modifying the node data according to surrogate data contained in the data
modification instruction, and setting a dirty flag for modified node data;
if NO, determining whether there is the node data matched with the node identifier
contained in the data modification instruction in the DCPMM;
when there is the node data matched with the node identifier contained in the data
modification instruction in the DCPMM, modifying the node data according to surrogate
data contained in the data modification instruction;
when there is no node data matched with the node identifier contained in the data
modification instruction in the DCPMM, reading the node data matched with the node
identifier contained in the data modification instruction from the hard disk to the
DRAM; and completing, in the DRAM, modification of the node data according to surrogate
data contained in the data modification instruction, and setting the dirty flag for
modified node data.
[0014] In a further embodiment, after storing underlying data of the B+ tree in the underlying
tree file, the method further includes:
migrating data mapped to the DRAM and set with the dirty flag to the DCPMM according
to preset periodic time.
[0015] The embodiments of the present disclosure also provide a B+ tree access apparatus,
including a first judgment unit, a first storage unit, a creation unit, and a second
storage unit.
[0016] The first judgment unit is configured to, when a B+ tree creation instruction is
acquired, determine whether there is an idle underlying tree file mapped to a DRAM,
if YES, trigger the first storage unit, or if NO, trigger the creation unit.
[0017] The first storage unit is configured to store underlying data of a B+ tree in the
underlying tree file.
[0018] The creation unit is configured to create a new target underlying tree file, and
map the target underlying tree file to the DRAM, so as to store the underlying data
of the B+ tree in the target underlying tree file.
[0019] The second storage unit is configured to, when a number of layers of the B+ tree
is greater than or equal to a preset threshold, store, in a preset storage area, data
of a layer numbered to be greater than or equal to the preset threshold in the B+
tree.
[0020] In an embodiment, the B+ tree correspondingly includes a first layer, a second layer,
and a third layer, and data of the first layer is determined as the underlying data.
[0021] Correspondingly, the second storage unit is specifically configured to store data
of the second layer of the B+ tree in a DCPMM, and store data of the third layer of
the B+ tree in a preset hard disk.
[0022] In a further embodiment, the apparatus further includes a determining-as unit.
[0023] The determining-as unit is configured to determine a minimum read/write granularity
of the DCPMM as a node capacity of the B+ tree.
[0024] In a further embodiment, the first storage unit is specifically configured to store
the underlying data of the B+ tree in the underlying tree file as a separate piece
of node data according to the node capacity, wherein an offset address of a node of
a next layer is stored in a key-value pair of the separate piece of node data.
[0025] In a further embodiment, the apparatus further includes a query unit, a determination
unit, and a reading unit.
[0026] The query unit is configured to, when a data query instruction is acquired, determine
a root node according to a logical address contained in the data query instruction.
[0027] The determination unit is configured to determine a leaf node according to an offset
address in the root node.
[0028] The reading unit is configured to read data corresponding to the leaf node.
[0029] In a further embodiment, the apparatus further includes a second judgment unit, a
modification unit, a setting unit, a third judgment unit, and a reading unit.
[0030] The second judgment unit is configured to, when a data modification instruction is
acquired, determine whether there is node data matched with a node identifier contained
in the data modification instruction in the DRAM, if YES, trigger the modification
unit, or if NO, trigger the third judgment unit.
[0031] The modification unit is configured to modify the node data according to surrogate
data contained in the data modification instruction.
[0032] The setting unit is configured to set a dirty flag for modified node data.
[0033] The third judgment unit determines whether there is the node data matched with the
node identifier contained in the data modification instruction in the DCPMM
[0034] The modification unit is further configured to, when there is the node data matched
with the node identifier contained in the data modification instruction in the DCPMM,
modify the node data according to surrogate data contained in the data modification
instruction.
[0035] The reading unit is configured to, when there is no node data matched with the node
identifier contained in the data modification instruction in the DCPMM, read the node
data matched with the node identifier contained in the data modification instruction
from the hard disk to the DRAM
[0036] The modification unit is further configured to complete, in the DRAM, modification
of the node data according to surrogate data contained in the data modification instruction,
and trigger the setting unit to set the dirty flag for modified node data.
[0037] In a further embodiment, the apparatus further includes a migration unit.
[0038] The migration unit is configured to migrate the data mapped to the DRAM and set with
the dirty flag to the DCPMM according to preset periodic time.
[0039] The embodiments of the present disclosure also provide a B+ tree access apparatus,
including:
a memory, configured to store a computer program; and
a processor, configured to execute the computer program to implement any steps of
the B+ tree access method as described above.
[0040] The embodiments of the present disclosure also provide a computer-readable storage
medium, storing a computer program that is executed by a processor to implement any
steps of the B+ tree access method as described above.
[0041] It can be seen from the above technical solutions that, when a B+ tree creation instruction
is acquired, whether there is an idle underlying tree file mapped to a DRAM is determined.
When there is the idle underlying tree file mapped to the DRAM, underlying data of
a B+ tree may be directly stored in the underlying tree file. When there is no idle
underlying tree file mapped to the DRAM, it is necessary to create a new target underlying
tree file and map the target underlying tree file to the DRAM, so as to store the
underlying data of the B+ tree in the target underlying tree file. When a number of
layers of the B+ tree is greater than or equal to a preset threshold, data of a layer
numbered to be greater than or equal to the preset threshold in the B+ tree is stored
in a preset storage area. On the basis of a data structure of the B+ tree, data needs
to be accessed from the underlying data whenever read, so the underlying data is accessed
more. An underlying file is stored in the idle underlying tree file mapped to the
DRAM, whereby the efficiency of accessing the underlying data is effectively improved.
The other data in the B+ tree except the underlying data is accessed less, and in
order to reduce the occupation of the DRAM, the other data may be stored in a storage
space other than the DRAM. Therefore, the utilization rate of DRAM resources is increased,
and the B+ tree read/write efficiency may also be ensured.
BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to describe the embodiments of the present disclosure more clearly, the
drawings required to be used in the embodiments will be introduced briefly below.
Apparently, the drawings in the description below are only some embodiments of the
present disclosure. Those ordinarily skilled in the art may further obtain other drawings
according to these drawings without creative work.
Fig. 1 is a flowchart of a B+ tree access method according to an embodiment of the
present disclosure;
Fig. 2 is a flowchart of a B+ tree data modification method according to an embodiment
of the present disclosure;
Fig. 3 is a schematic structural diagram of a B+ tree access apparatus according to
an embodiment of the present disclosure; and
Fig. 4 is a schematic diagram of a hardware structure of a B+ tree access apparatus
according to an embodiment of the present disclosure.
DETAILED DESCRIPTION
[0043] The technical solutions in the embodiments of the present disclosure will be described
clearly and completely below in combination with the drawings in the embodiments of
the present disclosure. Clearly, the described embodiments are not all but only part
of embodiments of the present disclosure. All other embodiments obtained by those
ordinarily skilled in the art based on the embodiments in the present disclosure without
creative work shall fall within the scope of protection of the present disclosure.
[0044] In order to make the solutions of the present disclosure understood better by those
skilled in the art, the present disclosure will be further described below in detail
in combination with the drawings and specific embodiments.
[0045] AB+ tree access method provided in the embodiments of the present disclosure is then
introduced in detail. Fig. 1 is a flowchart of a B+ tree access method according to
an embodiment of the present disclosure. The method includes the following steps.
[0046] In S101, when a B+ tree creation instruction is acquired, whether there is an idle
underlying tree file mapped to a DRAM is determined.
[0047] When there is the idle underlying tree file mapped to the DRAM, it indicates that
there is a file available for storing a B+ tree in the DRAM. In such case, S102 may
be performed.
[0048] When there is no idle underlying tree file mapped to the DRAM, it indicates that
there is no file for storing a B+ tree in the current DRAM. In such case, S103 may
be performed.
[0049] In S102, underlying data of a B+ tree is stored in the underlying tree file.
[0050] In S103, a new target underlying tree file is created, and the target underlying
tree file is mapped to the DRAM, so as to store the underlying data of the B+ tree
in the target underlying tree file.
[0051] On the basis of a data structure of the B+ tree, data needs to be accessed from the
underlying data whenever read, so the underlying data is accessed more frequently.
An underlying file is stored in the idle underlying tree file mapped to the DRAM,
whereby the efficiency of accessing the underlying data is effectively improved.
[0052] It is to be noted that, for ease of distinction, in the embodiment of the present
disclosure, a newly created underlying tree file is referred to as a target underlying
tree file. For a storage system, both the newly created target underlying tree file
and the underlying tree file are files for storing the underlying data, and there
are no substantial differences therebetween.
[0053] In S104, when a number of layers of the B+ tree is greater than or equal to a preset
threshold, data of a layer numbered to be greater than or equal to the preset threshold
in the B+ tree is stored in a preset storage area.
[0054] The B+ tree includes multiple layers of data. In the embodiment of the present disclosure,
the data of the B+ tree may be divided into different layers, and frequencies and
numbers of times of accessing the data of different layers are different. Therefore,
the data of different layers may be stored at different positions.
[0055] In a specific implementation, the B+ tree may be divided into a first layer, a second
layer, and a third layer. The data of the first layer is determined as the underlying
data.
[0056] At the beginning of creation of the B+ tree, the underlying data is accessed more
frequently. Therefore, in the embodiment of the present disclosure, the underlying
data is stored in the idle underlying tree file mapped to the DRAM
[0057] Considering that a DCPMM may implement direct data access without the DRAM in a Device
Direct Access (DAX) mode, a DCPMM device in the Device DAX mode may be regarded as
a DCPMM. In the embodiment of the present disclosure, data of the second layer of
the B+ tree may be stored in a DCPMM
[0058] In order to accurately control the use of the DCPMM and avoid DCPMM resources being
wasted, data of the third layer of the B+ tree may be stored in a preset hard disk.
[0059] In practical applications, a first-layer file to a third-layer file of the B+ tree
may be determined as the first layer, a fourth-layer file and a fifth-layer file may
be determined as the second layer, and the data above a fifth-layer file may be determined
as the third layer.
[0060] It can be seen from the above technical solutions that, when a B+ tree creation instruction
is acquired, whether there is an idle underlying tree file mapped to a DRAM is determined.
When there is the idle underlying tree file mapped to the DRAM, underlying data of
a B+ tree may be directly stored in the underlying tree file. When there is no idle
underlying tree file mapped to the DRAM, it is necessary to create a new target underlying
tree file and map the target underlying tree file to the DRAM, so as to store the
underlying data of the B+ tree in the target underlying tree file. When a number of
layers of the B+ tree is greater than or equal to a preset threshold, data of a layer
numbered to be greater than or equal to the preset threshold in the B+ tree is stored
in a preset storage area. On the basis of a data structure of the B+ tree, data needs
to be accessed from the underlying data whenever read, so the underlying data is accessed
more. An underlying file is stored in the idle underlying tree file mapped to the
DRAM, whereby the efficiency of accessing the underlying data is effectively improved.
The other data in the B+ tree except the underlying data is accessed less, and in
order to reduce the occupation of the DRAM, the other data may be stored in a storage
space other than the DRAM. Therefore, the utilization rate of DRAM resources is increased,
and the B+ tree read/write efficiency may also be ensured.
[0061] At the beginning of creation of the B+ tree, the underlying data is accessed more
frequently, and thus may be stored in the DRAM. As storage time increases, the underlying
data of the B+ tree is no longer accessed so frequently. In order to increase the
utilization rate of the DRAM, during specific implementation, a dirty flag may be
set for the underlying data stored in the DRAM, and then the underlying data stored
in the DRAM may be migrated to the DCPMM periodically.
[0062] In order to improve the data read efficiency, during specific implementation, a minimum
read/write granularity of the DCPMM may be determined as a node capacity of the B+
tree. An internal minimum read/write granularity of the DCPMM is 256 bytes, so a capacity
of a B+ tree node may be set to 256 bytes, namely a set of check protection data is
generated by every 256 bytes of data.
[0063] In the embodiment of the present disclosure, the underlying data of the B+ tree may
be stored in the underlying tree file as a separate piece of node data according to
the node capacity. An offset address of a node of a next layer is stored in a key-value
pair of the separate piece of node data.
[0064] In practical applications, each node may include a 16-byte node header and at most
15 key-value pairs. The node header includes a node type and other information. The
node type includes a leaf node and a non-leaf node. For a leaf node, a value in a
key-value pair thereof is a RAID physical address, and specific data corresponding
to the leaf node may be read according to the RAID physical address. For a non-leaf
node, an offset address of a node of a next layer may be stored in a key-value pair
thereof.
[0065] When a data query instruction is acquired, a root node may be determined according
to a logical address contained in the data query instruction. A leaf node is determined
according to an offset address in the root node. Data corresponding to the leaf node
is read.
[0066] For example, when data of the B+ tree needs to be queried, a logical address of a
data volume may be contained in a data query instruction. Metadata of the data volume
may be found according to the logical address. If a memory address of a root node
is protected in the metadata, an underlying tree file of the tree is in the memory.
A leaf node may be searched according to an offset address stored in the corresponding
node in the underlying tree file. If no leaf node is found till a third-layer node,
an offset address of the corresponding node in a third-layer file is read from the
metadata, thereby obtaining a storage address of a fourth-layer file. If this node
is still a non-leaf node, a fifth-layer node continues to be accessed. If the fifth-layer
node is still not a leaf node, the third-layer file is read into the memory to continue
searching until a leaf node is found. Specific data corresponding to the leaf node
may be read according to a RAID physical address stored in a key-value pair of the
leaf node.
[0067] The data of the B+ tree is stored at different positions according to the divided
layers. When data of the B+ tree needs to be modified, the storage position of the
data that needs to be modified may be queried according to the storage positions,
thereby implementing modification of the data in the B+ tree. Fig. 2 is a flowchart
of a B+ tree data modification method according to an embodiment of the present disclosure,
including the following steps.
[0068] In S201, when a data modification instruction is acquired, whether there is node
data matched with a node identifier contained in the data modification instruction
in the DRAM is determined.
[0069] When there is the node data matched with the node identifier contained in the data
modification instruction in the DRAM, S202 is performed.
[0070] When there is no node data matched with the node identifier contained in the data
modification instruction in the DRAM, it is necessary to further determine a position
of the node data that needs to be modified. In such case, S203 may be performed.
[0071] In S202, the node data is modified according to surrogate data contained in the data
modification instruction, and a dirty flag is set for modified node data.
[0072] Storing the node data in the DRAM may occupy DRAM resources. In order to increase
the utilization rate of the DRAM resources, a dirty flag may be set for modified node
data, and then the data mapped to the DRAM and set with the dirty flag may subsequently
be migrated to the DCPMM according to preset periodic time.
[0073] In S203, whether there is the node data matched with the node identifier contained
in the data modification instruction in the DCPMM is determined.
[0074] When there is the node data matched with the node identifier contained in the data
modification instruction in the DCPMM, S204 is performed.
[0075] In the embodiment of the present disclosure, the data of the B+ tree may be stored
in the DRAM, the DCPMM, and the preset hard disk respectively according to different
layers. When there is no node data matched with the node identifier contained in the
data modification instruction in the DRAM, and there is no node data matched with
the node identifier contained in the data modification instruction in the DCPMM, it
indicates that the node data that needs to be modified is stored in the preset hard
disk. In such case, S205 may be performed.
[0076] In S204, the node data is modified according to surrogate data contained in the data
modification instruction.
[0077] In S205, the node data matched with the node identifier contained in the data modification
instruction is read from the hard disk to the DRAM
[0078] Since data in the hard disk is not directly modifiable, when the node data that needs
to be modified is stored in the preset hard disk, the node data matched with the node
identifier contained in the data modification instruction needs to be read from the
hard disk to the DRAM
[0079] In S206, modification of the node data is completed in the DRAM according to surrogate
data contained in the data modification instruction, and a dirty flag is set for modified
node data.
[0080] When the node data that needs to be modified is stored in the DRAM or the hard disk,
the modified node data may be stored in the DRAM. Since there are limited DRAM resources,
to avoid the modified node data occupying the DRAM resources for long, in the embodiment
of the present disclosure, a dirty flag may be set for the modified node data stored
in the DRAM, and then the data mapped to the DRAM and set with the dirty flag may
subsequently be migrated to the DCPMM according to preset periodic time.
[0081] The data stored in the DRAM is migrated periodically, whereby the long-term occupation
of the DRAM resources by the data of the B+ tree is avoided, and the processing performance
of the storage system is improved effectively.
[0082] Fig. 3 is a schematic structural diagram of a B+ tree access apparatus according
to an embodiment of the present disclosure, including a first judgment unit 31, a
first storage unit 32, a creation unit 33, and a second storage unit 34.
[0083] The first judgment unit 31 is configured to, when a B+ tree creation instruction
is acquired, determine whether there is an idle underlying tree file mapped to a DRAM,
if YES, trigger the first storage unit 32, or if NO, trigger the creation unit 33.
[0084] The first storage unit 32 is configured to store underlying data of a B+ tree in
the underlying tree file.
[0085] The creation unit 33 is configured to create a new target underlying tree file, and
map the target underlying tree file to the DRAM, so as to store the underlying data
of the B+ tree in the target underlying tree file.
[0086] The second storage unit 34 is configured to, when a number of layers of the B+ tree
is greater than or equal to a preset threshold, store, in a preset storage area, data
of a layer numbered to be greater than or equal to the preset threshold in the B+
tree.
[0087] Optionally, the B+ tree correspondingly includes a first layer, a second layer, and
a third layer, and data of the first layer is determined as the underlying data.
[0088] Correspondingly, the second storage unit is specifically configured to store data
of the second layer of the B+ tree in a DCPMM, and store data of the third layer of
the B+ tree in a preset hard disk.
[0089] Optionally, the apparatus further includes a determining-as unit.
[0090] The determining-as unit is configured to determine a minimum read/write granularity
of the DCPMM as a node capacity of the B+ tree.
[0091] Optionally, the first storage unit is specifically configured to store the underlying
data of the B+ tree in the underlying tree file as a separate piece of node data according
to the node capacity, wherein an offset address of a node of a next layer is stored
in a key-value pair of the separate piece of node data.
[0092] Optionally, the apparatus further includes a query unit, a determination unit, and
a reading unit.
[0093] The query unit is configured to, when a data query instruction is acquired, determine
a root node according to a logical address contained in the data query instruction.
[0094] The determination unit is configured to determine a leaf node according to an offset
address in the root node.
[0095] The reading unit is configured to read data corresponding to the leaf node.
[0096] Optionally, the apparatus further includes a second judgment unit, a modification
unit, a setting unit, a third judgment unit, and a reading unit.
[0097] The second judgment unit is configured to, when a data modification instruction is
acquired, determine whether there is node data matched with a node identifier contained
in the data modification instruction in the DRAM, if YES, trigger the modification
unit, or if NO, trigger the third judgment unit.
[0098] The modification unit is configured to modify the node data according to surrogate
data contained in the data modification instruction.
[0099] The setting unit is configured to set a dirty flag for modified node data.
[0100] The third judgment unit determines whether there is the node data matched with the
node identifier contained in the data modification instruction in the DCPMM
[0101] The modification unit is further configured to, when there is the node data matched
with the node identifier contained in the data modification instruction in the DCPMM,
modify the node data according to surrogate data contained in the data modification
instruction.
[0102] The reading unit is configured to, when there is no node data matched with the node
identifier contained in the data modification instruction in the DCPMM, read the node
data matched with the node identifier contained in the data modification instruction
from the hard disk to the DRAM
[0103] The modification unit is further configured to complete, in the DRAM, modification
of the node data according to surrogate data contained in the data modification instruction,
and trigger the setting unit to set a dirty flag for modified node data.
[0104] Optionally, the apparatus further includes a migration unit.
[0105] The migration unit is configured to migrate the data mapped to the DRAM and set with
the dirty flag to the DCPMM according to preset periodic time.
[0106] Descriptions about features in the embodiment corresponding to Fig. 3 may refer to
the related descriptions in the embodiments corresponding to Figs. 1 and 2. Elaborations
are omitted herein.
[0107] It can be seen from the above technical solutions that, when a B+ tree creation instruction
is acquired, whether there is an idle underlying tree file mapped to a DRAM is determined.
When there is the idle underlying tree file mapped to the DRAM, underlying data of
a B+ tree may be directly stored in the underlying tree file. When there is no idle
underlying tree file mapped to the DRAM, it is necessary to create a new target underlying
tree file and map the target underlying tree file to the DRAM, so as to store the
underlying data of the B+ tree in the target underlying tree file. When a number of
layers of the B+ tree is greater than or equal to a preset threshold, data of a layer
numbered to be greater than or equal to the preset threshold in the B+ tree is stored
in a preset storage area. On the basis of a data structure of the B+ tree, data needs
to be accessed from the underlying data whenever read, so the underlying data is accessed
more. An underlying file is stored in the idle underlying tree file mapped to the
DRAM, whereby the efficiency of accessing the underlying data is effectively improved.
The other data in the B+ tree except the underlying data is accessed less, and in
order to reduce the occupation of the DRAM, the other data may be stored in a storage
space other than the DRAM. Therefore, the utilization rate of DRAM resources is increased,
and the B+ tree read/write efficiency may also be ensured.
[0108] Fig. 4 is a schematic diagram of a hardware structure of a B+ tree access apparatus
40 according to an embodiment of the present disclosure, including:
a memory 41, configured to store a computer program; and
a processor 42, configured to execute the computer program to implement any steps
of the B+ tree access method as described in any one of the above-mentioned embodiments.
[0109] The embodiments of the present disclosure also provide a computer-readable storage
medium, storing a computer program that is executed by a processor to implement any
steps of the B+ tree access method as described in any one of the above-mentioned
embodiments.
[0110] The B+ tree access method and apparatus and computer-readable storage medium provided
in the embodiments of the present disclosure are introduced above in detail. Each
embodiment in the specification is described progressively. Descriptions made in each
embodiment focus on differences from the other embodiments, and the same or similar
parts in each embodiment refer to the other embodiments. The apparatus disclosed in
the embodiments corresponds to the method disclosed in the embodiments, and thus is
described relatively briefly, and related parts refer to the descriptions about the
method. It is to be pointed out that those ordinarily skilled in the art may further
make a plurality of improvements and embellishments to the present disclosure without
departing from the principle of the present disclosure, and these improvements and
embellishments shall also fall within the scope of protection of the claims of the
present disclosure.
[0111] Professionals may further realize that the units and algorithm steps of each example
described in combination with the embodiments disclosed herein may be implemented
by electronic hardware, computer software, or a combination thereof. In order to describe
the interchangeability of hardware and software clearly, the compositions and steps
of each example have been described generally in the foregoing descriptions according
to functions. Whether these functions are executed by hardware or software depends
on specific applications and design constraints of the technical solutions. Professionals
may realize the described functions for each specific application by use of different
methods, but such realization shall fall within the scope of the present disclosure.
[0112] The steps of the method or algorithm described in combination with the embodiments
disclosed herein may directly be implemented by hardware, a software module executed
by the processor, or a combination thereof. The software module may be arranged in
a Random Access Memory (RAM), an internal memory, a Read-Only Memory (ROM), an electrically
programmable ROM, an electrically erasable programmable ROM, a register, a hard disk,
a removable disk, a Compact Disc Read-Only Memory (CD-ROM), or a storage medium in
any other form well known in this art.
1. A B+ tree access method,
characterized by comprising:
when a B+ tree creation instruction is acquired, determining whether there is an idle
underlying tree file mapped to a Dynamic Random Access Memory (DRAM);
if YES, storing underlying data of a B+ tree in the underlying tree file;
if NO, creating a new target underlying tree file, and mapping the target underlying
tree file to the DRAM, so as to store the underlying data of the B+ tree in the target
underlying tree file; and
when a number of layers of the B+ tree is greater than or equal to a preset threshold,
storing, in a preset storage area, data of a layer numbered to be greater than or
equal to the preset threshold in the B+ tree.
2. The method according to claim 1,
characterized in that the B+ tree correspondingly comprises a first layer, a second layer, and a third
layer, and data of the first layer is determined as the underlying data; and
correspondingly, when the number of layers of the B+ tree is greater than or equal
to the preset threshold, storing, in a preset storage area, data of a layer numbered
to be greater than or equal to the preset threshold in the B+ tree comprises:
storing data of the second layer of the B+ tree in a Data Center Persistent Memory
Module (DCPMM), and
storing data of the third layer of the B+ tree in a preset hard disk.
3. The method according to claim 2, characterized in that before the B+ tree creation instruction is acquired, determining whether there is
an idle underlying tree file mapped to a DRAM, the method further comprises:
determining a minimum read/write granularity of the DCPMM as a node capacity of the
B+ tree.
4. The method according to claim 3, characterized in that the step of storing underlying data of the B+ tree in the underlying tree file comprises:
storing the underlying data of the B+ tree in the underlying tree file as a separate
piece of node data according to the node capacity, wherein an offset address of a
node of a next layer is stored in a key-value pair of the separate piece of node data.
5. The method according to claim 4,
characterized by further comprising:
when a data query instruction is acquired, determining a root node according to a
logical address contained in the data query instruction; and
determining a leaf node according to an offset address in the root node, and reading
data corresponding to the leaf node.
6. The method according to claim 2,
characterized by further comprising:
when a data modification instruction is acquired, determining whether there is node
data matched with a node identifier contained in the data modification instruction
in the DRAM;
if YES, modifying the node data according to surrogate data contained in the data
modification instruction, and setting a dirty flag for modified node data;
if NO, determining whether there is the node data matched with the node identifier
contained in the data modification instruction in the DCPMM;
when there is the node data matched with the node identifier contained in the data
modification instruction in the DCPMM, modifying the node data according to surrogate
data contained in the data modification instruction;
when there is no node data matched with the node identifier contained in the data
modification instruction in the DCPMM, reading the node data matched with the node
identifier contained in the data modification instruction from the hard disk to the
DRAM; and completing, in the DRAM, modification of the node data according to surrogate
data contained in the data modification instruction, and setting the dirty flag for
modified node data.
7. The method according to claim 6, characterized in that after storing underlying data of the B+ tree in the underlying tree file, the method
further comprises:
migrating data mapped to the DRAM and set with the dirty flag to the DCPMM according
to preset periodic time.
8. A B+ tree access apparatus,
characterized by comprising a first judgment unit, a first storage unit, a creation unit, and a second
storage unit, wherein
the first judgment unit is configured to, when a B+ tree creation instruction is acquired,
determine whether there is an idle underlying tree file mapped to a Dynamic Random
Access Memory (DRAM), if YES, trigger the first storage unit, or if NO, trigger the
creation unit;
the first storage unit is configured to store underlying data of a B+ tree in the
underlying tree file;
the creation unit is configured to create a new target underlying tree file, and map
the target underlying tree file to the DRAM, so as to store the underlying data of
the B+ tree in the target underlying tree file; and
the second storage unit is configured to, when a number of layers of the B+ tree is
greater than or equal to a preset threshold, store, in a preset storage area, data
of a layer numbered to be greater than or equal to the preset threshold in the B+
tree.
9. A B+ tree access apparatus,
characterized by comprising:
a memory, configured to store a computer program; and
a processor, configured to execute the computer program to implement any steps of
the B+ tree access method according to any one of claims 1-7.
10. A computer-readable storage medium, characterized by storing a computer program that is executed by a processor to implement any steps
of the B+ tree access method according to any one of claims 1-7.