CN112765155A - Block chain-based key value storage method and device, terminal equipment and medium - Google Patents
Block chain-based key value storage method and device, terminal equipment and medium Download PDFInfo
- Publication number
- CN112765155A CN112765155A CN202011465232.6A CN202011465232A CN112765155A CN 112765155 A CN112765155 A CN 112765155A CN 202011465232 A CN202011465232 A CN 202011465232A CN 112765155 A CN112765155 A CN 112765155A
- Authority
- CN
- China
- Prior art keywords
- data
- node
- key value
- layer
- key
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/27—Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
- G06F16/278—Data partitioning, e.g. horizontal or vertical partitioning
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/22—Indexing; Data structures therefor; Storage structures
- G06F16/2282—Tablespace storage structures; Management thereof
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/28—Databases characterised by their database models, e.g. relational or object models
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/30—Information retrieval; Database structures therefor; File system structures therefor of unstructured textual data
- G06F16/31—Indexing; Data structures therefor; Storage structures
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/90—Details of database functions independent of the retrieved data types
- G06F16/901—Indexing; Data structures therefor; Storage structures
- G06F16/9024—Graphs; Linked lists
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Databases & Information Systems (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Software Systems (AREA)
- Computing Systems (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
The present application is applicable to the field of block chain technologies, and in particular, to a key value storage method and apparatus based on a block chain, a terminal device, and a medium. The method comprises the steps of searching an intelligent contract, comparing a key value of each data node of a data layer determined by searching with a key value to be inserted to obtain a target data node meeting a preset condition, inserting data to be inserted into a null data node, pointing a pointer of the null data node to a node pointed by the pointer of the target data node, and pointing the pointer of the target data node to the null data node, so that the target data node, the null data node and the node pointed by the pointer of the target data node form an ordered linked list, the ordered linked list is stored in an ordered form and can be convenient for subsequent query and use, the data node with the key value close to the key value to be queried can be found in the ordered linked list during query, a query result is found according to the front-back order of the data node, the whole intelligent contract does not need to be traversed, and the query efficiency is high.
Description
Technical Field
The present application belongs to the technical field of a block chain, and in particular, to a key value storage method and apparatus based on a block chain, a terminal device, and a medium.
Background
In the application of the blockchain technology, all data and computation are put in an intelligent contract in order to ensure the data is not falsifiable and traceable. The existing intelligent contract storage is a storage mode of a hash mapping structure table based on Key-Value (K-V), and the hash mapping structure table of the K-V is an unordered structure, so that a full table needs to be traversed when a group of K-V is queried, and the query efficiency is low.
Disclosure of Invention
The embodiment of the application provides a key value storage method, a key value storage device, terminal equipment and a key value storage medium based on a block chain, and can solve the problem that the query efficiency is low due to the existing unordered key value storage mode.
In a first aspect, an embodiment of the present application provides a key value storage method based on a block chain, where the key value storage method includes:
acquiring a key value to be inserted and a data value corresponding to the key value to be inserted;
searching an intelligent contract and determining a data layer of the intelligent contract;
acquiring key values of all data nodes of the data layer;
respectively comparing the key values of all the data nodes with the key values to be inserted to determine target data nodes, wherein the target data nodes are nodes corresponding to the key values of which the comparison results meet first preset conditions;
determining an empty data node in the data layer, wherein the empty data node refers to a node into which key value data is not inserted;
and inserting the key value to be inserted and the data value into the null data node, pointing the pointer of the null data node to the node pointed by the pointer of the target data node, and pointing the pointer of the target data node to the null data node.
In a second aspect, an embodiment of the present application provides a key value storage apparatus based on a block chain, including:
the insertion data acquisition module is used for acquiring a key value to be inserted and a data value corresponding to the key value to be inserted;
the data layer determining module is used for searching the intelligent contract and determining the data layer of the intelligent contract;
the key value acquisition module is used for acquiring key values of all data nodes of the data layer;
the comparison module is used for comparing the key values of all the data nodes with the key values to be inserted respectively to determine target data nodes, wherein the target data nodes are nodes corresponding to the key values of which the comparison results meet first preset conditions;
a null node determination module, configured to determine a null data node in the data layer, where the null data node is a node into which key value data is not inserted;
and the inserting module is used for inserting the key value to be inserted and the data value into the null data node, pointing the pointer of the null data node to the node pointed by the pointer of the target data node, and pointing the pointer of the target data node to the null data node.
In a third aspect, an embodiment of the present application provides a terminal device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, where the processor implements the key value storage method according to the first aspect when executing the computer program.
In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, where a computer program is stored, and when executed by a processor, the computer program implements the key-value storage method according to the first aspect.
In a fifth aspect, an embodiment of the present application provides a computer program product, which, when running on a terminal device, causes the terminal device to execute the key value storage method according to the first aspect.
Compared with the prior art, the embodiment of the application has the advantages that: the method comprises the steps of searching an intelligent contract, determining a data layer of the intelligent contract, comparing a key value of each data node of the data layer with a key value to be inserted to obtain a target data node meeting preset conditions, inserting the key value to be inserted and the data value into a null data node, pointing a pointer of the null data node to a node pointed by the pointer of the target data node, pointing a pointer of the target data node to the null data node, inserting the key value to be inserted and the data value between the target data node and the node pointed by the pointer of the target data node, enabling the nodes pointed by the pointers of the target data node, the null data node and the target data node to form an ordered linked list, storing in the ordered form to facilitate subsequent query, finding the data node with the key value close to the key value to be queried in the ordered linked list during query, and then, a determined query result is found according to the front-back sequence of the data node, the whole intelligent contract does not need to be traversed, and the query efficiency is high.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings needed to be used in the embodiments or the prior art descriptions will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present application, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without inventive exercise.
Fig. 1 is a schematic flowchart of a block chain-based key value storage method according to a first embodiment of the present application;
fig. 2 is a schematic flowchart of a block chain-based key value storage method according to a second embodiment of the present application;
fig. 3 is a schematic structural diagram of a key value storage device based on a block chain according to a third embodiment of the present application;
fig. 4 is a schematic structural diagram of a terminal device according to a fourth embodiment of the present application.
Detailed Description
In the following description, for purposes of explanation and not limitation, specific details are set forth, such as particular system structures, techniques, etc. in order to provide a thorough understanding of the embodiments of the present application. It will be apparent, however, to one skilled in the art that the present application may be practiced in other embodiments that depart from these specific details. In other instances, detailed descriptions of well-known systems, devices, circuits, and methods are omitted so as not to obscure the description of the present application with unnecessary detail.
It will be understood that the terms "comprises" and/or "comprising," when used in this specification and the appended claims, specify the presence of stated features, integers, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groups thereof.
It should also be understood that the term "and/or" as used in this specification and the appended claims refers to and includes any and all possible combinations of one or more of the associated listed items.
As used in this specification and the appended claims, the term "if" may be interpreted contextually as "when", "upon" or "in response to" determining "or" in response to detecting ". Similarly, the phrase "if it is determined" or "if a [ described condition or event ] is detected" may be interpreted contextually to mean "upon determining" or "in response to determining" or "upon detecting [ described condition or event ]" or "in response to detecting [ described condition or event ]".
Furthermore, in the description of the present application and the appended claims, the terms "first," "second," "third," and the like are used for distinguishing between descriptions and not necessarily for describing or implying relative importance.
Reference throughout this specification to "one embodiment" or "some embodiments," or the like, means that a particular feature, structure, or characteristic described in connection with the embodiment is included in one or more embodiments of the present application. Thus, appearances of the phrases "in one embodiment," "in some embodiments," "in other embodiments," or the like, in various places throughout this specification are not necessarily all referring to the same embodiment, but rather "one or more but not all embodiments" unless specifically stated otherwise. The terms "comprising," "including," "having," and variations thereof mean "including, but not limited to," unless expressly specified otherwise.
The key value storage method based on the block chain can be applied to terminal devices such as a palm computer, a desktop computer, a notebook computer, an ultra-mobile personal computer (UMPC), a netbook, a cloud server, a Personal Digital Assistant (PDA), and the like, and the specific type of the terminal device is not limited in any way in the embodiment of the present application.
It should be understood that, the sequence numbers of the steps in the foregoing embodiments do not imply an execution sequence, and the execution sequence of each process should be determined by its function and inherent logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.
In order to explain the technical means of the present application, the following description will be given by way of specific examples.
Referring to fig. 1, which is a schematic flowchart of a key value storage method based on a block chain according to an embodiment of the present application, where the key value storage method may be used in a terminal device, as shown in the figure, the key value storage method may include the following steps:
step S101, acquiring a key value to be inserted and a data value corresponding to the key value to be inserted.
The key value to be inserted may refer to a key value of data to be stored, which needs to be uplink stored, and the data value of the data to be stored is a data value corresponding to the key value, and in the key value storage, the data value may be represented by a value, for example, k ═ 3, value { \\ QYMC: \ "enterprise name \", \ "ZS \", \ "residence \", \ "CPMC \ product name \", "\" SCDZ \ \ production address "," \ "hb": certificate number "," rq \ \ sign date "," \ "," yxxrq \ "\ valid date \", wherein, the key value is 3, and the data value is "{ \" QYMC \ "enterprise name \", "ZS \", "production address \ Λ, \\ QFRQ \ \ \ "issue date \" YXRQ \ \ \ "effective date \". The uplink storage may be understood as storage on a block chain.
And step S102, searching the intelligent contract and determining the data layer of the intelligent contract.
The intelligent contract may refer to commitments (i.e. data) defined in a digital form, the intelligent contract may include a data layer and an index layer, the data layer stores data, the index layer may be used to query the location of the data in the data layer, and since the definitions of the node data structures of the data layer and the index layer are different, the data layer and the index layer may be determined by searching each layer.
Optionally, searching for the intelligent contract and determining the data layer of the intelligent contract includes:
detecting a node data structure of each layer in the intelligent contract;
and determining the data layer according to the node data structure of each layer.
The nodes can be storage points in which data can be inserted in each layer of the intelligent contract, one node corresponds to one address, when a data layer and an index layer of the intelligent contract are defined, the data layer can store data values, and the index layer cannot store data values, so that the data nodes of the data layer and the index nodes of the index layer have different node data structures, and the positions of the data layers can be determined by detecting the node data structures of each layer.
For example, the data structure of the data nodes of the data layer is:
Class Node<K,V>{
String key;
Object value;
Int next;
}
wherein, the variable key is a key value, the variable value is a data value, and the variable next pointer points to the next data node.
Optionally, after searching the intelligent contract and determining the data layer of the intelligent contract, the method further includes:
detecting whether a first data node of a data layer is an empty data node;
accordingly, obtaining key values of all data nodes of the data layer includes:
and if the first data node is not the empty data node, acquiring key values of all data nodes of the data layer.
After data is inserted into the data node, the key value and the data value corresponding to the key value exist in the data node, so that whether the data node is an empty data node can be determined by detecting whether the key value exists in the data node, for example, if the key value does not exist in the data node, the data node is determined to be an empty data node, and if the key value exists in the data node, the data node is determined not to be an empty data node. Of course, other methods for determining whether the data node is an empty data node are also within the scope of the present application, and are not limited herein.
Optionally, after detecting whether the first data node of the data layer is an empty data node, the method further includes:
and if the first data node is a null data node, inserting the key value to be inserted and the data value into the first data node, and pointing the pointer of the first data node to a successor node of the first data node.
The first data node is empty, which means that no data is inserted in the data layer of the intelligent contract, so that the key value to be inserted and the corresponding data value are only required to be inserted into the first data node; if the pointers in the data nodes of the data layer are all set to point to the next data node, the pointer of the first data node does not need to be adjusted when the key value to be inserted and the corresponding data value are inserted, and if the pointers in the data nodes of the data layer are not set, the pointer of the first data node needs to point to the next data node when the key value to be inserted and the corresponding data value are inserted.
Step S103, key values of all data nodes of the data layer are obtained.
All data nodes in the data layer comprise empty data nodes and data nodes into which key value data has been inserted, and the empty data nodes do not have the key values and other contents, so that the key values of all the data nodes are obtained, namely the key values of the data nodes into which the key value data has been inserted are obtained; when the key value of the data node is acquired, the other contents of the data node are not processed for the moment, for example, the data value stored in the data node is not processed.
And step S104, comparing the key values of all the data nodes with the key values to be inserted respectively, and determining the target data node.
The target data node is a node corresponding to a key value, the comparison result of the key value to be inserted meets a first preset condition, the first preset condition is set according to requirements, a sorting mode needing to refer to the data node is set, the data nodes can be sorted from small to large or from large to small, and the large or small of the target data node is directed at the key value stored in the data node. When sorting is performed from large to small according to the key values, the comparison result is that a key value larger than the key value to be inserted is found, and the key value is closest to the key value to be inserted (i.e., a first preset condition), where the closest key value to be inserted may refer to a key value having a smallest difference with the key value to be inserted among the key values when there are a plurality of key values larger than the key value to be inserted, for example, the key value sorting of all the data nodes is 5, 3, 1, and the key value to be inserted is 2, and then 3 is a value higher than 2 and closest to 2, and thus, the node corresponding to 3 is a target data node; when the key values are sorted from small to large, the comparison result is that a key value smaller than the key value to be inserted is found, and the key value is closest to the key value to be inserted (i.e. a first preset condition), where the closest key value to be inserted may refer to a key value having a smallest difference with the key value to be inserted among the key values when there are a plurality of key values smaller than the key value to be inserted, for example, the key values of the data nodes are sorted to 1, 3, and 5, and the key value to be inserted is 4, then 3 is a value lower than 4 and closest to 4, and thus, the node corresponding to 3 is the target data node.
Step S105, determining an empty data node in the data layer.
After data is inserted into the data node, the key value and the data value corresponding to the key value exist in the data node, and whether the data node is a null data node can be determined by detecting whether the key value exists in the data node, for example, if the key value does not exist in the data node, the data node is determined to be a null data node, and if the key value exists in the data node, the data node is determined not to be a null data node. Of course, other methods for determining whether the data node is an empty data node are also within the scope of the present application, and are not limited herein.
Optionally, determining a null data node in the data layer includes:
acquiring a pointer of a first data node of a data layer, and taking the pointer of the first data node as a reference pointer;
detecting whether key value data are stored in a data node pointed by a reference pointer;
if the key value data is not stored in the data node pointed by the reference pointer, determining that the data node is a null data node;
and if the data node pointed by the reference pointer stores the key-value data, taking the pointer of the data node as the reference pointer, and returning to execute detection whether the data node pointed by the reference pointer stores the key-value data or not.
The first data node of the data layer may refer to a data node corresponding to an initial position of the data layer, the data node pointed by the pointer may be found according to the pointer of the first data node, the data node is used as a current processing data node to determine whether the current processing data node is empty, if not, a next data node (the data node pointed by the pointer of the current processing data node) is determined whether the current processing data node is empty, and the data nodes are sequentially traversed until an empty data node is determined or the empty data node cannot be found in the data layer.
And S106, inserting the key value and the data value to be inserted into the empty data node, enabling the pointer of the empty data node to point to the node pointed by the pointer of the target data node, and enabling the pointer of the target data node to point to the empty data node.
The step of inserting the key value to be inserted and the corresponding data value into the empty data node may refer to filling a variable key in the empty data node as the key value to be inserted and filling a variable value in the empty data node as the data value; for convenience of understanding, the node pointed to by the pointer of the target data node is defined as a subsequent data node, the pointer of the null data node points to the subsequent data node, and in order to maintain the ordering of the data nodes, the pointer of the target data node no longer points to the subsequent data node, the pointer needs to be updated to point to the null data node, for example, the key value of the target data node is 1, the key value of the null data node is 2, and the key value of the subsequent data node is 3, and according to the pointing direction of the pointer, the target data node, the null data node, and the subsequent data node, namely 1-2-3, can be determined to be in order storage.
According to the method and the device for inquiring the key value, the key value to be inserted and the data value are inserted between the target data node and the node pointed by the pointer of the target data node, so that the node pointed by the pointer of the target data node, the empty data node and the target data node form the ordered linked list, the ordered linked list is stored in the ordered form, subsequent inquiry can be facilitated, the data node with the key value close to the key value to be inquired can be found in the ordered linked list during inquiry, the inquiry result is determined according to the front and back sequence of the data node, the whole intelligent contract does not need to be traversed, and the inquiry efficiency is high.
Referring to fig. 2, which is a schematic flowchart of a key value storage method based on a block chain according to a second embodiment of the present application, where the key value storage method is applicable to a terminal device, as shown in the figure, the key value storage method may include the following steps:
step S201, a key value to be inserted and a data value corresponding to the key value to be inserted are obtained.
Step S202, searching the intelligent contract and determining the data layer of the intelligent contract.
Step S203, key values of all data nodes of the data layer are obtained.
And S204, comparing the key values of all the data nodes with the key values to be inserted respectively, and determining the target data node.
Step S205, an empty data node in the data layer is determined.
Step S206, inserting the key value and the data value to be inserted into the empty data node, enabling the pointer of the empty data node to point to the node pointed by the pointer of the target data node, and enabling the pointer of the target data node to point to the empty data node.
The contents of steps S201 to S206 are the same as those of steps S101 to S106, and the descriptions of steps S101 to S106 can be referred to, and are not repeated herein.
And step S207, acquiring the maximum layer number of the index layer of the intelligent contract.
After the key value and the data value to be inserted are inserted into the empty data node, or after the key value and the data value to be inserted are inserted into the first data node, corresponding information needs to be stored into the index layer for the convenience of query use, the index layer of the intelligent contract may be set to be one layer or multiple layers, the higher the level of the index layer close to the data layer is (the larger the number of layers is), and the number of layers, namely the maximum number of layers, of the index layer in the intelligent contract is determined when the intelligent contract is designed.
In step S208, a target layer number is acquired.
The target layer number is an integer greater than zero and less than the maximum layer number, and the target layer number is any layer number below the maximum layer number, and the value of the target layer number may be generated by a random algorithm, for example, the maximum layer number is 3, and the target layer number is one of 1 and 2.
Step S209, the key value to be inserted is inserted into the empty index node of each target index layer.
The empty index node refers to a node without a key value inserted, and the target index layer comprises an index layer corresponding to the target layer number, an index layer corresponding to the maximum layer number and an index layer with the layer number between the target layer number and the maximum layer number; for example, if the maximum number of layers is 3 and the number of target layers is 1, the number of target index layers is 1, 2, and 3, and if the maximum number of layers is 3 and the number of target layers is 2, the number of target index layers is 2 and 3, so that resource waste caused by storing one index data in each index layer is avoided, and meanwhile, storing index data in multiple layers can help to improve the hit rate of query.
Optionally, the index node of the index layer of the intelligent contract further includes: a pointer for pointing to a node data structure of a next level indicating a level where the index node is located, a pointer for pointing to a node corresponding to the index node in the next level, and a pointer for pointing to a succeeding node of the index node;
the key value storage method further comprises:
acquiring a key value to be searched;
acquiring a key value of a first index node of an index layer of the intelligent contract, taking the key value of the first index node as a reference key value, and taking a layer where the first index node is located as a reference layer;
detecting whether the key value to be searched is the same as the reference key value;
if the key value to be searched is different from the reference key value, taking the key value of the successor node pointed by the pointer of the index node corresponding to the reference key value as the reference key value, and returning to execute detection to detect whether the key value to be searched is the same as the reference key value;
if the reference key value which is the same as the key value to be searched is not detected in the reference layer, taking the key value of the first index node of the next level of the reference layer as the reference key value, taking the next level of the reference layer as the reference layer, and returning to detect whether the key value to be searched is the same as the reference key value or not;
if a reference key value identical to the key value to be searched is detected in the reference layer, determining the position of the data value corresponding to the key value to be searched in the data layer according to a pointer which is used for pointing to a node data structure of a next level of a layer where the index node is located in the index node corresponding to the reference key value and a pointer which is used for pointing to a node corresponding to the index node in the next level;
and if the key values identical to the key values to be searched do not exist in all the index layers of the intelligent contract, returning the information of the query failure.
When querying, taking a key value to be searched as a reference, sequentially comparing the key value of each index node from a first index node of an index layer until an index node corresponding to the key value same as the key value to be searched (i.e. an index node corresponding to a reference key value) is found, for example, if the key value same as the key value to be searched is found in the first index layer, the index node corresponding to the key value is the index node corresponding to the reference key value; if the index layer comprises at least two layers, after the index node corresponding to the key value to be searched cannot be found after traversing one layer, entering the next layer for comparison query until the traversing of the whole index layer is completed, if the index node corresponding to the key value to be searched cannot be found after traversing the whole index layer, outputting information such as query failure and the like, and if the index node corresponding to the key value to be searched is found, determining the position of the key value to be searched in the data layer according to a pointer in the index node for pointing to a node data structure of the next level of the layer where the index node is located and a pointer for pointing to a node in the next level corresponding to the index node, namely completing the query.
For example, the data structure of an index node in the index layer is:
Class Index<K,V>{
String key;
String nextContractAddress;
Index nextContractindex;
Int next;
}
the variable key is a data node associated with the index node, the variable nextContractAddress pointer points to a node data structure of a next level of a layer where the index node is located, the variable nextContractindex pointer points to a node corresponding to the index node in the next level of the layer where the index node is located, and the variable right pointer points to a successor node of the index node.
According to the method and the device, the key value to be inserted and the position of the key value to be inserted in the data layer are inserted into the index layer of the intelligent contract, so that the corresponding data position in the data layer can be directly inquired from the index layer according to the key value, and the inquiry efficiency is improved.
Corresponding to the key value storage method based on the block chain in the foregoing embodiment, fig. 3 shows a block diagram of a key value storage apparatus based on the block chain provided in the third embodiment of the present application, and for convenience of description, only the parts related to the embodiment of the present application are shown.
Referring to fig. 3, the key value storage device includes:
the insertion data acquisition module 31 is configured to acquire a key value to be inserted and a data value corresponding to the key value to be inserted;
the data layer determining module 32 is used for searching the intelligent contract and determining the data layer of the intelligent contract;
the data key value acquisition module 33 is configured to acquire key values of all data nodes in the data layer;
the comparison module 34 is configured to compare the key values of all the data nodes with the key values to be inserted respectively, and determine a target data node, where the target data node is a node corresponding to the key value whose comparison result with the key value to be inserted meets a first preset condition;
a null node determining module 35, configured to determine a null data node in the data layer, where the null data node refers to a node into which key value data is not inserted;
the first inserting module 36 is configured to insert the key value to be inserted and the data value into the null data node, point the pointer of the null data node to the node pointed by the pointer of the target data node, and point the pointer of the target data node to the null data node.
Optionally, the key value storage device further includes:
the first detection module is used for detecting whether a first data node of a data layer is a null data node after searching the intelligent contract and determining the data layer of the intelligent contract;
accordingly, the key value obtaining module 33 is specifically configured to:
and if the first data node is not the empty data node, acquiring key values of all data nodes of the data layer.
Optionally, the key value storage device further includes:
and the second insertion module is used for inserting the key value and the data value to be inserted into the first data node and pointing the pointer of the first data node to the successor node of the first data node if the first data node is a null data node.
Optionally, the empty node determining module 35 includes:
the pointer acquisition unit is used for acquiring a pointer of a first data node of the data layer and taking the pointer of the first data node as a reference pointer;
the node detection unit is used for detecting whether the data node pointed by the reference pointer stores key value data or not;
the node determining unit is used for determining that the data node pointed by the reference pointer is a null data node if the key value data is not stored in the data node;
and the first return execution unit is used for taking the pointer of the data node as a reference pointer and returning to execute detection whether the key-value data is stored in the data node pointed by the reference pointer if the key-value data is stored in the data node pointed by the reference pointer.
Optionally, the key value storage device further includes:
the maximum layer number obtaining module is used for obtaining the maximum layer number of the index layer of the intelligent contract after the key value and the data value to be inserted are inserted into the empty data node or the first data node;
the target layer number acquisition module is used for acquiring a target layer number, wherein the target layer number is an integer which is larger than zero and smaller than the maximum layer number;
and the third inserting module is used for inserting the key value to be inserted into the empty index node of each target index layer, wherein the target index layers comprise index layers corresponding to the number of target layers, index layers corresponding to the maximum number of layers and index layers with the number of layers between the number of target layers and the maximum number of layers.
Optionally, the data layer determining module 32 includes:
the structure detection unit is used for detecting the node data structure of each layer in the intelligent contract;
and the data layer determining unit is used for determining the data layer according to the node data structure of each layer.
Optionally, the index node of the index layer of the intelligent contract further includes: a pointer for pointing to a node data structure of a next level indicating a level where the index node is located, a pointer for pointing to a node corresponding to the index node in the next level, and a pointer for pointing to a succeeding node of the index node;
the key value storage device further includes:
the search data acquisition module is used for acquiring a key value to be searched;
the index key value acquisition module is used for acquiring the key value of the first index node of the index layer of the intelligent contract, taking the key value of the first index node as a reference key value and taking the layer where the first index node is as a reference layer;
the second detection module is used for detecting whether the key value to be searched is the same as the reference key value;
the second return execution module is used for taking the key value of the successor node pointed by the pointer of the index node corresponding to the reference key value as the reference key value if the key value to be searched is different from the reference key value, and returning to execute detection to detect whether the key value to be searched is the same as the reference key value;
a third return execution module, configured to, if a reference key value that is the same as the key value to be searched is not detected in the reference layer, take the key value of the first index node of the next level of the reference layer as the reference key value, take the next level of the reference layer as the reference layer, and return to execute detection of whether the key value to be searched is the same as the reference key value;
the position determining module is used for determining the position of the data value corresponding to the key value to be searched in the data layer according to a pointer which is used for pointing to a node data structure of a next level of a layer where the index node is located in the index node corresponding to the reference key value and a pointer which is used for pointing to a node corresponding to the index node in the next level if the reference key value which is the same as the key value to be searched is detected in the reference layer;
and the query information feedback module is used for returning the information of the query failure if the key value which is the same as the key value to be searched does not exist in all the index layers of the intelligent contract.
It should be noted that, because the contents of information interaction, execution process, and the like between the modules are based on the same concept as that of the embodiment of the method of the present application, specific functions and technical effects thereof may be specifically referred to a part of the embodiment of the method, and details are not described here.
Fig. 4 is a schematic structural diagram of a terminal device according to a fourth embodiment of the present application. As shown in fig. 4, the terminal device 4 of this embodiment includes: at least one processor 40 (only one shown in fig. 4), a memory 41, and a computer program 42 stored in the memory 41 and executable on the at least one processor 40, the processor 40 implementing the steps in any of the various blockchain-based key-value storage method embodiments described above when executing the computer program 42.
The terminal device may include, but is not limited to, a processor 40, a memory 41. Those skilled in the art will appreciate that fig. 4 is merely an example of the terminal device 4, and does not constitute a limitation of the terminal device 4, and may include more or less components than those shown, or combine some components, or different components, such as an input-output device, a network access device, and the like.
The Processor 40 may be a Central Processing Unit (CPU), and the Processor 40 may be other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic device, discrete hardware component, or the like. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like.
The memory 41 may in some embodiments be an internal storage unit of the terminal device 4, such as a hard disk or a memory of the terminal device 4. The memory 41 may be an external storage device of the terminal device 4 in other embodiments, such as a plug-in hard disk provided on the terminal device 4, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like. Further, the memory 41 may also include both an internal storage unit of the terminal device 4 and an external storage device. The memory 41 is used for storing an operating system, an application program, a BootLoader (BootLoader), data, and other programs, such as program codes of a computer program. The memory 41 may also be used to temporarily store data that has been output or is to be output.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units and modules is illustrated, and in practical applications, the above-mentioned function distribution may be performed by different functional units and modules according to needs, that is, the internal structure of the apparatus is divided into different functional units or modules, so as to perform all or part of the functions described above. Each functional unit and module in the embodiments may be integrated in one processing unit, or each unit may exist alone physically, or two or more units are integrated in one unit, and the integrated unit may be implemented in a form of hardware, or in a form of software functional unit. In addition, specific names of the functional units and modules are only for convenience of distinguishing from each other, and are not used for limiting the protection scope of the present application. The specific working processes of the units and modules in the above-mentioned apparatus may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again. The integrated unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, all or part of the flow of the method of the embodiments described above can be implemented by a computer program, which can be stored in a computer readable storage medium and can implement the steps of the embodiments of the methods described above when the computer program is executed by a processor. Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer readable medium may include at least: any entity or device capable of carrying computer program code, recording medium, computer Memory, Read-Only Memory (ROM), Random-Access Memory (RAM), electrical carrier signals, telecommunications signals, and software distribution media. Such as a usb-disk, a removable hard disk, a magnetic or optical disk, etc. In certain jurisdictions, computer-readable media may not be an electrical carrier signal or a telecommunications signal in accordance with legislative and patent practice.
When the computer program product runs on the terminal device, the steps in the method embodiments can be implemented when the terminal device executes the computer program product.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and reference may be made to the related descriptions of other embodiments for parts that are not described or illustrated in a certain embodiment.
Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
In the embodiments provided in the present application, it should be understood that the disclosed apparatus/terminal device and method may be implemented in other ways. For example, the above-described embodiments of the apparatus/terminal device are merely illustrative, and for example, a module or a unit may be divided into only one logical function, and may be implemented in other ways, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form.
Units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
The above embodiments are only used to illustrate the technical solutions of the present application, and not to limit the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not substantially depart from the spirit and scope of the embodiments of the present application and are intended to be included within the scope of the present application.
Claims (10)
1. A key value storage method based on a block chain is characterized by comprising the following steps:
acquiring a key value to be inserted and a data value corresponding to the key value to be inserted;
searching an intelligent contract and determining a data layer of the intelligent contract;
acquiring key values of all data nodes of the data layer;
respectively comparing the key values of all the data nodes with the key values to be inserted to determine target data nodes, wherein the target data nodes are nodes corresponding to the key values of which the comparison results meet first preset conditions;
determining an empty data node in the data layer, wherein the empty data node refers to a node into which key value data is not inserted;
and inserting the key value to be inserted and the data value into the null data node, pointing the pointer of the null data node to the node pointed by the pointer of the target data node, and pointing the pointer of the target data node to the null data node.
2. The key-value storage method of claim 1, wherein after the searching the intelligent contracts to determine the data tier of the intelligent contracts, further comprising:
detecting whether a first data node of the data layer is an empty data node;
correspondingly, the acquiring key values of all data nodes of the data layer includes:
and if the first data node is not a null data node, acquiring key values of all data nodes of the data layer.
3. The key-value storage method of claim 2, wherein after detecting whether the first data node of the data layer is an empty data node, further comprising:
and if the first data node is a null data node, inserting the key value to be inserted and the data value into the first data node, and pointing the pointer of the first data node to a subsequent node of the first data node.
4. The key-value storage method of claim 1, wherein the determining an empty data node in the data layer comprises:
acquiring a pointer of a first data node of the data layer, and taking the pointer of the first data node as a reference pointer;
detecting whether the data node pointed by the reference pointer stores key value data or not;
if the key value data is not stored in the data node pointed by the reference pointer, determining that the data node is a null data node;
and if the data node pointed by the reference pointer stores the key-value data, taking the pointer of the data node as the reference pointer, and returning to execute the detection of whether the data node pointed by the reference pointer stores the key-value data or not.
5. The key-value storage method of claim 1, wherein after inserting the to-be-inserted key value and the data value into the null data node, further comprising:
acquiring the maximum number of index layers of the intelligent contract;
acquiring a target layer number, wherein the target layer number is an integer which is larger than zero and smaller than the maximum layer number;
and inserting the key value to be inserted into a null index node of each target index layer, wherein the target index layers comprise index layers corresponding to the target layer number, index layers corresponding to the maximum layer number and index layers with the layer number between the target layer number and the maximum layer number, and the null index node refers to a node without the key value inserted.
6. The key-value storage method of claim 5, wherein the inode of the index layer of the intelligent contract further comprises: a pointer for pointing to a node data structure of a next level indicating a level where the index node is located, a pointer for pointing to a node corresponding to the index node in the next level, and a pointer for pointing to a succeeding node of the index node;
the key value storage method further comprises:
acquiring a key value to be searched;
acquiring a key value of a first index node of an index layer of the intelligent contract, taking the key value of the first index node as a reference key value, and taking a layer where the first index node is located as a reference layer;
detecting whether the key value to be searched is the same as the reference key value;
if the key value to be searched is different from the reference key value, taking the key value of the successor node pointed by the pointer of the index node corresponding to the reference key value as the reference key value, and returning to execute the detection whether the key value to be searched is the same as the reference key value;
if the reference key value identical to the key value to be searched is not detected in the reference layer, taking the key value of the first index node of the next level of the reference layer as the reference key value, taking the next level of the reference layer as the reference layer, and returning to execute the detection whether the key value to be searched and the reference key value are identical or not;
if the reference key value identical to the key value to be searched is detected in the reference layer, determining the position of the data value corresponding to the key value to be searched in the data layer according to a pointer which is used for pointing to a node data structure of a next level representing the layer where the index node is located in the index node corresponding to the reference key value and a pointer which is used for pointing to a node corresponding to the index node in the next level;
and if the key value identical to the key value to be searched does not exist in all the index layers of the intelligent contract, returning the information of the query failure.
7. The key-value storage method according to any one of claims 1 to 6, wherein the searching for the intelligent contracts and determining the data tier of the intelligent contracts comprises:
detecting a node data structure of each layer in the intelligent contract;
and determining the data layer according to the node data structure of each layer.
8. A block chain-based key-value store, comprising:
the insertion data acquisition module is used for acquiring a key value to be inserted and a data value corresponding to the key value to be inserted;
the data layer determining module is used for searching the intelligent contract and determining the data layer of the intelligent contract;
the data key value acquisition module is used for acquiring key values of all data nodes of the data layer;
the comparison module is used for comparing the key values of all the data nodes with the key values to be inserted respectively to determine target data nodes, wherein the target data nodes are nodes corresponding to the key values of which the comparison results meet first preset conditions;
a null node determination module, configured to determine a null data node in the data layer, where the null data node is a node into which key value data is not inserted;
the first inserting module is used for inserting the key value to be inserted and the data value into the null data node, enabling the pointer of the null data node to point to the node pointed by the pointer of the target data node, and enabling the pointer of the target data node to point to the null data node.
9. A terminal device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that the processor implements the key-value storage method according to any one of claims 1 to 7 when executing the computer program.
10. A computer-readable storage medium, in which a computer program is stored, which, when being executed by a processor, implements the key-value storage method according to any one of claims 1 to 7.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011465232.6A CN112765155B (en) | 2020-12-14 | 2020-12-14 | Block chain-based key value storage method and device, terminal equipment and medium |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202011465232.6A CN112765155B (en) | 2020-12-14 | 2020-12-14 | Block chain-based key value storage method and device, terminal equipment and medium |
Publications (2)
Publication Number | Publication Date |
---|---|
CN112765155A true CN112765155A (en) | 2021-05-07 |
CN112765155B CN112765155B (en) | 2022-05-31 |
Family
ID=75693696
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202011465232.6A Active CN112765155B (en) | 2020-12-14 | 2020-12-14 | Block chain-based key value storage method and device, terminal equipment and medium |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN112765155B (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113672632A (en) * | 2021-08-06 | 2021-11-19 | 戈尔特西斯科技(济南)有限公司 | Quick query and call method for change records of historical data on chain based on intelligent contract |
CN113989000A (en) * | 2021-10-19 | 2022-01-28 | 深圳前海微众银行股份有限公司 | Method and device for processing uplink information of block chain |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106991102A (en) * | 2016-01-21 | 2017-07-28 | 腾讯科技(深圳)有限公司 | The processing method and processing system of key-value pair in inverted index |
CN108446376A (en) * | 2018-03-16 | 2018-08-24 | 众安信息技术服务有限公司 | Date storage method and device |
CN109165224A (en) * | 2018-08-24 | 2019-01-08 | 东北大学 | A kind of indexing means being directed to keyword key on block chain database |
CN110515957A (en) * | 2019-09-02 | 2019-11-29 | 深圳市网心科技有限公司 | A kind of method, system, equipment and the readable storage medium storing program for executing of the storage of block chain data |
US20200201833A1 (en) * | 2019-07-29 | 2020-06-25 | Alibaba Group Holding Limited | Creating index in blockchain-type ledger |
CN112035491A (en) * | 2020-09-30 | 2020-12-04 | 中山大学 | Data storage method based on block chain, electronic integral processing method and system |
-
2020
- 2020-12-14 CN CN202011465232.6A patent/CN112765155B/en active Active
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN106991102A (en) * | 2016-01-21 | 2017-07-28 | 腾讯科技(深圳)有限公司 | The processing method and processing system of key-value pair in inverted index |
CN108446376A (en) * | 2018-03-16 | 2018-08-24 | 众安信息技术服务有限公司 | Date storage method and device |
CN109165224A (en) * | 2018-08-24 | 2019-01-08 | 东北大学 | A kind of indexing means being directed to keyword key on block chain database |
US20200201833A1 (en) * | 2019-07-29 | 2020-06-25 | Alibaba Group Holding Limited | Creating index in blockchain-type ledger |
CN110515957A (en) * | 2019-09-02 | 2019-11-29 | 深圳市网心科技有限公司 | A kind of method, system, equipment and the readable storage medium storing program for executing of the storage of block chain data |
CN112035491A (en) * | 2020-09-30 | 2020-12-04 | 中山大学 | Data storage method based on block chain, electronic integral processing method and system |
Cited By (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN113672632A (en) * | 2021-08-06 | 2021-11-19 | 戈尔特西斯科技(济南)有限公司 | Quick query and call method for change records of historical data on chain based on intelligent contract |
CN113989000A (en) * | 2021-10-19 | 2022-01-28 | 深圳前海微众银行股份有限公司 | Method and device for processing uplink information of block chain |
WO2023065476A1 (en) * | 2021-10-19 | 2023-04-27 | 深圳前海微众银行股份有限公司 | Method and apparatus for processing information to be uploaded to blockchain |
Also Published As
Publication number | Publication date |
---|---|
CN112765155B (en) | 2022-05-31 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
CN107729371B (en) | Data indexing and querying method, device, equipment and storage medium of block chain | |
CN110597855B (en) | Data query method, terminal device and computer readable storage medium | |
CN111352902A (en) | Log processing method and device, terminal equipment and storage medium | |
CN112765155B (en) | Block chain-based key value storage method and device, terminal equipment and medium | |
CN110781203A (en) | Method and device for determining data width table | |
CN111104426B (en) | Data query method and system | |
CN110442773A (en) | Distributed system interior joint caching method, system, device and computer media | |
CN109739433A (en) | The method and terminal device of data processing | |
US20140019454A1 (en) | Systems and Methods for Caching Data Object Identifiers | |
CN108268503B (en) | Database storage and query method and device | |
CN111488371A (en) | Data query method and device | |
CN106815179B (en) | Text similarity determination method and device | |
CN111221742B (en) | Test case updating method and device, storage medium and server | |
CN113722600A (en) | Data query method, device, equipment and product applied to big data | |
CN103995831B (en) | Object processing method, system and device based on similarity among objects | |
CN113568877B (en) | File merging method and device, electronic equipment and storage medium | |
US8688605B2 (en) | Incremental context accumulating systems with information co-location for high performance and real-time decisioning systems | |
CN114443701A (en) | Data stream processing method, electronic device and computer program product | |
CN109992708B (en) | Method, device, equipment and storage medium for metadata query | |
CN111695153A (en) | K-anonymization method, system, equipment and readable storage medium for multi-branch forest | |
CN113256301B (en) | Data shielding method, device, server and medium | |
CN110709824B (en) | Data query method and device | |
Warashina et al. | Efficient k-nearest neighbor graph construction using mapreduce for large-scale data sets | |
CN113419792A (en) | Event processing method and device, terminal equipment and storage medium | |
CN114691610A (en) | Directory processing method and device, storage medium and processor |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |