Distributed transaction processing method and device

By processing local and non-local sub-transaction operations in parallel and merging pipeline commits, the performance issues of the TCC distributed transaction component in high-concurrency scenarios are resolved, improving transaction processing efficiency and reducing database load.

CN119045958AInactive Publication Date: 2024-11-29SICHUAN RURAL COMMERCIAL UNITED BANK CO LTD +1
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202411224149.8
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-02
Publication Date
2024-11-29
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

The existing TCC distributed transaction component performs poorly in high-concurrency scenarios, resulting in long transaction processing times and failing to meet performance requirements. This is mainly due to the excessive number of Try interface calls and database writes from multiple sub-transactions.

Method used

The method of parallel execution of the first and second business processing branches is adopted to handle the operations and resource reservations of local and non-local sub-transactions respectively, and the pipeline commit is merged after the transaction is successfully confirmed, thereby reducing the number of database writes and the size of the transaction log.

Benefits of technology

By processing branches in parallel and merging pipeline commits, the efficiency of distributed transaction processing is improved, database I/O overhead is reduced, and the performance requirements of high-concurrency scenarios are met.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119045958A_ABST
    Figure CN119045958A_ABST
Patent Text Reader

Abstract

The invention provides a distributed transaction processing method and device, and relates to the technical field of data processing. The method comprises the steps of registering a main transaction of a distributed transaction according to a transaction request; executing the first service processing branch and the second service processing branch in parallel; wherein the first business processing branch comprises registering a main transaction pipeline, and executing a transaction operation and a resource reservation operation associated with a local sub-transaction in a main transaction; the second business processing branch comprises execution of transaction operation and resource reservation operation associated with non-local sub-transactions in the main transaction; in response to successful execution of both the first business processing branch and the second business processing branch, executing a transaction confirmation task to confirm and submit transaction operations of a plurality of sub-transactions in the main transaction, and releasing resources reserved for the plurality of sub-transactions; and in response to successful execution of the transaction confirmation task, updating the pipeline state of the main transaction to be successful. Therefore, the transaction processing time consumption can be reduced, the write-in times of the database and the size of the transaction log are reduced, and the I / O overhead of the database is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present disclosure relates to the field of data processing technology, and in particular to a method and device for processing distributed transactions. Background Art

[0002] Distributed transactions refer to scenarios in which, in a distributed system, data is distributed across different services or nodes, so it is necessary to ensure that operations performed between multiple services can guarantee data consistency and integrity. Try-Confirm-Cancel (TCC) is a distributed transaction model based on a compensation mechanism. It divides a distributed transaction into three phases: Try, Confirm, and Cancel to ensure the atomicity and eventual consistency of the transaction. Each transaction participant (service) needs to provide the business logic corresponding to these three phases to ensure that the eventual consistency of the data can be achieved under different circumstances.

[0003] In the related technology, the TCC distributed transaction component independently registers the flow of the TCC main transaction and distinguishes it from the flow of sub-transactions. When the TCC main transaction includes multiple sub-transactions, it will serially call the Try interface of the TCC transaction participants associated with the multiple sub-transactions to implement the specific transaction operations and resource reservation operations of the multiple sub-transactions in sequence (such as locking account balances, checking account status, etc.).

[0004] However, the above implementation will result in poor TCC performance, especially when there are a large number of sub-transactions. It is necessary to call multiple Try interfaces in sequence and register multiple transaction information in the database, which takes a long time and cannot meet the high-concurrency transaction processing scenarios with high performance requirements. Summary of the invention

[0005] The present disclosure aims to solve one of the technical problems in the related art at least to some extent.

[0006] One aspect of the present disclosure provides a distributed transaction processing method and apparatus to reduce transaction processing time, reduce the number of database writes and the size of transaction logs, and reduce database I / O (Input / Output) overhead.

[0007] The first embodiment of the present disclosure provides a distributed transaction processing method, including:

[0008] Registering the first main transaction of the distributed transaction according to the received transaction request;

[0009] Executing a first business processing branch and a second business processing branch in parallel; wherein the first business processing branch includes registering the pipeline of the first main transaction in a database, and executing transaction operations and resource reservation operations associated with local subtransactions in the first main transaction; and the second business processing branch includes executing transaction operations and resource reservation operations associated with non-local subtransactions in the first main transaction;

[0010] In response to the first business processing branch and the second business processing branch being both executed successfully, executing a transaction confirmation task; wherein the transaction confirmation task is used to confirm and commit the transaction operations of the multiple sub-transactions in the first main transaction, and release resources reserved for the multiple sub-transactions;

[0011] In response to the transaction confirmation task being executed successfully, the pipeline status of the first main transaction in the database is updated to success.

[0012] A second aspect of the present disclosure provides a distributed transaction processing device, including:

[0013] A registration module, used for registering a first main transaction of a distributed transaction according to a received transaction request;

[0014] A first execution module is used to execute a first business processing branch and a second business processing branch in parallel; wherein the first business processing branch includes registering the pipeline of the first main transaction in a database, and executing transaction operations and resource reservation operations associated with local subtransactions in the first main transaction; and the second business processing branch includes executing transaction operations and resource reservation operations associated with non-local subtransactions in the first main transaction;

[0015] A second execution module, configured to execute a transaction confirmation task in response to the first business processing branch and the second business processing branch being successfully executed; wherein the transaction confirmation task is used to confirm and commit the transaction operations of the multiple sub-transactions in the first main transaction, and release resources reserved for the multiple sub-transactions;

[0016] An update module is used to update the pipeline status of the first main transaction in the database to success in response to the successful execution of the transaction confirmation task.

[0017] The third aspect embodiment of the present disclosure proposes an electronic device, comprising: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein when the processor executes the program, the distributed transaction processing method proposed in the first aspect embodiment of the present disclosure is implemented.

[0018] The fourth aspect embodiment of the present disclosure proposes a non-temporary computer-readable storage medium, on which a computer program is stored. When the program is executed by a processor, it implements the distributed transaction processing method proposed in the first aspect embodiment of the present disclosure.

[0019] The fifth aspect embodiment of the present disclosure proposes a computer program product. When the instructions in the computer program product are executed by a processor, the distributed transaction processing method proposed in the first aspect embodiment of the present disclosure is executed.

[0020] The technical solutions provided by the above embodiments of the present disclosure bring at least the following beneficial effects:

[0021] By executing the first business processing branch and the second business processing branch in parallel, the processing efficiency of the distributed transaction can be improved, that is, the Try phases of multiple sub-transactions in the main transaction of the distributed transaction can be executed in parallel, which can reduce the time consumption of transaction processing. Furthermore, by executing the Try phase of the local sub-transaction and the flow of the registered main transaction in the same transaction (that is, executing the Try phase of the local sub-transaction and the flow of the registered main transaction at the same time in the first business processing branch), the flow of the main transaction and the flow of the local sub-transaction can be merged into one transaction for submission, reducing the number of database writes and the size of the transaction log, thereby reducing the I / O overhead of the database.

[0022] Additional aspects and advantages of the present disclosure will be given in part in the following description and in part will be obvious from the following description or learned through practice of the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] The above and / or additional aspects and advantages of the present disclosure will become apparent and easily understood from the following description of the embodiments in conjunction with the accompanying drawings, in which:

[0024] Figure 1 This is a typical implementation principle diagram of traditional TCC transactions;

[0025] Figure 2 A schematic diagram of a process flow of a distributed transaction processing method provided by an embodiment of the present disclosure;

[0026] Figure 3 A flowchart of another distributed transaction processing method provided by an embodiment of the present disclosure;

[0027] Figure 4 A flowchart of another distributed transaction processing method provided by an embodiment of the present disclosure;

[0028] Figure 5 A flowchart of another distributed transaction processing method provided by an embodiment of the present disclosure;

[0029] Figure 6 A schematic diagram of the processing principle of distributed transactions provided by an embodiment of the present disclosure;

[0030] Figure 7 A schematic diagram of the principle of the bottom-up processing 1 in the bottom-up mechanism provided in the embodiment of the present disclosure;

[0031] Figure 8 A schematic diagram of the principle of the bottom-up processing 2 in the bottom-up mechanism provided in the embodiment of the present disclosure;

[0032] Fig. 9 A schematic diagram of the structure of a distributed transaction processing device provided by an embodiment of the present disclosure;

[0033] Fig.10 It is a schematic structural diagram of an electronic device shown in an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION

[0034] Embodiments of the present disclosure are described in detail below, examples of which are shown in the accompanying drawings, wherein the same or similar reference numerals throughout represent the same or similar elements or elements having the same or similar functions. The embodiments described below with reference to the accompanying drawings are exemplary and are intended to be used to explain the present disclosure, and should not be construed as limiting the present disclosure.

[0035] At present, the typical implementation methods of TCC transactions in financial business scenarios are as follows: Figure 1 As shown, it mainly includes the following steps:

[0036] Step 1: Upon receiving a transaction request from a customer or an internal system, the TCC transaction initiator (such as a financial institution's transaction processing service) registers a TCC transaction (main transaction) with the TCC transaction coordinator based on the transaction request.

[0037] Among them, the main transaction can represent the entire transaction process, including multiple sub-transactions, each sub-transaction is associated with a TCC transaction participant, and the TCC transaction participant is responsible for executing transaction operations and resource reservation operations related to the associated sub-transaction.

[0038] Step 2: After receiving the registration request of the main transaction, the TCC transaction coordinator registers the main transaction flow to the distributed database to ensure the existence and traceability of the main transaction.

[0039] Step 3: After the main transaction is successfully registered, the TCC transaction initiator starts to execute the Try phase of multiple sub-transactions, calling the Try interface of each TCC transaction participant in turn to execute the transaction operations corresponding to the sub-transaction and make necessary resource reservations (such as locking account balances, checking account status, etc.).

[0040] Among them, the Try interface of each TCC transaction participant is responsible for executing the specific transaction operations and resource reservation operations of the sub-transaction.

[0041] Step 4: After each successful call to the Try interface, that is, after each successful processing of a sub-transaction, the TCC transaction initiator will register a sub-transaction flow with the TCC transaction coordinator to facilitate tracking and management of the status of each sub-transaction.

[0042] Step 5: If the Try interface call of a subtransaction fails, the TCC transaction initiator will notify the TCC transaction coordinator to update the pipeline status of the main transaction to failure and start the rollback process, which includes calling the Cancel interface of the TCC transaction participants associated with other successfully processed subtransactions to return the resources reserved in the Try phase.

[0043] Step 6: After the Try interfaces of all TCC transaction participants are successfully called, the TCC transaction initiator will further call the Confirm interfaces of all TCC transaction participants to commit the subtransaction and release the resources reserved in the previous Try phase.

[0044] Step 7: When a subtransaction is confirmed successfully, that is, when the Confirm interface call of the TCC transaction participant associated with the subtransaction is successful, the TCC transaction initiator will notify the TCC transaction coordinator to update the pipeline status of the subtransaction to success.

[0045] Step 8: If the Try interfaces of all TCC transaction participants are called successfully, but the Confirm interfaces of one or some TCC transaction participants fail or time out, the TCC transaction coordinator is responsible for retrying the Confirm interfaces of these TCC transaction participants.

[0046] Among them, the retry strategy can be configured according to business requirements and system performance.

[0047] Step 9: When the pipeline status of all sub-transactions becomes final (Confirmed or Canceled), the TCC transaction coordinator will update the pipeline status of the main transaction, which indicates the completion or rollback of the entire distributed transaction.

[0048] For example, all subtransactions are confirmed successfully: If the Confirm interfaces of the TCC transaction participants associated with all subtransactions are called successfully and no exceptions or timeouts occur, the TCC transaction coordinator will update the pipeline status of the main transaction to "completed" or "successful". This indicates that the entire distributed transaction is successfully completed, all related resource reservations are committed, and the data status is consistent.

[0049] Another example is that some or all subtransactions are successfully Canceled: If some or all subtransactions fail to confirm due to some reasons, the TCC transaction coordinator decides to roll back the entire transaction. It will call the Cancel interface of the TCC transaction participants associated with all subtransactions that have not yet completed the confirmation (if some subtransactions have been successfully confirmed, additional mechanisms may be required to undo these operations, but this is usually not handled directly by the TCC model, but depends on business logic or other compensation mechanisms). After the Cancel interface of all subtransactions is successfully called, the TCC transaction coordinator will update the pipeline status of the main transaction to "failure" or "rollback". The specific naming may vary depending on the system.

[0050] Through the above process, the TCC model ensures the atomicity and eventual consistency of distributed transactions in financial business scenarios, while improving the reliability and performance of the system.

[0051] The above is the basic implementation principle of TCC transactions. For different TCC products, there are certain differences in their implementation. For example, some TCC distributed transaction components deploy the TCC transaction coordinator as an independent service, while some TCC distributed transaction components integrate the TCC transaction coordinator into the application in the form of SDK (Software Development Kit).

[0052] However, mainstream TCC distributed transaction components all register the flow of TCC main transactions independently, distinguishing them from the flow of sub-transactions. When there are multiple sub-transactions (each sub-transaction has a corresponding Try phase), the Try interfaces of TCC transaction participants associated with multiple sub-transactions are often called serially. Such an implementation will lead to poor TCC performance, especially when there are many TCC transaction participants, it is necessary to call the Try interfaces of multiple TCC transaction participants in sequence and register multiple data in the database (registered data flow information records are N+1, where N is the number of sub-transactions). Most information system data based on distributed architecture uses distributed databases. The time it takes to write and commit transactions in the database mainly depends on the synchronization time between multiple copies, which is often several times longer than that of traditional databases, and cannot meet high-concurrency transaction processing scenarios with high performance requirements.

[0053] In response to at least one of the above problems, the present disclosure provides a method and device for processing distributed transactions.

[0054] The following describes the distributed transaction processing method and device of the embodiment of the present disclosure with reference to the accompanying drawings. Before describing the embodiment of the present disclosure in detail, for ease of understanding, the commonly used technical terms are first introduced:

[0055] A main transaction refers to a program execution unit that completes a certain business function.

[0056] A subtransaction refers to a program execution unit that completes a task, where a main transaction contains several subtransactions.

[0057] Transaction flow, including the transaction or service call related flow number and input parameter information.

[0058] The main transaction flow, including but not limited to: the status of the main transaction, creation time, last update time, etc.

[0059] A local subtransaction is a transaction in which an application accesses and possibly updates various data items in the database that are all in the business system to which it belongs.

[0060] The local subtransaction flow, including but not limited to: the flow number, output parameter information, and input parameter information related to the local subtransaction call.

[0061] Non-local subtransactions, such as RPC (Remote Procedure Call) type subtransactions (i.e., remote RPC call subtransactions).

[0062] The sequence of a non-local subtransaction includes a sequence number.

[0063] Figure 2 A flowchart of a distributed transaction processing method provided in an embodiment of the present disclosure.

[0064] The distributed transaction processing method of the embodiment of the present disclosure can be applied to the TCC transaction initiator.

[0065] like Figure 2 As shown, the distributed transaction processing method includes the following steps S201 to S204:

[0066] Step S201: registering a first main transaction of a distributed transaction according to a received transaction request.

[0067] Among them, transaction requests include but are not limited to: transfer requests, payment requests, order requests, refund requests, query requests, authorization requests, etc.

[0068] The first main transaction includes multiple subtransactions, including local subtransactions and non-local subtransactions. Taking the transaction request as an example of a transfer request, the local subtransaction can be used to perform an account transfer-out operation, and the non-local subtransaction can be used to perform an account transfer-in operation.

[0069] In an embodiment of the present disclosure, upon receiving a transaction request, the TCC transaction initiator may register a main transaction (referred to as the first main transaction in the present disclosure) of a distributed transaction (ie, TCC transaction) with the TCC transaction coordinator according to the transaction request.

[0070] Step S202, executing the first business processing branch and the second business processing branch in parallel; wherein the first business processing branch includes registering the flow of the first main transaction in the database, and executing transaction operations and resource reservation operations associated with the local sub-transaction in the first main transaction; the second business processing branch includes executing transaction operations and resource reservation operations associated with the non-local sub-transaction in the first main transaction.

[0071] In the embodiment of the present disclosure, in order to improve the processing efficiency of distributed transactions, the first business processing branch and the second business processing branch may be executed in parallel.

[0072] The first business processing branch includes a transaction flow registration operation of the first main transaction and a Try phase of a local subtransaction in the first main transaction, wherein the transaction flow registration operation includes: registering the transaction flow of the first main transaction in a database.

[0073] The Try phase of the local subtransaction includes: executing transaction operations and resource reservation operations associated with the local subtransaction in the first main transaction.

[0074] The second business processing branch includes the Try phase of the non-local subtransaction in the first main transaction, wherein the Try phase of the non-local subtransaction includes: executing transaction operations and resource reservation operations associated with the non-local subtransaction.

[0075] That is, in the present disclosure, in order to improve the processing efficiency of distributed transactions, the Try phases of multiple subtransactions in the first main transaction can be executed in parallel. For example, multiple threads are called simultaneously to execute the Try phases of multiple subtransactions, wherein each thread is used to execute the Try phase of one subtransaction.

[0076] As an example, the first business processing branch may be executed by calling the main thread, and the second business processing branch may be executed by calling the transaction thread in parallel.

[0077] Step S203, in response to the first business processing branch and the second business processing branch being executed successfully, executing a transaction confirmation task; wherein the transaction confirmation task is used to confirm and commit the transaction operations of multiple sub-transactions in the first main transaction, and release resources reserved for the multiple sub-transactions.

[0078] In the embodiment of the present disclosure, when both the first business processing branch and the second business processing branch are successfully executed, a transaction confirmation task may be further executed.

[0079] The transaction confirmation task includes the Confirm phase of multiple subtransactions (including local subtransactions and non-local subtransactions) in the first main transaction. The Confirm phase of each subtransaction includes: confirming and committing the transaction operation of the subtransaction, and releasing the resources reserved for the subtransaction.

[0080] Step S204, in response to the successful execution of the transaction confirmation task, the pipeline status of the first main transaction in the database is updated to success.

[0081] In the embodiment of the present disclosure, when the transaction confirmation task is executed successfully, the first main transaction can be ended, and the pipeline status of the first main transaction in the database can be updated to success (or completed).

[0082] The distributed transaction processing method of the embodiment of the present disclosure can improve the processing efficiency of distributed transactions by executing the first business processing branch and the second business processing branch in parallel, that is, the Try phases of multiple sub-transactions in the main transaction of the distributed transaction can be executed in parallel, which can reduce the time consumption of transaction processing. Furthermore, the Try phase of the local sub-transaction and the flow of the registered main transaction are executed in the same transaction (that is, the Try phase of the local sub-transaction and the flow of the registered main transaction are executed simultaneously in the first business processing branch), which can realize the merging of the flow of the main transaction and the flow of the local sub-transaction into one transaction for submission, reducing the number of writes to the database and the size of the transaction log, thereby reducing the I / O (Input / Output) overhead of the database.

[0083] In order to clearly explain how the first business processing branch and the second business processing branch are executed in parallel in the above embodiment, the present disclosure further proposes a distributed transaction processing method.

[0084] Figure 3 A flowchart of another distributed transaction processing method provided by an embodiment of the present disclosure.

[0085] It should be noted that the distributed transaction processing method can be executed alone, or it can be executed in combination with any embodiment of the present disclosure or a possible implementation method in the embodiment, or it can be executed in combination with any technical solution in the related technology, and the embodiments of the present disclosure are not limited to this.

[0086] like Figure 3 As shown, the distributed transaction processing method includes the following steps S301 to S305:

[0087] Step S301: register a first main transaction of a distributed transaction according to a received transaction request.

[0088] The first main transaction includes multiple sub-transactions, wherein the multiple sub-transactions include local sub-transactions and non-local sub-transactions, and each sub-transaction is associated with a transaction participant.

[0089] For the explanation of step S301, reference may be made to the relevant description in any embodiment of the present disclosure, and no further details will be given here.

[0090] Step S302, executing the first business processing branch, includes: registering the flow of the first main transaction in the database, and querying whether there is a flow of the local sub-transaction in the first main transaction in the database; if not, calling the attempt interface of the transaction participant associated with the local sub-transaction; in response to a successful call to the attempt interface, determining that the first business processing branch is executed successfully, and updating the flow status of the local sub-transaction to attempted; in response to a failure in the attempt interface call, determining that the first business processing branch is executed unsuccessfully, and updating the flow status of the local sub-transaction to attempted failure.

[0091] In the embodiment of the present disclosure, the first business processing branch includes a transaction flow registration operation of the first main transaction and a Try phase of a local subtransaction in the first main transaction, wherein the transaction flow registration operation includes: registering the transaction flow of the first main transaction in a database.

[0092] The Try phase of the local subtransaction includes: querying whether there is a transaction flow of the local subtransaction in the database. If so, it indicates that the Try phase of the local subtransaction has been executed, and at this time, there is no need to execute the Try phase of the local subtransaction again; if not, it indicates that the Try phase of the local subtransaction has not been executed. At this time, the Try interface of the transaction participant associated with the local subtransaction can be called, wherein the Try interface is used to execute the transaction operation and resource reservation operation associated with the local subtransaction, and register the transaction flow of the local subtransaction in the database.

[0093] If the interface call attempt is successful, it is determined that the first business processing branch is executed successfully. At this time, the pipeline status of the local sub-transaction can be updated to attempted. In the case of a failed interface call attempt, it can be determined that the first business processing branch is executed unsuccessfully. At this time, the pipeline status of the local sub-transaction can be updated to failed attempt.

[0094] Step S303: When executing the first service processing branch, execute the second service processing branch in parallel.

[0095] In an embodiment of the present disclosure, the second business processing branch includes the Try phase of the non-local subtransaction in the first main transaction, wherein the Try phase of the non-local subtransaction includes: querying whether there is a flow of the non-local subtransaction in the database, if so, it indicates that the Try phase of the non-local subtransaction has been executed, and at this time, there is no need to execute the Try phase of the non-local subtransaction again; if not, it indicates that the Try phase of the non-local subtransaction has not been executed, and at this time, the Try interface of the transaction participant associated with the non-local subtransaction can be called; wherein the Try interface is used to execute transaction operations and resource reservation operations associated with the non-local subtransaction, and register the flow of the non-local subtransaction in the database.

[0096] If the attempt interface call is successful, it is determined that the second business processing branch is executed successfully. At this time, the pipeline status of the non-local sub-transaction can be updated to attempted. In the case where the attempt interface call fails, it can be determined that the second business processing branch is executed unsuccessfully. At this time, the pipeline status of the non-local sub-transaction can be updated to attempt failed.

[0097] Step S304: In response to the first business processing branch and the second business processing branch being successfully executed, a transaction confirmation task is executed.

[0098] The transaction confirmation task is used to confirm and commit the transaction operations of multiple sub-transactions in the first main transaction and release the resources reserved for the multiple sub-transactions.

[0099] Step S305 , in response to the successful execution of the transaction confirmation task, the pipeline status of the first main transaction in the database is updated to success.

[0100] For explanations of steps S304 to S305, reference may be made to the relevant descriptions in any embodiment of the present disclosure, and will not be repeated here.

[0101] The distributed transaction processing method of the embodiment of the present disclosure queries whether there is a flow of local sub-transactions in the database, and determines whether to execute the Try phase of the local sub-transaction according to the query result, thereby avoiding repeated scheduling of the Try interface, repeated use of resources, and ensuring the correct response to the transaction request.

[0102] In order to clearly explain how to perform the transaction confirmation task in any embodiment of the present disclosure, the present disclosure also proposes a distributed transaction processing method.

[0103] Figure 4 A flowchart of another distributed transaction processing method provided by an embodiment of the present disclosure.

[0104] It should be noted that the distributed transaction processing method can be executed alone, or it can be executed in combination with any embodiment of the present disclosure or a possible implementation method in the embodiment, or it can be executed in combination with any technical solution in the related technology, and the embodiments of the present disclosure are not limited to this.

[0105] like Figure 4 As shown, the distributed transaction processing method includes the following steps S401 to S404:

[0106] Step S401: register a first main transaction of a distributed transaction according to a received transaction request; wherein the first main transaction includes N subtransactions.

[0107] Wherein, N is a positive integer greater than 1, and each subtransaction is associated with a transaction participant.

[0108] Step S402: executing the first service processing branch and the second service processing branch in parallel.

[0109] Among them, the first business processing branch includes registering the flow of the first main transaction in the database, and executing transaction operations and resource reservation operations associated with the local sub-transaction in the first main transaction; the second business processing branch includes executing transaction operations and resource reservation operations associated with the non-local sub-transaction in the first main transaction.

[0110] For explanations of steps S401 to S402, reference may be made to the relevant descriptions in any embodiment of the present disclosure, and will not be repeated here.

[0111] Step S403, in response to the successful execution of the first business processing branch and the second business processing branch, execute the transaction confirmation tasks corresponding to the N sub-transactions in parallel; wherein, the transaction confirmation task corresponding to any sub-transaction includes: querying the database whether there is a transaction flow of the sub-transaction, if so, calling the confirmation interface of the transaction participant associated with any sub-transaction, in response to the successful call of the confirmation interface, determining that the transaction confirmation task corresponding to any sub-transaction is successfully executed, and updating the transaction flow status of any sub-transaction to submitted, in response to the failure of the confirmation interface call, determining that the transaction confirmation task corresponding to any sub-transaction fails to execute, and updating the transaction flow status of any sub-transaction to failed submission.

[0112] In the embodiment of the present disclosure, when both the first business processing branch and the second business processing branch are successfully executed, the transaction confirmation tasks corresponding to the N sub-transactions may be further executed.

[0113] The transaction confirmation task corresponding to any sub-transaction may include the following steps A to D:

[0114] Step A: Check whether there is a transaction flow for this subtransaction in the database. If not, it indicates that the Try phase of this subtransaction has not been executed or has been rolled back (or called rolled back). At this time, in order to ensure the final consistency and integrity of the transaction, there is no need to execute the subsequent step B. If it exists, it indicates that the Try phase of this subtransaction has been executed successfully. At this time, step B can be further executed.

[0115] Step B: If it exists, call the confirmation interface of the transaction participant associated with the subtransaction, where the confirmation interface is used to confirm and commit the transaction operation of the subtransaction and release the resources reserved for the subtransaction.

[0116] Step C: In response to the confirmation interface call being successful, determining that the transaction confirmation task associated with the subtransaction is successfully executed, and updating the pipeline status of the subtransaction to submitted.

[0117] Step D: In response to the failure of the confirmation interface call, determining that the transaction confirmation task associated with the subtransaction has failed to execute, and updating the pipeline status of the subtransaction to commit failure.

[0118] Step S404: in response to the successful execution of the transaction confirmation task, the pipeline status of the first main transaction in the database is updated to success.

[0119] For explanation of step S404, reference may be made to the relevant description in any embodiment of the present disclosure, and will not be repeated here.

[0120] The distributed transaction processing method of the embodiment of the present disclosure, since there are only the flow records of the sub-transactions that are successfully executed in the Try phase in the database, by querying the flow records, it is determined whether to execute the Confirm phase of the sub-transaction, which can ensure idempotence and avoid the reuse and release of resources.

[0121] In order to clearly illustrate any of the above embodiments of the present disclosure, the present disclosure also provides a method for processing distributed transactions.

[0122] Figure 5 A flowchart of another distributed transaction processing method provided by an embodiment of the present disclosure.

[0123] It should be noted that the distributed transaction processing method can be executed alone, or it can be executed in combination with any embodiment of the present disclosure or a possible implementation method in the embodiment, or it can be executed in combination with any technical solution in the related technology, and the embodiments of the present disclosure are not limited to this.

[0124] like Figure 5 As shown, the distributed transaction processing method includes the following steps S501 to S507:

[0125] Step S501: register a first main transaction of a distributed transaction according to a received transaction request.

[0126] Step S502: executing the first service processing branch and the second service processing branch in parallel.

[0127] Among them, the first business processing branch includes registering the flow of the first main transaction in the database, and executing transaction operations and resource reservation operations associated with the local sub-transaction in the first main transaction; the second business processing branch includes executing transaction operations and resource reservation operations associated with the non-local sub-transaction in the first main transaction.

[0128] For explanations of steps S501 to S502, reference may be made to the relevant descriptions in any embodiment of the present disclosure and will not be repeated here.

[0129] Step S503, in response to the failure of the execution of the second business processing branch, execute the first rollback task to roll back the transaction operations associated with the multiple sub-transactions in the first main transaction, return the resources reserved for the multiple sub-transactions and withdraw the flow of the multiple sub-transactions in the database.

[0130] In an embodiment of the present disclosure, in the event that the second business processing branch fails to execute, a second rollback task may be executed; wherein the second rollback task is used to roll back transaction operations associated with multiple subtransactions in the first main transaction, return resources reserved for the multiple subtransactions, and withdraw the flow of multiple subtransactions in the database.

[0131] As a possible implementation manner, when the first main transaction includes N subtransactions, and each subtransaction is associated with a transaction participant, the first rollback tasks corresponding to the N subtransactions may be executed in parallel.

[0132] The first rollback task corresponding to any subtransaction may include steps a to d:

[0133] Step a: Check whether there is a transaction flow for the subtransaction in the database. If not, it indicates that the Try phase of the subtransaction has not been executed or has been rolled back (or rolled back). At this time, in order to avoid an empty rollback, there is no need to execute the subsequent step b. If it exists, it indicates that the Try phase of the subtransaction has been executed successfully. At this time, step b can be further executed.

[0134] Step b: If it exists, call the cancel interface of the transaction participant associated with the subtransaction; wherein the cancel interface is used to roll back the transaction operation of the subtransaction, return the resources reserved for the subtransaction, and withdraw the transaction flow of the subtransaction in the database.

[0135] Step c: In response to the successful cancellation of the interface call, determining that the first rollback task corresponding to the subtransaction is successfully executed, and updating the pipeline status of the subtransaction to rolled back.

[0136] Step d: In response to the failure of canceling the interface call, determining that the first rollback task corresponding to the subtransaction has failed to execute, and updating the pipeline status of the subtransaction to rollback failure.

[0137] Step S504: in response to the first rollback task being executed successfully, updating the pipeline status of the first main transaction in the database to rollback success.

[0138] In the embodiment of the present disclosure, when the first rollback tasks corresponding to the plurality of sub-transactions are all executed successfully, the pipeline status of the first main transaction in the database may be updated to rollback success.

[0139] Step S505 , in response to the failure of the execution of the first business processing branch, registering the pipeline status of the first main transaction as pending rollback in the database.

[0140] In the embodiment of the present disclosure, when the execution of the first business processing branch fails, the pipeline status of the first main transaction may be registered in the database as pending rollback.

[0141] Step S506, executing the second rollback task to roll back the transaction operations associated with the multiple subtransactions, and returning the resources reserved for the multiple subtransactions and withdrawing the flow of the multiple subtransactions in the database.

[0142] Furthermore, a second rollback task may be executed, wherein the second rollback task is used to rollback the transaction operations associated with the multiple subtransactions, return the resources reserved for the multiple subtransactions, and withdraw the transactions of the multiple subtransactions in the database. The implementation principle is similar to the execution principle of the first rollback task, and will not be described in detail here.

[0143] Step S507: in response to the second rollback task being executed successfully, updating the pipeline status of the first main transaction to rollback successfully.

[0144] In the embodiment of the present disclosure, when the second rollback tasks corresponding to the multiple sub-transactions are all executed successfully, the pipeline status of the first main transaction in the database can be updated to rollback success.

[0145] In any one of the embodiments of the present disclosure, candidate main transactions whose pipeline states are non-terminal states (such as initial or to be rolled back) can also be queried from the database, and based on the processing time of the candidate main transactions, a second main transaction that has timed out can be determined from the candidate main transactions, and multiple subtransactions in the second main transaction can be rolled back.

[0146] The processing time of the second main transaction exceeds the first time threshold (the set maximum timeout time).

[0147] That is, the transaction rollback tasks corresponding to the multiple subtransactions in the second main transaction are executed in parallel, wherein the execution principle of the transaction rollback task of each subtransaction is similar to the execution principle of the first rollback task, which will not be elaborated here.

[0148] Therefore, through the fallback mechanism, the timed-out and unfinished transactions can be rolled back, so as to achieve the final consistency of distributed transactions and ensure the correctness of transaction processing. At the same time, the fallback mechanism can be executed asynchronously, which has little impact on system performance.

[0149] In any one of the embodiments of the present disclosure, it is also possible to query the target sub-transaction whose pipeline status satisfies the set status (wherein the set status is a non-terminal status, and the final status includes submitted and rolled back (or canceled)) and timed out, and query the main transaction to which the target sub-transaction belongs (referred to as the third main transaction in the present disclosure), and query the pipeline status of the third main transaction from the database. If the pipeline status of the third main transaction is to be submitted, multiple sub-transactions in the third main transaction are submitted, that is, the Confirm phases of multiple sub-transactions in the third main transaction are executed in parallel, and when the transaction is submitted successfully, the pipeline status of the third main transaction in the database is updated to success.

[0150] If the pipeline status of the third main transaction is initial or to be rolled back, the multiple subtransactions in the third main transaction are rolled back, that is, the transaction rollback tasks corresponding to the multiple subtransactions in the third main transaction are executed in parallel, wherein the execution principle of the transaction rollback task of each subtransaction is similar to the execution principle of the first rollback task, which will not be described in detail here. If the transaction rollback is successful, the pipeline status of the third main transaction in the database is updated to rollback success.

[0151] Therefore, through the fallback mechanism, transactions that have timed out and are waiting to be committed can be committed, and / or transactions that have timed out and are not completed and are in a non-final state can be rolled back, so that the eventual consistency of distributed transactions can be achieved and the correctness of transaction processing can be ensured. At the same time, the fallback mechanism can be executed asynchronously, with less impact on system performance.

[0152] The distributed transaction processing method of the embodiment of the present disclosure, since there is only the flow of sub-transactions that are successfully executed in the Try phase in the database, by querying the flow, it is determined whether to execute the Cancel phase of the sub-transaction, which can ensure idempotence, avoid the reuse and release of resources, avoid empty rollback, and ensure the correct execution of the rollback logic.

[0153] In any embodiment of the present disclosure, since the time required to submit a transaction is relatively long and has a great impact on performance, in the present disclosure, transactions can be merged as much as possible to reduce the number of database writes. At the beginning of the transaction, the Try phases of different branches are executed asynchronously using different transaction threads, and the flow of the registered main transaction is merged into the transaction of the main thread (the main branch, recorded as the first business processing branch in the present disclosure), and at the confluence point, the second-stage operation is determined based on the execution result of the Try phase: Confirm operation or Cancel operation. If all the Try phases of the confluence point are executed successfully, the second-stage Confirm operation is executed asynchronously. The principle of transaction processing can be as follows: Figure 6 As shown, it mainly includes the following steps:

[0154] Step 1: After receiving the transaction request, the transaction initiator registers the flow of the main transaction, executes the Try phase of the main branch (referred to as the first business processing branch in this disclosure), and asynchronously performs the Try phase of other branches (referred to as the second business processing branch in this disclosure).

[0155] Step 2: Summarize the execution results of the Try phase of the first step for subsequent second-stage processing. If the main branch Try phase and other branch Try phases are executed successfully, execute step 3; if the Try phase of a branch thread fails, execute step 4; if the main transaction and main branch Try phase fail, execute step 5.

[0156] Step 3: Asynchronously execute the second-stage Confirm operation and update the pipeline status of the main transaction (see Figures 2 to 4 any of the embodiments shown).

[0157] Step 4: Asynchronously execute the second-stage Cancel operation and insert or update the pipeline status of the main transaction (see Figure 5 Steps S503 to S504 in the embodiment).

[0158] Step 5: Register a transaction to be rolled back, asynchronously execute the second-stage Cancel operation, and insert or update the transaction status of the main transaction (see Figure 5 Steps S505 to S507 in the embodiment).

[0159] In order to ensure that the transaction can be rolled back through the Cancel operation in the event of an exception and to ensure the final consistency of the data, the specific processing mechanism is as follows:

[0160] 1. Idempotent processing (see Figures 4 to 5Embodiment): Due to network jitter and other reasons, the distributed transaction framework may repeatedly call the second-phase interface of a branch transaction in the same distributed transaction. Therefore, the second-phase Confirm / Cancel interface called by the branch transaction needs to be able to ensure idempotence to avoid repeated use and release of resources.

[0161] 2. Empty rollback processing (see Figure 5 Embodiment): If the Cancel interface is called without calling the Try interface, the Cancel interface needs to be able to recognize that this is an empty rollback and directly return success.

[0162] 3. Anti-hanging treatment (see Figure 5 Embodiment): For a distributed transaction, the second-phase Cancel interface may be executed before the Try interface. In this case, it is necessary to determine whether the Try interface has been executed in order to correctly execute the rollback logic.

[0163] 4. Safety net mechanism (see Figure 5 Related description in the embodiment):

[0164] Bottom-line treatment 1 (such as Figure 7 As shown): Scan the main transaction table in the database (used to store the flow status of the main transaction) and roll back.

[0165] The account center can batch scan the main transactions in the main transaction table with the status of pending rollback and initial transactions at regular intervals, and if the execution time of the main transaction exceeds the maximum timeout, the main transaction will be rolled back.

[0166] Bottom-line treatment 2 (such as Figure 8 As shown): Scan the branch transaction table in the database (used to store the flow status of sub-transactions) to perform a back-check and bottom-up rollback of the main transaction.

[0167] If an exception occurs in a transaction and the main transaction fails to be registered, and the asynchronous branch sub-transaction has not received the driver from the management node after the maximum transaction timeout, it will try to check the main transaction status at the management node. If the main transaction status is pending, the main transaction will be committed. If the main transaction status is initial / pending rollback, the main transaction will be rolled back.

[0168] In summary, the distributed transaction processing method provided by the present disclosure includes at least the following features:

[0169] 1. Concurrently process distributed sub-transactions to reduce transaction processing time; merge sub-transaction flows to reduce database overhead; distributed transaction backup mechanism to ensure the final consistency of distributed transactions;

[0170] 2. Distributed transaction processing mechanism deeply integrated with business. First, in financial business scenarios, a main transaction often contains multiple sub-transactions. By executing sub-transactions in parallel and merging transaction records, the processing capability of distributed transactions is greatly improved to meet high-concurrency business needs.

[0171] 3. The final consistency of distributed transactions is achieved through a backup mechanism to ensure the correctness of transaction processing. At the same time, the use of an asynchronous mechanism has little impact on system performance.

[0172] Through the above design method and implementation, it is possible to greatly improve the processing performance of distributed transactions while ensuring the final consistency of distributed transactions, and meet the use scenarios of high concurrency (tens of thousands of MIPS (Million Instructions Per Second)) of the core business systems of financial institutions.

[0173] In order to implement the above embodiments, the present disclosure also provides a distributed transaction processing device.

[0174] Fig. 9 A schematic diagram of the structure of a distributed transaction processing device provided in an embodiment of the present disclosure.

[0175] like Fig. 9 As shown, the distributed transaction processing device 900 includes: a registration module 910, a first execution module 920, a second execution module 930 and a first update module 940.

[0176] The registration module 910 is used to register the first main transaction of the distributed transaction according to the received transaction request;

[0177] The first execution module 920 is used to execute the first business processing branch and the second business processing branch in parallel; wherein the first business processing branch includes registering the flow of the first main transaction in the database, and executing the transaction operation and resource reservation operation associated with the local sub-transaction in the first main transaction; the second business processing branch includes executing the transaction operation and resource reservation operation associated with the non-local sub-transaction in the first main transaction;

[0178] The second execution module 930 is used to execute a transaction confirmation task in response to the first business processing branch and the second business processing branch being successfully executed; wherein the transaction confirmation task is used to confirm and commit the transaction operations of the multiple sub-transactions in the first main transaction, and release the resources reserved for the multiple sub-transactions;

[0179] The first updating module 940 is configured to update the pipeline status of the first main transaction in the database to success in response to the successful execution of the transaction confirmation task.

[0180] In a possible implementation of the embodiment of the present disclosure, each subtransaction in the first main transaction is associated with a transaction participant, and the first execution module 920 is specifically used to: register the flow of the first main transaction in the database, and query whether there is a flow of the local subtransaction in the database; if not, call the attempt interface of the transaction participant associated with the local subtransaction; wherein the attempt interface is used to execute the transaction operation and resource reservation operation associated with the local subtransaction, and register the flow of the local subtransaction in the database; in response to a successful call to the attempt interface, determine that the first business processing branch is executed successfully, and update the flow status of the local subtransaction to attempted; in response to a failure in the call to the attempt interface, determine that the first business processing branch fails to execute, and update the flow status of the local subtransaction to attempted failure.

[0181] In a possible implementation of the embodiment of the present disclosure, the first main transaction includes N sub-transactions, where N is a positive integer, and each sub-transaction is associated with a transaction participant. The second execution module 930 is specifically used to: execute transaction confirmation tasks corresponding to the N sub-transactions in parallel; wherein the transaction confirmation task corresponding to any sub-transaction includes: querying whether there is a transaction flow of any sub-transaction in the database; if so, calling the confirmation interface of the transaction participant associated with any sub-transaction; wherein the confirmation interface is used to confirm and submit the transaction operation of any sub-transaction and release the resources reserved for any sub-transaction; in response to a successful confirmation interface call, determining that the transaction confirmation task corresponding to any sub-transaction is successfully executed, and updating the transaction flow status of any sub-transaction to submitted; in response to a failed confirmation interface call, determining that the transaction confirmation task corresponding to any sub-transaction fails to execute, and updating the transaction flow status of any sub-transaction to failed submission.

[0182] In a possible implementation of the embodiment of the present disclosure, the distributed transaction processing device 900 further includes:

[0183] A third execution module is used to execute a first rollback task in response to the failure of the execution of the second business processing branch, so as to roll back the transaction operations associated with the multiple sub-transactions, return the resources reserved for the multiple sub-transactions, and withdraw the flow of the multiple sub-transactions in the database;

[0184] The second updating module is used to update the pipeline status of the first main transaction in the database to rollback success in response to the first rollback task being executed successfully.

[0185] In a possible implementation of the embodiment of the present disclosure, a first main transaction includes N subtransactions, where N is a positive integer, and each subtransaction is associated with a transaction participant. A third execution module is specifically used to: execute first rollback tasks corresponding to the N subtransactions in parallel; wherein the first rollback task corresponding to any subtransaction includes: querying whether there is a transaction flow of any subtransaction in the database; if so, calling a cancel interface of a transaction participant associated with any subtransaction; wherein the cancel interface is used to roll back the transaction operation of any subtransaction, and return the resources reserved for any subtransaction and withdraw the transaction flow of any subtransaction in the database; in response to a successful call to the cancel interface, determining that the first rollback task corresponding to any subtransaction is successfully executed, and updating the transaction flow status of any subtransaction to rolled back; in response to a failed call to the cancel interface, determining that the first rollback task corresponding to any subtransaction is failed, and updating the transaction flow status of any subtransaction to rollback failure.

[0186] In a possible implementation of the embodiment of the present disclosure, the distributed transaction processing device 900 further includes:

[0187] A registration module, configured to register, in response to a failure in the execution of the first business processing branch, a pipeline status of the first main transaction as pending rollback in a database;

[0188] A fourth execution module, configured to execute a second rollback task to roll back the transaction operations associated with the multiple subtransactions, and return resources reserved for the multiple subtransactions and withdraw the transactions of the multiple subtransactions in the database;

[0189] The third updating module is used to update the pipeline status of the first main transaction to rollback success in response to the second rollback task being executed successfully.

[0190] In a possible implementation of the embodiment of the present disclosure, the distributed transaction processing device 900 further includes:

[0191] The first query module is used to query candidate main transactions whose pipeline status is initial or to be rolled back;

[0192] A determination module, configured to determine a second main transaction from the candidate main transactions according to the processing duration of the candidate main transactions; wherein the processing duration of the second main transaction exceeds a first duration threshold;

[0193] The first rollback module is used to roll back multiple sub-transactions in the second main transaction.

[0194] In a possible implementation of the embodiment of the present disclosure, the distributed transaction processing device 900 further includes:

[0195] The second query module is used to query the target sub-transaction whose transaction status satisfies the set status; wherein the processing time of the target sub-transaction exceeds the second time threshold; the set status is a non-final status, and the final status includes submitted and rolled back;

[0196] A third query module, used to query the third main transaction to which the target sub-transaction belongs, and query the transaction status of the third main transaction from the database;

[0197] A commit module, configured to commit multiple subtransactions in the third main transaction in response to the pipeline status of the third main transaction being to be committed;

[0198] The fourth updating module is used to update the pipeline status of the third main transaction in the database to success in response to the transaction being submitted successfully.

[0199] In a possible implementation of the embodiment of the present disclosure, the distributed transaction processing device 900 further includes:

[0200] A second rollback module, configured to roll back multiple subtransactions in the third main transaction in response to the pipeline status of the third main transaction being initial or to be rolled back;

[0201] The fifth updating module is used to update the pipeline status of the third main transaction in the database to rollback success in response to the transaction rollback success.

[0202] It should be noted that the distributed transaction processing device provided in the embodiment of the present disclosure can achieve the above Figures 2 to 5 All the method steps implemented in the method embodiment can achieve the same technical effect, and the parts and beneficial effects of this embodiment that are the same as those in the method embodiment will not be described in detail here.

[0203] In order to implement the above embodiments, the present disclosure also proposes an electronic device, wherein the electronic device can be any device with computing capabilities, and the electronic device includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the processor executes the program, it implements the distributed transaction processing method proposed in any of the aforementioned embodiments of the present disclosure.

[0204] As an example, Fig.10 is a schematic diagram of the structure of an electronic device 1000 shown in an exemplary embodiment of the present disclosure, such as Fig.10 As shown, the electronic device 1000 may further include:

[0205] The memory 1010 and the processor 1020, the bus 1030 connecting different components (including the memory 1010 and the processor 1020), the memory 1010 stores a computer program, and when the processor 1020 executes the program, the distributed transaction processing method described in the embodiment of the present disclosure is implemented.

[0206] Bus 1030 represents one or more of several types of bus structures, including a memory bus or memory controller, a peripheral bus, an accelerated graphics port, a processor or a local bus using any of a variety of bus architectures. For example, these architectures include but are not limited to Industry Standard Architecture (ISA) bus, Micro Channel Architecture (MAC) bus, Enhanced ISA bus, Video Electronics Standards Association (VESA) local bus and Peripheral Component Interconnect (PCI) bus.

[0207] The electronic device 1000 typically includes a variety of electronic device readable media. These media can be any available media that can be accessed by the electronic device 1000, including volatile and non-volatile media, removable and non-removable media.

[0208] The memory 1010 may also include computer system readable media in the form of volatile memory, such as random access memory (RAM) 1040 and / or cache memory 1050. The server 1000 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 1060 may be used to read and write non-removable, non-volatile magnetic media ( Fig.10 not shown, usually called a "hard drive"). Although Fig.10 Not shown in the figure, a disk drive for reading and writing to a removable non-volatile disk (e.g., a "floppy disk"), and an optical disk drive for reading and writing to a removable non-volatile optical disk (e.g., a CD-ROM, a DVD-ROM, or other optical media) may be provided. In these cases, each drive may be connected to the bus 1030 via one or more data medium interfaces. The memory 1010 may include at least one program product having a set (e.g., at least one) of program modules that are configured to perform the functions of the various embodiments of the present disclosure.

[0209] A program / utility 1080 having a set (at least one) of program modules 1070 may be stored, for example, in the memory 1010, such program modules 1070 including, but not limited to, an operating system, one or more application programs, other program modules, and program data, each of which or some combination may include an implementation of a network environment. The program modules 1070 generally perform the functions and / or methods of the embodiments described in the present disclosure.

[0210] The electronic device 1000 may also communicate with one or more external devices 1090 (e.g., keyboard, pointing device, display 1091, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 1000, and / or communicate with any device that enables the electronic device 1000 to communicate with one or more other computing devices (e.g., network card, modem, etc.). Such communication may be performed through an input / output (I / O) interface 1092. In addition, the electronic device 1000 may also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN) and / or public network, such as the Internet) through a network adapter 1093. As shown, the network adapter 1093 communicates with other modules of the electronic device 1000 through a bus 1030. It should be understood that, although not shown in the figure, other hardware and / or software modules may be used in conjunction with the electronic device 1000, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0211] The processor 1020 executes various functional applications and data processing by running the programs stored in the memory 1010 .

