Transaction execution method, device, equipment and storage medium

By creating target transactions in the blockchain system and executing multiple SQL statements as one transaction, the problem of lack of support for transactions formed by multiple SQL statements in the blockchain system is solved, and higher business applicability is achieved.

CN114328591BActive Publication Date: 2025-05-23HANGZHOU QULIAN TECHNOLOGY CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202111677879.X
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-31
Publication Date
2025-05-23
Estimated Expiration
2041-12-31

AI Technical Summary

Technical Problem

The lack of support for transactions formed by multiple SQL statements in the blockchain system, resulting in limited service use.

Method used

By receiving the transaction with the start transaction statement sent by the client, the target transaction is created, and when multiple transactions carrying SQL statements are received, it is executed as a transaction, and the transaction is not submitted until the transaction with the commit statement is received.

Benefits of technology

It realizes the support for transactions by the blockchain system, improves the flexibility and accuracy of executing SQL statements, and thus improves business applicability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114328591B_ABST
    Figure CN114328591B_ABST
Patent Text Reader

Abstract

The present application discloses a transaction execution method, device, equipment and storage medium, which belongs to the field of blockchain technology. Applied to a blockchain system, it includes: creating a target transaction after receiving a first transaction carrying a start transaction statement; each time a second transaction is received, if the SQL statement carried by the second transaction is used to modify the first data in the blockchain account book, then modify the first data according to the SQL statement when the target transaction locks the first data; if a third transaction carrying a commit statement is received, then unlock all data locked by the target transaction in the blockchain account book to submit the modified data of multiple SQL statements executed by the target transaction. In the present application, the blockchain system implements support for transactions, that is, multiple SQL statements sent by the client can be executed as a transaction in the blockchain system, which improves the flexibility and accuracy of the blockchain system in executing SQL statements, thereby improving business applicability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of blockchain technology, and in particular to a transaction execution method, device, equipment and storage medium. Background Art

[0002] Currently, the client can send a transaction carrying a SQL (Structured Query Language) statement to the blockchain system. After the blockchain system receives the transaction sent by the client, it can execute the SQL statement carried by the transaction by executing the transaction, and then operate the blockchain ledger according to the execution result of the SQL statement.

[0003] In the above process, the SQL statement is carried in the transaction to realize the execution of the SQL statement in the blockchain system. However, compared with the traditional RDBMS (Relational Database Management System), the execution of SQL statements in the blockchain system lacks the characteristics of transactions. Because currently in the blockchain system, a transaction is actually a transaction, that is, a SQL statement is actually a transaction, and the traditional RDBMS can turn the execution of multiple SQL statements into a transaction for submission or rollback. Therefore, the current blockchain system does not implement the support for transactions formed by multiple SQL statements in the traditional RDBMS, which will be more limited in business use. Summary of the invention

[0004] This application provides a transaction execution method, device, equipment and storage medium, which can enable the blockchain system to support transactions. The technical solution is as follows:

[0005] In a first aspect, a transaction execution method is provided, which is applied to a blockchain system, and the method includes:

[0006] After receiving the first transaction carrying the start transaction statement sent by the client, create a target transaction;

[0007] Receiving multiple second transactions sent by the client, each of the multiple second transactions carries an SQL statement for operating a blockchain ledger that needs to be executed by the target transaction;

[0008] Whenever a second transaction sent by the client is received, if the SQL statement carried by the second transaction is used to modify the first data in the blockchain account book, then in the case where the target transaction locks the first data, modify the first data according to the SQL statement carried by the second transaction;

[0009] If a third transaction carrying a commit statement sent by the client is received, all data locked by the target transaction in the blockchain ledger are unlocked to commit the modified data of the multiple SQL statements executed by the target transaction.

[0010] In the present application, after the client sends a first transaction carrying a start transaction statement to the blockchain system to instruct the blockchain system to create a target transaction, the client can continuously send multiple second transactions carrying SQL statements to the blockchain system to instruct the blockchain system to execute multiple SQL statements as a transaction. After the blockchain system creates the target transaction, each time it receives a second transaction sent by the client, it can execute the SQL statement carried by the second transaction. Specifically, if the SQL statement carried by the second transaction is used to modify the first data in the blockchain account book, then when the target transaction locks the first data, the first data is modified according to the SQL statement carried by the second transaction. After that, the client can send a third transaction carrying a commit statement to the blockchain system. After receiving the third transaction, the blockchain system can unlock all data locked by the target transaction in the blockchain account book to submit the modified data of the multiple SQL statements executed by the target transaction. In this way, support for transactions is realized in the blockchain system, that is, the blockchain system executes multiple SQL statements sent by the client as a transaction, thereby improving the flexibility and accuracy of the blockchain system in executing SQL statements, thereby improving business applicability.

[0011] Optionally, the method further comprises:

[0012] Whenever a second transaction sent by the client is received, the SQL statement carried by the second transaction is parsed to obtain a parsing result, wherein the parsing result includes a key-value pair and an operation type;

[0013] If the operation type is a modification type, corresponding data is searched in the blockchain account book according to the key value in the key-value pair as the first data to be modified by the SQL statement carried by the second transaction.

[0014] Optionally, the data in the blockchain ledger has one or more version records, the version record includes a data value, a transaction identifier and a version number, and the transaction identifier is an identifier of a transaction that generates the version record;

[0015] When the target transaction locks the first data, modifying the first data according to the SQL statement carried by the second transaction includes:

[0016] If the version number in the version record with the largest version number of the first data is not the lock version number, then a new version record with the version number being the lock version number and the transaction identifier being the identifier of the target transaction is added to the blockchain account book for the first data, so that the target transaction locks the first data, and the lock version number is the maximum value that the version number can obtain; or, if the version number in the version record with the largest version number of the first data is the lock version number and the transaction identifier is the identifier of the target transaction, then it is determined that the first data has been locked by the target transaction;

[0017] The data value whose version number is the lock version number in the version record of the first data is modified according to the SQL statement carried by the second transaction.

[0018] Optionally, unlocking all data in the blockchain ledger that is locked by the target transaction includes:

[0019] Assigning a commit version number to the target transaction;

[0020] The version numbers in all version records in the blockchain account book whose version number is the lock version number and whose transaction identifier is the identifier of the target transaction are modified to the submission version number of the target transaction, so as to unlock all data locked by the target transaction in the blockchain account book.

[0021] Optionally, the method further comprises:

[0022] Whenever a second transaction sent by the client is received, if the SQL statement carried by the second transaction is used to read the second data in the blockchain ledger, determining whether the second data is locked by the target transaction;

[0023] If the second data has been locked by the target transaction, read the data value whose version number is the lock version number in the version record of the second data;

[0024] If the second data is not locked by the target transaction, then under the repeatable read isolation level, read the data value with the largest version number among the data values ​​in the version record of the second data whose version number is less than the start version number of the target transaction, where the start version number of the target transaction is assigned when the target transaction is created; under the read committed isolation level, read the data value with the largest version number among the data values ​​in the version record of the second data except those whose version number is the lock version number.

[0025] Optionally, the method further comprises:

[0026] If a fourth transaction carrying a rollback statement is received from the client, all version records in the blockchain account book whose version number is the lock version number and whose transaction identifier is the identifier of the target transaction are deleted to roll back the modified data of multiple SQL statements executed by the target transaction.

[0027] Optionally, the method further comprises:

[0028] After adding a preset number of blocks to the blockchain, clearing the historical version records in the blockchain ledger; or,

[0029] When each transaction is submitted, the historical version records in the blockchain ledger are cleared; or,

[0030] When each transaction reads data in the blockchain ledger, the historical version records in the blockchain ledger are cleared.

[0031] Optionally, the clearing of historical version records in the blockchain ledger includes:

[0032] The smallest start version number among the start version numbers of the currently alive transactions is used as the target version number, where the start version number of the transaction is assigned when the transaction is created;

[0033] For each data in the blockchain ledger, taking a version record having a version number smaller than the target version number in the version record of the data as the target version record of the data;

[0034] Delete other historical version records except the version record with the largest version number in the target version record of the data.

[0035] In a second aspect, a transaction execution device is provided, which is applied to a blockchain system, and the device includes:

[0036] A creation module, configured to create a target transaction after receiving a first transaction carrying a start transaction statement sent by a client;

[0037] A receiving module, configured to receive a plurality of second transactions sent by the client, each of the plurality of second transactions carrying an SQL statement for operating a blockchain ledger that needs to be executed by the target transaction;

[0038] a modification module, configured to, upon receiving a second transaction sent by the client, modify the first data according to the SQL statement carried by the second transaction when the target transaction locks the first data, if the SQL statement carried by the second transaction is used to modify the first data in the blockchain account book;

[0039] The commit module is configured to unlock all data locked by the target transaction in the blockchain ledger if a third transaction carrying a commit statement is received from the client, so as to commit the modified data of the multiple SQL statements executed by the target transaction.

[0040] Optionally, the device further comprises:

[0041] A parsing module, configured to parse the SQL statement carried by a second transaction sent by the client each time the second transaction is received, and obtain a parsing result, wherein the parsing result includes a key-value pair and an operation type;

[0042] A search module is used to search the blockchain account book for corresponding data as the first data to be modified by the SQL statement carried by the second transaction according to the key value in the key-value pair if the operation type is a modification type.

[0043] Optionally, the data in the blockchain account book has one or more version records, the version record includes a data value, a transaction identifier and a version number, the transaction identifier is an identifier of a transaction that generates the version record; the modification module is used to:

[0044] If the version number in the version record with the largest version number of the first data is not the lock version number, then a new version record with the version number being the lock version number and the transaction identifier being the identifier of the target transaction is added to the blockchain account book for the first data, so that the target transaction locks the first data, and the lock version number is the maximum value that the version number can obtain; or, if the version number in the version record with the largest version number of the first data is the lock version number and the transaction identifier is the identifier of the target transaction, then it is determined that the first data has been locked by the target transaction;

[0045] The data value whose version number is the lock version number in the version record of the first data is modified according to the SQL statement carried by the second transaction.

[0046] Optionally, the submission module is used to:

[0047] Assigning a commit version number to the target transaction;

[0048] The version numbers in all version records in the blockchain account book whose version number is the lock version number and whose transaction identifier is the identifier of the target transaction are modified to the submission version number of the target transaction, so as to unlock all data locked by the target transaction in the blockchain account book.

[0049] Optionally, the device further comprises:

[0050] A judgment module, configured to, upon receiving a second transaction sent by the client, determine whether the second data is locked by the target transaction if the SQL statement carried by the second transaction is used to read the second data in the blockchain account book;

[0051] A first reading module is configured to read a data value whose version number is the lock version number in a version record of the second data if the second data has been locked by the target transaction;

[0052] A second reading module is used for, if the second data is not locked by the target transaction, then, under a repeatable read isolation level, reading a data value with the largest version number among data values ​​in the version record of the second data whose version number is smaller than the start version number of the target transaction, where the start version number of the target transaction is assigned when the target transaction is created; and under a read committed isolation level, reading a data value with the largest version number among data values ​​in the version record of the second data except those whose version number is the lock version number.

[0053] Optionally, the device further comprises:

[0054] The rollback module is configured to delete all version records in the blockchain ledger whose version number is the lock version number and whose transaction identifier is the identifier of the target transaction if a fourth transaction carrying a rollback statement sent by the client is received, so as to roll back the modified data of the multiple SQL statements executed by the target transaction.

[0055] Optionally, the device further comprises:

[0056] A cleaning module is used to clean up the historical version records in the blockchain account book after adding a preset number of blocks to the blockchain; or, to clean up the historical version records in the blockchain account book each time a transaction is submitted; or, to clean up the historical version records in the blockchain account book each time a transaction reads data in the blockchain account book.

[0057] Optionally, the cleaning module is used to:

[0058] The smallest start version number among the start version numbers of the currently alive transactions is used as the target version number, where the start version number of the transaction is assigned when the transaction is created;

[0059] For each data in the blockchain ledger, taking a version record having a version number smaller than the target version number in the version record of the data as the target version record of the data;

[0060] Delete other historical version records except the version record with the largest version number in the target version record of the data.

[0061] In a third aspect, a computer device is provided, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the transaction execution method when executed by the processor.

[0062] In a fourth aspect, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the above-mentioned transaction execution method is implemented.

[0063] In a fifth aspect, a computer program product comprising instructions is provided, which, when executed on a computer, enables the computer to execute the steps of the above-mentioned transaction execution method.

[0064] It can be understood that the beneficial effects of the second, third, fourth and fifth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0065] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work.

[0066] Figure 1 It is a structural diagram of a blockchain system provided by an embodiment of the present application;

[0067] Figure 2 It is a schematic diagram of a blockchain provided by an embodiment of the present application;

[0068] Figure 3 is a schematic diagram of a transaction execution system provided in an embodiment of the present application;

[0069] Figure 4 is a flow chart of a transaction execution method provided by an embodiment of the present application;

[0070] Figure 5 is a schematic diagram of an execution process of a non-persistent transaction provided in an embodiment of the present application;

[0071] Figure 6 is a schematic diagram of an execution process of a persistent transaction provided by an embodiment of the present application;

[0072] Figure 7 It is a structural diagram of a transaction execution device provided in an embodiment of the present application;

[0073] Figure 8It is a structural diagram of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0074] In order to make the objectives, technical solutions and advantages of the present application clearer, the implementation methods of the present application will be further described in detail below with reference to the accompanying drawings.

[0075] It should be understood that the "multiple" mentioned in this application refers to two or more. In the description of this application, unless otherwise specified, " / " means or, for example, A / B can mean A or B; "and / or" in this article is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in order to facilitate the clear description of the technical solution of this application, the words "first" and "second" are used to distinguish between the same items or similar items with basically the same functions and effects. Those skilled in the art can understand that the words "first" and "second" do not limit the quantity and execution order, and the words "first" and "second" do not limit them to be different.

[0076] Before explaining the embodiments of the present application, the relevant contents of the blockchain are explained first.

[0077] Figure 1 It is a structural diagram of a blockchain system provided in an embodiment of the present application.

[0078] See also Figure 1 , the blockchain system 100 refers to a system for sharing data between nodes, and the blockchain system 100 may include multiple nodes 101. Each node 101 can receive input information when performing normal work, and maintain the shared data in the blockchain system 100 based on the received input information. In order to ensure the information intercommunication within the blockchain system 100, there can be an information connection between each node 101 in the blockchain system 100, and information can be transmitted between the nodes 101 through the information connection. For example, when any node 101 in the blockchain system 100 receives input information, other nodes 101 in the blockchain system 100 obtain the input information according to the consensus algorithm, and store the input information as data in the shared data, so that the data stored on all nodes 101 in the blockchain system 100 are consistent.

[0079] Each node 101 in the blockchain system 100 stores an identical blockchain. Figure 2 Take this as an example to illustrate a possible structure of a blockchain. Of course, in actual applications, the structure of a blockchain may be different depending on different scenarios, and this embodiment of the present application does not limit this.

[0080] See also Figure 2 , the blockchain consists of multiple blocks, and the genesis block includes a block header and a block body. As an example, the block header stores input information feature values, version numbers, timestamps, and difficulty values, and the block body stores input information; the next block of the genesis block uses the genesis block as its parent block, and the next block also includes a block header and a block body. The block header stores the input information feature values ​​of the current block, the block header feature values, version numbers, timestamps, and difficulty values ​​of the parent block, and so on, so that the block data stored in each block in the blockchain is associated with the block data stored in the parent block, ensuring the security of the input information in the block.

[0081] The blockchain system 100 has computer technologies such as distributed data storage, peer-to-peer transmission, consensus mechanism, encryption algorithm, etc. The blockchain system 100 is a distributed shared account book and database, which has the characteristics of decentralization, non-tamperability, full traceability, traceability, collective maintenance, openness and transparency. These characteristics ensure the sharing, openness, authenticity, integrity, security and reliability of the blockchain.

[0082] Before explaining the embodiments of the present application in detail, the relevant concepts of the matters involved in the embodiments of the present application are explained.

[0083] A transaction is a collection of operations that form a single logical unit of work. A transaction can contain one or more operations that form a logical whole. These operations that form the logical whole are either all executed successfully or not executed at all. In other words, all the operations that constitute a transaction either have an impact on the database or have no impact at all, so that the database can always maintain a consistent state regardless of whether the transaction is executed successfully.

[0084] Transactions have ACID characteristics, which are: Atomicity: All operations in a transaction are inseparable as a whole, either all succeed or all fail. Consistency: The execution result of a transaction must make the database go from one consistent state to another. Isolation: Concurrently executed transactions will not affect each other, and their impact on the database is the same as when they are executed serially. Durability: Once a transaction is committed, its updates to the database are persistent.

[0085] Transactions are isolated from each other. In theory, the execution of transactions should not affect each other, and their impact on the database should be the same as when they are executed serially. However, complete isolation will lead to very low system concurrency performance and reduce resource utilization. Therefore, the requirements for isolation will be relaxed in actual applications, which will also reduce the consistency requirements for the database to a certain extent. The SQL standard defines different isolation levels for transactions, from low to high: READ UNCOMMITTED: Uncommitted data can be read, that is, if a transaction has started writing data, another transaction is not allowed to write at the same time, but other transactions are allowed to read this data. READCOMMITTED: Committed data can be read, that is, if a transaction is reading data, other transactions are allowed to access this data (including read and write operations); if a transaction is writing data, other transactions are prohibited from accessing this data. REPEATABLE READ: Within a transaction, the same data is read multiple times, and other transactions cannot access this data before the transaction ends. SERIALIZABLE: Provides strict transaction isolation and requires transactions to be executed serially, that is, transactions can only be executed one after another and cannot be executed concurrently.

[0086] The system architecture involved in the embodiments of the present application is described below.

[0087] Figure 3 Schematic diagram of a transaction execution system provided by an embodiment of the present application. Figure 3 , the transaction execution system includes: a client 301 and a blockchain system 302.

[0088] The client 301 can be installed on a terminal or a server. The server corresponding to the client 301 is installed on the blockchain system 302. The blockchain system 302 can be the Figure 1-Figure 2 The blockchain system 100 shown in the embodiment. The client 301 and the blockchain system 302 can communicate through a wired connection and a wireless connection.

[0089] The client 301 is used to generate an SQL statement and carry the SQL statement in the transaction to the blockchain system 302. The SQL statement is used to implement operations on the blockchain account book, that is, to read or modify (including insert, update, and delete) the data in the blockchain account book. After the blockchain system 302 receives the transaction sent by the client 301, it can execute the SQL statement carried by the transaction by executing the transaction, thereby implementing operations on the blockchain account book. That is, in the embodiment of the present application, the client 301 can directly operate the blockchain account book in the blockchain system 302 through SQL statements.

[0090] Among them, the client 301 and the blockchain system 302 can be Figure 4 The transaction execution method provided in the embodiment is used to implement the blockchain system 302 to execute multiple SQL statements sent by the client 301 as a transaction, thereby improving the flexibility and accuracy of the blockchain system 302 in executing SQL statements, thereby improving business applicability.

[0091] The transaction execution method provided in the embodiment of the present application is explained in detail below.

[0092] Figure 4 is a flow chart of a transaction execution method provided by an embodiment of the present application. Figure 4 , the method comprises the following steps.

[0093] Step 401: The client sends a first transaction carrying a start transaction statement to the blockchain system.

[0094] The transaction body of the first transaction may include a start transaction statement. The start transaction statement is used to instruct the blockchain system to start a transaction so as to execute multiple SQL statements subsequently sent by the client as a transaction, that is, to commit or roll back the execution results of the multiple SQL statements at the same time.

[0095] Step 402: After receiving the first transaction sent by the client, the blockchain system creates a target transaction.

[0096] After the blockchain system creates the target transaction, it can use the multiple SQL statements subsequently sent by the client as the SQL statements to be executed by the target transaction. The execution results of multiple SQL statements in the target transaction can be committed or rolled back at the same time. In other words, target transaction commit means committing the execution results of multiple SQL statements in the target transaction at the same time; target transaction rollback means rolling back the execution results of multiple SQL statements in the target transaction at the same time.

[0097] The operation of the blockchain system to create a target transaction is similar to the operation of a device to create a transaction in the related art, and the embodiments of the present application will not elaborate on this.

[0098] After the blockchain system creates the target transaction, an identifier can be set for the target transaction, and a start version number can be assigned to the target transaction. Optionally, the identifier of the target transaction can be the same as the start version number of the target transaction.

[0099] The identifier of a transaction is used to uniquely identify the transaction. Optionally, in the blockchain system, the identifiers of each transaction may be incremental, that is, the identifier of a transaction created earlier may be smaller than the identifier of a transaction created later.

[0100] The start version number of a transaction can be the logical time when the transaction is created. For example, the blockchain system can have a logical clock, and the blockchain system can use the globally saved monotonically increasing logical clock to determine the logical time when each transaction is created, and use the logical time when each transaction is created as the start version number of each transaction. The logical time can be uint64 (unsigned 64-bit integer).

[0101] Step 403: The client sends multiple second transactions to the blockchain system.

[0102] The multiple second transactions sent by the client to the blockchain system are transactions for operating the blockchain ledger in the blockchain system. Each of the multiple second transactions carries an SQL statement. The SQL statement carried by each of the multiple second transactions is an SQL statement to be executed by the newly created target transaction of the blockchain system.

[0103] The SQL statement carried in the second transaction is used to operate the blockchain ledger. For example, the SQL statement may be a DML (Data Manipulation Language) statement. Specifically, the SQL statement may be used to read (SELECT) or modify (including insert (INSERT), update (UPDATE), delete (DELETE)) data in the blockchain ledger.

[0104] After the client sends multiple second transactions to the blockchain system, the blockchain system can receive the multiple second transactions, and each time the blockchain system receives a second transaction, it can execute the following steps 404 to 406.

[0105] Step 404: Whenever the blockchain system receives a second transaction sent by the client, it determines whether the second transaction is to modify or read data in the blockchain ledger.

[0106] Specifically, each time the blockchain system receives a second transaction sent by the client, it can parse the SQL statement carried by the second transaction to obtain a parsing result; if the operation type in the parsing result is a modification type, it is determined that the second transaction is to modify the data in the blockchain account book, and the corresponding data can be searched in the blockchain account book according to the key value in the key-value pair in the parsing result as the first data to be modified by the SQL statement carried by the second transaction; if the operation type in the parsing result is a read type, it is determined that the second transaction is to read the data in the blockchain account book, and the corresponding data can be searched in the blockchain account book according to the key value in the key-value pair in the parsing result as the second data to be read by the SQL statement carried by the second transaction.

[0107] The parsing result includes a key-value pair and an operation type. The key-value pair includes a key value and a value value. The key value is the keyword of the data to be operated (such as a primary key), and the data to be operated can be found from the blockchain account book according to the key value. The value value is the specific value of the data to be operated. The operation type is used to indicate the operation to be performed on the data, and can include a read type and a modification type (including an insert type, an update type, and a delete type).

[0108] The blockchain system parses the SQL statement carried by the second transaction, that is, converts the SQL statement's description of structured data into a description of kv type data, so that the parsing result containing key-value pairs and operation types can be obtained. Kv type data is the data format that can be stored in the blockchain ledger. The operation of the blockchain system parsing the SQL statement carried by the second transaction can be implemented by calling the SQL smart contract.

[0109] The operation of the blockchain system parsing the SQL statement carried by the second transaction can refer to the operation of a certain device parsing the SQL statement in the related technology, which is not elaborated in detail in the embodiments of the present application.

[0110] The following is an explanation of the data structure in the blockchain ledger.

[0111] The data in the blockchain ledger can have one or more version records. For any version record of any data in the blockchain ledger, this version record includes a data value, a transaction identifier, and a version number. The data value is the real value of the data (such as rowValue), the transaction identifier is the identifier of the transaction that generated this version record, and the version number is used to indicate the version of this version record. Optionally, the version number can be implemented with the help of the MVCC (Multiversion Concurrency Control) mechanism.

[0112] For any data in the blockchain ledger, if the data has only one version record, then this version record is the latest version of the data. If the data has multiple version records, the version record with the largest version number is the latest version of the data, and the other version records are historical versions of the data.

[0113] For example, the data in the blockchain account book can be kv type data. A piece of data in the blockchain account book can be shown in Table 1 below, where each line from the second to the third line in Table 1 is a version record of the data, that is, the data has three version records.

[0114] Table 1

[0115] key value value key3 Data value 3, transaction identifier 3, version number 3 key2 Data value 2, transaction identifier 2, version number 2 key1 Data value 1, transaction identifier 1, version number 1

[0116] The embodiment of the present application only uses Table 1 above as an example to illustrate the version record of data in the blockchain ledger, and Table 1 above does not limit the embodiment of the present application.

[0117] It is worth noting that in the embodiment of the present application, a lock version number is introduced. The lock version number is the maximum value that the version number can take. For example, when the version number is uint64, the lock version number can be the maximum value in uint64. For any data in the blockchain ledger, if the version number in the version record with the largest version number of this data is the lock version number, it means that this data has been locked and is locked by the transaction identified by the transaction identifier in the version record with the largest version number. After this data is locked by the transaction, only this transaction can modify this data, and other transactions cannot modify this data. That is, the embodiment of the present application adopts a pessimistic locking mechanism.

[0118] In addition, for any data in the blockchain ledger, the value in the version record of this data is structured data, and includes data value, transaction identifier and version number. Optionally, for the version record with the lock version number in the version record of this data, the value in the version record may also include a specified data type (i.e., lock), etc. For other version records in the version record of this data except the version record with the lock version number, the value in other version records may also include the commit version number of the transaction identified by the transaction identifier, the data type when the transaction is committed (i.e., write (insert or update), or delete), etc.

[0119] The submission version number of a transaction can be the logical time when the transaction is submitted. For example, the blockchain system can have a logical clock, and the blockchain system can use the globally saved monotonically increasing logical clock to determine the logical time when each transaction is submitted, and use the logical time when each transaction is submitted as the submission version number of each transaction. The logical time can be uint64.

[0120] It should be noted that when a transaction deletes a piece of data in the blockchain ledger, when the transaction is submitted, the data may not be deleted from the blockchain ledger first, but its data type may be marked as deleted first. In this way, if there are other transactions that want to read this data, when it is found that the data type of this data is deleted, it is determined that this data has been deleted and a null value is returned.

[0121] If the second transaction is to modify the data in the blockchain ledger, the blockchain system continues to execute the following step 405. If the second transaction is to read the data in the blockchain ledger, the blockchain system continues to execute the following step 406.

[0122] Step 405: If the SQL statement carried by the second transaction is used to modify the first data in the blockchain ledger, the blockchain system modifies the first data according to the SQL statement carried by the second transaction when the target transaction locks the first data.

[0123] If the SQL statement carried by the second transaction needs to modify the first data in the blockchain account book, it is necessary to first determine whether the first data is locked by other transactions except the target transaction. If the first data has been locked by other transactions, a lock conflict will occur. At this time, the second transaction cannot modify the first data, the second transaction fails to execute, and the target transaction rolls back; if the first data is not locked by other transactions, the second transaction can modify the first data, the second transaction can be executed normally, and the target transaction continues to execute normally.

[0124] In this case, if the version number in the version record with the largest version number of the first data is not the lock version number, it means that the first data is not locked by any transaction. At this time, since the second transaction needs to modify the first data, the target transaction needs to lock the first data. Specifically, if the first data is not locked by any transaction, a new version record with a version number of the lock version number and a transaction identifier of the target transaction is added to the blockchain account book for the first data, so that the target transaction locks the first data. Optionally, a target key-value pair can be written to the blockchain account book to implement the locking of the first data by the target transaction. Among them, the key value in the target key-value pair includes the key value (such as rowKey) and the lock version number in the key-value pair in the parsed result of the SQL statement carried by the second transaction, and the value in the target key-value pair is the data value in the version record of the current latest version of the first data.

[0125] Alternatively, if the version number in the version record with the largest version number of the first data is the lock version number, and the transaction identifier is the identifier of the target transaction, then it is determined that the first data has been locked by the target transaction. In this case, before executing the second transaction, when executing the first second transaction that needs to modify the first data, a version record with the version number being the lock version number and the transaction identifier being the identifier of the target transaction is added to the blockchain account book for the first data, so as to realize the locking of the first data by the target transaction.

[0126] For example, assuming that multiple version records of the first data are shown in Table 1, if the first data is not locked by any transaction, a new version record is added to Table 1, and the following Table 2 is obtained. As shown in Table 2, the data value in the new version record is the same as the data value in the previous version record, the version number in the new version record is the lock version number, and the transaction identifier in the new version record is the identifier of the target transaction. In this way, the target transaction locks the first data.

[0127] Table 2

[0128] key value value key4 Data value 3, target transaction identifier, lock version number key3 Data value 3, transaction identifier 3, version number 3 key2 Data value 2, transaction identifier 2, version number 2 key1 Data value 1, transaction identifier 1, version number 1

