A transaction execution method and apparatus

CN116266316BActive Publication Date: 2026-10-13DOUYIN VISION CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111543336.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-12-16
Publication Date
2026-10-13
Estimated Expiration
2041-12-16

AI Technical Summary

Technical Problem

再例如:在上述示例中,子事务“用户的余额增加转账金额”实现失败,而其它子事务均实现成功,用户得到的反馈为转账已接收但余额并未增加相应的金额,转账资金丢失

Benefits of technology

[0073]本发明实施例提供的事务执行方法在接收到用于请求执行目标事务的请求信息时,先创建所述目标事务的各个子事务,然后执行同步流程,以及根据所述同步流程的执行结果向事务协调节点发送状态报告,从而使所述事务协调节点在所述目标子事务的业务逻辑实现失败的情况下,对所述目标子事务之前的各个子事务的业务逻辑进行回滚或对所述目标子事务和所述目标子事务之后的各个子事务的业务逻辑进行实现。即,本发明实施例首先按照预设顺序逐一实现所述目标事务的各个子事务的业务逻辑,若所述目标事务的目标子事务的业务逻辑实现失败,则先停止实现后续子事务的业务逻辑,并向事务协调节点发送同步流程中最后一个进行业务逻辑实现的子事务的该子事务的业务逻辑实现结果,进而使所述事务协调节点在所述目标子事务的业务逻辑实现失败的情况下,对所述目标子事务之前的各个子事务的业务逻辑进行回滚或对所述目标子事务和所述目标子事务之后的各个子事务的业务逻辑进行实现。由于本发明实施例可以在同步流程未能实现所述目标事务的所有子事务的业务逻辑时,对业务逻辑已实现的子事务的业务逻辑进行回滚,或者对业务逻辑未实现的子事务的业务逻辑进行实现,因此上述实施例可以保证目标事务的最终执行结果为目标事务的所有子事务的业务逻辑均实现或均未实现,因此上述实施例可以保证目标事务的各个子事务的最终一致性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116266316B_ABST
    Figure CN116266316B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a transaction execution method and device, and relate to the technical field of computers. The method comprises: receiving request information; in response to the request information, creating each sub-transaction of a target transaction; executing a synchronization process; the synchronization process is used to sequentially implement the business logic of each sub-transaction of the target transaction in a preset order until the business logic of the current sub-transaction fails to be implemented or the business logic of each sub-transaction of the target transaction is successfully implemented; and sending a state report to a transaction coordination node according to the execution result of the synchronization process, so that the transaction coordination node, in the case that the business logic of the target sub-transaction fails to be implemented, rolls back the business logic of each sub-transaction before the target sub-transaction or implements the business logic of the target sub-transaction and each sub-transaction after the target sub-transaction. Embodiments of the present application are used to ensure the eventual consistency of each sub-transaction of a transaction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of computer technology, and in particular to a transaction execution method and apparatus. Background Technology

[0002] Distributed transactions refer to transactions where the participants, supporting servers, resource servers, and transaction management servers reside on different distributed nodes within a distributed system. With the rapid development of internet services and the increasing complexity of internet businesses, many systems have transitioned from centralized to distributed systems; therefore, distributed transactions are very common in the internet field.

[0003] With the prevalence of distributed systems and microservice frameworks, even a very simple transaction may require the server to collaborate through multiple services and database instances. Such transactions, completed collaboratively by multiple services and database instances, have consistency requirements. For example, in a scenario of receiving a network transfer, the transaction of "receiving a network transfer" includes sub-transactions such as checking if the transfer is valid, setting the transfer status to "received," and adding the transfer amount to the user's balance. Clearly, all these sub-transactions can succeed or fail. However, if some sub-transactions succeed while others fail, it results in a very serious system failure. For example, in the above example, the sub-transaction "setting the network transfer status to "received"" fails, while other sub-transactions succeed. Because the network transfer status is not set to "received," the user may receive a duplicate network transfer. As another example, in the above example, the sub-transaction "adding the transfer amount to the user's balance" fails, while other sub-transactions succeed. The user receives feedback that the transfer was received but the balance has not increased accordingly, resulting in lost funds. In summary, ensuring the eventual consistency of all sub-transactions is a fundamental requirement for transaction execution. Therefore, how to guarantee the eventual consistency of all sub-transactions is one of the classic problems in the transaction execution process. Summary of the Invention

[0004] In view of this, the present invention provides a transaction execution method and apparatus for ensuring the eventual consistency of each sub-transaction of a transaction.

[0005] To achieve the above objectives, the embodiments of the present invention provide the following technical solutions:

[0006] In a first aspect, embodiments of the present invention provide a transaction execution method applied to a transaction initiating node, the method comprising:

[0007] Receive request information, the request information being used to request the execution of a target transaction;

[0008] In response to the request information, create each sub-transaction of the target transaction;

[0009] Execute the synchronization process; the synchronization process is used to implement the business logic of each sub-transaction of the target transaction one by one in a preset order, until the business logic of the current sub-transaction fails to be implemented or the business logic of each sub-transaction of the target transaction is successfully implemented.

[0010] Based on the execution result of the synchronization process, a status report is sent to the transaction coordination node. The status report is used to indicate the target sub-transaction and the business logic implementation result of the target sub-transaction. The target sub-transaction is the last sub-transaction in the synchronization process to implement its business logic. This allows the transaction coordination node to roll back the business logic of each sub-transaction before the target sub-transaction or implement the business logic of the target sub-transaction and each sub-transaction after the target sub-transaction if the business logic implementation of the target sub-transaction fails.

[0011] As an optional implementation of this invention, the creation of each sub-transaction of the target transaction includes:

[0012] Configure the business logic of each sub-transaction of the target transaction and the preset order;

[0013] Configure the transaction type as a sub-transaction of a critical sub-transaction;

[0014] Configure the transaction type of each sub-transaction preceding the critical sub-transaction as a rollbackable sub-transaction;

[0015] Configure the transaction type of each subtransaction after the critical subtransaction as a non-rollback subtransaction.

[0016] As an optional implementation of this invention, the method further includes:

[0017] The execution result of the target transaction is output based on the execution result of the synchronization process.

[0018] As an optional implementation of this invention, the step of outputting the execution result of the target transaction based on the execution result of the synchronization process includes:

[0019] If the execution result of the synchronization process is that the business logic of each sub-transaction of the target transaction is successfully implemented or the business logic of any sub-transaction after the critical sub-transaction fails, a first execution result is output to characterize the successful execution of the target transaction.

[0020] If the execution result of the synchronization process is that the business logic implementation of the critical sub-transaction fails or the business logic implementation of any sub-transaction preceding the critical sub-transaction fails, a second execution result is output to characterize the failure of the target transaction.

[0021] As an optional implementation of this invention, the execution synchronization process includes:

[0022] Starting with the first sub-transaction in the preset order, the implementation method of the current sub-transaction is executed; the implementation method of any sub-transaction is used to implement the business logic of that sub-transaction;

[0023] Determine whether the implementation method of the current sub-transaction has been executed successfully;

[0024] If the implementation method of the current sub-transaction is executed successfully, then determine whether the current sub-transaction is the last sub-transaction in the preset order;

[0025] If the current sub-transaction is not the last sub-transaction in the preset order, then the implementation method of the next sub-transaction after the current sub-transaction is executed until the business logic of the current sub-transaction fails or the business logic of each sub-transaction of the target transaction is successfully implemented.

[0026] Secondly, embodiments of the present invention provide a transaction execution method applied to a transaction coordination node, the method comprising:

[0027] Receive a status report sent by the transaction initiating node. The status report is used to indicate the target sub-transaction and the business logic implementation result of the target sub-transaction. The target sub-transaction is the last sub-transaction to implement business logic in the synchronization process. The synchronization process is used to implement the business logic of each sub-transaction of the target transaction one by one in a preset order until the business logic implementation of the current sub-transaction fails or the business logic implementation of each sub-transaction of the target transaction is successful.

[0028] If the business logic of the target sub-transaction fails to be implemented, the business logic of each sub-transaction preceding the target sub-transaction is rolled back, or the business logic of the target sub-transaction and each sub-transaction following the target sub-transaction is implemented.

[0029] As an optional implementation of this invention, the step of rolling back the business logic of each sub-transaction preceding the target sub-transaction or implementing the business logic of the target sub-transaction and each sub-transaction following the target sub-transaction includes:

[0030] If the transaction type of the target sub-transaction is a rollback sub-transaction, a rollback process is executed to roll back the business logic of each sub-transaction preceding the target sub-transaction.

[0031] If the target sub-transaction is a non-rollbackable sub-transaction, an asynchronous process is executed to implement the business logic of the target sub-transaction and each subsequent sub-transaction.

[0032] As an optional implementation of this invention, the rollback process includes:

[0033] Starting from the target sub-transaction, execute the rollback method of the current sub-transaction. The rollback method of any sub-transaction is used to roll back the business logic of that sub-transaction.

[0034] Determine whether the rollback method of the current sub-transaction has been executed successfully;

[0035] If the rollback method of the current sub-transaction is executed successfully, then determine whether the current sub-transaction is the first sub-transaction in the preset order;

[0036] If the current sub-transaction is not the first sub-transaction in the preset order, then the rollback method of the previous sub-transaction is executed until the current sub-transaction is the first sub-transaction in the preset order.

[0037] As an optional implementation of this invention, the execution of the asynchronous process includes:

[0038] Starting from the target sub-transaction, execute the implementation method of the current sub-transaction; the implementation method of any sub-transaction is used to implement the business logic of that sub-transaction;

[0039] Determine whether the implementation method of the current sub-transaction has been executed successfully;

[0040] If the implementation method of the current sub-transaction is executed successfully, then determine whether the current sub-transaction is the last sub-transaction in the preset order;

[0041] If the current sub-transaction is not the last sub-transaction in the preset order, then the implementation method of the next sub-transaction of the current sub-transaction is executed until the current sub-transaction is the last sub-transaction in the preset order.

[0042] As an optional implementation of this invention, the method further includes:

[0043] If the target sub-transaction is a critical sub-transaction or the status report reception is abnormal, an confirmation process is executed, and the business logic of each sub-transaction whose business logic has been implemented is rolled back according to the execution result of the confirmation process, or the business logic of each sub-transaction whose business logic has not been implemented is implemented.

[0044] The confirmation process is used to confirm, in the preset order, whether the business logic of each sub-transaction of the target transaction has been implemented, and to determine whether the current sub-transaction is the critical sub-transaction when the business logic of the current sub-transaction has been implemented, until the business logic of the current sub-transaction has not been implemented or whether the current sub-transaction is the critical sub-transaction.

[0045] As an optional implementation of this invention, the execution confirmation process, and the rollback of the business logic of each sub-transaction that has been implemented, or the implementation of the business logic of each sub-transaction that has not been implemented, based on the execution result of the confirmation process, includes:

[0046] Starting from the first sub-transaction in the preset order, the confirmation method of the current sub-transaction is executed; the confirmation method of any sub-transaction is used to confirm whether the business logic of the sub-transaction has been implemented.

[0047] If the business logic of the current sub-transaction is not implemented, the business logic of all sub-transactions preceding the current sub-transaction will be rolled back.

[0048] If the business logic of the current sub-transaction has been implemented, then determine whether the current sub-transaction is the critical sub-transaction;

[0049] If the current sub-transaction is not the critical sub-transaction, then the confirmation method of the previous sub-transaction of the current sub-transaction is executed until the business logic of the current sub-transaction is not implemented or whether the current sub-transaction is the critical sub-transaction.

[0050] If the current sub-transaction is the critical sub-transaction, then the business logic of the current sub-transaction and all subsequent sub-transactions shall be implemented.

[0051] Thirdly, embodiments of the present invention provide a transaction execution apparatus, comprising:

[0052] A receiving unit is configured to receive request information, wherein the request information is used to request the execution of a target transaction;

[0053] A creation unit is used to create each sub-transaction of the target transaction in response to the request information;

[0054] An execution unit is used to execute a synchronization process; the synchronization process is used to implement the business logic of each sub-transaction of the target transaction one by one in a preset order, until the business logic of the current sub-transaction fails to be implemented or the business logic of each sub-transaction of the target transaction is successfully implemented.

[0055] The sending unit is configured to send a status report to the transaction coordination node based on the execution result of the synchronization process. The status report is used to indicate the target sub-transaction and the business logic implementation result of the target sub-transaction. The target sub-transaction is the last sub-transaction in the synchronization process to implement its business logic, so that if the business logic implementation of the target sub-transaction fails, the transaction coordination node can either roll back the business logic of each sub-transaction before the target sub-transaction or implement the business logic of the target sub-transaction and each sub-transaction after the target sub-transaction.

[0056] As an optional implementation of this invention, the creation unit is specifically used to configure the business logic of each sub-transaction of the target transaction and the preset order; configure the transaction type as a critical sub-transaction; configure the transaction type of each sub-transaction before the critical sub-transaction as a rollbackable sub-transaction; and configure the transaction type of each sub-transaction after the critical sub-transaction as a non-rollbackable sub-transaction.

[0057] As an optional implementation of this invention, the transaction execution device further includes:

[0058] The output unit is used to output the execution result of the target transaction based on the execution result of the synchronization process.

[0059] As an optional implementation of the present invention, the output unit is specifically configured to output a first execution result indicating that the target transaction was successfully executed when the execution result of the synchronization process is that the business logic of each sub-transaction of the target transaction was successfully implemented or the business logic of any sub-transaction after the critical sub-transaction failed; and to output a second execution result indicating that the target transaction failed when the execution result of the synchronization process is that the business logic of the critical sub-transaction failed or the business logic of any sub-transaction before the critical sub-transaction failed.

[0060] As an optional implementation of this invention, the execution unit is specifically used to execute the implementation method of the current sub-transaction starting from the first sub-transaction in the preset order; the implementation method of any sub-transaction is used to implement the business logic of the sub-transaction; it is determined whether the implementation method of the current sub-transaction is executed successfully; if the implementation method of the current sub-transaction is executed successfully, it is determined whether the current sub-transaction is the last sub-transaction in the preset order; if the current sub-transaction is not the last sub-transaction in the preset order, the implementation method of the next sub-transaction of the current sub-transaction is executed until the business logic of the current sub-transaction fails to be implemented or the business logic of each sub-transaction of the target transaction is successfully implemented.

[0061] Fourthly, embodiments of the present invention provide a transaction execution apparatus, comprising:

[0062] The receiving unit is used to receive a status report sent by the transaction initiating node. The status report is used to indicate the target sub-transaction and the business logic implementation result of the target sub-transaction. The target sub-transaction is the last sub-transaction to implement business logic in the synchronization process. The synchronization process is used to implement the business logic of each sub-transaction of the target transaction one by one in a preset order until the business logic implementation of the current sub-transaction fails or the business logic implementation of each sub-transaction of the target transaction is successful.

[0063] The processing unit is configured to, in the event that the business logic implementation of the target sub-transaction fails, either roll back the business logic of each sub-transaction preceding the target sub-transaction or implement the business logic of the target sub-transaction and each sub-transaction following the target sub-transaction, based on the transaction type of the target sub-transaction.

[0064] As an optional implementation of this invention, the processing unit is specifically configured to: execute a rollback process to roll back the business logic of each sub-transaction preceding the target sub-transaction when the transaction type of the target sub-transaction is a rollbackable sub-transaction; and execute an asynchronous process to implement the business logic of the target sub-transaction and each sub-transaction following the target sub-transaction when the type of the target sub-transaction is a non-rollbackable sub-transaction.

[0065] As an optional implementation of this invention, the rollback process includes: starting from the target sub-transaction, executing the rollback method of the current sub-transaction, wherein the rollback method of any sub-transaction is used to roll back the business logic of the sub-transaction; determining whether the rollback method of the current sub-transaction is executed successfully; if the rollback method of the current sub-transaction is executed successfully, determining whether the current sub-transaction is the first sub-transaction in the preset order; if the current sub-transaction is not the first sub-transaction in the preset order, executing the rollback method of the previous sub-transaction of the current sub-transaction, until the current sub-transaction is the first sub-transaction in the preset order.

[0066] As an optional implementation of this invention, the asynchronous execution process includes: starting from the target sub-transaction, executing the implementation method of the current sub-transaction; the implementation method of any sub-transaction is used to implement the business logic of the sub-transaction; determining whether the implementation method of the current sub-transaction is executed successfully; if the implementation method of the current sub-transaction is executed successfully, determining whether the current sub-transaction is the last sub-transaction in the preset order; if the current sub-transaction is not the last sub-transaction in the preset order, executing the implementation method of the next sub-transaction of the current sub-transaction, until the current sub-transaction is the last sub-transaction in the preset order.

[0067] As an optional implementation of this invention, the processing unit is further configured to execute a confirmation process when the target sub-transaction is a critical sub-transaction or the status report reception is abnormal, and to roll back the business logic of each sub-transaction whose business logic has been implemented, or to implement the business logic of each sub-transaction whose business logic has not been implemented, based on the execution result of the confirmation process.

[0068] The confirmation process is used to confirm, in the preset order, whether the business logic of each sub-transaction of the target transaction has been implemented, and to determine whether the current sub-transaction is the critical sub-transaction when the business logic of the current sub-transaction has been implemented, until the business logic of the current sub-transaction has not been implemented or whether the current sub-transaction is the critical sub-transaction.

[0069] As an optional implementation of this invention, the processing unit is specifically configured to execute the confirmation method of the current sub-transaction starting from the first sub-transaction in the preset order; the confirmation method of any sub-transaction is used to confirm whether the business logic of the sub-transaction is implemented; if the business logic of the current sub-transaction is not implemented, the business logic of each sub-transaction preceding the current sub-transaction is rolled back; if the business logic of the current sub-transaction is implemented, it is determined whether the current sub-transaction is the critical sub-transaction; if the current sub-transaction is not the critical sub-transaction, the confirmation method of the previous sub-transaction of the current sub-transaction is executed until the business logic of the current sub-transaction is not implemented or whether the current sub-transaction is the critical sub-transaction; if the current sub-transaction is the critical sub-transaction, the business logic of the current sub-transaction and each sub-transaction following the current sub-transaction is implemented.

[0070] Fifthly, embodiments of the present invention provide an electronic device, including: a memory and a processor, wherein the memory is used to store a computer program; and the processor is used to cause the electronic device to implement the transaction execution method described in any of the above embodiments when the computer program is invoked.

[0071] In a sixth aspect, embodiments of the present invention provide a computer-readable storage medium that, when the computer program is executed by a computing device, causes the computing device to implement the transaction execution method described in any of the above embodiments.

[0072] In a seventh aspect, embodiments of the present invention provide a computer program product that, when run on a computer, enables the computer to implement the transaction execution method described in any of the above embodiments.

[0073] The transaction execution method provided in this embodiment of the invention, upon receiving a request for execution of a target transaction, first creates each sub-transaction of the target transaction, then executes a synchronization process, and sends a status report to the transaction coordination node based on the execution result of the synchronization process. This allows the transaction coordination node to either roll back the business logic of each sub-transaction preceding the target sub-transaction or implement the business logic of the target sub-transaction and all subsequent sub-transactions if the business logic implementation of the target sub-transaction fails. Specifically, this embodiment of the invention first implements the business logic of each sub-transaction of the target transaction one by one in a preset order. If the business logic implementation of the target sub-transaction fails, the implementation of the business logic of subsequent sub-transactions is stopped, and the business logic implementation result of the last sub-transaction implemented in the synchronization process is sent to the transaction coordination node. This allows the transaction coordination node to either roll back the business logic of each sub-transaction preceding the target sub-transaction or implement the business logic of the target sub-transaction and all subsequent sub-transactions if the business logic implementation of the target sub-transaction fails. Since the embodiments of the present invention can roll back the business logic of the sub-transactions whose business logic has been implemented, or implement the business logic of the sub-transactions whose business logic has not been implemented, when the synchronous process fails to implement the business logic of all sub-transactions of the target transaction, the above embodiments can guarantee that the final execution result of the target transaction is that the business logic of all sub-transactions of the target transaction is implemented or not implemented. Therefore, the above embodiments can guarantee the eventual consistency of each sub-transaction of the target transaction. Attached Figure Description

[0074] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.

[0075] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0076] Figure 1 This is a scenario architecture diagram of the transaction execution method provided in an embodiment of the present invention;

[0077] Figure 2 This is one of the flowcharts for a transaction execution method provided in an embodiment of the present invention;

[0078] Figure 3 A flowchart illustrating the steps of the synchronization process provided in this embodiment of the invention;

[0079] Figure 4 The second flowchart of the transaction execution method provided in the embodiments of the present invention;

[0080] Figure 5 A flowchart illustrating the rollback process provided in this embodiment of the invention;

[0081] Figure 6 A flowchart illustrating the steps of an asynchronous process provided in an embodiment of the present invention;

[0082] Figure 7 The third flowchart of the transaction execution method provided in the embodiments of the present invention;

[0083] Figure 8 A flowchart illustrating the steps of the confirmation process provided in this embodiment of the invention;

[0084] Figure 9 One of the schematic diagrams of a transaction execution device provided in an embodiment of the present invention;

[0085] Figure 10 A second schematic diagram of a transaction execution device provided in an embodiment of the present invention;

[0086] Figure 11 A schematic diagram of a transaction execution device provided in an embodiment of the present invention;

[0087] Figure 12 This is a schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation

[0088] To better understand the above-mentioned objectives, features, and advantages of the present invention, the solutions of the present invention will be further described below. It should be noted that, unless otherwise specified, the embodiments of the present invention and the features thereof can be combined with each other.

[0089] Many specific details are set forth in the following description in order to provide a full understanding of the invention, but the invention may also be practiced in other ways different from those described herein; obviously, the embodiments in the specification are only some embodiments of the invention, and not all embodiments.

[0090] It should be noted that, in order to clearly describe the technical solutions of the embodiments of the present invention, the terms "first" and "second" are used in the embodiments of the present invention to distinguish identical or similar items with essentially the same function and effect. Those skilled in the art will understand that the terms "first" and "second" are not intended to limit the quantity or execution order. For example, the target sub-transaction and the second sub-transaction are merely to distinguish different sub-transactions, and not to limit the order of the sub-transactions.

[0091] In the embodiments of the present invention, the terms "exemplary" or "for example" are used to indicate that something is an example, illustration, or description. Any embodiment or design described as "exemplary" or "for example" in the embodiments of the present invention should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of the terms "exemplary" or "for example" is intended to present the relevant concepts in a specific manner. Furthermore, in the description of the embodiments of the present invention, unless otherwise stated, "a plurality of" means two or more.

[0092] The following section first describes the scenario architecture of the transaction execution method provided in the embodiments of the present invention.

[0093] Reference Figure 1 As shown, the scenario of the transaction execution method provided in this embodiment of the invention includes: a transaction initiating node (Transaction Manager, TM) 11, a transaction coordinating node (Transaction Coordinator, TC) 12, and multiple resource management nodes 13 (Resource Manager, RM). Figure 1 The example shown in the transaction execution method includes two resource management nodes 13, but the embodiments of the present invention are not limited thereto.

[0094] The main functions of the transaction initiating node 11 include:

[0095] a. Receive request information for requesting the execution of a specified transaction.

[0096] b. Invoke transaction coordinator node 12 to create a sub-transaction of the specified transaction.

[0097] c. Call resource management node 13 to execute the synchronization process.

[0098] d. Based on the execution result of the synchronization process, send a status report to the transaction coordination node 12 to indicate the last sub-transaction in the synchronization process to perform business logic implementation and the result of the business logic implementation of that transaction.

[0099] The main functions of transaction coordination node 12 include:

[0100] a. Accept the call from transaction initiator node 11 to create a sub-transaction of the specified transaction.

[0101] b. Receive the status report sent by the transaction initiating node 11.

[0102] c. If the business logic implementation of the last sub-transaction in the synchronization process fails, call the resource management node 13 to roll back the business logic of each sub-transaction before the target sub-transaction or to implement the business logic of the target sub-transaction and each sub-transaction after the target sub-transaction.

[0103] The main functions of resource management node 13 include:

[0104] a. Receive calls from transaction initiating node 11 or transaction coordinating node 12 to implement the business network logic of the sub-transaction.

[0105] b. Receive the call from transaction coordination node 12 and roll back the business network logic of the sub-transaction.

[0106] It should be noted that although the transaction initiating node 11, transaction coordinating node 12, and resource management node 13 in this embodiment of the invention are independent functional implementation nodes at the software level, this embodiment of the invention does not limit the relationship between the transaction initiating node 11, transaction coordinating node 12, and resource management node 13 at the hardware level. The transaction initiating node 11, transaction coordinating node 12, and resource management node 13 can be independent hardware devices in the distributed system, or multiple software devices located on the same hardware device in the distributed system.

[0107] Based on the above, embodiments of the present invention provide a transaction execution method, referring to... Figure 2 As shown, the transaction execution method provided in this embodiment of the invention includes the following steps:

[0108] S21. The transaction initiating node receives the request information.

[0109] The request information is used to request the execution of the target transaction.

[0110] For example, the implementation of the transaction initiating node receiving request information may include:

[0111] In response to a user's action on the terminal device, the terminal device sends a request message to the transaction initiating node, and the corresponding transaction initiating node receives the request message sent by the terminal device. For example, if a user enters an action to request a refund on the terminal device, the terminal device sends a request message to the transaction initiating node to request the execution of the refund transaction.

[0112] S22. The transaction initiating node responds to the request information and creates each sub-transaction of the target transaction.

[0113] Optionally, one implementation of step S22 (creating each sub-transaction of the target transaction) is as follows:

[0114] The transaction initiating node calls the transaction coordinating node to create the various sub-transactions of the target transaction.

[0115] Optionally, another implementation of step S22 (creating the sub-transactions of the target transaction) is as follows:

[0116] The transaction initiating node creates each sub-transaction of the target transaction.

[0117] Further optionally, step S22 (creating the sub-transactions of the target transaction) includes:

[0118] Configure the business logic, type, and order of each sub-transaction of the target transaction.

[0119] That is, the sub-transactions that create the target transaction include:

[0120] Configure the business logic of each sub-transaction of the target transaction and the preset order;

[0121] Configure the transaction type as a sub-transaction of a critical sub-transaction;

[0122] Configure the transaction type of each sub-transaction preceding the critical sub-transaction as a rollbackable sub-transaction;

[0123] Configure the transaction type of each subtransaction after the critical subtransaction as a non-rollback subtransaction.

[0124] That is, sub-transactions are abstracted into three types of self-transactions: rollback sub-transactions, critical sub-transactions, and non-rollback sub-transactions.

[0125] S23, The transaction initiating node executes the synchronization process.

[0126] The synchronization process is used to implement the business logic of each sub-transaction of the target transaction one by one in a preset order, until the business logic of the current sub-transaction fails or the business logic of each sub-transaction of the target transaction is successfully implemented.

[0127] As an optional implementation of the present invention, refer to Figure 3 As shown, the execution of the synchronization process includes: starting from the first sub-transaction in the preset order, performing the following steps:

[0128] S31. Execute the implementation method of the current sub-transaction.

[0129] The implementation method of any sub-transaction is used to implement the business logic of that sub-transaction.

[0130] Since the implementation method of each sub-transaction may be executed, it is also necessary to implement the implementation method of each sub-transaction when creating each sub-transaction.

[0131] S32. Determine whether the implementation method of the current sub-transaction has been executed successfully.

[0132] If the implementation method of the current sub-transaction fails to execute in step S32 above, then step S33 is executed.

[0133] S33. End the synchronization process.

[0134] In step S32 above, if the implementation method of the current sub-transaction is executed successfully, then step S34 is executed.

[0135] S34. Determine whether the current sub-transaction is the last sub-transaction in the preset order.

[0136] That is, determine whether there are any sub-transactions with unimplemented business logic after the current sub-transaction.

[0137] In step S34 above, if the current sub-transaction is the last sub-transaction in the preset order, then step S33 (end the synchronization process) is executed. If the current sub-transaction is not the last sub-transaction in the preset order, then the implementation method of the next sub-transaction of the current sub-transaction is executed until the business logic of the current sub-transaction fails or the business logic of each sub-transaction of the target transaction is successfully implemented.

[0138] S24. The transaction initiating node sends a status report to the transaction coordinating node based on the execution result of the synchronization process.

[0139] Correspondingly, the transaction coordinating node receives the status report sent by the transaction initiating node.

[0140] The status report is used to indicate the target sub-transaction and the business logic implementation result of the target sub-transaction, wherein the target sub-transaction is the last sub-transaction to implement business logic in the synchronization process.

[0141] For example: If the business logic implementation result of sub-transaction A in the synchronization process fails, then the synchronization process ends. Transaction A is the last sub-transaction to implement business logic in the synchronization process, therefore a status report indicating that transaction A failed is generated. As another example: If the business logic implementation result of the last sub-transaction B in the preset order of the synchronization process succeeds, then the synchronization process ends. Transaction B is the last sub-transaction to implement business logic in the synchronization process, therefore a status report indicating that transaction B succeeded is generated.

[0142] In this embodiment of the invention, the status report is used to indicate the transaction status of each sub-transaction. The transaction status of a sub-transaction includes three types: when the business logic of a sub-transaction is successfully implemented, the transaction status of the sub-transaction is a success status; when the business logic of a sub-transaction fails to be implemented, the transaction status of the sub-transaction is a failure status; and when the business logic of a sub-transaction has not been implemented, the transaction status of the sub-transaction is an initial status.

[0143] If the execution result of the synchronization process is that the transaction status of each sub-transaction of the target transaction is successful, the transaction execution method provided in this embodiment of the invention ends. If the business logic implementation of the target sub-transaction fails, the following step S25 continues to be executed.

[0144] S25. The transaction coordination node rolls back the business logic of each sub-transaction before the target sub-transaction or implements the business logic of the target sub-transaction and each sub-transaction after the target sub-transaction.

[0145] As an optional implementation of the present invention, refer to Figure 4 As shown, step S25 (the transaction coordination node rolls back the business logic of each sub-transaction before the target sub-transaction or implements the business logic of the target sub-transaction and each sub-transaction after the target sub-transaction) includes:

[0146] S41. Determine the transaction type of the target sub-transaction.

[0147] If the target subtransaction is a rollable subtransaction, perform step S42; if the target subtransaction is a non-rollable subtransaction, perform step S43.

[0148] S42. Execute the rollback process to roll back the business logic of each sub-transaction preceding the target sub-transaction.

[0149] S43. Execute an asynchronous process to implement the business logic of the target sub-transaction and each subsequent sub-transaction.

[0150] Furthermore, refer to Figure 5 As shown, step S42 (execute rollback process) includes: starting from the target sub-transaction, performing the following steps:

[0151] S51. Execute the rollback method of the current sub-transaction.

[0152] The rollback method for any sub-transaction is used to roll back the business logic of that sub-transaction.

[0153] S52. Determine whether the rollback method of the current sub-transaction has been executed successfully.

[0154] In step S52 above, if the rollback method of the current sub-transaction fails to execute successfully, return to step S51 and continuously retry executing the rollback method of the current sub-transaction until the rollback method of the current sub-transaction succeeds; if the rollback method of the current sub-transaction succeeds or fails to execute successfully, proceed to step S53 below.

[0155] S53. Determine whether the current sub-transaction is the first sub-transaction in the preset order.

[0156] In step S52 above, if the current sub-transaction is the first sub-transaction in the preset order, it indicates that the business logic of the sub-transactions whose business logic has been implemented in the synchronization process has been rolled back. Therefore, step S54 is executed.

[0157] S54, End the rollback process.

[0158] In step S53 above, if the current sub-transaction is not the first sub-transaction in the preset order, it indicates that the business logic of the sub-transactions whose business logic has been implemented in the synchronous process has not been rolled back. Therefore, the rollback method of the previous sub-transaction of the current sub-transaction is executed until the current sub-transaction is the first sub-transaction in the preset order.

[0159] Furthermore, refer to Figure 6 As shown, step S43 (execute asynchronous process) includes: starting from the target sub-transaction, executing the following steps:

[0160] S61. Execute the implementation method of the current sub-transaction.

[0161] S62. Determine whether the implementation method of the current sub-transaction has been executed successfully.

[0162] In step S62 above, if the implementation method of the current sub-transaction fails to execute, the process returns to step S61 and continuously retryes the implementation method of the current sub-transaction until the implementation method of the current sub-transaction succeeds.

[0163] In step S62 above, if the implementation method of the current sub-transaction is executed successfully, then step S63 is executed.

[0164] S63. Determine whether the current sub-transaction is the last sub-transaction in the preset order.

[0165] In step S63 above, if the current sub-transaction is the last sub-transaction in the preset order, it indicates that the business logic of the unimplemented sub-transactions in the synchronization process has been implemented, so step S64 is executed.

[0166] S64. End the asynchronous process.

[0167] In step S63 above, if the current sub-transaction is not the last sub-transaction in the preset order, it indicates that there are still sub-transactions in the synchronous process whose business logic has not been implemented. Therefore, the implementation method of the next sub-transaction after the current sub-transaction is executed until the current sub-transaction is the last sub-transaction in the preset order.

[0168] The transaction execution method provided in this embodiment of the invention, upon receiving a request for execution of a target transaction, first creates each sub-transaction of the target transaction, then executes a synchronization process, and sends a status report to the transaction coordination node based on the execution result of the synchronization process. This allows the transaction coordination node to either roll back the business logic of each sub-transaction preceding the target sub-transaction or implement the business logic of the target sub-transaction and all subsequent sub-transactions if the business logic implementation of the target sub-transaction fails. Specifically, this embodiment of the invention first implements the business logic of each sub-transaction of the target transaction one by one in a preset order. If the business logic implementation of the target sub-transaction fails, the implementation of the business logic of subsequent sub-transactions is stopped, and the business logic implementation result of the last sub-transaction implemented in the synchronization process is sent to the transaction coordination node. This allows the transaction coordination node to either roll back the business logic of each sub-transaction preceding the target sub-transaction or implement the business logic of the target sub-transaction and all subsequent sub-transactions if the business logic implementation of the target sub-transaction fails. Since the embodiments of the present invention can roll back the business logic of the sub-transactions whose business logic has been implemented, or implement the business logic of the sub-transactions whose business logic has not been implemented, when the synchronous process fails to implement the business logic of all sub-transactions of the target transaction, the above embodiments can guarantee that the final execution result of the target transaction is that the business logic of all sub-transactions of the target transaction is implemented or not implemented. Therefore, the above embodiments can guarantee the eventual consistency of each sub-transaction of the target transaction.

[0169] As an optional implementation of this invention, the method further includes:

[0170] The transaction initiating node outputs the execution result of the target transaction based on the execution result of the synchronization process.

[0171] Furthermore, the implementation method of outputting the execution result of the target transaction based on the execution result of the synchronization process includes:

[0172] If the execution result of the synchronization process is that the business logic of each sub-transaction of the target transaction is successfully implemented or the business logic of any sub-transaction after the critical sub-transaction fails, a first execution result is output to characterize the successful execution of the target transaction.

[0173] If the execution result of the synchronization process is that the business logic implementation of the critical sub-transaction fails or the business logic implementation of any sub-transaction preceding the critical sub-transaction fails, a second execution result is output to characterize the failure of the target transaction.

[0174] That is, the output of the first execution result used to characterize the successful execution of the target transaction includes:

[0175] Case 1: The business logic of each sub-transaction of the target transaction is successfully implemented.

[0176] Case 2: The business logic of all sub-transactions before the critical sub-transaction of the target transaction and the critical sub-transaction are all successfully implemented, while the business logic of the sub-transaction after the critical sub-transaction fails to be implemented.

[0177] The output of a second execution result to characterize the failure of the target transaction includes:

[0178] Case 3: The business logic implementation of the critical sub-transaction of the target transaction fails.

[0179] Case 4: The business logic implementation of a sub-transaction preceding the critical sub-transaction of the target transaction fails.

[0180] That is, if the sub-transaction in which the business logic fails is located after the critical sub-transaction, the first execution result is output synchronously; if the sub-transaction in which the business logic fails is a critical sub-transaction or is located before the critical sub-transaction, the second execution result is output synchronously.

[0181] The above embodiments can output corresponding feedback information based on the execution result of the synchronization process. Therefore, the above embodiments can synchronously output the execution result of the target transaction based on the execution result of the synchronization process, thereby enabling the above transaction execution method to meet the requirements of online business.

[0182] As an optional implementation of the present invention, refer to Figure 7 As shown, the transaction execution method provided in this embodiment of the invention further includes: when the target sub-transaction is a critical sub-transaction or the status report reception is abnormal, the transaction coordination node performs the following step S71:

[0183] S71. Execute the confirmation process, and roll back the business logic of each sub-transaction that has been implemented, or implement the business logic of each sub-transaction that has not been implemented, based on the execution result of the confirmation process.

[0184] The confirmation process is used to confirm, in the preset order, whether the business logic of each sub-transaction of the target transaction has been implemented, and to determine whether the current sub-transaction is the critical sub-transaction when the business logic of the current sub-transaction has been implemented, until the business logic of the current sub-transaction has not been implemented or whether the current sub-transaction is the critical sub-transaction.

[0185] Specifically, in cases of network anomalies, the transaction initiating node may be unable to send status reports to the transaction coordinating node normally. In this case, the transaction coordinating node needs to execute a confirmation process to determine the execution result of the synchronization process. Then, based on the execution result of the synchronization process, it can roll back the business logic of each sub-transaction that has been implemented, or implement the business logic of each sub-transaction that has not been implemented.

[0186] As an optional implementation of the present invention, refer to Figure 8 As shown, step S71 (execute the confirmation process, and roll back the business logic of each sub-transaction that has been implemented, or implement the business logic of each sub-transaction that has not been implemented, based on the execution result of the confirmation process) includes executing the following steps starting from the first sub-transaction in the preset order:

[0187] S81. Execute the confirmation method for the current sub-transaction.

[0188] The confirmation method for any sub-transaction is used to confirm whether the business logic of that sub-transaction has been implemented.

[0189] S82. Determine whether the confirmation method of the current sub-transaction has been executed successfully.

[0190] In step S82 above, if the confirmation method of the current sub-transaction fails to execute, the process returns to step S81 and continuously retryes the execution of the confirmation method of the current sub-transaction until the confirmation method of the current sub-transaction succeeds.

[0191] In step S82 above, if the confirmation method of the current sub-transaction is successful, then step S83 is executed.

[0192] S83. Confirm whether the business logic of the current sub-transaction has been implemented based on the return result of the confirmation method of the current sub-transaction.

[0193] If the business logic of the current sub-transaction is not implemented in step S83 above, then step S84 is executed.

[0194] S84. Roll back the business logic of each sub-transaction preceding the current sub-transaction.

[0195] Optionally, the rollback of the business logic of each sub-transaction preceding the current sub-transaction can be implemented by starting from the sub-transaction preceding the current sub-transaction and executing... Figure 5 The rollback process is shown.