[0212] It should be noted that the implementation process and technical principles of the electronic device of this embodiment refer to the aforementioned explanation of the distributed transaction processing method of the embodiment of the present disclosure, and will not be repeated here.

[0213] In order to implement the above embodiments, the present disclosure further proposes a non-temporary computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the distributed transaction processing method proposed in any of the above embodiments of the present disclosure is implemented.

[0214] In order to implement the above embodiments, the present disclosure further proposes a computer program product. When the instructions in the computer program product are executed by a processor, the distributed transaction processing method proposed in any of the above embodiments of the present disclosure is executed.

[0215] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "example", "specific example", or "some examples" etc. means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present disclosure. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner. In addition, those skilled in the art may combine and combine the different embodiments or examples described in this specification and the features of the different embodiments or examples, without contradiction.

[0216] In addition, the terms "first" and "second" are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of the features. In the description of the present disclosure, "plurality" means at least two, such as two, three, etc., unless otherwise clearly and specifically defined.

[0217] Any process or method description in a flowchart or otherwise described herein may be understood to represent a module, segment or portion of code that includes one or more executable instructions for implementing the steps of a custom logical function or process, and the scope of the preferred embodiments of the present disclosure includes additional implementations in which functions may not be performed in the order shown or discussed, including performing functions in a substantially simultaneous manner or in reverse order depending on the functions involved, which should be understood by technicians in the technical field to which the embodiments of the present disclosure belong.