[0129] The embodiment of the present application only uses Table 2 above as an example to illustrate the version record of the first data, and Table 2 above does not constitute a limitation on the embodiment of the present application.

[0130] In the case where the first data is locked by the target transaction, the blockchain system can modify the data value with the lock version number in the version record of the first data according to the SQL statement carried by the second transaction. Specifically, the data value with the lock version number in the version record of the first data can be modified according to the operation type in the parsing result of the SQL statement carried by the second transaction and the value in the key-value pair. At this time, the data value in the version record of the first data locked by the target transaction is actually modified.

[0131] It is worth noting that in the embodiment of the present application, if there is a second transaction to modify the first data, a version record with a version number of the lock version number and a transaction identifier of the target transaction will be added to the first data for modification by the target transaction. Other version records in the first data except for this newly added version record locked by the target transaction are generated by the submitted historical transaction. In this way, before the target transaction is submitted, the modification of the first data by the target transaction will not affect the data value previously submitted for the first data.

[0132] Another point worth noting is that after the target transaction modifies the data in the blockchain ledger, since the subsequent submission or rollback of the target transaction is involved, it is necessary to know the key value of the data modified by the target transaction in the blockchain ledger, so as to submit or roll back the modified data. Therefore, it is necessary to record the key value of the data modified by the target transaction. In this case, the identifier of the target transaction and the key value of the data modified by the target transaction can be stored in correspondence. For example, the key value of the data modified by the target transaction can be stored with the identifier of the target transaction as a prefix, and can be stored in memory for easy iteration, and the target transaction can be submitted or rolled back later.

[0133] Step 406: If the SQL statement carried by the second transaction is used to read the second data in the blockchain ledger, the blockchain system reads the second data according to the SQL statement carried by the second transaction.

[0134] The blockchain system can read the data value in the version record of the second data according to the operation type in the parsing result of the SQL statement carried by the second transaction and the value in the key-value pair. The specific reading process may include the following steps (1) to (3):

[0135] (1) The blockchain system first determines whether the second data is locked by the target transaction.

[0136] Specifically, if the version number in the version record with the largest version number of the second data is a lock version number, and the transaction identifier is the identifier of the target transaction, the blockchain system determines that the second data has been locked by the target transaction; otherwise, the blockchain system determines that the second data has not been locked by the target transaction.

[0137] (2) If the second data has been locked by the target transaction, the blockchain system reads the data value whose version number is the lock version number in the version record of the second data.

[0138] If the second data has been locked by the target transaction, the data value with the lock version number in the version record of the second data is the data value modified by the target transaction, and thus the data value can be directly read at this time.

[0139] (3) If the second data is not locked by the target transaction, then under the repeatable read isolation level, the blockchain system reads the data value with the largest version number among the data values ​​whose version numbers are less than the start version number of the target transaction in the version record of the second data; under the read committed isolation level, the blockchain system reads the data value with the largest version number among the data values ​​whose version numbers are other than the locked version number in the version record of the second data.

[0140] Under the repeatable read isolation level, what can be read is the data value in the version record generated by the transaction that was committed last before the target transaction was created, that is, the data value with the largest version number among the data values ​​in the version record of the second data whose version number is less than the start version number of the target transaction can be read.

[0141] At the read committed isolation level, the data value in the version record generated by the most recently committed transaction can be read, that is, the data value with the largest version number among the data values ​​in the version record of the second data except the data value with the lock version number can be read.

[0142] Furthermore, after the blockchain system reads the second data, it can also return the read second data to the client.

[0143] It is worth noting that the client sends multiple second transactions to the blockchain system. Each time the blockchain system receives a second transaction, it can execute the second transaction according to the above steps 404 to 406, that is, execute the SQL statement carried by the second transaction to operate the blockchain ledger, until the blockchain system receives and executes the last second transaction sent by the client.

[0144] After the client sends multiple second transactions to the blockchain system, it can instruct the blockchain system to commit or roll back the target transaction. If the client wants to instruct the target transaction to be committed, it can continue to perform the following steps 407-408. If the client wants to instruct the target transaction to be rolled back, it can perform the following steps 409-410.

[0145] Step 407: The client sends a third transaction carrying a commit statement to the blockchain system.

[0146] The commit statement is used to indicate the target transaction is committed. After the client sends a start transaction statement to the blockchain system to instruct the blockchain system to create a target transaction, it sends multiple SQL statements to the blockchain system. At this time, the blockchain system uses the multiple SQL statements as the SQL statements in the created target transaction and executes the multiple SQL statements. After that, the client can send a commit statement to the blockchain system to instruct the blockchain system to commit the created target transaction, that is, to commit the execution results of the multiple SQL statements in the target transaction.

[0147] Step 408: After receiving the third transaction sent by the client, the blockchain system unlocks all data locked by the target transaction in the blockchain ledger to submit the modified data of multiple SQL statements executed by the target transaction.

[0148] After the blockchain system receives the third transaction sent by the client, it determines that the target transaction needs to be committed, and then assigns a commit version number to the target transaction. Then, the version numbers of all version records in the blockchain ledger whose version number is the lock version number and whose transaction identifier is the identifier of the target transaction are modified to the commit version number of the target transaction, so as to unlock all data locked by the target transaction in the blockchain ledger.

[0149] The version record in the blockchain ledger whose version number is the lock version number and whose transaction identifier is the identifier of the target transaction is the version record locked by the target transaction, that is, the version record that is newly added when the target transaction is executed and the data value is modified. Therefore, when submitting the target transaction, it is only necessary to modify the version number in the version record to the submitted version number of the target transaction to achieve unlocking. At this time, the version record is updated to the blockchain ledger and is visible to other transactions, thereby realizing the submission of modified data of multiple SQL statements executed by the target transaction.

[0150] In one possible manner, since the target transaction identifier and the key value of the data modified by the target transaction in the blockchain system were stored when the target transaction was executed, after the blockchain system receives the third transaction sent by the client, it can first obtain the key value of the modified data according to the identifier of the target transaction, and then modify the version number of the data corresponding to the key value in the blockchain account book to the lock version number and the transaction identifier to the target transaction identifier. The version number in the version record is modified to the submission version number of the target transaction to submit the modified data of the target transaction, thereby improving the submission efficiency of the target transaction.

[0151] Step 409: The client sends a fourth transaction carrying a rollback statement to the blockchain system.

[0152] The rollback statement is used to instruct the target transaction to be rolled back. After the client sends a start transaction statement to the blockchain system to instruct the blockchain system to create a target transaction, it sends multiple SQL statements to the blockchain system. At this time, the blockchain system uses the multiple SQL statements as the SQL statements in the created target transaction and executes the multiple SQL statements. Afterwards, the client can send a rollback statement to the blockchain system to instruct the blockchain system to roll back the created target transaction, that is, to roll back the execution results of the multiple SQL statements in the target transaction.

[0153] Step 410: After receiving the fourth transaction sent by the client, the blockchain system rolls back the modified data of multiple SQL statements executed by the target transaction.

[0154] After the blockchain system receives the fourth transaction sent by the client, it determines that the target transaction needs to be rolled back, and deletes all version records in the blockchain ledger whose version number is the lock version number and whose transaction identifier is the identifier of the target transaction, so as to roll back the modified data of multiple SQL statements executed by the target transaction.

