Transaction processing method, device, equipment and storage medium
By building branch identifiers to judge the execution time of distributed transactions and performing rollback processing, the protocol blocking problem in the distributed transaction commit phase is solved, and the system throughput and availability is improved.
Patent Information
- Application Number
- CN202010615149.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-06-30
- Publication Date
- 2024-12-06
- Estimated Expiration
- 2040-06-30
AI Technical Summary
Distributed transactions are prone to protocol blocking during the commit phase, especially when the resource manager cannot obtain transaction coordinator commands, resulting in long-term locking of data tables, affecting system throughput and availability.
By obtaining the start execution time of the branch transaction and the preset timeout time of the global transaction, a branch identifier is built to judge the execution time of the branch transaction. If the timeout, a rollback processing operation is performed to release the data lock, and prevent the data table from being locked for a long time.
It effectively avoids protocol blockage, improves transaction processing throughput, and improves system availability in microservice architecture, especially when network exceptions are frequent.
Smart Images

Figure CN113872781B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a transaction processing method and device, an electronic device and a storage medium. Background Art
[0002] In the computer field, a transaction is a program execution unit that accesses and possibly updates various data items in a database. Transactions are usually written in high-level database manipulation languages or programming languages (such as SQL, C++, or Java, etc.), and consist of all operations performed between the start of a transaction (begin transaction) and the end of a transaction (end transaction). Transactions provide a mechanism to incorporate all operations involved in an activity into an indivisible execution unit. All operations that make up a transaction can only be committed if all operations can be executed normally. If any of the operations fail to execute, the entire transaction will be rolled back.
[0003] A transaction consists of all operations performed between the start of a transaction and the end of a transaction. Database transactions generally have four ACID properties, as follows:
[0004] A: Atomicity;
[0005] All operations in a transaction are either completed or not completed, and will not end at some stage in the middle. If an error occurs during the execution of a transaction, it will be rolled back to the state before the transaction started, as if the transaction had not been executed.
[0006] C: Consistency;
[0007] Transaction consistency means that the database must be in a consistent state before and after a transaction is executed. If the transaction is successfully completed, all changes in the system will be correctly applied and the system will be in a valid state. If an error occurs in the transaction, all changes in the system will be automatically rolled back and the system will return to its original state.
[0008] I: Isolation;
[0009] Isolation means that in a concurrent environment, when different transactions manipulate the same data at the same time, each transaction has its own complete data space. Modifications made by concurrent transactions must be isolated from modifications made by any other concurrent transactions. When a transaction views data updates, the state of the data is either the state before another transaction modified it or the state after another transaction modified it. The transaction will not view data in the intermediate state of other transactions.
[0010] D: Durability.
[0011] Persistence means that as long as a transaction ends successfully, the updates it makes to the database must be saved. Even if a system crashes, the database can be restored to the state when the transaction ends successfully after the database system is restarted.
[0012] Simply put, a distributed transaction is a large operation composed of different small operations. These small operations are distributed on different servers and belong to different applications. Distributed transactions need to ensure that these small operations either all succeed or all fail.
[0013] With the rapid development of the Internet, service architecture patterns such as microservice architecture and service-oriented architecture (SOA) are being used on a large scale, giving rise to distributed transactions. For example, a company's user assets may be divided into multiple parts, such as balance, points, coupons, etc.; the points function within the company is maintained by a microservice team, and coupons are maintained by another team. In this case, if the consistency of the database is not maintained, it is impossible to guarantee that the coupon can be successfully deducted after the points are deducted. Or, for an application's transfer business, user A transfers money to user B, user A's database is in city A, and user B's database is in city B. If distributed transactions are not executed, it is impossible to guarantee that user A can transfer money to user B and user B can receive money at the same time. Therefore, distributed transactions are an inevitable result of the rapid development of the Internet.
[0014] Specifically, a distributed transaction refers to a transaction in which the transaction participants, the server supporting the transaction, the resource server, and the transaction manager are located on different nodes of different distributed systems. In order to achieve the ACID properties of transactions, distributed transactions usually adopt a two-phase commit method based on the XA specification (a distributed transaction specification proposed by the X / Open organization), with the first phase being the preparation phase and the second phase being the commit phase.
[0015] During the commit phase, the transaction coordinator sends a rollback command to each resource manager involved in the transaction. During this process, protocol blocking is prone to occur. For example, some resource managers involved in the transaction are disconnected from the transaction coordinator, or the transaction coordinator crashes, resulting in the resource manager being unable to obtain the command from the transaction coordinator. The resource manager that has not received the rollback command (XArollback) is blocked, and the corresponding XA branch cannot be committed or rolled back. In this case, if there is no manual intervention by the database administrator, the data held by the blocked XA branch will remain locked. Summary of the invention
[0016] The embodiment of the present application provides a transaction processing method to solve the problem in the prior art that distributed transactions are prone to protocol blocking.
[0017] Correspondingly, an embodiment of the present application also provides a transaction processing device, an electronic device and a storage medium to ensure the implementation and application of the above method.
[0018] In order to solve the above problems, an embodiment of the present application discloses a transaction processing method, the method comprising:
[0019] Obtaining a branch identifier of a branch transaction; wherein the branch identifier includes a first time parameter and a second time parameter; the first time parameter includes a start execution time of the branch transaction, and the second time parameter includes a preset timeout time of a global transaction corresponding to the branch transaction;
[0020] Determining the execution duration of the branch transaction according to the first time parameter;
[0021] If the execution time exceeds the second time parameter, a rollback operation is performed on the branch transaction.
[0022] The present application embodiment discloses a transaction processing method, the method comprising:
[0023] Obtaining the start execution time of the branch transaction, and obtaining the preset timeout time of the global transaction corresponding to the branch transaction;
[0024] Adding the execution start time as a first time parameter and the preset timeout time as a second time parameter to the initial identifier of the branch transaction to obtain a branch identifier;
[0025] Determining the execution duration of the branch transaction according to the first time parameter in the branch identifier;
[0026] If the execution time exceeds the second time parameter in the branch identifier, a rollback operation is performed on the branch transaction.
[0027] The present application embodiment discloses a transaction processing method, which is applied to a distributed transaction processing system, wherein the distributed transaction processing system includes a resource manager and a transaction coordinator, and the method includes:
[0028] Controlling the resource manager to obtain a branch identifier of a branch transaction; wherein the branch identifier includes a first time parameter and a second time parameter; the first time parameter includes a start execution time of the branch transaction, and the second time parameter includes a preset timeout time of a global transaction corresponding to the branch transaction;
[0029] Determining the execution duration of the branch transaction according to the first time parameter;
[0030] If the execution time exceeds the second time parameter, a rollback operation is performed on the branch transaction, and a release request for releasing the data lock corresponding to the branch transaction is sent to the transaction coordinator;
[0031] The transaction coordinator is controlled to receive the release request and release the data lock.
[0032] The embodiment of the present application also discloses a transaction processing device, the device comprising:
[0033] An identifier acquisition module, configured to acquire a branch identifier of a branch transaction; wherein the branch identifier includes a first time parameter and a second time parameter; the first time parameter includes a start execution time of the branch transaction, and the second time parameter includes a preset timeout time of a global transaction corresponding to the branch transaction;
[0034] A first duration determination module, configured to determine the execution duration of the branch transaction according to the first time parameter;
[0035] The rollback processing module is used to perform a rollback processing operation on the branch transaction if the execution time exceeds the second time parameter.
[0036] The embodiment of the present application also discloses a transaction processing device, the device comprising:
[0037] A second time acquisition module, used to acquire the start execution time of the branch transaction, and to acquire the preset timeout time of the global transaction corresponding to the branch transaction;
[0038] A second adding module, configured to add the execution start time as a first time parameter and the preset timeout time as a second time parameter to the initial identifier of the branch transaction to obtain a branch identifier;
[0039] A second duration determination module, configured to determine the execution duration of the branch transaction according to the first time parameter in the branch identifier;
[0040] A rollback execution module, configured to execute a rollback operation on the branch transaction if the execution time exceeds the second time parameter in the branch identifier.
[0041] The embodiment of the present application further discloses a transaction processing device, which is applied to a distributed transaction processing system. The distributed transaction processing system includes a resource manager and a transaction coordinator. The device includes:
[0042] A first control module, configured to control the resource manager to obtain a branch identifier of a branch transaction; wherein the branch identifier includes a first time parameter and a second time parameter; the first time parameter includes a start execution time of the branch transaction, and the second time parameter includes a preset timeout time of a global transaction corresponding to the branch transaction;
[0043] Determining the execution duration of the branch transaction according to the first time parameter;
[0044] If the execution time exceeds the second time parameter, a rollback operation is performed on the branch transaction, and a release request for releasing the data lock corresponding to the branch transaction is sent to the transaction coordinator;
[0045] The second control module is used to control the transaction coordinator to receive the release request and release the data lock.
[0046] An embodiment of the present application further discloses an electronic device, including: a processor; and a memory, on which executable code is stored. When the executable code is executed, the processor executes one or more methods described in the embodiments of the present application.
[0047] The embodiments of the present application also disclose one or more machine-readable storage media on which executable codes are stored. When the executable codes are executed, the processor executes one or more methods described in the embodiments of the present application.
[0048] Compared with the prior art, the embodiments of the present application have the following advantages:
[0049] In an embodiment of the present application, the start execution time of the branch transaction and the preset timeout time of the global transaction corresponding to the branch transaction are obtained, and the execution time of the branch transaction is determined; if the execution time exceeds the preset timeout time, a rollback processing operation is performed on the branch transaction, so that when the resource manager cannot obtain the transaction coordinator command, it can promptly determine whether the execution timeout occurs based on the start execution time and the preset timeout time contained in the branch identifier; and in the case of execution timeout, the branch transaction is rolled back and the data table corresponding to the branch transaction is released to prevent the data table from being locked for a long time and causing protocol congestion, thereby improving the transaction processing throughput; when the probability of network abnormalities in the microservice architecture is high, the system availability is improved. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] Figure 1 This is one of the schematic diagrams of a data processing scenario in an embodiment of the present application;
[0051] Figure 2 This is the second schematic diagram of a data processing scenario in an embodiment of the present application;
[0052] Figure 3 It is a flowchart of steps of an embodiment of a transaction processing method of the present application;
[0053] Figure 4 is a flowchart of steps of another transaction processing method embodiment of the present application;
[0054] Figure 5 is a flowchart of steps of another transaction processing method embodiment of the present application;
[0055] Figure 6 It is a structural block diagram of an embodiment of a transaction processing device of the present application;
[0056] Figure 7 It is a structural block diagram of an embodiment of a transaction processing device of the present application;
[0057] Figure 8 is a structural block diagram of another transaction processing device embodiment of the present application;
[0058] Fig. 9 It is a schematic diagram of the structure of a device provided in one embodiment of the present application. DETAILED DESCRIPTION
[0059] In order to make the above-mentioned objects, features and advantages of the present application more obvious and easy to understand, the present application is further described in detail below in conjunction with the accompanying drawings and specific implementation methods.
[0060] The terms "first", "second", etc. in the specification and claims of this application are used to distinguish similar objects, rather than to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present application can be implemented in an order other than those illustrated or described herein.
[0061] The embodiments of the present application can be applied to data processing fields such as databases. When the resource manager cannot obtain the transaction coordinator command, it can promptly determine whether the branch transaction has timed out based on the start execution time and the preset timeout time contained in the branch identifier; and in the case of execution timeout, the branch transaction is rolled back and the data table corresponding to the branch transaction is released to prevent the data table from being locked for a long time and causing protocol congestion, thereby improving the transaction processing throughput; and in the case of a high probability of network anomalies in the microservice architecture, the system availability is improved.
[0062] Combination Figure 1 , Figure 1 An application scenario of an embodiment of the present application is shown, in which: Figure 1 , a global transaction 1 is illustrated in FIG. 1 , and the global transaction 1 can be converged with the global transaction in the same database through a transaction coordinator (TC).
[0063] Among them, TC acts as the coordinator in distributed transactions and manages the status information of global transactions, including the opening, submission, and rollback management of all transactions, the registration, submission, rollback, and status reporting of branch transactions, etc.; it maintains the running status of global transactions and is responsible for coordinating and driving the submission or rollback of global transactions.
[0064] Take global transaction 1 as an example, where global transaction 1 includes branch transaction 1 and branch transaction 2; specifically, global transaction refers to the transaction for operating multiple resource managers at one time, which is a global transaction; branch transaction: in a global transaction, a resource manager (RM) has its own independent task, and the collection of these tasks is the branch task of this resource manager; RM controls branch transactions, is responsible for branch registration, status reporting, and receives instructions from the transaction coordinator to drive the submission and rollback of branch (local) transactions. For example, in the global transaction for user A to transfer money to user B, there are two branch transactions, which are respectively to deduct the transfer amount from user A's account C and to increase the transfer amount from user B's account D.
[0065] The Transaction Manager (TM) is the core manager of distributed transactions. It communicates with each RM, coordinates and completes the processing of transactions; controls the global transaction boundary, and is responsible for the global transaction start, global commit, and global rollback. A transaction consists of all operations performed between the start of a transaction (begin transaction) and the end of a transaction (end transaction).
[0066] In order to achieve the ACID property of transactions, distributed transactions usually adopt a two-phase commit method based on the XA specification, with the first phase being the preparation phase and the second phase being the commit phase. In the commit phase, the transaction coordinator sends a rollback command to each resource manager participating in the transaction. During this process, protocol blocking is likely to occur. Therefore, the present application embodiment provides a transaction processing method to solve the above problem. Optionally, as Figure 1 As shown, the method can be applied to RM1. In the case that RM1 cannot obtain the TC command, RM1 promptly determines whether the execution of branch transaction 1 has timed out according to the start execution time and the preset timeout time contained in the branch identifier of the executed branch transaction 1; and in the case of execution timeout, the branch transaction 1 is rolled back, and the data table corresponding to the branch transaction 1 is released to prevent the data table from being locked for a long time and causing protocol congestion.
[0067] Specifically, the method comprises:
[0068] Step 101, obtaining a branch identifier of a branch transaction; wherein the branch identifier includes a first time parameter and a second time parameter; the first time parameter includes a start execution time of the branch transaction, and the second time parameter includes a preset timeout time of a global transaction corresponding to the branch transaction.
[0069] The branch identifier is used to uniquely mark a branch transaction. The branch identifier may include an initial identifier, which is a transaction identification number assigned by the TC to the branch transaction after the branch transaction is successfully registered on the TC side, such as a branch ID. In addition to the initial identifier, the branch identifier also includes a first time parameter and a second time parameter as a basis for detecting whether the branch transaction has timed out. Optionally, the first time parameter and the second time parameter are parameters pre-added to the initial identifier by the RM, and together with the initial identifier, they constitute the branch identifier.
[0070] Specifically, the first time parameter includes the start execution time of the branch transaction. Optionally, the start execution time is the time when the branch transaction is successfully registered. Figure 1, taking a global transaction of a transfer business as a first example, user A transfers money to user B; global transaction 1 includes branch transaction 1 and branch transaction 2; branch transaction 1 is to subtract 100 yuan from user A's account A, and branch transaction 2 is to add 100 yuan to user B's account B; RM1 is used to execute branch transaction 1, and RM2 is used to execute branch transaction 2. When RM1 parses the Structured Query Language (SQL) of branch transaction 1, executes SQL, and registers the branch transaction 1 with TC, the time of successful registration is the start execution time of branch transaction 1; similarly, when RM2 parses the SQL of branch transaction 2, executes SQL, and registers the branch transaction 2 with TC, the time of successful registration is the start execution time of branch transaction 2.
[0071] The second time parameter is the preset timeout of the global transaction; optionally, the preset timeout can be the upper limit of the total execution time of the global transaction, such as the maximum execution time threshold, or a period of time added to the maximum execution time threshold. When the total execution time is exceeded, protocol blocking may occur. Specifically, the numerical range of the preset timeout of a global transaction is usually in the second level, such as a few seconds or tens of seconds, while the numerical range of the execution time of a branch transaction is usually in the millisecond level; it is understandable that the preset timeout can also be dynamically adjusted according to different business scenarios and different application scenarios; for example, based on artificial intelligence (AI) or other machine learning and deep learning methods, the current business scenario or application scenario is identified, and the preset timeout corresponding to the current scenario is automatically matched.
[0072] Before executing a global transaction, a preset timeout period for each global transaction can be set based on an empirical value; for example, when RM executes each global transaction, it counts the actual execution time of the global transaction, and determines the preset timeout period based on the actual execution time; for example, still referring to the first example above, global transaction 1 is a transfer business, and its actual execution time is usually 5 seconds or 3 seconds. When RM executes the global transaction 1, it counts the actual execution time each time, and then determines the preset timeout period of the global transaction based on the actual execution time, such as the preset timeout period is the maximum value or average value of the actual execution time.
[0073] RM records the branch identifier of the branch transaction it controls, and during the execution of the branch transaction, uses real-time monitoring or periodic monitoring to query the branch identifier of the recorded branch transaction to monitor whether the branch transaction has an execution timeout.
[0074] For example, referring to the first example above, during the execution of branch transaction 1, RM1 obtains the first time parameter and the second time parameter in the branch identifier of branch transaction 1. The first time parameter is the start execution time of the branch transaction of subtracting 100 yuan from user A's account A, and the second time parameter is the preset timeout time of the global transaction of transferring money from user A to user B.
[0075] As a second example, global transaction 2 is when a buyer places an order on an e-commerce platform, which usually involves two actions, one is to deduct inventory, and the second is to update the order status; however, inventory and orders generally belong to different databases, and distributed transactions are required to ensure data consistency; global transaction 2 is divided into branch transaction 3 and branch transaction 4, branch transaction 3 is to deduct inventory, and is executed by RM1; branch transaction 4 is to update the order status, and is executed by RM2; in the process of executing branch transaction 3, RM1 obtains the first time parameter and the second time parameter in the branch identifier of branch transaction 3, the first time parameter is the start execution time of the branch transaction for deducting inventory, and the second time parameter is the preset timeout time of the global transaction for the user buyer to place an order on the e-commerce platform.
[0076] Step 102: Determine the execution duration of the branch transaction according to the first time parameter.
[0077] The first time parameter is the start execution time of the branch transaction. After the RM determines the first time parameter of the executed branch transaction, it obtains the current time and determines the execution duration of the branch transaction according to the time difference between the current time and the first time parameter.
[0078] Step 103: If the execution time exceeds the second time parameter, a rollback operation is performed on the branch transaction.
[0079] It can be understood that in the embodiment of the present application, "exceeds" includes this number, that is, the execution time exceeds the second time parameter and includes two situations: one is that the execution time is equal to the second time parameter; the other is that the execution time is greater than the second time parameter.
[0080] After obtaining the execution time of the branch transaction, it is further determined whether the execution time of the branch transaction exceeds the second time parameter, so as to determine whether to perform the rollback processing operation according to the determination result. Specifically, a global transaction usually includes multiple branch transactions. Therefore, when the transaction is executed normally, the execution time of each branch transaction must be less than the total execution time of the global transaction, and the total execution time is less than or equal to the second time parameter; therefore, the execution time of a single branch transaction must be less than the second time parameter. In this way, if the execution time exceeds the second time parameter, it can be confirmed that the branch transaction has timed out. For example, in the first example above, the second time parameter of the transfer transaction as a global transaction is 5 seconds, and RM1 has spent 5 seconds or more when executing branch transaction 1 of user A's account A minus 100 yuan, then branch transaction 1 has timed out and an exception has occurred; it may be that the communication connection between RM1 and TC is disconnected, or TC is down, which may easily cause protocol blocking of branch transaction 1.
[0081] Alternatively, in the second example above, the second time parameter of the transaction in which the buyer, as a global transaction, places an order on the e-commerce platform is 10 seconds, and RM1 has taken 10 seconds or more to execute branch transaction 3 of deducting inventory, so branch transaction 3 times out and an exception occurs.
[0082] For example, see Table 1 below:
[0083] Table 1:
[0084] Global Transactions Branch Transactions Start execution time Preset timeout Global Transaction 1 Branch transaction 1 2020 / 01 / 01 15:32:08.389 5s Global Transaction 1 Branch Transaction 2 2020 / 01 / 01 15:33:09.102 5s Global Transaction 2 Branch transaction 3 2020 / 01 / 01 15:33:50.513 10s Global Transaction 2 Branch Transaction 4 2020 / 01 / 01 15:33:03.721 10s
[0085] If the time indicated by the current timestamp is 2020 / 01 / 01 15:12:48.389, branch transaction 1, branch transaction 2, and branch transaction 4 have not timed out, but branch transaction 3 has timed out.
[0086] In the case of a branch transaction execution timeout, such as the disconnection of the communication connection between RM and TC, or the downtime of TC, it is easy to cause protocol blocking; specifically, protocol blocking means that when a participant occupies a public resource, other third-party nodes have to be blocked to access the public resource. For example, RM1 occupies and locks data table 1 of database A. If branch transaction 1 executed by RM1 times out, such as the disconnection of the communication connection between RM and TC, or the downtime of TC, branch transaction 1 cannot continue to execute, and data table 1 locked by branch transaction 2 will remain locked, and other global transactions cannot access data table 1.
[0087] In combination with the first example above, for example, if branch transaction 1 executed by RM1 times out, the data table of account A of user A will remain in a locked state, resulting in other global transactions being unable to access the data table of account A, such as if user A triggers other transfer services again, or other users transfer money to user A; for example, in the second example above, if branch transaction 3 for deducting inventory executed by RM1 times out, the data table 2 corresponding to the inventory will remain in a locked state, and other global transactions will not be able to access the data table, such as global transactions of orders placed by other buyers will not be able to proceed.
[0088] In the embodiment of the present application, when the branch transaction execution times out, a rollback operation is performed on the branch transaction to release the data table locked by the branch transaction and restore the data table to the state before the branch transaction execution. Figure 1 As shown, rollback refers to the operation of restoring the program or data to the last correct state according to the rollback log in the case of program or data processing errors. For example, in the first example, if branch transaction 1 is rolled back, user A's data table 1 will be restored to the state before branch transaction 1 is executed, and this state is saved in the rollback log; the rollback log saves a version of the data before the transaction occurs for rollback, and can also provide read operations under multi-version concurrency control. In addition, the rollback log is a log in a logical format. When executing the rollback log, the data is only logically restored to the state before the transaction, rather than being implemented from the physical page operation.
[0089] In addition to the rollback log, the ACID of transactions also needs to be guaranteed by the redo log and database lock. Specifically, the isolation of transactions is achieved through the database lock mechanism, the persistence is achieved through the redo log, and the atomicity and consistency are achieved through the rollback log. In order to meet the atomicity of transactions, before operating any data, the data is first backed up to a rollback log, and then the data is modified. If an error occurs or the user executes a rollback statement, the system can use the backup in the rollback log to restore the data to the state before the transaction started. In contrast to the rollback log, the redo log records the backup of new data. Before the transaction is committed, it is sufficient to persist the redo log, and the data does not need to be persisted. When the system crashes, although the data is not persisted, the redo log has been persisted. The system can restore all data to the latest state based on the content of the redo log. Usually before the transaction starts, RM generates the current version of the rollback log; after the transaction is committed, the rollback log cannot be deleted immediately, but is put into the linked list to be cleaned up, and a dedicated thread decides whether the log space of the rollback log can be cleaned up.
[0090] In this way, by rolling back the branch transaction that has timed out, it is possible to avoid the data table corresponding to the branch transaction being locked all the time and causing protocol congestion.
[0091] In the embodiment of the present application, the start execution time of the branch transaction and the preset timeout time of the global transaction corresponding to the branch transaction are obtained, and the execution time of the branch transaction is determined; if the execution time exceeds the preset timeout time, the branch transaction is rolled back, so that the resource manager can timely determine whether the execution timeout is reached according to the start execution time and the preset timeout time contained in the branch identifier when the transaction coordinator command cannot be obtained; and in the case of execution timeout, the branch transaction is rolled back, and the data table corresponding to the branch transaction is released to prevent the data table from being locked for a long time and causing protocol congestion, thereby improving the throughput of transaction processing; in the case of a high probability of network anomalies in the microservice architecture, the availability of the system is improved. The embodiment of the present application solves the problem in the prior art that distributed transactions are prone to protocol congestion.
[0092] In an optional embodiment, before the step of obtaining the branch identifier of the branch transaction, the method includes:
[0093] Obtaining a preset timeout time of the global transaction and a start execution time of the branch transaction; the initial identifier is a transaction identification number assigned by the TC to the branch transaction after the branch transaction is successfully registered on the TC side, such as a branch ID;
[0094] After the RM obtains the preset timeout and the start execution time, the preset timeout and the start execution time are added to the initial identifier of the branch transaction to obtain the branch identifier. The branch identifier may also include the identification number (ID) of the global transaction to which the branch belongs. Thus, the branch identifier includes the following four parts:
[0095] Global transaction ID (GX-ID), which can be obtained by RM in the current transaction context;
[0096] The branch transaction ID (BX-ID) can be determined during the process of RM registering the branch with the transaction coordinator;
[0097] The preset timeout is the timeout of the global transaction, which can be determined when the transaction is started;
[0098] The execution start time, that is, the branch start time, for example, the time point when the branch is successfully registered on the TC side.
[0099] Optionally, in order to avoid data redundancy caused by frequent timeout detection, the RM may set a preset period and perform a timeout detection once in each preset period. The step of obtaining the branch identifier of the branch transaction includes:
[0100] At the detection time of each preset cycle, a branch identifier of the branch transaction is obtained.
[0101] like Figure 2 As shown, RM communicates with the database (DB) and TC. When the preset period arrives, RM obtains the current timestamp, for example, 2020 / 01 / 01 15:33:16.513, that is, the date is 2020 / 01 / 01 and the time is 15:33:35.083; at this time, the branch transaction table recorded by RM includes 4 different branches of 4 global transactions, and the start execution time (Start Tme) and preset timeout (Timeout) of each branch transaction are as follows: Figure 2 shown in; according to Figure 2 It can be seen that BX-231, BX-319, and BX-428 have not timed out, while BX-276 has timed out.
[0102] In an optional embodiment, before the step of adding the preset timeout period and the start execution time to the initial identifier of the branch transaction, the method further includes:
[0103] Obtaining an exchange identifier of the global transaction and a transaction identifier of the branch transaction;
[0104] The exchange identifier and the transaction identifier are combined into the initial identifier.
[0105] The exchange identifier is the global transaction ID mentioned above; XID is the unique identification number of Transaction, which is used to uniquely identify a global transaction; when TM requests TC to initiate (Begin), commit (Commit), rollback (Rollback) and other global transactions, TM binds the XID of the global transaction to the branch transaction. When RM registers the branch transaction with the transaction coordinator, the branch transaction is registered in the global transaction through XID.
[0106] The transaction identifier is the branch transaction ID mentioned above. After the branch transaction is successfully registered, TC assigns a transaction identifier to the branch transaction. After RM receives the branch transaction identifier assigned by TC, it writes the branch transaction identifier into the rollback log and then commits the branch transaction so that the corresponding rollback record can be found according to the transaction identifier when sending a rollback.
[0107] In an optional embodiment, the step of obtaining the start execution time of the branch transaction includes:
[0108] Obtaining the reception time of the registration response message as the start execution time of the branch transaction;
[0109] The registration response message is a message indicating that the branch transaction is successfully registered with the transaction coordinator.
[0110] Before the data operation of the branch transaction is performed, RM needs to register with TC to incorporate the data operation of the upcoming branch transaction into the management of an already opened global transaction. Data operation can only be performed after the branch registration is successful. Therefore, the time when RM learns of the successful registration is used as the start time of execution.
[0111] RM registers the branch transaction with TC and submits a registration request to TC; after receiving the registration request from RM, TC binds the branch transaction of RM to the global transaction corresponding to the exchange identifier and feeds back a registration response message to RM. Therefore, the time of receiving the registration response message is used as the start time of the branch transaction. It can be understood that the registration response message is a response message indicating a successful registration. For example, in the first example above, when RM1 parses and registers the branch transaction 1 with TC, TC feeds back a registration response message indicating a successful registration. After receiving the registration success response message, RM1 starts to execute the data operation corresponding to branch transaction 1. Therefore, the time of receiving the registration response message is the start execution time of branch transaction 1.
[0112] In an optional embodiment, the step of performing a rollback operation on the branch transaction if the execution time exceeds the second time parameter includes:
[0113] If the execution duration exceeds the second time parameter, a transaction status parameter is obtained; wherein the transaction status parameter includes at least one of a first status parameter of the branch transaction and a second status parameter of the global transaction; the status parameters include being executed, ended, etc.; the first status parameter is a status parameter of the branch transaction, and the second status parameter is a status parameter of the global transaction.
[0114] If the transaction status parameter indicates that the corresponding transaction has not ended, for example, the first status parameter indicates that the branch transaction has not ended, or the second status parameter indicates that the global transaction has not ended, then the branch transaction is rolled back. On the contrary, if the first status parameter indicates that the branch transaction has ended, and the second status parameter indicates that the global transaction has ended, then there is no need to roll back the branch transaction, and the data lock of the branch transaction can be directly released.
[0115] In an optional embodiment, the step of performing a rollback operation on the branch transaction includes:
[0116] A rollback operation is performed on the branch transaction to release the data lock corresponding to the branch transaction.
[0117] In the case of a branch transaction execution timeout, such as the communication connection between RM and TC is disconnected, or TC crashes, it is easy to cause other third-party nodes to block access to the data table protocol. For example, RM1 occupies and locks data table 1 of database A. If branch transaction 1 executed by RM1 times out, such as the communication connection between RM and TC is disconnected, or TC crashes, branch transaction 1 cannot continue to execute, and data table 1 locked by branch transaction 2 will remain locked, and other global transactions cannot access data table 1.
[0118] Therefore, in the case of a branch transaction execution timeout, a rollback operation is performed on the branch transaction to release the data table locked by the branch transaction and restore the data table to the state before the branch transaction was executed. For example, in the first example above, if a certain failure occurs during the execution of branch transaction 1 or branch transaction 2, resulting in the failure of global transaction 1, the rollback of global transaction 1 is initiated, or only the branch that sent the failure is rolled back to release the data table locked by the branch, so that other global transactions can access the data table normally.
[0119] In an optional embodiment, after the rollback processing operation is performed, the TC and the RM resume communication subsequently; after the step of performing the rollback processing operation on the branch transaction, the method further includes:
[0120] Receive instruction information sent by the transaction coordinator;
[0121] If the operation indicated by the indication information is a rollback operation, feeding back first feedback information indicating a successful rollback to the transaction coordinator so as to perform the next operation;
[0122] If the operation indicated by the indication information is a commit operation, second feedback information indicating a commit exception is fed back to the transaction coordinator, so that the TC learns that the RM cannot commit the branch transaction and performs the next processing operation.
[0123] In an embodiment of the present application, the start execution time of a branch transaction and the preset timeout time of a global transaction corresponding to the branch transaction are obtained, and the execution time of the branch transaction is determined; if the execution time exceeds the preset timeout time, a rollback processing operation is performed on the branch transaction, so that when the resource manager cannot obtain a transaction coordinator command, it can promptly determine whether the execution has timed out based on the start execution time and the preset timeout time contained in the branch identifier; and in the case of an execution timeout, the branch transaction is rolled back and the data table corresponding to the branch transaction is released to prevent the data table from being locked for a long time and causing protocol congestion, thereby improving the transaction processing throughput; and in the case of a high probability of network anomalies in a microservice architecture, the availability of the system is improved.
[0124] On the basis of the above-mentioned embodiments, the embodiments of the present application also provide a transaction processing method, which can realize that when the resource manager cannot obtain the transaction coordinator command, it can timely determine whether the branch transaction has timed out based on the start execution time and the preset timeout time contained in the branch identifier; and in the case of execution timeout, the branch transaction is rolled back and the data table corresponding to the branch transaction is released to prevent the data table from being locked for a long time and causing protocol congestion, thereby improving the transaction processing throughput.
[0125] Reference Figure 3 , shows a flowchart of a transaction processing method embodiment of the present application; optionally, the method can be applied to RM, and the method includes:
[0126] Step 301, obtaining a branch identifier of a branch transaction; wherein the branch identifier includes a first time parameter and a second time parameter; the first time parameter includes a start execution time of the branch transaction, and the second time parameter includes a preset timeout time of a global transaction corresponding to the branch transaction.
[0127] The branch identifier is used to uniquely mark a branch transaction. The branch identifier may include an initial identifier, which is a transaction identification number assigned by the TC to the branch transaction after the branch transaction is successfully registered on the TC side, such as a branch ID. In addition to the initial identifier, the branch identifier also includes a first time parameter and a second time parameter, which serve as a basis for detecting whether the branch transaction has timed out.
[0128] Specifically, the first time parameter includes the start execution time of the branch transaction. Optionally, the start execution time is the time when the branch transaction is successfully registered. Figure 1 , taking a global transaction of a transfer business as a first example, user A transfers money to user B; global transaction 1 includes branch transaction 1 and branch transaction 2; branch transaction 1 is to subtract 100 yuan from user A's account A, and branch transaction 2 is to add 100 yuan to user B's account B; RM1 is used to execute branch transaction 1, and RM2 is used to execute branch transaction 2. When RM1 parses the Structured Query Language (SQL) of branch transaction 1, executes SQL, and registers the branch transaction 1 with TC, the time of successful registration is the start execution time of branch transaction 1; similarly, when RM2 parses the SQL of branch transaction 2, executes SQL, and registers the branch transaction 2 with TC, the time of successful registration is the start execution time of branch transaction 2.
[0129] The second time parameter is the preset timeout of the global transaction; optionally, the preset timeout can be the upper limit of the total execution time of the global transaction, such as the maximum execution time threshold, or a period of time added to the maximum execution time threshold. When the total execution time is exceeded, protocol blocking may occur. Specifically, the numerical range of the preset timeout of a global transaction is usually in the second level, such as a few seconds or tens of seconds, while the numerical range of the execution time of a branch transaction is usually in the millisecond level; it is understandable that the preset timeout can also be dynamically adjusted according to different business scenarios and different application scenarios; for example, based on AI or other machine learning and deep learning methods, the current business scenario or application scenario is identified, and the preset timeout corresponding to the current scenario is automatically matched.
[0130] Before executing a global transaction, a preset timeout period for each global transaction can be set based on an empirical value; for example, when RM executes each global transaction, it counts the actual execution time of the global transaction, and determines the preset timeout period based on the actual execution time; for example, still referring to the first example above, global transaction 1 is a transfer business, and its actual execution time is usually 5 seconds or 3 seconds. When RM executes the global transaction 1, it counts the actual execution time each time, and then determines the preset timeout period of the global transaction based on the actual execution time, such as the preset timeout period is the maximum value or average value of the actual execution time.
[0131] RM records the branch identifier of the branch transaction it controls, and during the execution of the branch transaction, uses real-time monitoring or periodic monitoring to query the branch identifier of the recorded branch transaction to monitor whether the branch transaction has an execution timeout.
[0132] For example, referring to the first example above, during the execution of branch transaction 1, RM1 obtains the first time parameter and the second time parameter in the branch identifier of branch transaction 1. The first time parameter is the start execution time of the branch transaction of subtracting 100 yuan from user A's account A, and the second time parameter is the preset timeout time of the global transaction of transferring money from user A to user B.
[0133] As a second example, global transaction 2 is when a buyer places an order on an e-commerce platform, which usually involves two actions, one is to deduct inventory, and the second is to update the order status; however, inventory and orders generally belong to different databases, and distributed transactions are required to ensure data consistency; global transaction 2 is divided into branch transaction 3 and branch transaction 4, branch transaction 3 is to deduct inventory, and is executed by RM1; branch transaction 4 is to update the order status, and is executed by RM2; in the process of executing branch transaction 3, RM1 obtains the first time parameter and the second time parameter in the branch identifier of branch transaction 3, the first time parameter is the start execution time of the branch transaction for deducting inventory, and the second time parameter is the preset timeout time of the global transaction for the user buyer to place an order on the e-commerce platform.
[0134] Step 302: Determine the execution duration of the branch transaction according to the first time parameter.
[0135] The first time parameter is the start execution time of the branch transaction. After the RM determines the first time parameter of the executed branch transaction, it obtains the current time and determines the execution duration of the branch transaction according to the time difference between the current time and the first time parameter.
[0136] Step 303: If the execution time exceeds the second time parameter, a rollback operation is performed on the branch transaction.
[0137] It can be understood that in the embodiment of the present application, "exceeds" includes this number, that is, the execution time exceeds the second time parameter and includes two situations: one is that the execution time is equal to the second time parameter; the other is that the execution time is greater than the second time parameter.
[0138] After obtaining the execution time of the branch transaction, it is further determined whether the execution time of the branch transaction exceeds the second time parameter, so as to determine whether to perform the rollback processing operation according to the determination result. Specifically, a global transaction usually includes multiple branch transactions. Therefore, when the transaction is executed normally, the execution time of each branch transaction must be less than the total execution time of the global transaction, and the total execution time is less than or equal to the second time parameter; therefore, the execution time of a single branch transaction must be less than the second time parameter. In this way, if the execution time exceeds the second time parameter, it can be confirmed that the branch transaction has timed out. For example, in the first example above, the second time parameter of the transfer transaction as a global transaction is 5 seconds, and RM1 has spent 5 seconds or more when executing branch transaction 1 of user A's account A minus 100 yuan, then branch transaction 1 has timed out and an exception has occurred; it may be that the communication connection between RM1 and TC is disconnected, or TC is down, which may easily cause protocol blocking of branch transaction 1.
[0139] Alternatively, in the second example above, the second time parameter of the transaction in which the buyer, as a global transaction, places an order on the e-commerce platform is 10 seconds, and RM1 has taken 10 seconds or more to execute branch transaction 3 of deducting inventory, so branch transaction 3 times out and an exception occurs.
[0140] For example, see Table 2 below:
[0141] Table 2:
[0142] Global Transactions Branch Transactions Start execution time Preset timeout Global Transaction 1 Branch transaction 1 2020 / 01 / 01 15:32:08.389 5s Global Transaction 1 Branch Transaction 2 2020 / 01 / 01 15:33:09.102 5s Global Transaction 2 Branch transaction 3 2020 / 01 / 01 15:33:50.513 10s Global Transaction 2 Branch Transaction 4 2020 / 01 / 01 15:33:03.721 10s
[0143] If the time indicated by the current timestamp is 2020 / 01 / 01 15:12:48.389, branch transaction 1, branch transaction 2, and branch transaction 4 have not timed out, but branch transaction 3 has timed out.
[0144] In the case of a branch transaction execution timeout, such as the disconnection of the communication connection between RM and TC, or the downtime of TC, it is easy to cause protocol blocking; specifically, protocol blocking means that when a participant occupies a public resource, other third-party nodes have to be blocked to access the public resource. For example, RM1 occupies and locks data table 1 of database A. If branch transaction 1 executed by RM1 times out, such as the disconnection of the communication connection between RM and TC, or the downtime of TC, branch transaction 1 cannot continue to execute, and data table 1 locked by branch transaction 2 will remain locked, and other global transactions cannot access data table 1.
[0145] In combination with the first example above, for example, if branch transaction 1 executed by RM1 times out, the data table of account A of user A will remain in a locked state, resulting in other global transactions being unable to access the data table of account A, such as if user A triggers other transfer services again, or other users transfer money to user A; for example, in the second example above, if branch transaction 3 for deducting inventory executed by RM1 times out, the data table 2 corresponding to the inventory will remain in a locked state, and other global transactions will not be able to access the data table, such as global transactions of orders placed by other buyers will not be able to proceed.
[0146] In the embodiment of the present application, when the branch transaction execution times out, a rollback operation is performed on the branch transaction to release the data table locked by the branch transaction and restore the data table to the state before the branch transaction execution. Figure 1As shown, rollback refers to the operation of restoring the program or data to the last correct state according to the rollback log in the case of program or data processing errors. For example, in the first example, if branch transaction 1 is rolled back, user A's data table 1 will be restored to the state before branch transaction 1 is executed, and this state is saved in the rollback log; the rollback log saves a version of the data before the transaction occurs for rollback, and can also provide read operations under multi-version concurrency control. In addition, the rollback log is a log in a logical format. When executing the rollback log, the data is only logically restored to the state before the transaction, rather than being implemented from the physical page operation.
[0147] In addition to the rollback log, the ACID of transactions also needs to be guaranteed by the redo log and database lock. Specifically, the isolation of transactions is achieved through the database lock mechanism, the persistence is achieved through the redo log, and the atomicity and consistency are achieved through the rollback log. In order to meet the atomicity of transactions, before operating any data, the data is first backed up to a rollback log, and then the data is modified. If an error occurs or the user executes a rollback statement, the system can use the backup in the rollback log to restore the data to the state before the transaction started. In contrast to the rollback log, the redo log records the backup of new data. Before the transaction is committed, it is sufficient to persist the redo log, and the data does not need to be persisted. When the system crashes, although the data is not persisted, the redo log has been persisted. The system can restore all data to the latest state based on the content of the redo log. Usually before the transaction starts, RM generates the current version of the rollback log; after the transaction is committed, the rollback log cannot be deleted immediately, but is put into the linked list to be cleaned up, and a dedicated thread decides whether the log space of the rollback log can be cleaned up.
[0148] In this way, by rolling back the branch transaction that has timed out, it is possible to avoid the data table corresponding to the branch transaction being locked all the time and causing protocol congestion.
[0149] In an optional embodiment, before the step of obtaining the branch identifier of the branch transaction, the method includes:
[0150] Obtaining a preset timeout time of the global transaction and obtaining a start execution time of the branch transaction;
[0151] The preset timeout period and the execution start time are added to the initial identifier of the branch transaction to obtain the branch identifier.
[0152] In an optional embodiment, the step of obtaining the start execution time of the branch transaction includes:
[0153] Obtaining the reception time of the registration response message as the start execution time of the branch transaction;
[0154] The registration response message is a message indicating that the branch transaction is successfully registered with the transaction coordinator.
[0155] In an optional embodiment, before the step of adding the preset timeout period and the start execution time to the initial identifier of the branch transaction, the method further includes:
[0156] Obtaining an exchange identifier of the global transaction and a transaction identifier of the branch transaction;
[0157] The exchange identifier and the transaction identifier are combined into the initial identifier.
[0158] In an optional embodiment, the step of performing a rollback operation on the branch transaction if the execution time exceeds the second time parameter includes:
[0159] If the execution time exceeds the second time parameter, acquiring a transaction state parameter; wherein the transaction state parameter includes at least one of a first state parameter of the branch transaction and a second state parameter of the global transaction;
[0160] If the transaction status parameter indicates that the corresponding transaction has not ended, a rollback operation is performed on the branch transaction.
[0161] In an optional embodiment, the step of performing a rollback operation on the branch transaction includes:
[0162] A rollback operation is performed on the branch transaction to release the data lock corresponding to the branch transaction.
[0163] In an optional embodiment, after the step of performing a rollback operation on the branch transaction, the method further includes:
[0164] Receive instruction information sent by the transaction coordinator;
[0165] If the operation indicated by the indication information is a rollback operation, feeding back first feedback information indicating a successful rollback to the transaction coordinator;
[0166] If the operation indicated by the indication information is a commit operation, second feedback information indicating a commit exception is fed back to the transaction coordinator.
[0167] In an optional embodiment, the step of obtaining a branch identifier of a branch transaction includes:
[0168] At the detection time of each preset cycle, a branch identifier of the branch transaction is obtained.
[0169] In an embodiment of the present application, the start execution time of a branch transaction and the preset timeout time of a global transaction corresponding to the branch transaction are obtained, and the execution time of the branch transaction is determined; if the execution time exceeds the preset timeout time, a rollback processing operation is performed on the branch transaction, so that when the resource manager cannot obtain a transaction coordinator command, it can promptly determine whether the execution has timed out based on the start execution time and the preset timeout time contained in the branch identifier; and in the case of an execution timeout, the branch transaction is rolled back and the data table corresponding to the branch transaction is released to prevent the data table from being locked for a long time and causing protocol congestion, thereby improving the transaction processing throughput; and in the case of a high probability of network anomalies in a microservice architecture, the availability of the system is improved.
[0170] On the basis of the above-mentioned embodiments, the embodiments of the present application also provide a transaction processing method, which can realize that when the resource manager cannot obtain the transaction coordinator command, it can timely determine whether the branch transaction has timed out based on the start execution time and the preset timeout time contained in the branch identifier; and in the case of execution timeout, the branch transaction is rolled back and the data table corresponding to the branch transaction is released to prevent the data table from being locked for a long time and causing protocol congestion, thereby improving the transaction processing throughput.
[0171] Reference Figure 4 , shows a flowchart of a transaction processing method embodiment of the present application, optionally, the method can be applied to RM, the method comprising:
[0172] Step 401: Obtain the start execution time of a branch transaction, and obtain the preset timeout time of the global transaction corresponding to the branch transaction.
[0173] The execution start time is the time when the branch transaction is successfully registered; combined Figure 1 , taking a global transaction of a transfer business as a first example, user A transfers money to user B; global transaction 1 includes branch transaction 1 and branch transaction 2; branch transaction 1 is to subtract 100 yuan from user A's account A, and branch transaction 2 is to add 100 yuan to user B's account B; RM1 is used to execute branch transaction 1, and RM2 is used to execute branch transaction 2. When RM1 parses the Structured Query Language (SQL) of branch transaction 1, executes SQL, and registers the branch transaction 1 with TC, the time of successful registration is the start execution time of branch transaction 1; similarly, when RM2 parses the SQL of branch transaction 2, executes SQL, and registers the branch transaction 2 with TC, the time of successful registration is the start execution time of branch transaction 2.
[0174] The preset timeout period can be the upper limit of the total execution time of the global transaction, such as the maximum execution time threshold, or a period of time added to the maximum execution time threshold. When the total execution time is exceeded, protocol blocking may occur. Specifically, the numerical range of the preset timeout period of a global transaction is usually in the second level, such as a few seconds or tens of seconds, while the numerical range of the execution time of a branch transaction is usually in the millisecond level; it is understandable that the preset timeout period can also be dynamically adjusted according to different business scenarios and different application scenarios; for example, based on AI or other machine learning and deep learning methods, the current business scenario or application scenario is identified, and the preset timeout period corresponding to the current scenario is automatically matched.
[0175] Before executing a global transaction, a preset timeout period for each global transaction can be set based on an empirical value; for example, when RM executes each global transaction, it counts the actual execution time of the global transaction, and determines the preset timeout period based on the actual execution time; for example, still referring to the first example above, global transaction 1 is a transfer business, and its actual execution time is usually 5 seconds or 3 seconds. When RM executes the global transaction 1, it counts the actual execution time each time, and then determines the preset timeout period of the global transaction based on the actual execution time, such as the preset timeout period is the maximum value or average value of the actual execution time.
[0176] Step 402: Add the execution start time as a first time parameter and the preset timeout time as a second time parameter to the initial identifier of the branch transaction to obtain a branch identifier.
[0177] The initial identifier is the transaction identification number assigned by the TC to the branch transaction after the branch transaction is successfully registered on the TC side, such as the branch ID; after the RM obtains the preset timeout time and the start execution time, the preset timeout time and the start execution time are added to the initial identifier of the branch transaction to obtain the branch identifier. The branch identifier may also include the identification number (ID) of the global transaction to which the branch belongs. In this way, the branch identifier includes the following 4 parts:
[0178] Global transaction ID (GX-ID), which can be obtained by RM in the current transaction context;
[0179] The branch transaction ID (BX-ID) can be determined during the process of RM registering the branch with the transaction coordinator;
[0180] The preset timeout is the timeout of the global transaction, which can be determined when the transaction is started;
[0181] The execution start time, that is, the branch start time, for example, the time point when the branch is successfully registered on the TC side.
[0182] Step 403: Determine the execution duration of the branch transaction according to the first time parameter in the branch identifier.
[0183] The first time parameter is the start execution time of the branch transaction. After the RM determines the first time parameter of the executed branch transaction, it obtains the current time and determines the execution duration of the branch transaction according to the time difference between the current time and the first time parameter.
[0184] Step 404: If the execution time exceeds the second time parameter in the branch identifier, a rollback operation is performed on the branch transaction.
[0185] It can be understood that in the embodiment of the present application, "exceeds" includes this number, that is, the execution time exceeds the second time parameter and includes two situations: one is that the execution time is equal to the second time parameter; the other is that the execution time is greater than the second time parameter.
[0186] After obtaining the execution time of the branch transaction, it is further determined whether the execution time of the branch transaction exceeds the second time parameter, so as to determine whether to perform the rollback processing operation according to the determination result. Specifically, a global transaction usually includes multiple branch transactions. Therefore, when the transaction is executed normally, the execution time of each branch transaction must be less than the total execution time of the global transaction, and the total execution time is less than or equal to the second time parameter; therefore, the execution time of a single branch transaction must be less than the second time parameter. In this way, if the execution time exceeds the second time parameter, it can be confirmed that the branch transaction has timed out. For example, in the first example above, the second time parameter of the transfer transaction as a global transaction is 5 seconds, and RM1 has spent 5 seconds or more when executing branch transaction 1 of user A's account A minus 100 yuan, then branch transaction 1 has timed out and an exception has occurred; it may be that the communication connection between RM1 and TC is disconnected, or TC is down, which may easily cause protocol blocking of branch transaction 1.
[0187] Alternatively, in the second example above, the second time parameter of the transaction in which the buyer, as a global transaction, places an order on the e-commerce platform is 10 seconds, and RM1 has taken 10 seconds or more to execute branch transaction 3 of deducting inventory, so branch transaction 3 times out and an exception occurs.
[0188] For example, see Table 3 below:
[0189] Table 3:
[0190] Global Transactions Branch Transactions Start execution time Preset timeout Global Transaction 1 Branch transaction 1 2020 / 01 / 01 15:32:08.389 5s Global Transaction 1 Branch Transaction 2 2020 / 01 / 01 15:33:09.102 5s Global Transaction 2 Branch transaction 3 2020 / 01 / 01 15:33:50.513 10s Global Transaction 2 Branch Transaction 4 2020 / 01 / 01 15:33:03.721 10s
[0191] If the time indicated by the current timestamp is 2020 / 01 / 01 15:12:48.389, branch transaction 1, branch transaction 2, and branch transaction 4 have not timed out, but branch transaction 3 has timed out.
[0192] In the case of a branch transaction execution timeout, such as the disconnection of the communication connection between RM and TC, or the downtime of TC, it is easy to cause protocol blocking; specifically, protocol blocking means that when a participant occupies a public resource, other third-party nodes have to be blocked to access the public resource. For example, RM1 occupies and locks data table 1 of database A. If branch transaction 1 executed by RM1 times out, such as the disconnection of the communication connection between RM and TC, or the downtime of TC, branch transaction 1 cannot continue to execute, and data table 1 locked by branch transaction 2 will remain locked, and other global transactions cannot access data table 1.
[0193] In combination with the first example above, for example, if branch transaction 1 executed by RM1 times out, the data table of account A of user A will remain in a locked state, resulting in other global transactions being unable to access the data table of account A, such as if user A triggers other transfer services again, or other users transfer money to user A; for example, in the second example above, if branch transaction 3 for deducting inventory executed by RM1 times out, the data table 2 corresponding to the inventory will remain in a locked state, and other global transactions will not be able to access the data table, such as global transactions of orders placed by other buyers will not be able to proceed.
[0194] In the embodiment of the present application, when the branch transaction execution times out, a rollback operation is performed on the branch transaction to release the data table locked by the branch transaction and restore the data table to the state before the branch transaction execution. Figure 1 As shown, rollback refers to the operation of restoring the program or data to the last correct state according to the rollback log in the case of program or data processing errors. For example, in the first example, if branch transaction 1 is rolled back, user A's data table 1 will be restored to the state before branch transaction 1 is executed, and this state is saved in the rollback log; the rollback log saves a version of the data before the transaction occurs for rollback, and can also provide read operations under multi-version concurrency control. In addition, the rollback log is a log in a logical format. When executing the rollback log, the data is only logically restored to the state before the transaction, rather than being implemented from the physical page operation.
[0195] In addition to the rollback log, the ACID of transactions also needs to be guaranteed by the redo log and database lock. Specifically, the isolation of transactions is achieved through the database lock mechanism, the persistence is achieved through the redo log, and the atomicity and consistency are achieved through the rollback log. In order to meet the atomicity of transactions, before operating any data, the data is first backed up to a rollback log, and then the data is modified. If an error occurs or the user executes a rollback statement, the system can use the backup in the rollback log to restore the data to the state before the transaction started. In contrast to the rollback log, the redo log records the backup of new data. Before the transaction is committed, it is sufficient to persist the redo log, and the data does not need to be persisted. When the system crashes, although the data is not persisted, the redo log has been persisted. The system can restore all data to the latest state based on the content of the redo log. Usually before the transaction starts, RM generates the current version of the rollback log; after the transaction is committed, the rollback log cannot be deleted immediately, but is put into the linked list to be cleaned up, and a dedicated thread decides whether the log space of the rollback log can be cleaned up.
[0196] In this way, by rolling back the branch transaction that has timed out, it is possible to avoid the data table corresponding to the branch transaction being locked all the time and causing protocol congestion.
[0197] In an optional embodiment, the step of obtaining the start execution time of the branch transaction includes:
[0198] Obtaining the reception time of the registration response message as the start execution time of the branch transaction;
[0199] The registration response message is a message indicating that the branch transaction is successfully registered with the transaction coordinator.
[0200] In an optional embodiment, before the step of using the execution start time as the first time parameter and adding the preset timeout time as the second time parameter to the initial identifier of the branch transaction, the method further includes:
[0201] Obtaining an exchange identifier of the global transaction and a transaction identifier of the branch transaction;
[0202] The exchange identifier and the transaction identifier are combined into the initial identifier.
[0203] In an embodiment of the present application, the start execution time of a branch transaction and the preset timeout time of a global transaction corresponding to the branch transaction are obtained, and the execution time of the branch transaction is determined; if the execution time exceeds the preset timeout time, a rollback processing operation is performed on the branch transaction, so that when the resource manager cannot obtain a transaction coordinator command, it can promptly determine whether the execution has timed out based on the start execution time and the preset timeout time contained in the branch identifier; and in the case of an execution timeout, the branch transaction is rolled back and the data table corresponding to the branch transaction is released to prevent the data table from being locked for a long time and causing protocol congestion, thereby improving the transaction processing throughput; and in the case of a high probability of network anomalies in a microservice architecture, the availability of the system is improved.
[0204] Based on the above embodiments, the present application also provides a transaction processing method, which is applied to a distributed transaction processing system. Figure 1 The distributed transaction processing system includes a resource manager RM and a transaction coordinator TC; optionally, it may also include a transaction manager TM.
[0205] Among them, TC acts as the coordinator in distributed transactions and manages the status information of global transactions, including the opening, submission, and rollback management of all transactions, the registration, submission, rollback, and status reporting of branch transactions, etc.; it maintains the running status of global transactions and is responsible for coordinating and driving the submission or rollback of global transactions.
[0206] In a global transaction, the resource manager has its own independent tasks, and the collection of these tasks is called the branch tasks of this resource manager; RM controls branch transactions, is responsible for branch registration and status reporting, and receives instructions from the transaction coordinator to drive the commit and rollback of branch (local) transactions.
[0207] The transaction manager is the core manager of distributed transactions. It communicates with each RM, coordinates and completes the processing of transactions; controls the global transaction boundary, and is responsible for the opening, committing, and rolling back of global transactions. When the resource manager cannot obtain the transaction coordinator command, it can timely determine whether the branch transaction has timed out based on the start execution time and the preset timeout time contained in the branch identifier; and in the case of timeout, it rolls back the branch transaction and releases the data table corresponding to the branch transaction to prevent the data table from being locked for a long time and causing protocol congestion, thereby improving the throughput of transaction processing.
[0208] Reference Figure 5 , shows a flowchart of a transaction processing method embodiment of the present application, the method comprising:
[0209] Step 501, control the resource manager to obtain a branch identifier of a branch transaction; wherein the branch identifier includes a first time parameter and a second time parameter; the first time parameter includes a start execution time of the branch transaction, and the second time parameter includes a preset timeout time of a global transaction corresponding to the branch transaction.
[0210] The branch identifier is used to uniquely mark a branch transaction. The branch identifier may include an initial identifier, which is a transaction identification number assigned by the TC to the branch transaction after the branch transaction is successfully registered on the TC side, such as a branch ID. In addition to the initial identifier, the branch identifier also includes a first time parameter and a second time parameter, which serve as a basis for detecting whether the branch transaction has timed out.
[0211] Specifically, the first time parameter includes the start execution time of the branch transaction. Optionally, the start execution time is the time when the branch transaction is successfully registered. Figure 1 , taking a global transaction of a transfer business as a first example, user A transfers money to user B; global transaction 1 includes branch transaction 1 and branch transaction 2; branch transaction 1 is to subtract 100 yuan from user A's account A, and branch transaction 2 is to add 100 yuan to user B's account B; RM1 is used to execute branch transaction 1, and RM2 is used to execute branch transaction 2. When RM1 parses the Structured Query Language (SQL) of branch transaction 1, executes SQL, and registers the branch transaction 1 with TC, the time of successful registration is the start execution time of branch transaction 1; similarly, when RM2 parses the SQL of branch transaction 2, executes SQL, and registers the branch transaction 2 with TC, the time of successful registration is the start execution time of branch transaction 2.
[0212] The second time parameter is the preset timeout of the global transaction; optionally, the preset timeout can be the upper limit of the total execution time of the global transaction, such as the maximum execution time threshold, or a period of time added to the maximum execution time threshold. When the total execution time is exceeded, protocol blocking may occur. Specifically, the numerical range of the preset timeout of a global transaction is usually in the second level, such as a few seconds or tens of seconds, while the numerical range of the execution time of a branch transaction is usually in the millisecond level; it is understandable that the preset timeout can also be dynamically adjusted according to different business scenarios and different application scenarios; for example, based on AI or other machine learning and deep learning methods, the current business scenario or application scenario is identified, and the preset timeout corresponding to the current scenario is automatically matched.
[0213] Before executing a global transaction, a preset timeout period for each global transaction can be set based on an empirical value; for example, when RM executes each global transaction, it counts the actual execution time of the global transaction, and determines the preset timeout period based on the actual execution time; for example, still referring to the first example above, global transaction 1 is a transfer business, and its actual execution time is usually 5 seconds or 3 seconds. When RM executes the global transaction 1, it counts the actual execution time each time, and then determines the preset timeout period of the global transaction based on the actual execution time, such as the preset timeout period is the maximum value or average value of the actual execution time.
[0214] RM records the branch identifier of the branch transaction it controls, and during the execution of the branch transaction, uses real-time monitoring or periodic monitoring to query the branch identifier of the recorded branch transaction to monitor whether the branch transaction has an execution timeout.
[0215] For example, referring to the first example above, during the execution of branch transaction 1, RM1 obtains the first time parameter and the second time parameter in the branch identifier of branch transaction 1. The first time parameter is the start execution time of the branch transaction of subtracting 100 yuan from user A's account A, and the second time parameter is the preset timeout time of the global transaction of transferring money from user A to user B.
[0216] As a second example, global transaction 2 is when a buyer places an order on an e-commerce platform, which usually involves two actions, one is to deduct inventory, and the second is to update the order status; however, inventory and orders generally belong to different databases, and distributed transactions are required to ensure data consistency; global transaction 2 is divided into branch transaction 3 and branch transaction 4, branch transaction 3 is to deduct inventory, and is executed by RM1; branch transaction 4 is to update the order status, and is executed by RM2; in the process of executing branch transaction 3, RM1 obtains the first time parameter and the second time parameter in the branch identifier of branch transaction 3, the first time parameter is the start execution time of the branch transaction for deducting inventory, and the second time parameter is the preset timeout time of the global transaction for the user buyer to place an order on the e-commerce platform.
[0217] Step 502: Determine the execution duration of the branch transaction according to the first time parameter.
[0218] The first time parameter is the start execution time of the branch transaction. After the RM determines the first time parameter of the executed branch transaction, it obtains the current time and determines the execution duration of the branch transaction according to the time difference between the current time and the first time parameter.
[0219] Step 503: If the execution time exceeds the second time parameter, a rollback operation is performed on the branch transaction, and a release request for releasing the data lock corresponding to the branch transaction is sent to the transaction coordinator.
[0220] It can be understood that in the embodiment of the present application, "exceeds" includes this number, that is, the execution time exceeds the second time parameter and includes two situations: one is that the execution time is equal to the second time parameter; the other is that the execution time is greater than the second time parameter.
[0221] After obtaining the execution time of the branch transaction, it is further determined whether the execution time of the branch transaction exceeds the second time parameter, so as to determine whether to perform the rollback processing operation according to the determination result. Specifically, a global transaction usually includes multiple branch transactions. Therefore, when the transaction is executed normally, the execution time of each branch transaction must be less than the total execution time of the global transaction, and the total execution time is less than or equal to the second time parameter; therefore, the execution time of a single branch transaction must be less than the second time parameter. In this way, if the execution time exceeds the second time parameter, it can be confirmed that the branch transaction has timed out. For example, in the first example above, the second time parameter of the transfer transaction as a global transaction is 5 seconds, and RM1 has spent 5 seconds or more when executing branch transaction 1 of user A's account A minus 100 yuan, then branch transaction 1 has timed out and an exception has occurred; it may be that the communication connection between RM1 and TC is disconnected, or TC is down, which may easily cause protocol blocking of branch transaction 1.
[0222] Alternatively, in the second example above, the second time parameter of the transaction in which the buyer, as a global transaction, places an order on the e-commerce platform is 10 seconds, and RM1 has taken 10 seconds or more to execute branch transaction 3 of deducting inventory, so branch transaction 3 times out and an exception occurs.
[0223] In the case of a branch transaction execution timeout, such as the disconnection of the communication connection between RM and TC, or the downtime of TC, it is easy to cause protocol blocking; specifically, protocol blocking means that when a participant occupies a public resource, other third-party nodes have to be blocked to access the public resource. For example, RM1 occupies and locks data table 1 of database A. If branch transaction 1 executed by RM1 times out, such as the disconnection of the communication connection between RM and TC, or the downtime of TC, branch transaction 1 cannot continue to execute, and data table 1 locked by branch transaction 2 will remain locked, and other global transactions cannot access data table 1.
[0224] In order to avoid protocol blocking, the RM performs a rollback processing operation on the branch transaction, and sends a release request to the transaction coordinator to release the data lock corresponding to the branch transaction.
[0225] Step 504: Control the transaction coordinator to receive the release request and release the data lock.
[0226] After receiving the release request, TC releases the data lock corresponding to the branch transaction; for example, in the first example above, if a certain failure occurs during the execution of branch transaction 1 or branch transaction 2, resulting in the failure of global transaction 1 to be executed successfully, then RM initiates the rollback of global transaction 1, or only rolls back the branch that sent the failure, and sends a release request to TC to release the data table locked by the branch. TC releases the data lock corresponding to the branch transaction, so that other global transactions can access the data table normally.
[0227] In an embodiment of the present application, the RM is controlled to obtain the start execution time of the branch transaction and the preset timeout time of the global transaction corresponding to the branch transaction, and the execution time of the branch transaction is determined; if the execution time exceeds the preset timeout time, a rollback processing operation is performed on the branch transaction, and the TC is controlled to release the data lock corresponding to the branch transaction, so that the resource manager can timely determine whether the execution timeout occurs according to the start execution time and the preset timeout time contained in the branch identifier when the transaction coordinator command cannot be obtained; and in the case of execution timeout, the branch transaction is rolled back and the data table corresponding to the branch transaction is released to prevent the data table from being locked for a long time and causing protocol congestion, thereby improving the transaction processing throughput; when the probability of network abnormalities in the microservice architecture is high, the system availability is improved.
[0228] On the basis of the above embodiments, the embodiments of the present application further provide a transaction processing device, which is applied to electronic devices such as terminal devices and servers.
[0229] Reference Figure 6 , shows a structural block diagram of an embodiment of a transaction processing device of the present application, which may specifically include the following modules:
[0230] The identifier acquisition module 601 is used to obtain a branch identifier of a branch transaction; wherein the branch identifier includes a first time parameter and a second time parameter; the first time parameter includes the start execution time of the branch transaction, and the second time parameter includes a preset timeout time of the global transaction corresponding to the branch transaction.
[0231] The first duration determination module 602 is configured to determine the execution duration of the branch transaction according to the first time parameter.
[0232] The rollback processing module 603 is used to perform a rollback processing operation on the branch transaction if the execution time exceeds the second time parameter.
[0233] In an optional embodiment, the device comprises:
[0234] A first time acquisition module, used to acquire a preset timeout time of the global transaction and to acquire a start execution time of the branch transaction;
[0235] The first adding module is used to add the preset timeout time and the start execution time to the initial identifier of the branch transaction to obtain the branch identifier.
[0236] In an optional embodiment, the identifier acquisition module 601 includes:
[0237] A time acquisition submodule, used to acquire the reception time of the registration response message as the start execution time of the branch transaction;
[0238] The registration response message is a message indicating that the branch transaction is successfully registered with the transaction coordinator.
[0239] In an optional embodiment, before the step of adding the preset timeout time and the start execution time to the initial identifier of the branch transaction, the apparatus further includes:
[0240] A first identifier generation module, configured to obtain an exchange identifier of the global transaction and a transaction identifier of the branch transaction;
[0241] The exchange identifier and the transaction identifier are combined into the initial identifier.
[0242] In an optional embodiment, the rollback processing module 603 includes:
[0243] a parameter acquisition submodule, configured to acquire a transaction status parameter if the execution duration exceeds the second time parameter; wherein the transaction status parameter includes at least one of a first status parameter of the branch transaction and a second status parameter of the global transaction;
[0244] The rollback submodule is used to perform a rollback processing operation on the branch transaction if the transaction status parameter indicates that the corresponding transaction has not ended.
[0245] In an optional embodiment, the rollback processing module 603 includes:
[0246] The release submodule is used to perform a rollback processing operation on the branch transaction and release the data lock corresponding to the branch transaction.
[0247] In an optional embodiment, after the step of performing a rollback operation on the branch transaction, the apparatus further includes:
[0248] An information receiving module, used for receiving instruction information sent by the transaction coordinator;
[0249] A first feedback module, configured to feed back first feedback information indicating a successful rollback to the transaction coordinator if the operation indicated by the indication information is a rollback operation;
[0250] The second feedback module is configured to feed back second feedback information indicating a commit exception to the transaction coordinator if the operation indicated by the indication information is a commit operation.
[0251] In an optional embodiment, the identifier acquisition module 601 is used to:
[0252] At the detection time of each preset cycle, a branch identifier of the branch transaction is obtained.
[0253] In an embodiment of the present application, the identifier acquisition module 601 acquires the start execution time of the branch transaction and the preset timeout time of the global transaction corresponding to the branch transaction, and the first duration determination module 602 determines the execution duration of the branch transaction; if the execution duration exceeds the preset timeout time, the rollback processing module 603 performs a rollback processing operation on the branch transaction, so that the resource manager can promptly determine whether the execution timeout occurs based on the start execution time and the preset timeout time contained in the branch identifier when the transaction coordinator command cannot be obtained; and in the case of execution timeout, the branch transaction is rolled back and the data table corresponding to the branch transaction is released to prevent the data table from being locked for a long time and causing protocol congestion, thereby improving the transaction processing throughput; and in the case of a high probability of network anomalies in the microservice architecture, the system availability is improved.
[0254] On the basis of the above embodiments, the embodiments of the present application further provide a transaction processing device, which is applied to electronic devices such as terminal devices and servers.
[0255] Reference Figure 7 , shows a structural block diagram of an embodiment of a transaction processing device of the present application, which may specifically include the following modules:
[0256] The second time acquisition module 701 is used to acquire the start execution time of the branch transaction and the preset timeout time of the global transaction corresponding to the branch transaction;
[0257] A second adding module 702, configured to add the execution start time as a first time parameter and the preset timeout time as a second time parameter to the initial identifier of the branch transaction to obtain a branch identifier;
[0258] A second duration determination module 703, configured to determine the execution duration of the branch transaction according to the first time parameter in the branch identifier;
[0259] The rollback execution module 704 is configured to execute a rollback processing operation on the branch transaction if the execution time exceeds the second time parameter.
[0260] In an optional embodiment, the second time acquisition module 701 includes:
[0261] An acquisition submodule, used for acquiring the reception time of the registration response message as the start execution time of the branch transaction;
[0262] The registration response message is a message indicating that the branch transaction is successfully registered with the transaction coordinator.
[0263] In an optional embodiment, before the step of using the execution start time as the first time parameter and adding the preset timeout time as the second time parameter to the initial identifier of the branch transaction, the apparatus further comprises:
[0264] A second identifier generating module, configured to obtain an exchange identifier of the global transaction and a transaction identifier of the branch transaction;
[0265] The exchange identifier and the transaction identifier are combined into the initial identifier.
[0266] In an embodiment of the present application, the second time acquisition module 701 acquires the start execution time of the branch transaction and the preset timeout time of the global transaction corresponding to the branch transaction; the second adding module 702 uses the start execution time as the first time parameter, and adds the preset timeout time as the second time parameter to the initial identifier of the branch transaction to obtain a branch identifier; the second duration determination module 703 determines the execution duration of the branch transaction according to the first time parameter; if the execution duration exceeds the preset timeout time, the rollback execution module 704 performs a rollback processing operation on the branch transaction, releases the data table corresponding to the branch transaction, prevents the data table from being locked for a long time and causing protocol congestion, and improves the transaction processing throughput; when the probability of network anomalies in the microservice architecture is high, the system availability is improved.
[0267] On the basis of the above embodiments, the embodiments of the present application further provide a transaction processing device, which is applied to electronic devices such as terminal devices and servers.
[0268] Reference Figure 8 , shows a structural block diagram of an embodiment of a transaction processing device of the present application, the device is applied to a distributed transaction processing system, the distributed transaction processing system includes a resource manager and a transaction coordinator, and specifically may include the following modules:
[0269] The first control module 801 is used to control the resource manager to obtain a branch identifier of a branch transaction; wherein the branch identifier includes a first time parameter and a second time parameter; the first time parameter includes a start execution time of the branch transaction, and the second time parameter includes a preset timeout time of a global transaction corresponding to the branch transaction;
[0270] Determining the execution duration of the branch transaction according to the first time parameter;
[0271] If the execution time exceeds the second time parameter, a rollback operation is performed on the branch transaction, and a release request for releasing the data lock corresponding to the branch transaction is sent to the transaction coordinator;
[0272] The second control module 802 is used to control the transaction coordinator to receive the release request and release the data lock.
[0273] In an embodiment of the present application, the first control module 801 controls the RM to obtain the start execution time of the branch transaction and the preset timeout time of the global transaction corresponding to the branch transaction, and determines the execution time of the branch transaction; if the execution time exceeds the preset timeout time, the branch transaction is rolled back; the second control module 802 controls the TC to release the data lock corresponding to the branch transaction, so that the resource manager can promptly determine whether the execution timeout occurs according to the start execution time and the preset timeout time contained in the branch identifier when the transaction coordinator command cannot be obtained; and in the case of execution timeout, the branch transaction is rolled back and the data table corresponding to the branch transaction is released to prevent the data table from being locked for a long time and causing protocol congestion, thereby improving the transaction processing throughput; and in the case of a high probability of network anomalies in the microservice architecture, the system availability is improved.
[0274] The embodiment of the present application also provides a non-volatile readable storage medium, which stores one or more modules (programs). When the one or more modules are applied to a device, the device can execute instructions (instructions) of each method step in the embodiment of the present application.
[0275] The present application embodiment provides one or more machine-readable storage media, on which instructions are stored, and when executed by one or more processors, the electronic device executes one or more of the methods described in the above embodiments. In the present application embodiment, the electronic device includes various types of devices such as terminal devices and servers (clusters).
[0276] The embodiments of the present disclosure may be implemented as a device configured as desired using any appropriate hardware, firmware, software, or any combination thereof, and the device may include electronic devices such as terminal devices and servers (clusters). Fig. 9 An exemplary apparatus 900 that can be used to implement various embodiments described in this application is schematically illustrated.
[0277] For one embodiment, Fig. 9An exemplary apparatus 900 is shown having one or more processors 902, a control module (chip set) 904 coupled to at least one of the processor(s) 902, a memory 906 coupled to the control module 904, a non-volatile memory (NVM) / storage device 908 coupled to the control module 904, one or more input / output devices 910 coupled to the control module 904, and a network interface 912 coupled to the control module 904.
[0278] The processor 902 may include one or more single-core or multi-core processors, and the processor 902 may include any combination of general-purpose processors or special-purpose processors (such as graphics processors, application processors, baseband processors, etc.). In some embodiments, the device 900 can be used as a terminal device, server (cluster), etc. described in the embodiments of the present application.
[0279] In some embodiments, the apparatus 900 may include one or more computer-readable media (e.g., memory 906 or NVM / storage device 908) having instructions 914 and one or more processors 902 combined with the one or more computer-readable media and configured to execute the instructions 914 to implement a module to perform the actions described in the present disclosure.
[0280] For one embodiment, the control module 904 may include any suitable interface controller to provide any suitable interface to at least one of the processor(s) 902 and / or any suitable device or component in communication with the control module 904 .
[0281] The control module 904 may include a memory controller module to provide an interface to the memory 906. The memory controller module may be a hardware module, a software module, and / or a firmware module.
[0282] The memory 906 may be used, for example, to load and store data and / or instructions 914 for the device 900. For one embodiment, the memory 906 may include any suitable volatile memory, such as a suitable DRAM. In some embodiments, the memory 906 may include double data rate type four synchronous dynamic random access memory (DDR4 SDRAM).
[0283] For one embodiment, control module 904 may include one or more input / output controllers to provide an interface to NVM / storage device 908 and input / output device(s) 910 .
[0284] For example, NVM / storage 908 may be used to store data and / or instructions 914. NVM / storage 908 may include any suitable non-volatile memory (e.g., flash memory) and / or may include any suitable non-volatile storage device(s) (e.g., one or more hard disk drives (HDDs), one or more compact disk (CD) drives, and / or one or more digital versatile disk (DVD) drives).
[0285] NVM / storage device 908 may include storage resources that are physically part of the device on which apparatus 900 is installed, or it may be accessible to the device without being part of the device. For example, NVM / storage device 908 may be accessed via (one or more) input / output devices 910 over a network.
[0286] (One or more) input / output devices 910 may provide an interface for the apparatus 900 to communicate with any other appropriate device, and the input / output device 910 may include a communication component, an audio component, a sensor component, etc. The network interface 912 may provide an interface for the apparatus 900 to communicate through one or more networks, and the apparatus 900 may wirelessly communicate with one or more components of a wireless network according to any of one or more wireless network standards and / or protocols, for example, accessing a wireless network based on a communication standard, such as WiFi, 2G, 3G, 4G, 5G, etc., or a combination thereof for wireless communication.
[0287] For one embodiment, at least one of the processor(s) 902 may be packaged together with the logic of one or more controllers (e.g., a memory controller module) of the control module 904. For one embodiment, at least one of the processor(s) 902 may be packaged together with the logic of one or more controllers of the control module 904 to form a system-in-package (SiP). For one embodiment, at least one of the processor(s) 902 may be integrated on the same die with the logic of one or more controllers of the control module 904. For one embodiment, at least one of the processor(s) 902 may be integrated on the same die with the logic of one or more controllers of the control module 904 to form a system-on-chip (SoC).
[0288] In various embodiments, the device 900 may be, but is not limited to, a terminal device such as a server, a desktop computing device, or a mobile computing device (e.g., a laptop computing device, a handheld computing device, a tablet computer, a netbook, etc.). In various embodiments, the device 900 may have more or fewer components and / or different architectures. For example, in some embodiments, the device 900 includes one or more cameras, a keyboard, a liquid crystal display (LCD) screen (including a touch screen display), a non-volatile memory port, multiple antennas, a graphics chip, an application-specific integrated circuit (ASIC), and a speaker.
[0289] Among them, the main control chip can be used as a processor or control module in the detection device, sensor data, location information, etc. are stored in a memory or NVM / storage device, the sensor group can be used as an input / output device, and the communication interface may include a network interface.
[0290] As for the device embodiment, since it is basically similar to the method embodiment, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0291] The various embodiments in this specification are described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the various embodiments can be referenced to each other.
[0292] The embodiments of the present application are described with reference to the flowcharts and / or block diagrams of the methods, terminal devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing terminal device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing terminal device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0293] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing terminal device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce a manufactured product including an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0294] These computer program instructions can also be loaded onto a computer or other programmable data processing terminal device so that a series of operating steps are executed on the computer or other programmable terminal device to produce a computer-implemented process, thereby providing instructions for implementing the process in the computer or other programmable terminal device. Figure 1 A process or multiple processes and / or boxes Figure 1 A step that specifies a function in one or more boxes.
[0295] Although the preferred embodiments of the present application have been described, those skilled in the art may make additional changes and modifications to these embodiments once they have learned the basic creative concept. Therefore, the appended claims are intended to be interpreted as including the preferred embodiments and all changes and modifications that fall within the scope of the embodiments of the present application.
[0296] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or terminal device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or terminal device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the existence of other identical elements in the process, method, article or terminal device including the elements.
[0297] The transaction processing method and device, an electronic device and a storage medium provided by the present application are introduced in detail above. The principles and implementation methods of the present application are explained in this article using specific examples. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for those skilled in the art, according to the idea of the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.
Claims
1. A transaction processing method, It is characterized in that The method comprises: Obtaining a branch identifier of a branch transaction; wherein the branch identifier includes a first time parameter and a second time parameter; the first time parameter includes a start execution time of the branch transaction, and the second time parameter includes a preset timeout time of a global transaction corresponding to the branch transaction; wherein the preset timeout time is an upper limit of a total execution time of the global transaction; the preset timeout time is determined according to a business scenario or an application scenario, or the preset timeout time is determined according to statistics of an actual execution time of the global transaction; determining the execution duration of the branch transaction according to the first time parameter; If the execution time exceeds the second time parameter, acquiring a transaction state parameter; wherein the transaction state parameter includes a first state parameter of the branch transaction and a second state parameter of the global transaction; If the first state parameter indicates that the branch transaction has not ended, or the second state parameter indicates that the global transaction has not ended, a rollback operation is performed on the branch transaction, and a data lock corresponding to the branch transaction is released.
2. The transaction processing method according to claim 1, It is characterized in that Before the step of obtaining the branch identifier of the branch transaction, the method includes: Obtaining a preset timeout time of the global transaction and obtaining a start execution time of the branch transaction; The preset timeout period and the execution start time are added to the initial identifier of the branch transaction to obtain the branch identifier.
3. The transaction processing method according to claim 2, It is characterized in that The step of obtaining the start execution time of the branch transaction includes: The receiving time of the registration response message is obtained as the start execution time of the branch transaction; the registration response message is a message indicating that the branch transaction is successfully registered with the transaction coordinator.
4. The transaction processing method according to claim 2, It is characterized in that Before the step of adding the preset timeout time and the start execution time to the initial identifier of the branch transaction, the method further includes: Obtaining an exchange identifier of the global transaction and a transaction identifier of the branch transaction; The exchange identifier and the transaction identifier are combined into the initial identifier.
5. The transaction processing method according to claim 1, It is characterized in that After the step of performing a rollback operation on the branch transaction, the method further includes: Receive instruction information sent by the transaction coordinator; If the operation indicated by the indication information is a rollback operation, feeding back first feedback information indicating a successful rollback to the transaction coordinator; If the operation indicated by the indication information is a commit operation, second feedback information indicating a commit exception is fed back to the transaction coordinator.
6. The transaction processing method according to claim 1, It is characterized in that The step of obtaining the branch identifier of the branch transaction includes: At the detection time of each preset cycle, a branch identifier of the branch transaction is obtained.
7. A transaction processing method, It is characterized in that The method comprises: Obtaining the start execution time of the branch transaction, and obtaining the preset timeout time of the global transaction corresponding to the branch transaction; wherein the preset timeout time is the upper limit of the total execution time of the global transaction; the preset timeout time is determined according to the business scenario or application scenario, or the preset timeout time is determined according to the statistics of the actual execution time of the global transaction; Adding the execution start time as a first time parameter and the preset timeout time as a second time parameter to the initial identifier of the branch transaction to obtain a branch identifier; Determining the execution duration of the branch transaction according to the first time parameter in the branch identifier; If the execution time exceeds the second time parameter in the branch identifier, acquiring a transaction state parameter; wherein the transaction state parameter includes a first state parameter of the branch transaction and a second state parameter of the global transaction; If the first state parameter indicates that the branch transaction has not ended, or the second state parameter indicates that the global transaction has not ended, a rollback operation is performed on the branch transaction, and a data lock corresponding to the branch transaction is released.
8. The transaction processing method according to claim 7, It is characterized in that The step of obtaining the start execution time of the branch transaction includes: Obtaining the reception time of the registration response message as the start execution time of the branch transaction; The registration response message is a message indicating that the branch transaction is successfully registered with the transaction coordinator.
9. The transaction processing method according to claim 7, It is characterized in that Before the step of using the execution start time as the first time parameter and adding the preset timeout time as the second time parameter to the initial identifier of the branch transaction, the method further includes: Obtaining an exchange identifier of the global transaction and a transaction identifier of the branch transaction; The exchange identifier and the transaction identifier are combined into the initial identifier.
10. A transaction processing method, applied to a distributed transaction processing system, wherein the distributed transaction processing system comprises a resource manager and a transaction coordinator, It is characterized in that The method comprises: Controlling the resource manager to obtain a branch identifier of a branch transaction; wherein the branch identifier includes a first time parameter and a second time parameter; the first time parameter includes a start execution time of the branch transaction, and the second time parameter includes a preset timeout time of a global transaction corresponding to the branch transaction; wherein the preset timeout time is an upper limit of a total execution time of the global transaction; the preset timeout time is determined according to a business scenario or an application scenario, or the preset timeout time is determined according to statistics of an actual execution time of the global transaction; Determining the execution duration of the branch transaction according to the first time parameter; If the execution time exceeds the second time parameter, a transaction state parameter is obtained; wherein the transaction state parameter includes a first state parameter of the branch transaction and a second state parameter of the global transaction; if the first state parameter indicates that the branch transaction has not ended, or the second state parameter indicates that the global transaction has not ended, a rollback processing operation is performed on the branch transaction, and a release request for releasing the data lock corresponding to the branch transaction is sent to the transaction coordinator; and the transaction coordinator is controlled to receive the release request and release the data lock.
11. A transaction processing device, It is characterized in that The device comprises: An identifier acquisition module, configured to acquire a branch identifier of a branch transaction; wherein the branch identifier includes a first time parameter and a second time parameter; the first time parameter includes a start execution time of the branch transaction, and the second time parameter includes a preset timeout time of a global transaction corresponding to the branch transaction; wherein the preset timeout time is an upper limit of a total execution time of the global transaction; the preset timeout time is determined according to a business scenario or an application scenario, or the preset timeout time is determined according to statistics of an actual execution time of the global transaction; A first duration determination module, configured to determine the execution duration of the branch transaction according to the first time parameter; A rollback processing module is used to obtain a transaction status parameter if the execution time exceeds the second time parameter; wherein the transaction status parameter includes a first status parameter of the branch transaction and a second status parameter of the global transaction; if the first status parameter indicates that the branch transaction has not ended, or the second status parameter indicates that the global transaction has not ended, a rollback processing operation is performed on the branch transaction, and a data lock corresponding to the branch transaction is released.
12. A transaction processing device, It is characterized in that The device comprises: A second time acquisition module is used to acquire the start execution time of the branch transaction and the preset timeout time of the global transaction corresponding to the branch transaction; wherein the preset timeout time is the upper limit of the total execution time of the global transaction; the preset timeout time is determined according to the business scenario or application scenario, or the preset timeout time is determined according to the statistics of the actual execution time of the global transaction; A second adding module, configured to add the execution start time as a first time parameter and the preset timeout time as a second time parameter to the initial identifier of the branch transaction to obtain a branch identifier; A second duration determination module, configured to determine the execution duration of the branch transaction according to the first time parameter in the branch identifier; A rollback execution module is used to obtain a transaction state parameter if the execution time exceeds the second time parameter in the branch identifier; wherein the transaction state parameter includes a first state parameter of the branch transaction and a second state parameter of the global transaction; if the first state parameter indicates that the branch transaction has not ended, or the second state parameter indicates that the global transaction has not ended, perform a rollback processing operation on the branch transaction, and release a data lock corresponding to the branch transaction.
13. A transaction processing device, the device being applied to a distributed transaction processing system, the distributed transaction processing system comprising a resource manager and a transaction coordinator, It is characterized in that The device comprises: A first control module, configured to control the resource manager to obtain a branch identifier of a branch transaction; wherein the branch identifier includes a first time parameter and a second time parameter; the first time parameter includes a start execution time of the branch transaction, and the second time parameter includes a preset timeout time of a global transaction corresponding to the branch transaction; wherein the preset timeout time is an upper limit of a total execution time of the global transaction; the preset timeout time is determined according to a business scenario or an application scenario, or the preset timeout time is determined according to statistics of an actual execution time of the global transaction; Determining the execution duration of the branch transaction according to the first time parameter; If the execution time exceeds the second time parameter, a transaction state parameter is obtained; wherein the transaction state parameter includes a first state parameter of the branch transaction and a second state parameter of the global transaction; if the first state parameter indicates that the branch transaction has not ended, or the second state parameter indicates that the global transaction has not ended, a rollback operation is performed on the branch transaction, and a release request for releasing the data lock corresponding to the branch transaction is sent to the transaction coordinator; The second control module is used to control the transaction coordinator to receive the release request and release the data lock.
14. An electronic device, It is characterized in that include: processor; and A memory having executable codes stored thereon, which, when executed, cause the processor to perform the method as claimed in one or more of claims 1 to 10.
15. One or more machine-readable storage media having executable code stored thereon, It is characterized in that When the executable code is executed, the processor is caused to perform the method as claimed in one or more of claims 1 to 10.
