Distributed transaction processing method

By merging service flows and transaction flows in the local database, using aspect-oriented programming technology and SDK packaging, the problems of low distributed transaction processing performance and high development difficulty are solved, and high performance and simplified development effects are achieved.

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

Patent Information

Application Number
CN202411223758.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-02
Publication Date
2024-11-29
Estimated Expiration
2044-09-02

AI Technical Summary

Technical Problem

The existing distributed transaction processing methods have low performance in financial application scenarios, are difficult to meet the needs of high concurrent services, and are difficult to develop, which requires developers to deeply understand the complex SAGA implementation.

Method used

A distributed transaction processing method is proposed. By merging service flows and transaction flows in the local database, the number of flow registrations is reduced, and the surface-oriented programming technology is used to insert flow table operations without changing the business logic code. Distributed transaction management is based on Local flow registration system, encapsulating processing logic using SDK to simplify development.

Benefits of technology

It improves microservice performance, reduces network call delay and complexity, simplifies distributed transaction development, reduces development difficulty and code volume, and meets the high concurrency needs of medium and large financial institutions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119045957A_ABST
    Figure CN119045957A_ABST
Patent Text Reader

Abstract

The invention provides a distributed transaction processing method, and relates to the technical field of data processing. The method comprises the following steps: in response to a received transaction request, determining a target business process corresponding to a transaction type of the transaction request; starting a main transaction of the distributed transaction for the transaction request based on a plurality of target tasks needing to be executed by the target business process, and registering the main transaction in a local database in a pipelined manner; wherein the main transaction comprises a plurality of ordered sub-transactions, and each sub-transaction corresponds to one target task; traversing the plurality of ordered sub-transactions in sequence, and processing the currently traversed sub-transactions according to a judgment result that whether the currently traversed sub-transactions are local transactions or not; in response to the fact that all the sub-transactions are successfully processed, the main transaction is ended, and the state of the main transaction pipeline in the local database is updated to be a completed state. Therefore, the number of times of pipeline registration can be reduced, and the performance is improved. Meanwhile, the management of the distributed transaction is realized based on a local pipeline registration system, and the performance is better.
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 for processing distributed transactions. Background Art

[0002] A distributed system is a system composed of a group of service nodes (or computer nodes) that communicate through a network and work in coordination to complete a common task. Due to the geographical and logical dispersion of its services and data, transaction management is much more complicated than traditional monolithic applications. With the rise of microservice architecture, in actual financial application scenarios, several microservices work together to complete a task or business function, which is inseparable from the participation of distributed transactions. Among them, when facing long business processes, SAGA (Sequentially Consistent Autonomous Global Transactions) can be used. SAGA is an event-driven distributed transaction model that can be widely used in distributed systems of microservice architecture. Its purpose is to ensure that operations between multiple services in a distributed system are sequentially consistent, thereby ensuring eventual consistency.

[0003] In related technologies, the processing method of distributed transactions requires independent processing of distributed transaction control processing and business code logic processing, and both transaction processes and business flow information need to be saved in the database at the same time. This reduces the performance of microservices and makes it difficult to meet the high-concurrency business scenario requirements of the core business systems of medium and large financial institutions. Summary of the invention

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

[0005] One aspect of the present disclosure provides a distributed transaction processing method to reduce the number of transaction registrations and improve performance. At the same time, the management of distributed transactions is implemented based on a local transaction registration system, which has better performance.

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

[0007] In response to receiving a transaction request, determining a target business process corresponding to a transaction type of the transaction request;

[0008] Based on the multiple target tasks required to be executed by the target business process, a main transaction of the distributed transaction is opened for the transaction request, and the main transaction flow is registered in the local database; wherein the main transaction includes multiple ordered sub-transactions, and each sub-transaction corresponds to a target task;

[0009] Traversing the multiple ordered subtransactions in sequence, and processing the currently traversed subtransaction according to a determination result of whether the currently traversed subtransaction is a local transaction;

[0010] In response to the multiple sub-transactions being successfully processed, the main transaction is terminated, and the status of the main transaction pipeline in the local database is updated to a completed status.

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

[0012] A determination module, configured to determine, in response to receiving a transaction request, a target business process corresponding to a transaction type of the transaction request;

[0013] An opening registration module is used to open a main transaction of a distributed transaction for the transaction request based on a plurality of target tasks to be executed by the target business process, and register the main transaction flow into a local database; wherein the main transaction includes a plurality of ordered sub-transactions, and each sub-transaction corresponds to a target task;

[0014] A traversal processing module, used to traverse the multiple ordered sub-transactions in sequence, and process the sub-transaction currently traversed according to a judgment result of whether the sub-transaction currently traversed is a local transaction;

[0015] The end update module is used to end the main transaction in response to the multiple sub-transactions being successfully processed, and update the status of the main transaction flow in the local database to a completed status.

[0016] 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.

[0017] 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.

