Transaction processing method, apparatus and electronic device
By detecting and managing the target data occupancy of database transactions, the problem of synchronization mechanism limitation in parallel transaction processing is solved, and transaction processing efficiency and system throughput are improved.
Patent Information
- Application Number
- CN202210495253.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-07
- Publication Date
- 2025-07-01
- Estimated Expiration
- 2042-05-07
AI Technical Summary
When multiple transactions are processed in parallel in the database, the synchronization mechanism limits lead to frequent system calls, affecting transaction processing efficiency and system throughput, and transactions are prone to waiting indefinitely and processing time is long.
By detecting whether the target data is occupied by other transactions, and performing transaction operations to process the target data according to the occupation type and transaction operation type, avoiding system calls to control parallel transaction processing.
Improve transaction processing efficiency, increase system throughput, avoid indefinite waiting of transactions, and improve system performance.
Smart Images

Figure CN115292335B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of database technology, and in particular, to a transaction processing method, apparatus, and electronic device. Background Art
[0002] A transaction refers to a program execution unit that accesses a database and may update various data in the database. A transaction includes at least one operation for processing at least one piece of data. In the field of database technology, there is a transaction processing method that executes the operations included in each transaction based on the data in the database.
[0003] In the related art, when multiple transactions are processed in parallel based on the data in the database, a synchronization mechanism is required to limit the data being processed to ensure that any piece of data is only processed by the operations in one transaction at the same time. This process is based on system calls and requires frequent access to the interfaces of programs running in the kernel mode to access the corresponding data. This process involves a large number of instruction call processes, affecting the transaction processing efficiency and system throughput; and when any transaction needs to access data being processed by other transactions, the transaction is prone to an indefinite waiting situation, with a long transaction processing time, resulting in low transaction processing efficiency. Summary of the Invention
[0004] Embodiments of this application provide a transaction processing method, apparatus, and electronic device to achieve efficient management of the transaction processing process.
[0005] On the one hand, a transaction processing management method is provided, and the method includes:
[0006] Detect whether the target data targeted by the first transaction is occupied by the second transaction, where the first transaction includes an operation for processing the target data, and the second transaction is another transaction parallel to the first transaction;
[0007] In response to the target data being occupied by the second transaction, execute the operation 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 the operation for processing the target data included in the first transaction.
[0008] In a possible implementation manner, the detecting whether the target data targeted by the first transaction is occupied by the second transaction includes:
[0009] Read the indication information carried by the target data, where the indication information includes the transaction number of the transaction that occupies the target data; if the transaction number included in the indication information is the transaction number of the second transaction, it is determined that the target data is occupied by the second transaction.
[0010] 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 type of the operation included in the first transaction for processing the target data, performing the operations included in the first transaction to process the target data includes:
[0011] In response to the target data being occupied by the second transaction and the operation included in the first transaction for processing the target data being an update operation, after the processing result of the second transaction is committed, updating the target data according to the operation included in the first transaction;
[0012] In response to the target data being occupied by the second transaction and the operation included in the first transaction for processing the target data being a read operation, reading the target data according to the occupation type of the target data by the second transaction and the operation included in the first transaction.
[0013] In a possible implementation, the reading the target data according to the occupation type of the target data by the second data and the operation included in the first transaction includes:
[0014] Determining the occupation type of the target data by the second transaction;
[0015] In response to the occupation type indicating that during the process of the second transaction occupying the target data, operations including updating and reading the target data by other transactions except the second transaction are prohibited, after the processing result of the second transaction is committed, performing the operations included in the first transaction to read the target data according to the isolation level of the first transaction, and 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.
[0016] In a possible implementation, the operation included in the first transaction for processing the target data is an update operation, and the performing the operations included in the first transaction to process the target data includes:
[0017] Setting the indication information of the target data, where the indication information includes the transaction number and occupation type of the first transaction, and the occupation type indicates that during the process of performing the operations included in the first transaction to update the target data, operations including reading or updating the target data by other transactions are prohibited; performing the operations included in the first transaction to update the target data.
[0018] 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 executing the operations included in the first transaction according to the isolation level of the first transaction to read the target data includes:
[0019] Set the indication information of the target data, where the indication information includes the transaction number and occupancy type of the first transaction, and the occupancy type indicates that during the process of executing the operations included in the first transaction to read the target data, the operations of other transactions to update the target data are prohibited; execute the operations included in the first transaction to read the target data.
[0020] In a possible implementation, the first transaction includes multiple operations, each operation is respectively directed to corresponding target data, and the first target data included in the multiple target data is occupied by the second transaction. The multiple operations are arranged in the execution order. Executing the operations included in the first transaction to process the target data includes:
[0021] In response to the submission of the processing result of the second transaction being completed within the first time interval, after the processing result of the second transaction is submitted, execute the first operation of the first transaction to process the first target data, and execute the operations included in the first transaction that are after the first operation in the execution order;
[0022] 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-execute the operations included in the first transaction that are before the first operation in the execution order; in response to the completion of the execution of the first operation, execute the operations included in the first transaction that are after the first operation in the execution order.
[0023] 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 multiple time versions of the target data. Executing the operations included in the first transaction to process the target data includes:
[0024] Determine the differential version data of the target data, where the multiple differential versions include the differential version corresponding to the target timestamp and the differential versions formed before the time corresponding to the target timestamp, and the differential version refers to the content of the update operation included in any transaction to update the target data; merge the base version of the target data with the multiple differential version data to obtain the target version data corresponding to the target timestamp among the multiple data versions of the target data.
[0025] In a possible implementation, the method further includes:
[0026] Based on the merge time interval, regularly merge the data of the base version of the target data and the differential version of the target data to obtain the merged data, and the merged data is used to update the base version of the target data.
[0027] On the one hand, a transaction processing apparatus is provided, and the apparatus includes:
[0028] A detection module, configured to detect whether the target data targeted by the first transaction is occupied by the second transaction, where the first transaction includes an operation for processing the target data, and the second transaction is another transaction parallel to the first transaction;
[0029] An execution module, configured to, 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 the operations included in the first transaction for processing the target data.
[0030] In a possible implementation, the detection module is configured to read the indication information carried by the target data, where the indication information includes the transaction number of the transaction that occupies the target data; if the transaction number included in the indication information is the transaction number of the second transaction, it is determined that the target data is occupied by the second transaction.
[0031] In a possible implementation, the execution module is configured to, in response to the target data being occupied by the second transaction and the operation for processing the target data included in the first transaction being an update operation, update the target data according to the operation included in the first transaction after the processing result of the second transaction is submitted; in response to the target data being occupied by the second transaction and the operation for processing the target data included in the first transaction being a read operation, read the target data according to the occupation type of the target data by the second transaction and the operation included in the first transaction.
[0032] 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 indicating that during the process of the second transaction occupying the target data, other transactions except the second transaction are prohibited from updating and reading the target data, after the processing result of the second transaction is submitted, execute the operations included in the first transaction to read the target data according to the isolation level of the first transaction, and 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.
[0033] In a possible implementation, the operation for processing the target data included in the first transaction is an update operation. The execution module is configured to set indication information of the target data, where the indication information includes the transaction number and occupancy type of the first transaction, and the occupancy type indicates that during the execution of the operation included in the first transaction to update the target data, the operations of reading or updating the target data included in other transactions are prohibited; and execute the operation included in the first transaction to update the target data.
[0034] In a possible implementation, the operation for 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 module is configured to set indication information of the target data, where the indication information includes the transaction number and occupancy type of the first transaction, and the occupancy type indicates that during the execution of the operation included in the first transaction to read the target data, the operation of updating the target data included in other transactions is prohibited;
[0035] Execute the operation included in the first transaction to read the target data.
[0036] In a possible implementation, the first transaction includes multiple operations, each operation is respectively directed to a corresponding target data, and the first target data among the multiple target data is occupied by the second transaction. The multiple operations are arranged in the execution order. The execution module is configured to, in response to the submission of the processing result of the second transaction being completed within the first time interval, after the processing result of the second transaction is submitted, execute the first operation for processing the first target data included in the first transaction, and execute the operations included in the first transaction that are after the first operation in the execution order; 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-execute the operations included in the first transaction that are before the first operation in the execution order; and in response to the completion of the execution of the first operation, execute the operations included in the first transaction that are after the first operation in the execution order.
[0037] In a possible implementation, the isolation type of the first transaction is snapshot isolation. The operations included in the first transaction are to read the target version data corresponding to the target timestamp from the target data of multiple time versions. The execution module is configured to 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 versions formed before the time corresponding to the target timestamp. The differential version refers to the content of the update operation included in any transaction for updating the target data. Merge the base version of the target data with the data of the multiple differential versions to obtain the target version data corresponding to the target timestamp in the target data of the multiple data versions.
[0038] In a possible implementation, the apparatus further includes:
[0039] A merge module, configured to periodically merge the base version of the target data with the data of the differential version of the target data based on a merge time interval to obtain merged data, and the merged data is used to update the base version of the target data.
[0040] 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 and is loaded and executed by the processor to enable the electronic device to implement any one of the above transaction processing methods.
[0041] 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, and the program code is loaded and executed by the processor to enable a computer to implement any one of the above transaction processing methods.
[0042] 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, and the at least one computer instruction is loaded and executed by the processor to enable a computer to implement any one of the above transaction processing methods.
[0043] The technical solution provided by the embodiments of the present application processes the target data based on the occupation type of the target data by the second transaction parallel to the first transaction and the operations included in the first transaction by detecting the occupation situation of the target data by the second transaction parallel to the first transaction. This process realizes the processing of parallel transactions based on the detection of the target data, and there is no need for system calls to control the scenario where the parallel first transaction and second transaction process the same target data, avoiding frequent entry into the operating system kernel state, improving the transaction processing efficiency, and improving the system throughput. Description of the Drawings
[0044] Figure 1A schematic diagram of an implementation environment provided by an embodiment of the present application;
[0045] Figure 2 A flowchart of a transaction processing provided by an embodiment of the present application;
[0046] Figure 3 A schematic diagram of data storage provided by an embodiment of the present application;
[0047] Figure 4 A schematic diagram of the structure of a server provided by an embodiment of the present application;
[0048] Figure 5 A schematic diagram of an online transaction processing interface provided by an embodiment of the present application;
[0049] Figure 6 A schematic diagram of a command - line transaction processing interface provided by an embodiment of the present application;
[0050] Figure 7 A schematic diagram of an interface transaction processing interface provided by an embodiment of the present application;
[0051] Figure 8 A schematic diagram of a transaction processing device provided by an embodiment of the present application;
[0052] Figure 9 A schematic diagram of an electronic device provided by an embodiment of the present application. Detailed implementation manners
[0053] In order to enable those skilled in the art to better understand the technical solutions in the present application, the following will describe some embodiments of the present application 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 meaning as commonly understood by those skilled in the art, and are only used to explain the embodiments of the present application, rather than aiming to limit the present application.
[0054] See 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 be communicatively connected to achieve the interactive transmission of information. The embodiment of the present application does not limit the connection manner between the terminal 11 and the server 12. In the embodiment of the present application, the terminal 11 submits a start request for a transaction to the server 12, and the server 12 executes the operations included in the transaction to process the data targeted by the transaction, and then sends the processing result to the terminal 11. In addition, the terminal 11 also sends the instructions generated during the interaction process to the server 12.
[0055] The terminal 11 can be any kind of electronic product that can perform human-computer interaction with users in one or more ways such as a keyboard, a touchpad, a touch screen, voice interaction, etc., such as a PC (Personal Computer), a mobile phone, a PPC (Pocket Personal Computer), a tablet computer, a vehicle-mounted computer, etc. The server 12 can be a single server, a server cluster composed of multiple servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms.
[0056] Those skilled in the art should understand that the above-mentioned terminal 11 and server 12 are only examples. Other existing or future terminal or server that can be used in this application should also be included within the protection scope of this application and are hereby incorporated by reference.
[0057] The embodiments of this application are applied to the field of database technology and are applicable to scenarios where data is managed based on operations in each transaction. Exemplarily, the transaction processing method of this application can be applied to the Resource Description Framework (RDF), and transaction processing is performed based on a large amount of RDF data included in the RDF database. The current RFF 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 may update various data in a database. A transaction includes at least one operation for processing at least one piece of data.
[0058] Database transactions need to satisfy four characteristics: Atomicity, Consistency, Isolation, and Durability.
[0059] Atomicity: A transaction is an indivisible whole. All operations included in a transaction only exist in two situations: either all are completed or none are executed, and there will be no situation where only part of the operations are executed. When an exception occurs during the process of performing operations on data, the data is restored to the state before the transaction started, and this process can be called rollback.
[0060] Consistency: Before and after the start and end of a transaction, the integrity constraints of the database are not violated, and the integrity of the data in the database remains consistent. For example: The balance of user A's account is 1000 yuan, and the balance of user B's account is 2900 yuan. Run a transaction where user A transfers 100 yuan to user B. After the transfer is completed, the balance of user A's account is 900, and the balance of user B's account is 3000. Before and after the transfer, the sum of the balances of user A and B's accounts remains unchanged at 3900 yuan.
[0061] Isolation: It means that at the same time, only the operations in one transaction are allowed to process the same data, and different transactions do not interfere with each other. Exemplarily, for the same data, user A and user B respectively start transaction 1 and transaction 2, and transaction 1 and transaction 2 are executed in parallel. Therefore, transaction 1 and transaction 2 need to 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 does not feel that there is transaction 2 executing in parallel with transaction 1.
[0062] Durability: After a transaction is completed, all updates to the data in the database by the operations in the transaction will be persistently saved to the database. After the transaction is successfully completed, even if a hardware failure or database crash occurs, the written data will not be lost.
[0063] See the appendix Figure 2 , the embodiments of the present application provide a flowchart of a transaction processing method. This method can be applied to a server. This method includes but is not limited to the following steps 201-202.
[0064] Step 201, detect whether the target data targeted by the first transaction is occupied by the second transaction. The first transaction includes operations for processing the target data, and the second transaction is another transaction that is parallel to the first transaction.
[0065] When a user starts the first transaction, there may be other transactions started by other users in the system that are parallel to the current first transaction. During the parallel processing of multiple transactions, it is easy to have situations where the operations included in different transactions update or read the same data. To ensure the accuracy of the transaction processing results, in some possible implementation manners, the operations included in different transactions cannot process the same target data simultaneously. Therefore, when the operations included in any transaction need to process the target data, it should be determined whether the target data is occupied by other transactions, and then it is determined whether to directly execute the operations included in the any transaction or wait for the other transaction that occupies the target data to end and then execute the operations included in that transaction.
[0066] In a 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 occupying the target data; and determining that the target data is occupied by the second transaction based on the transaction number included in the indication information being the transaction number of the second transaction.
[0067] In the embodiments of the present application, each transaction corresponds to a corresponding transaction number, and the transaction numbers of each transaction are unique. Exemplarily, the transaction number is randomly assigned by the server and stored in the transaction list for management.
[0068] 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 for the first transaction, and assigns a corresponding transaction number to the first transaction. Optionally, the reception of the start request and the assignment of the transaction number can be executed by the transaction scheduling processor in the server.
[0069] Exemplarily, the assignment of the transaction number is determined by a strictly increasing atomic counter to ensure the uniqueness of the transaction number of each transaction, and the relative order in which the multiple transactions are started can be determined based on the transaction numbers of the multiple transactions. Exemplarily, the transaction number of each transaction can be a 64-bit code.
[0070] In the embodiments of the present application, when starting the first transaction, the first transaction includes an 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, it means that the target data has not been occupied by other transactions, and the operation included in the first transaction can process the target data; if the indication information is not empty, then determine the transaction number included in the indication information, and the transaction label included in the indication information is the transaction number of the transaction currently occupying the target data. Exemplarily, when the current transaction occupies the target data, execute the update operation included in the current transaction that is currently occupying the target data to update the target data. Exemplarily, 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 execute the following step 202 to implement the processing of the target data by the operation included in the first transaction.
[0071] In step 201, the method for 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. Exemplarily, the server can 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. Among them, the instructions of each operation included in the first transaction are determined and submitted by the user at the terminal. The start request of the first transaction carries the information of the target data to be processed by the operations in the transaction. For example, the information of 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.
[0072] Step 202, 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 the operation for processing the target data included in the first transaction, execute the operations included in the first transaction to process the target data.
[0073] The target data being occupied by the second transaction means that during the process of the operations included in the second transaction processing the target data, the operations included in other transactions are restricted from processing the target data. Different occupation types have different restrictions on the operations included in other transactions. The restriction methods corresponding to the occupation types include, but are not limited to: the first occupation type, used to indicate that during the process of the target data being occupied by the second transaction, the update operations included in other transactions are prohibited from processing the target data; or, the second occupation type, used to indicate that during the process of the target data being occupied by the second transaction, in addition to prohibiting the update operations included in other transactions from processing the target data, the read operations included in other transactions are also prohibited from processing the target data.
[0074] In the embodiments of the present application, any transaction can include operations for processing target data. The types of these operations include, but are not limited to, updating or reading the data. The read operations include, but are not limited to, obtaining the data and obtaining the relevant information of the data; the update operations include, but are not limited to, adding, modifying, deleting, etc. of the data.
[0075] The embodiments of the present application do not limit the storage form of the data, etc. Exemplarily, the data can be stored in various forms such as numerical values, texts, pictures, etc.; then the update operation can include performing addition and subtraction calculations on any data in numerical form.
[0076] Any transaction can include one or more operations. When a transaction includes one operation, the corresponding operation is performed on one 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 multiple operations included in the data have a certain execution order. Exemplarily, in a transfer operation, in the transaction of "User A transfers X yuan to User B", it includes two operations of updating different data: reducing the deposit value in User A's account by X and increasing the deposit value in User B's account by X, and the execution order of these two operations is determined.
[0077] In a possible implementation manner, in response to the target data being occupied by a second transaction, and the operation included in the first transaction for processing the target data being an update operation, after the processing result of the second transaction is committed, the target data is updated according to the operation included in the first transaction.
[0078] In a possible implementation manner, when the operation included in the first transaction for processing the target data is an update operation, the process of executing the operation included in the first transaction to update the target data includes: setting the indication information of the target data, where the indication information includes the transaction number and occupancy type of the first transaction, and the occupancy type indicates that during the process of executing the operation 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; executing the operation included in the first transaction to update the target data.
[0079] In the embodiments of the present application, the current transaction occupying any data does not allow the operations included in other transactions to update the 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 operation included in the first transaction is to update the target data, and the target data is occupied by the parallel second transaction, regardless of whether the operation included in the second transaction reads or updates the target data, the operation included in the first transaction for the target data cannot be executed, but the update operation included in the first transaction for the target data needs to be executed after the processing result of the second transaction is committed. Among them, after the processing result of the second transaction is committed, the second transaction ends, the second transaction no longer occupies the target data, and the indication information of the target data is restored to be empty.
[0080] In a possible implementation manner, in response to the target data being occupied by a second transaction, and the operation included in the first transaction for processing the target data being a read operation, the target data is read according to the occupancy type of the second transaction for the target data and the operation included in the first transaction.
[0081] The occupation type of the second transaction for the target data has multiple forms. Different occupation types correspond to different restrictive conditions, and different restrictive conditions have different regulations on the operations included in other transactions for processing the target data. Therefore, the operations included in the first transaction are executed according to the occupation type of the second transaction for the target data to read the target data.
[0082] In a possible implementation manner, the occupation type of the second transaction for the target data is determined; 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, after the processing result of the second transaction is committed, the operations included in the first transaction are executed according to the isolation level of the first transaction to read the target data.
[0083] 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, the operations included in the first transaction are directly executed according to the isolation level of the first transaction to read the target data.
[0084] Wherein, 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.
[0085] Embodiments of the present 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 execution manner of the read operations included in the transaction is different, and the update manner of the indication information of the data read by the operations included in the transaction is different.
[0086] The read operations included in a transaction running at the read committed isolation level can read the updated content of a transaction that has committed the processing result and return the latest version corresponding to the data targeted by the read operation. The update operations included in a transaction running at the read committed isolation level can update the indication information corresponding to the data targeted by the update operation, 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 be used to set the occupation type of the transaction for 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 of the second occupation type indicating that the transaction occupies the data is the process of executing the update operation included in the transaction to update the data.
[0087] The read operations included in a transaction running at the snapshot isolation level can read the version corresponding to the timestamp among multiple versions of the data targeted by the read operation. The update operations included in a transaction running at 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 occupancy type of the transaction for the data to a second occupancy 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 of the transaction occupying the data indicated by the second occupancy type is the process of executing the update operation included in the transaction to update the data.
[0088] The read operations included in a transaction running at the serializable isolation level can read the update content of a transaction that has submitted the processing result 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 to include the transaction number of the transaction to indicate that the data is occupied by the transaction, and is also used to set the occupancy type of the transaction for the data to a first occupancy type to indicate that during the process of the transaction occupying the data, operations included in other transactions are prohibited from updating the data. At this time, the process of the transaction occupying the data indicated by the first occupancy type is the process of executing the read operation included in the transaction to read the data.
[0089] The update operations included in a transaction running at the serializable isolation level can update the indication information corresponding to the data targeted by the update operation, 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 is also used to set the occupancy type of the transaction for the data to a second occupancy 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 of the transaction occupying the data indicated by the second occupancy type is the process of executing the update operation included in the transaction to update the data.
[0090] In a possible implementation, the operation for processing target data included in the first transaction is a read operation, and the isolation level of the first transaction is serializable. Then, according to the isolation level of the first transaction, execute the operations included in the first transaction to read the target data, including but not limited to: setting the indication information of the target data, where the indication information includes the transaction number and occupancy type of the first transaction, and the occupancy type indicates that during the process of executing the operations included in the first transaction to read the target data, operations included in other transactions for updating the target data are prohibited; execute the operations included in the first transaction to read the target data.
[0091] In a possible implementation, before performing step 201, set the corresponding isolation level for the first transaction to be started, and then submit a start request including the isolation level to the server. After receiving the start request, the server starts the first transaction and executes the operations included in the first transaction.
[0092] In actual processing, according to the different processing requirements corresponding to different transactions, set the corresponding isolation level for the transaction to be started. The processing requirements may be the requirements for the consistency of the database state. Exemplarily, if the processing requirement corresponding to the transaction to be started is to obtain a strongly consistent database state, then set the isolation level corresponding to the transaction to serializable; or, if the processing requirement corresponding to the transaction to be started is not strict about the consistency of the database state, then set the isolation level corresponding to the transaction to snapshot isolation or read committed.
[0093] In a possible implementation, the first transaction includes multiple operations, each operation is respectively directed to the corresponding target data, and the first target data included in the multiple target data is occupied by the second transaction. If the multiple operations are arranged in the execution order, then the process of executing the operations included in the first transaction to process the target data in step 202 includes but is not limited to:
[0094] In response to the submission of the processing result of the second transaction being completed within the first time interval, after the processing result of the second transaction is submitted, execute the first operation included in the first transaction to process the first target data, and execute the operations included in the first transaction that are after the first operation in the execution order; 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-execute the operations included in the first transaction that are before the first operation in the execution order; in response to all the operations included in the first transaction being executed, submit the processing result of the first transaction.
[0095] In this possible implementation, the first transaction and the second transaction are processed in parallel, and the operations included in each transaction are executed in sequence according to the execution order. When any operation in the first transaction is directed to target data that 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 operations included in the first transaction are in a waiting state.
[0096] In this case, starting from when waiting for the operations included in the first transaction begins, record the waiting time of the operations included in the first transaction. 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, execute the first operation of processing the first target data included in the first transaction, and then execute the operations included in the first transaction whose execution order is 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, then after the waiting time reaches the first time interval, starting from the operation ranked first in the execution order of the multiple operations included in the first transaction, re-execute the multiple operations included in the first transaction; when re-executing to the first operation, if the waiting time of the first transaction during the re-execution does not exceed the first time again, then after the first operation is executed, sequentially execute the other operations included in the first transaction according to the execution order.
[0097] In a possible implementation manner, 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, then re-re-execute the operations included in the first transaction again according to the execution order. When the number of re-executions exceeds the repetition threshold, feedback a message indicating that the execution of the first transaction fails to the terminal. Among them, the setting of the repetition threshold can be determined according to the nature of the first transaction or can be preset, and the present application does not limit the setting of the value of the repetition threshold.
[0098] In the above scenario of repeatedly executing the operations included in the first transaction, the first time interval increases with the increase in the number of repeated executions. In a possible implementation manner, 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 manner, the increase in the first time interval makes the waiting time in each execution continuously extend, which can reduce the number of repeated executions, reduce the computational complexity, and reduce resource consumption.
[0099] Exemplarily, the first transaction is executed in parallel with the second transaction. 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 first operation pauses execution and waits for the second transaction to complete processing. After the first time interval t, if the second transaction has not committed the processing result, all the 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 that of the first time interval in the previous execution, that is, 2t. If during the waiting time of 2t, the processed data of the second transaction is committed, the first operation and other operations included in the first transaction are continued to be executed; if the second transaction has not been completed within the time of 2t, all the operations included in the first transaction are re-executed again. During the second re-execution, the first time interval is 4t. If the first operation still cannot be executed during the second re-execution, it loops into the third re-execution process until the first operation is completed, and then continues to execute other operations included in the first transaction; or until the number of re-executions exceeds the repetition threshold, a message indicating the failure of the first transaction execution is fed back to the terminal.
[0100] 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 in the target data of multiple time versions. Then, performing the operations included in the first transaction in step 202 to process the target data includes, but is not limited to:
[0101] Determining the data of multiple differential versions of the target data, where the multiple differential versions include the differential version corresponding to the target timestamp and the differential versions formed before the time corresponding to the target timestamp. The differential version refers to the content of the update operation included in any transaction to update the target data; merging the base data of the target data with 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.
[0102] In a possible implementation, merging the base data of the target data with the data of multiple differential versions may include: after obtaining the base version and multiple differential versions of the target data, updating the base data in sequence according to the time sequence corresponding to the differential versions to obtain the target version data.
[0103] In a possible implementation, merging the base data of the target data with the data of multiple differential versions may include: after obtaining the base version and multiple differential versions of the target data, performing deduplication and merging processing on all the obtained differential versions to obtain the merged result of the differential versions; merging the merged result with the base data to obtain the target version data.
[0104] In the embodiments of the present application, to save storage space, the base data of each data and the corresponding differential versions are stored according to the differential versioning method. Each differential version of each data corresponds to the content of the update operation included in the transaction for updating the data. Exemplarily, for an update operation of adding data N to a data M, the base data M and the differential version "add N" generated based on the updated data content are stored. Optionally, the present application may also directly store the updated target data. Exemplarily, "data M+N" is stored.
[0105] Each differential version corresponds to a different timestamp, which 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 generating the differential version belongs. Exemplarily, the representation form of the timestamp can be [start time, end time). This timestamp is generated based on both 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 order of the transaction corresponding to the differential version determined by applying a logical counter. The count of this logical counter increases during the start-up process of each transaction. This way of determining the timestamp can achieve the combination of logical order and physical order.
[0106] Exemplarily, transaction 1 and transaction 2 are successively started. Due to the influence of the time value accuracy, the start times of both transaction 1 and transaction 2 are recorded as 20:18:30. Then, only based on the physical time, the order of transaction 1 and transaction 2 cannot be determined. And the logical time can record the order of start of each transaction based on the count of the counter. Therefore, the method of combining physical time and logical time to determine the timestamp of the differential version in the embodiments of the present application can obtain a more accurate timestamp, can more accurately obtain the data required when performing the operations included in each transaction, and is beneficial to improving the transaction processing efficiency.
[0107] See 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 list. It includes a published version and differential versions 1-n. Exemplarily, in differential version 1, it corresponds to the timestamp [0, TS1), where 0 and TS1 respectively correspond to the start time and end time of the transaction to which the operation forming this differential version belongs. The version header is used to indicate the start of the differential version and does not indicate specific data.
[0108] 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 [TS1, TS2), 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 perform an update merge on the basis of 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 may include the following two methods:
[0109] Method 1: Merge the basic version and differential version 1 to obtain merge result 1, and then merge merge result 1 with differential version 2 to obtain the target version data.
[0110] Method 2: Merge differential version 1 and differential version 2 to obtain the merged result of the differential version, and then merge the basic data and the differential version to obtain the target version data. In a possible implementation, the contents of differential version 1 and differential version 2 may be update methods with opposite operations. For example, if differential version 1 is to add data 1 and differential version 2 is to subtract data 1, then the merged result of the differential version is not to update the basic data. At this time, the basic data is the target version data. In this possible implementation, the number of merge calculations is reduced, the computational complexity is reduced, and the transaction processing efficiency can be improved.
[0111] In a possible implementation, based on the merge time interval, the data of the basic version of the target data and the differential version of the target data are periodically merged to obtain the merged result, and the merged data is used to update the basic version of the target data.
[0112] During the transaction processing, a corresponding differential version is generated every time the data is updated. Then, it is easy to store a large number of differential versions. The large number of differential versions occupy a large amount of storage space, and it is necessary to periodically recycle and clean up the garbage data in the data. Therefore, in a possible implementation, every time the merge time interval elapses, the basic version of the target data and a certain number of differential version data are merged to obtain the merged result, and the basic version is updated with the merged result. The number of clearances can be set based on experience or based on the scenario, and the embodiments of the present application do not limit this either.
[0113] Among them, the merge time interval can be expressed as physical time or the number of committed transactions.
[0114] When the merge time interval is expressed as physical time, calculate the time interval from the time of the last merge operation to the current time. When this time interval reaches the merge time interval, perform the merge operation. Exemplarily, set the merge time interval to 30 minutes, and then perform a merge operation every 30 minutes.
[0115] When the merge time interval is the number of committed transactions, count the number of transactions that have completed the submission of the processing result from the time of the last merge operation to the current time. When the number of transactions that have completed the submission of the processing result reaches the merge time interval, perform the merge operation. Exemplarily, set the merge time interval to 10,000, then perform a merge operation every 10,000 successfully completed transactions.
[0116] During the process of merging each base version and differential version, temporarily interrupt the access or update operation of the data in the database, and clean up the data in the database that meets the cleaning conditions.
[0117] After step 202, in response to all operations included in the first transaction being completed, submit the processing result of the first transaction based on the submission instruction, and feedback a message indicating the successful execution of the first transaction to the terminal.
[0118] In a possible implementation, the submission instruction is generated by the user triggering it on the terminal. After all operations included in the first transaction are completed, 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 processing result of the first transaction.
[0119] Exemplarily, if the user submits the first transaction as "User A transfers 100 yuan to User B", then in this transaction, the operation of reducing 100 yuan from User A's account is first executed, and then the operation of adding 100 yuan to User B's account is executed. In response to both of these update operations being completed, the server feeds back a confirmation message of "Do you confirm the transfer of 100" to the terminal. If the user issues a "Confirmation completed" instruction, a submission instruction is sent to the server, instructing the server to submit the execution result of the first transaction, that is, store the data of reducing 100 yuan from A's account and the data of adding 100 yuan to B's account in the database. The server feeds back a message of "Transfer completed" to the terminal, prompting the user that the first transaction has been successfully executed.
[0120] In a possible implementation, see Figure 4 , the server can include a transaction scheduling processor, a query processor, an executor, and a garbage collection component to implement the above transaction processing method. Among them, the transaction scheduling processor receives instructions such as the start request of the transaction, and also periodically instructs the garbage collection component to clean up useless data; the query processor is used to parse the received start request and other statements; the executor performs corresponding operations on the data in the storage layer based on the parsed statements, such as creating a new differential version or merging data during the data acquisition process.
[0121] In an exemplary embodiment of processing data by applying the above transaction processing method, any one of an online transaction processing method, a command-line transaction processing method, or an API (Application Programming Interface) interface method can be applied for implementation. Refer to Figure 5 , 6 , 7 are respectively schematic diagrams of operation interfaces obtained by implementing transaction processing in the above manner.
[0122] Figure 5 is a schematic diagram of an online transaction processing interface. It includes execution pages for two transactions. TID indicates the transaction number. Taking the transaction with transaction number 1 as an example, "insert data { <v1> <value>"20” is the instruction of the submitted transaction, and "The Result" is used to indicate the result after the successful execution of the transaction.
[0123] Figure 6 It is a schematic diagram of the command-line transaction processing interface, which includes the start instruction for the transaction numbered 4.
[0124] Figure 7 It is a schematic diagram of the interface for transaction processing through API calls. In this Figure 7 the processes of multiple transaction processing are shown.
[0125] The transaction processing method provided by the embodiments of the present application determines the occupation type of the parallel second transaction for the target data based on the indication information of the target data, and then executes the operations included in the first transaction for the target data based on the isolation level and operations included in the first transaction, 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, avoiding frequent entry into the operating system kernel mode, improving the transaction processing efficiency, and increasing the system throughput. Moreover, the application of differential version data in the embodiments of the present application reduces the occupation of storage space by data and improves the efficiency of data update.
[0126] The embodiments of the present application provide a transaction processing device, which is used to implement Figure 2 the transaction processing method shown. Refer to Figure 8 and this device includes but is not limited to:
[0127] 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 for processing the target data, and the second transaction is other transactions parallel to the first transaction;
[0128] The execution module 802 is used to, 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 the operations included in the first transaction for processing the target data.
[0129] In a possible implementation manner, the detection module 801 is used to read the indication information carried by the target data. The indication information includes the transaction number of the transaction occupying the target data; if the transaction number included in the indication information is the transaction number of the second transaction, it is determined that the target data is occupied by the second transaction.
[0130] In a possible implementation, the execution module 802 is configured to, in response to the target data being occupied by a second transaction and the operation for processing the target data included in the first transaction being an update operation, update the target data according to the operation included in the first transaction after the processing result of the second transaction is committed; and in response to the target data being occupied by a second transaction and the operation for processing the target data included in the first transaction being a read operation, read the target data according to the occupation type of the target data by the second transaction and the operation included in the first transaction.
[0131] In a possible implementation, the execution module 802 is configured to determine the occupation type of the target data by the second transaction; and in response to the occupation type indicating that during the process of the second transaction occupying the target data, operations including update and read of other transactions except the second transaction are prohibited, after the processing result of the second transaction is committed, execute the operation included in the first transaction to read the target data according to the isolation level of the first transaction, where 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.
[0132] In a possible implementation, the operation for processing the target data included in the first transaction is an update operation, and the execution module 802 is configured to set indication information of the target data, where the indication information includes the transaction number and occupation type of the first transaction, and the occupation type indicates that during the process of executing the operation included in the first transaction to update the target data, operations including read or update of other transactions are prohibited; and execute the operation included in the first transaction to update the target data.
[0133] In a possible implementation, the operation for 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 module 802 is configured to set indication information of the target data, where the indication information includes the transaction number and occupation type of the first transaction, and the occupation type indicates that during the process of executing the operation included in the first transaction to read the target data, operations including update of other transactions are prohibited; and execute the operation included in the first transaction to read the target data.
[0134] In a possible implementation, the first transaction includes multiple operations, each operation being directed to corresponding target data respectively. The first target data included in the multiple target data is occupied by the second transaction. The multiple operations are arranged in the execution order. The execution module 802 is configured to, in response to the submission of the processing result of the second transaction being completed within the first time interval, after the processing result of the second transaction is submitted, execute the first operation of processing the first target data included in the first transaction, and execute the 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, re-execute, after the first time interval, the operations included in the first transaction whose execution order is before the first operation; and in response to the completion of the execution of the first operation, execute the operations included in the first transaction whose execution order is after the first operation.
[0135] In a possible implementation, the isolation type of the first transaction is snapshot isolation. The operations included in the first transaction are to read the target version data corresponding to the target timestamp in the target data of multiple time versions. The execution module 802 is configured to 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 versions formed before the time corresponding to the target timestamp. The differential version refers to the content of the update operation included in any transaction for updating the target data; merge the base version of the target data with the data of the multiple differential versions to obtain the target version data corresponding to the target timestamp in the target data of multiple data versions.
[0136] In a possible implementation, the apparatus further includes:
[0137] A merging module, configured to periodically merge the base version of the target data with the data of the differential version of the target data based on the merging time interval to obtain the merged data, and the merged data is used to update the base version of the target data.
[0138] The transaction processing apparatus is used to execute the above-mentioned transaction processing method, without the need for system calls to control parallel transactions to process the same data, and can frequently enter the operating system kernel mode, improving the transaction processing efficiency and the throughput of the system. Moreover, the application of the differential version data reduces the occupancy of the storage space by the data and improves the efficiency of updating the data.
[0139] The embodiment of the present application provides a computer-readable storage medium, in which at least one program code or instruction is stored, and the program code or instruction is loaded and executed by a processor to enable a computer to implement any transaction processing method described in the method embodiment.
[0140] Optionally, the above computer-readable storage medium may be a read-only memory (ROM), a random access memory (RAM), a compact disc read-only memory (CD-ROM), a magnetic tape, a floppy disk, an optical data storage device, or the like.
[0141] In an exemplary embodiment, there is also provided a computer program or a computer program product, in which at least one computer instruction is stored. The at least one computer instruction is loaded and executed by a processor to enable a computer to implement any one of the above transaction processing methods.
[0142] Figure 9 FIG. 7 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 performances, and may include one or more central processing units (CPUs) 901 and one or more memories 902. Among them, 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 the transaction processing method provided by each of the above method embodiments. Of course, the electronic device 900 may also have components such as a wired or wireless network interface, a keyboard, and an input / output interface for input and output. The electronic device 900 may further include other components for implementing the functions of the device, which will not be elaborated here.
[0143] It should be noted that the information (including but not limited to user device information, user personal information, etc.), data (including but not limited to data for analysis, stored data, displayed data, etc.), and signals involved in the present application are all authorized by users or fully authorized by all parties, and the collection, use, and processing of relevant data need to comply with relevant laws, regulations, and standards of relevant countries and regions. For example, the acquisition of target data involved in the present application is obtained under full authorization.
[0144] It should be understood that in various embodiments of the present application, the magnitudes of the sequence numbers of each process do not mean the order of execution is prior or posterior. The execution order of each process should be determined according to its function and internal logic, and should not constitute any limitation to the implementation process of the embodiments of the present application.
[0145] The meaning of the term "at least one" in the present application is one or more, and the meaning of the term "multiple" in the present application is two or more.
[0146] It should be understood that the terms used in the description of the various examples herein are for the purpose of describing particular examples only and are not intended to be limiting. As used in the description of the various examples and the appended claims, the singular forms "a", "an", and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise.
[0147] It should also be understood that the term "comprises" (also referred to as "includes", "including", "comprises", and / or "comprising") when used in this specification specifies the presence of the stated features, integers, steps, operations, elements, and / or components, but does not preclude the presence or addition of one or more other features, integers, steps, operations, elements, components, and / or their groups.
[0148] It should be understood that determining B based on A does not mean determining B solely based on A, and B can also be determined based on A and / or other information.
[0149] It should also be understood that the terms "if" and "when" can 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 determined..." or "if [the stated condition or event] is detected" can be interpreted to mean "when determining..." or "in response to determining..." or "when [the stated condition or event] is detected" or "in response to detecting [the stated condition or event]".
[0150] It should also be understood that the "one embodiment", "an embodiment", and "a possible implementation" mentioned throughout the specification mean that the specific features, structures, or characteristics related to the embodiment or implementation are included in at least one embodiment of the present application. Therefore, the appearances of "in one embodiment" or "in an embodiment", "a possible implementation" throughout the specification do not necessarily refer to the same embodiment. In addition, these specific features, structures, or characteristics can be combined in one or more embodiments in any suitable manner.
[0151] The foregoing are only exemplary embodiments of the present application and are not intended to limit the present application. Any modifications, equivalent replacements, improvements, etc. made within the spirit and principles of the present application shall be included within the protection scope of the present application.< / value> < / v1>
Claims
1. A transaction processing method, characterized in that, The method includes: Detecting whether the target data targeted by the first transaction is occupied by the second transaction, where the first transaction includes an operation for processing the target data, and the second transaction is another transaction parallel to the first transaction; In response to the target data being occupied by the second transaction and the operation for processing the target data included in the first transaction being an update operation, after the processing result of the second transaction is committed, updating the target data according to the operation included in the first transaction; In response to the target data being occupied by the second transaction and the operation for processing the target data included in the first transaction being a read operation, determining the occupancy type of the second transaction for the target data; in response to the occupancy type indicating that during the period when the second transaction occupies the target data, operations included in other transactions except the second transaction are prohibited from updating and reading the target data, after the processing result of the second transaction is committed, performing the operation included in the first transaction to read the target data according to the isolation level of the first transaction, where 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.
2. The method according to claim 1, characterized in that, The operation for processing the target data included in the first transaction is an update operation, and performing the operation included in the first transaction to process the target data includes: Setting indication information of the target data, where the indication information includes the transaction number and occupancy type of the first transaction, and the occupancy type indicates that during the process of performing the operation included in the first transaction to update the target data, operations of reading or updating the target data included in other transactions are prohibited from being performed; Performing the operation included in the first transaction to update the target data.
3. The method according to claim 1, wherein The operation for processing the target data included in the first transaction is a read operation, and the isolation level of the first transaction is serializable. Performing the operation included in the first transaction to read the target data according to the isolation level of the first transaction includes: Setting indication information of the target data, where the indication information includes the transaction number and occupancy type of the first transaction, and the occupancy type indicates that during the process of performing the operation included in the first transaction to read the target data, operations of updating the target data included in other transactions are prohibited from being performed; Performing the operation included in the first transaction to read the target data.
4. The method according to claim 1, characterized in that The first transaction includes multiple operations, each operation is respectively targeted at corresponding target data, and the first target data among the multiple target data is occupied by the second transaction. The multiple operations are arranged in the execution order. Performing the operation included in the first transaction to process the target data includes: In response to the processing result of the second transaction being committed within the first time interval, after the processing result of the second transaction is committed, performing the first operation included in the first transaction to process the first target data, and performing the operation included in the first transaction whose execution order is after the first operation; In response to the failure to submit the processing result of the second transaction within the first time interval, after the first time interval, operations included in the first transaction that are before the first operation in the execution order are re-executed; in response to the completion of the execution of the first operation, operations included in the first transaction that are after the first operation in the execution order are executed.
5. The method according to any one of claims 1-4, characterized in that, 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 in the target data of multiple time versions. The operations included in the execution of the first transaction to process the target data include: Determine the differential version data of the target data. The multiple differential versions include the differential version corresponding to the target timestamp and the differential versions formed before the time corresponding to the target timestamp. The differential version refers to the content updated to the target data by the update operation included in any transaction. Merge the base version of the target data with the differential version data of the multiple differential versions to obtain the target version data corresponding to the target timestamp in the target data of multiple data versions.
6. The method according to claim 5, wherein The method further includes: Based on the merge time interval, periodically merge the base version of the target data with the differential version data of the target data to obtain the merged data, and the merged data is used to update the base version of the target data.
7. An apparatus for transaction processing, 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 operations for processing the target data, and the second transaction is another transaction parallel to the first transaction. An execution module, configured to, in response to the target data being occupied by the second transaction and the operation for processing the target data included in the first transaction being an update operation, update the target data according to the operations included in the first transaction after the processing result of the second transaction is submitted; in response to the target data being occupied by the second transaction and the operation for processing the target data included in the first transaction being a read operation, determine the occupancy type of the second transaction for the target data; in response to the occupancy type indicating that during the period when the second transaction occupies the target data, operations included in other transactions except the second transaction are prohibited from updating and reading the target data, after the processing result of the second transaction is submitted, execute the operations included in the first transaction according to the isolation level of the first transaction to read the target data, and 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.
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 enable the electronic device to implement the transaction processing method according to any one of claims 1-6.
Citation Information
Patent Citations
Cross-database distributed transaction implementation method and device
CN104793988A
Database object blocking method and device, equipment and storage medium
CN110909012A