WO2023216636A1 - Transaction processing method and apparatus, and electronic device - Google Patents

Transaction processing method and apparatus, and electronic device Download PDF

Info

Publication number
WO2023216636A1
WO2023216636A1 PCT/CN2022/144419 CN2022144419W WO2023216636A1 WO 2023216636 A1 WO2023216636 A1 WO 2023216636A1 CN 2022144419 W CN2022144419 W CN 2022144419W WO 2023216636 A1 WO2023216636 A1 WO 2023216636A1
Authority
WO
WIPO (PCT)
Prior art keywords
transaction
target data
data
processing
operations
Prior art date
Application number
PCT/CN2022/144419
Other languages
French (fr)
Chinese (zh)
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 WO2023216636A1 publication Critical patent/WO2023216636A1/en

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/23Updating
    • 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/21Design, administration or maintenance of databases
    • G06F16/219Managing data history or versioning

Definitions

  • the present application relates to the field of database technology, and in particular, to a transaction processing method, device and electronic equipment.
  • a transaction refers to a program execution unit that accesses the database and may update various data in the database.
  • a transaction includes at least one operation that processes at least one piece of data.
  • transaction processing methods that perform operations included in each transaction based on data in the database.
  • Embodiments of the present application provide a transaction processing method, device and electronic equipment to achieve efficient management of the transaction processing process.
  • a transaction processing management method which method includes:
  • the first transaction includes an operation of processing the target data
  • the second transaction is another transaction in parallel with the first transaction
  • executing the The first transaction includes operations to process the target data.
  • detecting whether the target data targeted by the first transaction is occupied by the second transaction includes:
  • the instruction information carried by the target data includes the transaction number of the transaction that occupies the target data; based on the fact that the transaction number included in the instruction information is the transaction number of the second transaction, determine that the The target data is occupied by the second transaction.
  • the target data in response to the target data being occupied by the second transaction, according to the occupation type of the target data by the second transaction and the first transaction.
  • the types of operations included in processing the target data, and performing the operations included in the first transaction to process the target data include:
  • reading the target data according to the occupation type of the target data by the second transaction and the operations included in the first transaction includes:
  • the operation included in the first transaction to process the target data is an update operation
  • the execution of the operation included in the first transaction to process the target data includes:
  • the instruction information includes the transaction number and the occupation type of the first transaction, the occupation type indicates that in the process of executing the operation included in the first transaction to update the target data , prohibiting execution of operations included in other transactions to read or update the target data; execution of operations included in the first transaction to update the target data.
  • the operation of processing the target data included in the first transaction is a read operation
  • the isolation level of the first transaction is serializable
  • the isolation level of performing the operations included in the first transaction to read the target data includes:
  • the instruction information of the target data includes the transaction number and the occupation type of the first transaction, the occupation type indicates performing the operation included in the first transaction to read the During the process of obtaining the target data, it is prohibited to execute operations included in other transactions to update the target data; execute operations included in the first transaction to read the target data.
  • the first transaction includes multiple operations, each operation is directed to corresponding target data, the first target data included in the multiple target data is occupied by the second transaction, and the multiple target data is occupied by the second transaction.
  • the operations are arranged in order of execution, and the operations included in executing the first transaction to process the target data include:
  • the isolation type of the first transaction is snapshot isolation
  • the operation included in the first transaction is to read the target version data corresponding to the target timestamp among the target data of multiple time versions
  • the operations included in executing the first transaction to process the target data include:
  • the multiple differential versions include the differential version corresponding to the target timestamp and the differential version formed before the time corresponding to the target timestamp.
  • the differential version refers to The update operation included in any transaction updates the content of the target data; merge the basic version of the target data and the data of the multiple differential versions to obtain the target data of the multiple data versions that is consistent with the target The target version data corresponding to the timestamp.
  • the method further includes:
  • the base version of the target data and the differential version of the target data are merged regularly to obtain merged data, and the merged data is used to update the base version of the target data.
  • a transaction processing device which device includes:
  • a detection module configured to detect whether the target data targeted by the first transaction is occupied by a second transaction, the first transaction includes an operation of processing the target data, and the second transaction is other parallel transactions with the first transaction. affairs;
  • Execution module configured to respond to the target data being occupied by the second transaction, and perform an operation based on the occupation type of the target data by the second transaction and the operation of processing the target data included in the first transaction.
  • Type perform operations included in the first transaction to process the target data.
  • the detection module is configured to read the indication information carried by the target data, the indication information including the transaction number of the transaction occupying the target data; based on the indication information included If the transaction number is the transaction number of the second transaction, it is determined that the target data is occupied by the second transaction.
  • the execution module is configured to respond to the target data being occupied by the second transaction, and the operation of processing the target data included in the first transaction is an update operation, Then after the processing result of the second transaction is submitted, the target data is updated according to the operations included in the first transaction; in response to the target data being occupied by the second transaction, and the first transaction If the included operation of processing the target data is a read operation, then the target data is read according to the occupation type of the target data by the second transaction and the operation included in the first transaction.
  • the execution module is configured to determine the occupation type of the target data by the second transaction; in response to the occupation type indication, the process of occupying the target data by the second transaction , operations included in other transactions except the second transaction are prohibited from updating and reading the target data, then after the processing result of the second transaction is submitted, execution is performed according to the isolation level of the first transaction
  • the first transaction includes an operation to read the target data, and the isolation level of the first transaction is used to indicate a read rule corresponding to the operation included in the first transaction to read the target data.
  • the operation of processing the target data included in the first transaction is an update operation
  • the execution module is configured to set instruction information of the target data, and the instruction information includes the The transaction number and occupancy type of the first transaction, the occupancy type indicates that in the process of executing the operations included in the first transaction to update the target data, it is prohibited to perform other transactions including reading or updating the target data.
  • Operation perform operations included in the first transaction to update the target data.
  • the operation of processing the target data included in the first transaction is a read operation
  • the isolation level of the first transaction is serializable
  • the execution module is used to set Instruction information of the target data
  • the instruction information includes the transaction number and occupation type of the first transaction
  • the occupation type indicates performing operations included in the first transaction to read the target
  • the first transaction includes multiple operations, each operation is directed to corresponding target data, the first target data included in the multiple target data is occupied by the second transaction, and the multiple target data is occupied by the second transaction.
  • the operations are arranged in execution order, and the execution module is configured to respond to completing the submission of the processing result of the second transaction within the first time interval, and after the processing result of the second transaction is submitted, execute the
  • the first transaction includes a first operation of processing the first target data, and the execution sequence of the first transaction includes operations after the first operation; in response to not completing all the operations within the first time interval.
  • the isolation type of the first transaction is snapshot isolation
  • the operation included in the first transaction is to read the target version data corresponding to the target timestamp among the target data of multiple time versions
  • the execution module is used to determine data of multiple differential versions of the target data.
  • the multiple differential versions include the differential version corresponding to the target timestamp and the differential formed before the time corresponding to the target timestamp.
  • Version the differential version refers to the content of the update operation of the target data included in any transaction; merge the basic version of the target data and the data of the multiple differential versions to obtain the multiple data versions The target version data corresponding to the target timestamp in the target data.
  • the device further includes:
  • a merging module configured to regularly merge the basic version of the target data and the differential version of the target data based on the merging time interval to obtain merged data, and the merged data is used to update the target The base version of the data.
  • an electronic device includes a processor and a memory. At least one program code or instruction is stored in the memory. The at least one program code or instruction is loaded and executed by the processor, so that the electronic device Implement any of the above transaction processing methods.
  • a computer-readable storage medium is provided. At least one program code or instruction is stored in the computer-readable storage medium. The program code is loaded and executed by the processor to enable the computer to implement any of the above transaction processes. method.
  • a computer program or computer program product is provided. At least one computer instruction is stored in the computer program or computer program product. The at least one computer instruction is loaded and executed by the processor to enable the computer to implement any of the above. Transaction processing methods.
  • the technical solution provided by the embodiment of the present application detects the occupation of the target data by a second transaction that is parallel to the first transaction, and processes the target data based on the occupation type of the target data by the second transaction and the operations included in the first transaction. This process realizes the processing of parallel transactions based on the detection of target data. There is no need for system calls to control the scenario where the parallel first transaction and the second transaction are processed for the same target data. This avoids frequent falling into the operating system kernel state and improves efficiency. Transaction processing efficiency improves system throughput.
  • Figure 1 is a schematic diagram of an implementation environment provided by an embodiment of the present application.
  • Figure 2 is a flow chart of transaction processing provided by an embodiment of the present application.
  • FIG. 3 is a schematic diagram of data storage provided by an embodiment of the present application.
  • Figure 4 is a schematic structural diagram of a server provided by an embodiment of the present application.
  • Figure 5 is a schematic diagram of an online transaction processing interface provided by an embodiment of the present application.
  • Figure 6 is a schematic diagram of a command line transaction processing interface provided by an embodiment of the present application.
  • Figure 7 is a schematic diagram of an interface transaction processing interface provided by an embodiment of the present application.
  • Figure 8 is a schematic diagram of a transaction processing device provided by an embodiment of the present application.
  • FIG. 9 is a schematic diagram of an electronic device provided by an embodiment of the present application.
  • the implementation environment of the embodiment of the present application includes a terminal 11 and a server 12.
  • the terminal 11 and the server 12 can communicate and connect to realize interactive transmission of information.
  • the embodiment of the present application does not limit the connection method between the terminal 11 and the server 12 .
  • the terminal 11 submits a transaction startup request to the server 12.
  • the server 12 executes the operations included in the transaction to process the data targeted by the transaction, and then sends the processing results to the terminal 11.
  • the terminal 11 also sends instructions generated during the interaction to the server 12 .
  • the terminal 11 can be any electronic product that can perform human-computer interaction with the user through one or more methods such as keyboard, touch panel, touch screen, voice interaction, etc., such as PC (Personal Computer), mobile phone, PPC ( Pocket Personal Computer, tablet computer, car machine, etc.
  • the server 12 may be one server or a server cluster composed of multiple servers, or may provide cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, and domain names. Services, security services, CDN (Content Delivery Network, content distribution network), and cloud servers for basic cloud computing services such as big data and artificial intelligence platforms.
  • terminal 11 and server 12 are only examples. If other existing or possible terminals or servers that may appear in the future can be used in this application, they should also be included in the protection scope of this application. Incorporated herein by reference.
  • the embodiments of this application are applied in the field of database technology and are suitable for scenarios in which data is managed based on operations in each transaction.
  • the transaction processing method of this application can be applied in the Resource Description Framework (RDF) to perform transaction processing based on a large amount of RDF data included in the RDF database.
  • RDF Resource Description Framework
  • the current RDF database has weak transaction processing capabilities and few transaction processing functions.
  • the transaction processing method provided by this application can achieve efficient transaction processing.
  • a transaction refers to a program execution unit that accesses and possibly updates various data in the database.
  • a transaction includes at least one operation that processes at least one piece of data.
  • Atomicity A transaction is an indivisible whole. All operations included in a transaction can only be completed or not executed at all. Partial operations will not be executed. An exception occurs during the operation on the data, and the data is restored to the state before the transaction started. This process can be called rollback.
  • Consistency Before and after the transaction starts and ends, the integrity constraints of the database are not violated, and the integrity of the data in the database remains consistent. For example: User A's account balance is 1,000 yuan, User B's account balance is 2,900 yuan, and user A transfers 100 yuan to user B. After the transfer is completed, user A's account balance is 900, and user B's account balance is 3,000. Before and after the transfer, the sum of the balances of users A and B's accounts remains unchanged at 3,900 yuan.
  • Isolation means that only operations in one transaction are allowed to process the same data at the same time, and there is no interference between different transactions. For example, for the same data, users A and B start transaction 1 and transaction 2 respectively, and transaction 1 and transaction 2 are executed in parallel. Therefore, transaction 1 and transaction 2 should be isolated from each other. For transaction 1, the operations included in transaction 2 cannot interfere with the execution of transaction 1, and user A cannot feel that transaction 2 is executed in parallel with transaction 1.
  • an embodiment of the present application provides a flow chart of a transaction processing method. This method can be applied to the server. The method includes but is not limited to the following steps 201-202.
  • Step 201 Detect whether the target data targeted by the first transaction is occupied by a second transaction.
  • the first transaction includes an operation of processing the target data.
  • the second transaction is another transaction in parallel with the first transaction.
  • detecting whether the target data targeted by the first transaction is occupied by the second transaction includes: reading the indication information carried by the target data, where the indication information includes the transaction number of the transaction that occupies the target data; based on The transaction number included in the indication information is the transaction number of the second transaction, and it is determined that the target data is occupied by the second transaction.
  • each transaction corresponds to a corresponding transaction number, and the transaction number of each transaction is unique.
  • transaction numbers are randomly assigned by the server and are stored in a transaction list for management.
  • the server before executing step 201, the server receives a start request for the first transaction submitted by the terminal, the server starts the first transaction based on the start request of the first transaction, and allocates a corresponding response to the first transaction. transaction number.
  • the receipt of the start request and the assignment of the transaction number can be performed by a transaction scheduler in the server.
  • the allocation of transaction numbers is determined by a strictly incrementing atomic counter to ensure the uniqueness of the transaction number of each transaction, and the relative order in which multiple transactions are started can be determined based on the transaction numbers of multiple transactions.
  • the transaction number of each transaction may be a 64-bit code.
  • the first transaction is started.
  • the first transaction includes the operation of reading or updating the target data, accessing the target data, and reading the indication information carried by the target data. If the indication information is empty, then The target data has not been occupied by other transactions, and the operations included in the first transaction can process the target data; if the indication information is not empty, determine the transaction number included in the indication information, and the transaction number included in the indication information is The transaction number of the transaction currently occupying the target data. For example, when the current transaction occupies the target data, the update operation included in the current transaction that is occupying the target data is performed to update the target data.
  • the transaction number is the transaction number of the second transaction
  • the method of determining the target data targeted by the first transaction includes, but is not limited to: determining the target data targeted by the first transaction based on the information of the first transaction.
  • the server may determine the information of the first transaction by parsing the instructions of each operation included in the first transaction; or determine the information of the first transaction by parsing the start request of the first transaction.
  • the first transaction includes instructions for each operation that are determined and submitted by the user on the terminal.
  • the start request of the first transaction carries information about the target data to be processed by the operation in the transaction.
  • the information about the target data includes the storage location of the target data, the timestamp corresponding to the target data, or the version number of the target data, etc.
  • Step 202 in response to the target data being occupied by the second transaction, execute the operations included in the first transaction to process the target data according to the occupation type of the target data by the second transaction and the type of operations included in the first transaction to process the target data.
  • the fact that the target data is occupied by the second transaction means that during the process of processing the target data by the operations included in the second transaction, operations included in other transactions are restricted from processing the target data.
  • Different occupancy types have different restrictions on operations included in other transactions.
  • the restriction methods corresponding to the occupancy types include but are not limited to: The first occupancy type is used to indicate that update operations included in other transactions are prohibited while the target data is occupied by the second transaction. Process the target data; or, the second occupation type is used to indicate that when the target data is occupied by the second transaction, in addition to prohibiting update operations included in other transactions from processing the target data, it also prohibits read operations included in other transactions from processing the target data.
  • the target data is processed.
  • any transaction can include an operation to process target data.
  • the type of operation includes but is not limited to updating or reading data.
  • the read operation includes but is not limited to obtaining data and obtaining related data.
  • Information; update operations include but are not limited to adding, modifying, deleting, etc. data.
  • data can be stored in various forms such as numerical values, text, pictures, etc.; then the update operation can include addition and subtraction calculations for data in any numerical form.
  • Any transaction can include one or more operations.
  • a transaction includes one operation, a corresponding operation is performed on a piece of data; when a transaction includes multiple operations, the multiple operations included in the transaction can perform corresponding operations on the same data or different data, and the data includes multiple operations.
  • the operation of processing the target data included in the first transaction is an update operation
  • the processing result of the second transaction is submitted, according to the first A transaction consists of operations that update target data.
  • the operation of processing the target data included in the first transaction is an update operation
  • the process of executing the operation included in the first transaction to update the target data includes: setting instruction information of the target data, the instruction information includes The transaction number and occupancy type of the first transaction.
  • the occupancy type indicates that during the process of executing the operations included in the first transaction to update the target data, it is prohibited to perform the operations of reading or updating the target data included in other transactions; executing the operations included in the first transaction Operation to update target data.
  • the current transaction occupying any data does not allow operations included in other transactions to update any data, so as to avoid affecting the final result of the current transaction. Therefore, during the process of the second transaction occupying the target data, if the first transaction includes an operation to update the target data, and the target data is occupied by a parallel second transaction, regardless of the operation included in the second transaction, the target data is read. Or the update operation cannot perform the operation on the target data included in the first transaction, but it is necessary to perform the update operation on the target data included in the first transaction after the processing result of the second transaction is submitted. After the processing result of the second transaction is submitted, the second transaction ends, the second transaction no longer occupies the target data, and the indication information of the target data returns to empty.
  • the operation of processing the target data included in the first transaction is a read operation, then according to the occupation type of the target data by the second transaction And the first transaction includes the operation of reading the target data.
  • the occupation types of the target data by the second transaction have various forms. Different occupation types correspond to different restrictions, and different restrictions have different regulations on the operations of processing the target data included in other transactions. Thus, the operations included in the first transaction are performed to read the target data according to the occupation type of the target data by the second transaction.
  • the occupation type of the target data by the second transaction is determined; in response to the occupation type indication, during the process of the second transaction occupying the target data, operation updates included in other transactions except the second transaction are prohibited. and reading the target data, after the processing result of the second transaction is submitted, the operations included in the first transaction are performed according to the isolation level of the first transaction to read the target data.
  • the first transaction is directly executed according to the isolation level of the first transaction.
  • a transaction consists of operations to read the target data.
  • the isolation level of the first transaction is used to indicate the read rule corresponding to the operation of reading the target data included in the first transaction.
  • the embodiments of this application include but are not limited to three isolation levels: read committed, snapshot isolation, and serializable.
  • read committed When a transaction corresponds to different isolation levels, the read operations included in the transaction are executed in different ways. The operations included in the transaction have different effects on the read operations.
  • the instruction information of the fetched data is updated in different ways.
  • a read operation included in a transaction running under the Read Committed isolation level can read the updated content of the transaction that has submitted the processing result and return the latest version corresponding to the data targeted by the read operation.
  • the update operation included in the transaction running under the read committed isolation level can update the indication information corresponding to the data targeted by the update operation, and can be used to set the indication information to include the transaction number of the transaction to indicate that the data is occupied by the transaction, and can also Used to set the transaction's occupation type of the data to the second occupation type to indicate that operations included in other transactions are prohibited from updating or reading the data while the transaction is occupying the data.
  • the process in which the transaction occupies the data indicated by the second occupancy type is the process of executing the update operation included in the transaction to update the data.
  • Transactions running under the isolation level of snapshot isolation include read operations that can read multiple versions of the data targeted by the read operation, the version corresponding to the timestamp.
  • the update operation included in the transaction running under snapshot isolation can update the indication information corresponding to the data targeted by the update operation, and can be used to set the indication information to include the transaction number of the transaction to indicate that the data is occupied by the transaction.
  • the update operation is also used to set the transaction's occupation type of the data to the second occupation type to indicate that during the process of the transaction occupying the data, operations included in other transactions are prohibited from updating or reading the data.
  • the process in which the transaction occupies the data indicated by the second occupancy type is the process of executing the update operation included in the transaction to update the data.
  • Transactions running under the serializable isolation level include read operations that can read the updated content of the transaction that has submitted the processing results and return the latest version corresponding to the data targeted by the read operation.
  • the read operation can update the indication information corresponding to the data targeted by the read operation, can be used to set the indication information including the transaction number of the transaction to indicate that the data is occupied by the transaction, and can also be used to set the occupation of the data by the transaction.
  • the type is the first occupation type to indicate that operations included in other transactions are prohibited from updating the data while the transaction is occupying the data.
  • the process in which the transaction occupies the data indicated by the first occupancy type is the process of executing the read operation included in the transaction to read the data.
  • the update operation included in the transaction running under the serializable isolation level can update the instruction information corresponding to the data targeted by the update operation, and can be used to set the instruction information to include the transaction number of the transaction to indicate that the data is occupied by the transaction. , is also used to set the occupation type of the data by the transaction to the second occupation type, to indicate that during the process of the transaction occupying the data, operations included in other transactions are prohibited from updating or reading the data.
  • the process in which the transaction occupies the data indicated by the second occupancy type is the process of executing the update operation included in the transaction to update the data.
  • the operation of processing the target data included in the first transaction is a read operation
  • the isolation level of the first transaction is serializable.
  • executing the first transaction according to the isolation level of the first transaction includes:
  • the operation to read the target data includes, but is not limited to: setting instruction information of the target data, the instruction information includes the instruction information including the transaction number and occupancy type of the first transaction, the occupancy type indicates performing the operation included in the first transaction to read During the process of obtaining the target data, it is prohibited to perform operations included in other transactions to update the target data; operations included in the first transaction are performed to read the target data.
  • step 201 before performing step 201, set a corresponding isolation level for the first transaction to be started, and then submit a startup request including the isolation level to the server.
  • the server starts the first transaction after receiving the startup request. , perform the operations included in the first transaction.
  • the corresponding isolation level is set for the transaction to be started based on the different processing requirements corresponding to different transactions.
  • the processing requirements can be requirements for the consistency of the database state. For example, if the processing requirement corresponding to the transaction to be started is to obtain a strongly consistent database state, then the isolation level corresponding to the transaction is set to serializable; or, the processing requirement corresponding to the transaction to be started is to obtain a consistent database state. If the isolation level is not strict, set the isolation level corresponding to the transaction to snapshot isolation or read committed. Among them, the consistency of the database state is not strict, indicating a weakly consistent database state.
  • the first transaction includes multiple operations, each operation is directed to the corresponding target data, the first target data included in the multiple target data is occupied by the second transaction, and the multiple operations are executed in order arranged, then the process of performing the operations included in the first transaction to process the target data in step 202 includes but is not limited to:
  • executing the first operation of processing the first target data included in the first transaction includes The execution sequence of the operation is after the first operation; in response to the submission of the processing result of the second transaction not being completed within the first time interval, then after the first time interval, re-executing the execution sequence of the first transaction including the first operation The operation before the operation; in response to the completion of execution of multiple operations included in the first transaction, the processing result of the first transaction is submitted.
  • the first transaction and the second transaction are processed in parallel, and the operations included in each transaction are executed sequentially in the order of execution.
  • the target data targeted by any operation in the first transaction is being occupied by the second transaction, in some cases, it is necessary to wait for the processing result of the second transaction to be submitted before executing the operations included in the first transaction, that is, the first transaction includes The operation is waiting.
  • the waiting time of the operations included in the first transaction is recorded from the time the operations included in the first transaction start waiting. If the submission of the processing result of the second transaction is completed within the first time interval from the start of waiting, and the waiting time does not exceed the first time interval, then after the processing result of the second transaction is submitted, the processing step included in the first transaction is executed. A first operation on target data, and then performing operations included in the first transaction in execution order after the first operation. If the submission of the processing result of the second transaction is not completed within the first time interval from the start of waiting, and the waiting time exceeds the first time interval, after the waiting time reaches the first time interval, the first transaction will be processed according to the multiple operations included in the first transaction.
  • the first-ordered operation In the order of execution, starting from the first-ordered operation, re-execute the multiple operations included in the first transaction; when re-executing to the first operation, if the first transaction waits for no longer than the first operation during re-execution, time, after the execution of the first operation is completed, the first transaction including other operations are executed sequentially according to the execution order.
  • the operations included in the first transaction are re-executed again according to the execution order. operate.
  • the number of re-executions exceeds the repetition threshold, a message that the first transaction fails to execute is fed back to the terminal.
  • the setting of the repetition threshold can be determined according to the nature of the first transaction, or can be set in advance. This application does not limit the setting of the value of the repetition threshold.
  • the first time interval increases as the number of repeated executions increases.
  • the time length corresponding to the first time interval in the current repeated execution process is twice the length corresponding to the first time interval in the previous execution process.
  • the increase in the first time interval continuously extends the waiting time in each execution, which can reduce the number of repeated executions, reduce computational complexity, and reduce resource consumption.
  • the first transaction and the second transaction are executed in parallel.
  • the first operation in the first transaction is executed, the data targeted by the first operation is occupied by the second transaction, and the execution of the first operation is suspended, waiting for the completion of the second transaction.
  • the second transaction does not submit the processing result, all operations included in the first transaction are re-executed.
  • the second transaction still occupies the corresponding data.
  • the first time interval is twice the first time interval in the previous execution, that is, 2t. If the processing data of the second transaction is submitted during the waiting time 2t, continue to execute the first operation and other operations included in the first transaction; if the second transaction has not been completed during the waiting time 2t, re-execute the first transaction including all operations. During the second re-execution, the first time interval is 4t. If the first operation still cannot be executed during the second re-execution, the loop will enter the third repeated execution process until the first operation is completed, and then continue to execute other operations included in the first transaction; or until the number of repeated executions exceeds Repeat the threshold and feedback a message that the first transaction failed to execute to the terminal.
  • the isolation type of the first transaction is snapshot isolation
  • the operation included in the first transaction is to read the target version data corresponding to the target timestamp among the target data of multiple time versions, then in step 202 Execute operations included in the first transaction to process the target data, including but not limited to:
  • the multiple differential versions include the differential version corresponding to the target timestamp and the differential version formed before the time corresponding to the target timestamp.
  • the differential version refers to the update operation included in any transaction that affects the target.
  • the content of the data update merge the basic data of the target data and the data of multiple differential versions to obtain the target version data corresponding to the target timestamp in the target data of multiple data versions.
  • merging the basic data of the target data and the data of multiple differential versions may include: after obtaining the basic version and multiple differential versions of the target data, sequentially merge the basic data with the differential versions in the time sequence corresponding to the differential versions. The data is updated to obtain the target version data.
  • merging the basic data of the target data and the data of multiple differential versions may include: after obtaining the basic version and multiple differential versions of the target data, deduplication and merging all obtained differential versions Process to obtain the merged result of the differential version; merge the merged result with the basic data to obtain the target version data.
  • the basic data and corresponding differential versions of each data are stored according to the differential versioning method.
  • Each differential version of each data corresponds to the update operation included in the transaction to update the data. .
  • the basic data M and the differential version "add N" generated based on the updated data content are stored.
  • this application can also directly store the updated target data, for example, "data M+N".
  • the method of determining the target version corresponding to the target timestamp II includes: obtaining the basic data M and the differential version "Add N” and “Add P”, and calculate "M+N” and "M+N+P” in sequence; or, first calculate the merged result "N+P" of the differential version and then merge it with the basic data to obtain "M+N+P".
  • Each differential version corresponds to a different timestamp.
  • the timestamp can represent the life cycle of the differential version and is used to indicate the start time and end time of the transaction to which the operation that generated the differential version belongs. For example, the timestamp may be expressed in the form of [start time, end time).
  • the timestamp is generated based on a combination of physical time and logical time. Among them, physical time refers to the time in the real world, indicating the real time when the transaction corresponding to the differential version occurs; logical time refers to the processing sequence of the transaction corresponding to the differential version determined by applying a logical counter. The count of this logical counter is incremented when each transaction is started. This method of determining timestamps can achieve a combination of logical order and physical order.
  • transaction 1 and transaction 2 are opened successively. Due to the influence of time value accuracy, the opening time of transaction 1 and transaction 2 is both recorded as 20 hours, 18 minutes and 30 seconds. Therefore, transaction 1 and transaction 1 cannot be determined based on physical time only. 2 sequence.
  • the logical time can record the order in which each transaction is opened based on the counter's count. Therefore, the method in the embodiment of the present application that combines physical time and logical time to determine the differential version of the timestamp can obtain a more accurate timestamp, and can more accurately obtain the data required to execute the operations included in each transaction, and has Conducive to improving transaction processing efficiency.
  • Figure 3 shows a schematic diagram of storing data according to the differential versioning method, which is in the form of an adjacency linked list.
  • These include base version and differential version 1-n.
  • differential version 1 corresponds to timestamp [0, TS 1 ), where 0 and TS 1 respectively correspond to the start time and end time of the transaction to which the operation forming the differential version belongs.
  • the version header is used to indicate the start of the differential version and does not indicate specific data.
  • the instruction of the read operation in the first transaction is to read the target version data of the target data at the target timestamp [TS 1 , TS 2 ), then obtain the basic version , differential version 1 and differential version 2, and then merge the basic version, differential version 1 and differential version 2 to update and merge based on the basic version to obtain the target version data corresponding to the target timestamp.
  • the method of merging the basic version, differential version 1 and differential version 2 can include the following two methods:
  • Method 1 Merge the basic version and the differential version 1 to obtain the merge result 1, and then merge the merge result 1 with the differential version 2 to obtain the target version data.
  • Method 2 Merge differential version 1 and differential version 2 to obtain the merged result of the differential versions, and then merge the basic data and differential versions to obtain the target version data.
  • the contents of differential version 1 and differential version 2 may be updated in opposite ways.
  • differential version 1 is to add data 1 and the differential version is to subtract data 1
  • the merge result of the differential versions is not Update basic data.
  • the basic data is the target version data.
  • the number of merge calculations is reduced, the calculation complexity is reduced, and the transaction processing efficiency can be improved.
  • the base version of the target data and the differential version of the target data are merged regularly to obtain the merged result, and the merged data is used to update the base version of the target data.
  • each data update generates a corresponding differential version, which makes it easy to store a large number of differential versions.
  • a large number of differential versions occupy a large amount of storage space, and junk data in the data needs to be recycled and cleaned regularly. Therefore, in a possible implementation, every time the merging time interval elapses, the base version of the target data and the cleared number of differential version data are merged to obtain the merged result, and the base version is updated with the merged result.
  • the number of clearings can be set based on experience or based on scene settings, and this is not limited in the embodiments of the present application.
  • the merge time interval can be expressed as physical time, or the number of committed transactions.
  • the merge time interval is expressed as physical time
  • the time interval from the last time the merge operation was performed to the current time is calculated.
  • the merge operation is performed. For example, if the merging interval is set to 30 minutes, a merging operation will be performed after 30 minutes.
  • the merge time interval is the number of submitted transactions, count the number of transactions that have completed processing results and submitted them from the last time the merge operation was performed to the current time.
  • the number of completed transactions and submitted transactions reaches the merge time interval, execute Merge operation. For example, if the merge time interval is set to 10,000, a merge operation will be performed every time 10,000 transactions are successfully completed.
  • the access or update operation to the data in the database is temporarily interrupted, and the data in the database that meets the cleaning conditions is cleaned.
  • step 202 in response to the completion of all operations included in the first transaction, the processing result of the first transaction is submitted based on the commit instruction, and a message that the first transaction is successfully executed is fed back to the terminal.
  • the submission instruction is triggered by the user on the terminal. After all operations included in the first transaction are executed, the server feeds back a confirmation message to the terminal, prompting the user to confirm again whether to execute the first transaction. In response to the user feedback confirmation instruction, a submission instruction is sent to the server, and the server submits the first transaction. processing results.
  • the server feeds back the confirmation message "Whether the transfer 100 is confirmed" to the terminal.
  • the user issues a "confirm completion” instruction and then sends a submission instruction to the server, instructing the server to submit the execution result of the first transaction. That is, the data of A's account reduced by 100 yuan and the data of B's account added 100 yuan are stored in the database.
  • the server feeds back the "transfer completed” message to the terminal, prompting the user that the first transaction was executed successfully.
  • the server may include a transaction scheduling processor, a query, an executor, and a garbage collection component to implement the above transaction processing method.
  • the transaction scheduling process receives instructions such as transaction startup requests, and also periodically instructs the garbage collection component to clean up useless data;
  • the query is used to parse the received startup requests and other statements;
  • the executor executes the storage layer based on the parsed statements. Perform corresponding operations on the data in the database, such as creating a new differential version or merging the data during the data acquisition process.
  • any one of the online transaction processing method, the command line transaction processing method, or the API (Application Programming Interface, Application Programming Interface) interface method can be used for implementation. See Figures 5, 6, and 7 respectively for schematic diagrams of operation interfaces obtained by implementing transaction processing in the above manner.
  • FIG. 5 is a schematic diagram of the online transaction processing interface. It includes the execution pages of two transactions.
  • the TID indicates the transaction number.
  • the transaction number is 1.
  • "insert data ⁇ v1> ⁇ value>"20" ⁇ ” is the instruction of the submitted transaction.
  • "The Result” is used to indicate the result of successful execution of the transaction.
  • Figure 6 is a schematic diagram of the command line transaction processing interface, which includes a start instruction for transaction number 4.
  • FIG. 7 is a schematic diagram of an interface for performing transaction processing through API calls.
  • FIG. 7 shows multiple transaction processing processes.
  • the transaction processing method provided by the embodiment of the present application determines the occupation type of the target data by the parallel second transaction based on the instruction information of the target data, and then executes the operations included in the first transaction based on the isolation level corresponding to the first transaction and the included operations. Operate on the target data to obtain the processing result of the first transaction.
  • This method does not require system calls to control parallel transactions to process the same data, avoids frequently falling into the operating system kernel state, improves transaction processing efficiency, and improves system throughput.
  • the application of differential version data in the embodiments of the present application reduces the storage space occupied by the data and improves the efficiency of updating the data.
  • An embodiment of the present application provides a transaction processing device, which is used to implement the transaction processing method shown in Figure 2.
  • the device includes but is not limited to:
  • the detection module 801 is used to detect whether the target data targeted by the first transaction is occupied by the second transaction.
  • the first transaction includes operations of processing the target data, and the second transaction is other transactions in parallel with the first transaction;
  • Execution module 802 configured to respond to the target data being occupied by the second transaction, and execute operations included in the first transaction to process the target data according to the occupation type of the target data by the second transaction and the type of operations included in the first transaction to process the target data. target data.
  • the detection module 801 is configured to read the indication information carried by the target data, where the indication information includes the transaction number of the transaction occupying the target data; based on the transaction number included in the indication information, it is the transaction number of the second transaction. , then it is determined that the target data is occupied by the second transaction.
  • the execution module 802 is configured to respond to the target data being occupied by the second transaction, and the operation of processing the target data included in the first transaction is an update operation, then when the processing result of the second transaction is After submission, the target data is updated according to the operations included in the first transaction; in response to the target data being occupied by the second transaction, and the operation included in the first transaction to process the target data is a read operation, the target data is updated according to the second transaction.
  • the occupation type and the first transaction include operations that read the target data.
  • the execution module 802 is configured to determine the occupation type of the target data by the second transaction; in response to the occupation type indication, during the process of the second transaction occupying the target data, prohibit other transactions except the second transaction.
  • the included operations update and read the target data.
  • the operations included in the first transaction are executed to read the target data according to the isolation level of the first transaction.
  • the isolation level of the first transaction is used A read rule corresponding to an operation of reading target data included in the first transaction.
  • the operation of processing the target data included in the first transaction is an update operation.
  • the execution module 802 is used to set instruction information of the target data.
  • the instruction information includes the transaction number and occupation type of the first transaction. The type indicates that during the process of executing the operations included in the first transaction to update the target data, it is prohibited to execute the operations of reading or updating the target data included in other transactions; the operations included in the first transaction are executed to update the target data.
  • the operation of processing the target data included in the first transaction is a read operation
  • the isolation level of the first transaction is serializable
  • the execution module 802 is used to set the instruction information of the target data, indicating
  • the information includes the indication information including the transaction number and occupancy type of the first transaction.
  • the occupancy type indicates that during the process of executing the operations included in the first transaction to read the target data, it is prohibited to perform the operations of updating the target data included in other transactions; executing the first A transaction includes operations to read target data.
  • the first transaction includes multiple operations, each operation is directed to the corresponding target data, the first target data included in the multiple target data is occupied by the second transaction, and the multiple operations are arranged in execution order.
  • the execution module 802 is configured to respond to completing the submission of the processing result of the second transaction within the first time interval, and after the processing result of the second transaction is submitted, execute the first step of processing the first target data included in the first transaction.
  • Operation execute the operations included in the first transaction whose execution sequence is after the first operation; in response to the submission of the processing result of the second transaction not being completed within the first time interval, re-execute the first transaction after the first time interval
  • the operations included in the execution order are before the first operation; in response to completion of execution of the first operation, the first transaction includes the operations in the execution order after the first operation.
  • the isolation type of the first transaction is snapshot isolation
  • the operation included in the first transaction is to read the target version data corresponding to the target timestamp among the target data of multiple time versions, and the execution module 802, Data used to determine multiple differential versions of the target data.
  • the multiple differential versions include the differential version corresponding to the target timestamp and the differential version formed before the time corresponding to the target timestamp.
  • the differential version refers to the update operation pair included in any transaction.
  • the updated content of the target data merge the basic version of the target data and the data of multiple differential versions to obtain the target version data corresponding to the target timestamp in the target data of multiple data versions.
  • the device further includes:
  • the merging module is used to regularly merge the basic version of the target data and the differential version of the target data based on the merging time interval to obtain merged data.
  • the merged data is used to update the basic version of the target data.
  • the transaction processing device is used to execute the above transaction processing method without requiring system calls to control parallel transactions to process the same data, and can frequently fall into the operating system kernel state, thereby improving transaction processing efficiency and system throughput.
  • the application of differential version data reduces the storage space occupied by data and improves the efficiency of data update.
  • Embodiments of the present application provide a computer-readable storage medium in which at least one program code or instruction is stored.
  • the program code or instruction is loaded and executed by a processor, so that the computer implements the steps as described in the method embodiments. any of the transaction processing methods described above.
  • the above computer-readable storage medium may be read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), read-only compact disc (Compact Disc Read-Only Memory, CD-ROM) ), tapes, floppy disks and optical data storage devices, etc.
  • a computer program or computer program product is also provided. At least one computer instruction is stored in the computer program or computer program product, and the at least one computer instruction is loaded and executed by the processor, so that the computer implements Any of the above transaction processing methods.
  • FIG. 9 is a schematic structural diagram of an electronic device provided by an embodiment of the present application.
  • the electronic device 900 may vary greatly due to different configurations or performance, and may include one or more processors (Central Processing Units, CPUs) 901 and one or more memories 902, wherein at least one program instruction is stored in the one or more memories 902, and the at least one program instruction is loaded and executed by the one or more processors 901 to implement each of the above method embodiments.
  • the electronic device 900 may also have components such as wired or wireless network interfaces, keyboards, and input and output interfaces for input and output.
  • the electronic device 900 may also include other components for realizing device functions, which will not be described again here.
  • the information including but not limited to user equipment information, user personal information, etc.
  • data including but not limited to data used for analysis, stored data, displayed data, etc.
  • signals involved in this application are all It is authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data need to comply with the relevant laws, regulations and standards of the relevant countries and regions. For example, the acquisition of target data involved in this application was obtained with full authorization.
  • the size of the sequence number of each process does not mean the order of execution.
  • the execution order of each process should be determined by its function and internal logic, and should not be used in the implementation of the embodiments of the present application.
  • the process constitutes any limitation.
  • determining B based on A does not mean determining B only based on A, and B can also be determined based on A and/or other information.
  • references throughout this specification to "one embodiment,” “an embodiment,” and “a possible implementation” mean that specific features, structures, or characteristics related to the embodiment or implementation are included herein. In at least one embodiment of the application. Therefore, “in one embodiment” or “in an embodiment” or “a possible implementation” appearing in various places throughout this specification do not necessarily refer to the same embodiment. Furthermore, the particular features, structures or characteristics may be combined in any suitable manner in one or more embodiments.