[0196] In step S83 above, if the business logic of the current sub-transaction has been implemented, then step S85 is executed.

[0197] S85. Determine whether the current sub-transaction is the critical sub-transaction.

[0198] In step S85 above, if the current sub-transaction is not the critical sub-transaction, the confirmation method of the previous sub-transaction of the current sub-transaction is executed until the business logic of the current sub-transaction is not implemented or whether the current sub-transaction is the critical sub-transaction.

[0199] In step S85 above, if the current sub-transaction is the critical sub-transaction, then step S86 is executed.

[0200] S86. Implement the business logic of the current sub-transaction and each subsequent sub-transaction.

[0201] Optionally, the rollback of the business logic of each sub-transaction preceding the current sub-transaction can be implemented as follows: starting from the current sub-transaction, execute... Figure 6 The asynchronous process shown.

[0202] Furthermore, the transaction execution method provided in the above embodiments will be illustrated with examples below.

[0203] Example 1: In the e-commerce order refund transaction, the sub-transactions created are shown in Table 1 below:

[0204] Table 1

[0205]

[0206] The logic of e-commerce order refund transactions is as follows: if sub-transaction 1 is executed successfully, a refund success message is returned to the user, and sub-transactions 2 and 3 are guaranteed to be completed; if sub-transaction 1 fails, a refund failure message is returned to the user.

[0207] The possible scenarios for executing this transaction based on the transaction execution method provided in the above embodiments are shown in Table 2 below:

[0208] Table 2

[0209]

[0210] In other words, under normal status reports (cases 1-5), if the synchronous process executes successfully and the business logic of sub-transactions 1, 2, and 3 is all implemented, no other processes need to be executed. If the synchronous process executes unsuccessfully and the business logic of sub-transaction 1 is not implemented, a confirmation process is executed first. If it is confirmed that the business logic of sub-transaction 1 is not implemented, the process ends. If it is confirmed that the business logic of sub-transaction 1 is implemented, an asynchronous process is executed to implement the business logic of sub-transactions 2 and 3. If the synchronous process executes unsuccessfully and the business logic of sub-transaction 2 is not implemented, an asynchronous process is executed to implement the business logic of sub-transactions 2 and 3. If the synchronous process executes unsuccessfully and the business logic of sub-transaction 3 is not implemented, an asynchronous process is executed to implement the business logic of sub-transaction 3. Under abnormal status reports (cases 6-10), a confirmation process is executed first, starting from sub-transaction 1, to confirm whether the business logic is implemented. Based on the execution result of the confirmation process, the business logic of each sub-transaction whose business logic has been implemented is rolled back, or the business logic of each sub-transaction whose business logic has not been implemented is implemented.

[0211] As shown in Table 2 above, the transaction execution method provided in the above embodiments can return a refund success to the user when sub-transaction 1 is executed successfully, and ensure that sub-transactions 2 and 3 are completed. When sub-transaction 1 fails, a refund failure is returned to the user. Under all circumstances, the transaction execution method provided in the embodiments of the present invention can ensure the eventual consistency of sub-transactions 1, 2 and 3, and synchronously return the execution result of the e-commerce order refund transaction to the user.

[0212] Example 2: In the points-for-coupons transaction, the sub-transactions created are shown in Table 3 below:

[0213] Table 3

[0214]

[0215] The logic for redeeming coupons with points is as follows: If sub-transactions A and B execute successfully, a success message is returned to the user, and sub-transaction C is guaranteed to complete. If sub-transaction A or sub-transaction B fails, a failure message is returned to the user, and the business logic of sub-transaction A is guaranteed to be rolled back.

[0216] The possible scenarios for executing this transaction based on the transaction execution method provided in the above embodiments are shown in Table 4 below:

[0217] Table 4

[0218]

[0219] That is, under normal status reports (cases 1-5), if the execution result of the synchronous process is that the business logic of sub-transactions A, B, and C are all successfully implemented, then no other process needs to be executed; if the execution result of the synchronous process is that the business logic of sub-transaction A fails to be implemented, then the business logic of sub-transaction A is rolled back to the initial state; if the execution result of the synchronous process is that the business logic of sub-transaction B fails to be implemented, then the confirmation process is first executed to confirm whether the business logic of sub-transaction B is implemented. If it is confirmed that the business logic of sub-transaction B is not implemented, then the rollback process is executed to roll back the business logic of sub-transaction A to the initial state. If it is confirmed that the business logic of sub-transaction B is implemented, then the asynchronous process is executed to implement the business logic of sub-transaction C to the state of successful execution. If the execution result of the synchronous process is that the business logic of sub-transaction C fails to be implemented, then the asynchronous process is executed to implement the business logic of sub-transaction C. In the event of an abnormal status report (case 6-10), the confirmation process is executed first, starting from sub-transaction A to confirm whether the business logic has been implemented. Based on the execution result of the confirmation process, the business logic of each sub-transaction that has been implemented is rolled back, or the business logic of each sub-transaction that has not been implemented is implemented.

[0220] As shown in Table 4 above, the transaction execution method provided in the above embodiments can return a success message to the user when sub-transactions A and B are executed successfully, and ensure the implementation of the business logic of sub-task C. When sub-transaction B fails, it returns a failure message to the user, and ensures the rollback of the business logic of sub-transaction A. Under all circumstances, the transaction execution method provided in the embodiments of the present invention can ensure the eventual consistency of sub-transactions A, B and C, and synchronously return the execution result of the points redemption coupon transaction.

[0221] Based on the same inventive concept, as an implementation of the above method, this embodiment of the invention also provides a transaction execution device. This device embodiment corresponds to the aforementioned method embodiment. For ease of reading, this device embodiment will not repeat the details of the aforementioned method embodiment one by one, but it should be clear that the transaction execution device in this embodiment can correspondingly implement all the contents of the aforementioned method embodiment.

[0222] This invention provides a transaction execution device. Figure 9 This is a schematic diagram of the structure of the transaction execution device, as shown below. Figure 9 As shown, the transaction execution device 900 includes:

[0223] Receiving unit 91 is used to receive request information, the request information being used to request the execution of a target transaction;

[0224] Creation unit 92 is used to create each sub-transaction of the target transaction in response to the request information;

[0225] Execution unit 93 is used to execute a synchronization process; the synchronization process is used to implement the business logic of each sub-transaction of the target transaction one by one in a preset order until the business logic of the current sub-transaction fails to be implemented or the business logic of each sub-transaction of the target transaction is successfully implemented.

[0226] The sending unit 94 is used to send a status report to the transaction coordination node according to the execution result of the synchronization process. The status report is used to indicate the target sub-transaction and the business logic implementation result of the target sub-transaction. The target sub-transaction is the last sub-transaction in the synchronization process to implement business logic, so that if the business logic implementation of the target sub-transaction fails, the transaction coordination node can roll back the business logic of each sub-transaction before the target sub-transaction or implement the business logic of the target sub-transaction and each sub-transaction after the target sub-transaction.

[0227] As an optional implementation of this invention, the creation unit 92 is specifically used to configure the business logic of each sub-transaction of the target transaction and the preset order; configure the transaction type as a critical sub-transaction; configure the transaction type of each sub-transaction before the critical sub-transaction as a rollbackable sub-transaction; and configure the transaction type of each sub-transaction after the critical sub-transaction as a non-rollbackable sub-transaction.

[0228] As an optional implementation of the present invention, refer to Figure 10 As shown, the transaction execution device 900 further includes:

[0229] Output unit 95 is used to output the execution result of the target transaction based on the execution result of the synchronization process.

[0230] As an optional implementation of the present invention, the output unit 95 is specifically configured to output a first execution result indicating that the target transaction was successfully executed when the execution result of the synchronization process is that the business logic of each sub-transaction of the target transaction was successfully implemented or the business logic of any sub-transaction after the critical sub-transaction failed; and to output a second execution result indicating that the target transaction failed when the execution result of the synchronization process is that the business logic of the critical sub-transaction failed or the business logic of any sub-transaction before the critical sub-transaction failed.

