Tree structure data storage method, electronic equipment and computer program product

By using different data files to store intermediate nodes and leaf nodes of tree structure data in blockchain technology, and using the index information of the parent node for positioning, the problem of low efficiency of tree structure data query is solved, and efficient data query is achieved.

CN120030013APending Publication Date: 2025-05-23HANGZHOU HIGH-TECH ZONE (BINJIANG) INSTITUTE OF BLOCKCHAIN & DATA SECURITY
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411958220.5
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-26
Publication Date
2025-05-23

AI Technical Summary

Technical Problem

In existing blockchain technology, the query efficiency of tree structure data is low because the levelDB series database does not natively support tree structures and cannot directly understand the levels and relationships between nodes.

Method used

Different data files store data of intermediate nodes and leaf nodes in tree structure data respectively, and use the index information of the parent node to directly locate the data storage location of the child node, achieving efficient addressing from the root node to any child node.

Benefits of technology

The data query efficiency of tree structure data is improved, and the problem of low data query efficiency in the prior art is solved.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120030013A_ABST
    Figure CN120030013A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of block chains, and provides a tree structure data storage method, electronic equipment and a computer program product. The method comprises the following steps: obtaining to-be-stored tree structure data, wherein the tree structure data comprises a plurality of intermediate nodes and a plurality of leaf nodes; for each leaf node, writing data of the leaf node into a first data file, and recording index information of the leaf node into data of a father node of the leaf node; for each intermediate node except the root node, after index information of all child nodes of the intermediate node is recorded in the data of the intermediate node, writing the data of the intermediate node into a second data file, and recording the index information of the intermediate node into data of a father node of the intermediate node; and writing the data of the root node into the second data file, and storing the index information of the root node. By adopting the method, efficient addressing from the root node to any child node can be realized, and the data query efficiency of the tree structure data is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of blockchain technology, and in particular to a tree structure data storage method, electronic device and computer program product. Background Art

[0002] In the blockchain technology scenario, in order to improve data security, a tree structure is usually used to store account data, that is, account tree data. Tree structure data includes leaf nodes and intermediate nodes, where leaf nodes store original key-value pairs and intermediate nodes serve as indexes. At present, the levelDB series database is usually used as the underlying storage solution for tree structure data. This type of database has efficient data writing performance. However, the levelDB series database does not natively support tree structures and cannot directly understand the hierarchy and relationship between nodes, resulting in low data query efficiency. Summary of the invention

[0003] In view of this, embodiments of the present application provide a tree structure data storage method, electronic device, and computer program product, which can improve the data query efficiency of tree structure data.

[0004] A first aspect of an embodiment of the present application provides a tree structure data storage method, including:

[0005] Obtaining tree structure data to be stored, the tree structure data including a plurality of intermediate nodes and a plurality of leaf nodes;

[0006] For each leaf node, write the data of the leaf node into the first data file, and record the index information of the leaf node into the data of the parent node of the leaf node, where the index information of the leaf node is used to indicate the storage location of the data of the leaf node;

[0007] For each intermediate node except the root node, after the data of the intermediate node has recorded the index information of all child nodes of the intermediate node, the data of the intermediate node is written into the second data file, and the index information of the intermediate node is recorded into the data of the parent node of the intermediate node, and the index information of the intermediate node is used to indicate the storage location of the data of the intermediate node;

[0008] The data of the root node is written into the second data file, and the index information of the root node is stored, where the index information of the root node is used to indicate the storage location of the data of the root node.

[0009] The technical solution of the embodiment of the present application, after acquiring the tree structure data to be stored, writes the data of each leaf node into the first data file, and records the index information of the leaf node into the data of the corresponding parent node; writes the data of each intermediate node into the second data file, and records the index information of the intermediate node into the data of the corresponding parent node; finally, writes the data of the root node into the second data file, and stores the index information of the root node. The above process stores the data of the intermediate nodes and the data of the leaf nodes respectively through different data files. When it is necessary to query the node data, the storage position of the root node data in the data file can be located according to the index information of the root node, and the storage position of the child node data in the data file can be located according to the index information of the child node contained in the data of the parent node, thereby realizing efficient addressing from the root node to any child node, and improving the data query efficiency of the tree structure data.

[0010] In an implementation of the embodiment of the present application, the first data file has multiple first storage spaces of the same size, and the data size of each leaf node does not exceed the size of the first storage space; the second data file has multiple second storage spaces of the same size, and the data size of each intermediate node does not exceed the size of the second storage space;

[0011] Writing the data of the leaf node into the first data file and recording the index information of the leaf node into the data of the parent node of the leaf node includes:

[0012] Obtaining a first bitmap file corresponding to the first data file, wherein each bit of the first bitmap file is used to indicate the occupancy of each first storage space of the first data file;

[0013] According to the first bitmap file, obtaining a free first storage space from the first data file;

[0014] Writing the data of the leaf node into the free first storage space, and recording the file identifier of the first data file and the space identifier of the free first storage space into the data of the parent node of the leaf node;

[0015] Writing the data of the intermediate node into the second data file and recording the index information of the intermediate node into the data of the parent node of the intermediate node includes:

[0016] Acquire a second bitmap file corresponding to the second data file, where each bit of the second bitmap file is used to represent the occupancy of each second storage space of the second data file;

[0017] According to the second bitmap file, obtaining a free second storage space from the second data file;

[0018] The data of the intermediate node is written into the free second storage space, and the file identifier of the second data file and the space identifier of the free second storage space are recorded in the data of the parent node of the intermediate node.

[0019] In one implementation of the embodiment of the present application, the first bitmap file has multiple bitmap blocks, each bitmap block has m bits, m>1; the first bitmap file has multiple levels of first bitmap indexes, each bitmap block of the first bitmap index of the lowest level is used to indicate the occupancy of the m bitmap blocks of the first bitmap file, and each bitmap block of the first bitmap index of the upper level is used to indicate the occupancy of the m bitmap blocks of the first bitmap index of the lower level; the second bitmap file has multiple bitmap blocks, each bitmap block has n bits, n>1; the second bitmap file has multiple levels of second bitmap indexes, each bitmap block of the second bitmap index of the lowest level is used to indicate the occupancy of the n bitmap blocks of the second bitmap file, and each bitmap block of the second bitmap index of the upper level is used to indicate the occupancy of the n bitmap blocks of the second bitmap index of the lower level;

[0020] According to the first bitmap file, obtaining a free first storage space from the first data file includes:

[0021] Scanning the bits of the first value layer by layer starting from the first bitmap index of the highest level until a first bit of a first value in the first bitmap file is obtained;

[0022] Acquire a first storage space corresponding to the first bit from the first data file as the free first storage space;

[0023] According to the second bitmap file, obtaining an idle second storage space from the second data file includes:

[0024] Scanning the bits of the first value layer by layer starting from the second bitmap index of the highest level until a second bit of the first value in the second bitmap file is obtained;

[0025] A second storage space corresponding to the second bit is obtained from the second data file as the free second storage space.

[0026] In one implementation of the embodiment of the present application, the method further includes:

[0027] If data is written into any first storage space of the first data file, the third bit corresponding to the first storage space in the first bitmap file is updated to the second value;

[0028] If all bits contained in the first bitmap block where the third bit is located in the first bitmap file are the second value, then the fourth bit corresponding to the first bitmap block in the first bitmap index of the lowest level is updated to the second value until the bit update of the first bitmap index of the highest level is completed;

[0029] If data is written into any second storage space of the second data file, the fifth bit corresponding to the any second storage space in the second bitmap file is updated to a second value;

[0030] If all bits contained in the second bitmap block where the fifth bit is located in the second bitmap file are the second value, the sixth bit corresponding to the second bitmap block in the second bitmap index of the lowest level is updated to the second value until the bit update of the second bitmap index of the highest level is completed.

[0031] In one implementation of the embodiment of the present application, the method further includes:

[0032] If data is deleted from any first storage space of the first data file, the seventh bit corresponding to the any first storage space in the first bitmap file is updated to the first value;

[0033] Determine the third bitmap block where the seventh bit in the first bitmap file is located;

[0034] If the eighth bit corresponding to the third bitmap block in the first bitmap index of the lowest level is the second value, the eighth bit is updated to the first value until the bit update of the first bitmap index of the highest level is completed;

[0035] If data is deleted from any second storage space of the second data file, updating the ninth bit corresponding to the arbitrary second storage space in the second bitmap file to the first value;

[0036] Determine the fourth bitmap block where the ninth bit in the second bitmap file is located;

[0037] If the tenth bit corresponding to the fourth bitmap block in the second bitmap index of the lowest level is the second value, the tenth bit is updated to the first value until the bit update of the second bitmap index of the highest level is completed.

[0038] In one implementation of the embodiment of the present application, the method further includes:

[0039] When the node data of the tree structure data is updated, the first bitmap file, the first bitmap indexes of multiple levels, the second bitmap file and the second bitmap indexes of multiple levels stored in the memory are updated, and the corresponding bitmap update data is recorded in the designated file;

[0040] When the amount of bitmap update data recorded in the designated file reaches a set threshold, the first bitmap file, the first bitmap indexes of multiple levels, the second bitmap file and the second bitmap indexes of multiple levels stored in the memory are updated to the disk.

