Blockchain data management method and device, electronic device and medium
By obtaining block file attribute parameter values and archiving them in the blockchain system, the problem of high blockchain data storage costs is solved, efficient storage resource management and query performance are achieved, and the enterprise's storage costs are reduced.
Patent Information
- Application Number
- CN202110193724.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-02-20
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2041-02-20
AI Technical Summary
The amount of blockchain data stored by nodes in the blockchain system is huge, resulting in increased storage costs, and high-bandwidth and high-IOPS equipment increase the cost of enterprises on-chain, especially putting pressure on small, medium and micro enterprises.
By obtaining the block file attribute parameter values of the blockchain system, determine the target archive file and transfer it from the current storage area to the archive storage area, optimize blockchain data storage, reduce storage resource requirements, and achieve large-capacity storage and high performance Write disk and query requirements.
It effectively reduces the cost of blockchain data storage, optimizes the use of storage resources, and ensures the normal use and query performance of blockchain data. It is especially suitable for small, medium and micro enterprises.
Smart Images

Figure CN112925479B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of blockchain technology, and in particular to a blockchain data management method and device, electronic equipment and medium. Background Art
[0002] Each participating node in the blockchain system persists the block as the submission unit and maintains all historical transaction data for a long time. Due to the append-only feature of the blockchain, the amount of blockchain data maintained by a single node will become larger and larger. More urgently, each node in the blockchain system stores the full amount of data. For example, a small commercial blockchain system consisting of more than 10 nodes generally requires 10 times the storage capacity of a single node. In some well-known public blockchain systems, the size of blockchain data for a single node has exceeded 300GB, and the data size of a single node in some blockchains has exceeded 5TB. As a result, the storage cost of the blockchain is increasing.
[0003] On the other hand, in actual commercial blockchain systems, the data on the chain is larger and more frequent. In order to speed up the speed of block data landing on the disk, data query speed, and the speed of newly added nodes synchronizing blocks, blockchain management service providers often choose devices with higher bandwidth and IOPS (Input / Output Operations Per Second, the number of read and write operations per second) as storage facilities. In the Hyperledger Fabric blockchain system (Hyperledger Fabric blockchain system is an open source blockchain distributed ledger initiated and created by the Linux Foundation), the block header is larger, the single transaction data packet data is more, and the size of a single transaction is often several KB, which requires higher performance and capacity of storage devices. Obviously, this increases the cost of enterprises on the chain, especially small and medium-sized enterprises in the alliance.
[0004] Therefore, how to provide a blockchain data management solution that can optimize blockchain data storage while ensuring the normal use of blockchain data is a technical problem that needs to be urgently solved by technicians in this field. Summary of the invention
[0005] The present invention provides a blockchain data management method and device, an electronic device and a medium, which can optimize blockchain data storage while ensuring the normal use of blockchain data.
[0006] In a first aspect, the present invention provides a blockchain data management method, comprising:
[0007] Get the attribute parameter values of all current block files in the blockchain system;
[0008] Determine a target archive file in all current block files based on a relationship between the attribute parameter value and a preset threshold;
[0009] The target archive file is transferred from the current storage area to the archive storage area.
[0010] Furthermore, the acquisition of attribute parameter values of all current block files of the blockchain system includes:
[0011] Obtain the blockchain ledger of the blockchain system;
[0012] Determine the number of block files and file size values corresponding to each blockchain ledger.
[0013] Further, determining the target archive file in all current block files based on the relationship between the attribute parameter value and the preset threshold value includes:
[0014] Determine for each blockchain ledger whether the number of block files is greater than the archiving trigger number;
[0015] If yes, the N block files with the longest archiving time in the blockchain account book are used as the first target archive files; wherein N is the number of current block files in the account book minus the minimum number of remaining block files; the minimum number of block files is the number of block files that the blockchain account book must at least retain;
[0016] or
[0017] Determine for each blockchain ledger whether the block file size value is greater than the archiving trigger size value;
[0018] If yes, the block file with the longest archiving time in the blockchain account book is used as the second target archive file; wherein the file size value of the second target archive file is the block size value minus the archiving trigger size value;
[0019] The block file size value is the sum of the size values of all block files in the blockchain account book.
[0020] Further, the transferring of the target archive file from the current storage area to the archive storage area includes:
[0021] Read the block file path and block file serial number of the target archive file, and generate the corresponding archive file absolute path;
[0022] Transfer the target archive file to the archive storage area according to the archive file absolute path, and copy the target archive file under the current block data directory to the archive data directory;
[0023] Delete the target archive file to which the current storage block data directory has been transferred;
[0024] The archive checkpoint is updated, and the data in the archive checkpoint is persistently stored.
[0025] Furthermore, the archive storage area includes a cloud storage server or a proprietary file system server.
[0026] Further, determining the target archive file in all current block files based on the relationship between the attribute parameter value and the preset threshold value includes:
[0027] Count the global block file quantity and global file size value of all blockchain ledgers in the blockchain system;
[0028] Determine a first global target archive file based on the number of global block files and a first threshold;
[0029] determining a second global target archive file based on the global file size value and a second threshold;
[0030] determining the first global target archive file and the second global target archive file as target archive files;
[0031] Among them, after archiving the first global target archive file and the second global target archive file, the number of block files remaining in each blockchain account book is not less than the minimum number of block files
[0032] Among them, after the global target archive file is archived, the number of block files remaining in each blockchain account book is not less than the minimum number of block files.
[0033] Furthermore, it also includes:
[0034] Receive discrete query requests from users on the blockchain;
[0035] In response to the discrete query request, obtaining a file location pointer of the blockchain;
[0036] If the block file number pointed to by the file position pointer is not greater than the block file number in the archive checkpoint, the block file is read from the archive block data directory; if the block file number pointed to by the file position pointer is greater than the block file number in the archive checkpoint, the block file is read from the current block data directory and the block file is searched from the local ledger data directory.
[0037] Furthermore, it also includes:
[0038] Receiving a continuous query request from a user for a blockchain, wherein the continuous query request includes a target block query range interval;
[0039] If it is determined that the file position pointer of the blockchain blocks the target block query range interval, the query from the starting block file of the range to the block position uses the archived block data directory; and the block file data larger than the block position uses the local block data directory.
[0040] In a second aspect, the present invention provides a blockchain data management device, comprising:
[0041] The parameter acquisition module is used to obtain the attribute parameter values of all current block files of the blockchain system;
[0042] A target determination module, used for determining a target archive file in all current block files based on a relationship between the attribute parameter value and a preset threshold value;
[0043] The target transfer module is used to transfer the target archive file from the current storage area to the archive storage area.
[0044] Furthermore, the parameter acquisition module includes:
[0045] A ledger acquisition unit, used to acquire a blockchain ledger of a blockchain system;
[0046] The attribute determination unit is used to determine the number of block files and the file size value corresponding to each blockchain ledger.
[0047] Furthermore, the target determination module includes:
[0048] A quantity determination unit, used to determine whether the number of block files in each blockchain ledger is greater than the archiving trigger number;
[0049] A first target determination unit is configured to, if yes, use the N block files with the longest archiving time in the blockchain account book as the first target archive files; wherein N is the number of current block files in the account book minus the minimum number of remaining block files; the minimum number of block files is the number of block files that the blockchain account book must at least retain;
[0050] or
[0051] A size determination unit, used to determine whether the block file size value of each blockchain ledger is greater than the archiving trigger size value;
[0052] A second target determination unit is configured to, if yes, use the block file with the longest archiving time in the blockchain ledger as the second target archive file; wherein the file size value of the second target archive file is the block size value minus the archive trigger size value;
[0053] The block file size value is the sum of the size values of all block files in the blockchain account book.
[0054] Furthermore, the target transfer module includes:
[0055] A path generation unit, used for reading the block file path and block file serial number of the target archive file, and generating a corresponding archive file absolute path;
[0056] A file transfer unit, used to transfer the target archive file to the archive storage area according to the absolute path of the archive file, and copy the target archive file under the current block data directory to the archive data directory;
[0057] A file deletion unit is used to delete the target archive file to which the data directory of the current storage block has been transferred;
[0058] The directory updating unit is used to update the archive checkpoint and store the data in the archive checkpoint persistently.
[0059] Furthermore, the archive storage area includes a cloud storage server or a proprietary file system server.
[0060] Furthermore, the target determination module includes:
[0061] The global attribute statistics unit is used to count the global block file quantity and global file size value of all blockchain ledgers in the blockchain system;
[0062] a global target file determination unit, configured to determine a first global target archive file based on the number of global block files and a first threshold; determine a second global target archive file based on the global file size value and a second threshold; and determine the first global target archive file and the second global target archive file as target archive files;
[0063] Among them, after archiving the first global target archive file and the second global target archive file, the number of block files remaining in each blockchain account book is not less than the minimum number of block files
[0064] Among them, after the global target archive file is archived, the number of block files remaining in each blockchain account book is not less than the minimum number of block files.
[0065] Furthermore, it also includes:
[0066] Discrete query request module, used to receive discrete query requests from users on the blockchain;
[0067] A first response module, configured to obtain a file location pointer of the blockchain in response to the discrete query request;
[0068] The discrete query module is used to read the block file from the archived block data directory if the block file number pointed to by the file position pointer is not greater than the block file number in the archive checkpoint; if the block file number pointed to by the file position pointer is greater than the block file number in the archive checkpoint, the block file is read from the current block data directory and the block file is searched from the local account data directory.
[0069] Furthermore, it also includes:
[0070] A continuous query request module, used to receive a user's continuous query request for the blockchain, wherein the continuous query request includes a target block query range interval;
[0071] A continuous query module is used for, if it is determined that the file position pointer of the blockchain blocks the query range interval of the target block, the query from the starting block file of the range to the block position uses the archived block data directory; and the block file data larger than the block position uses the local block data directory.
[0072] In a third aspect, the present invention also provides an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the steps of the blockchain data management method as described in any one of the above are implemented.
[0073] In a fourth aspect, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon, which, when executed by a processor, implements the steps of any of the blockchain data management methods described above.
[0074] The present invention provides a blockchain data management method and device, electronic device and medium, which determine target archive files in all current block files based on the attribute parameter values of all current block files and archive them, thereby realizing the large-capacity storage and high-performance disk writing and query requirements required for the persistence of account data in the blockchain system with a smaller storage resource budget. The archived files can be placed in a specific archive storage area, which can optimize the blockchain data storage while ensuring the normal use of the blockchain data. BRIEF DESCRIPTION OF THE DRAWINGS
[0075] In order to more clearly illustrate the technical solutions in the present invention or the prior art, the following briefly introduces the drawings required for use in the embodiments or the description of the prior art. Obviously, the drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.
[0076] Figure 1 One of the flowcharts of a blockchain data management method provided by an embodiment of the present invention;
[0077] Figure 2 A schematic diagram of the structure of the logical model of the ledger data organization on the blockchain node provided by an embodiment of the present invention;
[0078] Figure 3 A second flowchart of a blockchain data management method provided by an embodiment of the present invention;
[0079] Figure 4 A schematic diagram of an application ledger model of a blockchain data management method provided by an embodiment of the present invention;
[0080] Figure 5 A schematic diagram of the structure of a blockchain data management device provided by an embodiment of the present invention;
[0081] Figure 6 It is a structural schematic diagram of the electronic device provided by the present invention. DETAILED DESCRIPTION
[0082] In order to make the purpose, technical solution and advantages of the present invention clearer, the technical solution of the present invention will be clearly and completely described below in conjunction with the drawings of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0083] Combine the following Figure 1-Figure 3 The blockchain data management method of the present invention is described.
[0084] Figure 1 One of the flowcharts of a blockchain data management method provided by an embodiment of the present invention; Figure 2 A schematic diagram of the structure of the logical model of the ledger data organization on the blockchain node provided by an embodiment of the present invention; Figure 3 The present invention provides a flowchart of a blockchain data management method according to an embodiment of the present invention.
[0085] In a specific embodiment of the present invention, the present invention provides a blockchain data management method, comprising:
[0086] Step 110: Obtain attribute parameter values of all current block files of the blockchain system;
[0087] In the embodiment of the present invention, in order to further reduce the storage cost incurred by customers using blockchain services, while still enjoying the rapid storage of new block data, fast block (transaction) query response speed, and fast synchronization speed of new nodes, the embodiment of the present invention proposes a block data archiving method, which aims to achieve the large-capacity storage and high-performance disk writing and query requirements required for the persistence of account data in the blockchain system with a smaller storage resource budget.
[0088] The basic idea of the embodiment of the present invention is to deal with the large capacity demand for persistent storage of block data and the performance problem of reading and writing disks separately. The recent block data is maintained by a high-end small-capacity or medium-capacity high-performance storage facility to meet the performance required for block data storage and query; while the historical block data is maintained by a low-end large-capacity storage facility to meet the capacity requirements, that is, to store archived block files.
[0089] In the embodiment of the present invention, the blockchain system designed for multiple ledgers can of course also be a blockchain system designed for a single ledger. The blocks of each ledger are functionally divided into configuration blocks and ordinary blocks, wherein the configuration block only contains one ledger configuration transaction, the ordinary block contains one or more ordinary transactions, and each ordinary block contains the number of the most recent configuration block. The configuration block mainly controls user identity authentication and access rights. Generally, a new configuration block is generated when a new member joins (members exit) and the administrator user certificate is updated. The most recent configuration block height will be included in the ordinary block. Blocks are organized in the form of block data files, and one block file usually contains multiple blocks. The size of the block file can be flexibly set. One ledger usually corresponds to multiple block data files. The block file number of each block and its starting offset in all current block files, the transaction ID in the block, and the offset in the block will be saved in the index database in the form of an index. The purpose is to speed up the query speed of blocks and transactions, and this mechanism is crucial to the normal operation of the blockchain system. The present invention is also applicable to blockchain systems of various node types. For example, a blockchain system with separated consensus and accounting, that is, both consensus nodes and accounting nodes hold block data. Figure 2 It is the logical model of ledger data organization on blockchain nodes.
[0090] In the embodiment of the present invention, the blockchain ledger of the blockchain system can be first obtained; then the number of block files and the file size value corresponding to each blockchain ledger can be determined. In other words, it is possible to obtain how many blockchain ledgers exist in the blockchain system, and determine the number of block files corresponding to each blockchain and the total file size value of the block files of the entire ledger.
[0091] Step 120: determining a target archive file from all current block files based on the relationship between the attribute parameter value and a preset threshold;
[0092] Specifically, after obtaining the attribute parameter values of the blockchain ledger, the target archive files to be archived can be determined according to the number of blockchain ledgers. Specifically, there are two configuration methods: archiving configuration at the single ledger level and archiving configuration at the multi-ledger global level.
[0093] For single-ledger archiving configuration, the archiving of each ledger is controlled by three parameters: the maximum number of block files, the maximum amount of block file data, and the minimum number of block files. The specific functions of these parameters are described as follows:
[0094] (1) Maximum number of block files Specifies that the block files triggered by the current ledger should be larger than this parameter.
[0095] (2) Maximum block file data size specifies that the block file data size of the current ledger that triggers archiving should be greater than this parameter. The unit can be KB, MB, GB, etc.
[0096] (3) The minimum number of block files specifies the number of block files that the current account should retain. Generally, the maximum number of block files should be strictly greater than the minimum number of block files.
[0097] The archiving module is triggered only when and only when the number of block files in the current account exceeds the configured maximum number of block files or the accumulated block file size exceeds the configured maximum block file data volume.
[0098] If the number of block files in each ledger is greater than the configured minimum number of blocks but does not meet the configured maximum number of block files or maximum block file size, the ledger level archiving is not met at this time. However, these block data files and their block data sizes will contribute to the global archiving configuration.
[0099] The present invention takes into account the multi-ledger blockchain system, which often supports multiple ledgers, and each ledger is a logical blockchain. When the ledger level does not meet the archiving requirements, but the current block file of each ledger exceeds the configured minimum block file, it will further check whether the global archiving conditions are met.
[0100] (b) For global configuration of multiple ledgers, that is, global archiving, the global archiving conditions are controlled by two parameters: the global maximum number of block files and the global maximum block file data volume. File archiving can be performed if any one of them is met. The global maximum number of block files (global maximum block file data volume) is the sum of all the current block file numbers (block file data volume) of each ledger. Under global archiving, all current ledgers will be sorted in descending order by the number of block files, that is, the ledgers with more block files (larger block data volume) will be archived first. Of course, at this time, each blockchain ledger still needs to retain the minimum number of block files configured at the ledger level.
[0101] Specifically, when archiving a global blockchain system, the number of global block files and the global file size value of all blockchain ledgers in the blockchain system may be first counted; a first global target archive file may be determined based on the number of global block files and a first threshold;
[0102] determining a second global target archive file based on the global file size value and a second threshold;
[0103] determining the first global target archive file and the second global target archive file as target archive files;
[0104] Among them, after archiving the first global target archive file and the second global target archive file, the number of block files remaining in each blockchain account book is not less than the minimum number of block files.
[0105] That is to say, in order to determine the target archive file in all current block files based on the relationship between the attribute parameter value and the preset threshold, the archive file can be determined based on the number of files, or based on the file size, but after archiving, the minimum number of block files of each blockchain account book must be guaranteed. Specifically, it can be determined for each blockchain account book whether the number of block files is greater than the archiving trigger number; if so, the N block files with the longest archiving time in the blockchain account book are used as the first target archive file; wherein N is the current number of block files in the account book minus the minimum number of block files left; the minimum number of block files is the number of block files that the blockchain account book must at least retain; or for each blockchain account book, it is determined whether the block file size value is greater than the archiving trigger size value; if so, the block file with the longest archiving time in the blockchain account book is used as the second target archive file; wherein the file size value of the second target archive file is the block size value minus the archiving trigger size value; wherein the block file size value is the sum of the size values of all block files in the blockchain account book.
[0106] Step 130: Transfer the target archive file from the current storage area to the archive storage area.
[0107] After the target archive files (which may be the first target archive files or the second target archive files) are determined, an archive operation may be performed on the target archive files. Specifically, the target archive files may be transferred from the current storage area to the archive storage area, including:
[0108] Step 210: Read the block file path and block file serial number of the target archive file, and generate the corresponding archive file absolute path;
[0109] Step 220: Transfer the target archive file to the archive storage area according to the archive file absolute path, and copy the target archive file under the current block data directory to the archive data directory;
[0110] Step 230: Delete the target archive file to which the current storage block data directory has been transferred;
[0111] Step 240: Update the archive checkpoint and store the data in the archive checkpoint persistently.
[0112] Specifically, in practice, the state of the ledger can be switched to the archive state; then the block file path and block file serial number under the ledger to be archived are read to generate the corresponding archive file absolute path; secondly, the file copy operation can be performed to copy one block file under the normal block data directory to the archive data directory; here, the block file serial number in the archive checkpoint can be updated, and the latest archive checkpoint information can be persistently stored; then the archived block files are trimmed under the normal block data directory to free up limited storage space; repeat the operation until all the target archive files that need to be archived in the current batch are archived. After archiving is completed, the state of the ledger can be reset and wait for the next archive check. Specifically, file system archiving is to transfer the archived block data files to the local file system archive directory (the directory can mount the corresponding configured disk or storage facility as needed). External storage system is to transfer the archived block data to cloud storage or proprietary file system services.
[0113] Moreover, when querying the archived information, the archived checkpoint information can be preferably stored in a key-value database, and specifically, a dedicated key can be used for storage. In the embodiment of the present invention, two archiving modes can be used, namely, automatic archiving mode and manual archiving mode. In the automatic archiving mode, during the operation of the blockchain consensus node or the accounting node, the archiving module executed in the background of the consensus or accounting node is automatically activated according to the scheduled task parameters set by the archiving configuration module, and the block data file is archived if the archiving conditions are met. After the automatic archiving mode configuration is started, no human intervention is required, and the block data file can be archived in time according to the configuration rules. In the manual archiving mode, the archiving operation is completed by the archiving tool when the blockchain consensus node or the accounting node is suspended.
[0114] Please refer to Figure 4 , Figure 4 A schematic diagram of an application ledger model of a blockchain data management method provided in an embodiment of the present invention.
[0115] In another specific embodiment of the present invention, the archiving of block data should not only free up high-performance storage space with limited capacity, but also meet the query needs of the blockchain system operation, regardless of whether the query request comes from the business level or the query design of the blockchain system itself. The embodiment of the present invention supports the query requirements of archived block data and normal account book data as data sources.
[0116] The block data in the embodiment of the present invention exists in two different storage locations, so it is called a dual-source block. The basic processing idea for querying is to first read the archived checkpoint information from the block (transaction) index library, and then determine whether to switch the query directory. According to the source of the query request, it can be divided into discrete queries and continuous queries. Discrete queries usually come from client applications of blockchain systems; continuous queries are more common in data exchanges between nodes of blockchain systems. For example, the accounting node pulls blocks from the sorting node. The specific operations of the two queries are as follows:
[0117] For discrete queries, that is, querying a block (transaction) from a specific block file, the following steps can be performed: receiving a user's discrete query request for the blockchain; in response to the discrete query request, obtaining a file location pointer of the blockchain; if the block file number pointed to by the file location pointer is not greater than the block file number in the archive checkpoint, reading the block file from the archive block data directory; if the block file number pointed to by the file location pointer is greater than the block file number in the archive checkpoint, reading the block file from the current block data directory, and searching for the block file from the local ledger data directory.
[0118] For continuous queries, that is, the block file being queried is a range interval, the starting block file of the interval may be located in the archived block data directory, and the ending block file may be in the normal ledger block data directory. The processing method is slightly different at this time. A more complicated situation is that if the block file number in the archive checkpoint separates the range interval, the query from the starting block file to the separation point will use the archived block data directory, while the block file data greater than the separation point will use the normal block data directory.
[0119] That is to say, in general, Figure 4 The current block data in the normal ledger data can already meet general query requirements, and the query is performed in the current block data first. If the required data cannot be found in the current block data, it is necessary to query the archived block data corresponding to the current block data. The current block data and the archived block data are continuous block data on the blockchain ledger.
[0120] In addition, given the importance of configuration blocks to the normal operation of nodes in some blockchain systems, the present invention stores the most recent configuration blocks in a dedicated most recent configuration block file to ensure smooth restart of blockchain nodes. When a blockchain node loads a configuration block, it is preferred to obtain it from the most recent configuration block file.
[0121] In order to realize continuous query, the following steps can be specifically performed: receiving a user's continuous query request for the blockchain, the continuous query request includes a target block query range interval; if it is determined that the file position pointer of the blockchain interrupts the target block query range interval, the query from the starting block file of the range to the interruption position uses the archived block data directory; and the block file data larger than the interruption position uses the local block data directory.
[0122] The embodiment of the present invention can archive historical block data files that occupy high-performance storage facilities, release valuable storage resources to receive new block data, and support users' needs for archiving historical blocks and historical transaction data queries. In terms of user experience, users are unaware and cannot distinguish whether node data has been archived. In terms of blockchain service costs, the blockchain service after applying the present invention will greatly reduce the storage budget. This is the most direct economic effect brought by the present invention. It brings significant budget savings to potential blockchain users and accelerates the process of universalization of blockchain services. This is the most direct social benefit generated by the present invention. The embodiment of the present invention establishes a set of archiving methods around the checkpoint mechanism and the state transfer mechanism, which can support the archiving of single ledgers and multiple ledgers; the archiving implementation methods are diverse, which can support both file system archiving and external storage system archiving; the archiving trigger mode supports automatic archiving and manual archiving.
[0123] The blockchain data management device provided by the present invention is described below. The blockchain data management device described below and the blockchain data management method described above can be referenced to each other.
[0124] Please refer to Figure 5 , Figure 5 A schematic diagram of the structure of a blockchain data management device provided by an embodiment of the present invention.
[0125] In another specific embodiment of the present invention, the present invention provides a blockchain data management device 500, comprising:
[0126] The parameter acquisition module 510 is used to obtain the attribute parameter values of all current block files of the blockchain system;
[0127] A target determination module 520, configured to determine a target archive file from all current block files based on a relationship between the attribute parameter value and a preset threshold;
[0128] The target transfer module 530 is used to transfer the target archive file from the current storage area to the archive storage area.
[0129] Furthermore, the parameter acquisition module includes:
[0130] A ledger acquisition unit, used to acquire a blockchain ledger of a blockchain system;
[0131] The attribute determination unit is used to determine the number of block files and the file size value corresponding to each blockchain ledger.
[0132] Furthermore, the target determination module includes:
[0133] A quantity determination unit, used to determine whether the number of block files in each blockchain ledger is greater than the archiving trigger number;
[0134] A first target determination unit is configured to, if yes, use the N block files with the longest archiving time in the blockchain account book as the first target archive files; wherein N is the number of current block files in the account book minus the minimum number of remaining block files; the minimum number of block files is the number of block files that the blockchain account book must at least retain;
[0135] or
[0136] A size determination unit, used to determine whether the block file size value of each blockchain ledger is greater than the archiving trigger size value;
[0137] A second target determination unit is configured to, if yes, use the block file with the longest archiving time in the blockchain ledger as the second target archive file; wherein the file size value of the second target archive file is the block size value minus the archive trigger size value;
[0138] The block file size value is the sum of the size values of all block files in the blockchain account book.
[0139] Furthermore, the target transfer module includes:
[0140] A path generation unit, used for reading the block file path and block file serial number of the target archive file, and generating a corresponding archive file absolute path;
[0141] A file transfer unit, used to transfer the target archive file to the archive storage area according to the absolute path of the archive file, and copy the target archive file under the current block data directory to the archive data directory;
[0142] A file deletion unit is used to delete the target archive file to which the data directory of the current storage block has been transferred;
[0143] The directory updating unit is used to update the archive checkpoint and store the data in the archive checkpoint persistently.
[0144] Furthermore, the archive storage area includes a cloud storage server or a proprietary file system server.
[0145] Furthermore, the target determination module includes:
[0146] The global attribute statistics unit is used to count the global block file quantity and global file size value of all blockchain ledgers in the blockchain system;
[0147] a global target file determination unit, configured to determine a first global target archive file based on the number of global block files and a first threshold;
[0148] determining a second global target archive file based on the global file size value and a second threshold;
[0149] determining the first global target archive file and the second global target archive file as target archive files;
[0150] Among them, after archiving the first global target archive file and the second global target archive file, the number of block files remaining in each blockchain account book is not less than the minimum number of block files.
[0151] Furthermore, it also includes:
[0152] Discrete query request module, used to receive discrete query requests from users on the blockchain;
[0153] A first response module, configured to obtain a file location pointer of the blockchain in response to the discrete query request;
[0154] The discrete query module is used to read the block file from the archived block data directory if the block file number pointed to by the file position pointer is not greater than the block file number in the archive checkpoint; if the block file number pointed to by the file position pointer is greater than the block file number in the archive checkpoint, the block file is read from the current block data directory and the block file is searched from the local account data directory.
[0155] Furthermore, it also includes:
[0156] A continuous query request module, used to receive a user's continuous query request for the blockchain, wherein the continuous query request includes a target block query range interval;
[0157] A continuous query module is used for, if it is determined that the file position pointer of the blockchain blocks the query range interval of the target block, the query from the starting block file of the range to the block position uses the archived block data directory; and the block file data larger than the block position uses the local block data directory.
[0158] Figure 6 An example of a physical structure diagram of an electronic device is shown in FIG. Figure 6 As shown, the electronic device may include: a processor 610, a communication interface 620, a memory 630 and a communication bus 640, wherein the processor 610, the communication interface 620 and the memory 630 communicate with each other through the communication bus 640. The processor 610 may call the logic instructions in the memory 630 to execute the blockchain data management method, which includes: obtaining the attribute parameter values of all current block files of the blockchain system; determining the target archive file in all current block files based on the relationship between the attribute parameter value and the preset threshold; and transferring the target archive file from the current storage area to the archive storage area.
[0159] In addition, the logic instructions in the above-mentioned memory 630 can be implemented in the form of a software functional unit and can be stored in a computer-readable storage medium when it is sold or used as an independent product. Based on such an understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art or the part of the technical solution, can be embodied in the form of a software product, and the computer software product is stored in a storage medium, including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk and other media that can store program codes.
[0160] On the other hand, the present invention also provides a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium, and the computer program includes program instructions. When the program instructions are executed by a computer, the computer can execute the blockchain data management method provided by the above methods, and the method includes: obtaining the attribute parameter values of all current block files of the blockchain system; determining a target archive file in all current block files based on the relationship between the attribute parameter value and a preset threshold; and transferring the target archive file from the current storage area to the archive storage area.
[0161] On the other hand, the present invention also provides a non-transitory computer-readable storage medium having a computer program stored thereon. When the computer program is executed by a processor, it is implemented to execute the above-mentioned blockchain data management method, the method comprising: obtaining attribute parameter values of all current block files of the blockchain system; determining a target archive file in all current block files based on the relationship between the attribute parameter value and a preset threshold; and transferring the target archive file from a current storage area to an archive storage area.
[0162] The device embodiments described above are merely illustrative, wherein 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 they may be distributed on multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. Ordinary technicians in this field can understand and implement it without paying creative labor.
[0163] Through the description of the above implementation methods, those skilled in the art can clearly understand that each implementation method can be implemented by means of software plus a necessary general hardware platform, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solution is essentially or the part that contributes to the prior art can be embodied in the form of a software product, and the computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, a disk, an optical disk, etc., including a number of instructions for a computer device (which can be a personal computer, a server, or a network device, etc.) to execute the methods described in each embodiment or some parts of the embodiments.
[0164] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, rather than to limit it. Although the present invention has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. However, these 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 invention.
Claims
1. A blockchain data management method, characterized in that: include: Obtaining attribute parameter values of all current block files of the blockchain system, including: obtaining a blockchain account book of the blockchain system, in which all current block files are stored; determining the number of block files and file size values corresponding to each blockchain account book; the attribute parameter values are archived through a single account book level or comprehensively configured across multiple accounts, including a maximum number of block files and a maximum amount of block file data; Determining a target archive file in all current block files based on the relationship between the attribute parameter value and the preset threshold value specifically includes: After obtaining the attribute parameter values of the blockchain ledger, determine the target archive files to be archived according to the number of blockchain ledgers, including single-ledger-level archive configuration and multi-ledger-level global archive configuration; For single-ledger-level archiving configuration: For each blockchain ledger, when the number of block files in the current blockchain ledger exceeds the configured maximum number of block files or the accumulated block file size exceeds the configured maximum block file data volume, single-ledger-level archiving is triggered; For the global-level archiving configuration of multiple ledgers: counting the number of global block files and the global file size value of all blockchain ledgers in the blockchain system; determining a first global target archive file based on the number of global block files and a first threshold; determining a second global target archive file based on the global file size value and a second threshold; determining the first global target archive file and the second global target archive file as target archive files; wherein, after archiving the first global target archive file and the second global target archive file, the number of block files remaining in each blockchain ledger is not less than the minimum number of block files; The target archive file is transferred from the current storage area to the archive storage area.
2. The blockchain data management method according to claim 1, characterized in that: The transferring of the target archive file from the current storage area to the archive storage area comprises: Read the block file path and block file serial number of the target archive file, and generate the corresponding archive file absolute path; Transfer the target archive file to the archive storage area according to the archive file absolute path, and copy the target archive file under the current block data directory to the archive data directory; Delete the target archive file to which the current storage block data directory has been transferred; The archive checkpoint is updated, and the data in the archive checkpoint is persistently stored.
3. The blockchain data management method according to claim 2, characterized in that: The archive storage area includes a cloud storage server or a dedicated file system server.
4. The blockchain data management method according to claim 1, characterized in that: Determining the target archive file in all current block files based on the relationship between the attribute parameter value and the preset threshold value includes: Determine for each blockchain account book whether the number of block files is greater than the archiving trigger number; if so, use the N block files with the longest archiving time in the blockchain account book as the first target archiving files; wherein N is the current number of block files in the account book minus the minimum number of block files left; the minimum number of block files is the number of block files that the blockchain account book must at least retain; or Determine for each blockchain ledger whether the block file size value is greater than the archiving trigger size value; if so, use the block file with the longest archiving time in the blockchain ledger as the second target archive file; wherein the file size value of the second target archive file is the block size value minus the archiving trigger size value, and the block file size value is the sum of the size values of all block files of the blockchain ledger.
5. The blockchain data management method according to any one of claims 1 to 4, characterized in that: Also includes: Receive discrete query requests from users on the blockchain; In response to the discrete query request, obtaining a file location pointer of the blockchain; If the block file number pointed to by the file position pointer is not greater than the block file number in the archive checkpoint, the block file is read from the archive block data directory; if the block file number pointed to by the file position pointer is greater than the block file number in the archive checkpoint, the block file is read from the current block data directory and the block file is searched from the local ledger data directory.
6. The blockchain data management method according to any one of claims 1 to 4, characterized in that: Also includes: Receiving a continuous query request from a user for a blockchain, wherein the continuous query request includes a target block query range interval; If it is determined that the file position pointer of the blockchain blocks the target block query range interval, the query from the starting block file of the range to the block position uses the archived block data directory; and the block file data larger than the block position uses the local block data directory.
7. A blockchain data management device, characterized in that: include: The parameter acquisition module is used to obtain the attribute parameter values of all current block files of the blockchain system, including: obtaining the blockchain account book of the blockchain system, in which all current block files are stored; determining the number of block files and the file size value corresponding to each blockchain account book; the attribute parameter value is configured through single account book level archiving or multi-account book comprehensive side configuration, including the maximum number of block files and the maximum amount of block file data; A target determination module, used to determine a target archive file in all current block files based on the relationship between the attribute parameter value and a preset threshold, includes: After obtaining the attribute parameter values of the blockchain ledger, determine the target archive files to be archived according to the number of blockchain ledgers, including single-ledger-level archive configuration and multi-ledger-level global archive configuration; For single-ledger-level archiving configuration: For each blockchain ledger, when the number of block files in the current blockchain ledger exceeds the configured maximum number of block files or the accumulated block file size exceeds the configured maximum block file data volume, single-ledger-level archiving is triggered; For the global-level archiving configuration of multiple ledgers: counting the number of global block files and the global file size value of all blockchain ledgers in the blockchain system; determining a first global target archive file based on the number of global block files and a first threshold; determining a second global target archive file based on the global file size value and a second threshold; determining the first global target archive file and the second global target archive file as target archive files; wherein, after archiving the first global target archive file and the second global target archive file, the number of block files remaining in each blockchain ledger is not less than the minimum number of block files; The target transfer module is used to transfer the target archive file from the current storage area to the archive storage area.
8. 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 program, the steps of the blockchain data management method according to any one of claims 1 to 6 are implemented.
9. A non-transitory computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the blockchain data management method as described in any one of claims 1 to 6 are implemented.
Citation Information
Patent Citations
Data processing method in blockchain system and related equipment
CN112291376A
