[go: up one dir, main page]

CN115248819A - Rich query protection method and device - Google Patents

Rich query protection method and device Download PDF

Info

Publication number
CN115248819A
CN115248819A CN202110461154.0A CN202110461154A CN115248819A CN 115248819 A CN115248819 A CN 115248819A CN 202110461154 A CN202110461154 A CN 202110461154A CN 115248819 A CN115248819 A CN 115248819A
Authority
CN
China
Prior art keywords
query
result
transaction
rich
read
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.)
Pending
Application number
CN202110461154.0A
Other languages
Chinese (zh)
Inventor
易翔宇
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Mobile Communications Group Co Ltd
China Mobile Financial Technology Co Ltd
Original Assignee
China Mobile Communications Group Co Ltd
China Mobile Financial Technology Co Ltd
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by China Mobile Communications Group Co Ltd, China Mobile Financial Technology Co Ltd filed Critical China Mobile Communications Group Co Ltd
Priority to CN202110461154.0A priority Critical patent/CN115248819A/en
Publication of CN115248819A publication Critical patent/CN115248819A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2458Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
    • GPHYSICS
    • G06COMPUTING OR CALCULATING; COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q40/00Finance; Insurance; Tax strategies; Processing of corporate or income taxes
    • G06Q40/04Trading; Exchange, e.g. stocks, commodities, derivatives or currency exchange