[0041] In one implementation of the embodiment of the present application, the method further includes:

[0042] When a new node is added to the tree structure data, the type of the new node is determined;

[0043] If the type of the new node is a leaf node, the data of the new node is written into the first data file, and the data of the parent node of the new node stored in the second data file is updated according to the index information of the new node and the type of the new node;

[0044] If the type of the new node is an intermediate node, the data of the new node is written into the second data file, and the data of the parent node of the new node stored in the second data file is updated according to the index information of the new node and the type of the new node.

[0045] In one implementation of the embodiment of the present application, the method further includes:

[0046] When the tree structure data deletes the target node, determine the type of the target node;

[0047] If the type of the target node is a leaf node, the data of the target node stored in the first data file is deleted, and the data of the parent node of the target node stored in the second data file is updated;

[0048] If the type of the target node is an intermediate node, the data of the target node stored in the second data file is deleted, and the data of the parent node of the target node stored in the second data file is updated.

[0049] A second aspect of an embodiment of the present application provides a tree structure data storage device, including:

[0050] A data acquisition module is used to acquire tree structure data to be stored, where the tree structure data includes a number of intermediate nodes and a number of leaf nodes;

[0051] A leaf node writing module is used to write the data of each leaf node into the first data file, and record the index information of the leaf node into the data of the parent node of the leaf node, where the index information of the leaf node is used to indicate the storage location of the data of the leaf node;

[0052] An intermediate node writing module is used for, for each intermediate node except the root node, after the data of the intermediate node has recorded the index information of all child nodes of the intermediate node, writing the data of the intermediate node into the second data file, and recording the index information of the intermediate node into the data of the parent node of the intermediate node, wherein the index information of the intermediate node is used to indicate the storage location of the data of the intermediate node;

[0053] The root node writing module is used to write the data of the root node into the second data file and store the index information of the root node, where the index information of the root node is used to indicate the storage location of the data of the root node.

[0054] A third aspect of an embodiment of the present application provides an electronic device, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the computer program, the tree structure data storage method provided in the first aspect of the embodiment of the present application is implemented.

[0055] A fourth aspect of the embodiments of the present application provides a computer program product. When the computer program product runs on an electronic device, the electronic device executes the tree structure data storage method provided in the first aspect of the embodiments of the present application.

[0056] A fifth aspect of the embodiments of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements the tree structure data storage method provided in the first aspect of the embodiments of the present application.

[0057] It can be understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0058] Figure 1 This is a flowchart of a tree structure data storage method provided by an embodiment of the present application;

[0059] Figure 2 It is a structural logic diagram of an account tree provided in an embodiment of the present application;

[0060] Figure 3 It is a schematic diagram of the working principle of the data file, bitmap file and bitmap index provided in the embodiment of the present application;

[0061] Figure 4 This is a schematic diagram of the operation principle of updating tree structure data provided by an embodiment of the present application;

[0062] Figure 5 It is a structural schematic diagram of a tree structure data storage device provided in an embodiment of the present application;

[0063] Figure 6 It is a schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0064] In the following description, for the purpose of illustration rather than limitation, specific details such as specific system structures, technologies, etc. are proposed, so as to thoroughly understand the embodiments of the present application. However, it should be clear to those skilled in the art that the present application can also be implemented in other embodiments without these specific details. In other cases, the detailed description of well-known systems, devices, circuits and methods is omitted to prevent unnecessary details from hindering the description of the present application. In addition, in the description of the present application specification and the attached claims, the terms "first", "second", "third" etc. are only used to distinguish the description, and cannot be interpreted as indicating or suggesting relative importance.

[0065] In the field of blockchain technology, in order to improve data security, a tree structure is usually used to store account data. Account data is usually of fixed length. For example, the fields of an Ethereum account include: [address (account address, 20 bytes)]-[nonce (incrementing number, 8 bytes)]-[balance (balance, 32 bytes)]-[stateRoot (Merkel root hash, 32 bytes)]-[codeHash (contract code hash, 32 bytes)], totaling 124 bytes. Tree structure data includes leaf nodes and intermediate nodes, where leaf nodes store original key-value pairs and intermediate nodes serve as indexes. At present, the levelDB series database is usually used as the underlying storage solution for tree structure data. This type of database has efficient data writing performance but slow data reading speed, and there is a problem of "fast writing and slow reading". Specifically, the levelDB series database does not natively support tree structure and cannot directly understand the hierarchy and relationship between nodes. Even if the parent node logically knows the key of the child node, the actual query still needs to go through the database interface, which is heavily dependent on the query performance of the database. The query performance of the levelDB series database is insufficient, resulting in low data query efficiency.

[0066] In response to the above-mentioned problems existing in the use of levelDB series databases, the embodiments of the present application propose a tree structure data storage method, electronic device, and computer program product, which use different data files to store the data of intermediate nodes and leaf nodes respectively, and can directly locate the storage location of the child node data in the data file according to the data of the parent node, thereby effectively improving the data query efficiency of the tree structure data. For more specific technical implementation details of the embodiments of the present application, please refer to the various method embodiments described below.

[0067] It should be understood that the execution subjects of the various method embodiments proposed in this application can be various types of electronic devices, such as mobile phones, tablet computers, wearable devices, learning machines, augmented reality (AR) / virtual reality (VR) devices, laptops, ultra-mobile personal computers (UMPC), netbooks, personal digital assistants (PDA), large-screen TVs, etc. The embodiments of this application do not impose any restrictions on the specific types of the electronic devices. For example, if applied to the scenario of blockchain account tree storage, the electronic device can be any blockchain node.

[0068] See also Figure 1 , shows a tree structure data storage method provided by an embodiment of the present application, including:

[0069] 101. Obtain tree structure data to be stored, where the tree structure data includes a number of intermediate nodes and a number of leaf nodes;

[0070] First, the tree structure data to be stored is obtained. The tree structure data can be any type of tree structure data, for example, it can be the MPT (Merkle Patricia Tree) state tree or JMT (Jellyfish Merkle Tree) state tree commonly used in blockchain systems, etc. The tree structure data includes several intermediate nodes and several leaf nodes. The embodiment of the present application does not impose any restrictions on the type of tree structure data stored, the number of intermediate nodes, the number of leaf nodes, and the node connection relationship.

[0071] As an example, the tree structure data to be stored may be an account tree, whose nodes are divided into two types: intermediate nodes and leaf nodes. The leaf nodes store the actual account data, while the intermediate nodes perform the indexing function. Figure 2 This is a structural logic diagram of an account tree provided by an embodiment of the present application. The structural logic of the account tree belongs to a 16-fork dictionary tree variant. The node forks of the tree structure are generated in sequence according to the hexadecimal characters of the leaf node keys, forming a hierarchical structure similar to a dictionary tree. Each intermediate node of the account tree can contain up to 16 child nodes, corresponding to hexadecimal characters 0 to F respectively. The key of the leaf node is composed of hexadecimal characters and is matched to the corresponding fork position layer by layer. For example, Figure 2 Six leaf nodes are shown, whose keys are ABCD, ACDE, ACEF, BCDE, BCFE and BDEF respectively.

[0072] 102. For each leaf node, write the data of the leaf node into the first data file, and record the index information of the leaf node into the data of the parent node of the leaf node;

[0073] To facilitate the management and reading of node data, the technical solution of the embodiment of the present application stores the data of the intermediate nodes and the data of the leaf nodes respectively through different data files, wherein the data files storing the leaf node data are recorded as the first data files. It should be noted that the first data file can be one or more data files. For example, if the amount of data of the leaf node is too large to be stored in one data file, multiple first data files for storing the leaf node data can be constructed, and different first data files correspond to different file identifiers (such as file numbers).

[0074] The technical solution of the embodiment of the present application writes the index information of the child node into the data of its parent node for preservation, so that the storage position of the child node's data in the data file can be located according to the index information of the child node contained in the data of the parent node. Based on this feature, it is necessary to store the data of the child node first to obtain the corresponding index information, and write the index information of the child node into the data of the parent node, and then store the data of the parent node. Considering that the leaf node has no child node, and the root node has no parent node, the data of each node can be written into the corresponding data file in the order of traversing upward layer by layer of the leaf node, the intermediate node of the non-root node, and the root node. According to the above-mentioned operating principle, an optional node traversal order is to traverse all leaf nodes first, then traverse all intermediate nodes of the level connected to the leaf node, and then traverse all intermediate nodes of the upper level, and so on until traversing all nodes. However, since the index information of the child node needs to be temporarily stored in the memory before writing the data of the parent node, if the number of nodes is too large, it will cause the problem of excessive memory usage. Another optional node traversal order does not require traversing all nodes level by level. As long as the data of all child nodes of a certain intermediate node have been written into the corresponding data file and the corresponding index information has been obtained, the index information can be written into the data of the intermediate node, and then the data of the intermediate node can be written into the data file without waiting for all nodes of the next level of the intermediate node to be traversed. This node traversal order does not need to temporarily store the index information of a large number of nodes in the memory, so it can avoid the problem of excessive memory usage.