[0018] 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.

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

[0020] When processing distributed transactions, distributed transaction control processing and business code logic processing can share the same flow table, that is, the service flow required by the business and the main transaction flow of the distributed transaction are combined into one. Only the main transaction flow needs to be logged in the local database, which can reduce the number of flow registrations and improve the performance of microservices to meet the high-concurrency business scenario requirements of the core business systems of medium and large financial institutions. Among them, by using aspect-oriented programming (Spring AOP) technology, the relevant operations of inserting the flow table of the local database can be implemented without changing the business logic code and without intrusion into the business logic code. At the same time, the management of distributed transactions is based on the local flow registration system. For example, registering the main transaction flow to the local database reduces the delay and complexity caused by network calls compared to the traditional external service or remote call service to implement transaction management, and has better performance.

[0021] In addition, the processing logic of distributed transactions is encapsulated in the SDK, so there is no need to implement distributed transaction processing separately in the business logic code. This approach allows developers to directly orchestrate business processes through visual tools without having to deeply understand the complex implementation of SAGA, and then the SDK automatically orchestrates distributed transactions. Therefore, developers do not need to write relevant code specifically, which improves development efficiency and code quality, and greatly reduces the difficulty of developing distributed microservices.

[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 A schematic diagram of a process flow of a distributed transaction processing method provided by an embodiment of the present disclosure;

[0025] Figure 2 A flowchart of another 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 schematic diagram of specific implementation steps of a distributed transaction processing method provided by an embodiment of the present disclosure;

[0029] Figure 6 A schematic diagram of the structure of a distributed transaction processing device provided by an embodiment of the present disclosure;

[0030] Figure 7 It is a schematic structural diagram of an electronic device shown in an exemplary embodiment of the present disclosure. DETAILED DESCRIPTION

[0031] 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.

[0032] At present, the implementation of SAGA transactions mainly has the following two problems:

[0033] First, microservice development is difficult. In actual engineering development, commercial products are only provided to application developers after being technically packaged through SDK (Software Development Kit). Developers need to handle a lot of distributed transaction-related logic in the business logic code, and need to implement business processes and handle distributed transaction processes according to system design, which requires high capabilities of developers. Investing a large number of senior professional technicians in the project not only increases project costs, but also increases the complexity of the system, and the quality is difficult to guarantee. Especially in financial application scenarios, system defects caused by transaction processing are one of the important challenges in the construction of core business systems.

[0034] The second aspect is the performance issue. Performance is also one of the important challenges of distributed transaction processing. The existing distributed transaction processing methods generally require distributed transaction control processing and business code logic processing to be processed independently. Both the transaction process and business flow information need to be saved in the database at the same time, that is, distributed transaction control processing and business code logic processing need to use different flow tables in the database respectively, one of which is used to record transaction flow, and the other is used to record service flow. It should be noted that registering service flow and registering transaction flow are two completely independent actions, which are implemented based on two different local transactions. This will increase the processing time, resource overhead and database access pressure of distributed transactions, reduce the performance of microservices (such as throughput, response time, resource utilization, etc.), and it is difficult to meet the high-concurrency business scenario requirements of the core business systems of medium and large financial institutions.

[0035] In view of at least one problem existing in the prior art, one aspect of the present disclosure provides a method and device for processing distributed transactions.

[0036] 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:

[0037] A distributed transaction means that the transaction participants, the servers supporting the transaction, the resource servers, and the transaction managers are located on different nodes of different distributed systems.

[0038] A local transaction is one in which an application accesses and potentially updates various data items in the database within its own business system.

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

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

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

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

[0043] For a local transaction in a subtransaction, the subtransaction flow includes, but is not limited to, the subtransaction call-related flow number, out-parameter information, and in-parameter information.

[0044] For a subtransaction of the RPC (Remote Procedure Call) type in a subtransaction (ie, a subtransaction of a remote RPC call), the subtransaction sequence only includes the sequence number.

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

[0046] The embodiment of the present disclosure takes the distributed transaction processing method as an example in which the distributed transaction processing method is configured in a distributed transaction processing device. The distributed transaction processing device can be applied to any electronic device with computing capabilities so that the electronic device can perform the distributed transaction processing function.

[0047] like Figure 1 As shown, the distributed transaction processing method includes the following steps S101 to S104:

[0048] Step S101, in response to receiving a transaction request, determining a target business process corresponding to a transaction type of the transaction request.

[0049] In the disclosed embodiment, the transaction request includes but is not limited to: a transfer request, a payment request, an order request, a refund request, a query request, an authorization request, etc.

[0050] In the disclosed embodiments, transaction types include, but are not limited to: transfer transactions, payment transactions, loan approval transactions, recharge transactions, withdrawal transactions, freeze transactions, unfreeze transactions, order transactions, etc.

[0051] In an embodiment of the present disclosure, when a transaction request is received, the transaction type of the transaction request can be determined, and the business process corresponding to the transaction type (referred to as the target business process in the present disclosure) can be determined.

[0052] As an example, the correspondence between different transaction types and business processes may be preconfigured, so that in the present disclosure, the correspondence may be queried according to the transaction type of the transaction request to determine the target business process corresponding to the transaction type.

[0053] Step S102, based on multiple target tasks that need to be executed in the target business process, a main transaction of the distributed transaction is opened for the transaction request, and the main transaction flow is registered in the local database.

[0054] In an embodiment of the present disclosure, multiple tasks (referred to as target tasks in the present disclosure) required to be executed by a target business process can be determined, and based on the multiple target tasks required to be executed by the target business process, a main transaction of a distributed transaction can be opened for a transaction request, wherein the main transaction can include multiple ordered sub-transactions, each sub-transaction corresponding to a target task.

[0055] In the embodiment of the present disclosure, when a main transaction is started, a unique main transaction identifier (such as a main transaction ID (Identity)) can be generated for the main transaction, and based on the main transaction identifier, the main transaction flow can be registered in the local database.

[0056] In any one of the embodiments of the present disclosure, the Spring AspectOriented Programming (Spring AOP) technology can be used to register the main transaction flow into the local database based on the main transaction identifier. Thus, the relevant operations of inserting the flow table of the local database can be implemented without changing the business logic code, and there is no intrusion into the business logic code.

[0057] Step S103, traverse the multiple ordered sub-transactions in the main transaction in sequence, and process the sub-transaction currently traversed according to the judgment result of whether the sub-transaction currently traversed is a local transaction.

[0058] In the disclosed embodiment, multiple ordered sub-transactions in the main transaction can be traversed in sequence, and it can be determined whether the currently traversed sub-transaction is a local transaction to obtain a determination result, so that the currently traversed sub-transaction can be processed based on the determination result.

[0059] Step S104, in response to multiple sub-transactions being successfully processed, the main transaction is terminated, and the status of the main transaction flow in the local database is updated to a completed status.

[0060] In the embodiment of the present disclosure, when multiple sub-transactions have been successfully processed, the main transaction can be ended, and the status of the main transaction flow in the local database is updated to a completed state (or a successful state).

[0061] In any one of the embodiments of the present disclosure, the aspect-oriented programming (Spring AOP) technology may be used to update the status of the main transaction pipeline in the local database to a completed state based on the main transaction identifier.

[0062] The distributed transaction processing method of the disclosed embodiment combines the service flow required by the business with the main transaction flow of the distributed transaction when processing distributed transactions. It only needs to log the main transaction flow in the local database, which can reduce the number of flow registrations and improve performance. At the same time, the management of distributed transactions is implemented based on the local flow registration system, such as registering the main transaction flow in the local database. Compared with the traditional external service or remote call service to implement transaction management, it reduces the delay and complexity caused by network calls and has better performance.

[0063] In order to clearly explain how the main transaction of the distributed transaction is opened for the transaction request based on multiple target tasks that need to be executed by the target business process in the above embodiment, the present disclosure also proposes a distributed transaction processing method.

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

[0065] 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.

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

[0067] Step S201, in response to receiving a transaction request, determining a target business process corresponding to a transaction type of the transaction request.

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

[0069] Step S202, obtaining multiple target tasks required to be executed by the target business process and the corresponding execution order, as well as the forward API (Application Programming Interface) and reverse API defined for the target tasks.

[0070] Among them, the forward API is used to perform the forward operation of the target task (i.e., normal or expected operation). This is the API called when each target task in the target business process moves forward. It is responsible for completing the business logic required for the target task, such as data processing, service calls, etc. It should be noted that the successful execution or call of the forward API is a key step in promoting the target business process.

[0071] The reverse API is used to cancel or roll back the forward operation of the target task, that is, to cancel or roll back the business operation performed by the forward API. The purpose of the reverse API is to restore the data and business status to the state before the forward API was executed. It should be noted that when the target business process needs to be interrupted due to errors, exceptions, user cancellation or other reasons, the call of the reverse API becomes particularly important to ensure the consistency of data and the reliability of the target business process.

[0072] In any embodiment of the present disclosure, a parsing result obtained by parsing a business process definition file can be obtained, wherein the business process definition file is generated or produced in response to business modeling, and the parsing result includes execution tasks defined for multiple business processes, the execution order of execution tasks under each business process, and forward APIs and reverse APIs defined for the execution tasks. In the present disclosure, multiple target tasks required to be executed by the target business process (i.e., the execution tasks defined for the target business process are taken as target tasks), the execution order of multiple target tasks, and the forward APIs and reverse APIs defined for the target tasks can be determined from the parsing result.

[0073] Step S203: based on the multiple target tasks and the corresponding execution order, forward API and reverse API, a main transaction of the distributed transaction is opened for the transaction request.

[0074] The main transaction includes multiple ordered sub-transactions, each sub-transaction corresponds to a target task, and the arrangement order of the sub-transactions is determined according to the execution order of the corresponding target tasks.

[0075] In the embodiment of the present disclosure, a main transaction of a distributed transaction may be opened for a transaction request based on multiple target tasks, the execution order of the multiple target tasks, and the forward APIs and reverse APIs of the multiple target tasks.

[0076] Step S204, registering the main transaction flow into the local database.

[0077] Step S205, traverse the multiple ordered sub-transactions in the main transaction in sequence, and process the sub-transaction currently traversed according to the judgment result of whether the sub-transaction currently traversed is a local transaction.

[0078] Step S206, in response to multiple sub-transactions being successfully processed, the main transaction is terminated, and the status of the main transaction flow in the local database is updated to a completed status.

[0079] The explanation of steps S204 to S206 can be found in the relevant description in any embodiment of the present disclosure, and will not be repeated here.

[0080] The distributed transaction processing method of the disclosed embodiment is based on multiple target tasks, the execution order of multiple target tasks, and the forward APIs and reverse APIs of multiple target tasks. It opens the main transaction of the distributed transaction for the transaction request, which can improve the accuracy and reliability of distributed transaction processing.

[0081] In order to clearly explain how any embodiment of the present disclosure processes a currently traversed sub-transaction according to whether the currently traversed sub-transaction is a local transaction, the present disclosure also proposes a distributed transaction processing method.

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

[0083] 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.

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

[0085] Step S301, in response to receiving a transaction request, determining a target business process corresponding to a transaction type of the transaction request.

[0086] Step S302: based on the multiple target tasks to be executed by the target business process, a main transaction of the distributed transaction is opened for the transaction request, and the main transaction flow is registered in the local database.

[0087] The main transaction includes multiple ordered sub-transactions, and each sub-transaction corresponds to a target task.

[0088] Step S303, traverse multiple ordered sub-transactions in the main transaction in sequence.

[0089] Step S304, determine whether the currently traversed subtransaction is a local transaction, and obtain a determination result.

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

[0091] Step S305 , processing the currently traversed sub-transaction according to the judgment result and the forward API and reverse API of the target task corresponding to the currently traversed sub-transaction.

[0092] In any embodiment of the present disclosure, when the judgment result indicates that the currently traversed subtransaction is a local transaction, the currently traversed subtransaction can be opened, and a subtransaction identifier (such as a subtransaction ID) can be generated for the currently traversed subtransaction. After that, the forward API of the target task corresponding to the currently traversed subtransaction can be called to execute the forward operation of the target task corresponding to the currently traversed subtransaction to complete the processing of the currently traversed subtransaction. Then, it can be determined whether the currently traversed subtransaction is successfully processed. If the currently traversed subtransaction is successfully processed, the currently traversed subtransaction flow can be registered in the local memory based on the subtransaction identifier.

[0093] The sub-transaction flow includes the flow number, output parameter information, and input parameter information related to the currently traversed sub-transaction call.

[0094] Therefore, the management of distributed transactions is implemented based on the local transaction flow registration system, such as registering the main transaction flow to the local database and registering the local transaction flow in the sub-transaction to the local memory. Compared with the traditional external service or remote call service to implement transaction management, it reduces the delay and complexity caused by network calls and has better performance.

[0095] In any embodiment of the present disclosure, if the currently traversed sub-transaction fails, the reverse API of the target task corresponding to the currently traversed sub-transaction can be further called to cancel or roll back the forward operation of the target task, and update the status of the main transaction flow in the local database to a failed state. In this way, the integrity, consistency and reliability of the target business process can be guaranteed.

[0096] In any embodiment of the present disclosure, when the judgment result indicates that the currently traversed subtransaction is not a local transaction, such as when the currently traversed subtransaction is an RPC-type subtransaction (i.e., a subtransaction of a remote RPC call), the uncommitted and successfully processed local transaction can be committed, and the subtransaction streams in the local memory can be merged. After that, the merged subtransaction streams can be registered in the local database, and the currently traversed subtransaction stream can be registered in the local database, wherein the subtransaction stream only includes the stream number, and the forward API of the target task corresponding to the currently traversed subtransaction is called through a remote call method to execute the forward operation of the target task corresponding to the currently traversed subtransaction, so as to complete the processing of the currently traversed subtransaction.

[0097] Therefore, when the currently traversed subtransaction is not a local transaction, the previously traversed and adjacent local subtransactions (including transaction registration) are automatically merged and submitted, which can reduce the number of times transactions are opened and submitted and improve the performance of microservices.

[0098] Step S306, in response to multiple sub-transactions being successfully processed, the main transaction is terminated, and the status of the main transaction flow in the local database is updated to a completed status.

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

[0100] The distributed transaction processing method of the embodiment of the present disclosure performs targeted processing on the currently traversed sub-transaction based on the judgment result of whether the currently traversed sub-transaction is a local transaction, and based on the forward API and reverse API of the target task corresponding to the currently traversed sub-transaction, thereby improving the accuracy and reliability of transaction processing.

[0101] 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.

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

[0103] 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.

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

[0105] Step S401, in response to receiving a transaction request, determining a target business process corresponding to a transaction type of the transaction request.

[0106] Step S402: based on the multiple target tasks to be executed by the target business process, a main transaction of the distributed transaction is opened for the transaction request, and the main transaction flow is registered in the local database.

[0107] The main transaction includes multiple ordered sub-transactions, and each sub-transaction corresponds to a target task.

[0108] Step S403, traverse the multiple ordered sub-transactions in the main transaction in sequence, and process the sub-transaction currently traversed according to the judgment result of whether the sub-transaction currently traversed is a local transaction.

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

[0110] In any one of the embodiments of the present disclosure, the distributed transaction processing method provided in any one of the embodiments of the present disclosure can be executed by a distributed transaction processing component, which is encapsulated with an SDK. In the present disclosure, the distributed transaction processing method proposed in any one of the embodiments of the present disclosure can be executed based on the algorithm logic encapsulated in the SDK.

[0111] As a result, the processing logic of distributed transactions is encapsulated in the SDK, so that distributed transaction processing does not need to be implemented separately in the business logic code. This method allows developers to directly orchestrate business processes through visual tools without having to deeply understand the complex implementation of SAGA, and then the SDK automatically orchestrates distributed transactions. Therefore, developers do not need to write relevant code specifically, which improves development efficiency and code quality, and greatly reduces the difficulty of developing distributed microservices.

[0112] Step S404: when the last sub-transaction among the multiple ordered sub-transactions is successfully processed, it is determined that the execution of the target business process is completed.

[0113] It should be noted that, in the case of a non-last sub-transaction in multiple ordered sub-transactions that fails to process, the reverse API of the target task corresponding to the sub-transaction that failed to execute will be called to cancel or roll back the forward operation of the target task corresponding to the sub-transaction that failed to execute, and update the status of the main transaction flow to a failed state. At this time, the subsequent sub-transactions will not be processed. Therefore, when the last sub-transaction in multiple ordered sub-transactions is successfully processed, it indicates that multiple sub-transactions have been successfully processed, and at this time, it can be determined that the target business process execution is completed.

[0114] Step S405: Commit the currently opened local transaction.

[0115] In the embodiment of the present disclosure, when it is determined that the execution of the target business process ends, the currently opened local transaction (ie, the local sub-transaction in the multiple sub-transactions) may be committed.

[0116] Step S406: Update the status of the main transaction flow in the local database to a completed status.

[0117] In any one of the embodiments of the present disclosure, the aspect-oriented programming (Spring AOP) technology may be used to update the status of the main transaction pipeline in the local database to a completed state based on the main transaction identifier.

[0118] In summary, by using aspect-oriented programming (Spring AOP) technology, it is possible to insert related operations into the local database flow table without changing the business logic code. At the same time, it is possible to automatically add transaction control logic before and after the execution of business methods, such as starting transactions, committing or rolling back transactions, without intruding on the business logic code.

[0119] In any one of the embodiments of the present disclosure, the present disclosure proposes a method for processing distributed transactions combined with business modeling, and a process engine device for efficiently processing distributed transactions, wherein the process engine device reads and parses the business process definition file generated in the business modeling stage, and automatically completes the distributed transactions of the business process based on the distributed transaction processing components in the process engine device, thereby ensuring the correctness of accounting processing.

[0120] As an example, the specific implementation principle of the distributed transaction processing method can be as follows: Figure 5 As shown, it mainly includes the following steps:

[0121] Step 1: Read and parse the business process definition file.

[0122] Through business modeling, a business process definition is generated, which consists of several tasks. Two APIs are designed corresponding to each task in the business process definition, namely the forward API and the reverse API. These APIs are arranged in a specific business process. Each execution node or task in the business process contains a pair of forward APIs and reverse APIs. In this step, the business process definition file will be obtained and parsed.

[0123] The second step is to start the main transaction.

[0124] In this step, the main transaction of the distributed transaction is started, a unique main transaction ID is generated, and the main transaction (service) flow is registered in the local database.

[0125] Step 3: Execute subtransaction.

[0126] Traverse multiple sub-transactions in the main transaction in sequence, and determine whether the currently traversed sub-transaction is a local transaction. If it is a local transaction, the process engine device automatically opens the currently traversed sub-transaction, generates a unique sub-transaction ID, and calls the forward API of the task corresponding to the currently traversed sub-transaction to complete the processing of the currently traversed sub-transaction. After completing the local sub-transaction related processing, register the currently traversed sub-transaction flow in the memory of the local flow registration system.

[0127] If it is not a local transaction, the previously uncommitted local transaction will be committed. At the same time, the sub-transaction flows in the memory will be merged and registered in the local database. Then, the sub-transaction flow currently traversed (including only the flow number) will be generated and registered in the local database, and the remote service will be called to complete the processing of the sub-transaction currently traversed.

[0128] If there are unprocessed sub-transactions after the currently traversed sub-transaction, that is, there are subsequent unprocessed tasks, repeat this step; if there are no unprocessed subsequent tasks, execute the fourth step.

[0129] Step 4: End the main transaction.

[0130] At the end of the business process, the currently opened local transaction is committed, and the status of the main transaction (service) flow is updated in the local database to the completed state.

[0131] Among them, the process engine device can be implemented by using aspect-oriented programming (Spring AOP), which can realize the relevant operations of inserting the local database flow table without changing the business logic code. At the same time, it can automatically add transaction control logic before and after the execution of the business method, such as starting a transaction, committing or rolling back a transaction, etc., without intruding the business logic code.

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

[0133] 1. The processing logic of distributed transactions is encapsulated in the SDK, so there is no need to implement distributed transaction processing separately in the business logic code. This method allows developers to directly orchestrate business processes through visual tools without having to deeply understand the complex implementation of SAGA, and then the SDK automatically orchestrates distributed transactions. Therefore, developers do not need to write relevant code specifically, which improves development efficiency and code quality, and greatly reduces the difficulty of developing distributed microservices.

[0134] 2. When processing distributed transactions, the service flow required by the business is combined with the main transaction flow of the distributed transaction. Only the main transaction flow needs to be logged in the local database, thereby reducing the number of flow registrations and improving performance. At the same time, the management of distributed transactions is implemented based on the local flow registration system. Compared with the traditional external service or remote call service to implement transaction management, it reduces the delay and complexity caused by network calls and has better performance.

[0135] 3. Automatically merge adjacent local sub-transactions (including transaction registration) to reduce the number of times transactions are opened and submitted, thereby improving performance.

[0136] Through the above design methods and implementations, developers can focus on the development of business logic while ensuring the correctness and efficiency of distributed transactions, greatly reducing the difficulty and entry threshold of distributed microservice development, and helping enterprises transform their distributed architecture.

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

[0138] Figure 6 A schematic diagram of the structure of a distributed transaction processing device provided in an embodiment of the present disclosure.

[0139] like Figure 6 As shown, the distributed transaction processing device 600 includes: a determination module 610, a registration start module 620, a traversal processing module 630 and an update end module 640.

[0140] The determination module 610 is used to determine the target business process corresponding to the transaction type of the transaction request in response to receiving the transaction request;

[0141] The registration module 620 is used to start a main transaction of a distributed transaction for a transaction request based on multiple target tasks to be executed by the target business process, and register the main transaction flow to a local database; wherein the main transaction includes multiple ordered sub-transactions, and each sub-transaction corresponds to a target task;

[0142] The traversal processing module 630 is used to traverse a plurality of ordered sub-transactions in sequence, and process the sub-transaction currently traversed according to the judgment result of whether the sub-transaction currently traversed is a local transaction;

[0143] The end update module 640 is used to end the main transaction in response to multiple sub-transactions being successfully processed, and update the status of the main transaction flow in the local database to a completed state.

[0144] In a possible implementation of the embodiment of the present disclosure, a registration module 620 is started, which is specifically used to: obtain multiple target tasks required to be executed by the target business process and the corresponding execution order, as well as a forward application program interface API and a reverse API defined for the target task; wherein the forward API is used to execute the forward operation of the target task, and the reverse API is used to cancel or roll back the forward operation of the target task; based on the multiple target tasks and the corresponding execution order, the forward API and the reverse API, a main transaction of a distributed transaction is started for the transaction request; wherein the main transaction includes multiple ordered sub-transactions, each sub-transaction corresponds to a target task, and the arrangement order of the sub-transactions is determined according to the execution order of the corresponding target tasks.

[0145] In a possible implementation of the embodiment of the present disclosure, the registration module 620 is started, specifically for: obtaining a parsing result obtained by parsing a business process definition file; wherein the business process definition file is generated in response to business modeling, and the parsing result includes execution tasks defined for multiple business processes, the execution order of execution tasks under each business process, and the forward API and reverse API defined for the execution tasks; from the parsing result, determining multiple target tasks required to be executed by the target business process, the execution order of multiple target tasks, and the forward API and reverse API defined for the target tasks.

[0146] In a possible implementation of the embodiment of the present disclosure, the traversal processing module 630 is specifically used to: traverse multiple ordered sub-transactions in sequence; determine whether the sub-transaction currently traversed is a local transaction and obtain a determination result; and process the sub-transaction currently traversed according to the determination result and the forward API and reverse API of the target task corresponding to the sub-transaction currently traversed.

[0147] In a possible implementation of the embodiment of the present disclosure, the traversal processing module 630 is specifically used to: when the judgment result indicates that the currently traversed subtransaction is a local transaction, start the currently traversed subtransaction and generate a subtransaction identifier for the currently traversed subtransaction; call the forward API of the target task corresponding to the currently traversed subtransaction, and execute the forward operation of the target task corresponding to the currently traversed subtransaction to complete the processing of the currently traversed subtransaction; when the currently traversed subtransaction is successfully processed, register the currently traversed subtransaction flow in the local memory based on the subtransaction identifier; wherein the subtransaction flow includes a flow number, output parameter information, and input parameter information.

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

[0149] The update module is called to call the reverse API of the target task corresponding to the currently traversed sub-transaction when the processing of the currently traversed sub-transaction fails, to cancel or roll back the forward operation of the target task; and to update the status of the main transaction flow in the local database to a failed status.

[0150] In a possible implementation of the embodiment of the present disclosure, the traversal processing module 630 is specifically used to: when the judgment result indicates that the currently traversed subtransaction is not a local transaction, commit the uncommitted and successfully processed local transaction; merge the subtransaction streams in the local memory, and register the merged subtransaction streams to the local database; register the currently traversed subtransaction stream to the local database; wherein the subtransaction stream includes a stream number; and call the forward API of the target task corresponding to the currently traversed subtransaction through a remote call method, and execute the forward operation of the target task corresponding to the currently traversed subtransaction to complete the processing of the currently traversed subtransaction.

[0151] In a possible implementation of the embodiment of the present disclosure, the end update module 640 is specifically used to: determine the end of the target business process execution when the last sub-transaction in multiple ordered sub-transactions is successfully processed; commit the currently opened local transaction; and update the status of the main transaction flow in the local database to a completed status.

[0152] In a possible implementation of the embodiment of the present disclosure, the registration module 620 is started, specifically for: generating a main transaction identifier corresponding to the main transaction; and registering the main transaction flow into the local database based on the main transaction identifier.

[0153] In a possible implementation of the embodiment of the present disclosure, the end update module 640 is specifically configured to update the status of the main transaction pipeline in the local database to a completed status based on the main transaction identifier.

[0154] In a possible implementation of the embodiment of the present disclosure, the distributed transaction processing device 600 is applied to a distributed transaction processing component, which is encapsulated with an SDK and executes the steps executed by any of the above modules based on the algorithm logic encapsulated in the SDK.

[0155] It should be noted that the distributed transaction processing device provided in the embodiment of the present disclosure can achieve the above Figures 1 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.

[0156] 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.

[0157] As an example, Figure 7 is a schematic diagram of the structure of an electronic device 700 shown in an exemplary embodiment of the present disclosure, such as Figure 7 As shown, the electronic device 700 may further include:

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

[0159] Bus 730 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.

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

[0161] The memory 710 may also include computer system readable media in the form of volatile memory, such as random access memory (RAM) 740 and / or cache memory 750. The server 700 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, the storage system 760 may be used to read and write non-removable, non-volatile magnetic media ( Figure 7 not shown, usually called a "hard drive"). Although Figure 7Not shown, 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 730 via one or more data medium interfaces. The memory 710 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.

[0162] A program / utility 780 having a set (at least one) of program modules 770 may be stored, for example, in the memory 710, such program modules 770 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 770 generally perform the functions and / or methods of the embodiments described in the present disclosure.

[0163] The electronic device 700 may also communicate with one or more external devices 790 (e.g., keyboard, pointing device, display 791, etc.), may also communicate with one or more devices that enable a user to interact with the electronic device 700, and / or communicate with any device that enables the electronic device 700 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 792. Furthermore, the electronic device 700 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 793. As shown, the network adapter 793 communicates with other modules of the electronic device 700 through a bus 730. 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 700, including but not limited to: microcode, device drivers, redundant processing units, external disk drive arrays, RAID systems, tape drives, and data backup storage systems.

[0164] The processor 720 executes various functional applications and data processing by running the programs stored in the memory 710 .

[0165] 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.

[0166] 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.

[0167] 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.

[0168] 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.

[0169] 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.

[0170] 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.

[0171] 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.

[0172] 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.

[0173] 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.

[0174] 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.

[0175] 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: In response to receiving a transaction request, determining a target business process corresponding to a transaction type of the transaction request; Based on the multiple target tasks required to be executed by the target business process, a main transaction of the distributed transaction is opened for the transaction request, and the main transaction flow is registered in the local database; wherein the main transaction includes multiple ordered sub-transactions, and each sub-transaction corresponds to a target task; Traversing the multiple ordered subtransactions in sequence, and processing the currently traversed subtransaction according to a determination result of whether the currently traversed subtransaction is a local transaction; In response to the multiple sub-transactions being successfully processed, the main transaction is terminated, and the status of the main transaction pipeline in the local database is updated to a completed status.

2. The method according to claim 1, characterized in that The multiple target tasks to be executed based on the target business process, opening a main transaction of a distributed transaction for the transaction request, includes: Acquire multiple target tasks and corresponding execution orders required for the target business process, as well as forward application programming interfaces (APIs) and reverse APIs defined for the target tasks; wherein the forward API is used to execute the forward operation of the target task, and the reverse API is used to cancel or roll back the forward operation of the target task; Based on the multiple target tasks and the corresponding execution order, forward API and reverse API, a main transaction of the distributed transaction is opened for the transaction request; The main transaction includes a plurality of ordered sub-transactions, each sub-transaction corresponds to a target task, and the arrangement order of the sub-transactions is determined according to the execution order of the corresponding target tasks.

3. The method according to claim 2, characterized in that The obtaining of the multiple target tasks required to be executed by the target business process and the corresponding execution order, as well as the forward API and reverse API defined for the target tasks, includes: Obtaining a parsing result obtained by parsing a business process definition file; wherein the business process definition file is generated in response to business modeling, and the parsing result includes execution tasks defined for multiple business processes, the execution order of the execution tasks under each of the business processes, and a forward API and a reverse API defined for the execution tasks; From the parsing result, a plurality of target tasks required to be executed by the target business process, an execution order of the plurality of target tasks, and a forward API and a reverse API defined for the target tasks are determined.

4. The method according to claim 2, characterized in that: The sequentially traversing the plurality of ordered subtransactions and processing the currently traversed subtransaction according to a result of determining whether the currently traversed subtransaction is a local transaction includes: Traversing the multiple ordered subtransactions in sequence; Determine whether the currently traversed subtransaction is a local transaction, and obtain the determination result; The sub-transaction currently being traversed is processed according to the judgment result and the forward API and reverse API of the target task corresponding to the sub-transaction currently being traversed.

5. The method according to claim 4, characterized in that The processing of the currently traversed subtransaction according to the judgment result and the forward API and the reverse API of the target task corresponding to the currently traversed subtransaction includes: In a case where the judgment result indicates that the subtransaction currently traversed is a local transaction, starting the subtransaction currently traversed, and generating a subtransaction identifier for the subtransaction currently traversed; Calling the forward API of the target task corresponding to the currently traversed subtransaction, executing the forward operation of the target task corresponding to the currently traversed subtransaction, so as to complete the processing of the currently traversed subtransaction; In the case that the currently traversed sub-transaction is processed successfully, based on the sub-transaction identifier, the currently traversed sub-transaction flow is registered in the local memory; wherein the sub-transaction flow includes a flow number, output parameter information, and input parameter information.

6. The method according to claim 5, characterized in that The method further comprises: In the case that the processing of the currently traversed sub-transaction fails, calling the reverse API of the target task corresponding to the currently traversed sub-transaction to cancel or roll back the forward operation of the target task; The status of the main transaction pipeline in the local database is updated to a failed status.

7. The method according to claim 4, characterized in that The processing of the currently traversed subtransaction according to the judgment result and the forward API and the reverse API of the target task corresponding to the currently traversed subtransaction includes: If the judgment result indicates that the currently traversed subtransaction is not a local transaction, committing the uncommitted and successfully processed local transaction; Merging the sub-transaction flows in the local memory, and registering the merged sub-transaction flows in the local database; Registering the sub-transaction sequence currently traversed into the local database; wherein the sub-transaction sequence includes a sequence number; By remote calling, the forward API of the target task corresponding to the currently traversed sub-transaction is called, and the forward operation of the target task corresponding to the currently traversed sub-transaction is executed to complete the processing of the currently traversed sub-transaction.

8. The method according to claim 1, characterized in that In response to the multiple sub-transactions being successfully processed, ending the main transaction and updating the status of the main transaction flow in the local database to a completed status, comprises: When the last subtransaction in the plurality of ordered subtransactions is successfully processed, determining that the execution of the target business process is completed; Commit the currently opened local transaction; The status of the main transaction pipeline in the local database is updated to a completed status.

9. The method according to claim 1, characterized in that: The registering the main transaction flow into the local database includes: Generate a main transaction identifier corresponding to the main transaction; Based on the main transaction identifier, register the main transaction flow into the local database; The updating the status of the main transaction flow in the local database to a completed status includes: Based on the main transaction identifier, the status of the main transaction pipeline in the local database is updated to a completed status.

10. The method according to any one of claims 1 to 9, characterized in that The method is executed by a distributed transaction processing component, which is encapsulated with a software development kit SDK. Based on the algorithm logic encapsulated in the SDK, the method described in any one of claims 1 to 9 is executed.

Citation Information

Patent Citations

  • Distributed transaction processing method and system, transaction manager and terminal device

    CN108958894A

  • Cross-node data processing method and device

    CN110287267A

  • Distributed transaction processing method and device

    CN113760924A

  • Distributed transaction processing method and device, electronic equipment and storage medium

    CN117971401A