WO2023124242A1 - 事务执行方法、装置、设备和存储介质 - Google Patents

事务执行方法、装置、设备和存储介质 Download PDF

Info

Publication number
WO2023124242A1
WO2023124242A1 PCT/CN2022/118805 CN2022118805W WO2023124242A1 WO 2023124242 A1 WO2023124242 A1 WO 2023124242A1 CN 2022118805 W CN2022118805 W CN 2022118805W WO 2023124242 A1 WO2023124242 A1 WO 2023124242A1
Authority
WO
WIPO (PCT)
Prior art keywords
transaction
data
version
version number
target
Prior art date
Application number
PCT/CN2022/118805
Other languages
English (en)
French (fr)
Inventor
张珂杰
尚璇
陶烨琪
邱炜伟
李伟
Original Assignee
杭州趣链科技有限公司
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by 杭州趣链科技有限公司 filed Critical 杭州趣链科技有限公司
Publication of WO2023124242A1 publication Critical patent/WO2023124242A1/zh

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/242Query formulation
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2458Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries

Definitions

  • the present application relates to the technical field of blockchain, and in particular to a transaction execution method, device, device and storage medium.
  • the client can send transactions carrying SQL (Structured Query Language, Structured Query Language) statements to the blockchain system.
  • SQL Structured Query Language
  • the blockchain system After the blockchain system receives the transaction sent by the client, by executing the transaction, the SQL statement carried by the transaction can be executed, and then the blockchain account book can be operated according to the execution result of the SQL statement.
  • the execution of the SQL statement in the blockchain system is realized by carrying the SQL statement in the transaction.
  • the traditional RDBMS Relational Database Management System, relational database management system
  • the execution of SQL statements in the blockchain system lacks the characteristics of transactions. Because a transaction in the blockchain system 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 commit or rollback, so the current The blockchain system does not support the transactions formed by multiple SQL statements in the traditional RDBMS, so the business use will be relatively limited.
  • the present application provides a transaction execution method, device, device and storage medium, which can enable the blockchain system to support transactions.
  • a transaction execution method which is applied to a blockchain system, and the method includes:
  • each of the plurality of second transactions carries an SQL statement for operating a blockchain ledger that needs to be executed by the target transaction;
  • the method also includes:
  • the SQL statement carried by the second transaction is parsed to obtain a parsing result, and the parsing result includes a key-value pair and an operation type;
  • the operation type is a modification type
  • search for the corresponding data in the block chain account book as the first data that needs to be modified in the SQL statement carried by the second transaction. data.
  • the data in the blockchain account book has one or more version records
  • the version records include data values, transaction identifiers and version numbers
  • the transaction identifiers are the identifiers of transactions that generate the version records
  • modifying the first data according to the SQL statement carried by the second transaction includes:
  • the version number in the version record with the largest version number of the first data is not the lock version number, then add a new version number for the first data in the block chain account book as the lock version number, transaction A version record identified as the identification of the target transaction, so that the target transaction locks the first data, and the lock version number is the maximum value that can be obtained by the version number; or, if the first data
  • the version number in the version record with the largest version number 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;
  • the unlocking of all data locked by the target transaction in the blockchain ledger includes:
  • the method also includes:
  • the second data is not locked by the target transaction, then under the repeatable read isolation level, read the data value whose version number in the version record of the second data is less than the start version number of the target transaction The data value with the largest version number, the start version number of the target transaction is assigned when the target transaction is created; under the read committed isolation level, read the version record of the second data except that the version number is the Lock the data value with the largest version number among the data values other than the version number.
  • the method also includes:
  • the method also includes:
  • the cleaning of historical version records in the blockchain ledger includes:
  • the start version number of the transaction is allocated when the transaction is created;
  • the version record whose version number is smaller than the target version number in the version record of the one data is used as the target version record of the one data;
  • a transaction execution device which is applied to a blockchain system, and the device includes:
  • the creation module is used to create the target transaction after receiving the first transaction carrying the start transaction statement sent by the client;
  • a receiving module configured to receive a plurality of second transactions sent by the client, each of the plurality of second transactions carries information for operating the blockchain ledger that needs to be executed by the target transaction SQL statement;
  • the modification module is configured to receive 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 ledger, then in the target When the transaction locks the first data, modify the first data according to the SQL statement carried by the second transaction;
  • a commit module configured to unlock all data locked by the target transaction in the block chain account book if a third transaction carrying a commit statement sent by the client is received, so as to unlock the target transaction
  • the modified data of multiple SQL statements executed by the transaction is committed.
  • a computer device in a third aspect, includes a memory, a processor, and a computer program stored in the memory and operable on the processor, the computer program being executed by the processor When implementing the above-mentioned transaction execution method.
  • a computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the above transaction execution method is implemented.
  • a computer program product containing instructions is provided, and when it is run on a computer, it causes the computer to execute the steps of the above-mentioned transaction execution method.
  • the client after the client sends to the blockchain system the first transaction with the start transaction statement indicating that the blockchain system creates the target transaction, the client can continuously send multiple first transactions with the SQL statement to the blockchain system. Two transactions to instruct the blockchain system to execute multiple SQL statements as one 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 For the first data in the blockchain ledger, when the target transaction locks the first data, the first data is modified according to the SQL statement carried by the second transaction. Afterwards, the client can send a third transaction with a commit statement to the blockchain system.
  • the blockchain system After the blockchain system receives the third transaction, it can unlock all the data locked by the target transaction in the blockchain ledger, so as to Commit the modified data of multiple SQL statements executed by the target transaction.
  • the support for transactions is realized in the blockchain system, that is, multiple SQL statements sent by the client are executed in the blockchain system as one transaction, thereby improving the efficiency of executing SQL statements in the blockchain system. Flexibility and accuracy, resulting in increased business applicability.
  • Fig. 1 is a schematic structural diagram of a block chain system provided by the embodiment of the present application.
  • Fig. 2 is a schematic diagram of a block chain provided by the embodiment of the present application.
  • Fig. 3 is a schematic diagram of a transaction execution system provided by an embodiment of the present application.
  • FIG. 4 is a flow chart of a transaction execution method provided by an embodiment of the present application.
  • Fig. 5 is a schematic diagram of an execution process of a non-persistent transaction provided by an embodiment of the present application
  • Fig. 6 is a schematic diagram of an execution process of a persistent transaction provided by the embodiment of the present application.
  • FIG. 7 is a schematic structural diagram of a transaction execution device provided by an embodiment of the present application.
  • Fig. 8 is a schematic structural diagram of a computer device provided by an embodiment of the present application.
  • Fig. 1 is a schematic structural diagram of a blockchain system provided by an embodiment of the present application.
  • a 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 during normal work, and maintain shared data in the blockchain system 100 based on the received input information.
  • there may be an information connection between each node 101 in the blockchain system 100 and information transmission may be performed between the nodes 101 through the information connection.
  • any node 101 in the blockchain system 100 receives input information
  • other nodes 101 in the blockchain system 100 will 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.
  • Each node 101 in the blockchain system 100 stores the same blockchain.
  • the following uses Figure 2 as an example to illustrate a possible structure of the blockchain.
  • the structure of the blockchain can also be different according to different scenarios, which is not limited by the embodiment of this application .
  • the blockchain consists of multiple blocks, and the genesis block includes a block header and a block body.
  • the input information feature value, version number, timestamp and difficulty value are stored in the block header, and the input information is stored in the block body; the next block of the genesis block takes the genesis block as the parent block, and the next The block also includes the block header and the block body.
  • the block header stores the input information feature value of the current block, the block header feature value of the parent block, the version number, the timestamp and the difficulty value, 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, which ensures the security of the input information in the block.
  • the blockchain system 100 has computer technologies such as distributed data storage, point-to-point transmission, consensus mechanism, and encryption algorithm.
  • the blockchain system 100 is a distributed shared account book and database, which has the characteristics of decentralization, non-tampering, traceability throughout the process, traceability, collective maintenance, and openness and transparency. These characteristics ensure the shared openness, authenticity, integrity, safety and reliability of the blockchain.
  • 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 constitute a logical whole are either all executed successfully, or none of them are executed. That is to say, all operations that constitute a transaction either all affect the database, or none of them affect it, so that regardless of whether the transaction is executed successfully, the database can always maintain a consistent state.
  • Transactions have ACID characteristics, which are: Atomicity: All operations in a transaction are inseparable as a whole like an atom, and either all succeed or all fail. Consistency: The execution result of the transaction must make the database go from one consistent state to another consistent state. Isolation: Concurrently executing transactions do not affect each other and have the same impact on the database as they do serially. Durability: Once a transaction is committed, its updates to the database are persistent.
  • Read committed able to read committed data, that is, if a transaction reads data, other transactions are allowed to access this data (including read and write operations); if a transaction writes data, other transactions are prohibited access this data.
  • Repeatable read Within a transaction, the same data is read multiple times, and other transactions cannot access this data while the transaction is not over.
  • Serialization SERIALIZABLE: Provides strict transaction isolation and requires serialized execution of transactions, that is, transactions can only be executed one after another, and cannot be executed concurrently.
  • Fig. 3 is a schematic diagram of a transaction execution system provided by an embodiment of the present application.
  • the transaction execution system includes: a client 301 and a blockchain system 302 .
  • the client 301 can be installed on a terminal or on a server.
  • the server corresponding to the client 301 is installed in the blockchain system 302 .
  • the blockchain system 302 may be the blockchain system 100 shown in the embodiments of Figs. 1-2 above.
  • the client 301 and the blockchain system 302 can communicate through a wired connection or a wireless connection.
  • the client 301 is used to generate an SQL statement, and carry the SQL statement in the transaction and send it to the blockchain system 302.
  • the SQL statement is used to realize the operation of the blockchain ledger, that is, to control the Data is read or modified (including insert, update, delete).
  • the blockchain system 302 After the blockchain system 302 receives the transaction sent by the client 301, it can execute the transaction to execute the SQL statement carried by the transaction, so as to realize the operation of the blockchain ledger. That is, in this embodiment of the application, the client 301 can directly operate the blockchain ledger in the blockchain system 302 through SQL statements.
  • the client 301 and the blockchain system 302 can use the transaction execution method provided in the embodiment of Figure 4 below to realize that the blockchain system 302 executes multiple SQL statements sent by the client 301 as one transaction, thereby improving
  • the blockchain system 302 has the flexibility and accuracy of executing SQL statements, thereby improving business applicability.
  • Fig. 4 is a flowchart of a transaction execution method provided by an embodiment of the present application. Referring to Fig. 4, the method includes the following steps.
  • Step 401 the client sends a first transaction carrying a transaction start statement to the blockchain system.
  • the transaction body of the first transaction may contain a start transaction statement.
  • the start transaction statement (start transaction statement) is used to instruct the blockchain system to start a transaction to execute multiple SQL statements sent by the client as a transaction, that is, to submit or return the execution results of the multiple SQL statements at the same time. roll.
  • Step 402 After receiving the first transaction sent by the client, the blockchain system creates a target transaction.
  • target transaction commit refers to submitting execution results of multiple SQL statements in the target transaction at the same time
  • target transaction rollback refers to simultaneously rolling back the execution results of multiple SQL statements in the target transaction.
  • the operation of the blockchain system to create a target transaction is similar to the operation of a device in the related art to create a certain transaction, which is not described in detail in the embodiment of this application.
  • the blockchain system After the blockchain system creates the target transaction, it can set an identifier for the target transaction, and can assign a start version number to the target transaction.
  • the identifier of the target transaction may be the same as the start version number of the target transaction.
  • a transaction ID is used to uniquely identify this transaction.
  • the identification of each transaction can be incremental, that is, the identification of the transaction created earlier can be smaller than the identification of the transaction created later.
  • the start version number of a transaction may be the logical time when the transaction was created.
  • the blockchain system can have a logical clock, and the blockchain system can use the monotonically increasing logical clock saved globally to determine the logical time when each transaction is created, and use the logical time when each transaction is created as the start version of each transaction Number.
  • This logical time can be a uint64 (unsigned 64-bit integer).
  • Step 403 the client sends multiple second transactions to the blockchain system.
  • the plurality of second transactions sent by the client to the blockchain system are transactions for operating blockchain ledgers in the blockchain system.
  • Each second transaction in the plurality of second transactions carries an SQL statement.
  • the SQL statement carried by each second transaction in the plurality of second transactions is the SQL statement to be executed by the target transaction newly created by the blockchain system.
  • the SQL statement carried in the second transaction is used to operate the blockchain ledger.
  • the SQL statement can be a DML (Data Manipulation Language, Data Manipulation Language) statement.
  • the SQL statement can be used to read (SELECT) or modify (including insert (INSERT) data in the blockchain ledger. ), update (UPDATE), delete (DELETE).
  • 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-406 .
  • Step 404 Each time the blockchain system receives a second transaction sent by the client, it determines whether the second transaction needs to be modified or read data in the blockchain ledger.
  • every time the blockchain system receives a second transaction sent by the client it can analyze the SQL statement carried by the second transaction to obtain the analysis result; if the operation type in the analysis result is the modification type, then determine This second transaction is to modify the data in the blockchain ledger, and the corresponding data can be searched in the blockchain ledger according to the key value in the key-value pair in the analysis result as the SQL statement carried by the second transaction needs to be modified the first data; if the operation type in the analysis result is the read type, it is determined that the second transaction is to read the data in the blockchain ledger, and the key value in the key-value pair in the analysis result can be determined Find the corresponding data in the blockchain ledger as the second data to be read by the SQL statement carried by the second transaction.
  • the parsed result includes key-value pairs and operation types.
  • the key-value pair includes a key value and a value value.
  • the key value is the keyword (such as the primary key) of the data to be operated, and the data to be operated can be found from the blockchain ledger 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 an operation to be performed on the data, and may include a read type and a modification type (including an insert type, an update type, and a delete type).
  • the blockchain system analyzes the SQL statement carried by the second transaction, that is, converts the expression of SQL statement for structured data into the expression of kv type data, so that the analysis including key-value pairs and operation types can be obtained result.
  • the kv type data is the data format that the blockchain ledger can store.
  • the operation of the block chain system to analyze the SQL statement carried by the second transaction can be implemented by calling the SQL smart contract.
  • the operation of the blockchain system to parse the SQL statement carried by the second transaction can refer to the operation of parsing the SQL statement by a certain device in the related art, which will not be elaborated in this embodiment of the present application.
  • Data in the blockchain ledger can have one or more version records.
  • this version record includes data value, transaction identifier and version number.
  • the data value is the real value of this data (for example, it can be rowValue).
  • Identified as the identification of the transaction that generated this version record, and the version number is used to indicate the version of this version record.
  • the version number can be implemented by means of MVCC (Multiversion Concurrency Control, multiversion concurrency control) mechanism.
  • MVCC Multiversion Concurrency Control, multiversion concurrency control
  • 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 other version records are the historical versions of the data.
  • the data in the blockchain ledger can be kv type data.
  • a piece of data in the blockchain ledger can be shown in Table 1 below, each row in the second row to the third row in Table 1 is a version record of this data, that is, this data has three version records.
  • key value value value key3 Data value 3 Data value 3, transaction ID 3, version number 3 key2 Data value 2, transaction ID 2, version number 2 key1 Data value 1, transaction ID 1, version number 1
  • the embodiment of the present application only uses the above Table 1 as an example to illustrate the version records of the data in the blockchain ledger, and the above Table 1 does not limit the embodiment of the present application.
  • the lock version number is introduced.
  • the lock version number is the maximum value that the version number can achieve.
  • the lock version number can be the maximum value in uint64.
  • the version number in the version record with the largest version number of the data is the lock version number, it means that the data has been locked and is locked in the version record with the largest version number. Locked by the transaction identified by the transaction ID. After the data is locked by the transaction, only the transaction can modify the data, and other transactions cannot modify the data. That is, the embodiment of the present application adopts a pessimistic locking mechanism.
  • the value value in the version record of this data is structured data, and includes data value, transaction identifier and version number.
  • the value value in the version record may also include a specified data type (ie, lock).
  • the value value in other version records can also include the commit version number of the transaction identified by the transaction identifier, the data when the transaction is committed type (i.e. write (insert or update), or delete), etc.
  • the commit version number of a transaction can be the logical time when the transaction was committed.
  • the blockchain system can have a logical clock, and the blockchain system can use the monotonically increasing logical clock saved globally to determine the logical time when each transaction is submitted, and use the logical time when each transaction is submitted as the submitted version of each transaction Number.
  • This logical time can be a uint64.
  • a transaction deletes a certain data in the blockchain ledger
  • the data may not be deleted from the blockchain ledger first, but its data type may be marked as delete. In this way, if there are other transactions to read this data, if the data type of this data is found to be deleted, it is determined that this data has been deleted, and a null value is returned.
  • the blockchain system continues to perform the following step 405 . If the second transaction is to read data in the blockchain ledger, the blockchain system continues to perform the following step 406 .
  • Step 405 If the SQL statement carried by the second transaction is used to modify the first data in the blockchain account book, then the blockchain system will lock the first data according to the second transaction carried by the second transaction. The SQL statement modifies the first data.
  • 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, there will be a lock conflict. At this time, the second transaction cannot modify the first data, the execution of the second transaction fails, and the target transaction is rolled back; lock, the second transaction can modify the first data, the second transaction can be executed normally, and the target transaction continues to execute normally.
  • 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 has not been locked by any transaction.
  • the target transaction needs to lock the first data.
  • a new version record with the version number of the lock version number and the transaction ID of the target transaction is added for the first data in the blockchain account book, so that the target transaction Lock the first data.
  • the target key-value pair can be written into the blockchain ledger to realize the locking of the first data by the target transaction.
  • the key value in the target key-value pair includes the key value in the key-value pair (such as rowKey) and the lock version number in the parsing result of the SQL statement carried by the second transaction, and the value value in the target key-value pair is the data value in the version record of the current latest version of the first data.
  • 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.
  • the transaction identifier is a version record of the identifier of the target transaction, so as to realize the locking of the first data by the target transaction.
  • Table 1 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 in Table 1 to obtain the following Table 2. As shown in Table 2, the data value in the newly added version record is the same as the data value in the previous version record, and the version number in the newly added version record is the lock version number. The transaction identifier in the version record is the identifier of the target transaction. In this way, the locking of the first data by the target transaction is realized.
  • key value value value key4 Data value 3, target transaction ID, lock version number key3 Data value 3, transaction ID 3, version number 3 key2 Data value 2, transaction ID 2, version number 2 key1 Data value 1, transaction ID 1, version number 1
  • the embodiment of the present application only uses the above Table 2 as an example to illustrate the version record of the first data, and the above Table 2 does not limit the embodiment of the present application.
  • the blockchain system can modify the data value whose version number is the lock version number in the version record of the first data according to the SQL statement carried by the second transaction.
  • the operation type in the analysis result of the SQL statement carried by the second transaction and the value in the key-value pair modify the data value whose version number is the lock version number in the version record of the first data.
  • the data value in the version record locked by the target transaction in the first data is modified.
  • a new version number is the lock version number
  • the transaction ID is the target transaction ID.
  • Other version records in the first data except the newly added version record locked by the target transaction are generated by the committed historical transaction. In this way, before the target transaction commits, the modification of the first data by the target transaction will not affect the previously committed data value of the first data.
  • the target transaction modifies the data in the blockchain ledger
  • the identifier of the target transaction can be stored corresponding to the key value of the data modified by the target transaction.
  • the target transaction can be stored with the identifier of the target transaction as a prefix.
  • the key value of the modified data can be stored in memory for easy iteration, and the target transaction can be committed or rolled back accordingly.
  • 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.
  • the blockchain system can read the data value in the version record of the second data according to the operation type in the analysis result of the SQL statement carried by the second transaction and the value in the key-value pair.
  • the specific reading process can include the following Step (1) - Step (3):
  • the blockchain system first determines whether the second data is locked by 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 is not locked by the target transaction.
  • the blockchain system 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.
  • the data value whose version number is the lock version number in the version record of the second data is the data value modified by the target transaction, so the data value can be directly read at this time.
  • the blockchain system reads the version number in the version record of the second data that is smaller than the start version number of the target transaction.
  • the data value with the largest number under the read-committed isolation level, the blockchain system reads the data value with the largest version number among the data values except that the version number is the lock version number in the version record of the second data.
  • the blockchain system can also return the read second data to the client.
  • the client sends multiple second transactions to the blockchain system, and each time the blockchain system receives a second transaction, it can execute the second transaction according to the above steps 404-406, that is, execute The SQL statement carried by the second transaction operates the blockchain ledger until the blockchain system receives and executes the last second transaction sent by the client.
  • the client can instruct the blockchain system to commit or roll back the target transaction. If the client wants to instruct to commit the target transaction, it can proceed to the following steps 407-408. If the client wants to instruct to roll back the target transaction, the following steps 409 - 410 may be performed.
  • Step 407 The client sends a third transaction carrying a commit statement to the blockchain system.
  • a commit statement (commit statement) is used to indicate that a target transaction is committed.
  • the client sends a start transaction statement to the blockchain system to instruct the blockchain system to create a target transaction, and then sends multiple SQL statements to the blockchain system.
  • the blockchain system uses the multiple SQL statements as the created target transaction SQL statements, execute the multiple SQL statements.
  • 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 multiple SQL statements in the target transaction.
  • Step 408 After receiving the third transaction sent by the client, the blockchain system unlocks all the data locked by the target transaction in the blockchain account book, so as to submit the modified data of multiple SQL statements executed by the target transaction .
  • the blockchain system After the blockchain system receives the third transaction sent by the client, if it determines that the target transaction needs to be submitted, it can assign a submission version number to the target transaction, and then use the version number in the blockchain ledger as the lock version number, and the transaction ID The version numbers in all version records identified by 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.
  • the version record in the blockchain ledger whose version number is the lock version number and whose transaction ID is the ID of the target transaction is a version record that is locked by the target transaction, that is, the data value is modified when the target transaction is executed. 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, and then the unlocking can be realized. At this time, the version record is updated to the blockchain ledger, and other The transaction is visible, thereby realizing the submission of modified data of multiple SQL statements executed by the target transaction.
  • the blockchain system receives the first transaction sent by the client. 3.
  • the key value of the modified data can be obtained according to the identification of the target transaction, and then the version number of the data corresponding to the key value in the blockchain account book is the lock version number, and the transaction identification is the target transaction.
  • the version number in the identified version record is changed to the commit version number of the target transaction, so as to commit the modified data of the target transaction, which can improve the commit efficiency of the target transaction.
  • Step 409 the client sends the fourth transaction carrying a rollback statement to the blockchain system.
  • a rollback statement (rollback statement) is used to indicate that the target transaction is rolled back.
  • the client sends a start transaction statement to the blockchain system to instruct the blockchain system to create a target transaction, and then sends multiple SQL statements to the blockchain system.
  • the blockchain system uses the multiple SQL statements as the created target transaction SQL statements, execute the multiple SQL statements.
  • 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 multiple SQL statements in the target transaction.
  • 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.
  • the blockchain system After the blockchain system receives the fourth transaction sent by the client, if it is determined that the target transaction needs to be rolled back, it will record all versions in the blockchain ledger whose version number is the lock version number and whose transaction ID is the ID of the target transaction. A delete is performed to roll back modified data for multiple SQL statements executed by the target transaction.
  • the version record in the blockchain ledger whose version number is the lock version number and whose transaction ID is the ID of the target transaction is a version record that is locked by the target transaction, that is, the data value is modified when the target transaction is executed. Therefore, when the target transaction is rolled back, only the version record needs to be deleted, and the modified data of multiple SQL statements executed by the target transaction can be rolled back.
  • the blockchain system receives the first transaction sent by the client. 4.
  • the key value of the modified data can be obtained according to the identification of the target transaction, and then the version number of the data corresponding to the key value in the blockchain account book is the lock version number, and the transaction is identified as the target transaction.
  • the identified version record is deleted to roll back the modified data of the target transaction, which can improve the rollback efficiency of the target transaction.
  • the blockchain system can also periodically perform GC (Garbage Collection, garbage collection), that is, the historical version records in the blockchain ledger can be cleaned up to delete redundant useless version records to save storage resource.
  • GC Garbage Collection, garbage collection
  • the blockchain system can clear 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 every time a transaction is submitted record; or, when each transaction reads the data in the blockchain ledger, clean up the historical version records in the blockchain ledger.
  • the historical version record of this data can be the version record in the version record of this data except the locked version record and the version record generated by the latest submitted transaction.
  • the operation of the blockchain system to clean up the historical version records in the blockchain account book can be: use the smallest start version number among the start version numbers of the currently surviving transactions as the target version number; For each data, use the version record whose version number is smaller than the target version number in the version record of this data as the target version record of this data; delete other historical versions in the target version record of this data except the version record with the largest version number Record.
  • the current surviving transaction is the transaction that is being executed and has not yet been committed.
  • the blockchain system can record the start version numbers of the currently surviving transactions in real time, so that the smallest start version number among the start version numbers of the currently surviving transactions can be known.
  • the version records whose version numbers are smaller than the target version number are the version records generated by the committed transactions. That is, the target version record of this data is the version record generated by the transaction that has been committed, so the version record with the largest version number in the target version record of this data can be kept, and other historical version records can be deleted.
  • the transaction there are two situations in which the transaction is used, and whether to automatically commit the transaction is determined by starting the transaction statement. If the blockchain system does not receive the start transaction statement, it will automatically submit the transaction, that is, execute the non-persistent transaction. Specifically, each time a SQL statement is received, it will be submitted after execution. A SQL statement is executed as a transaction. If the blockchain system receives the start transaction statement, it does not automatically submit the transaction, that is, executes the continuous transaction. Specifically, it executes the received multiple SQL statements as one transaction, and submits or executes the execution results of multiple SQL statements at the same time. rollback.
  • FIG. 5 is a schematic diagram of an execution process of a non-persistent transaction provided by an embodiment of the present application. Referring to Figure 5, the execution process of non-persistent transactions is applied to the blockchain system, which may include the following steps (1)-step (5).
  • the GC process is triggered to clean up the historical version records in the blockchain ledger.
  • FIG. 6 is a schematic diagram of an execution process of a persistent transaction provided by an embodiment of the present application.
  • the execution process of the persistent transaction is applied to the blockchain system, and may include the following steps (1)-step (8).
  • the SQL statement is parsed to determine whether the SQL statement needs to read the data in the blockchain ledger or need to modify the data in the blockchain ledger. data.
  • the version numbers in all version records whose version number is the lock version number in the blockchain ledger and whose transaction identifier is the transaction identifier are all modified to The commit version number of the transaction to commit the modified data of multiple SQL statements executed by the transaction.
  • the GC process is triggered to clean up the historical version records in the blockchain ledger.
  • the client can continuously send multiple transactions carrying the SQL statement to the block chain system.
  • a second transaction to instruct the blockchain system to execute multiple SQL statements as one transaction.
  • 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.
  • the SQL statement carried by the second transaction is used to modify For the first data in the blockchain ledger, when the target transaction locks the first data, the first data is modified according to the SQL statement carried by the second transaction.
  • the client can send a third transaction with a commit statement to the blockchain system.
  • the blockchain system After the blockchain system receives the third transaction, it can unlock all the data locked by the target transaction in the blockchain ledger, so as to Commit the modified data of multiple SQL statements executed by the target transaction.
  • the support for transactions is realized in the blockchain system, that is, multiple SQL statements sent by the client are executed in the blockchain system as one transaction, thereby improving the efficiency of executing SQL statements in the blockchain system. Flexibility and accuracy, resulting in increased business applicability.
  • FIG. 7 is a schematic structural diagram of a transaction execution device provided by an embodiment of the present application.
  • the device can be implemented by software, hardware or a combination of the two to become part or all of computer equipment, the computer equipment can be the computer equipment shown in Figure 8 below, and the computer equipment can be a block chain system.
  • the device includes: a creating module 701 , a receiving module 702 , a modifying module 703 , and a submitting module 704 .
  • the creating module 701 is configured to create a target transaction after receiving the first transaction that carries the start transaction statement sent by the client;
  • the receiving module 702 is configured to receive a plurality of second transactions sent by the client, each of the plurality of second transactions carries an SQL statement for operating the blockchain ledger that needs to be executed by the target transaction;
  • the modification module 703 is configured to receive 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 ledger, then lock the first data in the target transaction In the case of , modify the first data according to the SQL statement carried by a second transaction;
  • the submission module 704 is used to unlock all the data locked by the target transaction in the block chain account book if the third transaction carrying the submission statement sent by the client is received, so as to execute multiple SQL statements for the target transaction
  • the modified data is submitted.
  • the device also includes:
  • the parsing module is used to parse the SQL statement carried by the second transaction every time a second transaction sent by the client is received, and obtain the parsing result, the parsing result includes key-value pairs and operation types;
  • the search module is used to search for the corresponding data in the blockchain ledger according to the key value in the key-value pair if the operation type is a modification type, as the first data to be modified in the SQL statement carried by the second transaction.
  • the data in the blockchain account book has one or more version records
  • the version records include data values, transaction identifiers and version numbers
  • the transaction identifier is the identifier of the transaction that generates the version records
  • the modification module 703 is used for:
  • the version number in the version record with the largest version number of the first data is not the lock version number
  • the submission module 704 is used to:
  • the device also includes:
  • the judging module is used for every time 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 block chain account book, then judge whether the second data is added by the target transaction Lock;
  • the first reading module is used to read the data value whose version number is the lock version number in the version record of the second data if the second data has been locked by the target transaction;
  • the second reading module is used to read the data value whose version number in the version record of the second data is less than the start version number of the target transaction under the repeatable read isolation level if the second data is not locked by the target transaction
  • the data value with the largest version number, the start version number of the target transaction is allocated when the target transaction is created; under the read committed isolation level, read the data value in the version record of the second data except that the version number is the lock version number
  • the device also includes:
  • the rollback module is used to perform 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 if the fourth transaction carrying the rollback statement sent by the client is received. Delete to rollback the modified data of multiple SQL statements executed by the target transaction.
  • the device also includes:
  • 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, when each transaction is submitted, clean up the historical version records in the blockchain ledger; Or, when each transaction reads the data in the blockchain ledger, clean up the historical version records in the blockchain ledger.
  • the cleanup module is used to:
  • the version record whose version number is smaller than the target version number in the version record of a data is used as the target version record of a data;
  • the client can continuously send multiple transactions carrying the SQL statement to the block chain system.
  • a second transaction to instruct the blockchain system to execute multiple SQL statements as one transaction.
  • 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.
  • the SQL statement carried by the second transaction is used to modify For the first data in the blockchain ledger, when the target transaction locks the first data, the first data is modified according to the SQL statement carried by the second transaction.
  • the client can send a third transaction with a commit statement to the blockchain system.
  • the blockchain system After the blockchain system receives the third transaction, it can unlock all the data locked by the target transaction in the blockchain ledger, so as to Commit the modified data of multiple SQL statements executed by the target transaction.
  • the support for transactions is realized in the blockchain system, that is, multiple SQL statements sent by the client are executed in the blockchain system as one transaction, thereby improving the efficiency of executing SQL statements in the blockchain system. Flexibility and accuracy, resulting in increased business applicability.
  • the transaction execution device provided by the above embodiment only uses the division of the above-mentioned functional modules as an example for illustration during transaction execution.
  • the above-mentioned function allocation can be completed by different functional modules according to needs.
  • the internal structure of the device is divided into different functional modules to complete all or part of the functions described above.
  • the functional units and modules in the above-mentioned embodiments can be integrated into one processing unit, or each unit can exist separately physically, or two or more units can be integrated into one unit, and the above-mentioned integrated units can use hardware It can also be implemented in the form of software functional units.
  • 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.
  • FIG. 8 is a schematic structural diagram of a computer device provided by an embodiment of the present application.
  • the computer device 8 includes: a processor 80, a memory 81, and a computer program 82 stored in the memory 81 and operable on the processor 80.
  • the processor 80 executes the computer program 82, the above-mentioned embodiments are realized. Steps in a transaction execution method performed by the blockchain system.
  • the computer device 8 may be a server cluster including multiple servers, specifically, it may be a blockchain system.
  • FIG. 8 is only an example of computer equipment 8, and does not constitute a limitation to computer equipment 8. It may include more or less components than those shown in the figure, or combine certain components, or different components. , for example, may also include input and output devices, network access devices, and the like.
  • the processor 80 can be a central processing unit (Central Processing Unit, CPU), and the processor 80 can also be other general-purpose processors, a digital signal processor (Digital Signal Processor, DSP), an application specific integrated circuit (Application Specific Integrated Circuit, ASIC) , Off-the-shelf programmable gate array (Field-Programmable Gate Array, 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.
  • the memory 81 may be an internal storage unit of the computer device 8 in some embodiments, such as a hard disk or a memory of the computer device 8 .
  • Memory 81 also can be the external storage device of computer equipment 8 in other embodiments, such as plug-in hard disk equipped on computer equipment 8, smart memory card (Smart Media Card, SMC), secure digital (Secure Digital, SD) Card, Flash Card, etc.
  • the memory 81 may also include both an internal storage unit of the computer device 8 and an external storage device.
  • the memory 81 is used for storing operating system, application program, boot loader (Boot Loader), data and other programs, etc.
  • the memory 81 can also be used to temporarily store data that has been output or will be output.
  • the embodiment of the present application also provides a computer device, the computer device includes: at least one processor, a memory, and a computer program stored in the memory and operable on the at least one processor, and the processor executes the computer program implement the steps in any of the above method embodiments.
  • the embodiment of the present application also provides a computer-readable storage medium, where a computer program is stored in the computer-readable storage medium, and when the computer program is executed by a processor, the steps in the foregoing method embodiments can be implemented.
  • the embodiments of the present application provide a computer program product, which, when running on a computer, causes the computer to execute the steps in the above method embodiments.
  • the integrated unit is realized in the form of a software function unit and sold or used as an independent product, it can be stored in a computer-readable storage medium.
  • the present application realizes all or part of the processes in the above method embodiments, which can be completed by instructing related hardware through a computer program, and the computer program can be stored in a computer-readable storage medium.
  • the computer program includes computer program code
  • the computer program code may be in the form of source code, object code, executable file or some intermediate form.
  • the computer-readable medium may at least include: any entity or device capable of carrying computer program codes to the photographing device/terminal device, recording medium, computer memory, ROM (Read-Only Memory, read-only memory), RAM (Random Access Memory , Random Access Memory), CD-ROM (Compact Disc Read-Only Memory, CD-ROM), magnetic tape, floppy disk and optical data storage devices, etc.
  • the computer-readable storage medium mentioned in this application may be a non-volatile storage medium, in other words, may be a non-transitory storage medium.
  • the disclosed apparatus/computer equipment and methods can be implemented in other ways.
  • the device/computer device embodiments described above are only illustrative, 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 May be combined or may be integrated into another system, or some features may be omitted, or not implemented.
  • the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be in electrical, mechanical or other forms.
  • a unit described as a separate component may or may not be physically separated, and a component displayed as a unit may or may not be a physical unit, that is, it may be located in one place, or may be distributed to multiple network units. Part or all of the units can be selected according to actual needs to achieve the purpose of the solution of this embodiment.

Abstract

本申请公开了一种事务执行方法、装置、设备和存储介质,属于区块链技术领域。应用于区块链系统,包括:接收携带有启动事务语句的第一交易后创建目标事务;每接收到一个第二交易,若该第二交易携带的SQL语句用于修改区块链账本中的第一数据,则在目标事务对第一数据加锁的情况下根据该SQL语句修改第一数据;若接收到携带有提交语句的第三交易,则对区块链账本中被目标事务加锁的所有数据进行解锁,以提交目标事务执行的多个SQL语句的修改数据。本申请中区块链系统实现了对事务的支持,即在区块链系统中可将客户端发送的多个SQL语句作为一个事务进行执行,提高了区块链系统执行SQL语句的灵活性和准确性,从而提高了业务适用性。

Description

事务执行方法、装置、设备和存储介质
本申请要求于2021年12月31日在中国专利局提交的、申请号为202111677879.X、申请名称为“事务执行方法、装置、设备和存储介质”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。
技术领域
本申请涉及区块链技术领域,特别涉及一种事务执行方法、装置、设备和存储介质。
背景技术
目前,客户端可以向区块链系统发送携带有SQL(Structured Query Language,结构化查询语言)语句的交易。区块链系统接收到客户端发送的交易后,通过执行该交易,可以实现对该交易携带的SQL语句的执行,然后根据SQL语句的执行结果对区块链账本进行操作。
上述过程中,通过将SQL语句携带于交易中,来实现SQL语句在区块链系统中的执行。但是相比于传统的RDBMS(Relational Database Management System,关系数据库管理系统),区块链系统中的SQL语句的执行缺少了事务的特性。因为目前在区块链系统中一条交易实际上就是一个事务,即一条SQL语句实际上就是一个事务,而传统的RDBMS可以将多条SQL语句的执行变为一个事务进行提交或回滚,所以目前区块链系统没有实现传统的RDBMS中对于多条SQL语句形成的事务的支持,从而在业务使用上会比较受限。
技术问题
本申请提供了一种事务执行方法、装置、设备和存储介质,可以使区块链系统实现对事务的支持。
技术解决方案
第一方面,提供了一种事务执行方法,应用于区块链系统,所述方法包括:
接收到客户端发送的携带有启动事务语句的第一交易后,创建目标事务;
接收所述客户端发送的多个第二交易,所述多个第二交易中的每个第二交易均携带有需所述目标事务执行的用于操作区块链账本的SQL语句;
每接收到所述客户端发送的一个第二交易,若所述一个第二交易携带的SQL语句用于修改所述区块链账本中的第一数据,则在所述目标事务对所述第一数据加锁的情况下,根据所述一个第二交易携带的SQL语句修改所述第一数据;
若接收到所述客户端发送的携带有提交语句的第三交易,则对所述区块链账本中被所述目标事务加锁的所有数据进行解锁,以对所述目标事务执行的多个SQL语句的修改数据进行提交。
可选地,所述方法还包括:
每接收到所述客户端发送的一个第二交易,对所述一个第二交易携带的SQL语句进行解析,得到解析结果,所述解析结果包括键值对和操作类型;
若所述操作类型为修改类型,则根据所述键值对中的key值在所述区块链账本中查找对应的数据作为所述一个第二交易携带的SQL语句需修改的所述第一数据。
可选地,所述区块链账本中的数据具有一条或多条版本记录,所述版本记录包括数据值、事务标识和版本号,所述事务标识为生成所述版本记录的事务的标识;
所述在所述目标事务对所述第一数据加锁的情况下,根据所述一个第二交易携带的SQL语句修改所述第一数据,包括:
若所述第一数据的版本号最大的版本记录中的版本号不是锁版本号,则在所述区块链账本中为所述第一数据新增一条版本号为所述锁版本号、事务标识为所述目标事务的标识的版本记录,以使所述目标事务对所述第一数据加锁,所述锁版本号是版本号所能取得的最大值;或者,若所述第一数据的版本号最大的版本记录中的版本号是所述锁版本号、且事务标识是所述目标事务的标识,则确定所述第一数据已被所述目标事务加锁;
根据所述一个第二交易携带的SQL语句对所述第一数据的版本记录中版本号为所述锁版本号的数据值进行修改。
可选地,所述对所述区块链账本中被所述目标事务加锁的所有数据进行解锁,包括:
为所述目标事务分配提交版本号;
将所述区块链账本中版本号为锁版本号、且事务标识为所述目标事务的标识的所有版本记录中的版本号均修改为所述目标事务的提交版本号,以对所述区块链账本中被所述目标事务加锁的所有数据进行解锁。
可选地,所述方法还包括:
每接收到所述客户端发送的一个第二交易,若所述一个第二交易携带的SQL语句用于读取所述区块链账本中的第二数据,则判断所述第二数据是否被所述目标事务加锁;
若所述第二数据已被所述目标事务加锁,则读取所述第二数据的版本记录中版本号为所述锁版本号的数据值;
若所述第二数据未被所述目标事务加锁,则在可重复读隔离级别下,读取所述第二数据的版本记录中版本号小于所述目标事务的开始版本号的数据值中版本号最大的数据值,所述目标事务的开始版本号是在创建所述目标事务时分配的;在读已提交隔离级别下,读取所述第二数据的版本记录中除版本号为所述锁版本号之外的数据值中版本号最大的数据值。
可选地,所述方法还包括:
若接收到所述客户端发送的携带有回滚语句的第四交易,则将所述区块链账本中版本号为所述锁版本号、且事务标识为所述目标事务的标识的所有版本记录进行删除,以对所述目标事务执行的多个SQL语句的修改数据进行回滚。
可选地,所述方法还包括:
在向区块链添加预设数量的区块后,清理所述区块链账本中的历史版本记录;或者,
在每次事务提交时,清理所述区块链账本中的历史版本记录;或者,
在每次事务读取所述区块链账本中的数据时,清理所述区块链账本中的历史版本记录。
可选地,所述清理所述区块链账本中的历史版本记录,包括:
将当前存活的事务的开始版本号中最小的开始版本号作为目标版本号,所述事务的开始版本号是在所述事务创建时分配的;
对于所述区块链账本中的每一个数据,将所述一个数据的版本记录中版本号小于所述目标版本号的版本记录作为所述一个数据的目标版本记录;
删除所述一个数据的目标版本记录中除版本号最大的版本记录之外的其他历史版本记录。
第二方面,提供了一种事务执行装置,应用于区块链系统,所述装置包括:
创建模块,用于接收到客户端发送的携带有启动事务语句的第一交易后,创建目标事务;
接收模块,用于接收所述客户端发送的多个第二交易,所述多个第二交易中的每个第二交易均携带有需所述目标事务执行的用于操作区块链账本的SQL语句;
修改模块,用于每接收到所述客户端发送的一个第二交易,若所述一个第二交易携带的SQL语句用于修改所述区块链账本中的第一数据,则在所述目标事务对所述第一数据加锁的情况下,根据所述一个第二交易携带的SQL语句修改所述第一数据;
提交模块,用于若接收到所述客户端发送的携带有提交语句的第三交易,则对所述区块链账本中被所述目标事务加锁的所有数据进行解锁,以对所述目标事务执行的多个SQL语句的修改数据进行提交。
第三方面,提供了一种计算机设备,所述计算机设备包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机程序,所述计算机程序被所述处理器执行时实现上述的事务执行方法。
第四方面,提供了一种计算机可读存储介质,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时实现上述的事务执行方法。
第五方面,提供了一种包含指令的计算机程序产品,当其在计算机上运行时,使得计算机执行上述的事务执行方法的步骤。
有益效果
在本申请中,客户端向区块链系统发送携带有启动事务语句的第一交易指示区块链系统创建目标事务后,客户端可以不断向区块链系统发送携带有SQL语句的多个第二交易,以指示区块链系统将多个SQL语句作为一个事务进行执行。区块链系统创建目标事务后,每接收到客户端发送的一个第二交易,就可以对这个第二交易携带的SQL语句进行执行,具体地,若这个第二交易携带的SQL语句用于修改区块链账本中的第一数据,则在目标事务对第一数据加锁的情况下,根据这个第二交易携带的SQL语句修改第一数据。之后,客户端可以向区块链系统发送携带有提交语句的第三交易,区块链系统接收到第三交易后,可以对区块链账本中被目标事务加锁的所有数据进行解锁,以对目标事务执行的多个SQL语句的修改数据进行提交。如此,在区块链系统中实现了对事务的支持,即实现了在区块链系统将客户端发送的多个SQL语句作为一个事务进行执行,以此提高了区块链系统执行SQL语句的灵活性和准确性,从而提高了业务适用性。
附图说明
为了更清楚地说明本申请实施例中的技术方案,下面将对实施例描述中所需要使用的附图作简单地介绍,显而易见地,下面描述中的附图仅仅是本申请的一些实施例,对于本领域普通技术人员来讲,在不付出创造性劳动的前提下,还可以根据这些附图获得其他的附图。
图1是本申请实施例提供的一种区块链系统的结构示意图;
图2是本申请实施例提供的一种区块链的示意图;
图3是本申请实施例提供的一种事务执行系统的示意图;
图4是本申请实施例提供的一种事务执行方法的流程图;
图5是本申请实施例提供的一种非持续性事务的执行过程的示意图;
图6是本申请实施例提供的一种持续性事务的执行过程的示意图;
图7是本申请实施例提供的一种事务执行装置的结构示意图;
图8是本申请实施例提供的一种计算机设备的结构示意图。
本发明的实施方式
为使本申请的目的、技术方案和优点更加清楚,下面将结合附图对本申请实施方式作进一步地详细描述。
应当理解的是,本申请提及的“多个”是指两个或两个以上。在本申请的描述中,除非另有说明,“/”表示或的意思,比如,A/B可以表示A或B;本文中的“和/或”仅仅是一种描述关联对象的关联关系,表示可以存在三种关系,比如,A和/或B,可以表示:单独存在A,同时存在A和B,单独存在B这三种情况。另外,为了便于清楚描述本申请的技术方案,采用了“第一”、“第二”等字样对功能和作用基本相同的相同项或相似项进行区分。本领域技术人员可以理解“第一”、“第二”等字样并不对数量和执行次序进行限定,并且“第一”、“第二”等字样也并不限定一定不同。
在对本申请实施例进行解释说明之前,先对区块链的相关内容予以说明。
图1是本申请实施例提供的一种区块链系统的结构示意图。
参见图1,区块链系统100是指用于进行节点与节点之间数据共享的系统,区块链系统100中可以包括多个节点101。每个节点101在进行正常工作时可以接收到输入信息,并基于接收到的输入信息维护区块链系统100内的共享数据。为了保证区块链系统100内的信息互通,区块链系统100中的每个节点101之间可以存在信息连接,节点101之间可以通过该信息连接进行信息传输。比如,当区块链系统100中的任意节点101接收到输入信息时,区块链系统100中的其他节点101便根据共识算法获取该输入信息,将该输入信息作为共享数据中的数据进行存储,使得区块链系统100中全部节点101上存储的数据一致。
区块链系统100中的每个节点101均存储一条相同的区块链。下面以图2为例来对区块链的一种可能的结构进行说明,当然,实际应用中,根据不同的场景,区块链的结构也可以有所不同,本申请实施例对此不作限定。
参见图2,区块链由多个区块组成,创始块中包括区块头和区块主体。作为一种示例,区块头中存储有输入信息特征值、版本号、时间戳和难度值,区块主体中存储有输入信息;创始块的下一区块以创始块为父区块,下一区块中同样包括区块头和区块主体,区块头中存储有当前区块的输入信息特征值、父区块的区块头特征值、版本号、时间戳和难度值,并以此类推,使得区块链中每个区块中存储的区块数据均与父区块中存储的区块数据存在关联,保证了区块中输入信息的安全性。
区块链系统100具有分布式数据存储、点对点传输、共识机制、加密算法等计算机技术。区块链系统100是一个分布式的共享账本和数据库,具有去中心化、不可篡改、全程留痕、可以追溯、集体维护、公开透明等特点。这些特点保证了区块链的共享开放、真实完整和安全可靠。
在对本申请实施例进行详细地解释说明之前,对本申请实施例涉及的事务的有关概念进行说明。
事务是构成单一逻辑工作单元的操作集合。事务可以包含一个或多个操作,这些操作构成一个逻辑上的整体。构成逻辑整体的这些操作,要么全部执行成功,要么全部不执行。也即,构成事务的所有操作,要么全都对数据库产生影响,要么全都不产生影响,从而不 管事务是否执行成功,数据库总能保持一致性状态。
事务具有ACID特征,分别为:原子性(Atomicity):事务中的所有操作作为一个整体像原子一样不可分割,要么全部成功,要么全部失败。一致性(Consistency):事务的执行结果必须使数据库从一个一致性状态到另一个一致性状态。隔离性(Isolation):并发执行的事务不会相互影响,其对数据库的影响和它们串行执行时一样。持久性(Durability):事务一旦提交,其对数据库的更新就是持久的。
事务之间具有隔离性,理论上来说事务之间的执行不应该相互产生影响,其对数据库的影响应该和它们串行执行时一样。然而完全隔离会导致系统并发性能很低,降低对资源的利用率,因而实际应用时对隔离性的要求会有所放宽,这也会在一定程度上造成对数据库的一致性要求的降低。SQL标准为事务定义了不同的隔离级别,从低到高依次是:读未提交(READ UNCOMMITTED):能够读取到没有提交的数据,即如果一个事务已经开始写数据,则另一个事务不允许同时进行写操作,但允许其他事务读取此数据。读已提交(READ COMMITTED):能够读取到已经提交的数据,即如果一个事务是读取数据,则允许其他事务访问此数据(包括读写操作);如果一个事务是写数据,禁止其他事务访问此数据。可重复读(REPEATABLE READ):在一个事务内,多次读同一个数据,在这个事务还没结束时,其他事务不能访问此数据。串行化(SERIALIZABLE):提供严格的事务隔离,要求事务序列化执行,即事务只能一个接着一个地执行,不能并发执行。
下面对本申请实施例涉及的系统架构予以说明。
图3是本申请实施例提供的一种事务执行系统的示意图。参见图3,该事务执行系统包括:客户端301和区块链系统302。
客户端301可以安装于终端,也可以安装于服务器。客户端301对应的服务端安装于区块链系统302。区块链系统302可以是上文图1-图2实施例所示的区块链系统100。客户端301与区块链系统302可以通过有线连接与无线连接进行通信。
客户端301用于生成SQL语句,并将该SQL语句携带于交易中发送给区块链系统302,该SQL语句用于实现对区块链账本的操作,即用于对区块链账本中的数据进行读取或修改(包括插入、更新、删除)。区块链系统302接收到客户端301发送的交易后,可以通过执行该交易,来执行该交易携带的SQL语句,以此实现对区块链账本的操作。也即,在本申请实施例中,客户端301可以直接通过SQL语句来操作区块链系统302中的区块链账本。
其中,客户端301和区块链系统302可以通过下文图4实施例提供的事务执行方法,来实现区块链系统302将客户端301发送的多个SQL语句作为一个事务进行执行,以此提高区块链系统302执行SQL语句的灵活性和准确性,从而提高业务适用性。
下面对本申请实施例提供的事务执行方法进行详细地解释说明。
图4是本申请实施例提供的一种事务执行方法的流程图。参见图4,该方法包括以下步骤。
步骤401:客户端向区块链系统发送携带有启动事务语句的第一交易。
第一交易的交易体内可以包含启动事务语句。启动事务语句(start transaction语句)用于指示区块链系统启动事务,以将客户端后续发送的多个SQL语句作为一个事务进行执行,即对该多个SQL语句的执行结果同时进行提交或回滚。
步骤402:区块链系统接收到客户端发送的第一交易后,创建目标事务。
区块链系统创建目标事务后,即可将客户端后续发送的多个SQL语句作为需目标事务执行的SQL语句。目标事务中的多个SQL语句的执行结果可以同时进行提交或回滚。也即,目标事务提交,是指同时提交目标事务中多个SQL语句的执行结果;目标事务回滚,是指同时回滚目标事务中多个SQL语句的执行结果。
区块链系统创建目标事务的操作与相关技术中某个设备创建某个事务的操作类似,本申请实施例对此不进行详细阐述。
区块链系统创建目标事务后,可以为目标事务设置标识,且可以为目标事务分配开始版本号。可选地,目标事务的标识可以与目标事务的开始版本号相同。
某个事务的标识用于唯一标识这个事务。可选地,在区块链系统中,各个事务的标识可以是递增的,即先创建的事务的标识可以小于后创建的事务的标识。
某个事务的开始版本号可以为创建这个事务时的逻辑时间。示例地,区块链系统可以具有逻辑时钟,区块链系统可以使用全局保存的单调递增的逻辑时钟来确定创建各个事务时的逻辑时间,将创建各个事务时的逻辑时间作为各个事务的开始版本号。该逻辑时间可以为uint64(无符号64位整数)。
步骤403:客户端向区块链系统发送多个第二交易。
客户端向区块链系统发送的多个第二交易是用于对区块链系统中的区块链账本进行操作的交易。该多个第二交易中的每个第二交易均携带SQL语句。该多个第二交易中的每个第二交易携带的SQL语句均是区块链系统新创建的目标事务需执行的SQL语句。
第二交易中携带的SQL语句用于对区块链账本进行操作。比如,该SQL语句可以是DML(Data Manipulation Language,数据操纵语言)语句,具体来讲,该SQL语句可以用于对区块链账本中的数据进行读取(SELECT)或修改(包括插入(INSERT)、更新(UPDATE)、删除(DELETE)。
客户端向区块链系统发送多个第二交易后,区块链系统可以接收该多个第二交易,且区块链系统每接收到一个第二交易,就可以执行如下步骤404-步骤406。
步骤404:区块链系统每接收到客户端发送的一个第二交易,判断这个第二交易是要修改还是要读取区块链账本中的数据。
具体地,区块链系统每接收到客户端发送的一个第二交易,可以对这个第二交易携带的SQL语句进行解析,得到解析结果;若该解析结果中的操作类型为修改类型,则确定这个第二交易是要修改区块链账本中的数据,可以根据该解析结果中的键值对中的key值在区块链账本中查找对应的数据作为这个第二交易携带的SQL语句需修改的第一数据;若该解析结果中的操作类型为读取类型,则确定这个第二交易是要读取区块链账本中的数据,可以根据该解析结果中的键值对中的key值在区块链账本中查找对应的数据作为这个第二交易携带的SQL语句需读取的第二数据。
该解析结果包括键值对和操作类型。该键值对包括key值和value值。key值为所要操作的数据的关键字(如主键),根据key值可以从区块链账本中查找所要操作的数据。value值为所要操作的数据的具体值。该操作类型用于指示对数据要进行的操作,可以包括读取类型和修改类型(包括插入类型、更新类型、删除类型)。
区块链系统对这个第二交易携带的SQL语句进行解析,即是将SQL语句对于结构化数据的表述转换为对kv类型数据的表述,如此就可以得到包含有键值对和操作类型的解析结果。kv类型数据是区块链账本所能存储的数据格式。区块链系统对这个第二交易携带的 SQL语句进行解析的操作可以调用SQL智能合约实现。
区块链系统对这个第二交易携带的SQL语句进行解析的操作可以参考相关技术中某个设备对SQL语句进行解析的操作,本申请实施例对此不进行详细阐述。
下面对区块链账本中的数据结构进行说明。
区块链账本中的数据可以具有一条或多条版本记录。对于区块链账本中的任意一个数据的任意一条版本记录来说,这条版本记录包括数据值、事务标识和版本号,该数据值为这个数据的真实值(如可以为rowValue),该事务标识为生成这条版本记录的事务的标识,该版本号用于指示这条版本记录的版本。可选地,该版本号可以借助于MVCC(Multiversion Concurrency Control,多版本并发控制)机制实现。
对于区块链账本中的任意一个数据来说,若这个数据仅具有一条版本记录,则这条版本记录是这个数据的最新版本。若这个数据具有多条版本记录,则版本号最大的版本记录是这个数据的最新版本,其他版本记录是这个数据的历史版本。
比如,区块链账本中的数据可以为kv类型数据。区块链账本中的一个数据可以如下表1所示,表1中的第二行至第三行中的每一行为这个数据的一条版本记录,即这个数据具有三条版本记录。
表1
key值 value值
key3 数据值3、事务标识3、版本号3
key2 数据值2、事务标识2、版本号2
key1 数据值1、事务标识1、版本号1
本申请实施例仅以上表1为例来对区块链账本中的数据的版本记录进行举例说明,上表1并不对本申请实施例构成限定。
值得注意的是,在本申请实施例中,引入锁版本号。锁版本号是版本号所能取得的最大值。比如,在版本号为uint64的情况下,锁版本号可以为uint64中的最大值。对于区块链账本中的任意一个数据,若这个数据的版本号最大的版本记录中的版本号是锁版本号,则说明这个数据已被加锁,且是被该版本号最大的版本记录中的事务标识所标识的事务加锁的。这个数据被该事务加锁后,只有该事务可以对这个数据进行修改,其他事务不能对这个数据进行修改。也即,本申请实施例采用悲观锁机制。
此外,对于区块链账本中的任意一个数据来说,这个数据的版本记录中的value值为结构化数据,且包括数据值、事务标识和版本号。可选地,对于这个数据的版本记录中版本号为锁版本号的版本记录,该版本记录中的value值还可以包括指定数据类型(即锁)等。对于这个数据的版本记录中除版本号为锁版本号的版本记录之外的其他版本记录,其他版本记录中的value值还可以包括事务标识所标识的事务的提交版本号、事务提交时的数据类型(即写入(插入或更新)、或删除)等。
某个事务的提交版本号可以为提交这个事务时的逻辑时间。示例地,区块链系统可以具有逻辑时钟,区块链系统可以使用全局保存的单调递增的逻辑时钟来确定提交各个事务时的逻辑时间,将提交各个事务时的逻辑时间作为各个事务的提交版本号。该逻辑时间可以为uint64。
需说明的是,在某个事务删除区块链账本中的某个数据的情况下,这个事务提交时,这个数据可以先不从区块链账本中删除,而是先将其数据类型标记为删除。如此,若存在 其他事务要读取这个数据,则在发现这个数据的数据类型为删除的情况下,确定这个数据已被删除,返回空值。
若这个第二交易是要修改区块链账本中的数据,则区块链系统继续执行如下步骤405。若这个第二交易是要读取区块链账本中的数据,则区块链系统继续执行如下步骤406。
步骤405:若这个第二交易携带的SQL语句用于修改区块链账本中的第一数据,则区块链系统在目标事务对第一数据加锁的情况下,根据这个第二交易携带的SQL语句修改第一数据。
若这个第二交易携带的SQL语句需修改区块链账本中的第一数据,则需要先确定第一数据是否被除目标事务之外的其他事务加锁。若第一数据已被其他事务加锁,则会出现锁冲突,此时这个第二交易无法修改第一数据,这个第二交易执行失败,目标事务回滚;若第一数据未被其他事务加锁,则这个第二交易可以修改第一数据,这个第二交易可以正常执行,此时目标事务继续正常执行。
这种情况下,若第一数据的版本号最大的版本记录中的版本号不是锁版本号,说明第一数据未被任何事务加锁,此时由于这个第二交易需要修改第一数据,所以目标事务需要对第一数据加锁。具体地,若第一数据未被任何事务加锁,则在区块链账本中为第一数据新增一条版本号为锁版本号、事务标识为目标事务的标识的版本记录,以使目标事务对第一数据加锁。可选地,可以向区块链账本中写入目标键值对,来实现目标事务对第一数据的加锁。其中,目标键值对中的key值包括这个第二交易携带的SQL语句的解析结果中的键值对中的key值(如可以为rowKey)和锁版本号,目标键值对中的value值为第一数据的当前最新版本的版本记录中的数据值。
或者,若第一数据的版本号最大的版本记录中的版本号是锁版本号、且事务标识是目标事务的标识,则确定第一数据已被目标事务加锁。这种情况下,是在执行这个第二交易之前,在执行首个需修改第一数据的第二交易时,在区块链账本中为第一数据新增了一条版本号为锁版本号、事务标识为目标事务的标识的版本记录,以实现目标事务对第一数据的加锁。
比如,假设第一数据的多条版本记录如表1所示,若第一数据未被任何事务加锁,则在表1中新增一条版本记录,得到下表2。如表2所示,新增的这条版本记录中的数据值与前一版本的版本记录中的数据值相同,新增的这条版本记录中的版本号为锁版本号,新增的这条版本记录中的事务标识为目标事务的标识。如此,就实现了目标事务对第一数据的加锁。
表2
key值 value值
key4 数据值3、目标事务的标识、锁版本号
key3 数据值3、事务标识3、版本号3
key2 数据值2、事务标识2、版本号2
key1 数据值1、事务标识1、版本号1
本申请实施例仅以上表2为例来对第一数据的版本记录进行举例说明,上表2并不对本申请实施例构成限定。
在第一数据被目标事务加锁的情况下,区块链系统可以根据这个第二交易携带的SQL 语句对第一数据的版本记录中版本号为锁版本号的数据值进行修改,具体可以根据这个第二交易携带的SQL语句的解析结果中的操作类型和键值对中的value值,对第一数据的版本记录中版本号为锁版本号的数据值进行修改,此时实际上就是对第一数据中由目标事务加锁的版本记录中的数据值进行修改。
值得注意的一点是,在本申请实施例中,若存在第二交易要对第一数据进行修改,则对于第一数据,会新增一个版本号为锁版本号、事务标识为目标事务的标识的版本记录以供目标事务进行修改。第一数据中除此新增的由目标事务加锁的版本记录之外的其他版本记录是已提交的历史事务生成的。如此,在目标事务提交之前,目标事务对第一数据的修改不会影响到此前针对第一数据已提交的数据值。
值得注意的另一点是,目标事务对区块链账本中的数据进行修改后,由于后续涉及到对目标事务的提交或回滚,所以需要知道目标事务在区块链账本中修改的数据的key值,如此才能进行修改数据的提交或回滚。因而需要将目标事务修改的数据的key值记录下来,这种情况下,可以将目标事务的标识与目标事务修改的数据的key值对应存储,如可以以目标事务的标识为前缀来存储目标事务修改的数据的key值,且可以存储至内存中,方便迭代,后续可以据此进行目标事务的提交或回滚。
步骤406:若这个第二交易携带的SQL语句用于读取区块链账本中的第二数据,则区块链系统根据这个第二交易携带的SQL语句读取第二数据。
区块链系统可以根据这个第二交易携带的SQL语句的解析结果中的操作类型和键值对中的value值,读取第二数据的版本记录中的数据值,具体读取过程可以包括如下步骤(1)-步骤(3):
(1)区块链系统先判断第二数据是否被目标事务加锁。
具体地,若第二数据的版本号最大的版本记录中的版本号是锁版本号、且事务标识是目标事务的标识,则区块链系统确定第二数据已被目标事务加锁;否则,区块链系统确定第二数据未被目标事务加锁。
(2)若第二数据已被目标事务加锁,则区块链系统读取第二数据的版本记录中版本号为锁版本号的数据值。
若第二数据已被目标事务加锁,则第二数据的版本记录中版本号为锁版本号的数据值是经目标事务修改后的数据值,因而此时可以直接读取该数据值。
(3)若第二数据未被目标事务加锁,则在可重复读隔离级别下,区块链系统读取第二数据的版本记录中版本号小于目标事务的开始版本号的数据值中版本号最大的数据值;在读已提交隔离级别下,区块链系统读取第二数据的版本记录中除版本号为锁版本号之外的数据值中版本号最大的数据值。
在可重复读隔离级别下,可以读取的是在创建目标事务之前最晚提交的事务生成的版本记录中的数据值,也即可以读取第二数据的版本记录中版本号小于目标事务的开始版本号的数据值中版本号最大的数据值。
在读已提交隔离级别下,可以读取的是当前最新提交的事务生成的版本记录中的数据值,也即可以读取第二数据的版本记录中除版本号为锁版本号之外的数据值中版本号最大的数据值。
进一步地,区块链系统读取到第二数据后,还可以将读取到的第二数据返回给客户端。
值得注意的是,客户端向区块链系统发送多个第二交易,区块链系统每接收到一个第 二交易,就可以按照上述步骤404-步骤406来执行这个第二交易,也即执行这个第二交易携带的SQL语句来操作区块链账本,直至区块链系统接收到客户端发送的最后一个第二交易并执行为止。
客户端向区块链系统发送多个第二交易后,可以指示区块链系统对目标事务进行提交或回滚。若客户端想指示对目标事务进行提交,则可以继续进行如下步骤407-步骤408。若客户端想指示对目标事务进行回滚,则可以执行如下步骤409-步骤410。
步骤407:客户端向区块链系统发送携带有提交语句的第三交易。
提交语句(commit语句)用于指示对目标事务进行提交。客户端向区块链系统发送启动事务语句指示区块链系统创建目标事务后,向区块链系统发送多个SQL语句,此时区块链系统将该多个SQL语句作为所创建的目标事务中的SQL语句,对该多个SQL语句进行执行。之后,客户端可以向区块链系统发送提交语句,以指示区块链系统对所创建的目标事务进行提交,也即对目标事务中的多个SQL语句的执行结果进行提交。
步骤408:区块链系统接收到客户端发送的第三交易后,对区块链账本中被目标事务加锁的所有数据进行解锁,以对目标事务执行的多个SQL语句的修改数据进行提交。
区块链系统接收到客户端发送的第三交易后,确定需要对目标事务进行提交,则可以为目标事务分配提交版本号,然后将区块链账本中版本号为锁版本号、且事务标识为目标事务的标识的所有版本记录中的版本号均修改为目标事务的提交版本号,以对区块链账本中被目标事务加锁的所有数据进行解锁。
区块链账本中版本号为锁版本号、且事务标识为目标事务的标识的版本记录,是被目标事务加锁的版本记录,也即是目标事务在执行时新增的进行了数据值修改的版本记录,因而在提交目标事务时,只需要将该版本记录中的版本号修改为目标事务的提交版本号,就可以实现解锁,此时该版本记录更新至区块链账本中,对其他事务可见,从而实现了对目标事务执行的多个SQL语句的修改数据的提交。
一种可能的方式中,由于之前在目标事务执行的时候,存储了目标事务的标识与目标事务在区块链系统中修改的数据的key值,所以区块链系统接收到客户端发送的第三交易后,可以先根据目标事务的标识获取所修改的数据的key值,然后再将区块链账本中与该key值对应的数据的版本号为锁版本号、且事务标识为目标事务的标识的版本记录中的版本号修改为目标事务的提交版本号,以对目标事务的修改数据进行提交,如此可以提高目标事务的提交效率。
步骤409:客户端向区块链系统发送携带有回滚语句的第四交易。
回滚语句(rollback语句)用于指示对目标事务进行回滚。客户端向区块链系统发送启动事务语句指示区块链系统创建目标事务后,向区块链系统发送多个SQL语句,此时区块链系统将该多个SQL语句作为所创建的目标事务中的SQL语句,对该多个SQL语句进行执行。之后,客户端可以向区块链系统发送回滚语句,以指示区块链系统对所创建的目标事务进行回滚,也即对目标事务中的多个SQL语句的执行结果进行回滚。
步骤410:区块链系统接收到客户端发送的第四交易后,对目标事务执行的多个SQL语句的修改数据进行回滚。
区块链系统接收到客户端发送的第四交易后,确定需要对目标事务进行回滚,则将区块链账本中版本号为锁版本号、且事务标识为目标事务的标识的所有版本记录进行删除,以对目标事务执行的多个SQL语句的修改数据进行回滚。
区块链账本中版本号为锁版本号、且事务标识为目标事务的标识的版本记录,是被目标事务加锁的版本记录,也即是目标事务在执行时新增的进行了数据值修改的版本记录,因而在回滚目标事务时,只需要将该版本记录删除,即可实现对目标事务执行的多个SQL语句的修改数据的回滚。
一种可能的方式中,由于之前在目标事务执行的时候,存储了目标事务的标识与目标事务在区块链系统中修改的数据的key值,所以区块链系统接收到客户端发送的第四交易后,可以先根据目标事务的标识获取所修改的数据的key值,然后再将区块链账本中与该key值对应的数据的版本号为锁版本号、且事务标识为目标事务的标识的版本记录进行删除,以对目标事务的修改数据进行回滚,如此可以提高目标事务的回滚效率。
在一些实施例中,区块链系统还可以定期进行GC(Garbage Collection,垃圾回收),即可以对区块链账本中的历史版本记录进行清理,以将冗余的无用版本记录删除,节省存储资源。
比如,区块链系统可以在向区块链添加预设数量的区块后,清理区块链账本中的历史版本记录;或者,在每次事务提交时,清理区块链账本中的历史版本记录;或者,在每次事务读取区块链账本中的数据时,清理区块链账本中的历史版本记录。
对于区块链账本中的任意一个数据来说,这个数据的历史版本记录可以是这个数据的版本记录中除了加锁的版本记录和最新提交的事务生成的版本记录之外的版本记录。这种情况下,区块链系统清理区块链账本中的历史版本记录的操作可以为:将当前存活的事务的开始版本号中最小的开始版本号作为目标版本号;对于区块链账本中的每一个数据,将这个数据的版本记录中版本号小于目标版本号的版本记录作为这个数据的目标版本记录;删除这个数据的目标版本记录中除版本号最大的版本记录之外的其他历史版本记录。
当前存活的事务即是正在执行、尚未提交的事务。区块链系统可以实时记录当前存活的事务的开始版本号,据此可以获知当前存活的事务的开始版本号中最小的开始版本号。
由于目标版本号是当前存活的事务的开始版本号中最小的开始版本号,所以版本号小于目标版本号的版本记录均是已提交的事务生成的版本记录。也即,这个数据的目标版本记录是已提交的事务生成的版本记录,因而可以保留这个数据的目标版本记录中版本号最大的版本记录,删除其他历史版本记录。
值得注意的是,本申请实施例中区块链系统执行的操作均可以由区块链系统中的SQL执行引擎来执行,当然,也可以由其他模块来执行,本申请实施例对此不作限定。
在一些实施例中,事务使用会有两种情况,通过启动事务语句来决定是否自动提交事务。若区块链系统未接收到启动事务语句,则自动提交事务,即执行非持续性事务,具体是每接收到一条SQL语句便会在执行后提交,此时实际上是将每次接收到的一条SQL语句作为一个事务进行执行。若区块链系统接收到启动事务语句,则不自动提交事务,即执行持续性事务,具体是将接收到的多条SQL语句作为一个事务进行执行,对多条SQL语句的执行结果同时提交或回滚。
为了便于理解,下面结合图5和图6来对非持续性事务和持续性事务的执行过程进行举例说明。
图5是本申请实施例提供的一种非持续性事务的执行过程的示意图。参见图5,非持续性事务的执行过程应用于区块链系统,可以包括如下步骤(1)-步骤(5)。
(1)接收到客户端发送的携带有SQL语句的交易后,将这条SQL语句作为一个事务。
(2)对该SQL语句进行解析,以确定该SQL语句是需要读取区块链账本中的数据还是需要修改区块链账本中的数据。
(3)若该SQL语句需要修改区块链账本中的数据,则判断所要修改的数据是否已经被其他事务加锁;若该数据已被其他事务加锁,则锁冲突,当前交易执行失败;若该数据未被其他事务加锁,则该事务对该数据加锁后,对该数据进行修改,修改完成后对该数据进行解锁,以提交该事务。
(4)若该SQL语句需要读取区块链账本中的数据,则读取所要读取的数据的未被其他事务加锁的版本记录中版本号小于或等于该事务的开始版本号的数据值中版本号最大的数据值,将读取到的数据返回给客户端,以实现对该事务的提交。
(5)提交该事务后,触发GC流程,以对区块链账本中的历史版本记录进行清理。
图6是本申请实施例提供的一种持续性事务的执行过程的示意图。参见图6,持续性事务的执行过程应用于区块链系统,可以包括如下步骤(1)-步骤(8)。
(1)接收到客户端发送的携带有启动事务语句的交易后,创建事务。
(2)接收客户端发送的多个携带有SQL语句的交易。
(3)每接收到客户端发送的一个携带有SQL语句的交易,对该SQL语句进行解析,以确定该SQL语句是需要读取区块链账本中的数据还是需要修改区块链账本中的数据。
(4)若该SQL语句需要修改区块链账本中的数据,则判断所要修改的数据是否已经被其他事务加锁;若该数据已被其他事务加锁,则锁冲突,当前交易执行失败,该事务也执行失败;若该数据未被其他事务加锁,则该事务对该数据加锁后,对该数据进行修改。
(5)若该SQL语句需要读取区块链账本中的数据,则读取所要读取的数据的未被其他事务加锁的版本记录中版本号小于或等于该事务的开始版本号的数据值中版本号最大的数据值,将读取到的数据返回给客户端。
(6)若接收到客户端发送的携带有提交语句的交易,则将区块链账本中版本号为锁版本号、且事务标识为该事务的标识的所有版本记录中的版本号均修改为该事务的提交版本号,以对该事务执行的多个SQL语句的修改数据进行提交。
(7)若接收到客户端发送的携带有回滚语句的交易,则将区块链账本中版本号为锁版本号、且事务标识为该事务的标识的所有版本记录进行删除,以对该事务执行的多个SQL语句的修改数据进行回滚。
(8)提交或回滚该事务后,触发GC流程,以对区块链账本中的历史版本记录进行清理。
在本申请实施例中,客户端向区块链系统发送携带有启动事务语句的第一交易指示区块链系统创建目标事务后,客户端可以不断向区块链系统发送携带有SQL语句的多个第二交易,以指示区块链系统将多个SQL语句作为一个事务进行执行。区块链系统创建目标事务后,每接收到客户端发送的一个第二交易,就可以对这个第二交易携带的SQL语句进行执行,具体地,若这个第二交易携带的SQL语句用于修改区块链账本中的第一数据,则在目标事务对第一数据加锁的情况下,根据这个第二交易携带的SQL语句修改第一数据。之后,客户端可以向区块链系统发送携带有提交语句的第三交易,区块链系统接收到第三交易后,可以对区块链账本中被目标事务加锁的所有数据进行解锁,以对目标事务执行的多个SQL语句的修改数据进行提交。如此,在区块链系统中实现了对事务的支持,即实现了在区块链系统将客户端发送的多个SQL语句作为一个事务进行执行,以此提高了区块链系 统执行SQL语句的灵活性和准确性,从而提高了业务适用性。
图7是本申请实施例提供的一种事务执行装置的结构示意图。该装置可以由软件、硬件或者两者的结合实现成为计算机设备的部分或者全部,该计算机设备可以为下文图8所示的计算机设备,该计算机设备可以为区块链系统。参见图7,该装置包括:创建模块701、接收模块702、修改模块703、提交模块704。
创建模块701,用于接收到客户端发送的携带有启动事务语句的第一交易后,创建目标事务;
接收模块702,用于接收客户端发送的多个第二交易,多个第二交易中的每个第二交易均携带有需目标事务执行的用于操作区块链账本的SQL语句;
修改模块703,用于每接收到客户端发送的一个第二交易,若一个第二交易携带的SQL语句用于修改区块链账本中的第一数据,则在目标事务对第一数据加锁的情况下,根据一个第二交易携带的SQL语句修改第一数据;
提交模块704,用于若接收到客户端发送的携带有提交语句的第三交易,则对区块链账本中被目标事务加锁的所有数据进行解锁,以对目标事务执行的多个SQL语句的修改数据进行提交。
可选地,该装置还包括:
解析模块,用于每接收到客户端发送的一个第二交易,对一个第二交易携带的SQL语句进行解析,得到解析结果,解析结果包括键值对和操作类型;
查找模块,用于若操作类型为修改类型,则根据键值对中的key值在区块链账本中查找对应的数据作为一个第二交易携带的SQL语句需修改的第一数据。
可选地,区块链账本中的数据具有一条或多条版本记录,版本记录包括数据值、事务标识和版本号,事务标识为生成版本记录的事务的标识;修改模块703用于:
若第一数据的版本号最大的版本记录中的版本号不是锁版本号,则在区块链账本中为第一数据新增一条版本号为锁版本号、事务标识为目标事务的标识的版本记录,以使目标事务对第一数据加锁,锁版本号是版本号所能取得的最大值;或者,若第一数据的版本号最大的版本记录中的版本号是锁版本号、且事务标识是目标事务的标识,则确定第一数据已被目标事务加锁;
根据一个第二交易携带的SQL语句对第一数据的版本记录中版本号为锁版本号的数据值进行修改。
可选地,提交模块704用于:
为目标事务分配提交版本号;
将区块链账本中版本号为锁版本号、且事务标识为目标事务的标识的所有版本记录中的版本号均修改为目标事务的提交版本号,以对区块链账本中被目标事务加锁的所有数据进行解锁。
可选地,该装置还包括:
判断模块,用于每接收到客户端发送的一个第二交易,若一个第二交易携带的SQL语句用于读取区块链账本中的第二数据,则判断第二数据是否被目标事务加锁;
第一读取模块,用于若第二数据已被目标事务加锁,则读取第二数据的版本记录中版本号为锁版本号的数据值;
第二读取模块,用于若第二数据未被目标事务加锁,则在可重复读隔离级别下,读取第二数据的版本记录中版本号小于目标事务的开始版本号的数据值中版本号最大的数据值,目标事务的开始版本号是在创建目标事务时分配的;在读已提交隔离级别下,读取第二数据的版本记录中除版本号为锁版本号之外的数据值中版本号最大的数据值。
可选地,该装置还包括:
回滚模块,用于若接收到客户端发送的携带有回滚语句的第四交易,则将区块链账本中版本号为锁版本号、且事务标识为目标事务的标识的所有版本记录进行删除,以对目标事务执行的多个SQL语句的修改数据进行回滚。
可选地,该装置还包括:
清理模块,用于在向区块链添加预设数量的区块后,清理区块链账本中的历史版本记录;或者,在每次事务提交时,清理区块链账本中的历史版本记录;或者,在每次事务读取区块链账本中的数据时,清理区块链账本中的历史版本记录。
可选地,清理模块用于:
将当前存活的事务的开始版本号中最小的开始版本号作为目标版本号,事务的开始版本号是在事务创建时分配的;
对于区块链账本中的每一个数据,将一个数据的版本记录中版本号小于目标版本号的版本记录作为一个数据的目标版本记录;
删除一个数据的目标版本记录中除版本号最大的版本记录之外的其他历史版本记录。
在本申请实施例中,客户端向区块链系统发送携带有启动事务语句的第一交易指示区块链系统创建目标事务后,客户端可以不断向区块链系统发送携带有SQL语句的多个第二交易,以指示区块链系统将多个SQL语句作为一个事务进行执行。区块链系统创建目标事务后,每接收到客户端发送的一个第二交易,就可以对这个第二交易携带的SQL语句进行执行,具体地,若这个第二交易携带的SQL语句用于修改区块链账本中的第一数据,则在目标事务对第一数据加锁的情况下,根据这个第二交易携带的SQL语句修改第一数据。之后,客户端可以向区块链系统发送携带有提交语句的第三交易,区块链系统接收到第三交易后,可以对区块链账本中被目标事务加锁的所有数据进行解锁,以对目标事务执行的多个SQL语句的修改数据进行提交。如此,在区块链系统中实现了对事务的支持,即实现了在区块链系统将客户端发送的多个SQL语句作为一个事务进行执行,以此提高了区块链系统执行SQL语句的灵活性和准确性,从而提高了业务适用性。
需要说明的是:上述实施例提供的事务执行装置在事务执行时,仅以上述各功能模块的划分进行举例说明,实际应用中,可以根据需要而将上述功能分配由不同的功能模块完成,即将装置的内部结构划分成不同的功能模块,以完成以上描述的全部或者部分功能。
上述实施例中的各功能单元、模块可以集成在一个处理单元中,也可以是各个单元单独物理存在,也可以两个或两个以上单元集成在一个单元中,上述集成的单元既可以采用硬件的形式实现,也可以采用软件功能单元的形式实现。另外,各功能单元、模块的具体名称也只是为了便于相互区分,并不用于限制本申请实施例的保护范围。
上述实施例提供的事务执行装置与事务执行方法实施例属于同一构思,上述实施例中单元、模块的具体工作过程及带来的技术效果,可参见方法实施例部分,此处不再赘述。
图8为本申请实施例提供的一种计算机设备的结构示意图。如图8所示,计算机设备 8包括:处理器80、存储器81以及存储在存储器81中并可在处理器80上运行的计算机程序82,处理器80执行计算机程序82时实现上述实施例中的事务执行方法中由区块链系统执行的步骤。
计算机设备8可以是包括多台服务器的服务器集群,具体可以是区块链系统。本领域技术人员可以理解,图8仅仅是计算机设备8的举例,并不构成对计算机设备8的限定,可以包括比图示更多或更少的部件,或者组合某些部件,或者不同的部件,比如还可以包括输入输出设备、网络接入设备等。
处理器80可以是中央处理单元(Central Processing Unit,CPU),处理器80还可以是其他通用处理器、数字信号处理器(Digital Signal Processor,DSP)、专用集成电路(Application Specific Integrated Circuit,ASIC)、现成可编程门阵列(Field-Programmable Gate Array,FPGA)或者其他可编程逻辑器件、分立门或者晶体管逻辑器件、分立硬件组件等。通用处理器可以是微处理器或者也可以是任何常规的处理器。
存储器81在一些实施例中可以是计算机设备8的内部存储单元,比如计算机设备8的硬盘或内存。存储器81在另一些实施例中也可以是计算机设备8的外部存储设备,比如计算机设备8上配备的插接式硬盘、智能存储卡(Smart Media Card,SMC)、安全数字(Secure Digital,SD)卡、闪存卡(Flash Card)等。进一步地,存储器81还可以既包括计算机设备8的内部存储单元也包括外部存储设备。存储器81用于存储操作系统、应用程序、引导装载程序(Boot Loader)、数据以及其他程序等。存储器81还可以用于暂时地存储已经输出或者将要输出的数据。
本申请实施例还提供了一种计算机设备,该计算机设备包括:至少一个处理器、存储器以及存储在该存储器中并可在该至少一个处理器上运行的计算机程序,该处理器执行该计算机程序时实现上述任意各个方法实施例中的步骤。
本申请实施例还提供了一种计算机可读存储介质,该计算机可读存储介质存储有计算机程序,该计算机程序被处理器执行时可实现上述各个方法实施例中的步骤。
本申请实施例提供了一种计算机程序产品,当其在计算机上运行时,使得计算机执行上述各个方法实施例中的步骤。
集成的单元如果以软件功能单元的形式实现并作为独立的产品销售或使用时,可以存储在一个计算机可读取存储介质中。基于这样的理解,本申请实现上述方法实施例中的全部或部分流程,可以通过计算机程序来指令相关的硬件来完成,该计算机程序可存储于一计算机可读存储介质中,该计算机程序在被处理器执行时,可实现上述各个方法实施例的步骤。其中,该计算机程序包括计算机程序代码,该计算机程序代码可以为源代码形式、对象代码形式、可执行文件或某些中间形式等。该计算机可读介质至少可以包括:能够将计算机程序代码携带到拍照装置/终端设备的任何实体或装置、记录介质、计算机存储器、ROM(Read-Only Memory,只读存储器)、RAM(Random Access Memory,随机存取存储器)、CD-ROM(Compact Disc Read-Only Memory,只读光盘)、磁带、软盘和光数据存储设备等。本申请提到的计算机可读存储介质可以为非易失性存储介质,换句话说,可以是非瞬时性存储介质。
应当理解的是,实现上述实施例的全部或部分步骤可以通过软件、硬件、固件或者其任意结合来实现。当使用软件实现时,可以全部或部分地以计算机程序产品的形式实现。 该计算机程序产品包括一个或多个计算机指令。该计算机指令可以存储在上述计算机可读存储介质中。
在上述实施例中,对各个实施例的描述都各有侧重,某个实施例中没有详述或记载的部分,可以参见其它实施例的相关描述。
本领域普通技术人员可以意识到,结合本文中所公开的实施例描述的各示例的单元及算法步骤,能够以电子硬件、或者计算机软件和电子硬件的结合来实现。这些功能究竟以硬件还是软件方式来执行,取决于技术方案的特定应用和设计约束条件。专业技术人员可以对每个特定的应用来使用不同方法来实现所描述的功能,但是这种实现不应认为超出本申请的范围。
在本申请所提供的实施例中,应该理解到,所揭露的装置/计算机设备和方法,可以通过其它的方式实现。例如,以上所描述的装置/计算机设备实施例仅仅是示意性的,例如,模块或单元的划分,仅仅为一种逻辑功能划分,实际实现时可以有另外的划分方式,例如多个单元或组件可以结合或者可以集成到另一个系统,或一些特征可以忽略,或不执行。另一点,所显示或讨论的相互之间的耦合或直接耦合或通讯连接可以是通过一些接口,装置或单元的间接耦合或通讯连接,可以是电性,机械或其它的形式。
作为分离部件说明的单元可以是或者也可以不是物理上分开的,作为单元显示的部件可以是或者也可以不是物理单元,即可以位于一个地方,或者也可以分布到多个网络单元上。可以根据实际的需要选择其中的部分或者全部单元来实现本实施例方案的目的。
以上所述实施例仅用以说明本申请的技术方案,而非对其限制;尽管参照前述实施例对本申请进行了详细的说明,本领域的普通技术人员应当理解:其依然可以对前述各实施例所记载的技术方案进行修改,或者对其中部分技术特征进行等同替换;而这些修改或者替换,并不使相应技术方案的本质脱离本申请各实施例技术方案的精神和范围,均应包含在本申请的保护范围之内。

Claims (11)

  1. 一种事务执行方法,其特征在于,应用于区块链系统,所述方法包括:
    接收到客户端发送的携带有启动事务语句的第一交易后,创建目标事务;
    接收所述客户端发送的多个第二交易,所述多个第二交易中的每个第二交易均携带有需所述目标事务执行的用于操作区块链账本的结构化查询语言SQL语句;
    每接收到所述客户端发送的一个第二交易,若所述一个第二交易携带的SQL语句用于修改所述区块链账本中的第一数据,则在所述目标事务对所述第一数据加锁的情况下,根据所述一个第二交易携带的SQL语句修改所述第一数据;
    若接收到所述客户端发送的携带有提交语句的第三交易,则对所述区块链账本中被所述目标事务加锁的所有数据进行解锁,以对所述目标事务执行的多个SQL语句的修改数据进行提交。
  2. 如权利要求1所述的方法,其特征在于,所述方法还包括:
    每接收到所述客户端发送的一个第二交易,对所述一个第二交易携带的SQL语句进行解析,得到解析结果,所述解析结果包括键值对和操作类型;
    若所述操作类型为修改类型,则根据所述键值对中的key值在所述区块链账本中查找对应的数据作为所述一个第二交易携带的SQL语句需修改的所述第一数据。
  3. 如权利要求1所述的方法,其特征在于,所述区块链账本中的数据具有一条或多条版本记录,所述版本记录包括数据值、事务标识和版本号,所述事务标识为生成所述版本记录的事务的标识;
    所述在所述目标事务对所述第一数据加锁的情况下,根据所述一个第二交易携带的SQL语句修改所述第一数据,包括:
    若所述第一数据的版本号最大的版本记录中的版本号不是锁版本号,则在所述区块链账本中为所述第一数据新增一条版本号为所述锁版本号、事务标识为所述目标事务的标识的版本记录,以使所述目标事务对所述第一数据加锁,所述锁版本号是版本号所能取得的最大值;或者,若所述第一数据的版本号最大的版本记录中的版本号是所述锁版本号、且事务标识是所述目标事务的标识,则确定所述第一数据已被所述目标事务加锁;
    根据所述一个第二交易携带的SQL语句对所述第一数据的版本记录中版本号为所述锁版本号的数据值进行修改。
  4. 如权利要求3所述的方法,其特征在于,所述对所述区块链账本中被所述目标事务加锁的所有数据进行解锁,包括:
    为所述目标事务分配提交版本号;
    将所述区块链账本中版本号为锁版本号、且事务标识为所述目标事务的标识的所有版本记录中的版本号均修改为所述目标事务的提交版本号,以对所述区块链账本中被所述目标事务加锁的所有数据进行解锁。
  5. 如权利要求3所述的方法,其特征在于,所述方法还包括:
    每接收到所述客户端发送的一个第二交易,若所述一个第二交易携带的SQL语句用于读取所述区块链账本中的第二数据,则判断所述第二数据是否被所述目标事务加锁;
    若所述第二数据已被所述目标事务加锁,则读取所述第二数据的版本记录中版本号为所述锁版本号的数据值;
    若所述第二数据未被所述目标事务加锁,则在可重复读隔离级别下,读取所述第二数据的版本记录中版本号小于所述目标事务的开始版本号的数据值中版本号最大的数据值,所述目标事务的开始版本号是在创建所述目标事务时分配的;在读已提交隔离级别下,读取所述第二数据的版本记录中除版本号为所述锁版本号之外的数据值中版本号最大的数据值。
  6. 如权利要求3所述的方法,其特征在于,所述方法还包括:
    若接收到所述客户端发送的携带有回滚语句的第四交易,则将所述区块链账本中版本号为所述锁版本号、且事务标识为所述目标事务的标识的所有版本记录进行删除,以对所述目标事务执行的多个SQL语句的修改数据进行回滚。
  7. 如权利要求3-6任一所述的方法,其特征在于,所述方法还包括:
    在向区块链添加预设数量的区块后,清理所述区块链账本中的历史版本记录;或者,
    在每次事务提交时,清理所述区块链账本中的历史版本记录;或者,
    在每次事务读取所述区块链账本中的数据时,清理所述区块链账本中的历史版本记录。
  8. 如权利要求7所述的方法,其特征在于,所述清理所述区块链账本中的历史版本记录,包括:
    将当前存活的事务的开始版本号中最小的开始版本号作为目标版本号,所述事务的开始版本号是在所述事务创建时分配的;
    对于所述区块链账本中的每一个数据,将所述一个数据的版本记录中版本号小于所述目标版本号的版本记录作为所述一个数据的目标版本记录;
    删除所述一个数据的目标版本记录中除版本号最大的版本记录之外的其他历史版本记录。
  9. 一种事务执行装置,其特征在于,应用于区块链系统,所述装置包括:
    创建模块,用于接收到客户端发送的携带有启动事务语句的第一交易后,创建目标事务;
    接收模块,用于接收所述客户端发送的多个第二交易,所述多个第二交易中的每个第二交易均携带有需所述目标事务执行的用于操作区块链账本的结构化查询语言SQL语句;
    修改模块,用于每接收到所述客户端发送的一个第二交易,若所述一个第二交易携带的SQL语句用于修改所述区块链账本中的第一数据,则在所述目标事务对所述第一数据加锁的情况下,根据所述一个第二交易携带的SQL语句修改所述第一数据;
    提交模块,用于若接收到所述客户端发送的携带有提交语句的第三交易,则对所述区块链账本中被所述目标事务加锁的所有数据进行解锁,以对所述目标事务执行的多个SQL语句的修改数据进行提交。
  10. 一种计算机设备,其特征在于,所述计算机设备包括存储器、处理器以及存储在所述存储器中并可在所述处理器上运行的计算机程序,所述计算机程序被所述处理器执行时实现如权利要求1至8任一项所述的方法。
  11. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质存储有计算机程序,所述计算机程序被处理器执行时实现如权利要求1至8任一项所述的方法。
PCT/CN2022/118805 2021-12-31 2022-09-14 事务执行方法、装置、设备和存储介质 WO2023124242A1 (zh)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202111677879.XA CN114328591A (zh) 2021-12-31 2021-12-31 事务执行方法、装置、设备和存储介质
CN202111677879.X 2021-12-31

Publications (1)

Publication Number Publication Date
WO2023124242A1 true WO2023124242A1 (zh) 2023-07-06

Family

ID=81022758

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/118805 WO2023124242A1 (zh) 2021-12-31 2022-09-14 事务执行方法、装置、设备和存储介质

Country Status (2)

Country Link
CN (1) CN114328591A (zh)
WO (1) WO2023124242A1 (zh)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114328591A (zh) * 2021-12-31 2022-04-12 杭州趣链科技有限公司 事务执行方法、装置、设备和存储介质

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108804112A (zh) * 2018-05-22 2018-11-13 上海分布信息科技有限公司 一种区块链落账处理方法及系统
CN111475262A (zh) * 2020-04-02 2020-07-31 百度国际科技(深圳)有限公司 区块链中事务请求处理方法、装置、设备和介质
US20210109916A1 (en) * 2019-10-10 2021-04-15 Unisys Corporation Relational database blockchain accountability
CN114328591A (zh) * 2021-12-31 2022-04-12 杭州趣链科技有限公司 事务执行方法、装置、设备和存储介质

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108804112A (zh) * 2018-05-22 2018-11-13 上海分布信息科技有限公司 一种区块链落账处理方法及系统
US20210109916A1 (en) * 2019-10-10 2021-04-15 Unisys Corporation Relational database blockchain accountability
CN111475262A (zh) * 2020-04-02 2020-07-31 百度国际科技(深圳)有限公司 区块链中事务请求处理方法、装置、设备和介质
CN114328591A (zh) * 2021-12-31 2022-04-12 杭州趣链科技有限公司 事务执行方法、装置、设备和存储介质

Also Published As

Publication number Publication date
CN114328591A (zh) 2022-04-12

Similar Documents

Publication Publication Date Title
US11429641B2 (en) Copying data changes to a target database
US11314716B2 (en) Atomic processing of compound database transactions that modify a metadata entity
US11003689B2 (en) Distributed database transaction protocol
CN111143389B (zh) 事务执行方法、装置、计算机设备及存储介质
US11416470B2 (en) Multiversion concurrency control of database records with uncommitted transactions
CN106033437B (zh) 一种分布式事务处理方法及系统
CN111338766B (zh) 事务处理方法、装置、计算机设备及存储介质
EP3117348B1 (en) Systems and methods to optimize multi-version support in indexes
CN111159252B (zh) 事务执行方法、装置、计算机设备及存储介质
US10754854B2 (en) Consistent query of local indexes
CN111522631B (zh) 分布式事务处理方法、装置、服务器及介质
CN109710388B (zh) 数据读取方法、装置、电子设备以及存储介质
US9576038B1 (en) Consistent query of local indexes
CN111597015B (zh) 事务处理方法、装置、计算机设备及存储介质
JP2023546249A (ja) トランザクション処理方法、装置、コンピュータ機器及びコンピュータプログラム
US10866865B1 (en) Storage system journal entry redaction
CN111444027B (zh) 事务处理方法、装置、计算机设备及存储介质
WO2023124242A1 (zh) 事务执行方法、装置、设备和存储介质
US8909681B2 (en) Gap detection in a temporally unique index in a relational database
CN114691307A (zh) 事务处理方法及计算机系统
WO2022242401A1 (zh) 一种数据库系统的事务处理方法、装置、电子设备、计算机可读存储介质及计算机程序产品
US20230145054A1 (en) Multi-region database systems and methods
US20240045887A1 (en) Systems and methods for controlling replica placement in multi-region databases
US11599520B1 (en) Consistency management using query restrictions in journal-based storage systems
CN117435574A (zh) 改进的二阶段提交事务实现方法及系统、设备、存储介质

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 22913511

Country of ref document: EP

Kind code of ref document: A1