[0075] For leaf nodes, their data may include the node key value, hash value, and other fields stored according to business needs. For example, the data of the leaf nodes of the account tree may include account address, increment number, account balance, Merkle root hash, and contract code hash. As an example, the length of the leaf node data of the account tree is fixed at 164 bytes, which is used to store the actual data of the account. The fields it contains are defined as follows:

[0076] [Current Node Hash] (32 bytes): Hash value identifying the node, used for Merkle path verification;

[0077] [Version number] (8 bytes): used to record the updated version of the node;

[0078] [address] (20 bytes): account address;

[0079] [nonce (incremental number)] (8 bytes): records the number of transactions of the account;

[0080] [balance] (32 bytes): account balance;

[0081] [stateRoot] (32 bytes): The Merkle root hash representing the account state;

[0082] [codeHash] (32 bytes): records the hash value of the smart contract code.

[0083] For each leaf node, when traversing to the leaf node, the data of the leaf node will be written into the first data file, and the index information of the leaf node will be recorded in the data of the parent node of the leaf node. The index information of the leaf node is used to indicate the storage location of the data of the leaf node, and may specifically include information such as file identification, file offset, and storage space identification. Using the index information of the leaf node, the corresponding first data file and the storage location of the data of the leaf node in the first data file can be found, so that the data of the leaf node can be easily read out.

[0084] In an implementation of the embodiment of the present application, the first data file has multiple first storage spaces of the same size, and the data size of each leaf node does not exceed the size of the first storage space; writing the data of the leaf node into the first data file, and recording the index information of the leaf node into the data of the parent node of the leaf node, including:

[0085] (1) obtaining a first bitmap file corresponding to the first data file, wherein each bit of the first bitmap file is used to indicate the occupancy of each first storage space of the first data file;

[0086] (2) obtaining a free first storage space from the first data file according to the first bitmap file;

[0087] (3) The data of the leaf node is written into the free first storage space, and the file identifier of the first data file and the space identifier of the free first storage space are recorded in the data of the parent node of the leaf node.

[0088] To facilitate the addressing of node data, the first data file can be divided into multiple first storage spaces of the same size, and the data size of each leaf node does not exceed the size of the first storage space, so that the data of each leaf node can be written into a first storage space respectively. For example, if the length of the leaf node data of the known account tree is fixed to 164 bytes, the size of each storage space of the first data file can be set to 164 bytes or more, so that each storage space can be used to store the data of a leaf node respectively, and different storage spaces can be distinguished by their respective space identifiers. For example, assuming that a first data file is divided into n storage spaces, these storage spaces can be numbered in sequence from 1 to n to obtain their respective space identifiers. If the fixed size of each storage space is 100B, and the number of storage spaces n is 1024*1024*1024=1073741824, then the size of the first data file is approximately 100GB, which can be used to store a large amount of leaf node data of 100GB. Moreover, multiple first data files may be set for expansion. For example, m first data files may be set, so that m*100GB of leaf node data can be stored. Different first data files may be distinguished by their respective file identifiers.

[0089] In order to facilitate the management of the usage status of each storage space in the first data file and record whether each storage space is occupied or idle, a corresponding first bitmap file can be set for each first data file, and each bit of the first bitmap file is used to indicate the occupancy status of each first storage space of the corresponding first data file. A bitmap is an efficient way to store data, usually used to represent a set of binary data or a set of mark states. A bitmap represents the state of an element in the set through each bit, and is usually stored using an array or other data structure. For example, assuming that the first data file has n first storage spaces, its corresponding first bitmap file has n bits, and the n bits correspond one-to-one to the n first storage spaces, and each bit indicates whether the state of the corresponding first storage space is "idle" or "occupied" through a value of "0" or "1". In the initial state, the first data file does not store any node data, so all bits of the first bitmap file are 0. One byte of the first bitmap file contains 8 bits, which can be used to manage 8 storage spaces. Therefore, using the first bitmap file can significantly save storage space. For example, the storage space status of a 1GB data file only needs about 128KB of a bitmap file to manage.

[0090] When writing the data of each leaf node into the first data file, it is necessary to allocate a free storage space for the data of each leaf node. Assuming that the data of a certain leaf node is currently being written, first obtain the first bitmap file corresponding to the first data file, and then obtain a free first storage space from the first data file according to the first bitmap file, that is, scan and search for the first storage space corresponding to a certain bit "0" from the first bitmap file. Afterwards, write the data of the leaf node into the free first storage space, and the file identifier of the first data file and the space identifier of the free first storage space are used as the index information of the leaf node and recorded in the data of the parent node of the leaf node.

[0091] Since the number of bits in the first bitmap file is usually very large, if a large amount of the first storage space of the corresponding first data file has been occupied, it may take a long time to scan and find the bit "0" from the first bitmap file, resulting in low scanning efficiency. In order to improve the scanning efficiency of the bitmap file and obtain the free storage space in the data file more quickly, a multi-level bitmap index can be set for the bitmap file, as described below.

[0092] In an implementation of the embodiment of the present application, the first bitmap file has multiple bitmap blocks, each bitmap block has m bits, m>1; the first bitmap file has multiple levels of first bitmap indexes, each bitmap block of the first bitmap index of the lowest level is used to indicate the occupancy of the m bitmap blocks of the first bitmap file, and each bitmap block of the first bitmap index of the upper level is used to indicate the occupancy of the m bitmap blocks of the first bitmap index of the next level; according to the first bitmap file, obtaining a free first storage space from the first data file includes:

[0093] (1) Scanning the bits of the first value layer by layer starting from the first bitmap index of the highest level until a first bit of a first value in the first bitmap file is obtained;

[0094] (2) Obtaining a first storage space corresponding to the first bit from the first data file as the free first storage space.

[0095] In actual operation, all bits of the first bitmap file can be divided into multiple bitmap blocks, each bitmap block has m bits, m>1, so that m bits are managed as a bitmap block. The first bitmap file can set multiple levels of first bitmap indexes, wherein each bitmap block of the first bitmap index of the lowest level is used to indicate the occupancy of m bitmap blocks of the first bitmap file, that is, each bit of the first bitmap index of the lowest level is used to indicate the occupancy of 1 bitmap block (m bits) of the first bitmap file. If the m bits of a bitmap block of the first bitmap file are all 1 (indicating that the current bitmap block has no corresponding free storage space), the bit corresponding to the bitmap block in the first bitmap index of the lowest level is 1. If the m bits of a bitmap block of the first bitmap file are not all 1 (indicating that the current bitmap block has at least one free storage space), the bit corresponding to the bitmap block in the first bitmap index of the lowest level is 0, and so on. Each bitmap block of the first bitmap index of the previous level is used to indicate the occupancy of the m bitmap blocks of the first bitmap index of the next level, that is, each bit of the first bitmap index of the previous level is used to indicate the occupancy of 1 bitmap block (m bits) of the first bitmap index of the next level. If the m bits of a bitmap block of the first bitmap index of the next level are all 1 (indicating that the current bitmap block has no corresponding free storage space), the bit corresponding to the bitmap block in the first bitmap index of the previous level is 1. If the m bits of a bitmap block of the first bitmap index of the next level are not all 1 (indicating that the current bitmap block has at least one free storage space), the bit corresponding to the bitmap block in the first bitmap index of the previous level is 0, and so on. Bitmap indexes can be nested in multiple layers until the highest level bitmap index has only one bitmap block.

[0096] As an example, assuming that the first data file has 1024*1024*1024=1073741824 storage spaces, the first bitmap file has 1073741824 bits, and each bitmap block has 64 bits (i.e., m=64). In this way, the first bitmap file has 1073741824 / 64=16777216 bitmap blocks, the first bitmap index of the first level (lowest level) has 16777216 / 64=262144 bitmap blocks, the first bitmap index of the second level has 262144 / 64=4096 bitmap blocks, the first bitmap index of the third level has 4096 / 64=64 bitmap blocks, and the first bitmap index of the fourth level (highest level) has 64 / 64=1 bitmap block. Each bitmap block has 64 bits and is 8 bytes in size, so the size of the first bitmap index of the fourth level is 8 bytes, the size of the first bitmap index of the third level is 512 bytes, the size of the first bitmap index of the second level is 32KB, the size of the first bitmap index of the first level is approximately 2MB, and the size of the first bitmap file is approximately 128MB. The total size of the first bitmap file plus the multi-level bitmap index is approximately 130.03MB, and the data space required is relatively small.