Abstract

Provided in the embodiments of the present application are a transaction processing method and apparatus, and an electronic device. The method comprises: detecting whether target data, which a first transaction targets, is occupied by a second transaction, wherein the first transaction comprises an operation for processing the target data, and the second transaction is another transaction, which is in parallel with the first transaction; and in response to the target data being occupied by the second transaction and according to the type of occupation of the target data by the second transaction and the type of the operation that is comprised in the first transaction and is used for processing the target data, executing the operation comprised in the first transaction, so as to process the target data. By means of the embodiments of the present application, system calling is not required to control parallel first and second transactions with regard to a scenario in which the same target data is processed, thereby avoiding frequent involvement in a kernel mode of an operating system, improving the transaction processing efficiency, and increasing the throughput of the system.

Description

事务处理方法、装置及电子设备Transaction processing methods, devices and electronic equipment
本申请要求于2022年05月07日提交的申请号为202210495253.5、发明名称为“事务处理方法、装置及电子设备”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims priority to the Chinese patent application with application number 202210495253.5 and the invention name "Transaction Processing Method, Device and Electronic Equipment" submitted on May 7, 2022, the entire content of which is incorporated into this application by reference.
技术领域Technical field
本申请涉及数据库技术领域,尤其涉及一种事务处理方法、装置及电子设备。The present application relates to the field of database technology, and in particular, to a transaction processing method, device and electronic equipment.
背景技术Background technique
事务是指访问数据库并可能更新数据库中各种数据的一个程序执行单元,一个事务包括对至少一个数据进行处理的至少一个操作。在数据库技术领域中,存在事务处理方法,该方法基于数据库中的数据执行各个事务所包括的操作。A transaction refers to a program execution unit that accesses the database and may update various data in the database. A transaction includes at least one operation that processes at least one piece of data. In the field of database technology, there are transaction processing methods that perform operations included in each transaction based on data in the database.
相关技术中,基于数据库中的数据进行多个事务并行处理时,需要通过同步机制对正在被处理的数据进行限定,以保证任一数据在同一时间仅被一个事务中的操作所处理。该过程基于系统调用进行,需要通过频繁访问在内核态运行的程序的接口才能够访问到相应的数据,该过程涉及了大量的指令调用过程,影响了事务处理效率和系统吞吐量;且在任一事务需要访问处理的数据被其他事务占用时,该事务易出现无限期等待的情况,事务处理时间长,导致事务处理效率低。In related technologies, when multiple transactions are processed in parallel based on data in a database, the data being processed needs to be limited through a synchronization mechanism to ensure that any data is only processed by operations in one transaction at the same time. This process is based on system calls and requires frequent access to the interface of the program running in the kernel mode to access the corresponding data. This process involves a large number of instruction calling processes, which affects transaction processing efficiency and system throughput; and at any time When the data that a transaction needs to access and process is occupied by other transactions, the transaction is prone to wait indefinitely, and the transaction processing time is long, resulting in low transaction processing efficiency.
发明内容Contents of the invention
本申请实施例提供了一种事务处理方法、装置及电子设备,以实现对事务处理过程的高效管理。Embodiments of the present application provide a transaction processing method, device and electronic equipment to achieve efficient management of the transaction processing process.
一方面,提供了一种事务处理管理方法,该方法包括:On the one hand, a transaction processing management method is provided, which method includes:
检测第一事务针对的目标数据是否被第二事务所占用,所述第一事务包括处理所述目标数据的操作,所述第二事务是与所述第一事务并行的其他事务;Detect whether the target data targeted by the first transaction is occupied by a second transaction, the first transaction includes an operation of processing the target data, and the second transaction is another transaction in parallel with the first transaction;
响应于所述目标数据被所述第二事务所占用,根据所述第二事务对所述目标数据的占用类型和所述第一事务包括的处理所述目标数据的操作的类型,执行所述第一事务包括的操作以处理所述目标数据。In response to the target data being occupied by the second transaction, according to the occupation type of the target data by the second transaction and the type of operation of processing the target data included in the first transaction, executing the The first transaction includes operations to process the target data.
在一种可能的实现方式中,所述检测第一事务针对的目标数据是否被第二 事务所占用,包括:In a possible implementation, detecting whether the target data targeted by the first transaction is occupied by the second transaction includes:
读取所述目标数据携带的指示信息,所述指示信息包括占用所述目标数据的事务的事务编号;基于所述指示信息包括的事务编号为所述第二事务的事务编号,则确定所述目标数据被所述第二事务所占用。Read the instruction information carried by the target data, where the instruction information includes the transaction number of the transaction that occupies the target data; based on the fact that the transaction number included in the instruction information is the transaction number of the second transaction, determine that the The target data is occupied by the second transaction.
在一种可能的实现方式中,其特征在于,所述响应于所述目标数据被所述第二事务所占用,根据所述第二事务对所述目标数据的占用类型和所述第一事务包括的处理所述目标数据的操作的类型,执行所述第一事务包括的操作以处理所述目标数据,包括:In a possible implementation, it is characterized in that, in response to the target data being occupied by the second transaction, according to the occupation type of the target data by the second transaction and the first transaction The types of operations included in processing the target data, and performing the operations included in the first transaction to process the target data include:
响应于所述目标数据被所述第二事务所占用,且所述第一事务包括的处理所述目标数据的操作为更新操作,则在所述第二事务的处理结果被提交后,根据所述第一事务包括的操作更新所述目标数据;In response to the target data being occupied by the second transaction, and the operation of processing the target data included in the first transaction being an update operation, after the processing result of the second transaction is submitted, according to the The operation included in the first transaction updates the target data;
响应于所述目标数据被所述第二事务所占用,且所述第一事务包括的处理所述目标数据的操作为读取操作,则根据所述第二事务对所述目标数据的占用类型和所述第一事务包括的操作读取所述目标数据。In response to the target data being occupied by the second transaction, and the operation of processing the target data included in the first transaction being a read operation, then according to the occupation type of the target data by the second transaction and the first transaction includes an operation of reading the target data.
在一种可能的实现方式中,所述根据所述第二事务对所述目标数据的占用类型和所述第一事务包括的操作读取所述目标数据,包括:In a possible implementation, reading the target data according to the occupation type of the target data by the second transaction and the operations included in the first transaction includes:
确定所述第二事务对所述目标数据的占用类型;Determine the occupation type of the target data by the second transaction;
响应于所述占用类型指示在所述第二事务占用所述目标数据过程中,禁止除所述第二事务外的其他事务所包括的操作更新和读取所述目标数据,则在所述第二事务的处理结果被提交后,根据所述第一事务的隔离等级执行所述第一事务包括的操作以读取所述目标数据,所述第一事务的隔离等级用于指示所述第一事务包括的读取所述目标数据的操作对应的读取规则。In response to the occupation type indicating that during the process of the second transaction occupying the target data, operations included in other transactions except the second transaction are prohibited from updating and reading the target data, then in the process of the second transaction occupying the target data, After the processing results of the second transaction are submitted, operations included in the first transaction are executed to read the target data according to the isolation level of the first transaction, which is used to indicate the first transaction. The transaction includes read rules corresponding to the operation of reading the target data.
在一种可能的实现方式中,所述第一事务包括的处理所述目标数据的操作为更新操作,所述执行所述第一事务包括的操作以处理所述目标数据,包括:In a possible implementation, the operation included in the first transaction to process the target data is an update operation, and the execution of the operation included in the first transaction to process the target data includes:
设置所述目标数据的指示信息,所述指示信息包括所述第一事务的事务编号和占用类型,所述占用类型指示在执行所述第一事务包括的操作以更新所述目标数据的过程中,禁止执行其他事务包括的读取或更新所述目标数据的操作;执行所述第一事务包括的操作以更新所述目标数据。Set the instruction information of the target data, the instruction information includes the transaction number and the occupation type of the first transaction, the occupation type indicates that in the process of executing the operation included in the first transaction to update the target data , prohibiting execution of operations included in other transactions to read or update the target data; execution of operations included in the first transaction to update the target data.
在一种可能的实现方式中,所述第一事务包括的处理所述目标数据的操作为读取操作,所述第一事务的隔离等级为可串行化,所述根据所述第一事务的隔离等级执行所述第一事务包括的操作以读取所述目标数据,包括:In a possible implementation, the operation of processing the target data included in the first transaction is a read operation, the isolation level of the first transaction is serializable, and the operation according to the first transaction The isolation level of performing the operations included in the first transaction to read the target data includes:
设置所述目标数据的指示信息,所述指示信息包括所述指示信息包括所述第一事务的事务编号和占用类型,所述占用类型指示执行所述第一事务包括的 操作以读取所述目标数据的过程中,禁止执行其他事务所包括的更新所述目标数据的操作;执行所述第一事务包括的操作以读取所述目标数据。Set the instruction information of the target data, the instruction information includes the transaction number and the occupation type of the first transaction, the occupation type indicates performing the operation included in the first transaction to read the During the process of obtaining the target data, it is prohibited to execute operations included in other transactions to update the target data; execute operations included in the first transaction to read the target data.
在一种可能的实现方式中,所述第一事务包括多个操作,每个操作分别针对相应的目标数据,多个目标数据包括的第一目标数据被所述第二事务占用,所述多个操作按执行顺序排列,所述执行所述第一事务包括的操作以处理所述目标数据,包括:In a possible implementation, the first transaction includes multiple operations, each operation is directed to corresponding target data, the first target data included in the multiple target data is occupied by the second transaction, and the multiple target data is occupied by the second transaction. The operations are arranged in order of execution, and the operations included in executing the first transaction to process the target data include:
响应于在第一时间间隔内完成所述第二事务的处理结果的提交,在所述第二事务的处理结果被提交后,执行所述第一事务包括的处理所述第一目标数据的第一操作,执行所述第一事务包括的执行顺序在所述第一操作之后的操作;In response to completing the submission of the processing result of the second transaction within the first time interval, after the processing result of the second transaction is submitted, executing the first step of processing the first target data included in the first transaction. An operation to perform operations included in the first transaction whose execution order is after the first operation;
响应于在所述第一时间间隔内未完成所述第二事务的处理结果的提交,则在所述第一时间间隔后,重新执行所述第一事务包括的执行顺序在第一操作之前的操作;响应于所述第一操作执行完成,执行所述第一事务包括的执行顺序在所述第一操作之后的操作。In response to the submission of the processing result of the second transaction not being completed within the first time interval, after the first time interval, re-execute the first transaction including an execution sequence before the first operation. Operation: In response to completion of execution of the first operation, execute operations included in the first transaction in an execution sequence after the first operation.
在一种可能的实现方式中,所述第一事务的隔离类型为快照隔离,所述第一事务包括的操作为读取多个时间版本的目标数据中与目标时间戳对应的目标版本数据,所述执行所述第一事务包括的操作以处理所述目标数据,包括:In a possible implementation, the isolation type of the first transaction is snapshot isolation, and the operation included in the first transaction is to read the target version data corresponding to the target timestamp among the target data of multiple time versions, The operations included in executing the first transaction to process the target data include:
确定所述目标数据的多个差分版本的数据,所述多个差分版本包括所述目标时间戳对应的差分版本以及在所述目标时间戳对应的时间之前形成的差分版本,所述差分版本指任一事务包括的更新操作对所述目标数据进行更新的内容;合并所述目标数据的基础版本与所述多个差分版本的数据,得到所述多个数据版本的目标数据中与所述目标时间戳对应的目标版本数据。Determine the data of multiple differential versions of the target data. The multiple differential versions include the differential version corresponding to the target timestamp and the differential version formed before the time corresponding to the target timestamp. The differential version refers to The update operation included in any transaction updates the content of the target data; merge the basic version of the target data and the data of the multiple differential versions to obtain the target data of the multiple data versions that is consistent with the target The target version data corresponding to the timestamp.
在一种可能的实现方式中,所述方法还包括:In a possible implementation, the method further includes:
基于合并时间间隔,定期对所述目标数据的基础版本与所述目标数据的差分版本的数据进行合并,得到合并后的数据,所述合并后的数据用于更新所述目标数据的基础版本。Based on the merging time interval, the base version of the target data and the differential version of the target data are merged regularly to obtain merged data, and the merged data is used to update the base version of the target data.
一方面,提供了一种事务处理装置,该装置包括:On the one hand, a transaction processing device is provided, which device includes:
检测模块,用于检测第一事务针对的目标数据是否被第二事务所占用,所述第一事务包括处理所述目标数据的操作,所述第二事务是与所述第一事务并行的其他事务;A detection module, configured to detect whether the target data targeted by the first transaction is occupied by a second transaction, the first transaction includes an operation of processing the target data, and the second transaction is other parallel transactions with the first transaction. affairs;
执行模块,用于响应于所述目标数据被所述第二事务所占用,根据所述第二事务对所述目标数据的占用类型和所述第一事务包括的处理所述目标数据的操作的类型,执行所述第一事务包括的操作以处理所述目标数据。Execution module, configured to respond to the target data being occupied by the second transaction, and perform an operation based on the occupation type of the target data by the second transaction and the operation of processing the target data included in the first transaction. Type, perform operations included in the first transaction to process the target data.
在一种可能的实现方式中,所述检测模块,用于读取所述目标数据携带的 指示信息,所述指示信息包括占用所述目标数据的事务的事务编号;基于所述指示信息包括的事务编号为所述第二事务的事务编号,则确定所述目标数据被所述第二事务所占用。In a possible implementation, the detection module is configured to read the indication information carried by the target data, the indication information including the transaction number of the transaction occupying the target data; based on the indication information included If the transaction number is the transaction number of the second transaction, it is determined that the target data is occupied by the second transaction.
在一种可能的实现方式中,所述执行模块,用于响应于所述目标数据被所述第二事务所占用,且所述第一事务包括的处理所述目标数据的操作为更新操作,则在所述第二事务的处理结果被提交后,根据所述第一事务包括的操作更新所述目标数据;响应于所述目标数据被所述第二事务所占用,且所述第一事务包括的处理所述目标数据的操作为读取操作,则根据所述第二事务对所述目标数据的占用类型和所述第一事务包括的操作读取所述目标数据。In a possible implementation, the execution module is configured to respond to the target data being occupied by the second transaction, and the operation of processing the target data included in the first transaction is an update operation, Then after the processing result of the second transaction is submitted, the target data is updated according to the operations included in the first transaction; in response to the target data being occupied by the second transaction, and the first transaction If the included operation of processing the target data is a read operation, then the target data is read according to the occupation type of the target data by the second transaction and the operation included in the first transaction.
在一种可能的实现方式中,所述执行模块,用于确定所述第二事务对所述目标数据的占用类型;响应于所述占用类型指示在所述第二事务占用所述目标数据过程中,禁止除所述第二事务外的其他事务所包括的操作更新和读取所述目标数据,则在所述第二事务的处理结果被提交后,根据所述第一事务的隔离等级执行所述第一事务包括的操作以读取所述目标数据,所述第一事务的隔离等级用于指示所述第一事务包括的读取所述目标数据的操作对应的读取规则。In a possible implementation, the execution module is configured to determine the occupation type of the target data by the second transaction; in response to the occupation type indication, the process of occupying the target data by the second transaction , operations included in other transactions except the second transaction are prohibited from updating and reading the target data, then after the processing result of the second transaction is submitted, execution is performed according to the isolation level of the first transaction The first transaction includes an operation to read the target data, and the isolation level of the first transaction is used to indicate a read rule corresponding to the operation included in the first transaction to read the target data.
在一种可能的实现方式中,所述第一事务包括的处理所述目标数据的操作为更新操作,所述执行模块,用于设置所述目标数据的指示信息,所述指示信息包括所述第一事务的事务编号和占用类型,所述占用类型指示在执行所述第一事务包括的操作以更新所述目标数据的过程中,禁止执行其他事务包括的读取或更新所述目标数据的操作;执行所述第一事务包括的操作以更新所述目标数据。In a possible implementation, the operation of processing the target data included in the first transaction is an update operation, and the execution module is configured to set instruction information of the target data, and the instruction information includes the The transaction number and occupancy type of the first transaction, the occupancy type indicates that in the process of executing the operations included in the first transaction to update the target data, it is prohibited to perform other transactions including reading or updating the target data. Operation: perform operations included in the first transaction to update the target data.
在一种可能的实现方式中,所述第一事务包括的处理所述目标数据的操作为读取操作,所述第一事务的隔离等级为可串行化,所述执行模块,用于设置所述目标数据的指示信息,所述指示信息包括所述指示信息包括所述第一事务的事务编号和占用类型,所述占用类型指示执行所述第一事务包括的操作以读取所述目标数据的过程中,禁止执行其他事务所包括的更新所述目标数据的操作;执行所述第一事务包括的操作以读取所述目标数据。In a possible implementation, the operation of processing the target data included in the first transaction is a read operation, the isolation level of the first transaction is serializable, and the execution module is used to set Instruction information of the target data, the instruction information includes the transaction number and occupation type of the first transaction, and the occupation type indicates performing operations included in the first transaction to read the target During the process of data processing, it is prohibited to perform operations included in other transactions to update the target data; perform operations included in the first transaction to read the target data.
在一种可能的实现方式中,所述第一事务包括多个操作,每个操作分别针对相应的目标数据,多个目标数据包括的第一目标数据被所述第二事务占用,所述多个操作按执行顺序排列,所述执行模块,用于响应于在第一时间间隔内完成所述第二事务的处理结果的提交,在所述第二事务的处理结果被提交后,执行所述第一事务包括的处理所述第一目标数据的第一操作,执行所述第一事务包括的执行顺序在所述第一操作之后的操作;响应于在所述第一时间间隔内 未完成所述第二事务的处理结果的提交,则在所述第一时间间隔后,重新执行所述第一事务包括的执行顺序在第一操作之前的操作;响应于所述第一操作执行完成,执行所述第一事务包括的执行顺序在所述第一操作之后的操作。In a possible implementation, the first transaction includes multiple operations, each operation is directed to corresponding target data, the first target data included in the multiple target data is occupied by the second transaction, and the multiple target data is occupied by the second transaction. The operations are arranged in execution order, and the execution module is configured to respond to completing the submission of the processing result of the second transaction within the first time interval, and after the processing result of the second transaction is submitted, execute the The first transaction includes a first operation of processing the first target data, and the execution sequence of the first transaction includes operations after the first operation; in response to not completing all the operations within the first time interval. Submit the processing result of the second transaction, then after the first time interval, re-execute the operation included in the first transaction whose execution sequence is before the first operation; in response to the completion of the execution of the first operation, execute The first transaction includes operations whose execution sequence is subsequent to the first operation.
在一种可能的实现方式中,所述第一事务的隔离类型为快照隔离,所述第一事务包括的操作为读取多个时间版本的目标数据中与目标时间戳对应的目标版本数据,所述执行模块,用于确定所述目标数据的多个差分版本的数据,所述多个差分版本包括所述目标时间戳对应的差分版本以及在所述目标时间戳对应的时间之前形成的差分版本,所述差分版本指任一事务包括的更新操作对所述目标数据进行更新的内容;合并所述目标数据的基础版本与所述多个差分版本的数据,得到所述多个数据版本的目标数据中与所述目标时间戳对应的目标版本数据。In a possible implementation, the isolation type of the first transaction is snapshot isolation, and the operation included in the first transaction is to read the target version data corresponding to the target timestamp among the target data of multiple time versions, The execution module is used to determine data of multiple differential versions of the target data. The multiple differential versions include the differential version corresponding to the target timestamp and the differential formed before the time corresponding to the target timestamp. Version, the differential version refers to the content of the update operation of the target data included in any transaction; merge the basic version of the target data and the data of the multiple differential versions to obtain the multiple data versions The target version data corresponding to the target timestamp in the target data.
在一种可能的实现方式中,所述装置还包括:In a possible implementation, the device further includes:
合并模块,用于基于合并时间间隔,定期对所述目标数据的基础版本与所述目标数据的差分版本的数据进行合并,得到合并后的数据,所述合并后的数据用于更新所述目标数据的基础版本。A merging module, configured to regularly merge the basic version of the target data and the differential version of the target data based on the merging time interval to obtain merged data, and the merged data is used to update the target The base version of the data.
另一方面,提供了一种电子设备,该电子设备包括处理器和存储器,该存储器中存储有至少一条程序代码或指令,该至少一条程序代码或指令由处理器加载并执行,以使电子设备实现上述任一的事务处理方法。On the other hand, an electronic device is provided. The electronic device includes a processor and a memory. At least one program code or instruction is stored in the memory. The at least one program code or instruction is loaded and executed by the processor, so that the electronic device Implement any of the above transaction processing methods.
另一方面,提供了一种计算机可读存储介质,该计算机可读存储介质中存储有至少一条程序代码或指令,该程序代码由处理器加载并执行,以使计算机实现上述任一项事务处理方法。On the other hand, a computer-readable storage medium is provided. At least one program code or instruction is stored in the computer-readable storage medium. The program code is loaded and executed by the processor to enable the computer to implement any of the above transaction processes. method.
另一方面,提供了一种计算机程序或计算机程序产品,该计算机程序或计算机程序产品中存储有至少一条计算机指令,该至少一条计算机指令由处理器加载并执行,以使计算机实现上述任一项事务处理方法。On the other hand, a computer program or computer program product is provided. At least one computer instruction is stored in the computer program or computer program product. The at least one computer instruction is loaded and executed by the processor to enable the computer to implement any of the above. Transaction processing methods.
本申请实施例提供的技术方案,通过检测目标数据被与第一事务并行的第二事务的占用情况,基于第二事务对目标数据的占用类型和第一事务包括的操作对目标数据进行处理,该过程基于对目标数据的检测实现并行事务的处理,无需系统调用对并行的第一事务和第二事务针对同一目标数据进行处理的场景进行控制,避免了频发陷入操作系统内核态,提高了事务处理效率,提高了系统的吞吐量。The technical solution provided by the embodiment of the present application detects the occupation of the target data by a second transaction that is parallel to the first transaction, and processes the target data based on the occupation type of the target data by the second transaction and the operations included in the first transaction. This process realizes the processing of parallel transactions based on the detection of target data. There is no need for system calls to control the scenario where the parallel first transaction and the second transaction are processed for the same target data. This avoids frequent falling into the operating system kernel state and improves efficiency. Transaction processing efficiency improves system throughput.
附图说明Description of the drawings
图1为本申请实施例提供的一种实施环境的示意图;Figure 1 is a schematic diagram of an implementation environment provided by an embodiment of the present application;
图2为本申请实施例提供的一种事务处理的流程图;Figure 2 is a flow chart of transaction processing provided by an embodiment of the present application;
图3为本申请实施例提供的一种数据存储示意图;Figure 3 is a schematic diagram of data storage provided by an embodiment of the present application;
图4为本申请实施例提供的一种服务器的结构示意图;Figure 4 is a schematic structural diagram of a server provided by an embodiment of the present application;
图5为本申请实施例提供的一种在线事务处理界面示意图;Figure 5 is a schematic diagram of an online transaction processing interface provided by an embodiment of the present application;
图6为本申请实施例提供的一种命令行事务处理界面示意图;Figure 6 is a schematic diagram of a command line transaction processing interface provided by an embodiment of the present application;
图7为本申请实施例提供的一种接口事务处理界面示意图;Figure 7 is a schematic diagram of an interface transaction processing interface provided by an embodiment of the present application;
图8为本申请实施例提供的一种事务处理装置的示意图;Figure 8 is a schematic diagram of a transaction processing device provided by an embodiment of the present application;
图9为本申请实施例提供的一种电子设备的示意图。FIG. 9 is a schematic diagram of an electronic device provided by an embodiment of the present application.
具体实施方式Detailed ways
为了使本领域的人员更好地理解本申请中的技术方法,下面将结合附图对本申请部分实施例进行描述。应理解地,除非另有定义,本申请实施例中使用的所有技术用语均与本领域技术人员通常理解的含义相同,且仅用于对本申请实施例进行解释,而非旨在限定本申请。In order to enable those in the art to better understand the technical methods in this application, some embodiments of this application will be described below in conjunction with the accompanying drawings. It should be understood that, unless otherwise defined, all technical terms used in the embodiments of the present application have the same meanings as commonly understood by those skilled in the art, and are only used to explain the embodiments of the present application and are not intended to limit the present application.
参见图1,本申请实施例的实施环境包括终端11和服务器12。终端11和服务器12可以进行通信连接以实现信息的交互传输,本申请实施例对终端11和服务器12的连接方式不作限定。在本申请实施例中,终端11向服务器12提交事务的启动请求,服务器12执行该事务中包括的操作处理该事务针对的数据,然后将处理结果发送给终端11。此外,终端11还发送交互过程中产生的指令至服务器12。Referring to Figure 1, the implementation environment of the embodiment of the present application includes a terminal 11 and a server 12. The terminal 11 and the server 12 can communicate and connect to realize interactive transmission of information. The embodiment of the present application does not limit the connection method between the terminal 11 and the server 12 . In this embodiment of the present application, the terminal 11 submits a transaction startup request to the server 12. The server 12 executes the operations included in the transaction to process the data targeted by the transaction, and then sends the processing results to the terminal 11. In addition, the terminal 11 also sends instructions generated during the interaction to the server 12 .
该终端11可以是任何一种可以与用户通过键盘、触摸板、触摸屏、语音交互等一种或多种方式进行人机交互的电子产品,例如PC(Personal Computer,个人计算机)、手机、PPC(Pocket Personal Computer,掌上电脑)、平板电脑、车机等。服务器12可以是一台服务器,也可以是由多台服务器组成的服务器集群,还可以是提供云服务、云数据库、云计算、云函数、云存储、网络服务、云通信、中间件服务、域名服务、安全服务、CDN(Content Delivery Network,内容分发网络)、以及大数据和人工智能平台等基础云计算服务的云服务器。The terminal 11 can be any electronic product that can perform human-computer interaction with the user through one or more methods such as keyboard, touch panel, touch screen, voice interaction, etc., such as PC (Personal Computer), mobile phone, PPC ( Pocket Personal Computer, tablet computer, car machine, etc. The server 12 may be one server or a server cluster composed of multiple servers, or may provide cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, and domain names. Services, security services, CDN (Content Delivery Network, content distribution network), and cloud servers for basic cloud computing services such as big data and artificial intelligence platforms.
本领域技术人员应该能理解上述终端11和服务器12仅为举例,其他现有的或今后可能出现的终端或者服务器如可使用于本申请,也应包含在本申请的保护范围以内,并在此以引用方式包含于此。Those skilled in the art should understand that the above-mentioned terminal 11 and server 12 are only examples. If other existing or possible terminals or servers that may appear in the future can be used in this application, they should also be included in the protection scope of this application. Incorporated herein by reference.
本申请实施例应用于数据库技术领域,适用于基于各事务中的操作对数据进行管理的场景。示例性的,本申请的事务处理方法能够应用于资源描述框架 (RDF)中,基于RDF数据库包括的大量的RDF数据进行事务处理。当前的RDF数据库的事务处理能力弱,事务处理功能少,本申请提供的事务处理方法能够实现完成高效的事务处理。事务是指访问并可能更新数据库中各种数据的一个程序执行单元,一个事务包括对至少一个数据进行处理的至少一个操作。The embodiments of this application are applied in the field of database technology and are suitable for scenarios in which data is managed based on operations in each transaction. For example, the transaction processing method of this application can be applied in the Resource Description Framework (RDF) to perform transaction processing based on a large amount of RDF data included in the RDF database. The current RDF database has weak transaction processing capabilities and few transaction processing functions. The transaction processing method provided by this application can achieve efficient transaction processing. A transaction refers to a program execution unit that accesses and possibly updates various data in the database. A transaction includes at least one operation that processes at least one piece of data.
数据库事务需要满足四种特性:原子性(Atomicity)、一致性(Consistency)、隔离性(Isolation)以及持久性(Durability)。Database transactions need to meet four characteristics: atomicity (Atomicity), consistency (Consistency), isolation (Isolation) and durability (Durability).
原子性:事务是一个不可分割的整体,事务包括的所有操作,仅存在全部完成或者全部不执行的情况,不会出现执行部分操作的情况。对数据执行操作过程中出现异常,数据恢复到事务开始前的状态,该过程可以称为回滚。Atomicity: A transaction is an indivisible whole. All operations included in a transaction can only be completed or not executed at all. Partial operations will not be executed. An exception occurs during the operation on the data, and the data is restored to the state before the transaction started. This process can be called rollback.
一致性:事务开始前和结束后,数据库的完整性约束没有被破坏,数据库中数据的完整性保持一致。例如:用户A账户余额1000元,用户B账户余额2900元,运行用户A向用户B转账100元的事务,转账完成后,用户A账户余额为900,用户B账户余额为3000。转账前后,用户A、B账户余额的加和不变,为3900元。Consistency: Before and after the transaction starts and ends, the integrity constraints of the database are not violated, and the integrity of the data in the database remains consistent. For example: User A's account balance is 1,000 yuan, User B's account balance is 2,900 yuan, and user A transfers 100 yuan to user B. After the transfer is completed, user A's account balance is 900, and user B's account balance is 3,000. Before and after the transfer, the sum of the balances of users A and B's accounts remains unchanged at 3,900 yuan.
隔离性:指同一时间,只允许执行一个事务中的操作处理同一数据,不同的事务之间彼此没有任何干扰。示例性的,针对同一数据,用户A和B分别开启事务1和事务2,事务1和事务2并行执行。因此,事务1与事务2要相互隔离。针对事务1,事务2包括的操作不能干扰事务1的执行,用户A感受不到有事务2与事务1并行执行。Isolation: means that only operations in one transaction are allowed to process the same data at the same time, and there is no interference between different transactions. For example, for the same data, users A and B start transaction 1 and transaction 2 respectively, and transaction 1 and transaction 2 are executed in parallel. Therefore, transaction 1 and transaction 2 should be isolated from each other. For transaction 1, the operations included in transaction 2 cannot interfere with the execution of transaction 1, and user A cannot feel that transaction 2 is executed in parallel with transaction 1.
持久性:事务完成后,事务中的操作对数据库中数据的所有更新将被持久性地保存到数据库。事务成功完成后,即使发生硬件故障或者数据库崩溃,写入的数据也不会丢失。Durability: After the transaction is completed, all updates to the data in the database by operations in the transaction will be persisted to the database. After a transaction completes successfully, even if a hardware failure or database crash occurs, the written data will not be lost.
参见附图2,本申请实施例提供了一种事务处理方法的流程图。该方法可以应用于服务器。该方法包括但不限于下述步骤201-202。Referring to Figure 2, an embodiment of the present application provides a flow chart of a transaction processing method. This method can be applied to the server. The method includes but is not limited to the following steps 201-202.
步骤201,检测第一事务针对的目标数据是否被第二事务所占用,该第一事务包括处理目标数据的操作,第二事务是与第一事务并行的其他事务。Step 201: Detect whether the target data targeted by the first transaction is occupied by a second transaction. The first transaction includes an operation of processing the target data. The second transaction is another transaction in parallel with the first transaction.
当用户开启第一事务时,系统中可能存在其他用户开启的与当前的第一事务并行的第二事务。在多个事务并行处理的过程中,容易存在不同的事务包括的操作针对相同的数据进行更新或者读取的情况。为保证事务处理结果的准确,一些可能的实现方式中,不同事务所包括的操作不能同时对同一目标数据进行处理,因而,在任一事务包括的操作要对目标数据进行处理时,应当判断该目标数据是否被其他事务占用,然后确定直接执行该任一事务包括的操作,还是 等待占用该目标数据的其他事务结束后执行该事务包括的操作。When a user starts a first transaction, there may be a second transaction started by other users in the system that is parallel to the current first transaction. In the process of parallel processing of multiple transactions, it is easy for the operations included in different transactions to update or read the same data. In order to ensure the accuracy of transaction processing results, in some possible implementations, operations included in different transactions cannot process the same target data at the same time. Therefore, when operations included in any transaction want to process target data, the target should be judged Whether the data is occupied by other transactions, and then determine whether to directly perform the operations included in any transaction, or to wait for the completion of other transactions occupying the target data and then perform the operations included in the transaction.
一种可能的实现方式中,检测第一事务针对的目标数据是否被第二事务所占用,包括:读取目标数据携带的指示信息,该指示信息包括占用该目标数据的事务的事务编号;基于该指示信息包括的事务编号为第二事务的事务编号,确定该目标数据被第二事务所占用。In one possible implementation, detecting whether the target data targeted by the first transaction is occupied by the second transaction includes: reading the indication information carried by the target data, where the indication information includes the transaction number of the transaction that occupies the target data; based on The transaction number included in the indication information is the transaction number of the second transaction, and it is determined that the target data is occupied by the second transaction.
在本申请实施例中,各个事务对应有相应的事务编号,各个事务的事务编号是唯一的。示例性地,事务编号由服务器随机分配,事务编号存储在事务列表中以用于管理。In the embodiment of this application, each transaction corresponds to a corresponding transaction number, and the transaction number of each transaction is unique. Illustratively, transaction numbers are randomly assigned by the server and are stored in a transaction list for management.
在一种可能的实现方式中,在执行步骤201之前,服务器接收终端提交的第一事务的启动请求,服务器基于该第一事务的启动请求开启该第一事务,并为该第一事务分配相应的事务编号。可选的,启动请求的接收和事务编号的分配能够由服务器中的事务调度处理器执行。In a possible implementation, before executing step 201, the server receives a start request for the first transaction submitted by the terminal, the server starts the first transaction based on the start request of the first transaction, and allocates a corresponding response to the first transaction. transaction number. Optionally, the receipt of the start request and the assignment of the transaction number can be performed by a transaction scheduler in the server.
示例性地,事务编号的分配由一个严格递增的原子计数器决定,以保证每个事务的事务编号的唯一性,并且能够基于多个事务的事务编号确定该多个事务开启的相对顺序。示例性地,每个事务的事务编号可以为一个64位的编码。For example, the allocation of transaction numbers is determined by a strictly incrementing atomic counter to ensure the uniqueness of the transaction number of each transaction, and the relative order in which multiple transactions are started can be determined based on the transaction numbers of multiple transactions. For example, the transaction number of each transaction may be a 64-bit code.
在本申请实施例中,开启第一事务,该第一事务包括对目标数据进行读取或者更新的操作,访问该目标数据,读取该目标数据携带的指示信息,若指示信息为空,则该目标数据还没有被其他事务所占用,第一事务包括的操作能够对该目标数据进行处理;若指示信息不为空,则确定指示信息中包括的事务编号,该指示信息包括的事务标号为当前正在占用该目标数据的事务的事务编号。示例性的,当前事务占用目标数据时,执行正在占用该目标数据的当前事务所包括的更新操作,以更新目标数据。示例性的,若该事务编号为第二事务的事务编号,则确定该目标数据被第二事务所占用,第二事务所包括的操作正在处理该目标数据,则执行下述步骤202以实现该第一事务包括的操作对该目标数据的处理。In this embodiment of the present application, the first transaction is started. The first transaction includes the operation of reading or updating the target data, accessing the target data, and reading the indication information carried by the target data. If the indication information is empty, then The target data has not been occupied by other transactions, and the operations included in the first transaction can process the target data; if the indication information is not empty, determine the transaction number included in the indication information, and the transaction number included in the indication information is The transaction number of the transaction currently occupying the target data. For example, when the current transaction occupies the target data, the update operation included in the current transaction that is occupying the target data is performed to update the target data. For example, if the transaction number is the transaction number of the second transaction, it is determined that the target data is occupied by the second transaction, and the operation included in the second transaction is processing the target data, then the following step 202 is performed to implement the The first transaction includes operations on the target data.
在步骤201中,确定第一事务针对的目标数据的方法包括但不限于:基于第一事务的信息确定第一事务针对的目标数据。示例性地,服务器可以通过解析第一事务包括的各操作的指令确定该第一事务的信息;或者通过解析第一事务的启动请求确定第一事务的信息。其中,第一事务包括各操作的指令是用户在终端进行确定并提交的。第一事务的启动请求中携带该事务中的操作要处理的目标数据的信息,例如,该目标数据的信息包括目标数据的存储位置,目标数据对应的时间戳,或者目标数据的版本编号等。In step 201, the method of determining the target data targeted by the first transaction includes, but is not limited to: determining the target data targeted by the first transaction based on the information of the first transaction. For example, the server may determine the information of the first transaction by parsing the instructions of each operation included in the first transaction; or determine the information of the first transaction by parsing the start request of the first transaction. The first transaction includes instructions for each operation that are determined and submitted by the user on the terminal. The start request of the first transaction carries information about the target data to be processed by the operation in the transaction. For example, the information about the target data includes the storage location of the target data, the timestamp corresponding to the target data, or the version number of the target data, etc.
步骤202,响应于目标数据被第二事务所占用,根据该第二事务对目标数据 的占用类型和第一事务包括的处理目标数据的操作的类型,执行第一事务包括的操作以处理目标数据。 Step 202, in response to the target data being occupied by the second transaction, execute the operations included in the first transaction to process the target data according to the occupation type of the target data by the second transaction and the type of operations included in the first transaction to process the target data. .
目标数据被第二事务所占用是指在第二事务所包括的操作对目标数据进行处理的过程中,限制其他事务包括的操作对该目标数据进行处理。不同的占用类型对其他事务包括的操作的限制不同,占用类型对应的限制方式包括但不限于:第一占用类型,用于指示目标数据被第二事务占用过程中,禁止其他事务包括的更新操作对该目标数据进行处理;或者,第二占用类型,用于指示目标数据被第二事务占用过程中,除禁止其他事务包括的更新操作处理目标数据外,还禁止其他事务包括的读取操作对该目标数据进行处理。The fact that the target data is occupied by the second transaction means that during the process of processing the target data by the operations included in the second transaction, operations included in other transactions are restricted from processing the target data. Different occupancy types have different restrictions on operations included in other transactions. The restriction methods corresponding to the occupancy types include but are not limited to: The first occupancy type is used to indicate that update operations included in other transactions are prohibited while the target data is occupied by the second transaction. Process the target data; or, the second occupation type is used to indicate that when the target data is occupied by the second transaction, in addition to prohibiting update operations included in other transactions from processing the target data, it also prohibits read operations included in other transactions from processing the target data. The target data is processed.
在本申请实施例中,任一事务能够包括对目标数据进行处理的操作,该操作的类型包括但不限于对数据的更新或者读取,读取操作包括但不限于获取数据以及获取数据的相关信息;更新操作包括但不限于对数据的添加、修改、删除等。In the embodiment of this application, any transaction can include an operation to process target data. The type of operation includes but is not limited to updating or reading data. The read operation includes but is not limited to obtaining data and obtaining related data. Information; update operations include but are not limited to adding, modifying, deleting, etc. data.
本申请实施例不对数据的存储形式等进行限定。示例性的,数据能够以数值、文字、图片等多种形式进行存储;则更新操作可以包括对任一数值形式的数据进行加减计算。The embodiments of this application do not limit the storage form of data, etc. For example, data can be stored in various forms such as numerical values, text, pictures, etc.; then the update operation can include addition and subtraction calculations for data in any numerical form.
任一事务能够包括一个或者多个操作。事务包括一个操作时,则对一个数据执行相应的操作;事务包括多个操作时,事务中包括的多个操作能够针对相同的数据或者不同的数据进行相应的操作,且数据包括的多个操作具有一定的执行顺序。示例性地,转账操作中,在“用户A向用户B转账X元”的事务中,包括将用户A账户中的存款数值减少X和将用户B账户中的存款数值加上X这两个对不同数据进行更新的操作,且该两个操作的执行顺序是确定的。Any transaction can include one or more operations. When a transaction includes one operation, a corresponding operation is performed on a piece of data; when a transaction includes multiple operations, the multiple operations included in the transaction can perform corresponding operations on the same data or different data, and the data includes multiple operations. Have a certain order of execution. For example, in the transfer operation, the transaction "User A transfers X yuan to User B" includes two pairs: reducing the deposit value in User A's account by X and adding X to the deposit value in User B's account. Update operations are performed on different data, and the execution order of the two operations is determined.
在一种可能的实现方式中,响应于目标数据被第二事务所占用,且第一事务包括的处理该目标数据的操作为更新操作,则在第二事务的处理结果被提交后,根据第一事务包括的操作更新目标数据。In a possible implementation, in response to the target data being occupied by the second transaction, and the operation of processing the target data included in the first transaction is an update operation, after the processing result of the second transaction is submitted, according to the first A transaction consists of operations that update target data.
在一种可能的实现方式中,第一事务包括的处理目标数据的操作为更新操作,则执行第一事务包括的操作以更新目标数据的过程包括:设置目标数据的指示信息,该指示信息包括第一事务的事务编号和占用类型,占用类型指示在执行第一事务包括的操作以更新目标数据的过程中,禁止执行其他事务包括的读取或更新目标数据的操作;执行第一事务包括的操作以更新目标数据。In a possible implementation, the operation of processing the target data included in the first transaction is an update operation, and then the process of executing the operation included in the first transaction to update the target data includes: setting instruction information of the target data, the instruction information includes The transaction number and occupancy type of the first transaction. The occupancy type indicates that during the process of executing the operations included in the first transaction to update the target data, it is prohibited to perform the operations of reading or updating the target data included in other transactions; executing the operations included in the first transaction Operation to update target data.
本申请实施例中,占用任一数据的当前事务不允许其他事务包括的操作对该任一数据进行更新数据,以避免影响该当前事务的最终结果。因而,第二事务占用目标数据的过程中,若第一事务包括操作为更新目标数据,而该目标数 据被并行的第二事务所占用,不论该第二事务包括的操作对目标数据进行读取或者更新操作,均不能够执行第一事务包括的针对目标数据的操作,而需要在第二事务的处理结果被提交后再执行第一事务包括的对目标数据的更新操作。其中,第二事务的处理结果被提交后,第二事务结束,第二事务不再占用目标数据,目标数据的指示信息恢复为空。In the embodiment of this application, the current transaction occupying any data does not allow operations included in other transactions to update any data, so as to avoid affecting the final result of the current transaction. Therefore, during the process of the second transaction occupying the target data, if the first transaction includes an operation to update the target data, and the target data is occupied by a parallel second transaction, regardless of the operation included in the second transaction, the target data is read. Or the update operation cannot perform the operation on the target data included in the first transaction, but it is necessary to perform the update operation on the target data included in the first transaction after the processing result of the second transaction is submitted. After the processing result of the second transaction is submitted, the second transaction ends, the second transaction no longer occupies the target data, and the indication information of the target data returns to empty.
在一种可能的实现方式中,响应于该目标数据被第二事务所占用,且第一事务包括的处理目标数据的操作为读取操作,则根据第二事务对所述目标数据的占用类型和第一事务包括的操作读取目标数据。In a possible implementation, in response to the target data being occupied by the second transaction, and the operation of processing the target data included in the first transaction is a read operation, then according to the occupation type of the target data by the second transaction And the first transaction includes the operation of reading the target data.
第二事务对目标数据的占用类型具有多种形式,不同的占用类型对应不同的限制条件,不同的限制条件对其他事务包括的对目标数据进行处理的操作有不同的规定。因而根据第二事务对目标数据的占用类型执行第一事务中包括的操作以读取目标数据。The occupation types of the target data by the second transaction have various forms. Different occupation types correspond to different restrictions, and different restrictions have different regulations on the operations of processing the target data included in other transactions. Thus, the operations included in the first transaction are performed to read the target data according to the occupation type of the target data by the second transaction.
在一种可能的实现方式中,确定第二事务对目标数据的占用类型;响应于占用类型指示在第二事务占用该目标数据过程中,禁止除第二事务外的其他事务所包括的操作更新和读取该目标数据,则在第二事务的处理结果被提交后,根据第一事务的隔离等级执行第一事务包括的操作以读取该目标数据。In a possible implementation, the occupation type of the target data by the second transaction is determined; in response to the occupation type indication, during the process of the second transaction occupying the target data, operation updates included in other transactions except the second transaction are prohibited. and reading the target data, after the processing result of the second transaction is submitted, the operations included in the first transaction are performed according to the isolation level of the first transaction to read the target data.
可选地,响应于占用类型指示在第二事务占用该目标数据过程中,禁止除第二事务外的其他事务所包括的操作更新该目标数据,则直接根据第一事务的隔离等级执行该第一事务包括的操作以读取该目标数据。Optionally, in response to the occupation type indicating that during the process of the second transaction occupying the target data, operations included in other transactions except the second transaction are prohibited from updating the target data, then the first transaction is directly executed according to the isolation level of the first transaction. A transaction consists of operations to read the target data.
其中,第一事务的隔离等级用于指示第一事务包括的读取该目标数据的操作对应的读取规则。The isolation level of the first transaction is used to indicate the read rule corresponding to the operation of reading the target data included in the first transaction.
本申请实施例包括但不限于读已提交、快照隔离和可串行化这三个隔离等级,事务对应不同的隔离等级时,事务包括的读取操作的执行方式不同,事务包括的操作对读取的数据的指示信息的更新方式不同。The embodiments of this application include but are not limited to three isolation levels: read committed, snapshot isolation, and serializable. When a transaction corresponds to different isolation levels, the read operations included in the transaction are executed in different ways. The operations included in the transaction have different effects on the read operations. The instruction information of the fetched data is updated in different ways.
运行在读已提交这一隔离等级下的事务所包括的读取操作,能够读取已提交了处理结果的事务的更新内容,返回该读取操作所针对的数据所对应的最新版本。运行在读已提交隔离等级下的事务所包括的更新操作,能够更新该更新操作针对的数据对应的指示信息,能够用于设置指示信息包括该事务的事务编号以表示该数据被该事务占用,还用于设置该事务对该数据的占用类型为第二占用类型,以指示在该事务占用该数据过程中,禁止其他事务所包括的操作更新或者读取该数据。此时,第二占用类型指示的该事务占用该数据的过程为执行该事务中包括的更新操作更新该数据的过程。A read operation included in a transaction running under the Read Committed isolation level can read the updated content of the transaction that has submitted the processing result and return the latest version corresponding to the data targeted by the read operation. The update operation included in the transaction running under the read committed isolation level can update the indication information corresponding to the data targeted by the update operation, and can be used to set the indication information to include the transaction number of the transaction to indicate that the data is occupied by the transaction, and can also Used to set the transaction's occupation type of the data to the second occupation type to indicate that operations included in other transactions are prohibited from updating or reading the data while the transaction is occupying the data. At this time, the process in which the transaction occupies the data indicated by the second occupancy type is the process of executing the update operation included in the transaction to update the data.
运行在快照隔离这一隔离等级下的事务所包括的读取操作,能够读取该读 取操作所针对的数据的多个版本中,与时间戳对应的版本。运行在快照隔离下的事务所包括的更新操作,能够更新该更新操作针对的数据对应的指示信息,能够用于设置指示信息包括该事务的事务编号以表示该数据被该事务占用。可选地,该更新操作还用于设置该事务对该数据的占用类型为第二占用类型,以指示在该事务占用该数据过程中,禁止其他事务所包括的操作更新或者读取该数据。此时,第二占用类型指示的该事务占用该数据的过程为执行该事务中包括的更新操作更新该数据的过程。Transactions running under the isolation level of snapshot isolation include read operations that can read multiple versions of the data targeted by the read operation, the version corresponding to the timestamp. The update operation included in the transaction running under snapshot isolation can update the indication information corresponding to the data targeted by the update operation, and can be used to set the indication information to include the transaction number of the transaction to indicate that the data is occupied by the transaction. Optionally, the update operation is also used to set the transaction's occupation type of the data to the second occupation type to indicate that during the process of the transaction occupying the data, operations included in other transactions are prohibited from updating or reading the data. At this time, the process in which the transaction occupies the data indicated by the second occupancy type is the process of executing the update operation included in the transaction to update the data.
运行在可串行化这一隔离等级下的事务所包括的读取操作,能够读取已提交了处理结果的事务的更新内容,返回该读取操作所针对的数据所对应的最新版本。该读取操作能够更新该读取操作针对的数据对应的指示信息,能够用于设置指示信息包括该事务的事务编号以表示该数据被该事务占用,还用于设置该事务对该数据的占用类型为第一占用类型,以指示在该事务占用该数据过程中,禁止其他事务所包括的操作更新该数据。此时,第一占用类型指示的该事务占用该数据的过程为执行该事务中包括的读取操作读取该数据的过程。Transactions running under the serializable isolation level include read operations that can read the updated content of the transaction that has submitted the processing results and return the latest version corresponding to the data targeted by the read operation. The read operation can update the indication information corresponding to the data targeted by the read operation, can be used to set the indication information including the transaction number of the transaction to indicate that the data is occupied by the transaction, and can also be used to set the occupation of the data by the transaction. The type is the first occupation type to indicate that operations included in other transactions are prohibited from updating the data while the transaction is occupying the data. At this time, the process in which the transaction occupies the data indicated by the first occupancy type is the process of executing the read operation included in the transaction to read the data.
运行在可串行化隔离等级下的事务所包括的更新操作,能够更新该更新操作针对的数据对应的指示信息,能够用于设置指示信息包括该事务的事务编号以表示该数据被该事务占用,还用于设置该事务对该数据的占用类型为第二占用类型,以指示在该事务占用该数据过程中,禁止其他事务所包括的操作更新或者读取该数据。此时,第二占用类型指示的该事务占用该数据的过程为执行该事务中包括的更新操作更新该数据的过程。The update operation included in the transaction running under the serializable isolation level can update the instruction information corresponding to the data targeted by the update operation, and can be used to set the instruction information to include the transaction number of the transaction to indicate that the data is occupied by the transaction. , is also used to set the occupation type of the data by the transaction to the second occupation type, to indicate that during the process of the transaction occupying the data, operations included in other transactions are prohibited from updating or reading the data. At this time, the process in which the transaction occupies the data indicated by the second occupancy type is the process of executing the update operation included in the transaction to update the data.
在一种可能的实现方式中,第一事务包括的处理目标数据的操作为读取操作,该第一事务的隔离等级为可串行化,则根据第一事务的隔离等级执行第一事务包括的操作以读取目标数据,包括但不限于:设置目标数据的指示信息,指示信息包括指示信息包括第一事务的事务编号和占用类型,该占用类型指示执行第一事务包括的操作以读取该目标数据的过程中,禁止执行其他事务所包括的更新该目标数据的操作;执行第一事务包括的操作以读取所述目标数据。In a possible implementation, the operation of processing the target data included in the first transaction is a read operation, and the isolation level of the first transaction is serializable. Then executing the first transaction according to the isolation level of the first transaction includes: The operation to read the target data includes, but is not limited to: setting instruction information of the target data, the instruction information includes the instruction information including the transaction number and occupancy type of the first transaction, the occupancy type indicates performing the operation included in the first transaction to read During the process of obtaining the target data, it is prohibited to perform operations included in other transactions to update the target data; operations included in the first transaction are performed to read the target data.
在一种可能的实现方式中,在执行步骤201之前,为要启动的第一事务设置相应的隔离等级,然后向服务器提交包括该隔离等级的启动请求,服务器接收该启动请求后启动第一事务,执行第一事务包括的操作。In a possible implementation, before performing step 201, set a corresponding isolation level for the first transaction to be started, and then submit a startup request including the isolation level to the server. The server starts the first transaction after receiving the startup request. , perform the operations included in the first transaction.
实际处理中,根据不同事务对应的不同的处理要求,为要启动的事务设置相应的隔离等级,该处理要求可以为对数据库状态的一致性的要求。示例性的,要开启的事务对应的处理要求为获取到强一致的数据库状态,则设置该事务对应的隔离等级为可串行化;或者,要开始的事务对应的处理要求对数据库状态 的一致性不严格,则设置该事务对应的隔离等级为快照隔离或者读已提交。其中,对数据库状态的一致性不严格指示弱一致的数据库状态。In actual processing, the corresponding isolation level is set for the transaction to be started based on the different processing requirements corresponding to different transactions. The processing requirements can be requirements for the consistency of the database state. For example, if the processing requirement corresponding to the transaction to be started is to obtain a strongly consistent database state, then the isolation level corresponding to the transaction is set to serializable; or, the processing requirement corresponding to the transaction to be started is to obtain a consistent database state. If the isolation level is not strict, set the isolation level corresponding to the transaction to snapshot isolation or read committed. Among them, the consistency of the database state is not strict, indicating a weakly consistent database state.
一种可能的实现方式中,第一事务包括多个操作,每个操作分别针对相应的目标数据,多个目标数据中包括的第一目标数据被第二事务占用,该多个操作按照执行顺序排列,则步骤202中执行第一事务包括的操作以处理目标数据的过程包括但不限于:In a possible implementation, the first transaction includes multiple operations, each operation is directed to the corresponding target data, the first target data included in the multiple target data is occupied by the second transaction, and the multiple operations are executed in order arranged, then the process of performing the operations included in the first transaction to process the target data in step 202 includes but is not limited to:
响应于在第一时间间隔内完成第二事务的处理结果的提交,在第二事务的处理结果被提交后,执行第一事务包括的处理第一目标数据的第一操作,执行第一事务包括的执行顺序在第一操作之后的操作;响应于在第一时间间隔内未完成第二事务的处理结果的提交,则在第一时间间隔后,重新执行第一事务包括的执行顺序在第一操作之前的操作;响应于第一事务包括的多个操作全部执行完毕,提交第一事务的处理结果。In response to completing the submission of the processing result of the second transaction within the first time interval, after the processing result of the second transaction is submitted, executing the first operation of processing the first target data included in the first transaction, executing the first transaction includes The execution sequence of the operation is after the first operation; in response to the submission of the processing result of the second transaction not being completed within the first time interval, then after the first time interval, re-executing the execution sequence of the first transaction including the first operation The operation before the operation; in response to the completion of execution of multiple operations included in the first transaction, the processing result of the first transaction is submitted.
在该种可能的实现方式中,第一事务与第二事务并行处理,各事务包括的操作按照执行顺序依次执行。当第一事务中的任一操作针对的目标数据正在被第二事务占用,一些情况下,需要等待第二事务的处理结果被提交之后再执行第一事务所包括的操作,即第一事务包括的操作处于等待状态。In this possible implementation, the first transaction and the second transaction are processed in parallel, and the operations included in each transaction are executed sequentially in the order of execution. When the target data targeted by any operation in the first transaction is being occupied by the second transaction, in some cases, it is necessary to wait for the processing result of the second transaction to be submitted before executing the operations included in the first transaction, that is, the first transaction includes The operation is waiting.
在该种情况下,从第一事务包括的操作开始等待起,记录第一事务包括的操作的等待时间。若从开始等待起的第一时间间隔内完成第二事务的处理结果的提交,等待时间不超过第一时间间隔,则在第二事务的处理结果被提交后,执行第一事务包括的处理第一目标数据的第一操作,然后执行该第一事务包括的执行顺序在该第一操作之后的操作。若从开始等待起的第一时间间隔内未完成第二事务的处理结果的提交,等待时间超过第一时间间隔,则在等待时间达到第一时间间隔后,按照第一事务包括的多个操作的执行顺序,从排序第一的操作开始,重新执行该第一事务包括的多个操作;在重新执行至第一操作时,若该第一事务在重新执行过程中再次等待的时间不超过第一时间,则在第一操作执行完成后,按照执行顺序依次执行第一事务包括其他操作。In this case, the waiting time of the operations included in the first transaction is recorded from the time the operations included in the first transaction start waiting. If the submission of the processing result of the second transaction is completed within the first time interval from the start of waiting, and the waiting time does not exceed the first time interval, then after the processing result of the second transaction is submitted, the processing step included in the first transaction is executed. A first operation on target data, and then performing operations included in the first transaction in execution order after the first operation. If the submission of the processing result of the second transaction is not completed within the first time interval from the start of waiting, and the waiting time exceeds the first time interval, after the waiting time reaches the first time interval, the first transaction will be processed according to the multiple operations included in the first transaction. In the order of execution, starting from the first-ordered operation, re-execute the multiple operations included in the first transaction; when re-executing to the first operation, if the first transaction waits for no longer than the first operation during re-execution, time, after the execution of the first operation is completed, the first transaction including other operations are executed sequentially according to the execution order.
在一种可能的实现方式中,重新执行第一事务所包括的操作的过程中,如果执行第一操作的等待时间依旧超过第一时间间隔,则再次重新按照执行顺序重新执行第一事务包括的操作。在重新执行的次数超过重复阈值的情况下,向终端反馈该第一事务执行失败的消息。其中,重复阈值的设定可以根据第一事务的性质进行确定,也可以是预先设定好的,本申请对重复阈值的数值的设置不作限定。In a possible implementation, during the process of re-executing the operations included in the first transaction, if the waiting time for executing the first operation still exceeds the first time interval, the operations included in the first transaction are re-executed again according to the execution order. operate. When the number of re-executions exceeds the repetition threshold, a message that the first transaction fails to execute is fed back to the terminal. The setting of the repetition threshold can be determined according to the nature of the first transaction, or can be set in advance. This application does not limit the setting of the value of the repetition threshold.
在上述重复执行第一事务包括的操作的场景下,第一时间间隔随着重复执 行次数的增加而增大。在一种可能的实现方式中,当前重复执行过程中的第一时间间隔对应的时间长度为上一次执行过程中第一时间间隔对应的长度的二倍。该种实现方式中,第一时间间隔的增大使得每次执行中的等待时间不断延长,能够减少重复执行的次数,降低计算复杂度,减少资源的消耗。In the above scenario of repeatedly executing the operations included in the first transaction, the first time interval increases as the number of repeated executions increases. In a possible implementation, the time length corresponding to the first time interval in the current repeated execution process is twice the length corresponding to the first time interval in the previous execution process. In this implementation, the increase in the first time interval continuously extends the waiting time in each execution, which can reduce the number of repeated executions, reduce computational complexity, and reduce resource consumption.
示例性的,第一事务与第二事务并行执行,执行第一事务中的第一操作时,第一操作针对的数据被第二事务占用,第一操作暂停执行,等待第二事务处理完成,第一时间间隔t后,第二事务未提交处理结果,则重新执行第一事务包括的所有操作。第一次重新执行过程中,执行第一事务的第一操作时,第二事务仍占用相应的数据,此时,第一时间间隔为上一次执行中第一时间间隔的两倍,即2t,若等待时间2t中,第二事务的处理数据被提交,则继续执行第一操作以及第一事务包括的其他操作;若时间2t中,第二事务还未完成,则再次重新执行第一事务包括的所有操作。在第二次重新执行过程中,第一时间间隔为4t。若第二次重新执行过程中仍不能执行第一操作,循环进入第三次重复执行过程,直至第一操作被执行完成,然后继续执行第一事务包括的其他操作;或者直至重复执行的次数超过重复阈值,向终端反馈第一事务执行失败的消息。For example, the first transaction and the second transaction are executed in parallel. When the first operation in the first transaction is executed, the data targeted by the first operation is occupied by the second transaction, and the execution of the first operation is suspended, waiting for the completion of the second transaction. After the first time interval t, if the second transaction does not submit the processing result, all operations included in the first transaction are re-executed. During the first re-execution, when the first operation of the first transaction is executed, the second transaction still occupies the corresponding data. At this time, the first time interval is twice the first time interval in the previous execution, that is, 2t, If the processing data of the second transaction is submitted during the waiting time 2t, continue to execute the first operation and other operations included in the first transaction; if the second transaction has not been completed during the waiting time 2t, re-execute the first transaction including all operations. During the second re-execution, the first time interval is 4t. If the first operation still cannot be executed during the second re-execution, the loop will enter the third repeated execution process until the first operation is completed, and then continue to execute other operations included in the first transaction; or until the number of repeated executions exceeds Repeat the threshold and feedback a message that the first transaction failed to execute to the terminal.
一种可能的实现方式中,第一事务的隔离类型为快照隔离,该第一事务包括的操作为读取多个时间版本的目标数据中与目标时间戳对应的目标版本数据,则步骤202中执行第一事务包括的操作以处理目标数据,包括但不限于:In one possible implementation, the isolation type of the first transaction is snapshot isolation, and the operation included in the first transaction is to read the target version data corresponding to the target timestamp among the target data of multiple time versions, then in step 202 Execute operations included in the first transaction to process the target data, including but not limited to:
确定目标数据的多个差分版本的数据,多个差分版本包括目标时间戳对应的差分版本以及在该目标时间戳对应的时间之前形成的差分版本,差分版本指任一事务包括的更新操作对目标数据进行更新的内容;合并目标数据的基础数据与多个差分版本的数据,得到多个数据版本的目标数据中与目标时间戳对应的目标版本数据。Determine multiple differential versions of the target data. The multiple differential versions include the differential version corresponding to the target timestamp and the differential version formed before the time corresponding to the target timestamp. The differential version refers to the update operation included in any transaction that affects the target. The content of the data update; merge the basic data of the target data and the data of multiple differential versions to obtain the target version data corresponding to the target timestamp in the target data of multiple data versions.
在一种可能的实现方式中,合并目标数据的基础数据与多个差分版本的数据可以包括:获取到目标数据的基础版本和多个差分版本后,按照差分版本对应的时间顺序,依次对基础数据进行更新,以得到目标版本数据。In one possible implementation, merging the basic data of the target data and the data of multiple differential versions may include: after obtaining the basic version and multiple differential versions of the target data, sequentially merge the basic data with the differential versions in the time sequence corresponding to the differential versions. The data is updated to obtain the target version data.
在一种可能的实现方式中,合并目标数据的基础数据与多个差分版本的数据可以包括:获取到目标数据的基础版本和多个差分版本后,将得到的所有差分版本进行去重、合并处理,得到差分版本的合并结果;将该合并结果与基础数据进行合并,以得到目标版本数据。In a possible implementation, merging the basic data of the target data and the data of multiple differential versions may include: after obtaining the basic version and multiple differential versions of the target data, deduplication and merging all obtained differential versions Process to obtain the merged result of the differential version; merge the merged result with the basic data to obtain the target version data.
本申请实施例中,为节省存储的空间,按照差分版本化的方法存储各数据的基础数据与对应的差分版本,各数据的各差分版本分别对应事务包括的更新操对该数据进行更新的内容。示例性的,对一个数据M进行添加数据N的更新 操作,则存储基础数据M和基于更新的数据内容生成的差分版本“添加N”。可选的,本申请也可以直接存储更新后的目标数据,示例性地,存储“数据M+N”。In the embodiment of this application, in order to save storage space, the basic data and corresponding differential versions of each data are stored according to the differential versioning method. Each differential version of each data corresponds to the update operation included in the transaction to update the data. . For example, if an update operation of adding data N is performed on a piece of data M, the basic data M and the differential version "add N" generated based on the updated data content are stored. Optionally, this application can also directly store the updated target data, for example, "data M+N".
如存在基础数据M和时间戳依次为I、II、III的差分版本“添加N”、“添加P”和“减去H”,确定目标时间戳II对应的目标版本的方式包括:获取基础数据M和差分版本“添加N”和“添加P”,依次计算“M+N”、“M+N+P”;或者,先计算差分版本的合并结果“N+P”然后于基础数据合并得到“M+N+P”。If there is basic data M and differential versions with timestamps I, II, and III in order "add N", "add P" and "subtract H", the method of determining the target version corresponding to the target timestamp II includes: obtaining the basic data M and the differential version "Add N" and "Add P", and calculate "M+N" and "M+N+P" in sequence; or, first calculate the merged result "N+P" of the differential version and then merge it with the basic data to obtain "M+N+P".
各个差分版本对应有不同的时间戳,该时间戳能够表示该差分版本的生命周期,用于指示生成该差分版本的操作所属的事务的开始时间与结束时间。示例性地,时间戳的表示形式可以为[开始时间,结束时间)。该时间戳基于物理时间与逻辑时间共同生成。其中,物理时间指真实世界中的时间,指示该差分版本对应的事务发生的真实时间;逻辑时间指应用一个逻辑计数器确定的该差分版本对应的事务的处理顺序。该逻辑计数器的计数在各个事务开启过程时进行递增。该确定时间戳的方式可以实现逻辑顺序与物理顺序的结合。Each differential version corresponds to a different timestamp. The timestamp can represent the life cycle of the differential version and is used to indicate the start time and end time of the transaction to which the operation that generated the differential version belongs. For example, the timestamp may be expressed in the form of [start time, end time). The timestamp is generated based on a combination of physical time and logical time. Among them, physical time refers to the time in the real world, indicating the real time when the transaction corresponding to the differential version occurs; logical time refers to the processing sequence of the transaction corresponding to the differential version determined by applying a logical counter. The count of this logical counter is incremented when each transaction is started. This method of determining timestamps can achieve a combination of logical order and physical order.
示例性地,先后开启了事务1和事务2,由于时间取值精度的影响,事务1和事务2的开启时间均记录为20时18分30秒,则仅依据物理时间不能确定事务1和事务2的先后顺序。而逻辑时间可以基于计数器的计数记录各个事务开启的先后顺序。因此,本申请实施例中结合物理时间与逻辑时间确定差分版本的时间戳的方法可以获得精确度更高的时间戳,能够更准确地获取执行各事务中包括的操作时所需要的数据,有利于对事务处理效率的提高。For example, transaction 1 and transaction 2 are opened successively. Due to the influence of time value accuracy, the opening time of transaction 1 and transaction 2 is both recorded as 20 hours, 18 minutes and 30 seconds. Therefore, transaction 1 and transaction 1 cannot be determined based on physical time only. 2 sequence. The logical time can record the order in which each transaction is opened based on the counter's count. Therefore, the method in the embodiment of the present application that combines physical time and logical time to determine the differential version of the timestamp can obtain a more accurate timestamp, and can more accurately obtain the data required to execute the operations included in each transaction, and has Conducive to improving transaction processing efficiency.
参见图3,图3示出了按照差分版本化的方法存储数据的示意图,其形式为一种邻接链表。其中包括基础版本和差分版本1-n。示例性的,差分版本1中对应于时间戳[0,TS 1),其中,0和TS 1分别对应形成该差分版本的操作所属于的事务的开始时间和结束时间。其中版本头用于指示差分版本的开始,不指示具体数据。 Referring to Figure 3, Figure 3 shows a schematic diagram of storing data according to the differential versioning method, which is in the form of an adjacency linked list. These include base version and differential version 1-n. For example, differential version 1 corresponds to timestamp [0, TS 1 ), where 0 and TS 1 respectively correspond to the start time and end time of the transaction to which the operation forming the differential version belongs. The version header is used to indicate the start of the differential version and does not indicate specific data.
在该种可能的实现方式中,基于图3,若第一事务中的读取操作的指令为读取目标数据在目标时间戳[TS 1,TS 2)时的目标版本数据,则获取基本版本、差分版本1和差分版本2,然后合并该基础版本、差分版本1和差分版本2,以在基础版本的基础上进行更新合并得到目标时间戳对应的目标版本数据。其中,合并该基础版本、差分版本1和差分版本2的方法可以包括下述两种方式: In this possible implementation, based on Figure 3, if the instruction of the read operation in the first transaction is to read the target version data of the target data at the target timestamp [TS 1 , TS 2 ), then obtain the basic version , differential version 1 and differential version 2, and then merge the basic version, differential version 1 and differential version 2 to update and merge based on the basic version to obtain the target version data corresponding to the target timestamp. Among them, the method of merging the basic version, differential version 1 and differential version 2 can include the following two methods:
方式1:合并基础版本和差分版本1得到合并结果1,然后将合并结果1与差分版本2进行合并,得到目标版本数据。Method 1: Merge the basic version and the differential version 1 to obtain the merge result 1, and then merge the merge result 1 with the differential version 2 to obtain the target version data.
方式2:合并差分版本1和差分版本2得到差分版本的合并结果,然后合并基础数据和差分版本得到目标版本数据。在一种可能的实现方式中,差分版本1 和差分版本2的内容可能为操作相反的更新方式,如差分版本1为增加数据1差分版本为减去数据1,则差分版本的合并结果为不更新基础数据。此时,基础数据即为目标版本数据。在该种可能的实现方式中,减少了进行合并计算的次数,降低了计算复杂度,能够提高事务处理效率。Method 2: Merge differential version 1 and differential version 2 to obtain the merged result of the differential versions, and then merge the basic data and differential versions to obtain the target version data. In a possible implementation, the contents of differential version 1 and differential version 2 may be updated in opposite ways. For example, differential version 1 is to add data 1 and the differential version is to subtract data 1, then the merge result of the differential versions is not Update basic data. At this time, the basic data is the target version data. In this possible implementation method, the number of merge calculations is reduced, the calculation complexity is reduced, and the transaction processing efficiency can be improved.
在一种可能的实现方式中,基于合并时间间隔,定期对目标数据的基础版本与目标数据的差分版本的数据进行合并,得到合并后的结果,合并后的数据用于更新目标数据的基础版本。In one possible implementation, based on the merging time interval, the base version of the target data and the differential version of the target data are merged regularly to obtain the merged result, and the merged data is used to update the base version of the target data. .
在事务处理过程中,每更新一次数据均生成一个对应的差分版本,则容易存储大量的差分版本,大量差分版本占用了大量的存储空间,需要定期对数据中的垃圾数据进行回收清理。因此,在一种可能的实现方式中,每经过合并时间间隔,则对目标数据的基础版本以及清除数量个差分版本数据进行合并,得到合并后的结果,并用合并后的结果更新基础版本。该清除数量可以基于经验设置,也可基于场景设置,本申请实施例对此也不作限定。During transaction processing, each data update generates a corresponding differential version, which makes it easy to store a large number of differential versions. A large number of differential versions occupy a large amount of storage space, and junk data in the data needs to be recycled and cleaned regularly. Therefore, in a possible implementation, every time the merging time interval elapses, the base version of the target data and the cleared number of differential version data are merged to obtain the merged result, and the base version is updated with the merged result. The number of clearings can be set based on experience or based on scene settings, and this is not limited in the embodiments of the present application.
其中,合并时间间隔可以表示为物理时间,或者表示已提交事务数量。Among them, the merge time interval can be expressed as physical time, or the number of committed transactions.
合并时间间隔表示为物理时间时,计算上一次执行合并操作的时间到当前时间的时间间隔,在该时间间隔达到合并时间间隔时,执行合并操作。示例性的,设置该合并时间间隔为30分钟,则经过30分钟执行一次合并操作。When the merge time interval is expressed as physical time, the time interval from the last time the merge operation was performed to the current time is calculated. When the time interval reaches the merge time interval, the merge operation is performed. For example, if the merging interval is set to 30 minutes, a merging operation will be performed after 30 minutes.
合并时间间隔为已提交事务数量时,统计从上一次执行合并操作的时间到当前时间中,完成处理结果提交的事务的数量,在该完成处理结果提交的事务的数量达到合并时间间隔时,执行合并操作。示例性的,设置该合并时间间隔为10000,则每成功完成10000个事务执行一次合并操作。When the merge time interval is the number of submitted transactions, count the number of transactions that have completed processing results and submitted them from the last time the merge operation was performed to the current time. When the number of completed transactions and submitted transactions reaches the merge time interval, execute Merge operation. For example, if the merge time interval is set to 10,000, a merge operation will be performed every time 10,000 transactions are successfully completed.
在执行合并各基础版本和差分版本的过程中,暂时中断对数据库中数据的访问或者更新操作,将数据库中满足清理条件的数据进行清理。During the process of merging each basic version and differential version, the access or update operation to the data in the database is temporarily interrupted, and the data in the database that meets the cleaning conditions is cleaned.
在步骤202之后,响应于第一事务包括的所有操作执行完毕,基于提交指令提交第一事务的处理结果,向终端反馈该第一事务执行成功的消息。After step 202, in response to the completion of all operations included in the first transaction, the processing result of the first transaction is submitted based on the commit instruction, and a message that the first transaction is successfully executed is fed back to the terminal.
在一种可能的实现方式中,提交指令由用户在终端触发生成。在第一事务包括的所有操作执行完毕后,服务器向终端反馈确认消息,提示用户再次确认是否执行该第一事务,响应于用户反馈确认指令,则向服务器发送提交指令,服务器提交该第一事务的处理结果。In a possible implementation, the submission instruction is triggered by the user on the terminal. After all operations included in the first transaction are executed, the server feeds back a confirmation message to the terminal, prompting the user to confirm again whether to execute the first transaction. In response to the user feedback confirmation instruction, a submission instruction is sent to the server, and the server submits the first transaction. processing results.
示例性地,用户提交第一事务为“用户A向用户B转账100元”,则该事务中先后执行对用户A的账户减少100元的操作,再执行对用户B的账户添加100元的操作。响应于该两个更新操作均完成,服务器向终端反馈“是否确认转账100”的确认信息,用户发出“确认完成”指令,则向服务器发送提交指令,指示服务器 提交该第一事务的执行结果,即将A的账户减少100元的数据和B的账户添加了100元的数据存储在数据库中。服务器向终端反馈“转账完成”信息,提示用户第一事务执行成功。For example, if the user submits the first transaction as "User A transfers 100 yuan to user B", then in this transaction, the operation of reducing user A's account by 100 yuan is performed, and then the operation of adding 100 yuan to user B's account is performed. . In response to both update operations being completed, the server feeds back the confirmation message "Whether the transfer 100 is confirmed" to the terminal. The user issues a "confirm completion" instruction and then sends a submission instruction to the server, instructing the server to submit the execution result of the first transaction. That is, the data of A's account reduced by 100 yuan and the data of B's account added 100 yuan are stored in the database. The server feeds back the "transfer completed" message to the terminal, prompting the user that the first transaction was executed successfully.
在一种可能的实现方式中,参见图4,服务器可以包括事务调度处理器、查询器、执行器以及垃圾回收组件实现上述事务处理方法。其中,事务调度处理接收事务的启动请求等指令,还周期性的指示垃圾回收组件进行无用数据的清理;查询器用于解析接收到的启动请求等语句;执行器基于解析后的语句执行对存储层中的数据进行相应的操作,如创建新的差分版本或者在获取数据过程对数据进行合并。In a possible implementation, referring to Figure 4, the server may include a transaction scheduling processor, a query, an executor, and a garbage collection component to implement the above transaction processing method. Among them, the transaction scheduling process receives instructions such as transaction startup requests, and also periodically instructs the garbage collection component to clean up useless data; the query is used to parse the received startup requests and other statements; the executor executes the storage layer based on the parsed statements. Perform corresponding operations on the data in the database, such as creating a new differential version or merging the data during the data acquisition process.
在应用上述事务处理方法对数据进行处理的示例性实施例中,可以应用在线事务处理方法、命令行事务处理方法或者API(Application Programming Interface,应用程序接口)接口方法中的任一种进行实现。参见图5、6、7分别是采用上述方式实施事务处理得到的操作界面示意图。In an exemplary embodiment of applying the above transaction processing method to process data, any one of the online transaction processing method, the command line transaction processing method, or the API (Application Programming Interface, Application Programming Interface) interface method can be used for implementation. See Figures 5, 6, and 7 respectively for schematic diagrams of operation interfaces obtained by implementing transaction processing in the above manner.
图5是在线事务处理界面的示意图。其中包括两个事务的执行页面,TID指示事务编号,以事务编号为1的事务进行说明,“insert data{<v1><value>“20”}”是提交的该事务的指令,“The Result”用于指示该事务执行成功后的结果。Figure 5 is a schematic diagram of the online transaction processing interface. It includes the execution pages of two transactions. The TID indicates the transaction number. The transaction number is 1. "insert data{<v1><value>"20"}" is the instruction of the submitted transaction. "The Result" " is used to indicate the result of successful execution of the transaction.
图6是命令行事务处理界面的示意图,其中包括对事务编号为4的事务的启动指令。Figure 6 is a schematic diagram of the command line transaction processing interface, which includes a start instruction for transaction number 4.
图7是通过API的调用进行事务处理的界面的示意图,在该图7中示出了多个事务处理的过程。FIG. 7 is a schematic diagram of an interface for performing transaction processing through API calls. FIG. 7 shows multiple transaction processing processes.
本申请实施例提供的事务处理方法,基于目标数据的指示信息确定并行的第二事务对该目标数据的占用类型,再基于第一事务对应的隔离等级和包括的操作,执行第一事务包括的针对目标数据的操作,得到第一事务的处理结果。该方式无需系统调用以控制并行的事务对同一数据进行处理,避免了频繁陷入操作系统内核态,提高了事务处理效率,提高了系统吞吐量。且本申请实施例中对差分版本数据的应用,减少了数据对存储空间的占用,提高了对数据进行更新的效率。The transaction processing method provided by the embodiment of the present application determines the occupation type of the target data by the parallel second transaction based on the instruction information of the target data, and then executes the operations included in the first transaction based on the isolation level corresponding to the first transaction and the included operations. Operate on the target data to obtain the processing result of the first transaction. This method does not require system calls to control parallel transactions to process the same data, avoids frequently falling into the operating system kernel state, improves transaction processing efficiency, and improves system throughput. Moreover, the application of differential version data in the embodiments of the present application reduces the storage space occupied by the data and improves the efficiency of updating the data.
本申请实施例提供了一种事务处理装置,该装置用于实现图2示出的事务处理方法。参见图8,该装置包括但不限于:An embodiment of the present application provides a transaction processing device, which is used to implement the transaction processing method shown in Figure 2. Referring to Figure 8, the device includes but is not limited to:
检测模块801,用于检测第一事务针对的目标数据是否被第二事务所占用,第一事务包括处理目标数据的操作,第二事务是与第一事务并行的其他事务;The detection module 801 is used to detect whether the target data targeted by the first transaction is occupied by the second transaction. The first transaction includes operations of processing the target data, and the second transaction is other transactions in parallel with the first transaction;
执行模块802,用于响应于目标数据被第二事务所占用,根据第二事务对目 标数据的占用类型和第一事务包括的处理目标数据的操作的类型,执行第一事务包括的操作以处理目标数据。 Execution module 802, configured to respond to the target data being occupied by the second transaction, and execute operations included in the first transaction to process the target data according to the occupation type of the target data by the second transaction and the type of operations included in the first transaction to process the target data. target data.
在一种可能的实现方式中,检测模块801,用于读取目标数据携带的指示信息,指示信息包括占用目标数据的事务的事务编号;基于指示信息包括的事务编号为第二事务的事务编号,则确定目标数据被第二事务所占用。In a possible implementation, the detection module 801 is configured to read the indication information carried by the target data, where the indication information includes the transaction number of the transaction occupying the target data; based on the transaction number included in the indication information, it is the transaction number of the second transaction. , then it is determined that the target data is occupied by the second transaction.
在一种可能的实现方式中,执行模块802,用于响应于目标数据被第二事务所占用,且第一事务包括的处理目标数据的操作为更新操作,则在第二事务的处理结果被提交后,根据第一事务包括的操作更新目标数据;响应于目标数据被第二事务所占用,且第一事务包括的处理目标数据的操作为读取操作,则根据第二事务对目标数据的占用类型和第一事务包括的操作读取目标数据。In a possible implementation, the execution module 802 is configured to respond to the target data being occupied by the second transaction, and the operation of processing the target data included in the first transaction is an update operation, then when the processing result of the second transaction is After submission, the target data is updated according to the operations included in the first transaction; in response to the target data being occupied by the second transaction, and the operation included in the first transaction to process the target data is a read operation, the target data is updated according to the second transaction. The occupation type and the first transaction include operations that read the target data.
在一种可能的实现方式中,执行模块802,用于确定第二事务对目标数据的占用类型;响应于占用类型指示在第二事务占用目标数据过程中,禁止除第二事务外的其他事务所包括的操作更新和读取目标数据,则在第二事务的处理结果被提交后,根据第一事务的隔离等级执行第一事务包括的操作以读取目标数据,第一事务的隔离等级用于指示第一事务包括的读取目标数据的操作对应的读取规则。In a possible implementation, the execution module 802 is configured to determine the occupation type of the target data by the second transaction; in response to the occupation type indication, during the process of the second transaction occupying the target data, prohibit other transactions except the second transaction. The included operations update and read the target data. After the processing result of the second transaction is submitted, the operations included in the first transaction are executed to read the target data according to the isolation level of the first transaction. The isolation level of the first transaction is used A read rule corresponding to an operation of reading target data included in the first transaction.
在一种可能的实现方式中,第一事务包括的处理目标数据的操作为更新操作,执行模块802,用于设置目标数据的指示信息,指示信息包括第一事务的事务编号和占用类型,占用类型指示在执行第一事务包括的操作以更新目标数据的过程中,禁止执行其他事务包括的读取或更新目标数据的操作;执行第一事务包括的操作以更新目标数据。In a possible implementation, the operation of processing the target data included in the first transaction is an update operation. The execution module 802 is used to set instruction information of the target data. The instruction information includes the transaction number and occupation type of the first transaction. The type indicates that during the process of executing the operations included in the first transaction to update the target data, it is prohibited to execute the operations of reading or updating the target data included in other transactions; the operations included in the first transaction are executed to update the target data.
在一种可能的实现方式中,第一事务包括的处理目标数据的操作为读取操作,第一事务的隔离等级为可串行化,执行模块802,用于设置目标数据的指示信息,指示信息包括指示信息包括第一事务的事务编号和占用类型,占用类型指示执行第一事务包括的操作以读取目标数据的过程中,禁止执行其他事务所包括的更新目标数据的操作;执行第一事务包括的操作以读取目标数据。In a possible implementation, the operation of processing the target data included in the first transaction is a read operation, the isolation level of the first transaction is serializable, and the execution module 802 is used to set the instruction information of the target data, indicating The information includes the indication information including the transaction number and occupancy type of the first transaction. The occupancy type indicates that during the process of executing the operations included in the first transaction to read the target data, it is prohibited to perform the operations of updating the target data included in other transactions; executing the first A transaction includes operations to read target data.
在一种可能的实现方式中,第一事务包括多个操作,每个操作分别针对相应的目标数据,多个目标数据包括的第一目标数据被第二事务占用,多个操作按执行顺序排列,执行模块802,用于响应于在第一时间间隔内完成第二事务的处理结果的提交,在第二事务的处理结果被提交后,执行第一事务包括的处理第一目标数据的第一操作,执行第一事务包括的执行顺序在第一操作之后的操作;响应于在第一时间间隔内未完成第二事务的处理结果的提交,则在第一时间间隔后,重新执行第一事务包括的执行顺序在第一操作之前的操作;响应于 第一操作执行完成,执行第一事务包括的执行顺序在第一操作之后的操作。In a possible implementation, the first transaction includes multiple operations, each operation is directed to the corresponding target data, the first target data included in the multiple target data is occupied by the second transaction, and the multiple operations are arranged in execution order. , the execution module 802 is configured to respond to completing the submission of the processing result of the second transaction within the first time interval, and after the processing result of the second transaction is submitted, execute the first step of processing the first target data included in the first transaction. Operation, execute the operations included in the first transaction whose execution sequence is after the first operation; in response to the submission of the processing result of the second transaction not being completed within the first time interval, re-execute the first transaction after the first time interval The operations included in the execution order are before the first operation; in response to completion of execution of the first operation, the first transaction includes the operations in the execution order after the first operation.
在一种可能的实现方式中,第一事务的隔离类型为快照隔离,第一事务包括的操作为读取多个时间版本的目标数据中与目标时间戳对应的目标版本数据,执行模块802,用于确定目标数据的多个差分版本的数据,多个差分版本包括目标时间戳对应的差分版本以及在目标时间戳对应的时间之前形成的差分版本,差分版本指任一事务包括的更新操作对目标数据进行更新的内容;合并目标数据的基础版本与多个差分版本的数据,得到多个数据版本的目标数据中与目标时间戳对应的目标版本数据。In a possible implementation, the isolation type of the first transaction is snapshot isolation, and the operation included in the first transaction is to read the target version data corresponding to the target timestamp among the target data of multiple time versions, and the execution module 802, Data used to determine multiple differential versions of the target data. The multiple differential versions include the differential version corresponding to the target timestamp and the differential version formed before the time corresponding to the target timestamp. The differential version refers to the update operation pair included in any transaction. The updated content of the target data; merge the basic version of the target data and the data of multiple differential versions to obtain the target version data corresponding to the target timestamp in the target data of multiple data versions.
在一种可能的实现方式中,装置还包括:In a possible implementation, the device further includes:
合并模块,用于基于合并时间间隔,定期对目标数据的基础版本与目标数据的差分版本的数据进行合并,得到合并后的数据,合并后的数据用于更新目标数据的基础版本。The merging module is used to regularly merge the basic version of the target data and the differential version of the target data based on the merging time interval to obtain merged data. The merged data is used to update the basic version of the target data.
该事务处理装置用于执行上述事务处理方法,无需系统调用以控制并行的事务对同一数据进行处理,能够频繁陷入操作系统内核态,提高了事务处理效率,提高了系统的吞吐量。且对差分版本数据的应用,减少了数据对存储空间的占用,提高了对数据进行更新的效率。The transaction processing device is used to execute the above transaction processing method without requiring system calls to control parallel transactions to process the same data, and can frequently fall into the operating system kernel state, thereby improving transaction processing efficiency and system throughput. And the application of differential version data reduces the storage space occupied by data and improves the efficiency of data update.
本申请实施例提供了一种计算机可读存储介质,该计算机可读存储介质中存储有至少一条程序代码或指令,程序代码或指令由处理器加载并执行,以使计算机实现如方法实施例所述的任一事务处理方法。Embodiments of the present application provide a computer-readable storage medium in which at least one program code or instruction is stored. The program code or instruction is loaded and executed by a processor, so that the computer implements the steps as described in the method embodiments. any of the transaction processing methods described above.
可选地,上述计算机可读存储介质可以是只读存储器(Read-Only Memory,ROM)、随机存取存储器(Random Access Memory,RAM)、只读光盘(Compact Disc Read-Only Memory,CD-ROM)、磁带、软盘和光数据存储设备等。Optionally, the above computer-readable storage medium may be read-only memory (Read-Only Memory, ROM), random access memory (Random Access Memory, RAM), read-only compact disc (Compact Disc Read-Only Memory, CD-ROM) ), tapes, floppy disks and optical data storage devices, etc.
在示例性实施例中,还提供了一种计算机程序或计算机程序产品,该计算机程序或计算机程序产品中存储有至少一条计算机指令,该至少一条计算机指令由处理器加载并执行,以使计算机实现上述任一事务处理方法。In an exemplary embodiment, a computer program or computer program product is also provided. At least one computer instruction is stored in the computer program or computer program product, and the at least one computer instruction is loaded and executed by the processor, so that the computer implements Any of the above transaction processing methods.
图9是本申请实施例提供的一种电子设备的结构示意图,该电子设备900可因配置或性能不同而产生比较大的差异,可以包括一个或多个处理器(Central Processing Units,CPU)901和一个或多个的存储器902,其中,该一个或多个存储器902中存储有至少一条程序指令,该至少一条程序指令由该一个或多个处理器901加载并执行以实现上述各个方法实施例提供的事务处理方法。当然,该电子设备900还可以具有有线或无线网络接口、键盘以及输入输出接口等部件,以便进行输入输出,该电子设备900还可以包括其他用于实现设备功能的部件,在此不做赘述。Figure 9 is a schematic structural diagram of an electronic device provided by an embodiment of the present application. The electronic device 900 may vary greatly due to different configurations or performance, and may include one or more processors (Central Processing Units, CPUs) 901 and one or more memories 902, wherein at least one program instruction is stored in the one or more memories 902, and the at least one program instruction is loaded and executed by the one or more processors 901 to implement each of the above method embodiments. Provided transaction processing methods. Of course, the electronic device 900 may also have components such as wired or wireless network interfaces, keyboards, and input and output interfaces for input and output. The electronic device 900 may also include other components for realizing device functions, which will not be described again here.
需要说明的是本申请所涉及的信息(包括但不限于用户设备信息、用户个人信息等)、数据(包括但不限于用于分析的数据、存储的数据、展示的数据等)以及信号,均为经用户授权或者经过各方充分授权的,且相关数据的收集、使用和处理需要遵守相关国家和地区的相关法律法规和标准。例如,本申请中涉及到的对目标数据的获取都是在充分授权的情况下获取的。It should be noted that the information (including but not limited to user equipment information, user personal information, etc.), data (including but not limited to data used for analysis, stored data, displayed data, etc.) and signals involved in this application are all It is authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data need to comply with the relevant laws, regulations and standards of the relevant countries and regions. For example, the acquisition of target data involved in this application was obtained with full authorization.
应理解,在本申请的各个实施例中,各个过程的序号的大小并不意味着执行顺序的先后,各过程的执行顺序应以其功能和内在逻辑确定,而不应对本申请实施例的实施过程构成任何限定。It should be understood that in each embodiment of the present application, the size of the sequence number of each process does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not be used in the implementation of the embodiments of the present application. The process constitutes any limitation.
本申请中术语“至少一个”的含义是指一个或多个,本申请中术语“多个”的含义是指两个或两个以上。The term "at least one" in this application means one or more, and the term "plurality" in this application means two or more.
应理解,在本文中对各种所述示例的描述中所使用的术语只是为了描述特定示例,而并非旨在进行限制。如在对各种所述示例的描述和所附权利要求书中所使用的那样,单数形式“一个(“a”,“an”)”和“该”旨在也包括复数形式,除非上下文另外明确地指示。It is to be understood that the terminology used in the description of the various examples herein is for the purpose of describing the particular example only and is not intended to be limiting. As used in the description of various described examples and the appended claims, the singular forms "a," "an" and "the" are intended to include the plural forms as well, unless the context dictates otherwise. Instruct clearly.
还应理解,术语“包括”(也称“includes”、“including”、“comprises”和/或“comprising”)当在本说明书中使用时指定存在所陈述的特征、整数、步骤、操作、元素、和/或部件,但是并不排除存在或添加一个或多个其他特征、整数、步骤、操作、元素、部件、和/或其分组。It will also be understood that the term "includes" (also "includes," "including," "comprises," and/or "comprising") when used in this specification specifies the presence of stated features, integers, steps, operations, elements , and/or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and/or groupings thereof.
应理解,根据A确定B并不意味着仅仅根据A确定B,还可以根据A和/或其它信息确定B。It should be understood that determining B based on A does not mean determining B only based on A, and B can also be determined based on A and/or other information.
还应理解,术语“若”和“如果”可被解释为意指“当..时”(“when”或“upon”)或“响应于确定”或“响应于检测到”。类似地,根据上下文,短语“若确定...”或“若检测到[所陈述的条件或事件]”可被解释为意指“在确定...时”或“响应于确定...”或“在检测到[所陈述的条件或事件]时”或“响应于检测到[所陈述的条件或事件]”。It should also be understood that the terms "if" and "if" may be interpreted to mean "when" or "upon" or "in response to determining" or "in response to detecting." Similarly, depending on the context, the phrase "if it is determined..." or "if [stated condition or event] is detected" may be interpreted to mean "when it is determined..." or "in response to the determination... ” or “on detection of [stated condition or event]” or “in response to detection of [stated condition or event].”
还应理解,说明书通篇中提到的“一个实施例”、“一实施例”、“一种可能的实现方式”意味着与实施例或实现方式有关的特定特征、结构或特性包括在本申请的至少一个实施例中。因此,在整个说明书各处出现的“在一个实施例中”或“在一实施例中”、“一种可能的实现方式”未必一定指相同的实施例。此外,这些特定的特征、结构或特性可以任意适合的方式结合在一个或多个实施例中。It should also be understood that references throughout this specification to "one embodiment," "an embodiment," and "a possible implementation" mean that specific features, structures, or characteristics related to the embodiment or implementation are included herein. In at least one embodiment of the application. Therefore, “in one embodiment” or “in an embodiment” or “a possible implementation” appearing in various places throughout this specification do not necessarily refer to the same embodiment. Furthermore, the particular features, structures or characteristics may be combined in any suitable manner in one or more embodiments.
以上所述仅为本申请的示例性实施例,并不用以限制本申请,凡在本申请的精神和原则之内,所作的任何修改、等同替换、改进等,均应包含在本申请的保护范围之内。The above are only exemplary embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the protection of the present application. within the range.