[0218] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute the instructions), or in combination with these instruction execution systems, devices or apparatuses. For the purpose of this specification, "computer-readable medium" can be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in combination with these instruction execution systems, devices or apparatuses. More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection with one or more wires (electronic device), a portable computer disk box (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), a fiber optic device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium and then editing, interpreting or processing in other suitable ways if necessary, and then stored in a computer memory.

[0219] It should be understood that the various parts of the present disclosure can be implemented in hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, multiple steps or methods can be implemented in software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, any one of the following technologies known in the art or a combination thereof can be used to implement: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.

[0220] A person skilled in the art may understand that all or part of the steps in the method for implementing the above-mentioned embodiment may be completed by instructing related hardware through a program, and the program may be stored in a computer-readable storage medium, which, when executed, includes one or a combination of the steps of the method embodiment.

[0221] In addition, each functional unit in each embodiment of the present disclosure may be integrated into a processing module, or each unit may exist physically separately, or two or more units may be integrated into one module. The above-mentioned integrated module may be implemented in the form of hardware or in the form of a software functional module. If the integrated module is implemented in the form of a software functional module and sold or used as an independent product, it may also be stored in a computer-readable storage medium.

[0222] The storage medium mentioned above may be a read-only memory, a disk or an optical disk, etc. Although the embodiments of the present disclosure have been shown and described above, it can be understood that the above embodiments are exemplary and cannot be understood as limitations of the present disclosure. A person of ordinary skill in the art may change, modify, replace and modify the above embodiments within the scope of the present disclosure.

