Distributed trusted storage method and device oriented to graph data
By using the consistent hash algorithm and consensus algorithm in the distributed storage system, we ensure the consensus storage of graph data among multiple nodes, solve the problem of a single node being easily tampered with, and achieve the safe storage and system security of massive graph data. High reliability.
Patent Information
- Application Number
- CN202410604499.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-05-15
- Publication Date
- 2024-08-30
- Estimated Expiration
- 2044-05-15
AI Technical Summary
Existing distributed storage technology has the risk of a single node being easily tampered with and attacked in terms of secure storage of massive graph data, causing data integrity to be affected.
Using the consistent hash algorithm and the consensus algorithm in blockchain technology, by determining the source node location of the graph data on the hash ring, the data is stored in the temporary database of the target shard, and a new area is generated when the consensus conditions are met. Block consensus ensures that all nodes jointly maintain tamper-proof log chain storage.
It realizes the safe storage of massive graph data, ensures data security through the consensus of all nodes within the shard, and enhances the system's credibility and attack resistance.
Smart Images

Figure CN118568172A
Abstract
Description
Technical Field
[0001] The present application relates to the field of distributed storage technology, and in particular to a distributed trusted storage method and device for graph data. Background Art
[0002] Graph data can be used to store and represent the widespread and complex association information between things. The more complex the data network, the larger the data scale of the graph data. In order to meet the scalable demand for storage capacity, distributed storage technology came into being. Distributed storage uses multi-node remote distribution, and each storage node independently stores part of the data, which greatly expands the overall storage capacity of the system.
[0003] However, the existing distributed storage does not solve the security problem of data on a single node being tampered with. Since the data is distributed on multiple nodes, if the data of a node is tampered with or attacked maliciously, it may affect the data integrity of the entire system. Therefore, how to achieve secure storage of massive graph data is a technical problem that needs to be solved urgently. Summary of the invention
[0004] In view of the above problems, an embodiment of the present application provides a distributed trusted storage method and device for graph data to overcome the above problems or at least partially solve the above problems.
[0005] In a first aspect of an embodiment of the present application, a distributed trusted storage method for graph data is disclosed, the method comprising:
[0006] Determine the location of the source node of the graph data on the hash ring and the corresponding target shard, and send a storage request containing the graph data to all nodes inside the target shard, wherein the hash ring includes multiple shards based on a consistent hashing algorithm;
[0007] After receiving the storage request, all nodes in the target shard store the graph data in a temporary database;
[0008] When the consensus conditions are met, a new block is generated according to the graph data in the temporary database, and consensus is reached on the new block among all nodes in the target shard;
[0009] The new block that passes the consensus is added to the log chain for storage. The log chain is jointly maintained by all nodes within the target shard.
[0010] Optionally, the minimum number of nodes and the maximum number of nodes in each shard on the hash ring satisfy 3N+1, where N is the node fault tolerance number of the consensus algorithm; a new node is added to a shard on the hash ring according to the following steps:
[0011] Randomly add the new node to a shard on the hash ring, and determine whether the first shard after adding the new node is fully loaded, where fully loaded means that the number of nodes in the shard is greater than the maximum number of nodes;
[0012] When the first shard is not fully loaded, the original node in the first shard synchronizes the shard information to the new node;
[0013] When the first shard is fully loaded, the first shard is split into M new shards, and the target position of each new shard is determined after hash operation is performed on the M new shards. The M new shards are added to the hash ring according to the target positions, where M is an integer greater than or equal to 2, and the number of nodes inside the new shards is greater than or equal to the minimum number of nodes.
[0014] Optionally, determining the target location of each new shard after performing a hash operation on the M new shards includes:
[0015] Determine one of the M new shards as the original shard, and determine the remaining new shards of the M new shards except the original shard as extended shards;
[0016] Determine the sequence number of the original shard to be the same as the sequence number of the first shard, and perform a hash calculation based on the sequence number of the original shard to obtain a target position of the original shard;
[0017] The serial number of the extended shard is determined according to the maximum shard serial number on the hash ring, and a hash calculation is performed based on the serial number of the extended shard to obtain the target position of the extended shard.
[0018] Optionally, adding the M new shards to the hash ring respectively according to the target positions includes:
[0019] All nodes in the original shard retain their own shard information, and add the original shard to the hash ring according to the target position of the original shard;
[0020] The shard information in all nodes within the extended shard is cleared, the master node within the extended shard synchronizes the new shard information to other nodes, and the extended shard is added to the hash ring according to the target position of the extended shard.
[0021] Optionally, the method further comprises:
[0022] The newly added block in the log chain is mapped to the view to obtain a shard sub-view, and the shard sub-view contains all the graph data stored in the log chain.
[0023] Optionally, the temporary database includes a first key and a second key;
[0024] The first key represents the amount of graph data in the temporary database, and the value corresponding to the first key represents the value of the amount of graph data in the temporary database;
[0025] The second key represents a hash value obtained by hashing the graph data, and the value corresponding to the second key represents the graph data.
[0026] Optionally, the consensus condition is satisfied, including at least one of the following:
[0027] The amount of graph data in the temporary database is greater than a quantity threshold;
[0028] The time interval from the end of the last consensus to the current moment is greater than the time threshold.
[0029] Optionally, all nodes within the target shard include a master node and multiple slave nodes, and the master node is replaced in turn after each round of consensus;
[0030] Generate a new block according to the graph data in the temporary database, and reach consensus on the new block among all nodes in the target shard, including:
[0031] The master node packages the graph data in the temporary database into a new block;
[0032] The master node initiates a consensus request and forwards the consensus request to the multiple slave nodes;
[0033] After receiving the consensus request, each secondary node verifies the validity of the new block.
[0034] Optionally, add the new block that has passed the consensus to the log chain for storage, including:
[0035] All nodes in the target shard add the new block after consensus to the block database to obtain a log chain;
[0036] The block database includes a third key and a fourth key, the third key represents the number of blocks in the block database, and the value corresponding to the third key represents the value of the number of blocks in the block database;
[0037] The fourth key represents a block number, and a value corresponding to the fourth key represents block data corresponding to the block number.
[0038] In a second aspect of an embodiment of the present application, a distributed trusted storage device for graph data is disclosed, the device comprising:
[0039] A sending module, used to determine the location of a source node of graph data on a hash ring and a corresponding target shard, and send a storage request containing the graph data to all nodes inside the target shard, wherein the hash ring includes multiple shards based on a consistent hashing algorithm;
[0040] A storage module, configured for all nodes in the target shard to store the graph data in a temporary database after receiving the storage request;
[0041] A consensus module, configured to generate a new block according to the graph data in the temporary database when the consensus conditions are met, and to reach a consensus on the new block among all nodes in the target shard;
[0042] The adding module is used to add the new block that has passed the consensus to the log chain for storage. The log chain is jointly maintained by all nodes in the target shard.
[0043] The embodiments of the present application include the following advantages:
[0044] In the embodiment of the present application, a consistent hashing algorithm is used as the algorithm for data sharding, combined with the consensus algorithm in the blockchain technology to provide a reliable guarantee for the distributed storage of graph data. When storing graph data, first determine the position of the source node of the graph data on the hash ring and the corresponding target shard, and send a storage request containing the graph data to all nodes within the target shard; then, after receiving the storage request, all nodes within the target shard store the graph data in a temporary database; then, if the consensus conditions are met, generate a new block based on the graph data in the temporary database, and reach a consensus on the new block in all nodes within the target shard; finally, add the new block that passes the consensus to the log chain for storage. Since a log chain is jointly maintained by all nodes within the shard, when graph data is stored, consensus is required in all nodes within the shard to achieve storage, that is, each shard on the hash ring uses a consensus algorithm to ensure the security of data storage within the shard, thus solving the problem of secure storage of massive graph data. BRIEF DESCRIPTION OF THE DRAWINGS
[0045] In order to more clearly illustrate the technical solutions of the embodiments of the present application, the drawings required for use in the description of the embodiments of the present application will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.
[0046] Figure 1 It is a structural diagram of a distributed storage system without a central node provided in an embodiment of the present application;
[0047] Figure 2 It is a flowchart of the steps of a distributed trusted storage method for graph data provided by an embodiment of the present application;
[0048] Figure 3 It is a flow chart of a method for adding a new node to a hash ring provided by an embodiment of the present application;
[0049] Figure 4 It is a flowchart of the steps of another distributed trusted storage method for graph data provided by an embodiment of the present application;
[0050] Figure 5 It is a flow chart of a distributed trusted storage method for graph data provided by an embodiment of the present application;
[0051] Figure 6 It is a structural diagram of a distributed trusted storage device for graph data provided in an embodiment of the present application. DETAILED DESCRIPTION
[0052] In order to make the above-mentioned purposes, features and advantages of the present application more obvious and understandable, the technical solutions in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.
[0053] In the related art, the distributed storage system uses a single or clustered server as an independent node, which is responsible for the storage task of a part of the data. Multiple nodes together form a whole, responsible for the storage task of the entire system. By allocating storage tasks to different nodes according to a certain allocation algorithm, each node is only responsible for the data assigned to it; at the same time, in order to ensure that there is no data storage missing in the system as a whole and reduce the problem of duplicate data storage, a consistent hashing algorithm is used to map data to nodes. After mapping, each node can be regarded as an independent subsystem, responsible for the storage of a part of the data. This distributed storage system has low deployment difficulty and strong scalability. It can well realize the distributed storage of graph data when the system security risk is not high.
[0054] However, this approach still faces the problem of low security, easy attack, and easy tampering of a single sub-node. Since the data is distributed on multiple nodes, if the data of a node is tampered with or attacked maliciously, it may affect the data integrity of the entire system. To this end, the embodiment of the present application provides a distributed trusted storage method for graph data, which uses a consistent hashing algorithm as a data sharding algorithm and combines the consensus algorithm in blockchain technology to provide trusted protection for the distributed storage of graph data. See below for details.
[0055] The present application embodiment provides a distributed storage system without a central node, which is used to implement the distributed trusted storage method for graph data provided by the present application embodiment. Figure 1 As shown, Figure 1 is a structural diagram of a distributed storage system without a central node provided in an embodiment of the present application, such as Figure 1 As shown:
[0056] The distributed storage system without central nodes includes a hash ring using a consistent hashing algorithm. The hash ring consists of multiple shards, and each shard includes multiple nodes. When a new shard is added, only part of the data needs to be remapped without redistributing the entire data set; when a shard leaves, only a small amount of data needs to be remapped, thereby reducing the cost of data movement. The nodes within each shard jointly maintain an unalterable log chain. The basic component of the log chain is the block, where the block is divided into a block header and a block body. The block header is responsible for recording block-related information, and the block body is responsible for recording the data that needs to be stored. The view is generated from the graph data stored in the log chain. The view is centered on the point to form a shard subview to facilitate data query.
[0057] The present application embodiment provides a distributed trusted storage method for graph data. Figure 2 As shown, Figure 2 This is a flowchart of a distributed trusted storage method for graph data provided by an embodiment of the present application. Figure 2 As shown, the method may include steps S210 to S240:
[0058] Step S210: Determine the position of the source node of the graph data on the hash ring and the corresponding target shard, and send a storage request containing the graph data to all nodes inside the target shard, where the hash ring includes multiple shards based on a consistent hashing algorithm.
[0059] In an embodiment of the present application, graph data can be used to store and represent the widespread and complex association information between things. The graph data can be abstracted into a "point-edge-point" triple form, that is, the graph data is a node (i.e., the initial node) pointing to another node (i.e., the destination node) through an edge, and the source node of the graph data refers to the initial node of the graph.
[0060] The hash ring is a distributed storage system without a central node. The hash ring is composed of multiple shards, and multiple shards are distributed on the hash ring using a consistent hashing algorithm. Each molecule on the hash ring includes multiple nodes. The number of nodes in a shard is set according to the maximum latency requirement of the storage, and the minimum and maximum number of nodes in a shard satisfies 3N+1, where N is the node fault tolerance of the consensus algorithm. For example, when the value of N is less than or equal to 4, the minimum number of nodes in the shard can be 7 and the maximum number of nodes is 13. At this time, the shards on the hash ring are composed of 7 to 13 nodes.
[0061] The core idea of the consistent hashing algorithm is to map both graph data and shards to the same hash ring, and determine which node the graph data should be placed on by comparing the hash values of the node and the graph data. Therefore, when storing graph data, the source node in the graph data is hashed to obtain the location of the source node in the hash ring and the corresponding target shard. A node in the target shard is the source node of the graph data. Then, the storage request containing the graph data is sent to all nodes in the target shard.
[0062] Step S220: After receiving the storage request, all nodes in the target shard store the graph data in a temporary database.
[0063] In the embodiment of the present application, in order to ensure the security of data in each shard, the graph data to be stored must be stored after consensus is reached in all nodes within the shard. Since it takes a long time to execute consensus, consensus is not executed in the target shard after each storage request is received. Therefore, after receiving a storage request containing graph data, the nodes in the target shard first store the graph data in a temporary database, and only execute consensus when the consensus conditions are met.
[0064] The temporary database is a database for storing key-value (key key, value) data. In specific implementation, the temporary database can be implemented by embedded RocksDB, which is a high-performance embedded database for storing key-value data.
[0065] Step S230: When the consensus conditions are met, a new block is generated according to the graph data in the temporary database, and consensus is reached on the new block among all nodes within the target shard.
[0066] In an embodiment of the present application, in order to balance the average time consumed by the database consensus and the system throughput performance consumption, consensus is performed on the graph data in the temporary database only when the consensus conditions are met, that is, the graph data in the temporary database is packaged into a new block, and consensus is performed on the new block in all nodes within the target shard.
[0067] In an optional embodiment, the consensus condition is satisfied, including at least one of the following:
[0068] Item A-1: The amount of graph data in the temporary database is greater than the quantity threshold;
[0069] Item A-2: The time interval from the end of the last consensus to the current moment is greater than the time threshold.
[0070] In an embodiment of the present application, when the number of graph data in the temporary database is greater than the quantity threshold, consensus is executed on the graph data in the temporary database (i.e., item A-1), wherein the quantity threshold is adjusted according to the actual situation. For example, if the quantity threshold is 5000, then when the number of graph data in the temporary database is greater than 5000, consensus is executed on the graph data in the temporary database. In order to ensure the security of data in the temporary database, after completing the consensus, the target shard also monitors the time interval from the end of the last consensus to the current moment, and when it is monitored that the time interval from the end of the last consensus to the current moment is greater than the time threshold, consensus is executed on the graph data in the temporary database (i.e., item A-2). Among them, the time threshold is adjusted according to the actual situation. For example, if the time threshold is 30 seconds, then when the time interval from the end of the last consensus to the current moment is greater than 30 seconds, regardless of whether the number of graph data in the temporary database meets the quantity threshold, consensus will be executed on the graph data in the temporary database.
[0071] In a specific implementation, consensus on the new block is achieved among all nodes within the target shard through the PBFT (Practical Byzantine Fault Tolerance) algorithm, which is a distributed system consensus algorithm that can tolerate Byzantine faults. In addition, after the consensus is reached, the graph data in the temporary database is cleared to facilitate subsequent storage of graph data that has not yet reached consensus.
[0072] Step S240: Add the new block that has passed the consensus to the log chain for storage. The log chain is maintained by all nodes in the target shard.
[0073] In an embodiment of the present application, all nodes within each shard jointly maintain an unalterable log chain, and store graph data in the log chain. Each block in the log chain is divided into a block header and a block body. The block header is responsible for recording block-related information, including: block number, shard sequence number, timestamp, Merkle tree root (i.e., merkle tree root, merkle tree is a hash binary tree), previous block hash, and adjacent block information; the block body is responsible for recording graph data that needs to be stored, including: multiple graph data, i.e., the consensus data subject. For new blocks that have passed consensus within the shard, the new blocks that have passed consensus are connected to the log chain for storage.
[0074] Through the above steps, when storing graph data, first determine the location of the source node of the graph data on the hash ring and the corresponding target shard, and send a storage request containing the graph data to all nodes in the target shard; then, after receiving the storage request, all nodes in the target shard store the graph data in a temporary database; then, if the consensus conditions are met, generate a new block based on the graph data in the temporary database, and reach a consensus on the new block in all nodes in the target shard; finally, add the new block that passes the consensus to the log chain for storage. Since a log chain is jointly maintained by all nodes in the shard, when storing graph data, consensus is required in all nodes in the shard to achieve storage, that is, each shard on the hash ring uses a consensus algorithm to ensure the security of data storage in the shard, thus solving the problem of secure storage of massive graph data.
[0075] In an optional embodiment, the minimum number of nodes and the maximum number of nodes in each shard on the hash ring satisfy 3N+1, where N is the node fault tolerance number of the consensus algorithm; a new node is added to a shard on the hash ring according to the following steps B1 to B3:
[0076] Step B1: randomly add a new node to a shard on the hash ring, and determine whether the first shard after adding the new node is fully loaded, where fully loaded means that the number of nodes in the shard is greater than the maximum number of nodes.
[0077] In the embodiment of the present application, the specific process of randomly adding a new node to a shard on the hash ring is as follows: the new node randomly selects a shard in the hash ring and sends a join request to all nodes in the shard to inform all nodes in the shard that the new node is about to join the shard. After receiving the join request, the nodes in the shard add the new node to the shard information database where it is located and the shard information database of the entire hash ring to add the new shard to the shard.
[0078] After the new node is connected to the shard, the number of nodes inside the shard will increase. Since the number of nodes inside the shard in the hash ring is set according to the maximum latency requirement of the storage, and the maximum number of nodes needs to meet 3N+1. Therefore, after the new node is added to the shard, it is necessary to determine whether the first shard after the new node is added is fully loaded, that is, to determine whether the number of nodes inside the first shard is greater than the maximum number of nodes. If the first shard is not fully loaded, execute step B2, and if the first shard is fully loaded, execute step B3.
[0079] Step B2: When the first shard is not fully loaded, the original node in the first shard synchronizes the shard information to the new node.
[0080] In an embodiment of the present application, all nodes within the shard include a master node. When the first shard is not fully loaded (i.e., the number of nodes within the first shard is not greater than the maximum number of nodes), the original node within the first shard synchronizes the shard information to the new node. Specifically, it means that the master node on the first shard synchronizes its own database information to the new node.
[0081] Step B3: When the first shard is fully loaded, split the first shard into M new shards, and determine the target position of each new shard after performing hash operation on the M new shards, and add the M new shards to the hash ring according to the target positions, where M is an integer greater than or equal to 2, and the number of nodes inside the new shard is greater than or equal to the minimum number of nodes.
[0082] In the embodiment of the present application, when the first shard is fully loaded, the first shard will be randomly sharded into M new shards, which means that the addition of new nodes may lead to the generation of new shards, that is, the hash ring has scalability. For example, the minimum number of nodes is 7 and the maximum number of nodes is 13. If the number of internal nodes of the first shard after the new node is connected is 14, the first shard is fully loaded, and the first shard is split into two new shards with 7 internal nodes.
[0083] The M new shards obtained by the split are added to the hash ring through the consistent hashing algorithm. Specifically, the serial number of the new shard is used as the keyword for hash calculation, and the calculation result is used as the target position of the shard on the hash ring. The M new shards are added to the hash ring according to the target position.
[0084] Specifically, after performing a hash operation on the M new shards, determining the target location of each new shard includes steps C1 to C3:
[0085] Step C1: determining one of the M new shards as the original shard, and determining the remaining new shards of the M new shards except the original shard as extended shards;
[0086] Step C2: determining the sequence number of the original shard to be the same as the sequence number of the first shard, and performing a hash calculation based on the sequence number of the original shard to obtain the target position of the original shard;
[0087] Step C3: Determine the serial number of the extended slice according to the maximum slice serial number on the hash ring, and perform hash calculation based on the serial number of the extended slice to obtain the target position of the extended slice.
[0088] In an embodiment of the present application, one of the new shards is used as the original shard to retain the serial number of the first shard, that is, the serial number of the original shard is the same as the serial number of the first shard, and the target position of the original shard is obtained by hash calculation based on the serial number of the original shard (that is, hash calculation is performed based on the keyword generated by the serial number of the original shard), so the position of the original shard on the hash ring is the same as that of the first shard.
[0089] For the remaining shards (i.e., extended shards) except the original shards, the serial number of the extended shards is determined according to the maximum shard serial number on the hash ring, including: on the basis of the maximum shard serial number, the serial number of the extended shard is increased in sequence. For example, if there are two extended shards and the maximum shard serial number is 5, the serial number of one extended shard is 6 and the serial number of the other extended shard is 7. Then, a hash calculation is performed based on the serial number of each extended shard (i.e., a keyword is generated based on the serial number of the extended shard for hash calculation), and the calculation result is used as the target position of the extended shard.
[0090] For example, there are two new shards. One of the new shards is used as the original shard, and its sequence number is the same as that of the first shard. If the sequence number of the first shard is 2, the sequence number of the original shard is also 2. The other new shard is used as an extended shard. If the maximum shard sequence number on the hash ring is 5, the sequence number of the extended shard is 6.
[0091] Specifically, the M new shards are added to the hash ring respectively according to the target positions, including step D1 and step D2:
[0092] Step D1: All nodes in the original shard retain their own shard information, and add the original shard to the hash ring according to the target position of the original shard;
[0093] Step D2: Clear the shard information in all nodes within the extended shard, the master node within the extended shard synchronizes the new shard information to other nodes, and adds the extended shard to the hash ring according to the target position of the extended shard.
[0094] In the embodiment of the present application, the original shard is regarded as a shard corresponding to the first shard, the position of the original shard on the hash ring is the same as the position of the first shard, all nodes inside the original shard retain their own shard information, and the original shard is added to the hash ring according to the target position of the original shard. The extended shard is regarded as a new shard, so before the extended shard is added to the hash ring, the original data information of all nodes on each extended shard is cleared, and then the master node inside the extended shard synchronizes the new shard information to other nodes, and adds the extended shard to the hash ring according to the target position of the extended shard, so as to realize shard expansion.
[0095] For example, Figure 3 It is a flow chart of a method for adding a new node to a hash ring provided by an embodiment of the present application. Specifically, a new node is randomly added to a shard on the hash ring, and it is determined whether the first shard after the new node is added is fully loaded. When the first shard is not fully loaded, the original node inside the first shard synchronizes the shard information to the new node; when the first shard is fully loaded, the first shard is split into M new shards, and the target position of each new shard is determined after performing a hash operation on the M new shards. For the original shard, all nodes inside the original shard retain their own shard information, and the original shard is added to the hash ring according to the target position of the original shard; for the extended shard, the shard information in all nodes inside the extended shard is cleared, and the master node inside the extended shard synchronizes the new shard information to other nodes, and then adds the extended shard to the hash ring according to the target position of the extended shard.
[0096] In the embodiment of the present application, since the hash ring supports the addition of new nodes, the hash ring is scalable, and a new shard will be generated when a new node is added to the full hash ring. The new shard can share the evidence storage task of the original shard, and the addition of the new shard does not affect the work of other shards except the adjacent shards, thereby expanding the total number of shards of the system. By adding new nodes to the hash ring, the total throughput and storage capacity of the hash ring are increased, avoiding the problem of reduced availability caused by the increase in the scale of use of the hash ring. By expanding the new shard, new service nodes and storage nodes can be added, providing a solution for the long-term linear growth performance and storage requirements of the hash ring. And with the continuous increase of nodes in the hash ring, the overall credibility of the hash ring will continue to increase, and the difficulty of tampering will continue to increase.
[0097] Moreover, since the new node joins the hash ring randomly to a shard, rather than adding the new node to a designated shard, it is possible to avoid the Byzantine node maliciously occupying a certain shard, causing the shard to be occupied by the Byzantine node. In addition, the fully random rather than the priority random joining of the unloaded shards can, on the one hand, avoid the Byzantine node maliciously joining at a time point when there is only one unloaded shard on the entire hash ring, causing the actual designated joining to generate a Byzantine attack; on the other hand, if the priority random joining of the unloaded shards is adopted, then when all shards of the hash ring are fully loaded, any addition of a node will inevitably cause shard splitting (this is an event that consumes the performance of the hash ring), and the attacker can choose this time point to add a large number of new nodes at the same time, resulting in multiple shards on the hash ring splitting events at the same time, thereby causing the hash ring to be congested, reducing the performance of the hash ring, and even causing the hash ring to be unavailable for a short time. Therefore, by the way in which the new node joins the hash ring in the embodiment of the present application, while making the hash ring scalable, the security of the data in each shard on the hash ring is guaranteed.
[0098] Reference Figure 4 As shown, Figure 4 4 is a flowchart of another distributed trusted storage method for graph data provided by an embodiment of the present application, the method comprising steps S410 to S450:
[0099] Step S410: Determine the position of the source node of the graph data on the hash ring and the corresponding target shard, and send a storage request containing the graph data to all nodes inside the target shard, where the hash ring includes multiple shards based on a consistent hashing algorithm.
[0100] In the embodiment of the present application, step S410 may correspond to the relevant description of the aforementioned step 210, and will not be described again here to avoid repetition.
[0101] Step S420: After receiving the storage request, all nodes in the target shard store the graph data in a temporary database.
[0102] Specifically, the temporary database includes a first key and a second key; wherein, the first key represents the amount of graph data in the temporary database, and the value corresponding to the first key represents the value of the amount of graph data in the temporary database; the second key represents the hash value calculated by hashing the graph data, and the value corresponding to the second key represents the graph data.
[0103] In the embodiment of the present application, the first key can be used to record the number of graph data to be agreed upon in the temporary database, and then when the number of graph data meets certain conditions in the future, the consensus will be triggered; the second key can be used to store the graph data in the temporary database.
[0104] Step S430: When the consensus conditions are met, a new block is generated according to the graph data in the temporary database, and consensus is reached on the new block among all nodes within the target shard.
[0105] In the embodiment of the present application, satisfying the consensus condition refers to at least one of the above-mentioned items A-1 and A-2, which will not be described here to avoid repetition. In a specific implementation, the temporary database includes a first key, and when the value corresponding to the first key is greater than a quantity threshold, the graph data in the temporary database executes consensus.
[0106] Specifically, all nodes in the target shard include a master node and multiple slave nodes, and the master node is replaced in turn after each round of consensus. That is, there is only one master node in each round of consensus. In order to prevent the master node from forging blocks, a new master node will be elected at the end of each round of consensus.
[0107] Generate a new block according to the graph data in the temporary database, and reach a consensus on the new block among all nodes in the target shard, including steps S330-1 to S330-3:
[0108] Step S430-1: the master node packages the graph data in the temporary database into a new block;
[0109] Step S430-2: the master node initiates a consensus request and forwards the consensus request to the multiple slave nodes;
[0110] Step S430-3: After receiving the consensus request, each slave node verifies the validity of the new block.
[0111] In the embodiment of the present application, consensus on new blocks among all nodes within the target shard is achieved through the PBFT algorithm. In specific implementation, the master node acts as the master node in the consensus algorithm to package new blocks and initiate consensus requests, and other slave nodes act as slave nodes of the master node in the consensus algorithm to verify the validity of the new block.
[0112] In the embodiment of the present application, although the target shard includes a master node, the master node is replaced in turn after each round of consensus, and the master node is only meaningful within the shard, that is, the master node is invisible to other shards. For the entire hash ring, all nodes can be regarded as equal, that is, any node can be replaced by another node without affecting the normal operation of the hash ring. Therefore, the embodiment of the present application realizes a distributed decentralized storage. Therefore, the method can effectively prevent the central node from going down or being maliciously tampered with, resulting in the credibility of the entire hash ring completely relying on the reliability of the central node. While ensuring disaster recovery backup, it can avoid the damage of a single node from causing irreversible effects on the entire hash ring, and enhance the trusted consensus of each node on the entire hash ring.
[0113] It is understandable that since the PBFT algorithm is used within the shard, the Byzantine node fault tolerance of the algorithm is (that is, the node fault tolerance of the consensus algorithm) N. Therefore, in order to optimize the anti-attack performance of the shard more efficiently, the boundary of the number of nodes (that is, the minimum number of nodes and the maximum number of nodes) adopts the mode of 3N+1. Because the time complexity of the PBFT algorithm is O(N 2 ), so when the number of nodes is too large, the consensus efficiency of the consensus algorithm will be significantly reduced. In order to ensure the availability of the system, there should not be too many nodes in a single shard. At the same time, the number of nodes should not be too small, otherwise it is more likely that the number of Byzantine nodes exceeds N, resulting in a successful attack on the shard. In addition, due to the scalability of the hash ring, when the number of nodes in a shard reaches the maximum number of nodes, continuing to add a new node will cause the shard to split, forming M new shards after the split.
[0114] Step S440: All nodes within the target shard add the new block after consensus to the block database to obtain a log chain, which is jointly maintained by all nodes within the target shard.
[0115] Among them, the block database includes a third key and a fourth key, the third key represents the number of blocks in the block database, and the value corresponding to the third key represents the value of the number of blocks in the block database; the fourth key represents the block number, and the value corresponding to the fourth key represents the block data corresponding to the block number.
[0116] In an embodiment of the present application, for a new block after consensus is passed, all nodes within the target shard will add the new block to the block database. Among them, the block database is a database that stores key-value data. The block database includes two keys, namely the third key and the fourth key, and the number of blocks in the block database can be recorded by the third key. For example, if there are 5 blocks in the block database, the value corresponding to the third key is 5. The fourth key can record the data of each block, and the fourth key is an integer that increases from zero and represents the number of the block. For example, if the fourth key is the number of the 4th block, the fourth key is the data of the 4th block. In the specific implementation, the block database can also be implemented using an embedded RocksDB. Since the block data in the block database is backed up by disaster recovery of multiple nodes in the shard, the block database cannot be tampered with.
[0117] Step S450: Map the newly added new block in the log chain to the view to obtain a shard sub-view, and the shard sub-view contains all the graph data stored in the log chain.
[0118] In an embodiment of the present application, a view is generated based on the graph data stored in the log chain. The view is centered on the node to form a shard sub-view. The standard of the shard sub-view is to meet the data format of the graph data used, so that graph data queries can be performed based on the shard sub-view later.
[0119] For example, Figure 5 It is a flow chart of a distributed trusted storage method for graph data provided by an embodiment of the present application. Specifically, after determining the position of the source node of the graph data on the hash ring and the corresponding target shard, a storage request containing the graph data is sent to all nodes within the target shard. Then, after receiving the storage request, the nodes within the target shard store the graph data in a temporary database; determine whether the consensus conditions are met, and if the consensus conditions are met, generate a new block based on the graph data in the temporary database, and reach a consensus on the new block among all nodes within the target shard; then add the new block that passes the consensus to the log chain for storage, and map the newly added new block in the log chain to the view to obtain a shard subview. Since a log chain is jointly maintained by all nodes within the shard, when graph data is stored, consensus is required among all nodes within the shard to achieve storage, that is, each shard on the hash ring uses a consensus algorithm to ensure the security of data storage within the shard; and the data in the log chain can be queried through the shard subview. In this way, the problem of secure storage of massive graph data is solved.
[0120] The present application also provides a distributed trusted storage device for graph data. Figure 6 As shown, Figure 6: is a schematic diagram of a distributed trusted storage device for graph data provided by an embodiment of the present application, the device comprising:
[0121] A sending module 610 is used to determine the location of a source node of graph data on a hash ring and a corresponding target shard, and to send a storage request containing the graph data to all nodes inside the target shard, wherein the hash ring includes multiple shards based on a consistent hashing algorithm;
[0122] Storage module 620, configured for all nodes in the target shard to store the graph data in a temporary database after receiving the storage request;
[0123] A consensus module 630 is used to generate a new block according to the graph data in the temporary database when the consensus condition is met, and to reach a consensus on the new block among all nodes in the target shard;
[0124] The adding module 640 is used to add the new block that has passed the consensus into the log chain for storage. The log chain is jointly maintained by all nodes in the target shard.
[0125] In an optional embodiment, the minimum number of nodes and the maximum number of nodes in each shard on the hash ring satisfy 3N+1, where N is the node fault tolerance number of the consensus algorithm; the device includes a new node adding module, which is used to add a new node to a shard on the hash ring, and the new node adding module includes:
[0126] A adding judgment module is used to randomly add a new node to a shard on the hash ring, and judge whether the first shard after adding the new node is fully loaded, wherein fully loaded means that the number of nodes in the shard is greater than the maximum number of nodes;
[0127] An information synchronization module, configured to synchronize the shard information to the new node by the original node in the first shard when the first shard is not fully loaded;
[0128] A shard splitting module is used to split the first shard into M new shards when the first shard is fully loaded, and determine the target position of each new shard after performing hash operation on the M new shards, and add the M new shards to the hash ring according to the target positions, where M is an integer greater than or equal to 2, and the number of nodes inside the new shard is greater than or equal to the minimum number of nodes.
[0129] In an optional embodiment, the shard splitting module includes:
[0130] A first determination module is used to determine one of the M new shards as an original shard, and determine the remaining new shards of the M new shards except the original shard as extended shards;
[0131] A first calculation module, configured to determine the sequence number of the original shard to be the same as the sequence number of the first shard, and perform a hash calculation based on the sequence number of the original shard to obtain a target position of the original shard;
[0132] The second calculation module is used to determine the serial number of the extended slice according to the maximum slice serial number on the hash ring, and perform hash calculation based on the serial number of the extended slice to obtain the target position of the extended slice.
[0133] In an optional embodiment, the shard splitting module includes:
[0134] The first adding submodule is used for all nodes in the original shard to retain their own shard information and add the original shard to the hash ring according to the target position of the original shard;
[0135] The second adding submodule is used to clear the shard information in all nodes inside the extended shard. The master node inside the extended shard synchronizes the new shard information to other nodes and adds the extended shard to the hash ring according to the target position of the extended shard.
[0136] In an optional embodiment, the device further includes:
[0137] The view generation module is used to map the new block newly added to the log chain to the view to obtain a shard sub-view, and the shard sub-view contains all the graph data stored in the log chain.
[0138] In an optional embodiment, the temporary database includes a first key and a second key;
[0139] The first key represents the amount of graph data in the temporary database, and the value corresponding to the first key represents the value of the amount of graph data in the temporary database;
[0140] The second key represents a hash value obtained by hashing the graph data, and the value corresponding to the second key represents the graph data.
[0141] In an optional embodiment, the consensus condition is satisfied, including at least one of the following:
[0142] The amount of graph data in the temporary database is greater than a quantity threshold;
[0143] The time interval from the end of the last consensus to the current moment is greater than the time threshold.
[0144] In an optional embodiment, all nodes within the target shard include a master node and multiple slave nodes, and the master node is replaced in turn after each round of consensus; the consensus module includes:
[0145] A packaging module, used for the master node to package the graph data in the temporary database into a new block;
[0146] A forwarding module, used for the master node to initiate a consensus request and forward the consensus request to the multiple slave nodes;
[0147] The verification module is used for each secondary node to verify the validity of the new block after receiving the consensus request.
[0148] In an optional embodiment, the joining module includes:
[0149] Add a submodule, which is used for all nodes in the target shard to add the new block after consensus into the block database to obtain a log chain;
[0150] Among them, the block database includes a third key and a fourth key, the third key represents the number of blocks in the block database, and the value corresponding to the third key represents the value of the number of blocks in the block database; the fourth key represents the block number, and the value corresponding to the fourth key represents the block data corresponding to the block number.
[0151] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0152] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods and devices according to the embodiments of the present application. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of the processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0153] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0154] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for executing on the computer or other programmable terminal device to implement the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0155] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.
[0156] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0157] The above is a detailed introduction to a distributed trusted storage method and device for graph data provided by the present application. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea; at the same time, for general technical personnel in this field, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A distributed trusted storage method for graph data, characterized in that: The method comprises: Determine the location of the source node of the graph data on the hash ring and the corresponding target shard, and send a storage request containing the graph data to all nodes inside the target shard, wherein the hash ring includes multiple shards based on a consistent hashing algorithm; After receiving the storage request, all nodes in the target shard store the graph data in a temporary database; When the consensus conditions are met, a new block is generated according to the graph data in the temporary database, and consensus is reached on the new block among all nodes in the target shard; The new block that passes the consensus is added to the log chain for storage. The log chain is jointly maintained by all nodes within the target shard.
2. A distributed trusted storage method for graph data according to claim 1, characterized in that: The minimum number of nodes and the maximum number of nodes in each shard on the hash ring meet 3N+1, where N is the node fault tolerance of the consensus algorithm; a new node is added to a shard on the hash ring according to the following steps: Randomly add the new node to a shard on the hash ring, and determine whether the first shard after adding the new node is fully loaded, where fully loaded means that the number of nodes in the shard is greater than the maximum number of nodes; When the first shard is not fully loaded, the original node in the first shard synchronizes the shard information to the new node; When the first shard is fully loaded, the first shard is split into M new shards, and the target position of each new shard is determined after hash operation is performed on the M new shards. The M new shards are added to the hash ring according to the target positions, where M is an integer greater than or equal to 2, and the number of nodes inside the new shards is greater than or equal to the minimum number of nodes.
3. A distributed trusted storage method for graph data according to claim 2, characterized in that: After performing a hash operation on the M new shards, determining the target location of each new shard includes: Determine one of the M new shards as the original shard, and determine the remaining new shards of the M new shards except the original shard as extended shards; Determine the sequence number of the original shard to be the same as the sequence number of the first shard, and perform a hash calculation based on the sequence number of the original shard to obtain a target position of the original shard; The serial number of the extended shard is determined according to the maximum shard serial number on the hash ring, and a hash calculation is performed based on the serial number of the extended shard to obtain the target position of the extended shard.
4. A distributed trusted storage method for graph data according to claim 3, characterized in that: Adding the M new shards to the hash ring respectively according to the target positions includes: All nodes in the original shard retain their own shard information, and add the original shard to the hash ring according to the target position of the original shard; The shard information in all nodes within the extended shard is cleared, the master node within the extended shard synchronizes the new shard information to other nodes, and the extended shard is added to the hash ring according to the target position of the extended shard.
5. A distributed trusted storage method for graph data according to claim 1, characterized in that: The method further comprises: The newly added block in the log chain is mapped to the view to obtain a shard sub-view, and the shard sub-view contains all the graph data stored in the log chain.
6. A distributed trusted storage method for graph data according to claim 1, characterized in that: The temporary database includes a first key and a second key; The first key represents the amount of graph data in the temporary database, and the value corresponding to the first key represents the value of the amount of graph data in the temporary database; The second key represents a hash value obtained by hashing the graph data, and the value corresponding to the second key represents the graph data.
7. A distributed trusted storage method for graph data according to claim 1, characterized in that: The consensus condition is satisfied, including at least one of the following: The amount of graph data in the temporary database is greater than a quantity threshold; The time interval from the end of the last consensus to the current moment is greater than the time threshold.
8. A distributed trusted storage method for graph data according to claim 1, characterized in that: All nodes within the target shard include a master node and multiple slave nodes, and the master node is replaced in turn after each round of consensus; Generate a new block according to the graph data in the temporary database, and reach consensus on the new block among all nodes in the target shard, including: The master node packages the graph data in the temporary database into a new block; The master node initiates a consensus request and forwards the consensus request to the multiple slave nodes; After receiving the consensus request, each secondary node verifies the validity of the new block.
9. A distributed trusted storage method for graph data according to claim 1, characterized in that: Add the new blocks that pass the consensus to the log chain for storage, including: All nodes in the target shard add the new block after consensus to the block database to obtain a log chain; The block database includes a third key and a fourth key, the third key represents the number of blocks in the block database, and the value corresponding to the third key represents the value of the number of blocks in the block database; The fourth key represents a block number, and a value corresponding to the fourth key represents block data corresponding to the block number.
10. A distributed trusted storage device for graph data, characterized in that: The device comprises: A sending module, used to determine the location of a source node of graph data on a hash ring and a corresponding target shard, and send a storage request containing the graph data to all nodes inside the target shard, wherein the hash ring includes multiple shards based on a consistent hashing algorithm; A storage module, configured for all nodes in the target shard to store the graph data in a temporary database after receiving the storage request; A consensus module, configured to generate a new block according to the graph data in the temporary database when the consensus conditions are met, and to reach a consensus on the new block among all nodes in the target shard; The adding module is used to add the new block that has passed the consensus to the log chain for storage. The log chain is jointly maintained by all nodes in the target shard.
Citation Information
Patent Citations
PBFT-based alliance chain fragmentation method and corresponding alliance chain
CN109510876A
Intra-fragment data organization and management method for alliance chain
CN111324613A
Practical Byzantine fault-tolerant consensus method based on block chain type storage
CN111555858A
Novel alliance chain based on distributed storage
CN111770149A
Block chain storage capacity optimization method and system
CN112788139A
