Data processing method and device based on block chain, equipment and medium
By replacing the value elements and block height of the key-value pair to be modified in the blockchain, the problems of storage space and data security in the blockchain are solved, and efficient data storage and secure recovery are achieved.
Patent Information
- Application Number
- CN202311205715.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-18
- Publication Date
- 2025-03-18
AI Technical Summary
In blockchain, as the height of blocks increases, the required storage space increases dramatically, and blockchain nodes need to store multiple copies of the same data, resulting in huge challenges in storage space and data security issues.
By obtaining the target key-value pair of the block to be stored, determining the matching key-value pairs to be modified, and replacing the original value element and block height with the new value element and block height, thereby only storing the latest value and block height of the key element, reducing the use of storage space.
It effectively saves storage space and easily and accurately retrieves damaged or lost data through block height, improving data security.
Smart Images

Figure CN119645952A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of blockchain technology, and specifically, to a blockchain-based data processing method, a blockchain-based data processing device, an electronic device, and a computer-readable medium. Background Art
[0002] It is understandable that during the operation of the blockchain, blocks will continue to be generated and then stored in the database in sequence. In the related art, blockchain nodes usually convert the block data contained in the block into key-value pairs for storage. As the block height continues to grow, more and more storage space is required, and blockchain nodes also store multiple copies of the same data (for example, using a distributed NoSQL database tikv to store 3 copies). Although the integrity of the data is guaranteed, it is a huge challenge for storage space.
[0003] Therefore, how to improve the rationality of data storage in blockchain to save storage space is an urgent problem to be solved. Summary of the invention
[0004] The embodiments of the present application provide a blockchain-based data processing method, device, equipment, and medium, which improve the rationality of data processing in the blockchain, greatly save storage space, and ensure the security of data.
[0005] In a first aspect, an embodiment of the present application provides a data processing method based on blockchain, the method comprising: obtaining a target key-value pair corresponding to block data contained in a block to be stored; wherein the target key-value pair comprises a key element, a value element, and a block height of the block to be stored; based on the key element contained in the target key-value pair, determining a key-value pair to be modified that matches the key element contained in the target key-value pair from a storage area; replacing the value element contained in the key-value pair to be modified with the value element contained in the target key-value pair, and replacing the block height contained in the key-value pair to be modified with the block height contained in the target key-value pair.
[0006] In one embodiment of the present application, based on the aforementioned scheme, the storage area includes multiple shard areas, each shard area stores multiple target key-value pairs; the method also includes: receiving a shard area merge request, the shard area merge request includes identification information corresponding to at least two shard areas; based on the identification information corresponding to the at least two shard areas, merging the at least two shard areas to obtain a merged shard area; wherein the number of target key-value pairs stored in the merged shard area is equal to the total number of target key-value pairs stored in the at least two shard areas.
[0007] In one embodiment of the present application, based on the aforementioned scheme, the storage area includes multiple shard areas, each shard area stores multiple target key-value pairs; the method also includes: receiving a shard area split request, the shard area split request includes identification information corresponding to the shard area to be split; based on the identification information corresponding to the shard area to be split, the shard area to be split is split to obtain at least two shard areas; wherein the total number of target key-value pairs stored in the at least two shard areas is equal to the number of target key-value pairs stored in the shard area to be split.
[0008] In one embodiment of the present application, based on the aforementioned scheme, the storage area includes multiple shard areas, each shard area stores multiple target key-value pairs; the method also includes: receiving a shard area transfer request, the shard area move request includes identification information corresponding to the shard area to be transferred out, and identification information corresponding to the blockchain node to be transferred in; based on the identification information corresponding to the shard area to be transferred out, transferring the shard area to be transferred out to a blockchain node that matches the identification information corresponding to the blockchain node to be transferred in; wherein, the number of target key-value pairs stored in the shard area before and after the transfer is the same.
[0009] In a second aspect, an embodiment of the present application provides a blockchain-based data processing device, the device comprising: an acquisition module, configured to acquire a target key-value pair corresponding to the block data contained in the block to be stored; wherein the target key-value pair comprises a key element, a value element, and a block height of the block to be stored; a determination module, configured to determine, based on the key element contained in the target key-value pair, a key-value pair to be modified that matches the key element contained in the target key-value pair from a storage area; a replacement module, configured to replace the value element contained in the key-value pair to be modified with the value element contained in the target key-value pair, and to replace the block height contained in the key-value pair to be modified with the block height contained in the target key-value pair.
[0010] In a third aspect, an embodiment of the present application provides an electronic device, comprising one or more processors; and a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the electronic device implements the blockchain-based data processing method as described above.
[0011] In a fourth aspect, an embodiment of the present application provides a computer-readable medium on which a computer program is stored, and when the computer program is executed by a processor, the blockchain-based data processing method as described above is implemented.
[0012] In a fifth aspect, an embodiment of the present application provides a computer program product, including computer instructions, which, when executed by a processor, implement the blockchain-based data processing method as described above.
[0013] In the technical solution provided in the embodiments of the present application:
[0014] On the one hand, when there is a target key-value pair corresponding to a block to be stored, the value element contained in the key-value pair to be modified is replaced by the value element contained in the target key-value pair, and the block height contained in the key-value pair to be modified is replaced by the block height contained in the target key-value pair; that is, the value element and block height contained in the stored target key-value pair are updated instead of storing the target key-value pair separately. In this way, the target key-value pair for the same key element is only stored once (or the latest value element and block height of the key element are stored). Compared with storing multiple key-value pairs corresponding to the same key element in the related art, storage space is saved to a great extent.
[0015] On the one hand, the target key-value pair includes the block height, so that in the event of data damage / loss, the damaged / lost data can be easily and accurately retrieved through the block height, which greatly optimizes the tracing of the damaged / lost data and ensures the security of the data.
[0016] It should be understood that the foregoing general description and the following detailed description are exemplary and explanatory only and are not restrictive of the present application. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] Figure 1 It is a structural diagram of the blockchain network.
[0018] Figure 2 It is a schematic diagram of the connection relationship between blocks in the blockchain.
[0019] Figure 3 It is a schematic diagram of an exemplary implementation environment to which the technical solution of the embodiments of the present application can be applied.
[0020] Figure 4 It is a flowchart of a blockchain-based data processing method shown in an exemplary embodiment of the present application.
[0021] Figure 5 It is a flowchart of a blockchain-based data processing method shown in another exemplary embodiment of the present application.
[0022] Figure 6 It is a flowchart of a blockchain-based data processing method shown in another exemplary embodiment of the present application.
[0023] Figure 7It is a flowchart of a blockchain-based data processing method shown in another exemplary embodiment of the present application.
[0024] Figure 8 It is a flowchart of a blockchain-based data processing method shown in another exemplary embodiment of the present application.
[0025] Fig. 9 It is a flowchart of a blockchain-based data processing method shown in another exemplary embodiment of the present application.
[0026] Fig.10 It is a flowchart of a blockchain-based data processing method shown in another exemplary embodiment of the present application.
[0027] Fig.11 It is a schematic diagram of the overall architecture shown by an exemplary embodiment of the present application.
[0028] Fig.12 It is a schematic diagram of a block in a xxx.fdb file shown in an exemplary embodiment of the present application.
[0029] Fig.13 It is a schematic diagram of the storage of archive files and index files shown in an exemplary embodiment of the present application.
[0030] Fig.14 It is a schematic diagram of a target key-value pair shown in an exemplary embodiment of the present application.
[0031] Fig.15 It is a schematic diagram showing the change of region status according to an exemplary embodiment of the present application.
[0032] Figure 16-1 to Figure 16-2 It is a schematic diagram of region merging shown in an exemplary embodiment of the present application.
[0033] Fig.17 It is a schematic diagram of region segmentation shown in an exemplary embodiment of the present application.
[0034] Figure 18-1 to Figure 18-4 It is a schematic diagram of region transfer shown in an exemplary embodiment of the present application.
[0035] Figure 19-1 to Figure 19-4 It is a schematic diagram of region recovery shown in an exemplary embodiment of the present application.
[0036] Fig. 20 It is a schematic diagram of submission management shown in an exemplary embodiment of the present application.
[0037] Fig.21 It is a block diagram of a blockchain-based data processing device shown as an exemplary embodiment of the present application.
[0038] Fig. 22 It is a schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application. DETAILED DESCRIPTION
[0039] Here, exemplary embodiments will be described in detail, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments that are the same as the present application. Instead, they are only examples of devices and methods that are the same as some aspects of the present application as detailed in the attached claims.
[0040] The block diagrams shown in the accompanying drawings are merely functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities may be implemented in software form, or in one or more hardware modules or integrated circuits, or in different networks and / or processor devices and / or microcontroller devices.
[0041] The flowcharts shown in the accompanying drawings are only exemplary and do not necessarily include all the contents and operations / steps, nor must they be executed in the order described. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined, so the actual execution order may change according to actual conditions.
[0042] It should be noted that the "multiple" mentioned in this application refers to two or more than two. "And / or" describes the association relationship of the associated objects, indicating that there can be three relationships. For example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the previous and next associated objects are in an "or" relationship.
[0043] Before introducing the technical solution of the embodiment of the present application, the blockchain technology used in the embodiment of the present application is first introduced.
[0044] Blockchain is a new application model of computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. Blockchain is essentially a decentralized database, a string of data blocks (i.e. blocks) generated by cryptographic methods. Each data block contains a batch of network transaction information, which is used to verify the validity of its information (anti-counterfeiting) and generate the next block. Blockchain can include the underlying blockchain platform, platform product service layer, and application service layer.
[0045] As mentioned above, blockchain is essentially a decentralized database, and the blockchain is maintained by the nodes in the blockchain network. Figure 1 ,exist Figure 1 The blockchain network shown may include multiple nodes 101, and the multiple nodes 101 may be the various clients forming the blockchain network. Each node 101 may receive input information during normal operation, and maintain the shared data in the blockchain network based on the received input information. In order to ensure the information intercommunication within the blockchain network, there may be an information connection between each node in the blockchain network, and the nodes may transmit information through the above information connection. For example, when any node in the blockchain network receives input information, the other nodes in the blockchain network obtain the input information according to the consensus algorithm, and store the input information as shared data, so that the data stored on all nodes in the blockchain network are consistent.
[0046] Each node in the blockchain network has a corresponding node identifier, and each node in the blockchain network can store the node identifiers of other nodes, so that the generated blocks can be broadcast to other nodes in the blockchain network according to the node identifiers of other nodes. A node identifier list can be maintained in each node, and the node name and node identifier are stored in the node identifier list accordingly. The node identifier can be an IP (Internet Protocol, a protocol for interconnecting networks) address or any other information that can be used to identify the node.
[0047] Each node in the blockchain network stores the same blockchain. The blockchain consists of multiple blocks, see Figure 2 The blockchain consists of multiple blocks. The genesis block includes a block header and a block body. The block header stores input information feature values, version numbers, timestamps, and difficulty values, and the block body stores input information. The next block of the genesis block uses the genesis block as its parent block. The next block also includes a block header and a block body. The block header stores the input information feature values of the current block, the block header feature values, version numbers, timestamps, and difficulty values of the parent block, and so on. This ensures that the block data stored in each block in the blockchain is associated with the block data stored in the parent block, thereby ensuring the security of the input information in the block.
[0048] Each node in the blockchain network can be a server or a terminal device. The server can be an independent physical server, a server cluster or a distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and intelligent platforms. The terminal device can be a smart phone, tablet computer, laptop computer, desktop computer, smart speaker, smart watch, etc., but is not limited to this. Each node can be directly or indirectly connected by wired or wireless communication, and this application is not limited here.
[0049] The aforementioned cloud computing refers to the delivery and use model of IT infrastructure, specifically refers to obtaining required resources through the network in an on-demand, easily scalable manner; in a broad sense, cloud computing refers to the delivery and use model of services, which refers to obtaining required services through the network in an on-demand, easily scalable manner. This service can be related to IT and software, the Internet, or other services. Cloud computing is the product of the development and integration of traditional computer and network technologies such as grid computing, distributed computing, parallel computing, utility computing, network storage technologies, virtualization, and load balancing. With the development of the Internet, real-time data streams, and the diversification of connected devices, as well as the promotion of search services, social networks, mobile commerce, and open collaboration, cloud computing has developed rapidly. Different from the previous parallel distributed computing, the emergence of cloud computing will promote revolutionary changes in the entire Internet model and enterprise management model in terms of concept.
[0050] The aforementioned blockchains are generally divided into three types: public blockchain, private blockchain and consortium blockchain. In addition, there can also be a combination of the above types, such as private blockchain + consortium blockchain, consortium blockchain + public blockchain, etc.
[0051] Among them, the public chain has the highest degree of decentralization. Participants who join the public chain (also known as nodes in the blockchain network) can read data records on the chain, participate in transactions, and compete for the right to record new blocks. Moreover, each node can freely join or exit the blockchain network and perform related operations.
[0052] On the contrary, the private chain has a blockchain network where the write permission is controlled by a certain organization or institution, and the data read permission is regulated by the organization. In simple terms, a private chain can be a weakly centralized system with strict restrictions on nodes and a small number of nodes. This type of blockchain is more suitable for use within a specific organization.
[0053] The consortium chain is a blockchain between the public chain and the private chain, which can achieve "partial decentralization". Each node in the consortium chain usually has a corresponding entity or organization; the nodes join the network through authorization and form a stakeholder alliance to jointly maintain the operation of the blockchain network.
[0054] The aforementioned blockchain is deployed with smart contracts. It can be understood that a transaction is a user's operation request for a smart contract deployed on the blockchain. The transaction is initiated by the user and sent from the user's client to a node in the blockchain network (called a master node). After receiving the transaction, the master node calls the corresponding smart contract according to the contract address and interface specified in the transaction, and then notifies the transaction to other nodes (called slave nodes). After receiving the transaction, the slave node calls the corresponding smart contract according to the contract address and interface specified in the transaction.
[0055] Among them, the master node notifies the slave node of the transaction, which involves the consensus mechanism in the blockchain technology. The consensus mechanism is the basis for ensuring the normal operation of the blockchain network. The so-called consensus means reaching an agreement. Each node in the blockchain network stores a distributed ledger (i.e., blockchain). The consensus process of the blockchain network is the process of keeping the distributed ledgers between each node consistent. Among them, all or part of the nodes in the blockchain network can participate in the consensus process of the blockchain network. The consensus process of the blockchain network is usually based on the consensus algorithm. Each node participating in the consensus executes the corresponding process of the consensus process by running the consensus algorithm. Optional consensus algorithms include PoW (Proof of Work), PoS (Proof of Stake), DPoS (Delegated Proof of Stake), PBFT (Practical Byzantine Fault Tolerance), etc.
[0056] Usually, one or more rounds of consensus process are required at a certain block height of the blockchain to reach an agreement among the nodes participating in the consensus to store a block of a certain block height. The block height is used to indicate the number of blocks connected to the blockchain. The block height is the identifier of the block, which can be used to indicate the position of the block in the blockchain. For example, the block height of the genesis block in the blockchain defaults to 0, the block height of the first block after the genesis block is 1 (the first block can be referred to as block 1), the block height of the second block after the genesis block is 2 (the second block can be referred to as block 2), and so on. Among them, a round of consensus process can be divided into three consensus stages in the order of execution, namely the proposal stage (Pre-prepare), the pre-voting stage (Prepare) and the pre-commit stage (Commit).
[0057] It is understandable that during the operation of the blockchain, blocks will continue to be generated and then stored in the database in sequence. In the related art, blockchain nodes usually convert the block data contained in the block into key-value pairs for storage. As the block height continues to grow, more and more storage space is required, and blockchain nodes also store multiple copies of the same data (for example, using a distributed NoSQL database tikv to store 3 copies). Although the integrity of the data is guaranteed, it is a huge challenge for storage space.
[0058] Therefore, in order to improve the rationality of data processing in the blockchain, save storage space, and ensure data security, this application provides a data processing solution based on the blockchain. Figure 3 , Figure 3 3011, a first data node 3012, a second data node 3013, a second blockchain node 3021, a third data node 3022, and a fourth data node 3023. It is understood that the first blockchain node 3011, the first data node 3012, the second data node 3013, the second blockchain node 3021, the third data node 3022, and the fourth data node 3023 are connected through network communication, and the network may include various connection types, such as wireless communication links, wired and optical fiber cables, etc., wherein:
[0059] The first blockchain node 3011, the first data node 3012, and the second data node 3013 may be the aforementioned Figure 1 Any node 101, that is, node 101 includes a first blockchain node 3011, a first data node 3012 and a second data node 3013.
[0060] Among them, the first blockchain node 3011 is used to participate in the block consensus and store the corresponding blockchain data in the first data node 3012 and the second data node 3013. The first blockchain node 3011 can be a server that provides various services; the server that provides various services includes but is not limited to an independent physical server, a server cluster or distributed system composed of multiple physical servers, and a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content distribution networks, and big data and artificial intelligence platforms. The first blockchain node 3011 can also be a terminal device; the terminal device includes but is not limited to smart phones, tablets, laptops, computers, intelligent voice interaction devices, smart home appliances, smart wearable devices, aircraft, etc.
[0061] Among them, the first data node 3012 and the second data node 3013 are used to store blockchain-related data. Exemplarily, the first data node 3012 and the second data node 3013 are databases for storing different types of blockchain-related data.
[0062] Optionally, the first data node 3012 is used to store complete blocks, which can be a block file storage database (BFDB for short), usually using xxx.fdb files (also called archive files) to store blocks. For example, the xx1.fdb file stores block heights of 0, 1, 2, 3, and 4, for a total of 5 blocks; the xx2.fdb file stores block heights of 5, 6, 7, 8, and 9, for a total of 5 blocks, and so on.
[0063] Optionally, the second data node 3013 is used to store the key-value pairs converted from the index data and status data in the BFDB (obtained by assembling the block data in the BFDB) (it can be understood that the K in the key-value pair is called the key element, and the V in the key-value pair is called the value element), which can be a distributed KV database (KVDB for short), where KVDB includes but is not limited to leveldb and rocksdb (rocksdb is an optimized version of leveldb).
[0064] The second blockchain node 3021, the third data node 3022, and the fourth data node 3023 may be the aforementioned Figure 1 Any one of the nodes 101, that is, node 101 includes the second blockchain node 3021, the third data node 3022 and the fourth data node 3023.
[0065] Among them, the second blockchain node 3021 is used to participate in the block consensus and store the corresponding blockchain data in the third data node 3022 and the fourth data node 3023. The second blockchain node 3021 can be a server that provides various services; the servers that provide various services include but are not limited to independent physical servers, server clusters or distributed systems composed of multiple physical servers, cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content distribution networks, and cloud servers that provide basic cloud computing services such as big data and artificial intelligence platforms. The second blockchain node 3021 can also be a terminal device; the terminal device includes but is not limited to smart phones, tablets, laptops, computers, intelligent voice interaction devices, smart home appliances, smart wearable devices, aircraft, etc.
[0066] Among them, the third data node 3022 and the fourth data node 3023 are used to store blockchain-related data. Exemplarily, the third data node 3022 and the fourth data node 3023 are databases for storing different types of blockchain-related data.
[0067] Optionally, the third data node 3022 is used to store complete blocks, which can be a block file storage database, usually using xxx.fdb files to store blocks, for example, the xx1.fdb file stores block heights of 0, 1, 2, 3, 4 for a total of 5 blocks, and the xx2.fdb file stores block heights of 5, 6, 7, 8, 9 for a total of 5 blocks, and so on.
[0068] Optionally, the fourth data node 3023 is used to store key-value pairs converted from index data and status data in the BFDB, which may be a distributed KV database, wherein the KVDB includes but is not limited to leveldb and rocksdb.
[0069] It should be noted that Figure 3 Only the details are shown in Figure 1 In practical applications, Figure 1 Each node in the can be flexibly adjusted according to the specific application scenario.
[0070] In one embodiment of the present application, the blockchain-based data processing method can be executed by the first blockchain node 3011, or the second data node 3013, or the first blockchain node 3011 and the second data node 3013 interactively.
[0071] In one embodiment of the present application, the blockchain-based data processing method can be executed by the second blockchain node 3021, or the fourth data node 3023, or the second blockchain node 3021 and the fourth data node 3023 interactively.
[0072] It should be noted that in the specific implementation of this application, user-related data is involved. When the embodiments of this application are applied to specific products or technologies, user permission or consent is required, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards of relevant countries and regions.
[0073] The following is a detailed description of various implementation details of the technical solution of the embodiment of the present application:
[0074] See also Figure 4 , Figure 4 3011 is a flowchart of a data processing method based on blockchain shown in an embodiment of the present application. The data processing method based on blockchain can be executed by the first blockchain node 3011. Figure 4 As shown, the data processing method based on blockchain includes at least S401 to S403, which are described in detail as follows:
[0075] S401, obtaining a target key-value pair corresponding to the block data contained in the block to be stored; wherein the target key-value pair includes a key element, a value element, and a block height of the block to be stored.
[0076] In the embodiment of the present application, the block to be stored refers to the block required to be stored to reach a consensus. It is understandable that the block data contained in the block to be stored can be any type of transaction data.
[0077] For example, the block to be stored is block_100 with a block height of 100, and the block data contained in block_100 is 2 transactions tx_1 and tx_2, and both tx_1 and tx_2 are executed successfully;
[0078] Exemplarily, tx_1 is used to represent that user A creates a guessing game a, the gameid of guessing game a is 1, and the game details of guessing game a are m1. tx_2 is used to represent that user A updates the created guessing game b, the gameid of guessing game b is 2, the gamedetails of guessing game b before the update are m2, and the gamedetails of guessing game b after the update are m3.
[0079] Exemplarily, tx_1 is used to represent that user A transfers out a virtual resource of amount n1 for account a, and tx_2 is used to represent that user A transfers into a virtual resource of amount n2 for account b.
[0080] In the embodiment of the present application, the target key-value pair refers to the key-value pair obtained by converting the block data contained in the block to be stored, and the key-value pair obtained by the conversion includes a key element, a value element, and a block height of the block to be stored.
[0081] S402: Based on the key element contained in the target key-value pair, determine from the storage area a key-value pair to be modified that matches the key element contained in the target key-value pair.
[0082] In the embodiment of the present application, a target key-value pair corresponding to the block data contained in the block to be stored is obtained, and then based on the key element contained in the target key-value pair, a key-value pair to be modified that matches the key element contained in the target key-value pair can be determined from the storage area.
[0083] In the embodiment of the present application, the storage area refers to the storage area used for storage in the storage device on the first blockchain node side. Optionally, the storage device is the aforementioned second data node, specifically, it can be BFKV.
[0084] It can be understood that there are multiple target key-value pairs stored in the storage area, wherein the multiple target key-value pairs stored in the storage area are stored before the current moment. In short, the multiple target key-value pairs stored in the storage area are stored in the past time period; they are different from the aforementioned acquired target key-value pairs. The aforementioned acquired target key-value pairs are currently required to be stored in the storage area. When the acquired target key-value pairs are stored in the storage area, they become the target key-value pairs stored in the storage area.
[0085] It should be noted that each target key-value pair stored in the storage area also includes a key element, a value element, and a block height (related to the block height of the block during actual storage).
[0086] For example, please refer to Table 1, which shows an example storage area storing multiple target key-value pairs.
[0087] Target key-value pair 1 k:xx11,v:xx12,h:xx13 Target key-value pair 2 k:xx21,v:xx22,h:xx23 Target key-value pair 3 k:xx31,v:xx32,h:xx33 …… …… Target key-value pair n k:xxn1,v:xxn2,h:xxn3
[0088] Table 1
[0089] T is used to represent multiple target key-value pairs stored in the storage area. As shown in Table 1, T = {target key-value pair 1, target key-value pair 2, target key-value pair 3 ... target key-value pair n}, wherein target key-value pair 1 = {k: xx11, v: xx12, h: xx13}, target key-value pair 2 = {k: xx21, v: xx22, h: xx23}, target key-value pair 3 = {k: xx31, v: xx32, h: xx33} ... target key-value pair n = {k: xxn1, v: xxn2, h: xxn3}.
[0090] In an embodiment of the present application, the key-value pair to be modified refers to a target key-value pair determined from the storage area that matches the key element contained in the acquired target key-value pair, wherein, in order to distinguish the acquired target key-value pair from the target key-value pair determined from the storage area, the target key-value pair determined from the storage area is referred to as the key-value pair to be modified.
[0091] For example, assume that the target key-value pair obtained is target key-value pair 3', where target key-value pair 3' = {k:xx31, v:xx32', h:xx33'}. Based on the storage area shown in Table 1, it can be determined that the key-value pair to be modified that matches the key element (i.e., k:xx31) contained in the target key-value pair 3' is the target key-value pair 3.
[0092] S403, replacing the value element contained in the key-value pair to be modified with the value element contained in the target key-value pair, and replacing the block height contained in the key-value pair to be modified with the block height contained in the target key-value pair.
[0093] In the embodiment of the present application, the key-value pair to be modified is determined, and then the value element contained in the key-value pair to be modified can be replaced by the value element contained in the obtained target key-value pair, and the block height contained in the key-value pair to be modified can be replaced by the block height contained in the obtained target key-value pair.
[0094] That is, in the embodiment of the present application, when the value element and block height in the stored target key-value pair change, the value element and block height are updated based on the target key-value pair, rather than storing the target key-value pair separately. That is, the target key-value pair for the same key element is only stored once, thereby saving storage space to a great extent.
[0095] For ease of understanding, the storage situation in the related art and the storage situation in the embodiments of the present application will be exemplified here.
[0096] For example, please refer to Table 2, which is an example of storage conditions in related technologies.
[0097] Time Key-value pairs Time point t1 k:xx11,v:xx12 Time point t2 k:xx11,v:xx12' Time point t3 k:xx11, v:xx12"
[0098] Table 2
[0099] Among them, time point t1 is earlier than time point t2, and time point t2 is earlier than time point t3. As shown in Table 2, the initial key-value pair (i.e., at time point t1) is {k:xx11, v:xx12}. As transactions continue to occur, new key-value pairs are continuously generated. Specifically, at time point t2, a key-value pair {k:xx11, v:xx12'} is generated, and at time point t3, a key-value pair {k:xx11, v:xx12"} is generated. It can be seen that in the related art, multiple key-value pairs are stored for the same key element.
[0100] Please refer to Table 3, which is an example of the storage situation in an embodiment of the present application.
[0101] Time Target key-value pair Time point t3 k:xx11, v:xx12”, h:xx13”
[0102] Table 3
[0103] Continuing with the above example, in the embodiment of the present application, through the replacement operation, only the target key-value pair {k:xx11, v:xx12", h:xx13"} corresponding to the time point t3 is stored in the storage area.
[0104] It is understandable that since only the latest target key-value pair is stored in the embodiment of the present application, in order to better trace data when needed, a parameter of block height is added to the target key-value pair, so that in the event of data damage / loss, the damaged / lost data can be retrieved through the block height.
[0105] In one embodiment of the present application, the process of replacing the value element contained in the key-value pair to be modified with the value element contained in the target key-value pair in S403 may include:
[0106] If it is detected that the value element contained in the target key-value pair is different from the value element contained in the key-value pair to be modified, the value element contained in the key-value pair to be modified is replaced by the value element contained in the target key-value pair.
[0107] That is, in an optional embodiment, it can be detected first whether the value element contained in the obtained target key-value pair is the same as the value element contained in the key-value pair to be modified; wherein, if it is detected that the value element contained in the obtained target key-value pair is different from the value element contained in the key-value pair to be modified, the value element contained in the key-value pair to be modified can be replaced by the value element contained in the target key-value pair; if it is detected that the value element contained in the obtained target key-value pair is the same as the value element contained in the key-value pair to be modified, no processing is performed, that is, there is no need to replace the value element contained in the key-value pair to be modified with the value element contained in the target key-value pair, thereby saving replacement time and improving storage efficiency.
[0108] In one embodiment of the present application, the process of replacing the block height contained in the key-value pair to be modified with the block height contained in the target key-value pair in S403 may include:
[0109] If it is detected that the block height contained in the target key-value pair is different from the block height contained in the key-value pair to be modified, the block height contained in the key-value pair to be modified is replaced by the block height contained in the target key-value pair.
[0110] That is, in an optional embodiment, it is possible to first detect whether the block height contained in the obtained target key-value pair is the same as the block height contained in the key-value pair to be modified; wherein, if it is detected that the block height contained in the obtained target key-value pair is different from the block height contained in the key-value pair to be modified, the block height contained in the key-value pair to be modified can be replaced by the block height contained in the target key-value pair; if it is detected that the block height contained in the obtained target key-value pair is the same as the block height contained in the key-value pair to be modified, no processing is required, that is, there is no need to replace the block height contained in the key-value pair to be modified with the block height contained in the target key-value pair, thereby saving replacement time and improving storage efficiency.
[0111] In one embodiment of the present application, if, based on the key element contained in the target key-value pair, a key-value pair to be modified that matches the key element contained in the target key-value pair is not determined from the storage area (i.e., the key-value pair to be modified is not determined), then it is characterized that the target key-value pair corresponding to the key element is not currently stored in the storage area (it may have never been stored, or has been deleted or lost, etc.), and therefore, the acquired target key-value pair can be directly stored in the storage area.
[0112] In the embodiment of the present application, the target key-value pair for the same key element is only stored once (or the latest value element and block height of the key element are stored), which saves storage space to a great extent compared to storing multiple key-value pairs corresponding to the same key element in the related art; at the same time, since the target key-value pair includes the block height, the damaged / lost data can be easily and accurately retrieved through the block height, thereby ensuring the security of the data.
[0113] In one embodiment of the present application, another blockchain-based data processing method is provided, and the blockchain-based data processing method can be executed by the first blockchain node 3011. Figure 5 As shown, the blockchain-based data processing method may include S501 to S503, S402 to S403.
[0114] S501 to S503 are described in detail as follows:
[0115] S501, converting the block data contained in the block to be stored into an initial key-value pair, where the initial key-value pair includes a key element and a value element.
[0116] In the embodiment of the present application, the block to be stored is obtained, and then the block data contained in the block to be stored can be converted into an initial key-value pair, and the initial key-value pair includes a key element and a value element.
[0117] In the embodiment of the present application, the initial key-value pair refers to a key-value pair obtained by converting the block data contained in the storage block using a preset conversion rule, and the key-value pair obtained by the conversion includes a key element and a value element.
[0118] S502, obtaining the block height of the block to be stored.
[0119] In the embodiment of the present application, the block to be stored is obtained, and then the block height of the block to be stored can be determined based on the block to be stored.
[0120] S503, associating the block height with the initial key-value pair to generate a target key-value pair.
[0121] In the embodiment of the present application, the block height and the initial key-value pair are obtained, and then the block height and the initial key-value pair can be associated to generate a target key-value pair.
[0122] In one embodiment of the present application, the process of associating the block height with the initial key-value pair to generate the target key-value pair in S503 may include:
[0123] Encapsulate the key element contained in the initial key-value pair in the first field;
[0124] Encapsulate the block height and the value element contained in the initial key-value pair in the second field; wherein the position of the block height in the second field is before the position of the value element contained in the initial key-value pair;
[0125] Combine the first field and the second field to generate a target key-value pair.
[0126] That is, in an optional embodiment, associating the block height with the initial key-value pair can be accomplished by encapsulating the key element contained in the initial key-value pair in a first field, and encapsulating the block height and the value element contained in the initial key-value pair in a second field, wherein the position of the block height in the second field is before the position of the value element contained in the initial key-value pair, and then combining the first field and the second field to obtain the target key-value pair.
[0127] For example, please refer to Table 4, which is an example of the generation of target key-value pairs.
[0128] First Field Second field Key elements Block height + value element
[0129] Table 4
[0130] Among them, in an optional embodiment, the byte corresponding to the block height can be specified, or a preset separator can be used to separate the block height and the value element.
[0131] By implementing an optional embodiment, the key element is encapsulated in the first field, and the block height and value element are encapsulated in the second field, so that the key element is separated out, which is convenient for accurately determining the key element, thereby improving storage efficiency; at the same time, the block height in the second field is before the value element, which is convenient for accurately determining the block height and value element, avoiding the phenomenon that when the block height and value element are distinguished by a preset separator, the block height and value element cannot be accurately distinguished due to the presence of the same preset separator in the value element.
[0132] In one embodiment of the present application, the block height and the value element contained in the initial key-value pair may also be encapsulated in different fields. In practical applications, they can be flexibly adjusted according to specific application scenarios.
[0133] It should be noted that Figure 5 For detailed description of S402 to S403, please refer to Figure 4 S402 to S403 shown are not described in detail here.
[0134] In the embodiment of the present application, the block height of the block to be stored is associated with the initial key-value pair including the key element and the value element, so that the target key-value pair can be generated simply and accurately; and because the generated target key-value pair includes the block height, in the event of data damage / loss, the damaged / lost data can be retrieved through the block height.
[0135] In one embodiment of the present application, another blockchain-based data processing method is provided, and the blockchain-based data processing method can be executed by the first blockchain node 3011. Figure 6 As shown, the blockchain-based data processing method may include S601 to S603, S401, and S403.
[0136] In the embodiment of the present application, the storage area includes multiple shard areas, wherein the number of target key-value pairs stored in different shard areas may be the same or different.
[0137] For example, assume that the storage area includes a shard area region1 and a shard area region2, wherein the shard area region1 stores 100 target key-value pairs, and the shard area region2 stores 200 target key-value pairs.
[0138] Optionally, after storing the target key-value pair in the shard area, the storage-related attribute information of the shard area may be recorded; wherein the attribute information includes but is not limited to the currently stored minimum key element and maximum key element, the number of times the shard area is merged, the number of times it is split, etc.
[0139] S601 to S603 are described in detail as follows:
[0140] S601, based on the key element contained in the target key-value pair, determine a sharding area for storing the target key-value pair.
[0141] In the embodiment of the present application, a target key-value pair is obtained, and then a sharding area for storing the obtained target key-value pair can be determined based on the key element contained in the obtained target key-value pair.
[0142] Exemplarily, based on the key element contained in the acquired target key-value pair, identification information corresponding to the shard area for storing the acquired target key-value pair is determined.
[0143] S602, modifying the block height corresponding to the determined sharding area to the block height contained in the target key-value pair, and modifying the state corresponding to the determined sharding area to a write state; wherein the write state is used to indicate that the determined sharding area cannot be accessed.
[0144] In an embodiment of the present application, a shard area for storing the acquired target key-value pair is determined, and then the block height corresponding to the determined shard area can be modified to the block height contained in the acquired target key-value pair, and the state corresponding to the determined shard area can be modified to a write state; wherein the write state is used to indicate that the determined shard area cannot be accessed.
[0145] That is, the shard area determined in the embodiment of the present application corresponds to a block height and a status, wherein the writing process of the target key-value pair can be started by modifying the block height and the status of the shard area.
[0146] For example, if region.targetHeight is used to represent the block height of the shard region, and the block height contained in the target key-value pair is 100, then region.targetHeight is modified to 100, that is, region.targetHeight:100. If region.status is used to represent the status of the shard region, and applying is used to represent the write status, then region.status is modified to applying, that is, region.status:applying.
[0147] S603: Search for a target key-value pair that matches the key element contained in the target key-value pair from the determined shard area, and use the found target key-value pair as the key-value pair to be modified.
[0148] In the embodiment of the present application, the block height and status corresponding to the determined shard area are modified, and then a target key-value pair matching the key element contained in the target key-value pair can be searched from the determined shard area, and the found target key-value pair can be used as the key-value pair to be modified.
[0149] For example, continuing with the previous example, assuming that the determined shard region is region1, and shard region region1 stores 100 target key-value pairs, then search for a target key-value pair 3 that matches the key element contained in the acquired target key-value pair 3' from the 100 target key-value pairs stored in shard region region1, and use the target key-value pair 3 as the key-value pair to be modified.
[0150] By implementing an optional embodiment, when it is necessary to write a target key-value pair, the block height (modified to the target block height) and status (modified to the write status) corresponding to the shard area to be written by the target key value are first modified to indicate that the target key-value pair is currently being written and the shard area cannot be accessed. This not only avoids the impact of other data writing on the writing of the target key-value pair, thereby improving the accuracy of writing the target key-value pair, but also avoids erroneous reading of the target key-value pair, thereby improving the accuracy of related business execution, and is suitable for a wide range of application scenarios.
[0151] In one embodiment of the present application, after the process of replacing the block height contained in the key-value pair to be modified with the block height contained in the target key-value pair in S403, the following may also be included:
[0152] If it is detected that the block height contained in the target key-value pair stored in the determined shard area matches the block height of the shard area, the state of the shard area is modified to a normal state; wherein the normal state is used to indicate that the shard area can be accessed.
[0153] That is, in an optional embodiment, when the block height contained in the key-value pair to be modified is replaced with the block height contained in the target key-value pair, the block height contained in the target key-value pair stored in the determined sharding area can be scanned, and then the scanned block height is matched with the block height corresponding to the sharding area; wherein, if the scanned block height matches the block height corresponding to the sharding area, it indicates that the writing of the target key-value pair is completed (i.e., the replacement is completed), and the state of the sharding area can be modified to a normal state at this time; if the scanned block height does not match the block height corresponding to the sharding area, it indicates that the writing of the target key-value pair is not completed (i.e., the replacement is not completed), and you can continue to wait at this time, and if it is found that there is still no match after waiting for a preset period of time, it is determined that the writing of the target key-value pair has failed / error, and related operations for the writing failure / error can be performed.
[0154] For example, continuing with the previous example, normal is used to represent the normal state. If it is detected that the block height 100 contained in the target key-value pair stored in the determined shard region matches the block height region.targetHeigh:100 of the shard region, then region.status:applying is modified to region.status:normal.
[0155] By implementing an optional embodiment, when the target key-value pair is written successfully / correctly, the status corresponding to the shard area where the target key-value pair is written is modified in time (modified to a normal status) to indicate that the shard area can be accessed, thereby avoiding the phenomenon of being unable to access the shard area for a long time, improving the efficiency of related business execution, and being suitable for a wide range of application scenarios.
[0156] In one embodiment of the present application, after the process of replacing the block height contained in the key-value pair to be modified with the block height contained in the target key-value pair in S403, the following may also be included:
[0157] If it is detected that the target key-value pair fails to be written, the first blockchain node is controlled to restart;
[0158] After the first blockchain node is restarted, the target key-value pair corresponding to the block data contained in the block to be stored is re-obtained to complete the writing.
[0159] As described in the foregoing embodiment, a target key-value pair may fail to be written / an error may occur. If a target key-value pair failure to be written / an error is detected, the first blockchain node may be controlled to restart, and after the first blockchain node is restarted, the target key-value pair corresponding to the block data contained in the block to be stored may be re-obtained to complete the writing (i.e., jump back to S401).
[0160] Among them, in an optional embodiment, if a write failure / error in the target key-value pair is detected, a write failure / error information can be returned to the first blockchain node or other device (such as a management device of the first blockchain node, etc.), so that the write failure / error in the current target key-value pair can be quickly clarified through the write failure / error information; further, the first blockchain node can be caused to crash, thereby realizing the restart of the first blockchain node.
[0161] Among them, in an optional embodiment, after the first blockchain node is restarted, it can determine the block where writing fails / errors occur by scanning, and use the block where writing fails / errors occur as the block to be stored, and re-execute the target key-value pair corresponding to the block data contained in the block to be stored.
[0162] By implementing an optional embodiment, in the event of a target key-value pair write failure / error, the device is restarted to rewrite the target key-value pair, so that the target key-value pair can be successfully written to the shard area, which is suitable for a wide range of application scenarios.
[0163] It should be noted that Figure 6 For detailed description of S401 and S403, please refer to Figure 4 S401 and S403 shown are not described in detail here.
[0164] In the embodiment of the present application, during the process of writing the target key-value pair, the block height and status corresponding to the shard area where the target key-value pair is written are utilized to manage / control the target key-value pair writing process. The management / control is simple and applicable to a wide range of application scenarios.
[0165] In one embodiment of the present application, another blockchain-based data processing method is provided, and the blockchain-based data processing method can be executed by the first blockchain node 3011. Figure 7 As shown, the blockchain-based data processing method may further include S701 to S703 after S403 (or before S403, or after or before S401, or after or before S402).
[0166] In the embodiment of the present application, the storage area includes multiple shard areas, wherein the number of target key-value pairs stored in different shard areas may be the same or different.
[0167] For example, assume that the storage area includes a shard area region1 and a shard area region2, wherein the shard area region1 stores 100 target key-value pairs, and the shard area region2 stores 200 target key-value pairs.
[0168] Optionally, after storing the target key-value pair in the shard area, the storage-related attribute information of the shard area may be recorded; wherein the attribute information includes but is not limited to the currently stored minimum key element and maximum key element, the number of times the shard area is merged, the number of times it is split, etc.
[0169] S701 to S702 are described in detail as follows:
[0170] S701: If it is detected that a target shard area in which a target key-value pair is missing exists in multiple shard areas, the attribute information of the target shard area is obtained, where the attribute information includes a minimum key element and a maximum key element corresponding to the target key-value pair stored in the target shard area.
[0171] In the embodiment of the present application, the target shard area refers to a shard area in which target key-value pairs are lost among multiple shard areas, wherein the target key-value pairs lost by the target shard area may be all the target key-value pairs stored therein or part of the target key-value pairs stored therein.
[0172] In the embodiment of the present application, each shard area has attribute information. Therefore, when the existence of a target shard area is detected, the attribute information of the target shard area can be obtained, where the attribute information includes the minimum key element and the maximum key element corresponding to the target key-value pair stored in the target shard area.
[0173] For example, following the above example, please refer to Table 5, which is an example of attribute information.
[0174] Shard Region Minimum key element Maximum key element region1 mink11 maxk12 region2 mink21 maxk22
[0175] Table 5
[0176] Assuming that the target shard region is shard region region2, the minimum key element mink21 and the maximum key element maxk22 corresponding to the target key-value pair stored in shard region region2 can be obtained from Table 5.
[0177] S702: Generate a key element interval to be retrieved based on the minimum key element and the maximum key element.
[0178] In the embodiment of the present application, the minimum key element and the maximum key element corresponding to the target key-value pair stored in the target shard area are obtained, and then the key element interval to be retrieved can be generated based on the minimum key element and the maximum key element.
[0179] For example, continuing with the above example, the minimum key element corresponding to the target key-value pair stored in shard region region2 is mink21, and the maximum key element is maxk22, then the generated interval of key elements to be retrieved is [mink21, maxk22].
[0180] S703, obtaining a target key-value pair corresponding to the key element interval to be retrieved, and storing the obtained target key-value pair corresponding to the key element interval to be retrieved in the target shard area.
[0181] In the embodiment of the present application, a key element interval to be retrieved is obtained, and then a target key-value pair corresponding to the key element interval to be retrieved can be obtained, and the obtained target key-value pair corresponding to the key element interval to be retrieved is stored in the target shard area, thereby realizing the recovery of lost data in the target shard area.
[0182] To illustrate, for example, following the previous example, assume that the [target key-value pair 201, target key-value pair 202, target key-value pair 203 ... target key-value pair 400] corresponding to the key element interval [mink21, maxk22] to be retrieved is obtained. It can be understood that the target key-value pair 201 contains the key element mink21, and the target key-value pair 400 contains the key element maxk22, and the obtained [target key-value pair 201, target key-value pair 202, target key-value pair 203 ... target key-value pair 400] are stored in the target shard area region2.
[0183] In one embodiment of the present application, the storage area is located in the first blockchain node; the process of obtaining the target key-value pair corresponding to the key element interval to be retrieved in S703 may include:
[0184] Matching the latest block height in the first blockchain node with the latest block height in the second blockchain node; wherein the first blockchain node and the second blockchain node are used to maintain the same blockchain;
[0185] If the latest block height in the first blockchain node matches the latest block height in the second blockchain node, then obtaining the target key-value pair corresponding to the key element interval to be retrieved from the second blockchain node;
[0186] If the latest block height in the first blockchain node does not match the latest block height in the second blockchain node, the target key-value pair corresponding to the key element interval to be retrieved is obtained based on the target key-value pair stored in the second blockchain node, the block stored in the first blockchain node, and the block height interval corresponding to the key element interval to be retrieved.
[0187] That is, in an optional embodiment, if data loss occurs in the target shard area in the storage area of the first blockchain node, the data can be obtained from the storage area of the second blockchain node. When obtaining the lost data of the target shard area from the storage area of the second blockchain node, the relationship between the latest block height in the first blockchain node and the latest block height in the second blockchain node can be detected first, and then the lost data in the target shard area can be recovered based on the detected relationship.
[0188] The process of recovering the lost data in the target shard area based on the detected relationship may include the following two cases:
[0189] Case 1: If the latest block height in the first blockchain node matches the latest block height in the second blockchain node, the target key-value pair corresponding to the key element interval to be retrieved is obtained from the second blockchain node.
[0190] That is, in case 1, the latest block height in the first blockchain node matches the latest block height in the second blockchain node, which means that no new block corresponding to the target key-value pair is written during the time period when data loss occurs in the target shard area. Therefore, the target key-value pair stored on the first blockchain node is the same as the target key-value pair stored on the second blockchain node. At this time, the target key-value pair corresponding to the key element interval to be retrieved can be directly obtained from the second blockchain node.
[0191] Case 2: If the latest block height in the first blockchain node does not match the latest block height in the second blockchain node, the target key-value pair corresponding to the key element interval to be retrieved is obtained based on the target key-value pair stored in the second blockchain node, the block stored in the first blockchain node, and the block height interval corresponding to the key element interval to be retrieved.
[0192] That is, in situation 2, the latest block height in the first blockchain node does not match the latest block height in the second blockchain node, which means that during the time period when data loss occurs in the target shard area, a target key-value pair corresponding to a new block is written. Therefore, the target key-value pair stored on the first blockchain node is not the same as the target key-value pair stored on the second blockchain node. At this time, the target key-value pair corresponding to the key element interval to be retrieved can be obtained based on the target key-value pair stored in the second blockchain node, the block stored in the first blockchain node, and the block height interval corresponding to the key element interval to be retrieved.
[0193] Among them, the block stored in the first blockchain node in the optional embodiment refers to the complete block stored in the first blockchain node, that is, the block stored in the xxx.fdb file introduced in the aforementioned embodiment.
[0194] Among them, in an optional embodiment, the block height interval corresponding to the key element interval to be retrieved can be obtained from the attribute information of the target shard area.
[0195] For example, please refer to Table 6, which is another example of attribute information.
[0196] Shard Region Minimum key element + minimum block height Maximum key element + maximum block height region1 mink11, minHeight11 maxk12, maxHeight12 region2 mink21, minHeight21 maxk22, maxHeight22
[0197] Table 6
[0198] Continuing with the above example, as shown in Table 6, the block height interval corresponding to the key element interval [mink21, maxk22] to be retrieved is [minHeight21, maxHeight22].
[0199] It is understandable that in case 2, the latest block height in the first blockchain node does not match the latest block height in the second blockchain node, including two cases:
[0200] Case 2.1: The latest block height in the first blockchain node is greater than the latest block height in the second blockchain node.
[0201] In one embodiment of the present application, based on the target key-value pair stored by the second blockchain node, the block stored by the first blockchain node, and the block height interval corresponding to the key element interval to be retrieved, the process of obtaining the target key-value pair corresponding to the key element interval to be retrieved may include:
[0202] If the latest block height in the first blockchain node is greater than the latest block height in the second blockchain node, obtaining a target key-value pair whose key element is in the interval of the key element to be retrieved from the second blockchain node;
[0203] Detect the remaining key elements in the key element interval to be retrieved except the key elements contained in the acquired target key-value pair;
[0204] Based on the block height interval corresponding to the key element interval to be retrieved and the blocks stored by the first blockchain node, a target key-value pair corresponding to the detected key element is calculated.
[0205] That is, in situation 2.1, the latest block height in the first blockchain node is greater than the latest block height in the second blockchain node, which means that the target key-value pairs stored on the first blockchain node are newer than the target key-value pairs stored on the second blockchain node. Therefore, only part of the target key-value pairs corresponding to the key element interval to be retrieved may be obtained from the second blockchain node, and the remaining target key-value pairs can be recalculated based on the blocks stored in the first blockchain node.
[0206] For example, continuing with the previous example, the key element interval [mink21, maxk22] to be retrieved corresponds to 200 target key-value pairs, and the second blockchain node may only store the first 150 target key-value pairs of these 200 target key-value pairs. The remaining 50 target key-value pairs can be recalculated through the block height interval [minHeight21, maxHeight22] corresponding to the key element interval [mink21, maxk22] to be retrieved and the blocks stored in the first blockchain node.
[0207] Case 2.2: The latest block height in the first blockchain node is less than the latest block height in the second blockchain node.
[0208] That is, in situation 2.2, the latest block height in the first blockchain node is less than the latest block height in the second blockchain node, which means that the target key-value pair stored on the second blockchain node is newer than the target key-value pair stored on the first blockchain node. At this time, the target key-value pair corresponding to the key element interval to be retrieved can be obtained from the second blockchain node.
[0209] Among them, in the optional embodiment, since the target key-value pair stored on the second blockchain node is newer than the target key-value pair stored on the first blockchain node; therefore, in order to ensure the accuracy of the retrieved data, in one embodiment of the present application, based on the target key-value pair stored by the second blockchain node, the block stored by the first blockchain node, and the block height interval corresponding to the key element interval to be retrieved, the process of obtaining the target key-value pair corresponding to the key element interval to be retrieved may include:
[0210] If the latest block height in the first blockchain node is less than the latest block height in the second blockchain node, determining a target key-value pair that matches the minimum key element in the key element interval to be retrieved from the target key-value pairs stored in the second blockchain node;
[0211] Starting from the determined target key-value pair, detect the size relationship between the block height corresponding to the maximum key element in the key element interval to be retrieved and the block height contained in the target key-value pair to obtain a detection result;
[0212] Based on the detection result, the block height interval corresponding to the key element interval to be retrieved, and the block stored by the first blockchain node, a target key-value pair corresponding to the key element interval to be retrieved is obtained.
[0213] That is, in situation 2.2, the latest block height in the first blockchain node is smaller than the latest block height in the second blockchain node, and the target key-value pair that matches the minimum key element in the key element interval to be retrieved can be determined from the target key-value pair stored in the second blockchain node, and starting from the determined target key-value pair, the relationship between the block height corresponding to the maximum key element in the key element interval to be retrieved and the block height contained in the target key-value pair is detected to obtain the detection result, and then based on the detection result, the block height interval corresponding to the key element interval to be retrieved, and the block stored in the first blockchain node, the target key-value pair corresponding to the key element interval to be retrieved is obtained.
[0214] For example, following the above example, it is assumed that a target key-value pair 101 that matches the minimum key element mink21 of the key element interval [mink21, maxk22] to be retrieved is determined from the target key-value pairs stored in the second blockchain node.
[0215] It can be understood that the second blockchain node stores the target key-value pairs arranged in sequence, and then starting from the determined target key-value pair 101, first detect the size relationship between the block height maxHeight22 corresponding to the maximum key element maxk22 in the key element interval [mink21, maxk22] to be retrieved and the block height value.Height contained in the target key-value pair 101, and then detect the size relationship between the block height maxHeight22 corresponding to the maximum key element maxk22 in the key element interval [mink21, maxk22] to be retrieved and the block height value.Height contained in the target key-value pair 102, and then detect the size relationship between the block height maxHeight22 corresponding to the maximum key element maxk22 in the key element interval [mink21, maxk22] to be retrieved and the block height value.Height contained in the target key-value pair 103, and so on, until the preset stop condition is reached. Optionally, the preset stop condition may be reaching a preset number of detections or reaching a preset detection duration, etc., wherein the preset number of detections may be set based on the number of target key-value pairs stored in the target shard area.
[0216] Then, based on the obtained detection result, the block height interval [minHeight21, maxHeight22] corresponding to the key element interval [mink21, maxk22] to be retrieved, and the block stored by the first blockchain node, the target key-value pair corresponding to the key element interval [mink21, maxk22] to be retrieved is obtained.
[0217] In one embodiment of the present application, based on the detection result, the block height interval corresponding to the key element interval to be retrieved, and the block stored by the first blockchain node, the process of obtaining the target key-value pair corresponding to the key element interval to be retrieved may include:
[0218] If the detection result indicates that the block height corresponding to the maximum key element in the key element interval to be retrieved is greater than or equal to the block height contained in the target key-value pair, then the target key-value pair is obtained from the second blockchain node;
[0219] If the detection result indicates that the block height corresponding to the maximum key element in the key element interval to be retrieved is less than the block height contained in the target key-value pair, the target key-value pair is calculated based on the block height interval corresponding to the key element interval to be retrieved and the blocks stored in the first blockchain node.
[0220] Among them, in an optional embodiment, if the detection result indicates that the block height corresponding to the maximum key element in the key element interval to be retrieved is greater than or equal to the block height contained in the target key-value pair, the target key-value pair can be directly obtained from the second blockchain node.
[0221] For example, continuing with the previous example, if maxHeight22≥value.Height, the target key-value pair is obtained from the second blockchain node.
[0222] Among them, in an optional embodiment, if the detection result indicates that the block height corresponding to the maximum key element in the key element interval to be retrieved is smaller than the block height contained in the target key-value pair, then the target key-value pair can be calculated based on the block height interval corresponding to the key element interval to be retrieved and the blocks stored in the first blockchain node.
[0223] For example, continuing with the previous example, if maxHeight22<value.Height, then based on the block height interval [minHeight21, maxHeight22] corresponding to the key element interval [mink21, maxk22] to be retrieved, and the block stored by the first blockchain node, the target key-value pair is calculated.
[0224] It should be noted that Figure 7 For detailed description of S401 to S403, please refer to Figure 4 S401 to S403 shown are not described in detail here.
[0225] In the embodiment of the present application, the lost data in the target shard area can be easily and accurately retrieved through the attribute information of the target shard area, thereby realizing the tracing of lost data and ensuring the security of the data.
[0226] In one embodiment of the present application, another blockchain-based data processing method is provided, and the blockchain-based data processing method can be executed by the first blockchain node 3011. Figure 8 As shown, the blockchain-based data processing method may further include S801 to S802 after S403 (or before S403, or after or before S401, or after or before S402).
[0227] In the embodiment of the present application, the storage area includes multiple shard areas, and each shard area stores multiple target key-value pairs.
[0228] S801 to S802 are described in detail as follows:
[0229] S801: Receive a shard region merging request, where the shard region merging request includes identification information corresponding to at least two shard regions.
[0230] S802, based on identification information corresponding to the at least two shard areas, merge the at least two shard areas to obtain a merged shard area; wherein the number of target key-value pairs stored in the merged shard area is equal to the total number of target key-value pairs stored in the at least two shard areas.
[0231] In the embodiment of the present application, if a shard region merge request is received, it indicates that there is a demand for shard region merge. At this time, based on the identification information corresponding to at least two shard regions contained in the shard region merge request, at least two shard regions can be merged to obtain a merged shard region. It can be understood that the number of target key-value pairs stored in the merged shard region is equal to the total number of target key-value pairs stored in the at least two shard regions.
[0232] In the embodiment of the present application, the identification information of the shard area includes but is not limited to the number and name of the shard area.
[0233] It should be noted that Figure 8 For detailed description of S401 to S403, please refer to Figure 4 S401 to S403 shown are not described in detail here.
[0234] In the embodiment of the present application, when a shard area merging request is received, the merging of shard areas can be achieved simply and accurately, and is suitable for a wide range of application scenarios.
[0235] In one embodiment of the present application, another blockchain-based data processing method is provided, and the blockchain-based data processing method can be executed by the first blockchain node 3011. Fig. 9 As shown, the blockchain-based data processing method may further include S901 to S902 after S403 (or before S403, or after or before S401, or after or before S402).
[0236] In the embodiment of the present application, the storage area includes multiple shard areas, and each shard area stores multiple target key-value pairs.
[0237] S901 to S902 are described in detail as follows:
[0238] S901: Receive a shard region segmentation request, where the shard region segmentation request includes identification information corresponding to a shard region to be segmented.
[0239] S902, based on the identification information corresponding to the shard area to be divided, divide the shard area to be divided to obtain at least two shard areas; wherein the total number of target key-value pairs stored in the at least two shard areas is equal to the number of target key-value pairs stored in the shard area to be divided.
[0240] In the embodiment of the present application, if a shard region splitting request is received, it indicates that there is currently a demand for shard region splitting. At this time, the shard region to be split can be split based on the identification information corresponding to the shard region to be split contained in the shard region splitting request to obtain at least two shard regions. It can be understood that the total number of target key-value pairs stored in the at least two shard regions is equal to the number of target key-value pairs stored in the shard region to be split.
[0241] In the embodiment of the present application, the identification information of the shard area includes but is not limited to the number and name of the shard area.
[0242] It should be noted that Fig. 9 For detailed description of S401 to S403, please refer to Figure 4 S401 to S403 shown are not described in detail here.
[0243] In the embodiment of the present application, when a shard region segmentation request is received, the segmentation of the shard region can be achieved simply and accurately, and is suitable for a wide range of application scenarios.
[0244] In one embodiment of the present application, another blockchain-based data processing method is provided, and the blockchain-based data processing method can be executed by the first blockchain node 3011. Fig.10 As shown, the blockchain-based data processing method may further include S1001 to S1002 after S403.
[0245] In the embodiment of the present application, the storage area includes multiple shard areas, and each shard area stores multiple target key-value pairs.
[0246] S1001 to S1002 are described in detail as follows:
[0247] S1001, receiving a shard area transfer request, the shard area transfer request includes identification information corresponding to the shard area to be transferred out, and identification information corresponding to the blockchain node to be transferred in.
[0248] S1002, based on the identification information corresponding to the shard area to be transferred out, transfer the shard area to be transferred out to a blockchain node that matches the identification information corresponding to the blockchain node to be transferred in; wherein the number of target key-value pairs stored in the shard area before and after the transfer is the same.
[0249] In the embodiment of the present application, if a shard region transfer request is received, it indicates that there is a demand for shard region transfer. At this time, based on the identification information corresponding to the shard region to be transferred out contained in the shard region transfer request and the identification information corresponding to the blockchain node to be transferred in, the shard region to be transferred out can be transferred to a blockchain node that matches the identification information corresponding to the blockchain node to be transferred in. It is understandable that the number of target key-value pairs stored in the shard region before and after the transfer is the same.
[0250] The identification information of the sharding area in the embodiment of the present application includes but is not limited to the number and name of the sharding area. The identification information of the blockchain node in the embodiment of the present application includes but is not limited to the number and name of the blockchain node.
[0251] It should be noted that Fig.10 For detailed description of S401 to S403, please refer to Figure 4 S401 to S403 shown are not described in detail here.
[0252] In the embodiment of the present application, when a shard area transfer request is received, the transfer of the shard area can be realized simply and accurately, and is suitable for a wide range of application scenarios.
[0253] The following is a detailed description of a specific scenario of an embodiment of the present application:
[0254] First, see Fig.11 The overall architecture in the embodiment of the present application mainly includes:
[0255] 1.1. Node: a single blockchain node.
[0256] Exemplarily, Node includes consensus and store, where consensus is the consensus module in Node, which is mainly used to complete block generation and verification in the blockchain consensus process, and store is the storage module in Node, which is mainly used to store blocks sent by the consensus module.
[0257] 1.2. bfdb: A block database used to store blocks in ChainMaker (a blockchain provided by a certain enterprise), where bfdb uses xxx.fdb files to store blocks.
[0258] Exemplarily, the file name of the xxx.fdb file is set to the block height of the first block stored in the file after conversion according to the file name rule. This setting allows the user to see the xxx.fdb file where the first block in a batch of consecutive blocks is located through the file; for example, the xxx.fdb file contains 5 blocks with block heights of 0, 1, 2, 3, and 4, then the file name can be 00000000000000000000.fdb.
[0259] For example, a single xxx.fdb file storing blocks has a certain size limit. ChainMaker limits it based on the size of xxx.fdb, for example, each xxx.fdb is limited to 1024MB, regardless of how many blocks are stored; or a single xxx.fdb file storing blocks can also set the number of blocks stored, for example, each xxx.fdb file stores 100 blocks; in actual applications, the number of blocks in a single xxx.fdb file can be flexibly adjusted according to the specific application scenario.
[0260] For example, the xxx.fdb file will have corresponding index information, where the index information is stored in kvdb (also called bfkv, bfkv will be described in detail below), and the structure of the index information is as follows:
[0261] type Index struct {
[0262] / / file name xxx.fdb file name
[0263] FileName string
[0264] / / Offset in file The offset of the block in the xxx.fdb file
[0265] Offset uint64`
[0266] / / The length of the data length block in the xxx.fdb file
[0267] ByteLen uint64
[0268] }
[0269] For example, the xxx.fdb file contains 10 blocks with block heights of 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9. Suppose it is divided into two xxx.fdb files, then the inclusion relationship between xxx.fdb and blocks can be shown in Table 7:
[0270] file name Contains blocks Contains object index 00000000000000000000.fdb 0、1、2、3、4 block, blockHeader, tx… 00000000000000000005.fdb 5、6、7、8、9 block, blockHeader, tx…
[0271] Table 7
[0272] It can be understood that an archive file (ie, xxx.fdb file) can be generated based on the included blocks, and an index file (ie, xxx.ldb file) can be generated based on the included object indexes.
[0273] See also Fig.12 , which is a schematic diagram of the block in the xxx.fdb file.
[0274] like Fig.12 As shown, the serialized texts of multiple blocks constitute the xxx.fdb file, that is, a single xxx.fdb file includes the serialized texts of multiple blocks, wherein the serialized text of each block includes the serialized text of the block header, the serialized text of the transaction, and the serialized text of other objects in the block (such as read-write sets, etc.).
[0275] See also Fig.13 , schematic diagram of archive file and index file storage.
[0276] like Fig.13 As shown, the bfdb file directory includes multiple xxx.fdb files, and the xxx.fdb.END file is the xxx.fdb file being written. When the size of the xxx.fdb.END file being written reaches the specified size, it is renamed to the xxx.fdb file, and a new xxx.fdb.END file is generated at the same time. The Blockdb file directory includes multiple xxx.ldb files. For example, the folder corresponding to the Blockdb file directory uses leveldb (since rocksdb is an optimized version of leveldb, rocksdb can be used preferentially in the embodiments of this application).
[0277] 1.3. PD (placement drive): A service used to coordinate the interaction between Node and multiple bfkv. It is mainly used for: 1. It can start a cluster composed of multiple PDs and coordinated by the raft algorithm (a data consensus algorithm that ensures data consistency on distributed multiple nodes) to provide external services; 2. PD records the metadata (index) of the KV data shards, and ensures the security and availability of metadata and the consistency of index data through multiple PDs and the raft algorithm; 3. Coordinate the collaboration between multiple bfkvs.
[0278] 1.4, bfkv: The database where the node's block index data (i.e., index files) and status data are ultimately stored. The data is ultimately stored in the underlying rocksdb in bfkv. In the upper layer of bfkv, all keys in rocksdb are grouped according to preset rules (such as the number of keys or the disk space occupied by key / value, etc.). Each group corresponds to a shard area (i.e., Fig.11 It can be understood that bfkv manages data in units of regions.
[0279] It should be noted that Fig.11The overall process is as follows: Node's consensus sends the consensus-passed block to Node's store, Node's store stores the block in bfdb, and then converts the index data and status data in bfdb into kv data (i.e., target key-value pairs). After locating the bfkv where the key is located through pd, the kv data is pushed to the corresponding bfkv.
[0280] See also Fig.14 In the embodiment of the present application, the kv data is a triple (key, height, value), such as Fig.14 As shown, the key is in one field, and the height and value are in another field; the structure of the kv data is as follows:
[0281] type Data struct {
[0282] Key[]byte / / key key element
[0283] Value[]byte / / value element
[0284] Height uint64 / / The block height changed this time
[0285] }
[0286] It is understandable that when the value changes, the old value and height will be overwritten, so that the latest kv data is stored in the embodiment of the present application, saving storage space to a great extent.
[0287] Secondly, based on Fig.11 The overall architecture shown in the figure introduces the relevant contents involving bfkv in detail.
[0288] 2. Region: The basic unit of data sharding management, which is a logical concept. The meta information of the region is stored in the pd. The structure of the region is as follows:
[0289] type Region struct{
[0290] Id uint64
[0291] / / Region key range[start_key, end_key) shard key element interval
[0292] StartKey[]byte / / Minimum key element of the slice
[0293] EndKey[]byte / / The maximum key element of the shard
[0294] RegionEpoch*RegionEpoch / / Related to the number of merges and splits
[0295] Peer*Peer / / peer information of bfkv
[0296] }
[0297] type RegionEpoch struct{
[0298] / / Conf change version, auto increment when add or remove peer
[0299] uint64 conf_ver = 1;
[0300] / / Region version, auto increment when split or merge
[0301] uint64 version = 2;
[0302] / / all keys min(maxHeight)in region; the smallest key.minHeight among all keys in this shard
[0303] uint64 minHeight = 3;
[0304] / / all keys max(maxHeight)in region; the largest key.maxHeight among all keys in this shard
[0305] uint64 maxHeight = 4;
[0306] / / target modify height; the smallest key.maxHeight among all keys in this slice
[0307] uint64 targetHeight = 5;
[0308] }
[0309] See also Fig.15 , is a schematic diagram of region state changes; where:
[0310] Normal: The region is in normal state and can be accessed and modified.
[0311] Applying: The region is writing kv data and needs to wait until the writing is completed before reading the kv data.
[0312] Left: has been merged or split. The region meta can be deleted later, but the kv data in rocskdb is not deleted (this is because the merge or restore occurs in the same bfkv. You only need to delete the region, and the kv data in rocskdb remains unchanged).
[0313] Tombstone: has been transferred. You can delete the kv data in region meta and rocksdb later (this is because the transfer occurs in different bfkvs. You need to delete all related data in the bfkv before the transfer to avoid taking up unnecessary storage space).
[0314] 3. Region management:
[0315] 3.1. Region merging: Merge two regions with consecutive keys into a larger region. Take merging region1 and region2 into a larger region1 as an example.
[0316] 3.1.1. Please refer to Figure 16-1 , change the state of region2 to Left and update the state in pd.
[0317] 3.1.2. Please refer to Figure 16-2 , merge the kv data of region2 into region1. After the merge is completed, change the status of region2 to Normal and update the status to pd.
[0318] 3.2, Region Split: Split a large region into two consecutive regions, taking the example of splitting region3 into region3 and region4. Fig.17 , the split point is between key:kr3+nm-1 and kr3+nm.
[0319] 3.3. Region transfer: transfer a region from one bfkv to another bfkv, taking moving region3 from bfkv1 to bfkv2 as an example.
[0320] 3.3.1. Please refer to Figure 18-1 , which is the state before region transfer.
[0321] 3.3.2. Please refer to Figure 18-2, create region3' on bfkv2 based on region3 on bfkv1, change the status of region3' to Applying, and update the status to pd, then start synchronizing the kv data of bfkv1.region3 to bfkv2.region3'.
[0322] 3.3.3. Please refer to Figure 18-3 , wait for the synchronization of kv data of bfkv1.region3 to bfkv2.region3` to be completed. If there is an interruption or failure in the middle, change the state of region3' to Tombstone, and then delete the relevant information of region3' on pd and the relevant data within the range of region3' on bfkv2.
[0323] 3.3.4. Please refer to Figure 18-4 After the kv data synchronization is completed, the state of region3' is changed to Normal, the state of region3 is changed to Tombstone, and then the relevant information of region3 on pd and the relevant data within the range of region3 on bfkv1 are deleted.
[0324] 3.4. Region recovery: Recover the kv data in the damaged or lost region (may be due to damage to part of the disk track or server damage). Based on the above introduction, the original data of all kv data in bfkv can be found in bfdb, and other blockchain nodes also have complete data, but the kv data will change during the growth of the block. Take the region3 on Node1 that needs to be restored as an example.
[0325] 3.4.1. Please refer to Figure 19-1 , which is a status to be repaired.
[0326] 3.4.2. Since the block heights of Node1 and Node2 may be different, different solutions can be adopted according to the situation:
[0327] 3.4.2.1. Please refer to Figure 19-2 , Node1 and Node2 are highly consistent, and the kv data of Node2 can be directly stored in Node1.
[0328] 3.4.2.2. Please refer to Figure 19-3 , Node1 is higher than Node2. At this time, based on the data on Node2 and the blocks in bfdb, the data that should exist in region3 on Node1 can be calculated according to the block index and status data.
[0329] 3.4.2.3. Please refer to Figure 19-4Node1 is lower than Node2 in height. At this time, based on the data on Node2 and the blocks in bfdb, the data that should exist on Node1 can be calculated according to the block index and status data. When rengion3.maxHeight22≥value.Height, it can be directly stored, and when rengion3.maxHeight22<value.Height, it needs to be calculated.
[0330] 4. Submission Management, please refer to Fig. 20 :
[0331] 4.1. Determine the region to which the kv data to be submitted belongs, modify region.targetHeight to the block height of the block to be stored and submitted this time, modify the state of the region to Applying, and update the state to pd.
[0332] 4.2. Write the kv data to the region corresponding to bfkv, and update region.maxHeight after writing. pd scans the changed region, and if region.maxHeight == region.targetHeight, it indicates that the region is written and the state of the region is changed to Normal. After all regions become Normal, it indicates that the kv data is written.
[0333] 4.3. If an error occurs during the kv data writing process, an error message will be returned, and the node will be guided to restart after crashing. When the node restarts, it will determine whether the kv data of the previous block has been written successfully by scanning the status of the region. If not, continue writing.
[0334] It should be noted that some of the introductions in the embodiments of the present application refer to the aforementioned embodiments and will not be repeated here.
[0335] In the embodiment of the present application, the target key-value pair for the same key element is only stored once (or the latest value element and block height of the key element are stored), which saves storage space to a great extent compared to storing multiple key-value pairs corresponding to the same key element in the related art; at the same time, since the target key-value pair includes the block height, the damaged / lost data can be easily and accurately retrieved through the block height, thereby ensuring the security of the data.
[0336] Fig.21 FIG. 1 is a block diagram of a data processing device based on blockchain, which is shown in an embodiment of the present application. Fig.21 As shown, the blockchain-based data processing device includes:
[0337] The acquisition module 2101 is configured to acquire a target key-value pair corresponding to the block data contained in the block to be stored; wherein the target key-value pair includes a key element, a value element, and a block height of the block to be stored;
[0338] The determination module 2102 is configured to determine, based on the key element contained in the target key-value pair, a key-value pair to be modified that matches the key element contained in the target key-value pair from a storage area;
[0339] The replacement module 2103 is configured to replace the value element contained in the key-value pair to be modified with the value element contained in the target key-value pair, and to replace the block height contained in the key-value pair to be modified with the block height contained in the target key-value pair.
[0340] In one embodiment of the present application, based on the above solution, the acquisition module 2101 is specifically configured as follows:
[0341] Converting the block data contained in the block to be stored into an initial key-value pair, wherein the initial key-value pair includes a key element and a value element;
[0342] Obtaining the block height of the block to be stored;
[0343] The block height is associated with the initial key-value pair to generate the target key-value pair.
[0344] In one embodiment of the present application, based on the above solution, the acquisition module 2101 is further specifically configured as follows:
[0345] Encapsulating the key element contained in the initial key-value pair in a first field;
[0346] Encapsulate the block height and the value element contained in the initial key-value pair in a second field; wherein the position of the block height in the second field is before the position of the value element contained in the initial key-value pair;
[0347] The first field and the second field are combined to generate the target key-value pair.
[0348] In one embodiment of the present application, based on the above solution, the replacement module 2103 is specifically configured as follows:
[0349] If it is detected that the value element contained in the target key-value pair is different from the value element contained in the key-value pair to be modified, the value element contained in the key-value pair to be modified is replaced by the value element contained in the target key-value pair.
[0350] In one embodiment of the present application, based on the above solution, the replacement module 2103 is specifically configured as follows:
[0351] If it is detected that the block height contained in the target key-value pair is different from the block height contained in the key-value pair to be modified, the block height contained in the key-value pair to be modified is replaced by the block height contained in the target key-value pair.
[0352] In one embodiment of the present application, based on the above solution, the storage area includes multiple shard areas; the determination module 2102 is specifically configured as follows:
[0353] Based on the key element contained in the target key-value pair, determining a sharding area for storing the target key-value pair;
[0354] Modify the block height corresponding to the determined sharding area to the block height contained in the target key-value pair, and modify the state corresponding to the determined sharding area to a write state; wherein the write state is used to indicate that the determined sharding area cannot be accessed;
[0355] A target key-value pair matching the key element contained in the target key-value pair is searched from the determined shard area, and the searched target key-value pair is used as the key-value pair to be modified.
[0356] In one embodiment of the present application, based on the above solution, the device further includes a modification module configured to:
[0357] If it is detected that the block height contained in the target key-value pair stored in the determined shard area matches the block height of the shard area, the state of the shard area is modified to a normal state; wherein the normal state is used to indicate that the shard area can be accessed.
[0358] In one embodiment of the present application, based on the above solution, the method is performed by a first blockchain node, and the device further includes:
[0359] A restart module, configured to control the first blockchain node to restart if it is detected that the target key-value pair fails to be written;
[0360] The re-acquisition module is configured to re-acquire the target key-value pair corresponding to the block data contained in the block to be stored after the first blockchain node is restarted to complete the writing.
[0361] In one embodiment of the present application, based on the above solution, the storage area includes multiple shard areas, each shard area stores multiple target key-value pairs; the device also includes a recovery module configured to:
[0362] If it is detected that there is a target sharding area where the target key-value pair is missing among the multiple sharding areas, acquiring attribute information of the target sharding area, the attribute information including the minimum key element and the maximum key element corresponding to the target key-value pair stored in the target sharding area;
[0363] Generate a key element interval to be retrieved based on the minimum key element and the maximum key element;
[0364] The target key-value pair corresponding to the key element interval to be retrieved is obtained, and the target key-value pair corresponding to the key element interval to be retrieved is stored in the target shard area.
[0365] In one embodiment of the present application, based on the above solution, the storage area is located in the first blockchain node; the recovery module is specifically configured as follows:
[0366] Matching the latest block height in the first blockchain node with the latest block height in the second blockchain node; wherein the first blockchain node and the second blockchain node are used to maintain the same blockchain;
[0367] If the latest block height in the first blockchain node matches the latest block height in the second blockchain node, obtaining a target key-value pair corresponding to the key element interval to be retrieved from the second blockchain node;
[0368] If the latest block height in the first blockchain node does not match the latest block height in the second blockchain node, the target key-value pair corresponding to the key element interval to be retrieved is obtained based on the target key-value pair stored in the second blockchain node, the block stored in the first blockchain node, and the block height interval corresponding to the key element interval to be retrieved.
[0369] In one embodiment of the present application, based on the above solution, the recovery module is further specifically configured as follows:
[0370] If the latest block height in the first blockchain node is greater than the latest block height in the second blockchain node, obtaining a target key-value pair whose key element is in the range of key elements to be retrieved from the second blockchain node;
[0371] Detecting the remaining key elements in the key element interval to be retrieved except the key elements contained in the acquired target key-value pair;
[0372] Based on the block height interval corresponding to the key element interval to be retrieved and the blocks stored by the first blockchain node, a target key-value pair corresponding to the detected key element is calculated.
[0373] In one embodiment of the present application, based on the above solution, the recovery module is further specifically configured as follows:
[0374] If the latest block height in the first blockchain node is less than the latest block height in the second blockchain node, determining a target key-value pair that matches the minimum key element in the key element interval to be retrieved from the target key-value pairs stored in the second blockchain node;
[0375] Starting from the determined target key-value pair, detecting the size relationship between the block height corresponding to the maximum key element in the key element interval to be retrieved and the block height contained in the target key-value pair, and obtaining a detection result;
[0376] Based on the detection result, the block height interval corresponding to the key element interval to be retrieved, and the block stored by the first blockchain node, a target key-value pair corresponding to the key element interval to be retrieved is obtained.
[0377] In one embodiment of the present application, based on the above solution, the recovery module is further specifically configured as follows:
[0378] If the detection result indicates that the block height corresponding to the maximum key element in the key element interval to be retrieved is greater than or equal to the block height contained in the target key-value pair, then obtaining the target key-value pair from the second blockchain node;
[0379] If the detection result indicates that the block height corresponding to the maximum key element in the key element interval to be retrieved is less than the block height contained in the target key-value pair, then the target key-value pair is calculated based on the block height interval corresponding to the key element interval to be retrieved and the blocks stored in the first blockchain node.
[0380] In one embodiment of the present application, based on the above solution, the storage area includes multiple shard areas, each shard area stores multiple target key-value pairs; the device also includes a merging module configured to:
[0381] Receive a shard region merging request, where the shard region merging request includes identification information corresponding to at least two shard regions;
[0382] Based on the identification information corresponding to the at least two shard areas, the at least two shard areas are merged to obtain a merged shard area; wherein the number of target key-value pairs stored in the merged shard area is equal to the total number of target key-value pairs stored in the at least two shard areas.
[0383] In one embodiment of the present application, based on the above solution, the storage area includes multiple shard areas, each shard area stores multiple target key-value pairs; the device also includes a segmentation module, configured to:
[0384] Receive a shard region segmentation request, where the shard region segmentation request includes identification information corresponding to the shard region to be segmented;
[0385] Based on the identification information corresponding to the shard area to be divided, the shard area to be divided is divided to obtain at least two shard areas; wherein the total number of target key-value pairs stored in the at least two shard areas is equal to the number of target key-value pairs stored in the shard area to be divided.
[0386] In one embodiment of the present application, based on the above solution, the storage area includes multiple shard areas, each shard area stores multiple target key-value pairs; the device also includes a transfer module configured to:
[0387] Receive a shard region transfer request, wherein the shard region transfer request includes identification information corresponding to the shard region to be transferred out and identification information corresponding to the blockchain node to be transferred in;
[0388] Based on the identification information corresponding to the shard area to be transferred out, the shard area to be transferred out is transferred to a blockchain node that matches the identification information corresponding to the blockchain node to be transferred in; wherein the number of target key-value pairs stored in the shard area before and after the transfer is the same.
[0389] It should be noted that the apparatus provided in the aforementioned embodiment and the method provided in the aforementioned embodiment belong to the same concept, wherein the specific manner in which each module and unit performs the operation has been described in detail in the method embodiment.
[0390] An embodiment of the present application also provides an electronic device, comprising: one or more processors; and a memory for storing one or more programs, wherein when the one or more programs are executed by the one or more processors, the electronic device implements the blockchain-based data processing method as described above.
[0391] Fig. 22 It is a schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application.
[0392] It should be noted that Fig. 22 The computer system 2200 of the electronic device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.
[0393] like Fig. 22As shown, the computer system 2200 includes a central processing unit (CPU) 2201, which can perform various appropriate actions and processes according to the program stored in the read-only memory (ROM) 2202 or the program loaded from the storage part 2208 to the random access memory (RAM) 2203, such as executing the method in the above embodiment. In the RAM 2203, various programs and data required for system operation are also stored. The CPU 2201, ROM 2202 and RAM 2203 are connected to each other through a bus 2204. An input / output (I / O) interface 2205 is also connected to the bus 2204.
[0394] The following components are connected to the I / O interface 2205: an input section 2206 including a keyboard, a mouse, etc.; an output section 2207 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 2208 including a hard disk, etc.; and a communication section 2209 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 2209 performs communication processing via a network such as the Internet. A drive 2210 is also connected to the I / O interface 2205 as needed. A removable medium 2211, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 2210 as needed so that a computer program read therefrom is installed into the storage section 2208 as needed.
[0395] In particular, according to an embodiment of the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present application includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 2209, and / or installed from the removable medium 2211. When the computer program is executed by the central processing unit (CPU) 2201, various functions defined in the system of the present application are executed.
[0396] It should be noted that the computer-readable medium shown in the embodiment of the present application may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. Computer-readable media may be, for example, a system, device or device of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples of computer-readable media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable medium may be any tangible medium containing or storing a program, which may be used by an instruction execution system, device or device or used in combination with it. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, wherein a computer-readable computer program is carried. This propagated data signal may take a variety of forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. A computer program contained on a computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0397] The flowchart and block diagram in the accompanying drawings illustrate the possible architecture, functions and operations of the system, method and computer program product according to various embodiments of the present application. Wherein, each box in the flowchart or block diagram can represent a module, a program segment, or a part of the code, and the above-mentioned module, program segment, or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order than the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flowchart, and the combination of boxes in the block diagram or flowchart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0398] The units involved in the embodiments described in this application may be implemented by software or hardware, and the units described may also be set in a processor. The names of these units do not, in some cases, constitute limitations on the units themselves.
[0399] Another aspect of the present application further provides a computer-readable medium having a computer program stored thereon, which implements the blockchain-based data processing method as described above when the computer program is executed by a processor. The computer-readable medium may be included in the electronic device described in the above embodiment, or may exist independently without being assembled into the electronic device.
[0400] Another aspect of the present application further provides a computer program product or a computer program, which includes a computer instruction stored in a computer-readable medium. The processor of the computer device reads the computer instruction from the computer-readable medium, and the processor executes the computer instruction, so that the computer device executes the data processing method based on blockchain provided in each of the above embodiments.
[0401] The above content is only a preferred exemplary embodiment of the present application and is not intended to limit the implementation scheme of the present application. A person skilled in the art can easily make corresponding changes or modifications based on the main concept and spirit of the present application. Therefore, the scope of protection of the present application shall be based on the scope of protection required by the claims.
Claims
1. A data processing method based on blockchain, characterized in that: include: Obtaining a target key-value pair corresponding to the block data contained in the block to be stored; wherein the target key-value pair includes a key element, a value element, and a block height of the block to be stored; Based on the key element contained in the target key-value pair, determining from a storage area a key-value pair to be modified that matches the key element contained in the target key-value pair; The value element contained in the to-be-modified key-value pair is replaced with the value element contained in the target key-value pair, and the block height contained in the to-be-modified key-value pair is replaced with the block height contained in the target key-value pair.
2. The method according to claim 1, characterized in that The step of obtaining a target key-value pair corresponding to the block data contained in the block to be stored includes: Converting the block data contained in the block to be stored into an initial key-value pair, wherein the initial key-value pair includes a key element and a value element; Obtaining the block height of the block to be stored; The block height is associated with the initial key-value pair to generate the target key-value pair.
3. The method according to claim 2, characterized in that The associating the block height with the initial key-value pair to generate the target key-value pair includes: Encapsulating the key element contained in the initial key-value pair in a first field; Encapsulate the block height and the value element contained in the initial key-value pair in a second field; wherein the position of the block height in the second field is before the position of the value element contained in the initial key-value pair; The first field and the second field are combined to generate the target key-value pair.
4. The method according to claim 1, characterized in that The replacing the value element contained in the to-be-modified key-value pair with the value element contained in the target key-value pair includes: If it is detected that the value element contained in the target key-value pair is different from the value element contained in the key-value pair to be modified, the value element contained in the key-value pair to be modified is replaced with the value element contained in the target key-value pair; The replacing the block height contained in the to-be-modified key-value pair with the block height contained in the target key-value pair includes: If it is detected that the block height contained in the target key-value pair is different from the block height contained in the key-value pair to be modified, the block height contained in the key-value pair to be modified is replaced by the block height contained in the target key-value pair.
5. The method according to any one of claims 1 to 4, characterized in that The storage area includes a plurality of shard areas; and based on the key element contained in the target key-value pair, determining from the storage area a key-value pair to be modified that matches the key element contained in the target key-value pair includes: Based on the key element contained in the target key-value pair, determining a sharding area for storing the target key-value pair; Modify the block height corresponding to the determined sharding area to the block height contained in the target key-value pair, and modify the state corresponding to the determined sharding area to a write state; wherein the write state is used to indicate that the determined sharding area cannot be accessed; A target key-value pair matching the key element contained in the target key-value pair is searched from the determined shard area, and the searched target key-value pair is used as the key-value pair to be modified.
6. The method according to claim 5, characterized in that After replacing the block height contained in the to-be-modified key-value pair with the block height contained in the target key-value pair, the method further includes: If it is detected that the block height contained in the target key-value pair stored in the determined shard area matches the block height of the shard area, the state of the shard area is modified to a normal state; wherein the normal state is used to indicate that the shard area can be accessed.
7. The method according to claim 5, characterized in that The method is performed by a first blockchain node, and the method further includes: If it is detected that the target key-value pair fails to be written, controlling the first blockchain node to restart; After the first blockchain node is restarted, the target key-value pair corresponding to the block data contained in the block to be stored is re-obtained to complete the writing.
8. The method according to any one of claims 1 to 4, characterized in that The storage area includes a plurality of shard areas, each shard area stores a plurality of target key-value pairs; the method further includes: If it is detected that there is a target sharding area where the target key-value pair is missing among the multiple sharding areas, acquiring attribute information of the target sharding area, the attribute information including the minimum key element and the maximum key element corresponding to the target key-value pair stored in the target sharding area; Generate a key element interval to be retrieved based on the minimum key element and the maximum key element; The target key-value pair corresponding to the key element interval to be retrieved is obtained, and the target key-value pair corresponding to the key element interval to be retrieved is stored in the target shard area.
9. The method according to claim 8, characterized in that The storage area is located in the first blockchain node; the obtaining the target key-value pair corresponding to the key element interval to be retrieved includes: Matching the latest block height in the first blockchain node with the latest block height in the second blockchain node; wherein the first blockchain node and the second blockchain node are used to maintain the same blockchain; If the latest block height in the first blockchain node matches the latest block height in the second blockchain node, obtaining a target key-value pair corresponding to the key element interval to be retrieved from the second blockchain node; If the latest block height in the first blockchain node does not match the latest block height in the second blockchain node, the target key-value pair corresponding to the key element interval to be retrieved is obtained based on the target key-value pair stored in the second blockchain node, the block stored in the first blockchain node, and the block height interval corresponding to the key element interval to be retrieved.
10. The method according to claim 9, characterized in that The obtaining, based on the target key-value pair stored by the second blockchain node, the block stored by the first blockchain node, and the block height interval corresponding to the key element interval to be retrieved, the target key-value pair corresponding to the key element interval to be retrieved includes: If the latest block height in the first blockchain node is greater than the latest block height in the second blockchain node, obtaining a target key-value pair whose key element is in the range of key elements to be retrieved from the second blockchain node; Detecting the remaining key elements in the key element interval to be retrieved except the key elements contained in the acquired target key-value pair; Based on the block height interval corresponding to the key element interval to be retrieved and the blocks stored by the first blockchain node, a target key-value pair corresponding to the detected key element is calculated.
11. The method according to claim 9, characterized in that The obtaining, based on the target key-value pair stored by the second blockchain node, the block stored by the first blockchain node, and the block height interval corresponding to the key element interval to be retrieved, the target key-value pair corresponding to the key element interval to be retrieved includes: If the latest block height in the first blockchain node is less than the latest block height in the second blockchain node, determining a target key-value pair that matches the minimum key element in the key element interval to be retrieved from the target key-value pairs stored in the second blockchain node; Starting from the determined target key-value pair, detecting the size relationship between the block height corresponding to the maximum key element in the key element interval to be retrieved and the block height contained in the target key-value pair, and obtaining a detection result; Based on the detection result, the block height interval corresponding to the key element interval to be retrieved, and the block stored by the first blockchain node, a target key-value pair corresponding to the key element interval to be retrieved is obtained.
12. The method according to claim 11, characterized in that The obtaining, based on the detection result, the block height interval corresponding to the key element interval to be retrieved, and the block stored by the first blockchain node, a target key-value pair corresponding to the key element interval to be retrieved, comprises: If the detection result indicates that the block height corresponding to the maximum key element in the key element interval to be retrieved is greater than or equal to the block height contained in the target key-value pair, then obtaining the target key-value pair from the second blockchain node; If the detection result indicates that the block height corresponding to the maximum key element in the key element interval to be retrieved is less than the block height contained in the target key-value pair, then the target key-value pair is calculated based on the block height interval corresponding to the key element interval to be retrieved and the blocks stored in the first blockchain node.
13. A data processing device based on blockchain, characterized in that: include: An acquisition module, configured to acquire a target key-value pair corresponding to the block data contained in the block to be stored; wherein the target key-value pair includes a key element, a value element, and a block height of the block to be stored; A determination module configured to determine, based on the key element contained in the target key-value pair, a key-value pair to be modified that matches the key element contained in the target key-value pair from a storage area; A replacement module is configured to replace the value element contained in the key-value pair to be modified with the value element contained in the target key-value pair, and to replace the block height contained in the key-value pair to be modified with the block height contained in the target key-value pair.
14. An electronic device, characterized in that: include: one or more processors; A memory for storing one or more programs, which, when executed by the electronic device, enables the electronic device to implement the blockchain-based data processing method as described in any one of claims 1 to 12.
15. A computer readable medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the blockchain-based data processing method according to any one of claims 1 to 12 is implemented.
16. A computer program product comprising computer instructions, characterized in that When the computer instructions are executed by the processor, the blockchain-based data processing method as described in any one of claims 1 to 12 is implemented.