Landscapes

  • Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Business, Economics & Management (AREA)
  • Accounting & Taxation (AREA)
  • Finance (AREA)
  • General Physics & Mathematics (AREA)
  • General Business, Economics & Management (AREA)
  • Mathematical Physics (AREA)
  • Strategic Management (AREA)
  • Marketing (AREA)
  • Economics (AREA)
  • Development Economics (AREA)
  • Fuzzy Systems (AREA)
  • Technology Law (AREA)
  • Probability & Statistics with Applications (AREA)
  • Software Systems (AREA)
  • Computational Linguistics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • General Engineering & Computer Science (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

本发明实施例提供一种富查询保护方法及装置,该方法包括:在根据客户端发起的交易提案模拟交易的过程中,对数据库进行富查询,获取第一查询结果;将富查询的查询记录和第一查询结果加入到交易结果中的读写集,并将读写集返回给客户端,以供客户端将读写集经排序集群发送给记账节点,记账节点根据读写集中的查询记录和第一查询结果进行MVCC检测,在MVCC检测未通过的情况下确认交易结果无效。本发明能识别出富查询出现的脏读、幻读,防止包含脏读、幻读的富查询交易错误提交,实现富查询的脏读、幻读保护,提高了富查询操作的安全性,进而拓宽了富查询的使用范围。

Figure 202110461154

Embodiments of the present invention provide a rich query protection method and device. The method includes: in the process of simulating a transaction according to a transaction proposal initiated by a client, performing a rich query on a database to obtain a first query result; recording the query of the rich query And the first query result is added to the read-write set in the transaction result, and the read-write set is returned to the client, so that the client can send the read-write set to the accounting node through the sorted cluster. The MVCC test is performed on the query record and the first query result, and the transaction result is confirmed to be invalid if the MVCC test fails. The invention can identify dirty reads and phantom reads that occur in rich queries, prevent erroneous submission of rich query transactions including dirty reads and phantom reads, realize the protection of dirty reads and phantom reads of rich queries, improve the security of rich query operations, and further Broadened the scope of use of rich queries.

Figure 202110461154

Description

Rich query protection method and device
Technical Field
The invention relates to the technical field of block chains, in particular to a rich query protection method and device.
Background
HyperLegendr Fabric is currently the most widely used alliance-link technology. Hyperhedgehog Fabric supports the use of the corehDB for the state database and supports the rich query function since the 1.0-release version.
However, rich queries can only be used in query transactions that are not packed and sent to the ranking cluster, and if the rich queries are used in ordinary transactions that need to be submitted to the ranking cluster, the consistency of data in the simulation transaction and the submission stage needs to be ensured by self, otherwise, the problems of dirty reading and unreal reading may occur. Thus limiting the scope of use of rich queries so that they are generally only used in read-only transactions that do not need to be submitted to the ranking cluster.
Thus, because rich queries lack magic read protection mechanisms, transactions submitted to the ranking cluster may appear dirty, magic reads, causing inconsistencies with the expected results.
Disclosure of Invention
The embodiment of the invention provides a rich query protection method and device, which are used for solving the defects that hyper-resolution Fabric rich query in the prior art lacks a protection mechanism and dirty reading and unreal reading occur, realizing dirty reading and unreal reading protection on hyper-resolution Fabric rich query and ensuring consistency of rich query transaction.
The embodiment of the invention provides a rich query protection method, which comprises the following steps:
in the process of simulating a transaction according to a transaction proposal initiated by a client, carrying out rich query on a database to obtain a first query result;
adding the query record of the rich query and the first query result into a read-write set in a transaction result, returning the read-write set to the client, so that the client sends the read-write set to a billing node through a sequencing cluster, and the billing node performs MVCC detection according to the query record in the read-write set and the first query result, and determines that the transaction result is invalid when the MVCC detection fails.
According to the rich query protection method of one embodiment of the present invention, the query record includes selector information.
According to an embodiment of the present invention, the adding the query record of the rich query and the first query result to the read-write set of the transaction result includes:
creating a new set in the read-write set;
adding the query record and the first query result to the new set.
The embodiment of the invention also provides a rich query protection method, which comprises the following steps:
receiving a read-write set of transaction results of simulated transactions sent by a client through a sequencing cluster, and performing MVCC detection according to query records and a first query result in the read-write set;
the query records and the first query result are acquired by rich query of the database by the endorsement node in the process of simulating the transaction according to the transaction proposal initiated by the client and are added into the read-write set;
confirming that the transaction result is invalid if the MVCC detection fails.
According to the rich query protection method of one embodiment of the present invention, the query record includes selector information.
According to an embodiment of the present invention, the method for protecting rich query, which performs MVCC detection according to the query record in the read-write set and the first query result, includes:
performing rich query on the database according to the query record in the read-write set to obtain a second query result;
and comparing the first query result with the second query result, and obtaining that the MVCC detection fails under the condition that the first query result is inconsistent with the second query result.
According to the rich query protection method of one embodiment of the present invention, the first query result and the second query result are triples, and the triples include a key, a value, and a version number;
accordingly, the learning that the MVCC detection fails when the first query result and the second query result are inconsistent includes:
if the key in the second query result does not exist in the key in the first query result, and/or the key in the first query result does not exist in the key in the second query result, it is known that the first query result has magic reading, and the MVCC detection fails;
and if the corresponding version numbers of the same key in the first query result and the second query result are different, the fact that dirty reading exists in the first query result is known, and the MVCC detection is failed.
An embodiment of the present invention further provides a rich query protection device, including:
the query module is used for carrying out rich query on the database in the process of simulating the transaction according to the transaction proposal initiated by the client to obtain a first query result;
and the adding module is used for adding the query record and the first query result of the rich query into a read-write set in a transaction result, returning the read-write set to the client, so that the client can send the read-write set to an accounting node through the ordered cluster, and the accounting node performs MVCC detection according to the query record and the first query result in the read-write set and confirms that the transaction result is invalid under the condition that the MVCC detection fails.
An embodiment of the present invention further provides a rich query protection device, including:
the detection module is used for receiving a read-write set of transaction results of the simulated transactions sent by the client through the sequencing cluster and carrying out MVCC detection according to query records in the read-write set and a first query result;
the query records and the first query result are acquired by rich query of the database by the endorsement node in the process of simulating the transaction according to the transaction proposal initiated by the client and are added into the read-write set;
a confirmation module to confirm that the transaction result is invalid if the MVCC detection fails.
An embodiment of the present invention further provides an electronic 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 steps of any of the above rich query protection methods when executing the program.
According to the rich query protection method and device provided by the embodiment of the invention, the rich query record field and the query result are added in the read-write set of the simulated transaction result returned by the simulated transaction, and the rich query check is added when the MVCC check is performed on the block containing the rich query transaction, so that dirty read and unreal read of the rich query can be identified, the rich query transaction containing the dirty read and the unreal read is prevented from being wrongly submitted, the dirty read and unreal read protection of the rich query is realized, the safety of rich query operation is improved, and the application range of the rich query is widened.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and those skilled in the art can also obtain other drawings according to the drawings without creative efforts.
FIG. 1 is a prior art schematic of a generic transaction flow for Fabric submission to a sort cluster;
FIG. 2 is a flow chart of a rich query protection method according to an embodiment of the present invention;
FIG. 3 is a diagram of a data format of a read-write set in the prior art;
FIG. 4 is a schematic diagram of a data format of a read/write set in a rich query protection method according to an embodiment of the present invention;
FIG. 5 is a flowchart illustrating a rich query protection method according to another embodiment of the present invention;
fig. 6 is a schematic structural diagram of a rich query protection device according to an embodiment of the present invention;
fig. 7 is a schematic structural diagram of a rich query protection device according to another embodiment of the present invention;
fig. 8 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be obtained by a person skilled in the art without inventive step based on the embodiments of the present invention, are within the scope of protection of the present invention.
Before the embodiment of the present invention is introduced, a general transaction flow submitted to a sorting cluster in a Hyperhedger Fabric is introduced, and as shown in FIG. 1, the general transaction flow mainly includes the following steps:
1. the client initiates a transaction proposal to the endorsement node.
2. And the endorsement node performs simulated transaction according to the transaction proposal.
3. And the endorsement node packs the simulation transaction result and returns the signature to the client.
4. And the client sends the packed simulated transaction result to the sequencing cluster for sequencing.
5. And the sequencing cluster is used for sequencing the simulation transaction results and then packaging the results into blocks.
6. And the accounting node verifies and drops the chain of the simulated transaction result in the block.
7. And informing the client of successful transaction through the event.
For the read-only query transaction in HyperLegendr Fabric, the transaction flow only includes the first three steps. Because of the uncertainty of rich queries, they are typically only used in read-only query transactions that do not need to be submitted to the ranking cluster, resulting in a limited scope of use for rich queries.
The rich query refers to querying according to values in the key value pairs, the common query refers to querying according to keys in the key value pairs, and the range query refers to querying according to the specified key value ranges.
Like ordinary queries and range queries, rich queries may also present instances of inconsistencies in step 2 and step 6 data in transactions. Since rich queries do not have dirty-read and magic-read protection mechanisms, if the rich queries are used for transactions that need to be submitted to the ranking cluster, the transaction results may be inconsistent with expectations.
A dirty read refers to when a transaction is accessing data and has made a modification to the data, but the modification has not yet been committed to the database, another transaction is accessing the data and then using the data.
Magic reads refer to a phenomenon that occurs when transactions are not executed independently. For example, the first transaction modifies data in a table, which modification involves all the rows of data in the table. At the same time, the second transaction also modifies the data in this table by inserting a new row of data into the table. Then later it will happen that the user operating the first transaction finds that there are rows of data in the table that have not been modified, as if the illusion had occurred.
The rich query protection method of the embodiment of the present invention is described below with reference to fig. 2, and the method includes: step 201, in the process of simulating a transaction according to a transaction proposal initiated by a client, performing rich query on a database to obtain a first query result;
the execution subject of the embodiment is an endorsement node. The endorsement node receives the transaction proposal initiated by the client and carries out simulated transaction according to the transaction proposal, as shown in step 2 in figure 1.
The rich query is executed in step 2 simulation transaction of the Fabric transaction, and has the effect of using a selector to obtain all terms with satisfied values in a CoochDB K-V (Key-Value pair) database. And taking a query result obtained by the endorsement node performing rich query on the database as a first query result.
The following is a rich query API (Application Programming Interface):
stub.GetQueryResult(queryString);
wherein stub is a K-V database to be queried, queryString is a query selector used for selecting required data items.
For example, one query selector is as follows:
{″selector″:{″num″:{″$gt″:10}}};
the function of the query selector is to obtain all data items with num attribute larger than 10 in V from the K-V database.
Step 202, adding the query record of the rich query and the first query result into a read-write set in a transaction result, and returning the read-write set to the client, so that the client sends the read-write set to an accounting node via a sorted cluster, and the accounting node performs MVCC detection according to the query record in the read-write set and the first query result, and determines that the transaction result is invalid when the MVCC detection fails.
The read-write set is a collection of read and write operations in a step 2 simulated transaction of a Fabric transaction, the data format being shown in FIG. 3. Wherein ReadSet is a single-key read operation set, writeSet is a single-key write operation set, and QueryInfoSet is a range query operation set.
The query record is used for the accounting node to perform the same query on the database again according to the query record, and the embodiment is not limited to the specific content of the query record.
And adding the query record of the rich query and the first query result into a read-write set in the transaction result. Then steps 2 to 6 of the Fabric transaction are performed in sequence.
MVCC (Muti-Version Concurrency Control) is a step in the 6 th step of Fabric transaction, and is used for checking the data Version to prevent the data inconsistency between the simulated transaction in the 2 nd step and the verified data in the 6 th step.
For each transaction in the block, MVCC detection will be performed in sequence. MVCC only detects read sets and scope query sets. Because writing the data only in the write set does not cause data inconsistency.
In this embodiment, when the MVCC is detected in step 6, the accounting node performs the same query on the database again according to the query record to obtain a second query result. And taking the inquiry result obtained by the account node performing the same rich inquiry with the endorsement node on the database as a second inquiry result.
And if the first query result is inconsistent with the second query result, indicating that dirty reading and/or unreal reading exist in the rich query, marking the current transaction result invalid, triggering a transaction failure event, and restarting the transaction by the client.
In the embodiment, the rich query record field and the query result are added in the read-write set of the simulated transaction result returned by the simulated transaction, and the rich query check is added when the MVCC check is performed on the block containing the rich query transaction, so that dirty reading and unreal reading of the rich query can be identified, the rich query transaction containing the dirty reading and the unreal reading is prevented from being wrongly submitted, the dirty reading and the unreal reading protection of the rich query are realized, the safety of the rich query operation is improved, and the application range of the rich query is widened.
On the basis of the above embodiment, the query record in this embodiment includes selector information.
Specifically, the accounting node performs the same query on the database again according to the selector information in the query record to obtain a second query result.
On the basis of the foregoing embodiments, in this embodiment, adding the query record of the rich query and the first query result to the read-write set of the transaction result includes: creating a new set in the read-write set; and adding the query record and the first query result into the new set.
In this embodiment, the read-write set is modified, and a new set, that is, the rich query set RichQueryInfoSet, is added to the read-write set, as shown in fig. 4. Each term in the set of rich queries includes a query record of the rich query and a first query result. And adding the query records of all rich queries and the first query result into the RichQueryInfoSet in the simulated transaction stage by the endorsement node.
In the sixth step of the Fabric transaction, when MVCC verification is performed on each transaction, verification of RichQueryInfSet is added besides the verification of ReadSet and QueryInfSet.
The rich query protection method of the embodiment of the present invention is described below with reference to fig. 5, and the method includes: step 501, receiving a read-write set of transaction results of simulated transactions sent by a client through a sequencing cluster, and performing MVCC detection according to query records and a first query result in the read-write set;
the execution subject of the embodiment is the accounting node. At step 6 of the Fabric transaction, the accounting node receives the simulated transaction result sent by the client through the sequencing cluster. And carrying out MVCC detection on the read-write set in the simulation transaction result.
As the endorsement node in the transaction stage is additionally provided with the query record of the rich query and the first query result in the read-write set, the MVCC detection is carried out on the query record of the rich query and the first query result in the accounting stage in the verification stage.
The query records and the first query result are obtained by rich query of a database by an endorsement node in the process of simulating transaction according to a transaction proposal initiated by the client and are added into the read-write set;
step 502, confirming that the transaction result is invalid if the MVCC detection fails.
And under the condition that the rich query does not pass the MVCC detection, the accounting node marks that the current transaction result is invalid, triggers a transaction failure event, and the client-side initiates the transaction again.
In the embodiment, the rich query record field and the query result are added in the read-write set of the simulated transaction result returned by the simulated transaction, and the rich query is checked when the MVCC check is performed on the block containing the rich query transaction, so that invalid transactions with dirty reading and unreal reading phenomena can be identified, the rich query transaction containing the dirty reading and unreal reading phenomena is prevented from being submitted wrongly, the dirty reading and unreal reading protection of the rich query is realized, the safety of rich query operation is improved, and the application range of the rich query is widened.
On the basis of the above embodiment, the query record in this embodiment includes selector information.
Specifically, the accounting node performs the same query on the database again according to the selector information in the query record to obtain a second query result.
On the basis of the foregoing embodiments, the performing MVCC detection according to the query record in the read-write set and the first query result in this embodiment includes: performing rich query on the database according to the query record in the read-write set to obtain a second query result;
specifically, the present embodiment traverses each item of the rich query set RichQueryInfoSet in the read-write set. And assuming that the current traversal item is RichQueryInfo, acquiring a query record and a first query result in the RichQueryInfo. And querying the same database again by using the query record to obtain a second query result.
And comparing the first query result with the second query result, and obtaining that the MVCC detection fails under the condition that the first query result is inconsistent with the second query result.
And comparing the second query result with the first query result in the RichQueryInfo. If the two are not consistent, dirty reading and/or unreal reading are/is indicated, and MVCC detection fails.
For example, during the simulated trade execution, a { "selector": { "num": { "$ gt": 10} } and { "selector": { "num": { "$ gt": 30} the two selectors are used for carrying out rich query to respectively obtain a first query result A and a first query result B, and then the two selectors and the corresponding query results are added into the RichQueryInfoSet.
And executing the query by using two selectors during the MVCC to obtain second query results A 'and B', if A = = A 'and B = = B', the MVCC passes the check, the transaction result is valid, otherwise, the transaction result is marked to be invalid.
On the basis of the above embodiment, in this embodiment, the first query result and the second query result are triples, and the triples include keys, values, and version numbers;
the first query results A and B, and the second query results A 'and B' are triples. Each triplet includes a key, a value and a version number.
For example, the triplet for a is:
{
Key:“a”,
Value:“111”,
Version:1
}
the triplet of B is:
{
Key:“b”,
Value:“222”,
Version:2
}
a = = a 'can be assumed only if the corresponding data in the triplets of a and a' are identical. Wherein the ordering of the triples in the triple set has no effect on the MVCC detection result.
Correspondingly, in the case that the first query result and the second query result are inconsistent, learning that the MVCC detection fails includes: if the key in the second query result does not exist in the key in the first query result, and/or the key in the first query result does not exist in the key in the second query result, it is known that the first query result has magic reading, and the MVCC detection fails;
in the event that a key in the second query result is not present in a key in the first query result, indicating that a new data item has been added to the database.
In the case where the key in the first query result does not exist in the key in the second query result, deletion of the data item in the database is described.
The addition and deletion of data items causes the rich query to appear unrealistic, and the transaction result is marked as invalid.
And if the corresponding version numbers of the same key in the first query result and the second query result are different, the fact that dirty reading exists in the first query result is known, and the MVCC detection is failed.
And under the condition that the corresponding version numbers of the same key in the first query result and the second query result are different, the data items in the database are modified, so that dirty reading occurs in the rich query, and the transaction result is marked as invalid.
The following use case shows the dirty reading and phantom reading problems solved by the embodiment.
For example, in an account hierarchy, all accounts with an account balance below Y are issued X-ary. All accounts with an account balance below Y-ary can be obtained more simply by using rich queries without traversing all accounts.
1. If the dirty reading problem is not solved, if there are two transactions, 10 dollars are issued to accounts with account balances below 50 dollars. The initial balance of an account is 10 yuan, and the expected result after the transaction is completed is 30 yuan. However, if the two transactions are performed in a time period less than one block output interval, a dirty reading problem is likely to occur, the first transaction has a read balance of 10 yuan, the balance is written to 10+10=20 yuan, the second transaction has a read balance of 10 yuan, the balance is written to 10+10=20 yuan, and the results and the expectations are different from each other due to the fact that the balance is detected by the MVCC. If dirty read protection is introduced, the second transaction cannot pass the detection of the MVCC and is marked as an invalid transaction, a transaction failure event is sent, and the client side can perform a transaction flow after receiving the failure event.
2. If the problem of the unreal reading is not solved, if there is a transaction, 10 yuan is issued to the account with the account balance lower than 50 yuan. The account M was created prior to this transaction and the initial balance was 10 dollars. If the interval between the account creation time and the transaction time is less than one out-of-block time, then the problem of being read by mistake is likely to occur, and the account M will not appear in the 10-tuple release list and will be detected by MVCC, resulting in a discrepancy with the expected result. If the magic read protection is introduced, the transaction which is issued with 10 yuan will not pass the detection of the MVCC and will be marked as invalid transaction, a transaction failure event is sent, and the client end will end the transaction flow after receiving the failure event.
The following describes the rich query protection device provided by the embodiment of the present invention, and the rich query protection device described below and the rich query protection method described above may be referred to correspondingly.
As shown in fig. 6, the apparatus includes a query module 601 and an add module 602, wherein:
the query module 601 is configured to perform rich query on the database in a process of simulating a transaction according to a transaction proposal initiated by a client, and obtain a first query result;
the execution subject of the embodiment is an endorsement node. And the endorsement node receives a transaction proposal initiated by the client and carries out simulated transaction according to the transaction proposal.
The rich query is executed in step 2 simulation transaction of the Fabric transaction, and has the effect of using a selector to obtain all terms with satisfied values in a CoochDB K-V (Key-Value pair) database. And taking a query result obtained by the rich query of the endorsement node on the database as a first query result.
The adding module 602 is configured to add the query record of the rich query and the first query result into a read-write set in the transaction result, and return the read-write set to the client, so that the client sends the read-write set to an accounting node via a sorted cluster, and the accounting node performs MVCC detection according to the query record in the read-write set and the first query result, and confirms that the transaction result is invalid when the MVCC detection fails.
The query record is used for the accounting node to perform the same query on the database again according to the query record, and the embodiment is not limited to the specific content of the query record.
And adding the query record of the rich query and the first query result into the read-write set in the transaction result. Then steps 2 to 6 of the Fabric transaction are performed in sequence.
In this embodiment, when the MVCC is detected in step 6, the accounting node performs the same query on the database again according to the query record to obtain a second query result. And taking the inquiry result obtained by the account node performing the same rich inquiry with the endorsement node on the database as a second inquiry result.
And if the first query result is inconsistent with the second query result, indicating that dirty reading and/or unreal reading exist in the rich query, marking the current transaction result invalid, triggering a transaction failure event, and restarting the transaction by the client.
In the embodiment, the rich query record field and the query result are added in the read-write set of the simulated transaction result returned by the simulated transaction, and the rich query check is added when the MVCC check is performed on the block containing the rich query transaction, so that dirty reading and unreal reading of the rich query can be identified, the rich query transaction containing the dirty reading and the unreal reading is prevented from being wrongly submitted, the dirty reading and the unreal reading protection of the rich query are realized, the safety of the rich query operation is improved, and the application range of the rich query is widened.
On the basis of the above embodiment, the query record in this embodiment includes selector information.
On the basis of the above embodiment, the module added in this embodiment is used to: creating a new set in the read-write set; and adding the query record and the first query result into the new set.
The following describes the rich query protection device provided in the embodiment of the present invention, and the rich query protection device described below and the rich query protection method described above may be referred to correspondingly.
As shown in fig. 7, the apparatus comprises a detection module 701 and a confirmation module 702, wherein:
the detection module 701 is used for receiving a read-write set of transaction results of simulated transactions sent by a client through a sequencing cluster, and performing MVCC detection according to query records in the read-write set and a first query result;
the execution subject of the embodiment is the accounting node. At step 6 of the Fabric transaction, the accounting node receives the simulated transaction result sent by the client through the sequencing cluster. And performing MVCC detection on the read-write set in the simulated transaction result.
As the endorsement node in the transaction stage is additionally provided with the query record of the rich query and the first query result in the read-write set, the MVCC detection is carried out on the query record of the rich query and the first query result in the accounting stage in the verification stage.
The query records and the first query result are obtained by rich query of a database by an endorsement node in the process of simulating transaction according to a transaction proposal initiated by the client and are added into the read-write set;
a confirmation module 702 is used to confirm that the transaction result is invalid if the MVCC detection fails.
And under the condition that the rich query fails to pass the MVCC detection, the accounting node marks that the current transaction result is invalid, triggers a transaction failure event, and the client side initiates the transaction again.
In the embodiment, the rich query record field and the query result are added in the read-write set of the simulated transaction result returned by the simulated transaction, and the rich query check is added when the MVCC check is performed on the block containing the rich query transaction, so that invalid transactions with dirty reading and unreal reading phenomena can be identified, the rich query transaction containing dirty reading and unreal reading is prevented from being wrongly submitted, the dirty reading and unreal reading protection of the rich query is realized, the safety of the rich query operation is improved, and the application range of the rich query is widened.
On the basis of the above embodiment, the query record in this embodiment includes selector information.
On the basis of the foregoing embodiments, the detection module in this embodiment is configured to: performing rich query on the database according to the query record in the read-write set to obtain a second query result; and comparing the first query result with the second query result, and obtaining that the MVCC detection fails under the condition that the first query result is inconsistent with the second query result.
On the basis of the above embodiment, in this embodiment, the first query result and the second query result are triples, and the triples include keys, values, and version numbers; accordingly, the detection module is configured to: if the key in the second query result does not exist in the key in the first query result and/or the key in the first query result does not exist in the key in the second query result, it is known that the first query result is read by illusion, and the MVCC detection fails; and if the corresponding version numbers of the same key in the first query result and the second query result are different, the fact that dirty reading exists in the first query result is known, and the MVCC detection is failed.
Fig. 8 illustrates a physical structure diagram of an electronic device, which may include, as shown in fig. 8: a processor (processor) 810, a communication Interface 820, a memory 830 and a communication bus 840, wherein the processor 810, the communication Interface 820 and the memory 830 communicate with each other via the communication bus 840. Processor 810 may invoke logic instructions in memory 830 to perform a rich query protection method comprising: in the process of simulating a transaction according to a transaction proposal initiated by a client, carrying out rich query on a database to obtain a first query result; and adding the query record of the rich query and the first query result into a read-write set in the transaction result, returning the read-write set to the client, so that the client sends the read-write set to the accounting node through the ordered cluster, and the accounting node performs MVCC detection according to the query record in the read-write set and the first query result, and confirming that the transaction result is invalid under the condition that the MVCC detection fails.
In addition, the logic instructions in the memory 830 can be implemented in the form of software functional units and stored in a computer readable storage medium when the software functional units are sold or used as independent products. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk, or an optical disk, and various media capable of storing program codes.
In another aspect, an embodiment of the present invention further provides a computer program product, where the computer program product includes a computer program stored on a non-transitory computer-readable storage medium, the computer program includes program instructions, and when the program instructions are executed by a computer, the computer can execute the rich query protection method provided by the above-mentioned method embodiments, where the method includes: in the process of simulating a transaction according to a transaction proposal initiated by a client, carrying out rich query on a database to obtain a first query result; and adding the query record of the rich query and the first query result into a read-write set in the transaction result, returning the read-write set to the client, so that the client sends the read-write set to the accounting node through the ordered cluster, and the accounting node performs MVCC detection according to the query record in the read-write set and the first query result, and confirming that the transaction result is invalid under the condition that the MVCC detection fails.
In yet another aspect, an embodiment of the present invention further provides a non-transitory computer-readable storage medium, on which a computer program is stored, where the computer program is implemented by a processor to perform the rich query protection method provided in the foregoing embodiments, and the method includes: in the process of simulating a transaction according to a transaction proposal initiated by a client, carrying out rich query on a database to obtain a first query result; and adding the query record of the rich query and the first query result into a read-write set in the transaction result, returning the read-write set to the client, so that the client sends the read-write set to the accounting node through the sequencing cluster, and the accounting node performs MVCC detection according to the query record in the read-write set and the first query result and confirms that the transaction result is invalid under the condition that the MVCC detection fails.
The above-described embodiments of the apparatus are merely illustrative, and the 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 modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. Based on the understanding, the above technical solutions substantially or otherwise contributing to the prior art may be embodied in the form of a software product, which may be stored in a computer-readable storage medium, such as ROM/RAM, magnetic disk, optical disk, etc., and includes several instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method according to the various embodiments or some parts of the embodiments.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will 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; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (10)

1.一种富查询保护方法,其特征在于,包括:1. a rich query protection method, is characterized in that, comprises: 在根据客户端发起的交易提案模拟交易的过程中,对数据库进行富查询,获取第一查询结果;In the process of simulating the transaction according to the transaction proposal initiated by the client, perform a rich query on the database to obtain the first query result; 将所述富查询的查询记录和第一查询结果加入到交易结果中的读写集,并将所述读写集返回给所述客户端,以供所述客户端将所述读写集经排序集群发送给记账节点,所述记账节点根据所述读写集中的查询记录和第一查询结果进行MVCC检测,在所述MVCC检测未通过的情况下确认所述交易结果无效。Add the query record of the rich query and the first query result to the read-write set in the transaction result, and return the read-write set to the client, so that the client can process the read-write set by the client. The sorting cluster is sent to the accounting node, and the accounting node performs MVCC detection according to the query records in the read-write set and the first query result, and confirms that the transaction result is invalid if the MVCC detection fails. 2.根据权利要求1所述的富查询保护方法,其特征在于,所述查询记录包括选择器信息。2 . The rich query protection method according to claim 1 , wherein the query record includes selector information. 3 . 3.根据权利要求1或2所述的富查询保护方法,其特征在于,所述将所述富查询的查询记录和第一查询结果加入到所述交易结果的读写集,包括:3. The rich query protection method according to claim 1 or 2, wherein the adding the query record of the rich query and the first query result to the read-write set of the transaction result comprises: 在所述读写集中创建一个新集合;create a new collection in the read-write set; 将所述查询记录和第一查询结果加入到所述新集合中。The query record and the first query result are added to the new set. 4.一种富查询保护方法,其特征在于,包括:4. A rich query protection method, comprising: 接收客户端经排序集群发送的模拟交易的交易结果的读写集,根据所述读写集中的查询记录和第一查询结果进行MVCC检测;Receive the read-write set of the transaction result of the simulated transaction sent by the client through the sorting cluster, and perform MVCC detection according to the query record in the read-write set and the first query result; 其中,所述查询记录和第一查询结果由背书节点在根据所述客户端发起的交易提案模拟交易的过程中,对数据库进行富查询获取,并加入到所述读写集中;Wherein, the query record and the first query result are obtained by the endorsement node by performing a rich query on the database in the process of simulating the transaction according to the transaction proposal initiated by the client, and adding it to the read-write set; 在所述MVCC检测未通过的情况下确认所述交易结果无效。If the MVCC test fails, it is confirmed that the transaction result is invalid. 5.根据权利要求4所述的富查询保护方法,其特征在于,所述查询记录包括选择器信息。5 . The rich query protection method according to claim 4 , wherein the query record includes selector information. 6 . 6.根据权利要求4或5所述的富查询保护方法,其特征在于,所述根据所述读写集中的查询记录和第一查询结果进行MVCC检测,包括:6. The rich query protection method according to claim 4 or 5, wherein the MVCC detection is carried out according to the query record in the read-write set and the first query result, comprising: 根据所述读写集中的查询记录对所述数据库进行富查询,获取第二查询结果;Perform a rich query on the database according to the query records in the read-write set to obtain a second query result; 将所述第一查询结果和第二查询结果进行比对,在所述第一查询结果和第二查询结果不一致的情况下,获知所述MVCC检测未通过。The first query result and the second query result are compared, and in the case that the first query result and the second query result are inconsistent, it is learned that the MVCC test fails. 7.根据权利要求6所述的富查询保护方法,其特征在于,所述第一查询结果和第二查询结果为三元组,所述三元组包括键、值和版本号;7. The rich query protection method according to claim 6, wherein the first query result and the second query result are triples, and the triples include a key, a value, and a version number; 相应地,所述在所述第一查询结果和第二查询结果不一致的情况下,获知所述MVCC检测未通过,包括:Correspondingly, in the case that the first query result and the second query result are inconsistent, learning that the MVCC test fails, including: 若所述第二查询结果中的键在所述第一查询结果中的键中不存在,和/或所述第一查询结果中的键在所述第二查询结果中的键中不存在,则获知所述第一查询结果存在幻读,所述MVCC检测未通过;If the key in the second query result does not exist in the key in the first query result, and/or the key in the first query result does not exist in the key in the second query result, Then learn that the first query result has phantom reading, and the MVCC detection fails; 若同一所述键在所述第一查询结果和第二查询结果中对应的版本号不同,则获知所述第一查询结果存在脏读,所述MVCC检测未通过。If the version numbers corresponding to the same key in the first query result and the second query result are different, it is known that there is a dirty read in the first query result, and the MVCC test fails. 8.一种富查询保护装置,其特征在于,包括:8. A rich query protection device, characterized in that, comprising: 查询模块,用于在根据客户端发起的交易提案模拟交易的过程中,对数据库进行富查询,获取第一查询结果;The query module is used to perform a rich query on the database to obtain the first query result in the process of simulating the transaction according to the transaction proposal initiated by the client; 添加模块,用于将所述富查询的查询记录和第一查询结果加入到交易结果中的读写集,并将所述读写集返回给所述客户端,以供所述客户端将所述读写集经排序集群发送给记账节点,所述记账节点根据所述读写集中的查询记录和第一查询结果进行MVCC检测,在所述MVCC检测未通过的情况下确认所述交易结果无效。The adding module is used to add the query record of the rich query and the first query result to the read-write set in the transaction result, and return the read-write set to the client, so that the client can The read-write set is sent to the billing node through the sorting cluster, and the billing node performs MVCC detection according to the query record in the read-write set and the first query result, and confirms the transaction when the MVCC test fails. The result is invalid. 9.一种富查询保护装置,其特征在于,包括:9. A rich query protection device, characterized in that, comprising: 检测模块,用于接收客户端经排序集群发送的模拟交易的交易结果的读写集,根据所述读写集中的查询记录和第一查询结果进行MVCC检测;a detection module, configured to receive a read-write set of the transaction result of the simulated transaction sent by the client through the sorting cluster, and perform MVCC detection according to the query record in the read-write set and the first query result; 其中,所述查询记录和第一查询结果由背书节点在根据所述客户端发起的交易提案模拟交易的过程中,对数据库进行富查询获取,并加入到所述读写集中;Wherein, the query record and the first query result are obtained by the endorsement node by performing a rich query on the database in the process of simulating the transaction according to the transaction proposal initiated by the client, and adding it to the read-write set; 确认模块,用于在所述MVCC检测未通过的情况下确认所述交易结果无效。A confirmation module, configured to confirm that the transaction result is invalid when the MVCC test fails. 10.一种电子设备,包括存储器、处理器及存储在存储器上并可在处理器上运行的计算机程序,其特征在于,所述处理器执行所述程序时实现如权利要求1至7任一项所述富查询保护方法的步骤。10. An electronic device, comprising a memory, a processor and a computer program stored on the memory and running on the processor, wherein the processor implements any one of claims 1 to 7 when the processor executes the program The steps of the rich query protection method described in item .
CN202110461154.0A 2021-04-27 2021-04-27 Rich query protection method and device Pending CN115248819A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110461154.0A CN115248819A (en) 2021-04-27 2021-04-27 Rich query protection method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110461154.0A CN115248819A (en) 2021-04-27 2021-04-27 Rich query protection method and device

Publications (1)

Publication Number Publication Date
CN115248819A true CN115248819A (en) 2022-10-28

Family

ID=83697387

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110461154.0A Pending CN115248819A (en) 2021-04-27 2021-04-27 Rich query protection method and device

Country Status (1)

Country Link
CN (1) CN115248819A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160147814A1 (en) * 2014-11-25 2016-05-26 Anil Kumar Goel In-Memory Database System Providing Lockless Read and Write Operations for OLAP and OLTP Transactions
CN110717764A (en) * 2019-10-21 2020-01-21 深圳前海环融联易信息科技服务有限公司 Multi-account book management method and device, computer equipment and storage medium
CN110827008A (en) * 2018-08-08 2020-02-21 华为技术有限公司 A blockchain node and transaction method
CN111242620A (en) * 2020-01-15 2020-06-05 阳光易购(湖南)科技有限公司 Data caching and querying method of block chain transaction system, terminal and storage medium
CN112514319A (en) * 2018-07-27 2021-03-16 甲骨文国际公司 System and method for supporting SQL-based rich queries in a hyper-ledger architecture blockchain

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20160147814A1 (en) * 2014-11-25 2016-05-26 Anil Kumar Goel In-Memory Database System Providing Lockless Read and Write Operations for OLAP and OLTP Transactions
CN112514319A (en) * 2018-07-27 2021-03-16 甲骨文国际公司 System and method for supporting SQL-based rich queries in a hyper-ledger architecture blockchain
CN110827008A (en) * 2018-08-08 2020-02-21 华为技术有限公司 A blockchain node and transaction method
CN110717764A (en) * 2019-10-21 2020-01-21 深圳前海环融联易信息科技服务有限公司 Multi-account book management method and device, computer equipment and storage medium
CN111242620A (en) * 2020-01-15 2020-06-05 阳光易购(湖南)科技有限公司 Data caching and querying method of block chain transaction system, terminal and storage medium

Similar Documents

Publication Publication Date Title
CN111104392B (en) Database migration method and device, electronic equipment and storage medium
US11868330B2 (en) Method for indexing data in storage engine and related apparatus
CN108415835B (en) Distributed database testing method, apparatus, device and computer readable medium
CN103853718B (en) Fragment data storehouse access method and Database Systems
CN112669155A (en) Transaction distribution execution method based on block chain, device server and storage medium
TWI730690B (en) Method and device for simultaneously executing transactions in block chain, computer readable storage medium and computing equipment
EP1669904B1 (en) Verifying dynamically generated operations on a data store
CN105653579B (en) The method and apparatus that a kind of pair of distributed transaction is tested
CN108573015A (en) Method, device, electronic device and readable storage medium for changing table format
WO2020119143A1 (en) Database deleted record recovery method and system
CN114385722A (en) Interface attribute consistency checking method and device, electronic equipment and storage medium
CN118445212B (en) Code generation method and device for software test driver
US20250021581A1 (en) Data processing method, blockchain node, and blockchain system
CN114936164B (en) Automated anomaly testing method, device, equipment, and medium for distributed transactions
CN115248819A (en) Rich query protection method and device
CN114372051B (en) Data processing system, data processing method and device based on block chain
CN114610644B (en) Method and device for testing database
CN115640236B (en) Script quality detection method and computing device
CN112232768A (en) A Merchant Data Processing Method Based on Whole Life Cycle Management
CN107256252A (en) A third-party multi-dimensional data migration method and device
US11768855B1 (en) Replicating data across databases by utilizing validation functions for data completeness and sequencing
CN117951002A (en) Incremental code unit test method, device, computer equipment and storage medium
JP2939414B2 (en) Database Equivalent Processor for Dual Computer
CN105787011B (en) Ranking update method and device
Hierons et al. Scenarios‐based testing of systems with distributed ports

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