[0231] As an optional implementation of this invention, the execution unit 93 is specifically configured to execute the implementation method of the current sub-transaction starting from the first sub-transaction in the preset order; the implementation method of any sub-transaction is used to implement the business logic of the sub-transaction; determine whether the implementation method of the current sub-transaction is executed successfully; if the implementation method of the current sub-transaction is executed successfully, determine whether the current sub-transaction is the last sub-transaction in the preset order; if the current sub-transaction is not the last sub-transaction in the preset order, execute the implementation method of the next sub-transaction of the current sub-transaction, until the business logic of the current sub-transaction fails to be implemented or the business logic of each sub-transaction of the target transaction is successfully implemented.

[0232] This invention provides another transaction execution apparatus. Figure 11 This is a schematic diagram of the structure of the transaction execution device, as shown below. Figure 11 As shown, the transaction execution device 110 includes:

[0233] The receiving unit 111 is used to receive a status report sent by the transaction initiating node. The status report is used to indicate the target sub-transaction and the business logic implementation result of the target sub-transaction. The target sub-transaction is the last sub-transaction to implement business logic in the synchronization process. The synchronization process is used to implement the business logic of each sub-transaction of the target transaction one by one in a preset order until the business logic implementation of the current sub-transaction fails or the business logic implementation of each sub-transaction of the target transaction is successful.

[0234] The processing unit 112 is configured to, in the event that the business logic implementation of the target sub-transaction fails, either roll back the business logic of each sub-transaction preceding the target sub-transaction or implement the business logic of the target sub-transaction and each sub-transaction following the target sub-transaction, based on the transaction type of the target sub-transaction.

[0235] As an optional implementation of this invention, the processing unit 112 is specifically used to execute a rollback process to roll back the business logic of each sub-transaction before the target sub-transaction when the transaction type of the target sub-transaction is a rollbackable sub-transaction; and to execute an asynchronous process to implement the business logic of the target sub-transaction and each sub-transaction after the target sub-transaction when the type of the target sub-transaction is a non-rollbackable sub-transaction.

[0236] As an optional implementation of this invention, the rollback process includes: starting from the target sub-transaction, executing the rollback method of the current sub-transaction, wherein the rollback method of any sub-transaction is used to roll back the business logic of the sub-transaction; determining whether the rollback method of the current sub-transaction is executed successfully; if the rollback method of the current sub-transaction is executed successfully, determining whether the current sub-transaction is the first sub-transaction in the preset order; if the current sub-transaction is not the first sub-transaction in the preset order, executing the rollback method of the previous sub-transaction of the current sub-transaction, until the current sub-transaction is the first sub-transaction in the preset order.

[0237] As an optional implementation of this invention, the asynchronous execution process includes: starting from the target sub-transaction, executing the implementation method of the current sub-transaction; the implementation method of any sub-transaction is used to implement the business logic of the sub-transaction; determining whether the implementation method of the current sub-transaction is executed successfully; if the implementation method of the current sub-transaction is executed successfully, determining whether the current sub-transaction is the last sub-transaction in the preset order; if the current sub-transaction is not the last sub-transaction in the preset order, executing the implementation method of the next sub-transaction of the current sub-transaction, until the current sub-transaction is the last sub-transaction in the preset order.

[0238] As an optional implementation of the present invention, the processing unit 112 is further configured to execute a confirmation process when the target sub-transaction is a critical sub-transaction or the status report reception is abnormal, and to roll back the business logic of each sub-transaction whose business logic has been implemented, or to implement the business logic of each sub-transaction whose business logic has not been implemented, based on the execution result of the confirmation process.

[0239] The confirmation process is used to confirm, in the preset order, whether the business logic of each sub-transaction of the target transaction has been implemented, and to determine whether the current sub-transaction is the critical sub-transaction when the business logic of the current sub-transaction has been implemented, until the business logic of the current sub-transaction has not been implemented or whether the current sub-transaction is the critical sub-transaction.

[0240] As an optional implementation of this invention, the processing unit 112 is specifically configured to execute the confirmation method of the current sub-transaction starting from the first sub-transaction in the preset order; the confirmation method of any sub-transaction is used to confirm whether the business logic of the sub-transaction is implemented; if the business logic of the current sub-transaction is not implemented, the business logic of each sub-transaction preceding the current sub-transaction is rolled back; if the business logic of the current sub-transaction is implemented, it is determined whether the current sub-transaction is the critical sub-transaction; if the current sub-transaction is not the critical sub-transaction, the confirmation method of the previous sub-transaction of the current sub-transaction is executed until the business logic of the current sub-transaction is not implemented or whether the current sub-transaction is the critical sub-transaction; if the current sub-transaction is the critical sub-transaction, the business logic of the current sub-transaction and each sub-transaction following the current sub-transaction is implemented.

[0241] The transaction execution device provided in this embodiment can execute the transaction execution method provided in the above method embodiment. Its implementation principle and technical effect are similar, and will not be described again here.

[0242] Based on the same inventive concept, embodiments of the present invention also provide an electronic device. Figure 12 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention, such as... Figure 12 As shown, the electronic device provided in this embodiment includes a memory 121 and a processor 122. The memory 121 is used to store computer programs; the processor 122 is used to execute the transaction execution method provided in the above embodiment when the computer program is invoked.

[0243] Based on the same inventive concept, embodiments of the present invention also provide a computer-readable storage medium storing a computer program, which, when executed by a processor, causes the computing device to implement the transaction execution method provided in the above embodiments.

[0244] Based on the same inventive concept, this embodiment of the invention also provides a computer program product, which, when run on a computer, enables the computing device to implement the transaction execution method provided in the above embodiments.

[0245] Those skilled in the art will understand that embodiments of the present invention can be provided as methods, systems, or computer program products. Therefore, the present invention can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, the present invention can take the form of a computer program product implemented on one or more computer-usable storage media containing computer-usable program code.

[0246] The processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor can be a microprocessor or any conventional processor.

[0247] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, like read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.

[0248] Computer-readable media include both permanent and non-permanent, removable and non-removable storage media. Storage media can store information using any method or technology; the information can be computer-readable instructions, data structures, units of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media do not include transient computer-readable media, such as modulated data signals and carrier waves.

[0249] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some or all of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present invention.

Claims

1. A transaction execution method, characterized in that, Applied to the transaction initiating node, the method includes: Receive request information, the request information being used to request the execution of a target transaction; In response to the request information, create each sub-transaction of the target transaction; Execute the synchronization process; the synchronization process is used to implement the business logic of each sub-transaction of the target transaction one by one in a preset order, until the business logic of the current sub-transaction fails to be implemented or the business logic of each sub-transaction of the target transaction is successfully implemented. Based on the execution result of the synchronization process, a status report is sent to the transaction coordination node. The status report is used to indicate the target sub-transaction and the business logic implementation result of the target sub-transaction. The target sub-transaction is the last sub-transaction in the synchronization process to implement business logic. This allows the transaction coordination node to roll back the business logic of each sub-transaction before the target sub-transaction or implement the business logic of each sub-transaction after the target sub-transaction, depending on the transaction type of the target sub-transaction. The transaction type includes rollbackable sub-transactions and non-rollbackable sub-transactions.

2. The method according to claim 1, characterized in that, The sub-transactions that create the target transaction include: Configure the business logic of each sub-transaction of the target transaction and the preset order; Configure a subtransaction with the transaction type of critical subtransaction; Configure the transaction type of each sub-transaction preceding the critical sub-transaction as a rollbackable sub-transaction; Configure the transaction type of each subtransaction after the critical subtransaction as a non-rollback subtransaction.

3. The method according to claim 2, characterized in that, The method further includes: The execution result of the target transaction is output based on the execution result of the synchronization process.