[0097] By using the first bitmap file and its multi-level bitmap index, when obtaining a free first storage space from the first data file, a layer-by-layer scanning method starting from the highest-level bitmap index can be adopted. Specifically, the bits of the first value are scanned layer by layer starting from the highest-level first bitmap index until the first bit of a first value in the first bitmap file is obtained, and then the first storage space corresponding to the first bit is obtained from the first data file as the obtained free first storage space. Taking the first bitmap index of the above four levels as an example, first, scan the 64 bits of a bitmap block of the first bitmap index of the fourth level in a set order (for example, from left to right) to find a bit with a first value, for example, find the first bit n1 with a value of 0; the value of bit n1 is 0, indicating that the "n1"th bitmap block corresponding to the bit n1 in the first bitmap index of the third level has a free bit (a bit with a value of 0), then scan the 64 bits of the "n1"th bitmap block of the first bitmap index of the third level in a set order to find a bit with a first value. Special bit, for example, the first bit n2 with a value of 0 is found; the value of bit n2 is 0, which means that there is a free bit in the "n1×64+n2"th bitmap block corresponding to bit n2 in the first bitmap index of the second level. Next, the 64 bits of the "n1×64+n2"th bitmap block of the first bitmap index of the second level are scanned in the set order to find a bit of the first value... and so on, until a bit of the first value is found from the first bitmap file, recorded as the first bit x, so that the first storage space corresponding to x in the first data file is the found free storage space. Assuming that the space identifier of a first storage space is x, its offset in the first data file is (x-1)×len, and len represents the fixed size of the first storage space. When writing or reading leaf node data, the first data file can be operated according to the corresponding offset. Using the above-mentioned free storage space scanning method, in the worst case, each level of the bitmap index needs to scan a complete bitmap block (64 bits, 8 bytes), so the 4-level bitmap index plus the first bitmap file need to scan 5*8=40 bytes, that is, only 40 bytes at most need to be scanned to complete the free storage space scanning process. It can be seen that the scanning efficiency can be effectively improved, and the free storage space in the data file can be obtained more quickly.

[0098] 103. For each intermediate node except the root node, after the data of the intermediate node has recorded the index information of all child nodes of the intermediate node, write the data of the intermediate node into the second data file, and record the index information of the intermediate node into the data of the parent node of the intermediate node;

[0099] The technical solution of the embodiment of the present application stores the data of the intermediate node and the data of the leaf node respectively through different data files, wherein the data stored in the intermediate node is recorded as the second data file. Similar to the first data file, the second data file can also be one or more data files. For example, if the amount of data of the intermediate node is too large to be stored in one data file, multiple second data files for storing the intermediate node data can be constructed, and different second data files correspond to different file identifiers (such as file numbers).

[0100] The technical solution of the embodiment of the present application writes the index information of the child node into the data of its parent node for storage. Based on this feature, it is necessary to first store the data of the child node to obtain the corresponding index information, and then write the index information of the child node into the data of the parent node, and then store the data of the parent node. Therefore, for each intermediate node, the data of the intermediate node is written into the second data file only after the data of the intermediate node has recorded the index information of all the child nodes of the intermediate node.

[0101] For an intermediate node, its data may include storage contents such as the node's hash value, version number, and child node information.

[0102] As an example, the length of the intermediate node data of the account tree is fixed at 264 bytes, and the fields it contains are defined as follows:

[0103] [Current node hash] (32 bytes): hash value that identifies the node;

[0104] [Version number] (8 bytes): used to record the updated version of the node and quickly find the latest data;

[0105] [Slot list of 16 child nodes] (224 bytes): used to store the slot information of the 16 child nodes of the current node, each child node occupies 14 bytes.

[0106] The slot information length of a single child node is 14 bytes, and its fields are defined as follows:

[0107] [Existence flag] (1 byte): indicates whether the slot has a child node. 0 indicates no child node, and 1 indicates yes child node.

[0108] [Node Type] (1 byte): identifies the type of the child node. 0 indicates an intermediate node and 1 indicates a leaf node.

[0109] [Node index in the data file, i.e. index information] (12 bytes): locates the storage location of the child node data, which may include the following two fields:

[0110] [File Number] (4 bytes): indicates the data file number where the child node data is located;

[0111] [Data page number] (8 bytes): indicates the specific page number of the child node data in the data file. Each storage space of the data file can be called a data page, and the corresponding space is identified as the data page number.

[0112] For each intermediate node except the root node, after the data of the intermediate node has recorded the index information of all the child nodes of the intermediate node, the data of the intermediate node is written into the second data file, and the index information of the intermediate node is recorded in the data of the parent node of the intermediate node. The index information of the intermediate node is used to indicate the storage location of the data of the intermediate node, and may specifically include information such as file identification, file offset, and storage space identification. Using the index information of the intermediate node, the corresponding second data file and the storage location of the data of the intermediate node in the second data file can be found, so that the data of the intermediate node can be easily read out.

[0113] In an implementation of the embodiment of the present application, the second data file has multiple second storage spaces of the same size, and the data size of each intermediate node does not exceed the size of the second storage space; writing the data of the intermediate node into the second data file, and recording the index information of the intermediate node into the data of the parent node of the intermediate node, including:

[0114] (1) obtaining a second bitmap file corresponding to the second data file, wherein each bit of the second bitmap file is used to represent the occupancy status of each second storage space of the second data file;

[0115] (2) acquiring an idle second storage space from the second data file according to the second bitmap file;

[0116] (3) The data of the intermediate node is written into the free second storage space, and the file identifier of the second data file and the space identifier of the free second storage space are recorded in the data of the parent node of the intermediate node.

[0117] Similar to the first data file, the second data file can also be divided into multiple second storage spaces of the same size, and the data size of each intermediate node does not exceed the size of the second storage space, so that the data of each intermediate node can be written into a second storage space respectively. For example, if the length of the intermediate node data of the known account tree is fixed to 264 bytes, the size of each storage space of the second data file can be set to 264 bytes or more, so that each storage space can be used to store the data of an intermediate node respectively, and different storage spaces can be distinguished by their respective space identifiers. For example, assuming that a second data file is divided into n storage spaces, these storage spaces can be numbered in sequence from 1 to n to obtain their respective space identifiers. If the fixed size of each storage space is 100B, and the number of storage spaces n is 1024*1024*1024=1073741824, then the size of the second data file is approximately 100GB, which can be used to store a large amount of 100GB of intermediate node data. Moreover, multiple second data files may be set for expansion. For example, m second data files may be set, so that m*100GB of intermediate node data can be stored. Different second data files may be distinguished by their respective file identifiers.

[0118] Similarly, in order to facilitate the management of the usage status of each storage space in the second data file and record whether each storage space is occupied or idle, a corresponding second bitmap file can be set for each second data file, and each bit of the second bitmap file is used to indicate the occupancy status of each second storage space of the corresponding second data file. For example, assuming that the second data file has n second storage spaces, its corresponding second bitmap file has n bits, and the n bits correspond one-to-one to the n second storage spaces, and each bit indicates whether the status of the corresponding second storage space is "idle" or "occupied" through a value of "0" or "1". In the initial state, the second data file does not store any node data, so all bits of the second bitmap file are 0.

[0119] When writing the data of each intermediate node into the second data file, it is necessary to allocate a free storage space for the data of each intermediate node. Assuming that the data of a certain intermediate node is currently being written, the second bitmap file corresponding to the second data file is first obtained, and then a free second storage space is obtained from the second data file according to the second bitmap file, that is, the second storage space corresponding to a bit "0" is scanned from the second bitmap file. After that, the data of the intermediate node is written into the free second storage space, and the file identifier of the second data file and the space identifier of the free second storage space are used as the index information of the intermediate node and recorded in the data of the parent node of the intermediate node.

[0120] Similar to the first bitmap file, in order to improve the scanning efficiency of the bitmap file and obtain the free storage space in the second data file more quickly, a multi-level bitmap index may also be set for the second bitmap file, as described below.

[0121] In an implementation of the embodiment of the present application, the second bitmap file has multiple bitmap blocks, each bitmap block has n bits, n>1; the second bitmap file has multiple levels of second bitmap indexes, each bitmap block of the second bitmap index of the lowest level is used to indicate the occupancy of n bitmap blocks of the second bitmap file, and each bitmap block of the second bitmap index of the upper level is used to indicate the occupancy of n bitmap blocks of the second bitmap index of the lower level; according to the second bitmap file, obtaining a free second storage space from the second data file includes:

[0122] (1) scanning the bits of the first value layer by layer starting from the second bitmap index of the highest level until a second bit of the first value in the second bitmap file is obtained;

[0123] (2) Obtaining a second storage space corresponding to the second bit position from the second data file as the free second storage space.

[0124] Similar to the operation process of the first bitmap file, all bits of the second bitmap file can be divided into multiple bitmap blocks, each bitmap block has n bits, n>1, so that n bits are managed as a bitmap block. The second bitmap file can set multiple levels of second bitmap indexes, wherein each bitmap block of the second bitmap index of the lowest level is used to indicate the occupancy of n bitmap blocks of the second bitmap file, that is, each bit of the second bitmap index of the lowest level is used to indicate the occupancy of 1 bitmap block (n bits) of the second bitmap file. If the n bits of a bitmap block of the second bitmap file are all 1 (indicating that the current bitmap block has no corresponding free storage space), the bit corresponding to the bitmap block in the second bitmap index of the lowest level is 1. If the n bits of a bitmap block of the second bitmap file are not all 1 (indicating that the current bitmap block has at least one free storage space), the bit corresponding to the bitmap block in the second bitmap index of the lowest level is 0, and so on. Each bitmap block of the second bitmap index of the previous level is used to indicate the occupancy status of the n bitmap blocks of the second bitmap index of the next level, that is, each bit of the second bitmap index of the previous level is used to indicate the occupancy status of one bitmap block (n bits) of the second bitmap index of the next level. If the n bits of a bitmap block of the second bitmap index of the next level are all 1 (indicating that the current bitmap block has no corresponding free storage space), the bit corresponding to the bitmap block in the second bitmap index of the previous level is 1; if the n bits of a bitmap block of the second bitmap index of the next level are not all 1 (indicating that the current bitmap block has at least one free storage space), the bit corresponding to the bitmap block in the second bitmap index of the previous level is 0, and so on.

