Data storage method, terminal equipment and computer readable storage medium
By adopting TSMM-Tree structure and CoW B+ tree in the blockchain network, the problem of increasing data storage demand in the blockchain network is solved, efficient data management and storage efficiency are improved, and system complexity and storage pressure are reduced.
Patent Information
- Application Number
- CN202510059741.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-15
- Publication Date
- 2025-02-25
AI Technical Summary
The demand for data storage in blockchain networks has increased dramatically. In the existing technology, data storage efficiency is low, read and write performance is insufficient, and dynamic scalability is insufficient, resulting in increased system complexity and decreased user experience.
The Time-Structured Multi-version Merkle Tree (TSMM-Tree) structure is adopted, and the design of copy-on-Write (CoW) B+ tree and time structure is combined with the design of copy-on-Write (CoW) B+ tree and time structure. It realizes efficient data management through multi-version data storage mechanism and data separation in time dimensions.
Shorten data read paths by creating new nodes, reduce access latency, improve system processing capabilities, improve data storage efficiency, reduce storage pressure, and support dynamic scaling and data migration.
Smart Images

Figure CN119512469A_ABST
Abstract
Description
Technical Field
[0001] The present application belongs to the technical field of data storage, and in particular, relates to a data storage method, a terminal device, and a computer-readable storage medium. Background Art
[0002] With the widespread application of blockchain technology in finance, Internet of Things, supply chain and other fields, the amount of data in the blockchain network has exploded. Each participating node needs to store all transaction data and status updates starting from the blockchain genesis block, which has led to a sharp increase in the storage requirements of the blockchain network.
[0003] In the related art, a two-layer structure of data authentication + key-value storage is used for data storage, which leads to system complexity and low data storage efficiency. Summary of the invention
[0004] The embodiments of the present application provide a data storage method, a terminal device, and a computer-readable storage medium, which can reduce unnecessary data reading and improve data storage efficiency.
[0005] In a first aspect, an embodiment of the present application provides a data storage method, including: Obtaining first state data of a first unit where data update occurs on the blockchain; the first unit is a block unit where data update occurs in the blockchain; Creating a first storage unit corresponding to the first state data, wherein the first storage unit has the same storage structure as the second storage unit where the second state data is located, and the first storage unit contains the second state data; wherein the second state data is state data before data update occurs in the first unit; The first state data is stored in the first storage unit.
[0006] In an embodiment of the present application, the state data after a certain data update is executed is retrieved from the blockchain. This state data represents the data after the transaction is confirmed and written to the blockchain. In order to save the first state data obtained above, the system needs to create a new storage unit. This area is called the "first storage unit". The first storage unit is designed to have the same performance characteristics as the existing storage unit (called the "second storage unit"). This may include read and write speed, data consistency, concurrent processing capabilities, etc. The second storage unit is used to store the state data before the first state data, that is, before the current transaction occurs. Finally, the first state data obtained is saved to the first storage unit created previously. In this way, the first storage unit contains the latest state data after the data update occurs, which is equivalent to copying the second storage unit and storing the state data of the transaction in the newly created area. In this way, in the process of storing or writing state data, it is not necessary to modify all nodes on the data path, and the need for such comprehensive modification can be avoided. In this way, it is only necessary to add or update the state data in a specific storage unit without touching the entire data path, which can simplify the data writing process and improve the storage efficiency of the state data.
[0007] In a possible implementation manner of the first aspect, creating a first storage unit corresponding to the first state data includes: Acquire a first node and a second node corresponding to the second storage unit; wherein the first node represents first identifier information corresponding to the second storage unit, and the second node represents first data query entry information corresponding to the second state data stored in the second storage unit; A first storage unit corresponding to the first state data is created according to the first node, the second node and the third node corresponding to the second storage unit; wherein the third node represents the node information corresponding to the second storage unit storing the second state data, and the first node, the second node and the third node are connected with a first connection relationship.
[0008] In a possible implementation manner of the first aspect, creating a first storage unit corresponding to the first state data according to the first node, the second node, and a third node corresponding to the second storage unit includes: Copy the node information corresponding to the first node, the second node and the third node respectively to obtain the copied fourth node, the fifth node and the sixth node; The fourth node, the fifth node and the sixth node are connected according to the first connection relationship to obtain the created first storage unit; wherein the fourth node represents the second identifier information corresponding to the first storage unit, the fifth node represents the second data query entry information corresponding to the first storage unit storing the first state data, and the sixth node represents the storage information corresponding to the first storage unit.
[0009] In a possible implementation manner of the first aspect, the method further includes: Connecting the fifth node corresponding to the second query entry information to the seventh node, wherein the seventh node represents the third identifier information corresponding to the state data under the second node corresponding to the first query entry information that has not undergone data update; The fourth node corresponding to the second identifier information is connected to an eighth node, wherein the eighth node represents storage information of a third storage unit corresponding to status data of the first node corresponding to the first identifier information that has not undergone data update.
[0010] In the embodiment of the present application, by creating a new node, the data reading path can be shortened and the access delay can be reduced, which enables users to obtain required information more quickly when querying data, thereby improving the overall user experience.
[0011] In a possible implementation manner of the first aspect, adding the first state data to an end of the second state data in the first storage unit includes: Dividing the state data in the blockchain into multiple time series according to the block heights corresponding to the multiple block units; each time series includes multiple block units; wherein the block height is a fourth identifier corresponding to the block unit, and the block unit includes the first unit; The first state data is stored in the first storage unit according to the time series.
[0012] In the embodiment of the present application, storing data through a time structure can ensure that the data is managed by version within a certain time interval, thereby avoiding the difficulty of splitting due to inconsistency between the byte sequence and the time sequence.
[0013] In a possible implementation manner of the first aspect, storing the first state data in the first storage unit according to the time series includes: Creating a first storage area for a plurality of block units in each time series; Determine the first storage area corresponding to the first state data according to the block height of the first unit corresponding to the first state data and the block height of the block unit in the first storage area; The first state data is stored in a corresponding first storage unit in the first storage area.
[0014] In a possible implementation manner of the first aspect, the method further includes: When the amount of the first state data stored in the first storage area reaches the amount of data included in the multiple block units in the time series, re-create a second storage area for each of the multiple block units in the time series; The first state data is stored in a third storage unit corresponding to the second storage area.
[0015] In an embodiment of the present application, when the orders received in the system reach a storage threshold, the system can dynamically expand according to the storage load and automatically add a new storage area (third storage area) to cope with future data growth needs.
[0016] In a possible implementation manner of the first aspect, the method further includes: When the amount of the first state data stored in the first storage area reaches the amount of data contained in the block units in the time series, the first state data in the first storage area is migrated to a third storage area, wherein the storage performance of the third storage area is lower than that of the first storage area and the second storage area.
[0017] In the embodiment of the present application, when the storage area is fully loaded with storage data, the historical data can be smoothly migrated to a storage device with lower performance, which can improve the storage performance of the system.
[0018] In a second aspect, an embodiment of the present application provides a data storage device, including: A data acquisition module, used to acquire first state data of a first unit where data update occurs on the blockchain; the first unit is a block unit where data update occurs in the blockchain; A data creation module is used to create a first storage unit corresponding to the first state data, wherein the first storage unit has the same storage structure as the second storage unit where the second state data is located, and the first storage unit contains the second state data; wherein the second state data is the state data before the data is updated in the first unit.
[0019] A data storage module is used to store the first state data in the first storage unit.
[0020] In a third aspect, an embodiment of the present application 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 data storage method as described in any one of the first aspects above is implemented.
[0021] In a fourth aspect, an embodiment of the present application provides a computer program product, which, when executed on a terminal device, enables the terminal device to execute the data storage method described in any one of the above-mentioned first aspects.
[0022] It can be understood that the beneficial effects of the second to fourth 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
[0023] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0024] Figure 1 This is a schematic diagram of the data storage structure provided by the embodiment of the present application. Figure 1 ; Figure 2 It is a flowchart of a data storage method provided in an embodiment of the present application; Figure 3 is a schematic diagram of a process for obtaining a first storage unit provided in an embodiment of the present application; Figure 4 This is a schematic diagram of the data storage structure provided by the embodiment of the present application. Figure 2 ; Figure 5 It is a schematic diagram of the data writing process provided by an embodiment of the present application; Figure 6 is a schematic diagram of the structure of a data storage device provided in an embodiment of the present application; Figure 7 It is a structural diagram of a terminal device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0025] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.
[0026] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.
[0027] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.
[0028] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.
[0029] In addition, in the description of the present application specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish the descriptions and cannot be understood as indicating or implying relative importance.
[0030] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the phrases "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. appearing in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways.
[0031] With the widespread application of blockchain technology in finance, the Internet of Things, supply chain and other fields, the amount of data in the blockchain network has exploded. Each participating node needs to store all transaction data and status updates starting from the blockchain genesis block, which has led to a sharp increase in the storage requirements of the blockchain network. Due to the decentralized nature of the blockchain, each node must maintain a complete ledger, causing the entire system to face unprecedented storage pressure and performance bottlenecks. The specific core issues are as follows: ①Data storage pressure In blockchain systems, as the amount of data continues to grow, storage pressure gradually increases. This problem not only leads to an increase in storage costs but also seriously affects the read and write performance of the system. The traditional blockchain structure cannot effectively cope with the unlimited growth of data, resulting in a decline in user experience and a longer system response time, which in turn affects the overall transaction efficiency and network availability.
[0032] ② Insufficient reading and writing performance Most of the current mainstream storage solutions use a two-layer structure, which is specifically manifested in using an authentication data structure as a data index and using a key-value (KV) storage engine for data management. However, the main drawback of this design is that the data reading path is too long, which significantly increases the access time of the data. In addition, during the writing process, all nodes on the path must be modified, which makes the write amplification phenomenon particularly serious, thereby increasing the complexity of the system and resource consumption.
[0033] ③Insufficient dynamic scalability Most existing storage solutions use static expansion strategies and cannot flexibly cope with the rapid growth of data scale. As the amount of system data continues to increase, the capacity of storage nodes quickly reaches the upper limit, and existing storage solutions lack dynamic response capabilities in expansion. This static characteristic greatly limits the scalability of the system in high concurrency and high data growth scenarios.
[0034] In order to solve the above-mentioned related problems, the embodiment of the present application provides a single-layer blockchain state data storage solution. In this application, a new tree structure (Time-Structured Multi-version Merkle Tree, TSMM-Tree) for data division according to the timeline order is proposed. The present application combines the design of Copy-on-Write (CoW) B+ tree and time structure (Time-structure), and realizes efficient data management through multi-version data storage mechanism and data separation in time dimension. During the data writing process, the system will not directly overwrite the original data, but will retain the historical version by creating a new node. After a certain number of blocks or time intervals, TSMM-Tree will generate a new Young tree (first storage area) for storing current data. When the Young tree is full, it will be converted to the Old tree to retain the historical state. This structure can dynamically manage and rebuild the state tree according to time or data volume, ensure data consistency, and support the migration of old data to free up storage space and reduce storage pressure.
[0035] Before introducing the data storage method proposed in this application, the B+ tree is first explained: B+ tree is a self-balancing multi-way search tree, which is specially designed for indexing in databases and file systems. The structure of B+ tree includes root node, child node and leaf node.
[0036] The root node of a B+ tree can be a leaf node or an internal node with at least two child nodes. The root node is the top layer of the entire tree, and its relationship with other nodes is a direct parent-child relationship; child nodes refer to nodes on the path from the root node to the leaf nodes. All nodes except leaf nodes are child nodes. Each child node is connected to its parent node through a pointer, and the pointer points to the smallest key in the child node; leaf nodes are nodes that store data in the B+ tree. They are connected through links, and leaf nodes are linked to each other through links to form an ordered linked list, and are connected to parent nodes through pointers.
[0037] The B+ tree optimizes index lookup, insertion, and deletion operations through its unique structure. The relationship between the root node, child nodes, and leaf nodes ensures that the height of the tree is low, thereby improving the efficiency of operations. The position of child nodes is determined by the key value range of the internal nodes, and the ordered linked list of leaf nodes. The B+ tree can quickly locate data and support range queries. The internal nodes in the B+ tree contain multiple keys. These keys are used to index data and are arranged in ascending order. Each key corresponds to a pointer to a child node. These pointers are used to navigate the tree so that the search operation can quickly locate the target data. The pointer in the internal node is actually a reference to the child node, not the data itself. This means that the internal node does not store data, but rather stores references to data storage units.
[0038] See also Figure 1 , is a schematic diagram of a data storage structure provided in an embodiment of the present application Figure 1 ,like Figure 1 As shown, the node root-1 is equivalent to the root node, nodes 1 and 2 are equivalent to child nodes, and nodes 3, 4, 5 and 6 are equivalent to leaf nodes. The leaf nodes are used to store actual data. Among them, nodes 1 and 2 are equivalent to keys, which are used to index data, and the pointers are equivalent to the location information of the leaf nodes, which are used to quickly locate the target data.
[0039] See also Figure 2 , is a flow chart of a data storage method provided in an embodiment of the present application. As an example but not a limitation, the method may include the following steps: S101, obtaining first state data of a first unit where data update occurs on the blockchain; the first unit is a block unit where data update occurs in the blockchain.
[0040] In the embodiment of the present application, blockchain is a distributed database or public ledger technology that stores and verifies data through multiple nodes (computers) in the network. The blockchain is composed of multiple blocks, each of which contains a block header and a block body. Each block header contains metadata of the block, such as a timestamp, a hash value of the previous block, etc.; the block body contains actual transaction data or other types of data. In the present application, "block unit" refers to a block, and each block can be regarded as an independent unit, which contains all transactions or data updates that occurred within a specific time period. The "first unit" refers to the block unit in which data updates occur in the current blockchain, and the "state data" generally refers to the information stored in the block unit on the blockchain, such as account balances, asset ownership, the status of smart contracts, etc. The "first state data" refers to the state data after the first unit transaction occurs in the blockchain.
[0041] Specifically, when a transaction is completed, the relevant status of the transaction changes, and the relevant status data is extracted from the transaction record, which may include but is not limited to account balance, tokens owned by the address, storage variables of the smart contract, etc.
[0042] S102, creating a first storage unit corresponding to the first state data, wherein the first storage unit has the same storage structure as the second storage unit where the second state data is located, and the first storage unit contains the second state data; wherein the second state data is the state data before data update occurs in the first unit.
[0043] In the embodiment of the present application, the first storage unit is a storage structure for storing first state data, and the storage unit has the same storage structure as the storage unit (second storage unit) corresponding to the state data (second state data) before the data update in the first unit. In other words, the first storage unit is equivalent to a copy of the second storage unit, which is obtained by copying the second storage unit.
[0044] Specifically, this application uses CoW-B+ tree technology for data storage, where CoW-B is a technology that optimizes write operations. When data needs to be updated, the updated data does not directly overwrite the original data during the storage process, but creates a new node (storage unit) to store the updated data. Therefore, when the data in the blockchain is updated, a storage unit corresponding to the updated data needs to be created.
[0045] like Figure 1 In the data structure shown, if the current status data stored in the leaf node 6 is the second status data, its corresponding storage unit is the second storage unit. If it is detected that the status data in the leaf node 6 is updated, in order to save the updated data, that is, the first status data, it is necessary to create a new storage unit (first storage unit) to store the updated status data (first status data).
[0046] In one embodiment, see Figure 3 , is a schematic diagram of a process of obtaining a first storage unit provided in an embodiment of the present application, wherein step S102 includes: S201, obtain a first node and a second node corresponding to a second storage unit; wherein the first node represents first identifier information corresponding to the second storage unit, and the second node represents first data query entry information corresponding to second state data stored in the second storage unit.
[0047] In the embodiment of the present application, the first node represents the index data corresponding to the second storage unit, i.e., the first identifier information, which is used to locate the location where the updated data occurs; the second node represents the data query entry corresponding to the updated data, which is equivalent to the root node corresponding to the update node. This node is equivalent to the entry point of the tree and is used to determine the direction of the data search path, i.e., to determine which child node should be accessed. Therefore, before creating the first storage unit, it is necessary to first determine the node information corresponding to the second storage unit.
[0048] S202, create a first storage unit corresponding to the first state data based on the first node, the second node and the third node corresponding to the second storage unit; wherein the third node represents the node information corresponding to the second storage unit storing the second state data, and the first node, the second node and the third node are connected with a first connection relationship.
[0049] In the embodiment of the present application, in the process of creating the first storage unit, it is necessary to obtain the key-value connection relationship of the second storage unit, such as Figure 1 When copying the second storage unit (third node) corresponding to leaf node 6, all nodes in the connection path corresponding to leaf node 6 need to be copied, and each node represents different data information. Because when a leaf node changes, the change will propagate upward along the tree hierarchy, updating the parent node in turn until the root node. Such a hierarchical propagation mechanism ensures the integrity of the tree structure and can reflect the latest status changes at all levels.
[0050] In one embodiment, step S202 includes: Copy the node information corresponding to the first node, the second node and the third node respectively to obtain the copied fourth node, the fifth node and the sixth node; The fourth node, the fifth node and the sixth node are connected according to the first connection relationship to obtain the created first storage unit; wherein the fourth node represents the second identifier information corresponding to the first storage unit, the fifth node represents the second data query entry information corresponding to the first storage unit storing the first state data, and the sixth node represents the storage information corresponding to the first storage unit.
[0051] In the embodiment of the present application, when creating the first storage unit, it is necessary to copy all nodes in the path where the node corresponding to the first storage unit is located. For example, the path where the leaf node 6 (the third node) is located includes the first node (node 2) and the second node (root-1). When copying, it is necessary to copy the node information of all nodes in the path. After copying, the following is obtained: Figure 4 middle (the fourth node), root-2 (the fifth node), and (the sixth node). Among them, the node Indicates the copied node identifier information, i.e., the second identifier information. The root-2 node indicates the root node, i.e., the data query entry. The corresponding position indicates a newly created storage unit, namely, a first storage unit, which is used to store the updated state data (first state data) at the node 6 .
[0052] The node root-2 obtained after copying, and Connect according to the first connection relationship, that is, Figure 1 The first connection relationship shown in the figure is root-1→2→6, then the copied root-2, and The connection relationship is still root-2→ → .
[0053] In the above method, by recreating a new storage unit to save the state data of the data update, the data reading path can be shortened, the access delay can be reduced, and the processing capability of the system can be improved.
[0054] In one embodiment, the method further comprises: The fifth node corresponding to the second query entry information is connected to the seventh node, wherein the seventh node represents the third identifier information corresponding to the status data of the second node corresponding to the first query entry information and no data update has occurred; the fourth node corresponding to the second identifier information is connected to the eighth node, wherein the eighth node represents the storage information of the third storage unit corresponding to the status data of the first node corresponding to the first identifier information and no data update has occurred.
[0055] In the embodiment of the present application, after creating a new node corresponding to the updated node, it is necessary to connect the newly created node to the node where no data update has occurred, such as Figure 4 The following is a schematic diagram of a data storage structure provided by an embodiment of the present application. Figure 2 , the nodes that have not undergone data update under the root-1 node include node 1, leaf node 3, leaf node 4 and leaf node 5, wherein node 1, i.e. the seventh node, represents the identifier information corresponding to leaf node 3 and leaf node 4 that have not undergone data update; leaf node 5 represents the storage information of the storage unit corresponding to the state data that has not undergone data update, i.e. the eighth node. The recreated nodes are connected according to the connection relationship (first connection relationship) created by the nodes.
[0056] Specifically, Figure 4As shown, in the first connection relationship, the root-1 node (the second node) is connected to node 1 (the seventh node) and node 2 (the first node), and the copied root-2 node (the fifth node) is also connected to child node 1 (the seventh node). Similarly, the copied child node (The fourth node) is connected to the leaf node 5 (the eighth node) where no data update has occurred.
[0057] S103, storing the first state data in the first storage unit.
[0058] In the embodiment of the present application, since the newly created storage unit (first storage unit) is a copy of the existing storage unit (second storage unit), the newly created first storage unit contains the status data before the data update occurs in the second storage unit. Therefore, when storing the first status data in the first storage unit, the first status data needs to be stored at the end of the first status data in the first storage unit.
[0059] In one embodiment, see Figure 5 , is a schematic diagram of the data storage process provided by the embodiment of the present application, such as Figure 5 As shown, including: S301, dividing the state data in the blockchain into multiple time series according to the block heights corresponding to the multiple block units; wherein each time series contains multiple block units, wherein the block height is a fourth identifier corresponding to the block unit, and the block unit includes the first unit.
[0060] In the embodiment of the present application, in order to manage state data more effectively, the present application writes (stores) data based on a time structure. In this structure, data is divided by time, which ensures that data is managed by version within a certain time interval, avoiding the difficulty of splitting due to inconsistency between byte order and time order.
[0061] Specifically, the state data can be divided into several time periods according to the block height of the block unit. The block height is the sequential number of the block in the blockchain (the fourth identifier). Each new block will contain the hash value of the previous block in its header to form a chain. The time period is defined according to the frequency of block generation (for example, one block is generated every 10 minutes). The time period can be a continuous sequence of blocks, for example, from block height 1 to block height 100 is the first time period, and from block height 101 to block height 200 is the second time period, etc.
[0062] S302, storing first state data in a first storage unit according to a time series.
[0063] In the embodiment of the present application, the time series to which the first state data belongs is obtained, and the first state data is stored in a corresponding storage unit, namely, a first storage unit, according to the corresponding time series.
[0064] In one embodiment, step S302 includes: A first storage area is created for a plurality of block units in each time series; a first storage area corresponding to the first storage unit is determined according to the block height of the first unit corresponding to the first state data and the block height of the block unit; and the first state data is stored in the first storage unit corresponding to the first storage area.
[0065] In an embodiment of the present application, when the Cow-B structure is used for data storage, the data structure is equivalent to a state tree. There are two types of state trees for different time periods. The one responsible for processing the current data write is called the Young tree (the first storage area). When the Young tree is filled with N blocks (the number of data in the preset block unit contained in the time series), it will be converted into an Old tree. After that, it will no longer accept data writing but still provide data query function.
[0066] Specifically, multiple block units of different time series correspond to a Young tree. When using the Young tree for data writing, it is necessary to determine the block unit corresponding to the first state data, that is, the block height of the first unit, and determine its corresponding time series according to the block height of the first unit. For example, in the above example, the block height of the first unit is 101, which corresponds to 101-200, that is, the second time period (time series), then the Young tree corresponding to the second time period is used for data storage, and the first state data is written to the corresponding storage location in the Young tree, that is, the first storage unit.
[0067] In the above method, storing data through a time structure can ensure that data is managed by version within a certain time interval, avoiding the difficulty of splitting due to inconsistency between byte order and time order.
[0068] In one embodiment, the method further comprises: When the amount of the first state data stored in the first storage area reaches the amount of data contained in the multiple block units in the time series, a second storage area is recreated for each of the multiple block units in the time series; and the first state data is stored in a third storage unit corresponding to the second storage area.
[0069] In the embodiment of the present application, when there are multiple first state data, the Young tree corresponding to the first storage area writes multiple first state data into the first storage unit of the first storage area, but a Young tree maintains N blocks, that is, N state data. When the Young tree corresponding to the first storage area is filled with N blocks, that is, the number of state data reaches N, the Young tree will become an Old tree and no longer perform write operations. The system will rebuild according to the previous version of the data, and the system will automatically read the state of the previous tree, generate a new state tree, that is, a new storage area (second storage area), continue to receive new data, and store the newly updated first state data in the third storage unit corresponding to the second storage area.
[0070] In one embodiment, the method further comprises: When the amount of first state data stored in the first storage area reaches the amount of data contained in multiple block units in the time series, the first state data in the first storage area is migrated to a third storage area, wherein the storage performance of the third storage area is lower than that of the first storage area and the second storage area.
[0071] In an embodiment of the present application, in order to further optimize the storage space, the present invention designs a dynamic expansion and data migration mechanism. When the storage capacity of a certain state tree reaches a certain threshold, the system will migrate the old data to a low-cost storage device (such as HDD) (third node), and the number of third storage areas can be multiple. Multiple old data can be migrated to multiple storage areas according to the capacity limit of the system to release core storage resources.
[0072] Specifically, the historical data in the current state tree may be transferred according to the time structure Time-0 . . . Time-n, etc., to release the storage resources of the current state tree.
[0073] In this application, a new tree structure (Time-Structured Multi-version Merkle Tree, TSMM-Tree) for data partitioning according to the timeline sequence is proposed. This application combines the design of Copy-on-Write (CoW) B+ tree and time structure (Time-structure), and realizes efficient data management through multi-version data storage mechanism and data separation in time dimension. During the data writing process, the system will not directly overwrite the original data, but retain the historical version by creating a new node, which can well support the storage requirements for multiple versions in the blockchain, and this single-layer model well solves the read-write amplification problem of the two-layer model (authentication data structure + storage engine). After a certain number of blocks or time intervals, TSMM-Tree will generate a new Young tree to store the current data. When the Young tree is full, it will be converted to the Old tree to retain the historical state. This structure can dynamically manage and rebuild the state tree according to time or data volume to ensure data consistency, while supporting the migration of old data to free up storage space and reduce storage pressure.
[0074] Corresponding to the data processing method described in the above embodiment, Figure 6 This is a structural block diagram of a data processing device provided in an embodiment of the present application. For the sake of convenience of explanation, only the parts related to the embodiment of the present application are shown.
[0075] Reference Figure 6 , the device 6 comprises: A data acquisition module 61 is used to acquire first state data of a first unit where data update occurs on the blockchain; the first unit is a block unit where data update occurs in the blockchain; A data creation module 62 is used to create a first storage unit corresponding to the first state data, wherein the first storage unit has the same storage structure as the second storage unit where the second state data is located, and the first storage unit contains the second state data; wherein the second state data is the state data before the data is updated in the first unit.
[0076] The data storage module 63 is used to store the first state data in the first storage unit.
[0077] Optionally, the data creation module 62 is further used for: Acquire a first node and a second node corresponding to the second storage unit; wherein the first node represents first identifier information corresponding to the second storage unit, and the second node represents first data query entry information corresponding to the second state data stored in the second storage unit; A first storage unit corresponding to the first state data is created based on the first node, the second node and the third node corresponding to the second storage unit; wherein the third node represents the node information corresponding to the second storage unit storing the second state data, and the first node, the second node and the third node are connected with a first connection relationship.
[0078] Optionally, the data creation module 62 is further used for: Respectively copy the node information corresponding to the first node, the second node and the third node to obtain the copied fourth node, the fifth node and the sixth node; The fourth node, the fifth node and the sixth node are connected according to the first connection relationship to obtain the created first storage unit; wherein the fourth node represents the second identifier information corresponding to the first storage unit, the fifth node represents the second data query entry information corresponding to the first storage unit storing the first state data, and the sixth node represents the storage information corresponding to the first storage unit.
[0079] Optionally, the data creation module 62 is further used for: Connecting the fifth node corresponding to the second query entry information to the seventh node, wherein the seventh node represents the third identifier information corresponding to the state data under the second node corresponding to the first query entry information that has not undergone data update; The fourth node corresponding to the second identifier information is connected to an eighth node, wherein the eighth node represents storage information of a third storage unit corresponding to status data of the first node corresponding to the first identifier information that has not undergone data update.
[0080] Optionally, the data storage module 63 is further used for: Dividing the state data in the blockchain into multiple time series according to the block heights corresponding to the multiple block units; each time series includes multiple block units; wherein the block height is a fourth identifier corresponding to the block unit, and the block unit includes the first unit; The first state data is stored in the first storage unit according to the time series.
[0081] Optionally, the data storage module 63 is further used for: Creating a first storage area for each of the plurality of block units in the time series; Determine the first storage area corresponding to the first state data according to the block height of the first unit corresponding to the first state data and the block height of the block unit in the first storage area; The first state data is stored in the first storage unit corresponding to the first storage area.
[0082] Optionally, the data storage module 63 is further used for: When the amount of the first state data stored in the first storage area reaches the amount of data included in the plurality of block units in the time series, re-create a second storage area for each of the plurality of block units in the time series; The first state data is stored in a third storage unit corresponding to the second storage area.
[0083] The device 6 further comprises: The data migration module 64 is used to: When the amount of the first state data stored in the first storage area reaches the amount of data contained in multiple block units in the time series, the first state data in the first storage area is migrated to a third storage area, wherein the storage performance of the third storage area is lower than that of the first storage area and the second storage area.
[0084] in addition, Figure 6 The data storage device shown may be a software unit, a hardware unit, or a combination of software and hardware units built into an existing terminal device, or may be integrated into the terminal device as an independent accessory, or may exist as an independent terminal device.
[0085] 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.
[0086] 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.
[0087] Figure 7Schematic diagram of the structure of the terminal device provided in the embodiment of the present application. Figure 7 As shown, the terminal device 7 of this embodiment includes: at least one processor 70 ( Figure 7 Only one is shown in the figure) a processor, a memory 71, and a computer program 72 stored in the memory 71 and executable on the at least one processor 70, wherein the processor 70 implements the steps of any of the above-mentioned data storage method embodiments when executing the computer program 72.
[0088] The terminal device may be a computing device such as a desktop computer, a notebook, a PDA, or a cloud server. The terminal device may include, but is not limited to, a processor and a memory. Those skilled in the art will understand that Figure 7 It is only an example of the terminal device 7 and does not constitute a limitation on the terminal device 7. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components. For example, it may also include input and output devices, network access devices, etc.
[0089] The processor 70 may be a central processing unit (CPU), or 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.
[0090] In some embodiments, the memory 71 may be an internal storage unit of the terminal device 7, such as a hard disk or memory of the terminal device 7. In other embodiments, the memory 71 may also be an external storage device of the terminal device 7, such as a plug-in hard disk, a smart memory card (SmartMediaCard, SMC), a secure digital (SecureDigital, SD) card, a flash card (FlashCard), etc. equipped on the terminal device 7. Further, the memory 71 may also include both an internal storage unit of the terminal device 7 and an external storage device. The memory 71 is used to store an operating system, an application program, a boot loader (BootLoader), data, and other programs, such as the program code of the computer program, etc. The memory 71 may also be used to temporarily store data that has been output or is to be output.
[0091] 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 steps in the above-mentioned method embodiments can be implemented.
[0092] An embodiment of the present application provides a computer program product. When the computer program product runs on a terminal device, the terminal device can implement the steps in the above-mentioned method embodiments when executing the computer program product.
[0093] 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, which can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of the above-mentioned various method embodiments can be implemented. 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 at least include: any entity or device that can carry the computer program code to the device / terminal device, recording medium, 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. For example, a USB flash drive, a mobile hard disk, a magnetic disk or an optical disk. In some jurisdictions, according to legislation and patent practice, computer-readable media cannot be electric carrier signals and telecommunication signals.
[0094] 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.
[0095] 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.
[0096] In the embodiments provided in the present application, it should be understood that the disclosed devices / terminal equipment and methods can be implemented in other ways. For example, the device / terminal equipment 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 through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0097] The units described as separate components may or may not be physically separated, and the components shown 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 solution of this embodiment.
[0098] 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 data storage method, characterized in that: Applied to blockchain, the method includes: Acquire first state data of a first unit where data update occurs on the blockchain; the first unit is a block unit where data update occurs in the blockchain; Creating a first storage unit corresponding to the first state data, wherein the first storage unit has the same storage structure as the second storage unit where the second state data is located, and the first storage unit contains the second state data; wherein the second state data is state data before data update occurs in the first unit; The first state data is stored in the first storage unit.
2. The data storage method according to claim 1, characterized in that: The creating a first storage unit corresponding to the first state data includes: Acquire a first node and a second node corresponding to the second storage unit; wherein the first node represents first identifier information corresponding to the second storage unit, and the second node represents first data query entry information corresponding to the second state data stored in the second storage unit; A first storage unit corresponding to the first state data is created based on the first node, the second node and the third node corresponding to the second storage unit; wherein the third node represents the node information corresponding to the second storage unit storing the second state data, and the first node, the second node and the third node are connected with a first connection relationship.
3. The data storage method according to claim 2, characterized in that: The step of creating a first storage unit corresponding to the first state data according to the first node, the second node, and a third node corresponding to the second storage unit includes: Respectively copy the node information corresponding to the first node, the second node and the third node to obtain the copied fourth node, the fifth node and the sixth node; The fourth node, the fifth node and the sixth node are connected according to the first connection relationship to obtain the created first storage unit; wherein the fourth node represents the second identifier information corresponding to the first storage unit, the fifth node represents the second data query entry information corresponding to the first storage unit storing the first state data, and the sixth node represents the storage information corresponding to the first storage unit.
4. The data storage method according to claim 3, characterized in that: The method further comprises: Connecting the fifth node corresponding to the second query entry information to the seventh node, wherein the seventh node represents the third identifier information corresponding to the state data under the second node corresponding to the first query entry information where no data update has occurred; The fourth node corresponding to the second identifier information is connected to an eighth node, wherein the eighth node represents storage information of a third storage unit corresponding to status data of the first node corresponding to the first identifier information that has not undergone data update.
5. The data storage method according to any one of claims 1 to 4, characterized in that: The storing the first state data into the first storage unit comprises: Dividing the state data in the blockchain into multiple time series according to the block heights corresponding to the multiple block units; each time series includes multiple block units; wherein the block height is a fourth identifier corresponding to the block unit, and the block unit includes the first unit; The first state data is stored in the first storage unit according to the time series.
6. The data storage method according to claim 5, characterized in that: The storing the first state data to the first storage unit according to the time series includes: Creating a first storage area for each of the plurality of block units in the time series; Determine the first storage area corresponding to the first state data according to the block height of the first unit corresponding to the first state data and the block height of the block unit in the first storage area; The first state data is stored in the first storage unit corresponding to the first storage area.
7. The data storage method according to claim 6, characterized in that: The method further comprises: When the amount of the first state data stored in the first storage area reaches the amount of data included in the plurality of block units in the time series, re-create a second storage area for each of the plurality of block units in the time series; The first state data is stored in a third storage unit corresponding to the second storage area.
8. The data storage method according to claim 7, characterized in that: The method further comprises: When the amount of the first state data stored in the first storage area reaches the amount of data contained in multiple block units in the time series, the first state data in the first storage area is migrated to a third storage area, wherein the storage performance of the third storage area is lower than that of the first storage area and the second storage area.
9. A terminal 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 method according to any one of claims 1 to 7 is implemented.
10. A computer-readable storage medium storing a computer program, characterized in that: When the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.
Citation Information
Patent Citations
Hierarchical storage method and device based on block chain and electronic equipment
CN110347684A
Lightweight and extensible block chain system based on edge computing
CN114745102A
Verifiable index construction, updating and verification method for high read-write contention workload
CN116361295A
Block chain-based data processing method and related equipment
CN117056342A