Claims

1. A distributed transaction processing method, characterized in that: include: Registering the first main transaction of the distributed transaction according to the received transaction request; Executing a first business processing branch and a second business processing branch in parallel; wherein the first business processing branch includes registering the pipeline of the first main transaction in a database, and executing transaction operations and resource reservation operations associated with local subtransactions in the first main transaction; and the second business processing branch includes executing transaction operations and resource reservation operations associated with non-local subtransactions in the first main transaction; In response to the first business processing branch and the second business processing branch being both executed successfully, executing a transaction confirmation task; wherein the transaction confirmation task is used to confirm and commit the transaction operations of the multiple sub-transactions in the first main transaction, and release resources reserved for the multiple sub-transactions; In response to the transaction confirmation task being executed successfully, the pipeline status of the first main transaction in the database is updated to success.

2. The method according to claim 1, characterized in that Each sub-transaction in the first main transaction is associated with a transaction participant, and a first business processing branch is executed, including: Registering the transaction log of the first main transaction in the database, and querying whether the transaction log of the local subtransaction exists in the database; If it does not exist, calling the attempt interface of the transaction participant associated with the local subtransaction; wherein the attempt interface is used to execute the transaction operation and resource reservation operation associated with the local subtransaction, and register the flow of the local subtransaction in the database; In response to the attempt interface call being successful, determining that the first business processing branch is executed successfully, and updating the pipeline status of the local subtransaction to attempted; In response to the failure of the interface call attempt, it is determined that the execution of the first business processing branch has failed, and the pipeline status of the local sub-transaction is updated to a failed attempt.