[0125] By using the second bitmap file and its multi-level bitmap index, when obtaining a free second storage space from the second data file, a layer-by-layer scanning method starting from the highest-level bitmap index can be adopted. Specifically, the bits of the first value are scanned layer by layer starting from the highest-level second bitmap index until a second bit of a first value in the second bitmap file is obtained, and then the second storage space corresponding to the second bit is obtained from the second data file as the obtained free second storage space.

[0126] As an example, Figure 3 It is a schematic diagram of the working principle of the data file, bitmap file and bitmap index provided in the embodiment of the present application. Figure 3The data files, bitmap files and bitmap indexes shown can be applicable to the storage and indexing of leaf node data (corresponding to the first data file, the first bitmap index and the first bitmap indexes of multiple levels described above), and can also be applicable to the storage and indexing of intermediate node data (corresponding to the second data file, the second bitmap index and the second bitmap indexes of multiple levels described above). Each data file may include multiple storage spaces, each storage space is called a data page, and the space size is fixed to len bytes; each bitmap block of the bitmap file includes 64 bits, each bit is used to indicate the occupancy of the corresponding data page in the data file, "0" indicates that the data page is free, and "1" indicates that the data page is occupied; each bitmap block of the first-level bitmap index includes 64 bits, each bit is used to indicate the occupancy of the corresponding bitmap block in the bitmap file, "0" indicates that the bitmap block has at least one free bit, and "1" indicates that the bitmap block has no free bits; each bitmap block of the second-level bitmap index includes 64 bits, each bit is used to indicate the occupancy of the corresponding bitmap block in the first-level bitmap index, "0" indicates that the bitmap block has at least one free bit, and "1" indicates that the bitmap block has no free bits, and so on, and higher-level bitmap indexes can be expanded. By introducing bitmap files and multiple levels of bitmap indexes, the retrieval efficiency of free storage space in data files can be effectively improved.

[0127] When writing node data to a data file, the corresponding storage space is marked as occupied, and the bits of the bitmap file and the bitmap index need to be updated accordingly. Similarly, when deleting node data from a data file, the corresponding storage space can be reclaimed and marked as free, and the bits of the bitmap file and the bitmap index also need to be updated accordingly. See below for details.

[0128] In one implementation of the embodiment of the present application, the method further includes:

[0129] (1) if data is written into any first storage space of the first data file, updating the third bit corresponding to the first storage space in the first bitmap file to the second value;

[0130] (2) If all bits contained in the first bitmap block where the third bit is located in the first bitmap file are the second value, then the fourth bit corresponding to the first bitmap block in the first bitmap index of the lowest level is updated to the second value until the bit update of the first bitmap index of the highest level is completed;

[0131] (3) if data is written into any second storage space of the second data file, updating the fifth bit corresponding to the arbitrary second storage space in the second bitmap file to the second value;

[0132] (4) If all bits contained in the second bitmap block where the fifth bit is located in the second bitmap file are the second value, the sixth bit corresponding to the second bitmap block in the second bitmap index of the lowest level is updated to the second value until the bit update of the second bitmap index of the highest level is completed.

[0133] If data is written into any first storage space of the first data file, the third bit corresponding to the arbitrary first storage space in the first bitmap file is updated to the second value, and if all bits contained in the first bitmap block where the third bit is located in the first bitmap file are the second value, then the fourth bit corresponding to the first bitmap block in the lowest level first bitmap index is updated to the second value, and so on, layer by layer, until the bit update of the first bitmap index at the highest level is completed. Similarly, if data is written into any second storage space of the second data file, the fifth bit corresponding to the arbitrary second storage space in the second bitmap file is updated to the second value, and if all bits contained in the second bitmap block where the fifth bit is located in the second bitmap file are the second value, then the sixth bit corresponding to the second bitmap block in the second bitmap index at the lowest level is updated to the second value, and so on, layer by layer, until the bit update of the second bitmap index at the highest level is completed. For example, assuming that data is written to the storage space x of the data file, the "x"th bit of the bitmap file is updated to 1. If the 64 bits in the bitmap block where the "x"th bit in the bitmap file is located are not all 1, the bits of the bitmap indexes at each level do not need to be updated. The bitmap block where the "x"th bit in the bitmap file is located can be calculated using x / 64. If x / 64≤1, it is the first bitmap block. If 1<x / 64≤2, it is the second bitmap block, and so on. Conversely, if the 64 bits in the bitmap block where the "x"th bit in the bitmap file is located are all 1, the bit corresponding to the bitmap block in the bitmap index of the first level needs to be updated to 1, and so on. The bit update of the bitmap index is completed level by level until the bit update of the bitmap index of the highest level is completed.

[0134] In one implementation of the embodiment of the present application, the method further includes:

[0135] (1) if data is deleted from any first storage space of the first data file, updating the seventh bit corresponding to the any first storage space in the first bitmap file to the first value;

[0136] (2) determining the third bitmap block where the seventh bit in the first bitmap file is located;

[0137] (3) If the eighth bit corresponding to the third bitmap block in the first bitmap index of the lowest level is the second value, the eighth bit is updated to the first value until the bit update of the first bitmap index of the highest level is completed;

[0138] (4) if data is deleted from any second storage space of the second data file, updating the ninth bit corresponding to the arbitrary second storage space in the second bitmap file to the first value;

[0139] (5) determining the fourth bitmap block where the ninth bit in the second bitmap file is located;

[0140] (6) If the tenth bit corresponding to the fourth bitmap block in the second bitmap index of the lowest level is the second value, the tenth bit is updated to the first value until the bit update of the second bitmap index of the highest level is completed.

[0141] If data is deleted from any first storage space of the first data file, the seventh bit corresponding to the arbitrary first storage space in the first bitmap file is updated to the first value, the third bitmap block where the seventh bit is located in the first bitmap file is determined, and it is determined whether the eighth bit corresponding to the third bitmap block in the first bitmap index of the lowest level is the second value. If so, the eighth bit is updated to the first value, layer by layer, until the bit update of the first bitmap index of the highest level is completed. Similarly, if data is deleted from any second storage space of the second data file, the ninth bit corresponding to the arbitrary second storage space in the second bitmap file is updated to the first value, the fourth bitmap block where the ninth bit is located in the second bitmap file is determined, and it is determined whether the tenth bit corresponding to the fourth bitmap block in the second bitmap index of the lowest level is the second value. If so, the tenth bit is updated to the first value, layer by layer, until the bit update of the second bitmap index of the highest level is completed. For example, assuming that data is deleted from the storage space x of the data file, the "x"th bit of the bitmap file is updated to 0, the bitmap block y where the "x"th bit of the bitmap file is located is determined, and it is determined whether the bit corresponding to the bitmap block y in the first-level bitmap index is 1. If it is 1, since there is free storage space at this time, the bit corresponding to the bitmap block y in the first-level bitmap index needs to be updated to 0; if it is 0, the bits of the bitmap indexes at each level do not need to be updated. In the same way, the bit updates of the bitmap indexes are completed level by level until the bit updates of the highest-level bitmap indexes are completed.

[0142] 104. Write the data of the root node into a second data file, and store index information of the root node, where the index information of the root node is used to indicate a storage location of the data of the root node.

[0143] After the data of all leaf nodes of the tree structure data are written into the first data file in the manner described above, and the data of all intermediate nodes except the root node are written into the second data file, the data of the root node is stored. Since the root node is also an intermediate node, the data of the root node is also written into the second data file. However, since the root node has no parent node, the parent node cannot be used to store the index information of the root node, so the index information of the root node needs to be stored in other places, for example, the index information of the root node can be stored separately in a key-value database, or in the last storage space of the second data file. The index information of the root node is used to indicate the storage location of the data of the root node, and may specifically include information such as a file identifier, a file offset, and a storage space identifier. Using the index information of the root node, the corresponding second data file and the storage location of the data of the root node in the second data file can be found, so that the data of the root node can be easily read out.

[0144] After all the node data of the tree structure data are written into the corresponding data files in the above manner, the following describes how to read the tree structure data from each data file. In one implementation of the embodiment of the present application, the method further includes:

[0145] (1) When a request to read data of any leaf node among several leaf nodes is received, the index information of the root node is read;

[0146] (2) Reading the data of the root node from the second data file according to the index information of the root node;

[0147] (3) reading, from the data of the root node, the index information of the first child node corresponding to the addressing path of any leaf node in the tree structure data;

[0148] (4) If the first child node is any leaf node, then read the data of any leaf node from the first data file according to the index information of the first child node;

[0149] (5) If the first child node is not any leaf node, then according to the index information of the first child node, the data of the first child node is read from the second data file, and from the data of the first child node, the index information of the second child node corresponding to the addressing path is read until the index information of any leaf node is obtained; according to the index information of any leaf node, the data of any leaf node is read from the first data file.