Claims (10)

  1. 一种事务处理方法,其特征在于,所述方法包括:A transaction processing method, characterized in that the method includes:
    检测第一事务针对的目标数据是否被第二事务所占用,所述第一事务包括处理所述目标数据的操作,所述第二事务是与所述第一事务并行的其他事务;Detect whether the target data targeted by the first transaction is occupied by a second transaction, the first transaction includes an operation of processing the target data, and the second transaction is another transaction in parallel with the first transaction;
    响应于所述目标数据被所述第二事务所占用,根据所述第二事务对所述目标数据的占用类型和所述第一事务包括的处理所述目标数据的操作的类型,执行所述第一事务包括的操作以处理所述目标数据。In response to the target data being occupied by the second transaction, according to the occupation type of the target data by the second transaction and the type of operation of processing the target data included in the first transaction, executing the The first transaction includes operations to process the target data.
  2. 根据权利要求1所述的方法,其特征在于,所述响应于所述目标数据被所述第二事务所占用,根据所述第二事务对所述目标数据的占用类型和所述第一事务包括的处理所述目标数据的操作的类型,执行所述第一事务包括的操作以处理所述目标数据,包括:The method according to claim 1, characterized in that, in response to the target data being occupied by the second transaction, according to the occupation type of the target data by the second transaction and the first transaction The types of operations included in processing the target data, and performing the operations included in the first transaction to process the target data include:
    响应于所述目标数据被所述第二事务所占用,且所述第一事务包括的处理所述目标数据的操作为更新操作,则在所述第二事务的处理结果被提交后,根据所述第一事务包括的操作更新所述目标数据;In response to the target data being occupied by the second transaction, and the operation of processing the target data included in the first transaction being an update operation, after the processing result of the second transaction is submitted, according to the The operation included in the first transaction updates the target data;
    响应于所述目标数据被所述第二事务所占用,且所述第一事务包括的处理所述目标数据的操作为读取操作,则根据所述第二事务对所述目标数据的占用类型和所述第一事务包括的操作读取所述目标数据。In response to the target data being occupied by the second transaction, and the operation of processing the target data included in the first transaction being a read operation, then according to the occupation type of the target data by the second transaction and the first transaction includes an operation of reading the target data.
  3. 根据权利要求2所述的方法,其特征在于,所述根据所述第二事务对所述目标数据的占用类型和所述第一事务包括的操作读取所述目标数据,包括:The method of claim 2, wherein reading the target data according to the occupation type of the target data by the second transaction and the operations included in the first transaction includes:
    确定所述第二事务对所述目标数据的占用类型;Determine the occupation type of the target data by the second transaction;
    响应于所述占用类型指示在所述第二事务占用所述目标数据过程中,禁止除所述第二事务外的其他事务所包括的操作更新和读取所述目标数据,则在所述第二事务的处理结果被提交后,根据所述第一事务的隔离等级执行所述第一事务包括的操作以读取所述目标数据,所述第一事务的隔离等级用于指示所述第一事务包括的读取所述目标数据的操作对应的读取规则。In response to the occupation type indicating that during the process of the second transaction occupying the target data, operations included in other transactions except the second transaction are prohibited from updating and reading the target data, then in the process of the second transaction occupying the target data, After the processing results of the second transaction are submitted, operations included in the first transaction are executed to read the target data according to the isolation level of the first transaction, which is used to indicate the first transaction. The transaction includes read rules corresponding to the operation of reading the target data.
  4. 根据权利要求1-3任一所述的方法,其特征在于,所述第一事务包括的处理所述目标数据的操作为更新操作,所述执行所述第一事务包括的操作以处理所述目标数据,包括:The method according to any one of claims 1 to 3, characterized in that the operation of processing the target data included in the first transaction is an update operation, and the operation included in the execution of the first transaction is to process the Target data, including:
    设置所述目标数据的指示信息,所述指示信息包括所述第一事务的事务编 号和占用类型,所述占用类型指示在执行所述第一事务包括的操作以更新所述目标数据的过程中,禁止执行其他事务包括的读取或更新所述目标数据的操作;Set the instruction information of the target data, the instruction information includes the transaction number and the occupation type of the first transaction, the occupation type indicates that in the process of executing the operation included in the first transaction to update the target data , prohibiting the execution of operations including reading or updating the target data included in other transactions;
    执行所述第一事务包括的操作以更新所述目标数据。Execute operations included in the first transaction to update the target data.
  5. 根据权利要求1-3任一所述的方法,其特征在于,所述第一事务包括的处理所述目标数据的操作为读取操作,所述第一事务的隔离等级为可串行化,所述根据所述第一事务的隔离等级执行所述第一事务包括的操作以读取所述目标数据,包括:The method according to any one of claims 1 to 3, characterized in that the operation of processing the target data included in the first transaction is a read operation, and the isolation level of the first transaction is serializable, The execution of operations included in the first transaction according to the isolation level of the first transaction to read the target data includes:
    设置所述目标数据的指示信息,所述指示信息包括所述指示信息包括所述第一事务的事务编号和占用类型,所述占用类型指示执行所述第一事务包括的操作以读取所述目标数据的过程中,禁止执行其他事务所包括的更新所述目标数据的操作;Set the instruction information of the target data, the instruction information includes the transaction number and the occupation type of the first transaction, the occupation type indicates performing the operation included in the first transaction to read the During the process of target data, it is prohibited to perform operations that update the target data included in other transactions;
    执行所述第一事务包括的操作以读取所述目标数据。Execute operations included in the first transaction to read the target data.
  6. 根据权利要求1所述的方法,其特征在于,所述第一事务包括多个操作,每个操作分别针对相应的目标数据,多个目标数据包括的第一目标数据被所述第二事务占用,所述多个操作按执行顺序排列,所述执行所述第一事务包括的操作以处理所述目标数据,包括:The method of claim 1, wherein the first transaction includes a plurality of operations, each operation is directed to corresponding target data, and the first target data included in the plurality of target data is occupied by the second transaction. , the plurality of operations are arranged in order of execution, and the execution of operations included in the first transaction to process the target data includes:
    响应于在第一时间间隔内完成所述第二事务的处理结果的提交,在所述第二事务的处理结果被提交后,执行所述第一事务包括的处理所述第一目标数据的第一操作,执行所述第一事务包括的执行顺序在所述第一操作之后的操作;In response to completing the submission of the processing result of the second transaction within the first time interval, after the processing result of the second transaction is submitted, executing the first step of processing the first target data included in the first transaction. An operation to perform operations included in the first transaction whose execution order is after the first operation;
    响应于在所述第一时间间隔内未完成所述第二事务的处理结果的提交,则在所述第一时间间隔后,重新执行所述第一事务包括的执行顺序在第一操作之前的操作;响应于所述第一操作执行完成,执行所述第一事务包括的执行顺序在所述第一操作之后的操作。In response to the submission of the processing result of the second transaction not being completed within the first time interval, after the first time interval, re-execute the first transaction including an execution sequence before the first operation. Operation: In response to completion of execution of the first operation, execute operations included in the first transaction in an execution sequence after the first operation.
  7. 根据权利要求1-3,6任一所述的方法,其特征在于,所述第一事务的隔离类型为快照隔离,所述第一事务包括的操作为读取多个时间版本的目标数据中与目标时间戳对应的目标版本数据,所述执行所述第一事务包括的操作以处理所述目标数据,包括:The method according to any one of claims 1-3 and 6, characterized in that the isolation type of the first transaction is snapshot isolation, and the operation included in the first transaction is to read multiple time versions of the target data. Target version data corresponding to the target timestamp, and performing operations included in the first transaction to process the target data include:
    确定所述目标数据的多个差分版本的数据,所述多个差分版本包括所述目标时间戳对应的差分版本以及在所述目标时间戳对应的时间之前形成的差分版本,所述差分版本指任一事务包括的更新操作对所述目标数据进行更新的内容;Determine the data of multiple differential versions of the target data. The multiple differential versions include the differential version corresponding to the target timestamp and the differential version formed before the time corresponding to the target timestamp. The differential version refers to The update operation included in any transaction updates the content of the target data;
    合并所述目标数据的基础版本与所述多个差分版本的数据,得到所述多个数据版本的目标数据中与所述目标时间戳对应的目标版本数据。Merge the basic version of the target data and the data of the multiple differential versions to obtain the target version data corresponding to the target timestamp among the target data of the multiple data versions.
  8. 根据权利要求7所述的方法,其特征在于,所述方法还包括:The method of claim 7, further comprising:
    基于合并时间间隔,定期对所述目标数据的基础版本与所述目标数据的差分版本的数据进行合并,得到合并后的数据,所述合并后的数据用于更新所述目标数据的基础版本。Based on the merging time interval, the base version of the target data and the differential version of the target data are merged regularly to obtain merged data, and the merged data is used to update the base version of the target data.
  9. 一种事务处理的装置,其特征在于,所述装置包括:A transaction processing device, characterized in that the device includes:
    检测模块,用于检测第一事务针对的目标数据是否被第二事务所占用,所述第一事务包括处理所述目标数据的操作,所述第二事务是与所述第一事务并行的其他事务;A detection module, configured to detect whether the target data targeted by the first transaction is occupied by a second transaction, the first transaction includes an operation of processing the target data, and the second transaction is other parallel transactions with the first transaction. affairs;
    执行模块,用于响应于所述目标数据被所述第二事务所占用,根据所述第二事务对所述目标数据的占用类型和所述第一事务包括的处理所述目标数据的操作的类型,执行所述第一事务包括的操作以处理所述目标数据。Execution module, configured to respond to the target data being occupied by the second transaction, and perform an operation based on the occupation type of the target data by the second transaction and the operation of processing the target data included in the first transaction. Type, perform operations included in the first transaction to process the target data.
  10. 一种电子设备,其特征在于,所述电子设备包括处理器和存储器,所述存储器中存储有至少一条程序代码或指令,所述至少一条程序代码或指令由所述处理器加载并执行,以使所述电子设备实现权利要求1-8任一所述的事务处理方法。An electronic device, characterized in that the electronic device includes a processor and a memory, at least one program code or instruction is stored in the memory, and the at least one program code or instruction is loaded and executed by the processor to The electronic device is allowed to implement the transaction processing method described in any one of claims 1-8.