[0155] The version record in the blockchain ledger whose version number is the lock version number and whose transaction identifier is the identifier of the target transaction is the version record locked by the target transaction, that is, the version record that is newly added when the target transaction is executed and the data value is modified. Therefore, when rolling back the target transaction, you only need to delete the version record to achieve the rollback of the modified data of multiple SQL statements executed by the target transaction.

[0156] In one possible manner, since the target transaction identifier and the key value of the data modified by the target transaction in the blockchain system were stored when the target transaction was executed, after the blockchain system receives the fourth transaction sent by the client, it can first obtain the key value of the modified data according to the identifier of the target transaction, and then delete the version record in the blockchain account book whose version number of the data corresponding to the key value is the lock version number and whose transaction identifier is the identifier of the target transaction, so as to roll back the modified data of the target transaction, thereby improving the rollback efficiency of the target transaction.

[0157] In some embodiments, the blockchain system may also periodically perform GC (Garbage Collection), that is, it may clean up historical version records in the blockchain ledger to delete redundant and useless version records and save storage resources.

[0158] For example, the blockchain system can clean up the historical version records in the blockchain ledger after adding a preset number of blocks to the blockchain; or, clean up the historical version records in the blockchain ledger each time a transaction is submitted; or, clean up the historical version records in the blockchain ledger each time a transaction reads data in the blockchain ledger.

[0159] For any data in the blockchain ledger, the historical version record of this data can be the version record of this data except the locked version record and the version record generated by the latest submitted transaction. In this case, the operation of the blockchain system to clean up the historical version records in the blockchain ledger can be: take the smallest start version number among the start version numbers of the currently alive transactions as the target version number; for each data in the blockchain ledger, take the version record with a version number smaller than the target version number in the version record of this data as the target version record of this data; delete other historical version records except the version record with the largest version number in the target version record of this data.

[0160] The currently live transaction is the transaction that is being executed but not yet committed. The blockchain system can record the start version number of the currently live transaction in real time, and based on this, the smallest start version number among the start version numbers of the currently live transactions can be obtained.

[0161] Since the target version number is the smallest start version number among the start version numbers of the currently alive transactions, the version records with version numbers smaller than the target version number are all version records generated by the committed transactions. That is, the target version record of this data is the version record generated by the committed transaction, so the version record with the largest version number among the target version records of this data can be retained, and other historical version records can be deleted.

[0162] It is worth noting that the operations performed by the blockchain system in the embodiments of the present application can all be performed by the SQL execution engine in the blockchain system. Of course, they can also be performed by other modules, and the embodiments of the present application are not limited to this.

[0163] In some embodiments, there are two situations in which transactions are used, and whether to automatically submit transactions is determined by starting transaction statements. If the blockchain system does not receive a start transaction statement, the transaction is automatically submitted, that is, a non-persistent transaction is executed. Specifically, each SQL statement received is submitted after execution. At this time, each received SQL statement is actually executed as a transaction. If the blockchain system receives a start transaction statement, the transaction is not automatically submitted, that is, a persistent transaction is executed. Specifically, multiple received SQL statements are executed as a transaction, and the execution results of multiple SQL statements are submitted or rolled back at the same time.

[0164] For ease of understanding, the following Figure 5 and Figure 6 Let's take an example to illustrate the execution process of non-persistent transactions and persistent transactions.

[0165] Figure 5 Schematic diagram of the execution process of a non-persistent transaction provided by an embodiment of the present application. Figure 5 ,The execution process of non-persistent transactions applied to the blockchain system may include the following steps (1) to (5).

[0166] (1) After receiving the transaction containing the SQL statement sent by the client, this SQL statement is regarded as a transaction.

[0167] (2) Parse the SQL statement to determine whether the SQL statement needs to read data in the blockchain ledger or needs to modify data in the blockchain ledger.

[0168] (3) If the SQL statement needs to modify data in the blockchain ledger, it is determined whether the data to be modified has been locked by other transactions; if the data has been locked by other transactions, there is a lock conflict and the current transaction fails to execute; if the data has not been locked by other transactions, the transaction locks the data and then modifies the data. After the modification is completed, the data is unlocked to commit the transaction.

[0169] (4) If the SQL statement needs to read data in the blockchain ledger, the data value with the largest version number among the data values ​​whose version number is less than or equal to the start version number of the transaction in the version record of the data to be read that is not locked by other transactions is read, and the read data is returned to the client to commit the transaction.

[0170] (5) After the transaction is submitted, the GC process is triggered to clean up the historical version records in the blockchain ledger.

[0171] Figure 6 Schematic diagram of the execution process of a persistent transaction provided by an embodiment of the present application. Figure 6 ,The execution process of persistent transactions applied to the blockchain system can include the following steps (1)-step (8).

[0172] (1) After receiving the transaction sent by the client with the start transaction statement, create a transaction.

[0173] (2) Receive multiple transactions containing SQL statements sent by the client.

[0174] (3) Whenever a transaction carrying an SQL statement is received from a client, the SQL statement is parsed to determine whether the SQL statement needs to read data in the blockchain ledger or needs to modify data in the blockchain ledger.

[0175] (4) If the SQL statement needs to modify data in the blockchain ledger, determine whether the data to be modified has been locked by other transactions; if the data has been locked by other transactions, there is a lock conflict, the current transaction fails, and the transaction also fails; if the data has not been locked by other transactions, the transaction locks the data and then modifies the data.

[0176] (5) If the SQL statement needs to read data in the blockchain ledger, the data value with the largest version number among the data values ​​whose version number is less than or equal to the start version number of the transaction in the version record of the data to be read that is not locked by other transactions is read, and the read data is returned to the client.

[0177] (6) If a transaction carrying a commit statement is received from the client, the version numbers of all version records in the blockchain ledger whose version number is the lock version number and whose transaction identifier is the identifier of the transaction are modified to the commit version number of the transaction, so as to commit the modified data of multiple SQL statements executed by the transaction.

[0178] (7) If a transaction carrying a rollback statement is received from the client, all version records in the blockchain ledger whose version number is the lock version number and whose transaction identifier is the identifier of the transaction are deleted to roll back the modified data of multiple SQL statements executed by the transaction.

[0179] (8) After the transaction is committed or rolled back, the GC process is triggered to clean up the historical version records in the blockchain ledger.

[0180] In an embodiment of the present application, after the client sends a first transaction carrying a start transaction statement to the blockchain system to instruct the blockchain system to create a target transaction, the client can continuously send multiple second transactions carrying SQL statements to the blockchain system to instruct the blockchain system to execute multiple SQL statements as a transaction. After the blockchain system creates the target transaction, each time it receives a second transaction sent by the client, it can execute the SQL statement carried by the second transaction. Specifically, if the SQL statement carried by the second transaction is used to modify the first data in the blockchain account book, then when the target transaction locks the first data, the first data is modified according to the SQL statement carried by the second transaction. After that, the client can send a third transaction carrying a commit statement to the blockchain system. After receiving the third transaction, the blockchain system can unlock all data locked by the target transaction in the blockchain account book to submit the modified data of the multiple SQL statements executed by the target transaction. In this way, support for transactions is realized in the blockchain system, that is, the blockchain system executes multiple SQL statements sent by the client as a transaction, thereby improving the flexibility and accuracy of the blockchain system in executing SQL statements, thereby improving business applicability.