[0150] When a request to read the data of any leaf node in the tree structure data is received, the index information of the root node is first read from the key-value database or other locations. Based on the index information, the data of the root node can be located and read from the second data file. For example, assuming that the index information includes a file identifier and a space identifier, the corresponding second data file is first found according to the file identifier, and then the corresponding storage space in the second data file is found according to the space identifier. Here, the space identifier can be converted into a corresponding file offset to read the corresponding node data; then, the data of the root node is parsed, and the index information of the first child node corresponding to the addressing path of any leaf node in the tree structure data is read. For example, if the addressing path is 2D5B, the slot information of the third child node corresponding to slot "2" can be read from the slot list of the 16 child nodes of the root node, and the index information of the child node (such as the file number and data page number) can be read from the slot information; if the first child node If the type is a leaf node, the first child node is the leaf node that needs to be read, so the data of the leaf node can be located and read from the first data file according to the index information of the first child node; if the type of the first child node is an intermediate node, it means that the first child node is not the leaf node that needs to be read. At this time, the data of the first child node is located and read from the second data file according to the index information of the first child node, and then the index information of the second child node corresponding to the addressing path is read from the data of the first child node. For example, the slot information of the 14th child node corresponding to slot "D" is read from the slot list of the 16 child nodes of the first child node, and the index information of the second child node is read from the slot information; next, the type of the second child node is determined in the same way, and the addressing is performed downward layer by layer until the index information of the leaf node is obtained, and finally the data of the leaf node is located and read from the first data file according to the index information of the leaf node. It can be seen from this that when it is necessary to query node data, the storage location of the root node data in the data file can be located based on the index information of the root node, and the storage location of the child node data in the data file can be located based on the index information of the child node contained in the parent node data, thereby achieving efficient addressing from the root node to any child node.

[0151] Taking the application scenario of account tree data storage as an example, the embodiment of the present application can create an intermediate node data file with a storage space of 264 bytes and related bitmap files and bitmap indexes, and can create a leaf node data file with a storage space of 164 bytes and related bitmap files and bitmap indexes. In order to support file expansion, the file identifier of the data file can be determined in a 4-byte increment, such as 1.data, 2.data... The bitmap file and the bitmap index can use the file identifier of the associated data file as a prefix. For example, the bitmap file corresponding to the data file 1.data can be named 1.bitmap, and the bitmap indexes of each level can be named 1_1.bitmap-index, 1_2.bitmap-index... and so on. Whether it is an intermediate node or a leaf node, a fixed-length storage space can be allocated from the corresponding data file to write node data, which can avoid storage fragmentation and support in-situ modification and update of node data.

[0152] In many cases, the stored tree structure data is not constant. For example, account tree data often needs to perform operations such as adding new nodes, deleting existing nodes, or updating node data. The following describes the specific operation process of updating tree structure data.

[0153] In one implementation of the embodiment of the present application, the method further includes:

[0154] (1) When a new node is added to the tree structure data, determine the type of the new node;

[0155] (2) If the type of the new node is a leaf node, the data of the new node is written into the first data file, and the data of the parent node of the new node stored in the second data file is updated according to the index information of the new node and the type of the new node;

[0156] (3) If the type of the new node is an intermediate node, the data of the new node is written into the second data file, and the data of the parent node of the new node stored in the second data file is updated according to the index information of the new node and the type of the new node.

[0157] For the operation of adding a new node, all newly added nodes can be collected from the memory, and the processing method can be determined according to the type of the new node. If the type of the new node is a leaf node, the data of the new node is written into the first data file, where a free storage space is obtained from the first data file in the manner described above to store the data of the new node, the corresponding index information is recorded, and the corresponding storage space is marked as occupied in the manner described above; then, according to the index information of the new node and the type of the new node, the data of the parent node of the new node stored in the second data file is updated. For example, assuming that the new node corresponds to slot "2", the data of the parent node of the new node is obtained from the second data file, and the slot information corresponding to slot "2" in the slot list of the 16 child nodes is updated, for example, the "existence flag" in the slot information is updated to "yes", indicating that the child node exists, and the "node type" in the slot information is set to 1, indicating a leaf node, and the index information of the new node is written into the slot information corresponding to slot "2". If the type of the new node is an intermediate node, the data of the new node is written into the second data file. Here, a free storage space is obtained from the second data file in the manner described above to store the data of the new node, and the corresponding index information is recorded; then, according to the index information of the new node and the type of the new node, the data of the parent node of the new node stored in the second data file is updated. For example, assuming that the new node corresponds to slot "2", the data of the parent node of the new node is obtained from the second data file, and the slot information corresponding to slot "2" in the slot list of 16 child nodes is updated. For example, the "whether there is an identifier" in the slot information is updated to "yes", indicating that the child node exists, and the "node type" in the slot information is set to 0, indicating an intermediate node, and the index information of the new node is written into the slot information corresponding to slot "2".

[0158] In one implementation of the embodiment of the present application, the method further includes:

[0159] (1) When the tree structure data deletes the target node, determine the type of the target node;

[0160] (2) If the type of the target node is a leaf node, the data of the target node stored in the first data file is deleted, and the data of the parent node of the target node stored in the second data file is updated;

[0161] (3) If the type of the target node is an intermediate node, the data of the target node stored in the second data file is deleted, and the data of the parent node of the target node stored in the second data file is updated.

[0162] For the operation of deleting the original node, assuming that a target node is deleted, the type of the target node is first determined; if the type of the target node is a leaf node, the data of the target node stored in the first data file is deleted, and the corresponding storage space can be recovered in the manner described above after the data is deleted, and the data of the parent node of the target node stored in the second data file is updated. If the type of the target node is an intermediate node, the data of the target node stored in the second data file is deleted, and the corresponding storage space can be recovered in the manner described above after the data is deleted, and the data of the parent node of the target node stored in the second data file is updated. When updating the data of the parent node of the target node stored in the second data file, assuming that the target node corresponds to slot "2", the data of the parent node of the target node is obtained from the second data file, and the slot information corresponding to slot "2" in the slot list of the 16 child nodes is updated, for example, the "existence flag" in the slot information is updated to "no", indicating that the child node does not exist, and the node type and index information of the target node stored in the slot information do not need to be changed, and can be retained or cleared.

[0163] The operation of updating node data only involves the modification of node data, and does not involve adding or deleting nodes. At this time, you only need to find the storage space of the data file where the data of the node to be updated is located, and overwrite the old data in the storage space with the new data of the node to be updated. There is no need to reallocate free storage space or recycle storage space.

[0164] As an example, Figure 4 Schematic diagram of the operation principle of updating tree structure data provided by an embodiment of the present application. Figure 4 In the data file, bitmap file and bitmap index of the leaf node are 2.data, 2.bitmap, 2_1.bitmap-index, 2_2.bitmap-index, 2_3.bitmap-index and 2_4.bitmap-index, respectively, and the data file, bitmap file and bitmap index of the intermediate node are 1.data, 1.bitmap, 1_1.bitmap-index, 1_2.bitmap-index, 1_3.bitmap-index and 1_4.bitmap-index respectively. When the tree structure data is updated from version v1 to version v2, operations such as adding nodes, deleting nodes and updating node data are involved. At this time, the corresponding node data writing, node data deletion, node data update, free storage space allocation, marking occupied storage space and reclaiming storage space are performed on each data file, bitmap file and bitmap index in the manner described above.

[0165] The data file has a large amount of data and can generally only be set up for operation on the disk, while the bitmap file and bitmap index have a small amount of data. In order to improve the operation efficiency, the bitmap file and bitmap index can be loaded into the memory for operation, which can reduce the frequent access to the disk every time the data changes and will not cause excessive memory consumption. In addition, you can also scan and obtain the free storage locations in the data file in advance, and record the information of the free storage locations. In this way, when you need to write node data later, you don’t need to frequently scan the bitmap index and bitmap file, you only need to read the information of the previously saved free storage locations.

[0166] In one implementation of the embodiment of the present application, the method further includes:

[0167] (1) When the node data of the tree structure data is updated, the first bitmap file, the first bitmap indexes of multiple levels, the second bitmap file and the second bitmap indexes of multiple levels stored in the memory are updated, and the corresponding bitmap update data is recorded in the designated file;

[0168] (2) When the amount of bitmap update data recorded in the designated file reaches a set threshold, the first bitmap file, the first bitmap indexes of multiple levels, the second bitmap file, and the second bitmap indexes of multiple levels stored in the memory are updated to the disk.