3. The method according to claim 1, characterized in that The first main transaction includes N subtransactions, where N is a positive integer, each subtransaction is associated with a transaction participant, and the execution of the transaction confirmation task includes: Execute transaction confirmation tasks corresponding to N sub-transactions in parallel; wherein, the transaction confirmation task corresponding to any sub-transaction includes: Querying the database whether there is a transaction record of any of the sub-transactions; If so, calling the confirmation interface of the transaction participant associated with any of the subtransactions; wherein the confirmation interface is used to confirm and commit the transaction operation of any of the subtransactions, and release the resources reserved for any of the subtransactions; In response to the confirmation interface call being successful, determining that the transaction confirmation task corresponding to any of the subtransactions is successfully executed, and updating the pipeline status of any of the subtransactions to submitted; In response to the failure of calling the confirmation interface, it is determined that the transaction confirmation task corresponding to any of the sub-transactions has failed to execute, and the pipeline status of any of the sub-transactions is updated to submission failure.

4. The method according to claim 1, characterized in that: The method further comprises: In response to the failure of the execution of the second business processing branch, executing a first rollback task to roll back the transaction operations associated with the multiple subtransactions, return the resources reserved for the multiple subtransactions, and withdraw the pipelines of the multiple subtransactions in the database; In response to the first rollback task being executed successfully, the pipeline status of the first main transaction in the database is updated to rollback success.