[0181] Figure 7 1 is a schematic diagram of a transaction execution device provided in an embodiment of the present application. The device can be implemented as part or all of a computer device by software, hardware, or a combination of both. The computer device can be the following Figure 8 The computer device shown may be a blockchain system. Figure 7 The device includes: a creation module 701, a receiving module 702, a modification module 703, and a submission module 704.

[0182] A creation module 701 is used to create a target transaction after receiving a first transaction carrying a start transaction statement sent by a client;

[0183] A receiving module 702 is used to receive multiple second transactions sent by the client, each of the multiple second transactions carries an SQL statement for operating a blockchain ledger that needs to be executed by the target transaction;

[0184] The modification module 703 is configured to, upon receiving a second transaction sent by the client, modify the first data according to the SQL statement carried by the second transaction if the SQL statement carried by the second transaction is used to modify the first data in the blockchain ledger, when the target transaction locks the first data;

[0185] The commit module 704 is configured to unlock all data locked by the target transaction in the blockchain ledger if a third transaction carrying a commit statement is received from the client, so as to commit the modified data of the multiple SQL statements executed by the target transaction.

[0186] Optionally, the device further comprises:

[0187] A parsing module, configured to parse an SQL statement carried by a second transaction each time a second transaction sent by a client is received, and obtain a parsing result, wherein the parsing result includes a key-value pair and an operation type;

[0188] The search module is used to search the corresponding data in the blockchain account book according to the key value in the key-value pair as the first data to be modified by the SQL statement carried by the second transaction if the operation type is a modification type.

[0189] Optionally, the data in the blockchain ledger has one or more version records, the version record includes a data value, a transaction identifier and a version number, the transaction identifier is an identifier of a transaction that generates the version record; the modification module 703 is used to:

[0190] If the version number in the version record with the largest version number of the first data is not the lock version number, then a new version record with the version number being the lock version number and the transaction identifier being the identifier of the target transaction is added to the blockchain account book for the first data, so that the target transaction locks the first data, and the lock version number is the maximum value that the version number can obtain; or, if the version number in the version record with the largest version number of the first data is the lock version number, and the transaction identifier is the identifier of the target transaction, then it is determined that the first data has been locked by the target transaction;

[0191] The data value whose version number is the lock version number in the version record of the first data is modified according to an SQL statement carried by a second transaction.

[0192] Optionally, the submission module 704 is used to:

[0193] Assign a commit version number to the target transaction;

[0194] The version numbers in all version records in the blockchain ledger whose version number is the lock version number and whose transaction identifier is the identifier of the target transaction are modified to the committed version number of the target transaction, so as to unlock all data locked by the target transaction in the blockchain ledger.

[0195] Optionally, the device further comprises:

[0196] A judgment module, configured to, upon receiving a second transaction sent by a client, determine whether the second data is locked by a target transaction if a SQL statement carried by the second transaction is used to read the second data in the blockchain account book;

[0197] A first reading module is used to read a data value whose version number is a lock version number in a version record of the second data if the second data has been locked by the target transaction;

[0198] The second reading module is used to read the data value with the largest version number among the data values ​​whose version number is less than the start version number of the target transaction in the version record of the second data under the repeatable read isolation level if the second data is not locked by the target transaction, and the start version number of the target transaction is assigned when the target transaction is created; and to read the data value with the largest version number among the data values ​​whose version number is the lock version number in the version record of the second data under the read committed isolation level.

[0199] Optionally, the device further comprises:

[0200] The rollback module is used to delete all version records in the blockchain ledger whose version number is the lock version number and whose transaction identifier is the identifier of the target transaction if a fourth transaction carrying a rollback statement is received from the client, so as to roll back the modified data of multiple SQL statements executed by the target transaction.

[0201] Optionally, the device further comprises:

[0202] The cleaning module is used to clean up the historical version records in the blockchain ledger after adding a preset number of blocks to the blockchain; or, to clean up the historical version records in the blockchain ledger each time a transaction is submitted; or, to clean up the historical version records in the blockchain ledger each time a transaction reads data in the blockchain ledger.

[0203] Optionally, the cleanup module is used to:

[0204] The smallest start version number among the start versions of the currently alive transactions is used as the target version number. The start version number of a transaction is assigned when the transaction is created.

[0205] For each data in the blockchain ledger, the version record with a version number smaller than the target version number in the version record of a data is used as the target version record of the data;

[0206] Delete all historical version records except the one with the largest version number in the target version record of a data.

[0207] In an embodiment of the present application, after the client sends a first transaction carrying a start transaction statement to the blockchain system to instruct the blockchain system to create a target transaction, the client can continuously send multiple second transactions carrying SQL statements to the blockchain system to instruct the blockchain system to execute multiple SQL statements as a transaction. After the blockchain system creates the target transaction, each time it receives a second transaction sent by the client, it can execute the SQL statement carried by the second transaction. Specifically, if the SQL statement carried by the second transaction is used to modify the first data in the blockchain account book, then when the target transaction locks the first data, the first data is modified according to the SQL statement carried by the second transaction. After that, the client can send a third transaction carrying a commit statement to the blockchain system. After receiving the third transaction, the blockchain system can unlock all data locked by the target transaction in the blockchain account book to submit the modified data of the multiple SQL statements executed by the target transaction. In this way, support for transactions is realized in the blockchain system, that is, the blockchain system executes multiple SQL statements sent by the client as a transaction, thereby improving the flexibility and accuracy of the blockchain system in executing SQL statements, thereby improving business applicability.

[0208] It should be noted that: the transaction execution device provided in the above embodiment only uses the division of the above-mentioned functional modules as an example when executing transactions. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0209] The functional units and modules in the above embodiments may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit, and the above integrated units may be implemented in the form of hardware or in the form of software functional units. In addition, the specific names of the functional units and modules are only for the convenience of distinguishing each other, and are not used to limit the protection scope of the embodiments of the present application.

[0210] The transaction execution device and transaction execution method embodiments provided in the above embodiments belong to the same concept. The specific working process of the units and modules in the above embodiments and the technical effects brought about can be found in the method embodiment part and will not be repeated here.

[0211] Figure 8 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present application. Figure 8As shown, the computer device 8 includes: a processor 80, a memory 81, and a computer program 82 stored in the memory 81 and executable on the processor 80. When the processor 80 executes the computer program 82, the steps executed by the blockchain system in the transaction execution method in the above embodiment are implemented.

[0212] The computer device 8 may be a server cluster including multiple servers, and specifically may be a blockchain system. Those skilled in the art will appreciate that Figure 8 It is only an example of the computer device 8 and does not constitute a limitation on the computer device 8. It may include more or fewer components than shown in the figure, or a combination of certain components, or different components, such as input and output devices, network access devices, etc.