[0169] Normally, data files, bitmap files, and bitmap indexes are all stored in disks for maintenance and update. However, when operations such as adding new nodes, deleting nodes, and updating node data are involved, data files, bitmap files, and bitmap indexes need to be updated (for example, some storage space needs to be marked as occupied or recycled). The processing efficiency of frequent data update operations in disks is low. To solve this problem, each bitmap file and each bitmap index can be loaded into memory for operation. For example, when the node data of the tree structure data is updated, the first bitmap file, the first bitmap index of multiple levels, the second bitmap file, and the second bitmap index of multiple levels stored in the memory are first updated, and the corresponding bitmap update data is recorded to a specified file, such as recording the bit changes in the bitmap file and the bitmap index. In actual operation, the specified file can be a wal log file (i.e., a write-ahead log). Using the wal log file can ensure data consistency and avoid losing data that has not been updated on the disk when the system crashes. When the number of bitmap update data recorded in the specified file reaches the set threshold, the first bitmap file, the first bitmap index of multiple levels, the second bitmap file and the second bitmap index of multiple levels stored in the memory are updated to the disk, and the persistence operation of the bitmap data update is completed. In addition, for changes in node data, the storage space identifier, data file identifier, node type and other data that need to be changed in the node can also be written to the wal log file first, and according to the amount of accumulated change data, it is decided when to batch update the change data stored in the memory to the disk, that is, to complete the persistence operation of the node data update.

[0170] The technical solution of the embodiment of the present application, after acquiring the tree structure data to be stored, writes the data of each leaf node into the first data file, and records the index information of the leaf node into the data of the corresponding parent node; writes the data of each intermediate node into the second data file, and records the index information of the intermediate node into the data of the corresponding parent node; finally, writes the data of the root node into the second data file, and stores the index information of the root node. The above process stores the data of the intermediate nodes and the data of the leaf nodes respectively through different data files. When it is necessary to query the node data, the storage position of the root node data in the data file can be located according to the index information of the root node, and the storage position of the child node data in the data file can be located according to the index information of the child node contained in the data of the parent node, thereby realizing efficient addressing from the root node to any child node, and improving the data query efficiency of the tree structure data.

[0171] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0172] A tree structure data storage method is mainly described above, and a tree structure data storage device will be described below.

[0173] See also Figure 5 , shows a tree structure data storage device provided by an embodiment of the present application, including:

[0174] The data acquisition module 501 is used to acquire the tree structure data to be stored, where the tree structure data includes a number of intermediate nodes and a number of leaf nodes;

[0175] The leaf node writing module 502 is used to write the data of each leaf node into the first data file, and record the index information of the leaf node into the data of the parent node of the leaf node, where the index information of the leaf node is used to indicate the storage location of the data of the leaf node;

[0176] The intermediate node writing module 503 is used for, for each intermediate node except the root node, after the data of the intermediate node has recorded the index information of all child nodes of the intermediate node, writing the data of the intermediate node into the second data file, and recording the index information of the intermediate node into the data of the parent node of the intermediate node, wherein the index information of the intermediate node is used to indicate the storage location of the data of the intermediate node;

[0177] The root node writing module 504 is used to write the data of the root node into the second data file and store the index information of the root node, where the index information of the root node is used to indicate the storage location of the data of the root node.

[0178] In an implementation of the embodiment of the present application, the first data file has multiple first storage spaces of the same size, and the data size of each leaf node does not exceed the size of the first storage space; the second data file has multiple second storage spaces of the same size, and the data size of each intermediate node does not exceed the size of the second storage space; the leaf node writing module includes:

[0179] A first bitmap file acquisition unit, used to acquire a first bitmap file corresponding to the first data file, each bit of the first bitmap file is used to indicate the occupancy of each first storage space of the first data file;

[0180] A first storage space acquisition unit, used for acquiring a free first storage space from the first data file according to the first bitmap file;

[0181] A first data writing unit is used to write the data of the leaf node into the free first storage space, and record the file identifier of the first data file and the space identifier of the free first storage space into the data of the parent node of the leaf node;

[0182] The intermediate node writing module includes:

[0183] A second bitmap file acquisition unit, used to acquire a second bitmap file corresponding to the second data file, each bit of the second bitmap file is used to represent the occupancy of each second storage space of the second data file;

[0184] A second storage space acquisition unit, used for acquiring an idle second storage space from the second data file according to the second bitmap file;

[0185] The second data writing unit is used to write the data of the intermediate node into the free second storage space, and record the file identifier of the second data file and the space identifier of the free second storage space into the data of the parent node of the intermediate node.

[0186] In one implementation of the embodiment of the present application, the first bitmap file has multiple bitmap blocks, each bitmap block has m bits, m>1; the first bitmap file has multiple levels of first bitmap indexes, each bitmap block of the first bitmap index of the lowest level is used to indicate the occupancy of the m bitmap blocks of the first bitmap file, and each bitmap block of the first bitmap index of the upper level is used to indicate the occupancy of the m bitmap blocks of the first bitmap index of the lower level; the second bitmap file has multiple bitmap blocks, each bitmap block has n bits, n>1; the second bitmap file has multiple levels of second bitmap indexes, each bitmap block of the second bitmap index of the lowest level is used to indicate the occupancy of the n bitmap blocks of the second bitmap file, and each bitmap block of the second bitmap index of the upper level is used to indicate the occupancy of the n bitmap blocks of the second bitmap index of the lower level;

[0187] The first storage space acquisition unit includes:

[0188] A first bit scanning subunit, configured to scan the bits of the first value layer by layer starting from the first bitmap index of the highest level until a first bit of a first value in the first bitmap file is obtained;

[0189] A first storage space acquisition subunit is used to acquire a first storage space corresponding to the first bit from the first data file as the free first storage space;

[0190] The second storage space acquisition unit includes:

[0191] A second bit scanning subunit is used to scan the bits of the first value layer by layer starting from the second bitmap index of the highest level until a second bit of the first value in the second bitmap file is obtained;

[0192] The second storage space acquisition subunit is used to acquire the second storage space corresponding to the second bit from the second data file as the free second storage space.

[0193] In one implementation of the embodiment of the present application, the tree structure data storage device further includes:

[0194] A first bit updating module, configured to update a third bit corresponding to any first storage space in the first data file to a second value if data is written into any first storage space of the first data file;

[0195] a second bit updating module, configured to update the fourth bit corresponding to the first bit block in the first bit map index of the lowest level to the second value if all bits contained in the first bit map block where the third bit is located in the first bit map file are the second value, until the bit update of the first bit map index of the highest level is completed;

[0196] A third bit updating module is configured to update a fifth bit corresponding to any second storage space in the second bitmap file to a second value if data is written into any second storage space of the second data file;

[0197] The fourth bit update module is used to update the sixth bit corresponding to the second bitmap block in the second bitmap index of the lowest level to the second value if all bits contained in the second bitmap block where the fifth bit is located in the second bitmap file are the second value, until the bit update of the second bitmap index of the highest level is completed.

[0198] In one implementation of the embodiment of the present application, the tree structure data storage device further includes:

[0199] a fifth bit updating module, configured to update the seventh bit corresponding to any first storage space in the first data file to a first value if data is deleted from any first storage space of the first data file;

[0200] A first bitmap block determination module, used to determine a third bitmap block where the seventh bit in the first bitmap file is located;

[0201] a sixth bit updating module, configured to update the eighth bit to the first value if the eighth bit corresponding to the third bitmap block in the first bitmap index of the lowest level is the second value, until the bit update of the first bitmap index of the highest level is completed;

[0202] a seventh bit updating module, configured to update a ninth bit corresponding to any second storage space in the second bitmap file to a first value if data is deleted from any second storage space of the second data file;

[0203] A second bitmap block determination module, used to determine a fourth bitmap block where the ninth bit in the second bitmap file is located;

[0204] The eighth bit updating module is used to update the tenth bit to the first value if the tenth bit corresponding to the fourth bitmap block in the second bitmap index of the lowest level is the second value, until the bit update of the second bitmap index of the highest level is completed.

[0205] In one implementation of the embodiment of the present application, the tree structure data storage device further includes:

[0206] A memory update module, used for updating the first bitmap file, the first bitmap indexes of multiple levels, the second bitmap file and the second bitmap indexes of multiple levels stored in the memory when the node data of the tree structure data is updated, and recording the corresponding bitmap update data to the designated file;

[0207] The disk update module is used to update the first bitmap file, multiple levels of first bitmap indexes, second bitmap files and multiple levels of second bitmap indexes stored in the memory to the disk when the amount of bitmap update data recorded in the designated file reaches a set threshold.

[0208] In one implementation of the embodiment of the present application, the tree structure data storage device further includes:

[0209] A first node type determination module, used to determine the type of a new node when a new node is added to the tree structure data;

[0210] A first parent node data updating module, used for writing the data of the new node into the first data file if the type of the new node is a leaf node, and updating the data of the parent node of the new node stored in the second data file according to the index information of the new node and the type of the new node;

[0211] The second parent node data updating module is used to write the data of the new node into the second data file if the type of the new node is an intermediate node, and update the parent node data of the new node stored in the second data file according to the index information of the new node and the type of the new node.

[0212] In one implementation of the embodiment of the present application, the tree structure data storage device further includes:

[0213] A second node type determination module, used to determine the type of the target node when the tree structure data deletes the target node;

[0214] A third parent node data updating module is used to delete the data of the target node stored in the first data file and update the data of the parent node of the target node stored in the second data file if the type of the target node is a leaf node;

[0215] The fourth parent node data updating module is used to delete the data of the target node stored in the second data file if the type of the target node is an intermediate node, and to update the data of the parent node of the target node stored in the second data file.