PCT/CN2022/144419 2022-05-07 2022-12-31 Transaction processing method and apparatus, and electronic device WO2023216636A1 (en)

Applications Claiming Priority (2)

Application Number Priority Date Filing Date Title
CN202210495253.5A CN115292335A (en) 2022-05-07 2022-05-07 Transaction processing method and device and electronic equipment
CN202210495253.5 2022-05-07

Publications (1)

Publication Number Publication Date
WO2023216636A1 true WO2023216636A1 (en) 2023-11-16

Family

ID=83820230

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2022/144419 WO2023216636A1 (en) 2022-05-07 2022-12-31 Transaction processing method and apparatus, and electronic device

Country Status (2)

Country Link
CN (1) CN115292335A (en)
WO (1) WO2023216636A1 (en)

Families Citing this family (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115292335A (en) * 2022-05-07 2022-11-04 北京大学 Transaction processing method and device and electronic equipment

Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7269588B1 (en) * 2003-09-24 2007-09-11 Oracle International Corporation Neighborhood locking technique for increasing concurrency among transactions
CN104679881A (en) * 2015-03-13 2015-06-03 华为技术有限公司 Concurrency control method and concurrency control device
CN110888717A (en) * 2019-11-05 2020-03-17 中盈优创资讯科技有限公司 Transaction control method and device for directory operation of HDFS (Hadoop distributed File System)
CN111475262A (en) * 2020-04-02 2020-07-31 百度国际科技(深圳)有限公司 Transaction request processing method, device, equipment and medium in block chain
CN111984379A (en) * 2020-07-14 2020-11-24 上海金仕达软件科技有限公司 Read-write transaction control method, system, terminal device and storage medium
CN112463311A (en) * 2021-01-28 2021-03-09 腾讯科技(深圳)有限公司 Transaction processing method and device, computer equipment and storage medium
CN115292335A (en) * 2022-05-07 2022-11-04 北京大学 Transaction processing method and device and electronic equipment

Patent Citations (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7269588B1 (en) * 2003-09-24 2007-09-11 Oracle International Corporation Neighborhood locking technique for increasing concurrency among transactions
CN104679881A (en) * 2015-03-13 2015-06-03 华为技术有限公司 Concurrency control method and concurrency control device
CN110888717A (en) * 2019-11-05 2020-03-17 中盈优创资讯科技有限公司 Transaction control method and device for directory operation of HDFS (Hadoop distributed File System)
CN111475262A (en) * 2020-04-02 2020-07-31 百度国际科技(深圳)有限公司 Transaction request processing method, device, equipment and medium in block chain
CN111984379A (en) * 2020-07-14 2020-11-24 上海金仕达软件科技有限公司 Read-write transaction control method, system, terminal device and storage medium
CN112463311A (en) * 2021-01-28 2021-03-09 腾讯科技(深圳)有限公司 Transaction processing method and device, computer equipment and storage medium
CN115292335A (en) * 2022-05-07 2022-11-04 北京大学 Transaction processing method and device and electronic equipment

Also Published As

Publication number Publication date
CN115292335A (en) 2022-11-04

Similar Documents

Publication Publication Date Title
US11321303B2 (en) Conflict resolution for multi-master distributed databases
CN109739935B (en) Data reading method and device, electronic equipment and storage medium
JP6346376B2 (en) Scalable log-based transaction management
CN111143389B (en) Transaction execution method and device, computer equipment and storage medium
WO2022161308A1 (en) Transaction processing method and apparatus, computer device, and storage medium
US10250693B2 (en) Idempotence for database transactions
US9317372B1 (en) Dynamic membership management in a distributed system
US8364634B2 (en) System and method for processing fault tolerant transaction
US8924346B2 (en) Idempotence for database transactions
EP3726365B1 (en) Data processing method and device
WO2022111188A1 (en) Transaction processing method, system, apparatus, device, storage medium, and program product
US6434710B1 (en) Commit controlling scheme for transaction processing in system utilizing check point/roll back scheme
WO2021036768A1 (en) Data reading method, apparatus, computer device, and storage medium
CN110413687B (en) Distributed transaction fault processing method and related equipment based on node interaction verification
US20230110826A1 (en) Log execution method and apparatus, computer device and storage medium
CN109783578B (en) Data reading method and device, electronic equipment and storage medium
CN112084161A (en) Database-based data processing method and device and readable storage medium
WO2023216636A1 (en) Transaction processing method and apparatus, and electronic device
CN113010549A (en) Data processing method based on remote multi-active system, related equipment and storage medium
US11449241B2 (en) Customizable lock management for distributed resources
Zhou et al. GeoGauss: Strongly Consistent and Light-Coordinated OLTP for Geo-Replicated SQL Database
CN114846458A (en) Distributed serializable concurrency control scheme
Chhatrapati Towards Achieving Stronger Isolation in Serverless Computing
JP2002297422A (en) Network system, main memory resident data management method and recording medium
Bista Performance Study of Replica Concurrency Control Algorithms For Distributed Databases

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: 22941568

Country of ref document: EP

Kind code of ref document: A1