[0213] The processor 80 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), field-programmable gate arrays (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.

[0214] In some embodiments, the memory 81 may be an internal storage unit of the computer device 8, such as a hard disk or memory of the computer device 8. In other embodiments, the memory 81 may also be an external storage device of the computer device 8, such as a plug-in hard disk, a smart media card (SMC), a secure digital (SD) card, a flash card, etc. equipped on the computer device 8. Further, the memory 81 may also include both an internal storage unit and an external storage device of the computer device 8. The memory 81 is used to store an operating system, an application program, a boot loader, data, and other programs. The memory 81 may also be used to temporarily store data that has been output or is to be output.

[0215] An embodiment of the present application also provides a computer device, which includes: at least one processor, a memory, and a computer program stored in the memory and executable on the at least one processor, and when the processor executes the computer program, the steps in any of the above-mentioned method embodiments are implemented.

[0216] An embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.

[0217] An embodiment of the present application provides a computer program product, which, when executed on a computer, enables the computer to execute the steps in the above-mentioned method embodiments.

[0218] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above method embodiments, which can be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium. When the computer program is executed by the processor, the steps of the above method embodiments can be implemented. Among them, the computer program includes computer program code, which can be in source code form, object code form, executable file or some intermediate form. The computer-readable medium may at least include: any entity or device that can carry the computer program code to the camera / terminal device, recording medium, computer memory, ROM (Read-Only Memory), RAM (Random Access Memory), CD-ROM (Compact Disc Read-Only Memory), magnetic tape, floppy disk and optical data storage device. The computer-readable storage medium mentioned in the present application can be a non-volatile storage medium, in other words, it can be a non-transient storage medium.

[0219] It should be understood that all or part of the steps to implement the above embodiments can be implemented by software, hardware, firmware or any combination thereof. When implemented using software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. The computer instructions can be stored in the above-mentioned computer readable storage medium.

[0220] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0221] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0222] In the embodiments provided in the present application, it should be understood that the disclosed devices / computer equipment and methods can be implemented in other ways. For example, the device / computer equipment embodiments described above are only schematic, for example, the division of modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.

[0223] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0224] The embodiments described above are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, a person skilled in the art should understand that the technical solutions described in the aforementioned embodiments may still be modified, or some of the technical features may be replaced by equivalents. Such modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.

Claims

1. A transaction execution method, It is characterized in that Applied to a blockchain system, the method includes: After receiving the first transaction carrying the start transaction statement sent by the client, create a target transaction; Receive multiple second transactions sent by the client, each of the multiple second transactions carries a structured query language SQL statement for operating a blockchain ledger that needs to be executed by the target transaction, the data in the blockchain ledger has one or more version records, the version record includes a data value, a transaction identifier and a version number, the transaction identifier is an identifier of a transaction that generates the version record, the version number in the version record is a lock version number or a commit version number of a transaction identified by the transaction identifier, the commit version number of the transaction is a logical time when the transaction is committed, and the lock version number is the maximum value that the version number can obtain; Whenever a second transaction sent by the client is received, if the SQL statement carried by the second transaction is used to modify the first data in the blockchain account book, then, if the version number in the version record with the largest version number of the first data is not the lock version number, a version record with a version number of the lock version number and a transaction identifier of the target transaction is added to the blockchain account book for the first data, so that the target transaction locks the first data, or, if the version number in the version record with the largest version number of the first data is the lock version number and the transaction identifier is the identifier of the target transaction, it is determined that the first data has been locked by the target transaction; modify the data value with a version number of the lock version number in the version record of the first data according to the SQL statement carried by the second transaction; If a third transaction carrying a commit statement sent by the client is received, all data locked by the target transaction in the blockchain ledger are unlocked to commit the modified data of the multiple SQL statements executed by the target transaction.

2. The method according to claim 1, It is characterized in that The method further comprises: Whenever a second transaction sent by the client is received, the SQL statement carried by the second transaction is parsed to obtain a parsing result, wherein the parsing result includes a key-value pair and an operation type; If the operation type is a modification type, corresponding data is searched in the blockchain account book according to the key value in the key-value pair as the first data to be modified by the SQL statement carried by the second transaction.

3. The method according to claim 1, It is characterized in that The unlocking of all data in the blockchain ledger that is locked by the target transaction includes: Assigning a commit version number to the target transaction; The version numbers in all version records in the blockchain account book whose version number is the lock version number and whose transaction identifier is the identifier of the target transaction are modified to the submission version number of the target transaction, so as to unlock all data locked by the target transaction in the blockchain account book.

4. The method according to claim 1, It is characterized in that The method further comprises: Whenever a second transaction sent by the client is received, if the SQL statement carried by the second transaction is used to read the second data in the blockchain ledger, determining whether the second data is locked by the target transaction; If the second data has been locked by the target transaction, read the data value whose version number is the lock version number in the version record of the second data; If the second data is not locked by the target transaction, then under the repeatable read isolation level, read the data value with the largest version number among the data values ​​in the version record of the second data whose version number is less than the start version number of the target transaction, where the start version number of the target transaction is assigned when the target transaction is created; under the read committed isolation level, read the data value with the largest version number among the data values ​​in the version record of the second data except those whose version number is the lock version number.

5. The method according to claim 1, It is characterized in that The method further comprises: If a fourth transaction carrying a rollback statement is received from the client, all version records in the blockchain account book whose version number is the lock version number and whose transaction identifier is the identifier of the target transaction are deleted to roll back the modified data of multiple SQL statements executed by the target transaction.

6. The method according to any one of claims 1 to 5, It is characterized in that The method further comprises: After adding a preset number of blocks to the blockchain, clearing the historical version records in the blockchain ledger; or, When each transaction is submitted, the historical version records in the blockchain ledger are cleared; or, When each transaction reads data in the blockchain ledger, the historical version records in the blockchain ledger are cleared.

7. The method according to claim 6, It is characterized in that The clearing of historical version records in the blockchain ledger includes: The smallest start version number among the start version numbers of the currently alive transactions is used as the target version number, where the start version number of the transaction is assigned when the transaction is created; For each data in the blockchain ledger, taking a version record having a version number smaller than the target version number in the version record of the data as the target version record of the data; Delete other historical version records except the version record with the largest version number in the target version record of the data.

8. A transaction execution device, It is characterized in that Applied to a blockchain system, the device comprises: A creation module, configured to create a target transaction after receiving a first transaction carrying a start transaction statement sent by a client; A receiving module, configured to receive a plurality of second transactions sent by the client, each of the plurality of second transactions carrying a structured query language SQL statement for operating a blockchain ledger that needs to be executed by the target transaction, the data in the blockchain ledger having one or more version records, the version record including a data value, a transaction identifier and a version number, the transaction identifier being an identifier of a transaction that generates the version record, the version number in the version record being a lock version number or a commit version number of a transaction identified by the transaction identifier, the commit version number of the transaction being a logical time when the transaction is committed, and the lock version number being a maximum value that the version number can obtain; a modification module, configured to, upon receiving a second transaction sent by the client, if the SQL statement carried by the second transaction is used to modify the first data in the blockchain account book, then, if the version number in the version record with the largest version number of the first data is not the lock version number, add a version record with the version number being the lock version number and the transaction identifier being the identifier of the target transaction in the blockchain account book for the first data, so that the target transaction locks the first data, or, if the version number in the version record with the largest version number of the first data is the lock version number and the transaction identifier is the identifier of the target transaction, determine that the first data has been locked by the target transaction; and modify the data value with the version number being the lock version number in the version record of the first data according to the SQL statement carried by the second transaction; The commit module is configured to unlock all data locked by the target transaction in the blockchain ledger if a third transaction carrying a commit statement is received from the client, so as to commit the modified data of the multiple SQL statements executed by the target transaction.

9. A computer device, It is characterized in that The computer device comprises a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program implements the method according to any one of claims 1 to 7 when executed by the processor.

10. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method according to any one of claims 1 to 7 is implemented.

Citation Information

Patent Citations

  • Operation processing method and device

    CN105573828A