[0216] An embodiment of the present application further provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the tree structure data storage method described in any of the above embodiments is implemented.

[0217] An embodiment of the present application also provides a computer program product. When the computer program product is run on an electronic device, the electronic device executes the tree structure data storage method described in any of the above embodiments.

[0218] Figure 6 is a schematic diagram of an electronic device provided by an embodiment of the present application. Figure 6 As shown, the electronic device 6 of this embodiment includes: a processor 60, a memory 61, and a computer program 62 stored in the memory 61 and executable on the processor 60. When the processor 60 executes the computer program 62, the steps in the above-mentioned tree structure data storage method embodiments are implemented, such as Figure 1 Alternatively, when the processor 60 executes the computer program 62, the functions of each module / unit in the above-mentioned device embodiments are realized, for example, Figure 5 Functions of modules 501 - 504 of the illustrated apparatus.

[0219] The computer program 62 may be divided into one or more modules / units, which are stored in the memory 61 and executed by the processor 60 to complete the present application. The one or more modules / units may be a series of computer program instruction segments capable of completing specific functions, which are used to describe the execution process of the computer program 62 in the electronic device 6.

[0220] The processor 60 may be a central processing unit (CPU), other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor, etc.

[0221] The memory 61 may be an internal storage unit of the electronic device 6, such as a hard disk or memory of the electronic device 6. The memory 61 may also be an external storage device of the electronic device 6, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the electronic device 6. Further, the memory 61 may also include both an internal storage unit and an external storage device of the electronic device 6. The memory 61 is used to store the computer program and other programs and data required by the electronic device. The memory 61 may also be used to temporarily store data that has been output or is to be output.

[0222] The technicians in the relevant field can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example for illustration. In practical applications, the above-mentioned function allocation can be completed by different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiment can be integrated in a processing unit, or each unit can exist physically separately, or two or more units can be integrated in one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the scope of protection of this application. The specific working process of the units and modules in the above-mentioned system can refer to the corresponding process in the aforementioned method embodiment, which will not be repeated here.

[0223] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the systems, devices and units described above can refer to the corresponding processes in the aforementioned method embodiments and will not be repeated here.

[0224] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0225] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0226] In the embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the system embodiments described above are only schematic. For example, the division of the modules or units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0227] The units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the embodiments of the present application.

[0228] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.

[0229] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), electric carrier signal, telecommunication signal and software distribution medium. It should be noted that the content contained in the computer-readable medium can be appropriately increased or decreased according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electric carrier signals and telecommunication signals.

[0230] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.

Claims

1. A tree structure data storage method, characterized in that: include: Acquire tree structure data to be stored, wherein the tree structure data includes a plurality of intermediate nodes and a plurality of leaf nodes; For each leaf node, write the data of the leaf node into the first data file, and record the index information of the leaf node into the data of the parent node of the leaf node, where the index information of the leaf node is used to indicate the storage location of the data of the leaf node; For each of the intermediate nodes except the root node, after the data of the intermediate node has recorded the index information of all the child nodes of the intermediate node, the data of the intermediate node is written into the second data file, and the index information of the intermediate node is recorded into the data of the parent node of the intermediate node, and the index information of the intermediate node is used to indicate the storage location of the data of the intermediate node; The data of the root node is written into the second data file, and index information of the root node is stored, where the index information of the root node is used to indicate the storage location of the data of the root node.

2. The method according to claim 1, characterized in that The first data file has a plurality of first storage spaces of the same size, and the data size of each leaf node does not exceed the size of the first storage space; the second data file has a plurality of second storage spaces of the same size, and the data size of each intermediate node does not exceed the size of the second storage space; The step of writing the data of the leaf node into the first data file and recording the index information of the leaf node into the data of the parent node of the leaf node includes: Obtaining a first bitmap file corresponding to the first data file, wherein each bit of the first bitmap file is used to indicate the occupancy of each first storage space of the first data file; According to the first bitmap file, obtaining a free first storage space from the first data file; Writing the data of the leaf node into the free first storage space, and recording the file identifier of the first data file and the space identifier of the free first storage space into the data of the parent node of the leaf node; The step of writing the data of the intermediate node into the second data file and recording the index information of the intermediate node into the data of the parent node of the intermediate node includes: Acquire a second bitmap file corresponding to the second data file, where each bit of the second bitmap file is used to indicate the occupancy of each second storage space of the second data file; According to the second bitmap file, obtaining a free second storage space from the second data file; The data of the intermediate node is written into the free second storage space, and the file identifier of the second data file and the space identifier of the free second storage space are recorded in the data of the parent node of the intermediate node.

3. The method according to claim 2, characterized in that The first bitmap file has a plurality of bitmap blocks, each of which has m bits, where m>1; the first bitmap file has a plurality of levels of first bitmap indexes, each bitmap block of the first bitmap index of the lowest level is used to indicate the occupancy of m bitmap blocks of the first bitmap file, and each bitmap block of the first bitmap index of the upper level is used to indicate the occupancy of m bitmap blocks of the first bitmap index of the lower level; the second bitmap file has a plurality of bitmap blocks, each of which has n bits, where n>1; the second bitmap file has a plurality of levels of second bitmap indexes, each bitmap block of the second bitmap index of the lowest level is used to indicate the occupancy of n bitmap blocks of the second bitmap file, and each bitmap block of the second bitmap index of the upper level is used to indicate the occupancy of n bitmap blocks of the second bitmap index of the lower level; The step of acquiring a free first storage space from the first data file according to the first bitmap file includes: Scanning the bits of the first value layer by layer starting from the first bitmap index of the highest level until a first bit of a first value in the first bitmap file is obtained; Acquire a first storage space corresponding to the first bit from the first data file as the free first storage space; The step of acquiring a free second storage space from the second data file according to the second bitmap file includes: Scanning the bits of the first value layer by layer starting from the second bitmap index of the highest level until a second bit of the first value in the second bitmap file is obtained; A second storage space corresponding to the second bit is obtained from the second data file as the free second storage space.

4. The method according to claim 3, characterized in that Also includes: If data is written into any first storage space of the first data file, updating the third bit corresponding to the any first storage space in the first bitmap file to a second value; If all bits contained in the first bitmap block where the third bit is located in the first bitmap file are the second value, then the fourth bit corresponding to the first bitmap block in the first bitmap index of the lowest level is updated to the second value until the bit update of the first bitmap index of the highest level is completed; If data is written into any second storage space of the second data file, updating the fifth bit corresponding to the any second storage space in the second bitmap file to a second value; If all bits contained in the second bitmap block where the fifth bit is located in the second bitmap file are second values, the sixth bit corresponding to the second bitmap block in the second bitmap index of the lowest level is updated to the second value until the bit update of the second bitmap index of the highest level is completed.

5. The method according to claim 3, characterized in that Also includes: If data is deleted from any first storage space of the first data file, updating the seventh bit corresponding to the any first storage space in the first bitmap file to a first value; Determine a third bitmap block in which the seventh bit is located in the first bitmap file; If the eighth bit corresponding to the third bitmap block in the first bitmap index of the lowest level is the second value, updating the eighth bit to the first value until the bit update of the first bitmap index of the highest level is completed; If data is deleted from any second storage space of the second data file, updating the ninth bit corresponding to the any second storage space in the second bitmap file to the first value; Determine a fourth bitmap block in which the ninth bit is located in the second bitmap file; If the tenth bit corresponding to the fourth bitmap block in the second bitmap index of the lowest level is the second value, the tenth bit is updated to the first value until the bit update of the second bitmap index of the highest level is completed.

6. The method according to claim 3, characterized in that Also includes: When the node data of the tree structure data is updated, the first bitmap file, the first bitmap index of the multiple levels, the second bitmap file and the second bitmap index of the multiple levels stored in the memory are updated, and the corresponding bitmap update data is recorded in the designated file; When the amount of bitmap update data recorded in the designated file reaches a set threshold, the first bitmap file, the first bitmap indexes of the multiple levels, the second bitmap file and the second bitmap indexes of the multiple levels stored in the memory are updated to the disk.

7. The method according to claim 1, characterized in that Also includes: When a new node is added to the tree structure data, determining the type of the new node; If the type of the new node is a leaf node, the data of the new node is written into the first data file, and the data of the parent node of the new node stored in the second data file is updated according to the index information of the new node and the type of the new node; If the type of the new node is an intermediate node, the data of the new node is written into the second data file, and the data of the parent node of the new node stored in the second data file is updated according to the index information of the new node and the type of the new node.

8. The method according to any one of claims 1 to 7, characterized in that Also includes: When the tree structure data deletes a target node, determining the type of the target node; If the type of the target node is a leaf node, the data of the target node stored in the first data file is deleted, and the data of the parent node of the target node stored in the second data file is updated; If the type of the target node is an intermediate node, the data of the target node stored in the second data file is deleted, and the data of the parent node of the target node stored in the second data file is updated.

9. An electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the tree structure data storage method according to any one of claims 1 to 8 is implemented.

10. A computer program product, characterized in that When the computer program product is run on an electronic device, the electronic device executes the tree structure data storage method according to any one of claims 1 to 8.