4. The method according to claim 3, characterized in that, The step of outputting the execution result of the target transaction based on the execution result of the synchronization process includes: If the execution result of the synchronization process is that the business logic of each sub-transaction of the target transaction is successfully implemented or the business logic of any sub-transaction after the critical sub-transaction fails, a first execution result is output to characterize the successful execution of the target transaction. If the execution result of the synchronization process is that the business logic implementation of the critical sub-transaction fails or the business logic implementation of any sub-transaction preceding the critical sub-transaction fails, a second execution result is output to characterize the failure of the target transaction.

5. The method according to any one of claims 1-4, characterized in that, The execution synchronization process includes: Starting with the first sub-transaction in the preset order, the implementation method of the current sub-transaction is executed; the implementation method of any sub-transaction is used to implement the business logic of that sub-transaction; Determine whether the implementation method of the current sub-transaction has been executed successfully; If the implementation method of the current sub-transaction is executed successfully, then determine whether the current sub-transaction is the last sub-transaction in the preset order; If the current sub-transaction is not the last sub-transaction in the preset order, then the implementation method of the next sub-transaction after the current sub-transaction is executed until the business logic of the current sub-transaction fails or the business logic of each sub-transaction of the target transaction is successfully implemented.

6. A transaction execution method, characterized in that, Applied to a transaction coordination node, the method includes: Receive a status report sent by the transaction initiating node. The status report is used to indicate the target sub-transaction and the business logic implementation result of the target sub-transaction. The target sub-transaction is the last sub-transaction to implement business logic in the synchronization process. The synchronization process is used to implement the business logic of each sub-transaction of the target transaction one by one in a preset order until the business logic implementation of the current sub-transaction fails or the business logic implementation of each sub-transaction of the target transaction is successful. If the business logic of the target sub-transaction fails to be implemented, the business logic of each sub-transaction preceding the target sub-transaction is rolled back, or the business logic of the target sub-transaction and each sub-transaction following the target sub-transaction is implemented, depending on the transaction type of the target sub-transaction. The transaction type includes rollbackable sub-transactions and non-rollbackable sub-transactions.

7. The method according to claim 6, characterized in that, The step of rolling back the business logic of each sub-transaction preceding the target sub-transaction or implementing the business logic of the target sub-transaction and each sub-transaction following the target sub-transaction, based on the transaction type of the target sub-transaction, includes: If the transaction type of the target sub-transaction is a rollback sub-transaction, a rollback process is executed to roll back the business logic of each sub-transaction preceding the target sub-transaction. If the target sub-transaction is a non-rollbackable sub-transaction, an asynchronous process is executed to implement the business logic of the target sub-transaction and each subsequent sub-transaction.

8. The method according to claim 7, characterized in that, The rollback process includes: Starting from the target sub-transaction, execute the rollback method of the current sub-transaction. The rollback method of any sub-transaction is used to roll back the business logic of that sub-transaction. Determine whether the rollback method of the current sub-transaction has been executed successfully; If the rollback method of the current sub-transaction is executed successfully, then determine whether the current sub-transaction is the first sub-transaction in the preset order; If the current sub-transaction is not the first sub-transaction in the preset order, then the rollback method of the previous sub-transaction is executed until the current sub-transaction is the first sub-transaction in the preset order.

9. The method according to claim 8, characterized in that, The execution of the asynchronous process includes: Starting from the target sub-transaction, execute the implementation method of the current sub-transaction; the implementation method of any sub-transaction is used to implement the business logic of that sub-transaction; Determine whether the implementation method of the current sub-transaction has been executed successfully; If the implementation method of the current sub-transaction is executed successfully, then determine whether the current sub-transaction is the last sub-transaction in the preset order; If the current sub-transaction is not the last sub-transaction in the preset order, then the implementation method of the next sub-transaction of the current sub-transaction is executed until the current sub-transaction is the last sub-transaction in the preset order.

10. The method according to claim 6, characterized in that, The method further includes: If the target sub-transaction is a critical sub-transaction or the status report reception is abnormal, an confirmation process is executed, and the business logic of each sub-transaction whose business logic has been implemented is rolled back according to the execution result of the confirmation process, or the business logic of each sub-transaction whose business logic has not been implemented is implemented. The confirmation process is used to confirm, in the preset order, whether the business logic of each sub-transaction of the target transaction has been implemented, and to determine whether the current sub-transaction is the critical sub-transaction when the business logic of the current sub-transaction has been implemented, until the business logic of the current sub-transaction has not been implemented or the current sub-transaction is the critical sub-transaction.

11. The method according to claim 10, characterized in that, The execution confirmation process, and based on the execution result of the confirmation process, rollback of the business logic of each sub-transaction that has been implemented, or implementation of the business logic of each sub-transaction that has not been implemented, includes: Starting from the first sub-transaction in the preset order, the confirmation method of the current sub-transaction is executed; the confirmation method of any sub-transaction is used to confirm whether the business logic of the sub-transaction has been implemented. If the business logic of the current sub-transaction is not implemented, the business logic of all sub-transactions preceding the current sub-transaction will be rolled back. If the business logic of the current sub-transaction has been implemented, then determine whether the current sub-transaction is the critical sub-transaction; If the current sub-transaction is not the critical sub-transaction, then the confirmation method of the previous sub-transaction of the current sub-transaction is executed until the business logic of the current sub-transaction is not implemented or the current sub-transaction is the critical sub-transaction; If the current sub-transaction is the critical sub-transaction, then the business logic of the current sub-transaction and all subsequent sub-transactions shall be implemented.

12. A transaction execution apparatus, characterized in that, include: A receiving unit is configured to receive request information, wherein the request information is used to request the execution of a target transaction; A creation unit is used to create each sub-transaction of the target transaction in response to the request information; An execution unit is used to execute a synchronization process; the synchronization process is used to implement the business logic of each sub-transaction of the target transaction one by one in a preset order, until the business logic of the current sub-transaction fails to be implemented or the business logic of each sub-transaction of the target transaction is successfully implemented. The sending unit is configured to send a status report to the transaction coordination node based on the execution result of the synchronization process. The status report is used to indicate the target sub-transaction and the business logic implementation result of the target sub-transaction. The target sub-transaction is the last sub-transaction in the synchronization process to implement its business logic. This allows the transaction coordination node to roll back the business logic of each sub-transaction before the target sub-transaction or implement the business logic of the target sub-transaction and each sub-transaction after the target sub-transaction, depending on the transaction type of the target sub-transaction. The transaction type includes rollbackable sub-transactions and non-rollbackable sub-transactions.

13. A transaction execution apparatus, characterized in that, include: The receiving unit is used to receive a status report sent by the transaction initiating node. The status report is used to indicate the target sub-transaction and the business logic implementation result of the target sub-transaction. The target sub-transaction is the last sub-transaction to implement business logic in the synchronization process. The synchronization process is used to implement the business logic of each sub-transaction of the target transaction one by one in a preset order until the business logic implementation of the current sub-transaction fails or the business logic implementation of each sub-transaction of the target transaction is successful. The processing unit is configured to, in the event that the business logic implementation of the target sub-transaction fails, either roll back the business logic of each sub-transaction preceding the target sub-transaction or implement the business logic of the target sub-transaction and each sub-transaction following the target sub-transaction, based on the transaction type of the target sub-transaction. The transaction type includes rollable sub-transactions and non-rollable sub-transactions.

14. An electronic device, characterized in that, include: A memory and a processor, the memory being used to store a computer program; the processor being used to cause the electronic device to implement the transaction execution method according to any one of claims 1-11 when executing the computer program.

15. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a computing device, causes the computing device to implement the transaction execution method according to any one of claims 1-11.

16. A computer program product, characterized in that, When the computer program product is run on a computer, the computer enables the transaction execution method as described in any one of claims 1-11.

Citation Information

Patent Citations

  • Distributed transaction dynamic processing method and system based on sub-transaction flows

    CN109491768A

  • Method and device for processing distributed transactions

    CN112445860A