5. The method according to claim 4, characterized in that The first main transaction includes N subtransactions, where N is a positive integer, each subtransaction is associated with a transaction participant, and the executing the first rollback task includes: The first rollback tasks corresponding to the N subtransactions are executed in parallel; wherein the first rollback task corresponding to any subtransaction includes: Querying the database whether there is a transaction record of any of the sub-transactions; If it exists, calling the cancel interface of the transaction participant associated with any sub-transaction; wherein the cancel interface is used to roll back the transaction operation of any sub-transaction, return the resources reserved for any sub-transaction, and withdraw the transaction flow of any sub-transaction in the database; In response to the cancellation interface call being successful, determining that the first rollback task corresponding to any of the subtransactions is successfully executed, and updating the pipeline status of any of the subtransactions to rolled back; In response to the failure of the cancel interface call, it is determined that the first rollback task corresponding to any of the subtransactions has failed to execute, and the pipeline state of any of the subtransactions is updated to rollback failure.

6. The method according to claim 1, characterized in that The method further comprises: In response to the failure of execution of the first business processing branch, registering in the database the pipeline status of the first main transaction as pending rollback; Executing a second rollback task to roll back transaction operations associated with the multiple subtransactions, and returning resources reserved for the multiple subtransactions and withdrawing the transactions of the multiple subtransactions in the database; In response to the second rollback task being executed successfully, the pipeline status of the first main transaction is updated to rollback success.

7. The method according to any one of claims 1 to 6, characterized in that The method further comprises: Query the candidate main transactions whose flow status is initial or to be rolled back; Determine a second main transaction from the candidate main transactions according to the processing duration of the candidate main transactions; wherein the processing duration of the second main transaction exceeds a first duration threshold; Roll back the multiple subtransactions in the second main transaction.

8. The method according to any one of claims 1 to 6, characterized in that The method further comprises: Querying a target subtransaction whose transaction status satisfies a set status; wherein the processing time of the target subtransaction exceeds a second time threshold; the set status is a non-final status, and the final status includes submitted and rolled back; Querying a third main transaction to which the target subtransaction belongs, and querying the transaction status of the third main transaction from the database; In response to the pipeline status of the third main transaction being to be committed, committing the multiple subtransactions in the third main transaction; In response to successful transaction submission, the pipeline status of the third main transaction in the database is updated to success.

9. The method according to claim 8, characterized in that The method further comprises: In response to the pipeline status of the third main transaction being initial or to be rolled back, multiple subtransactions in the third main transaction are rolled back; In response to a successful transaction rollback, the pipeline status of the third main transaction in the database is updated to rollback success.

10. A distributed transaction processing device, characterized in that: include: A registration module, used for registering a first main transaction of a distributed transaction according to a received transaction request; A first execution module is used to execute a first business processing branch and a second business processing branch in parallel; wherein the first business processing branch includes registering the pipeline of the first main transaction in a database, and executing transaction operations and resource reservation operations associated with local subtransactions in the first main transaction; and the second business processing branch includes executing transaction operations and resource reservation operations associated with non-local subtransactions in the first main transaction; A second execution module, configured to execute a transaction confirmation task in response to the first business processing branch and the second business processing branch being successfully executed; wherein the transaction confirmation task is used to confirm and commit the transaction operations of the multiple sub-transactions in the first main transaction, and release resources reserved for the multiple sub-transactions; An update module is used to update the pipeline status of the first main transaction in the database to success in response to the successful execution of the transaction confirmation task.

Citation Information

Patent Citations

  • Distributed transaction processing method and system

    CN106775959A

  • Task scheduling method, distributed system, electronic equipment and storage medium

    CN115421926A

  • Transaction processing system and device

    CN116339928A

  • Distributed transaction processing method based on PHP

    CN116842028A

  • Transaction processing method and device

    CN117667319A