Disclosure of Invention
The invention provides a method and a device for operating blockchain data, which solve the problem of low read-write efficiency when a main key corresponds to more data records in the prior art.
The invention provides an operation method of blockchain data, which comprises the steps that a blockchain link point obtains a data operation instruction, the data operation instruction comprises a first data record with a target main key, the blockchain node stores the data record in a key value pair form in a multi-data page mode, each main key corresponds to at least one key value, the blockchain node determines a page to be operated of the first data record, the blockchain link point reads an existing data record with the target main key in the page to be operated, and the blockchain node performs data operation on the existing data record according to the data operation instruction.
According to the method, the blockchain node stores data records in the form of key value pairs in a multi-data page mode, each primary key corresponds to at least one key value, after the blockchain node acquires a data operation instruction, the data operation instruction comprises a first data record with a target primary key, all key values of the primary key stored in the multi-data page do not need to be acquired, a page to be operated of the first data record is determined firstly, then the existing data record with the target primary key in the page to be operated is read, and data operation is carried out on the existing data record according to the data operation instruction, so that all key values of the primary key do not need to be acquired, and the read-write performance of the data record can be greatly improved.
In an optional implementation manner, the data operation instruction is a new instruction, the method further comprises the steps that the blockchain node generates target index information of the first data record according to the corresponding relation between a value of a preset object in the first data record and the page to be operated, the blockchain node determines a first index page in an index library, which is reserved for storing the target index information in the index library, according to the value of the preset object in the first data record, and the blockchain node stores the target index information to the index library according to the first index page.
In the method, the blockchain node generates the target index information of the first data record according to the corresponding relation between the value of the preset object in the first data record and the page to be operated, determines the first index page according to the value of the preset object in the first data record, and stores the target index information into the index library, so that the target index information of the first data record is recorded after the first data record is newly added, and the subsequent searching of the first data record can be facilitated.
In an alternative implementation mode, the index information in the index pages is arranged according to the preset sequence according to the value of the preset object, the blockchain node stores the target index information in the index library according to the first index page, the blockchain node determines the page position ready to store the first index page according to the value of the preset object, if the page position ready to store the first index page is the middle part of the first index page and the first index page is full, the blockchain node splits the first index page into a second index page and a third index page from the middle part of the first index page, the blockchain node stores the index information before the middle part of the first index page and the target index information in the second index page, and the blockchain node stores the index information after the middle part of the first index page in the third index page.
In the above method, after determining the page position of the first index page to be stored according to the value of the preset object, if the page position of the first index page to be stored is the middle of the first index page and the first index page is full, the blockchain node may be split into the second index page and the third index page without affecting the preset sequence between the index information, so as to open up a space capable of storing the index information again and reconstruct the index page, thereby providing a method for adding the index information without changing the preset sequence between the index information.
In an alternative implementation manner, the index information in the index pages is arranged according to the preset sequence according to the value of the preset object, the blockchain node stores the target index information into the index library according to the first index page, the method comprises the steps that the blockchain node determines the page position ready to store the first index page according to the value of the preset object, and if the page position ready to store the first index page is the head part or the tail part of the first index page and the first index page is full, the blockchain node creates a fourth index page and stores the target index information into the fourth index page.
In the above manner, after determining the page position of the first index page to be stored according to the value of the preset object, if the page position of the first index page to be stored is the head or the tail of the first index page and the first index page is full, the fourth index page can be created under the condition that the preset sequence between the index information is not affected, so that a new space for storing the index information is opened up, and the index page is reconstructed, thereby providing a method for adding the index information in the preset sequence between the index information without changing.
In an alternative implementation manner, the data operation instruction is a new instruction, and the blockchain node performs data operation on the existing data record according to the data operation instruction, and the method comprises the step that the blockchain node adds the first data record to the existing data record according to the existing data record and the first data record, so that the data record of the target main key in the page to be operated is updated.
In the above manner, when the data operation instruction is a new instruction, the blockchain node can add the first data record to the existing data record only by the existing data record and the first data record of the page to be operated without acquiring all key values according to the target main key, so that a method for updating the data record of the target main key in the page to be operated with higher performance is provided.
In an optional implementation manner, the data operation instruction is a modification instruction or a query instruction, the blockchain node determines a page to be operated of the first data record, the method comprises the steps that the blockchain node determines a first index page corresponding to the first data record according to a value of a preset object in the first data record, a plurality of pieces of index information are recorded in the first index page, a corresponding relation between the value of the preset object and the data page is recorded in each piece of index information, the blockchain node determines target index information corresponding to the first data record from the first index page, and the blockchain node determines the page to be operated according to the target index information.
In the above manner, since a plurality of pieces of index information are recorded in the first index page, wherein the corresponding relation between the value of the preset object and the data page is recorded in each piece of index information, and the blockchain node can determine the first index page corresponding to the first data record according to the value of the preset object in the first data record, the blockchain node can quickly find the target index information and the page to be operated, so that all the data pages do not need to be traversed, and the query performance of the data is improved.
In an alternative implementation mode, the data operation instruction is a modification instruction, the modification instruction further comprises a second data record with a target main key, the modification instruction is used for modifying the first data record into the second data record, the existing data record comprises the first data record, the blockchain node performs data operation on the existing data record according to the data operation instruction, and the blockchain node modifies the first data record in the existing data record into the second data record according to the existing data record and the second data record, so that the existing data record of the target main key in the page to be operated is updated.
In the above manner, when the data operation instruction is a modification instruction, the modification instruction further includes a second data record having a target main key, and the modification instruction is used for modifying the first data record into the second data record, and since the existing data record includes the first data record, the first data record in the existing data record can be modified into the second data record only by reading a page to be operated, thereby improving the modification performance of data.
In a second aspect, the invention provides an operating device of blockchain data, which comprises an acquisition module, a processing module and a data operation module, wherein the acquisition module is used for acquiring a data operation instruction, the data operation instruction comprises a first data record with a target main key, the blockchain node stores the data record in a key value pair form in a multi-data page mode, each main key corresponds to at least one key value, the processing module is used for determining a page to be operated of the first data record, and is used for reading an existing data record with the target main key in the page to be operated and performing data operation on the existing data record according to the data operation instruction.
In an alternative implementation manner, the processing module is further configured to generate target index information of the first data record according to a corresponding relationship between a value of a preset object in the first data record and the page to be operated, determine a first index page in an index library, in which the target index information is prepared to be stored, according to the value of the preset object in the first data record, and store the target index information to the index library according to the first index page.
In an alternative implementation manner, the index information in the index pages is arranged according to a preset sequence according to the value of the preset object, the processing module is specifically configured to determine a page position to be stored in the first index page according to the value of the preset object, split the first index page into a second index page and a third index page from the middle of the first index page if the page position to be stored in the first index page is the middle of the first index page and the first index page is full, store index information before the middle of the first index page and the target index information to the second index page, and store index information after the middle of the first index page to the third index page.
In an optional implementation manner, the index information in the index pages is arranged according to the preset sequence according to the value of the preset object, the processing module is specifically configured to determine a page position to be stored in the first index page according to the value of the preset object, and if the page position to be stored in the first index page is the head or the tail of the first index page and the first index page is full, create a fourth index page and store the target index information to the fourth index page.
In an optional implementation manner, the data operation instruction is a new instruction, and the processing module is specifically configured to add the first data record to the existing data record according to the existing data record and the first data record, so as to update the data record of the target main key in the page to be operated.
In an optional implementation manner, the data operation instruction is a modification instruction or a query instruction, and the processing module is specifically configured to determine a first index page corresponding to the first data record according to a value of a preset object in the first data record, record a plurality of pieces of index information in the first index page, record a corresponding relation between the value of the preset object and the data page in each piece of index information, determine target index information corresponding to the first data record from the first index page, and determine the page to be operated according to the target index information.
In an alternative implementation mode, the data operation instruction is a modification instruction, the modification instruction further comprises a second data record with a target main key, the modification instruction is used for modifying the first data record into the second data record, the existing data record comprises the first data record, and the processing module is specifically used for modifying the first data record in the existing data record into the second data record according to the existing data record and the second data record, so that the existing data record of the target main key in the page to be operated is updated.
The advantages of the second aspect and the second aspect may be referred to the advantages of the first aspect and the first aspect, and will not be described here again.
In a third aspect, the present invention provides a computer device comprising a program or instructions which, when executed, is operable to perform the above-described first aspect and the respective alternative methods of the first aspect.
In a fourth aspect, the present invention provides a storage medium comprising a program or instructions which, when executed, is adapted to carry out the above-described first aspect and the respective alternative methods of the first aspect.
Detailed Description
In order to better understand the above technical solutions, the following detailed description will be made with reference to the accompanying drawings and specific embodiments of the present application, and it should be understood that specific features in the embodiments and examples of the present application are detailed descriptions of the technical solutions of the present application, and not limiting the technical solutions of the present application, and the technical features in the embodiments and examples of the present application may be combined with each other without conflict.
And the mapping from the main key of the distributed storage (ADVANCED MASS Database, AMDB) to the corresponding entry in the storage table can be added, deleted and checked based on the main key of the AMDB, and the condition screening is supported.
And the data record corresponds to one row in the storage table, each row takes a column name as a key, and the corresponding value is taken as a key value to form a key value pair (KV) structure. Each data record has its own AMDB key, and different data records are allowed to have the same AMDB key.
And the data record group is used for storing the data records with the same main key. The primary key of the ambb is different from the primary key in the conventional database, and the ambb primary key is used for indicating which primary key the data record belongs to, and the data records of the same primary key are stored in the same data record group.
Screening conditions, namely, a censoring and checking interface in a storage table supports the incoming screening conditions, and the three interfaces return the result after screening according to the conditions. If the screening conditions are empty, no screening is performed.
As shown in Table 1, the above-mentioned terms are explained by taking a material registry taken by a staff of a certain company as an example.
Name (Main key) |
Data record number |
Data record name |
Alice (Alice) |
1001001 |
Notebook computer |
Alice (Alice) |
1001002 |
Display device |
Bob (Bob) |
1002001 |
Notebook computer |
Cris (Kerisi) |
1003001 |
Desk computer |
TABLE 1
Specifically, the name is a primary key of the distributed storage. One data record for each behavior in table 1. There are a total of 4 data records, each storing data in key-value pairs. The 4 data were recorded as follows:
data record 1 { name: alice, data record number: 1001001, data record name: notebook };
data record 2 { name: alice, data record number: 1001002, data record name: display };
data record 3 { name: bob, data record number: 1002001, data record name: notebook };
data record 4 { name: kris, data record number: 1003001, data record name: desktop }.
The storage table stores 3 data record group objects by taking names as main keys. Alice's 2 records are stored in the 1 st data record group, bob's 1 record is stored in the 2 nd data record group, and kris's one record is stored in the 3 rd data record group. When the query interface of the storage list class is called, the query interface needs to specify a main key and a screening condition in the distributed storage, the main key of the queried distributed storage is set as alice, and the screening condition is that the condition number=1001001, and the data record 1 can be queried.
During operation of a financial institution (banking, insurance or securities institution) in performing a business (e.g., loan, deposit, etc. of a bank), data is often stored at blockchain nodes by storing tables. The memory table is read and written in a whole mode to operate the key value of the main key. When the data record corresponding to one main key is more, the reading and writing efficiency is very low. This situation does not meet the requirements of financial institutions such as banks, and cannot guarantee efficient operation of various businesses of the financial institutions.
To this end, as shown in fig. 1, the present application provides a method of operating blockchain data.
And step 101, obtaining a data operation instruction by the block link point, wherein the data operation instruction comprises a first data record with a target main key.
Step 102, the blockchain node determines a page to be operated of the first data record.
And 103, reading the existing data record with the target main key in the page to be operated by the block chain link point.
And 104, the blockchain node performs data operation on the existing data record according to the data operation instruction.
It should be noted that in the steps 101 to 104, the blockchain node stores the data record in the form of key value pairs in a multi-data page manner, and each primary key corresponds to at least one key value. The space for storing the data records for each data page may be set to be the same, e.g., 5 rows per page, and 5 data records can be stored.
For example, as shown in tables 2-1 and 2-2, the data records with the same primary key (Ming) are stored in pages of 9 data records with the primary key Ming, and each data page stores 5 rows of data records. Wherein, table 2-1 shows data page one of the small names, and table 2-2 shows data page two of the small names.
Name of name |
Asset numbering |
Asset type |
Price of |
Xiaoming (Ming) |
1 |
Watch with a watch body |
100k |
Xiaoming (Ming) |
2 |
Sports car |
1000k |
Xiaoming (Ming) |
3 |
Sea Jing Fang |
60m |
Xiaoming (Ming) |
4 |
High-rise building |
80m |
Xiaoming (Ming) |
5 |
Shop(s) |
200m |
TABLE 2-1
Name of name |
Asset numbering |
Asset type |
Price of |
Xiaoming (Ming) |
6 |
Apartment house |
100m |
Xiaoming (Ming) |
7 |
Securities |
600m |
Xiaoming (Ming) |
8 |
Safety device |
100k |
Xiaoming (Ming) |
9 |
Yacht |
200m |
TABLE 2-2
When the instruction to be operated is a new instruction, the page to be operated can be a randomly designated data page, or the last page of the data page can be directly defaulted as the page to be operated. The append rule of the data record may be: ordering the data pages with small brightness according to the first data page with small brightness and the second data page with small brightness. Append at the end of the data page of the last page of the small, for example, increment the data record with the asset number 10, there is directly the last two rows of the data page of the small. In addition, the total number of pages of the small data pages can be recorded in the first page, for example, the total number of pages is recorded as 2 in the first page. If the data records with the asset numbers of 10 and 11 are added, a new data page of less bright data page three can be created, and the total number of pages of 3 recorded in the less bright data page one is updated. Therefore, in the best case, the write operation only needs to update the data page where the data record is located, and needs to write 1 page, and in the worst case, the write operation needs to create a new page, needs to write 2 data pages, the newly created data page and the first data page. It can be seen that when the page is only stored as the data record of one main key, the total page number of the first page record can be rapidly positioned to the data page to be operated.
In an alternative embodiment, the blockchain in steps 101 to 104 may add index information of the data record when the data record is newly added, so that the page to be operated may be quickly and conveniently located when the data record is modified, queried and deleted later. The method can be concretely as follows:
The method comprises the steps that a block chain node generates target index information of a first data record according to a corresponding relation between a value of a preset object in the first data record and a page to be operated, the block chain node determines a first index page in an index library, in which the target index information is reserved, according to the value of the preset object in the first data record, and the block chain node stores the target index information to the index library according to the first index page.
For example, the preset object is a preset column name, such as the prices in tables 2-1 and 2-2, and the corresponding relationship between the value of the preset object in the first data record and the page to be operated is that the price is 40K, the data page 10, i.e. the data record with the price of 40K is stored in the data page 10. It should be noted that there may be a plurality of data records of price 40K, or may be stored in a plurality of data pages, and there may be a correspondence between one price and a plurality of data pages, for example, price 40K, data page 10, price 40K, and data page 11.
The index information is uniformly stored in an index library, the index library is provided with a plurality of index pages for storing the index information, and the index page where each piece of index information is stored can also be determined according to the value of a preset object. The storage rule of the specific index information can be flexibly set according to the scene, for example, the specific index information can be sequentially stored according to the value sequence of the preset object, the index information with the storage price of 0-80K is set in the first index page, and the index information with the storage price of 80-100K is set in the second index page. Then the first index page into which the generated target index information is prepared is index page one when the price of the first data record is 40K. Then, when the page to be operated of the first data record needs to be queried, the price 40K knows that the first index information is queried to the index page, and the page to be operated of the first data record is found.
It should be noted that the data structure of the index library may be various, for example, the index library may use a b+ tree to store the index information. The leaf nodes of the b+ tree are index pages for storing index information, and the non-leaf nodes (root pages in two layers) are used for indexing the stored index pages, and the specific structure can be shown in fig. 2. It should be noted that the structure of the 2-layer b+ tree shown in fig. 2 is merely illustrative, and the b+ tree may be any layer in practice.
The root node stores the index of the index page, as shown in Table 3-1, for example.
TABLE 3-1
And the index information stored in the index page may be as shown in table 3-2.
Price of |
Data page number |
10K |
4 |
20K |
1 |
30K |
3 |
42K |
3 |
60K |
2 |
TABLE 3-2
It should be noted that the value size of the preset object and the size of the data page number are not necessarily positively correlated, which is related to the storage mechanism of the data page, and if the mechanism is added according to the tail, the data record which is added first is stored first, and the more front the stored data page is.
In the above alternative embodiment, the index information in the index page may be arranged in a preset order according to the value of the preset object. The above blockchain node determines the page position to be stored in the first index page according to the value of the preset object, and the following steps can be specifically divided into the following cases:
First, write to the first index page, and the first index page is not full.
The first index page is directly updated and 1 page is written.
Second, write to the middle of the first index page, and the first index page is full.
If the page position of the first index page to be stored is the middle part of the first index page and the first index page is full, the blockchain node splits the first index page into a second index page and a third index page from the middle part of the first index page.
The block link point stores the index information before the middle part of the first index page and the target index information to the second index page, and the block link point stores the index information after the middle part of the first index page to the third index page. For example, taking the index page as 1000 rows, the first index page is 1000 rows, and the row number of the target index information to be stored is 751 th row. Then the front 750 rows of the second index page just after splitting stores the front 750 rows of index information of the original first index page, the back 250 rows are empty, the target index information is stored in the 751 th row of the second index page, the front 250 rows of the third index page stores index information, and the back 750 rows are empty. The target index information may be stored in the 1 st line of the third index page, and the 2 nd line to 251 nd line of the third index page stores the 1 st line to 250 nd line of the original first index page. And updating the root page simultaneously, and writing 3 pages in total.
More specifically, as shown in table 4-1, the range of the index information stored in the first index page is the index information with the preset object value between 0k and 100k, and 1000 lines are already stored.
TABLE 4-1
For example, the value of the preset object of the newly added target index information is 80K, and obviously, 80K is between 0K and 100K, so that the 0K to 100K needs to be split into a second index page for storing 0K to 80K and a third index page for storing 80K to 100K. The index of the first index page in the root page is also divided into 2 parts. The root page is shown in Table 4-2.
Start value |
Termination value |
Index page |
0 |
80K |
Second index page |
80K |
100K |
Third index page |
TABLE 4-2
The divided second index page and third index page are shown in tables 4-3 and 4-4, respectively:
the second index page is shown in Table 4-3:
TABLE 4-3
The third index page is shown in tables 4-4:
Tables 4 to 4
Third, write to the head or tail of the first index page and the first index page is full.
The blockchain node creates a fourth index page and stores the target index information to the fourth index page. And updating the root page simultaneously, and writing 2 pages in total. The specific procedure can be deduced from the second case, and will not be described in detail here.
It should be noted that in step 101 to step 104, the data operation instruction may be a new instruction, a query instruction, or a modification instruction.
In an alternative embodiment of step 103, the data operation instruction is a modification instruction or a query instruction, and step 103 may be performed in the following manner:
the block chain node determines a first index page corresponding to the first data record according to a value of a preset object in the first data record, determines target index information corresponding to the first data record from the first index page, and determines the page to be operated according to the target index information.
For example, the value of the preset object in the first data record is 40K, and the index information stored in the first index page is 0K to 80K, so that it is known that the first data record corresponds to the first index page. Then, the target index information corresponding to 40K is found in the first index page, and at this time, the target index information may be one index information corresponding to one data page, the data page is a page to be operated, the target index information may also be a plurality of index information, and then, according to the first data record, the page to be operated where the first data record is located is found in the plurality of data pages.
And the first index page records a plurality of pieces of index information, wherein each piece of index information records the corresponding relation between the value of the preset object and the data page.
In an alternative embodiment of step 104, the data manipulation instruction is a new instruction, then step 104 may be performed as follows:
And the blockchain node adds the first data record to the existing data record according to the existing data record and the first data record, so as to update the data record of the target main key in the page to be operated.
The specific update operation may be similar to the operation in the index page, creating a new data page when the data page is full.
In another alternative embodiment of step 104, the data operation instruction is a modification instruction, the modification instruction further includes a second data record having a target primary key, the modification instruction is used to modify the first data record into the second data record, the existing data record includes the first data record, and step 104 may specifically be performed in the following manner:
and the blockchain node modifies the first data record in the existing data records into the second data record according to the existing data records and the second data record, so that the existing data records of the target main key in the page to be operated are updated.
As shown in FIG. 3, the invention provides an operating device for blockchain data, which comprises an acquisition module 301 for acquiring a data operation instruction, wherein the data operation instruction comprises a first data record with a target main key, the blockchain node stores the data record in the form of key value pairs in a multi-data page mode, each main key corresponds to at least one key value, a processing module 302 for determining a page to be operated of the first data record, reading an existing data record with the target main key in the page to be operated, and performing data operation on the existing data record according to the data operation instruction.
In an alternative implementation manner, the processing module 302 is further configured to generate target index information of the first data record according to a corresponding relationship between a value of a preset object in the first data record and the page to be operated, determine a first index page in an index library, where the target index information is prepared to be stored, according to the value of the preset object in the first data record, and store the target index information to the index library according to the first index page.
In an alternative implementation manner, the index information in the index pages is arranged according to a preset sequence according to the value of the preset object, the processing module 302 is specifically configured to determine a page position to be stored in the first index page according to the value of the preset object, split the first index page into a second index page and a third index page from the middle of the first index page if the page position to be stored in the first index page is the middle of the first index page and the first index page is full, store index information before the middle of the first index page and the target index information to the second index page, and store index information after the middle of the first index page to the third index page.
In an alternative implementation manner, the index information in the index pages is arranged according to the preset sequence according to the value of the preset object, the processing module 302 is specifically configured to determine a page position to be stored in the first index page according to the value of the preset object, and if the page position to be stored in the first index page is the head or the tail of the first index page and the first index page is full, create a fourth index page and store the target index information to the fourth index page.
In an alternative implementation manner, the data operation instruction is a new instruction, and the processing module 302 is specifically configured to add the first data record to the existing data record according to the existing data record and the first data record, so as to update the data record of the target primary key in the page to be operated.
In an optional implementation manner, the data operation instruction is a modification instruction or a query instruction, and the processing module 302 is specifically configured to determine a first index page corresponding to the first data record according to a value of a preset object in the first data record, record a plurality of pieces of index information in the first index page, record a corresponding relationship between the value of the preset object and the data page in each piece of index information, determine target index information corresponding to the first data record from the first index page, and determine the page to be operated according to the target index information.
In an alternative implementation manner, the data operation instruction is a modification instruction, the modification instruction further comprises a second data record with a target main key, the modification instruction is used for modifying the first data record into the second data record, the existing data record comprises the first data record, and the processing module 302 is specifically used for modifying the first data record in the existing data record into the second data record according to the existing data record and the second data record, so that the existing data record of the target main key in the page to be operated is updated.
The embodiment of the application provides a computer device, which comprises a program or an instruction, and the program or the instruction are used for executing the operation method and any optional method of the blockchain data provided by the embodiment of the application when being executed.
The embodiment of the application provides a storage medium, which comprises a program or an instruction, and when the program or the instruction is executed, the program or the instruction is used for executing the operation method and any optional method of the blockchain data provided by the embodiment of the application.
Finally, it should be noted that those skilled in the art will appreciate that embodiments of the present application may be provided as a method, system, or computer program product. Accordingly, the present application may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present application may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, optical storage, and the like) having computer-usable program code embodied therein.
The present application is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems) and computer program products according to the application. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
It will be apparent to those skilled in the art that various modifications and variations can be made to the present application without departing from the scope of the application. Thus, it is intended that the present application also include such modifications and alterations insofar as they come within the scope of the appended claims or the equivalents thereof.