SAGA-based distributed transaction implementation method and device
By binding the SAGA transaction coordinator to the composition service, coordinating distributed transactions and employing a compensation mechanism, the performance pressure caused by independently deploying the transaction coordinator is resolved, achieving efficient distributed transaction processing and data consistency.
Patent Information
- Application Number
- CN202111621008.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-27
- Publication Date
- 2025-12-23
- Estimated Expiration
- 2041-12-27
AI Technical Summary
In existing technologies, independently deployed transaction coordinators lead to high server performance pressure in distributed microservice architectures, and non-functional guarantees such as high availability and high performance need to be considered.
By binding the SAGA transaction coordinator with the composition service to form a bound composition service, the distributed transaction-related layer operations are coordinated, and anomalies are handled through a compensation mechanism, including immediate compensation, post-event recovery, and manual intervention mechanisms, thus avoiding the performance pressure of deploying a separate transaction coordinator.
It solves the problem of high performance pressure on distributed transaction coordinator servers, reduces the reliance on high availability and high performance, and improves transaction processing efficiency and data consistency.
Smart Images

Figure CN114327796B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of computer software, and more specifically, to a method, apparatus, computer-readable storage medium, and processor for implementing distributed transactions based on SAGA. Background Technology
[0002] In a distributed microservice architecture, a single transaction spans multiple applications, each holding its own database. How to ensure that the data under the operation of multiple applications can all succeed or all fail is a problem that distributed transactions need to solve. The current mainstream distributed transaction framework in the SAGA pattern is servicecomb-saga.
[0003] ServiceComb-Saga is a data eventual consistency solution for microservice applications. It's a framework based on both 2PC and TCC, essentially a TCC approach that relies on a coordinator. In ServiceComb-Saga, Alpha acts as the coordinator, primarily responsible for persistently storing transaction events and coordinating the state of sub-transactions to ensure they eventually remain consistent with the global transaction state. Omega is an embedded agent within the microservice, responsible for intercepting network requests, reporting transaction events to Alpha, and performing appropriate compensation operations based on Alpha's instructions in case of anomalies.
[0004] The servicecomb-saga pattern requires a separately deployed transaction coordinator service. When a large number of transactions occur, each transaction needs to interact with the transaction coordinator, which puts a heavy performance load on the transaction coordinator server and may lead to performance bottlenecks. Furthermore, the transaction coordinator needs to be deployed independently, and its high availability and high performance must also be considered. Summary of the Invention
[0005] The main objective of this application is to provide a method, apparatus, computer-readable storage medium, and processor for implementing distributed transactions based on SAGA, in order to solve the problem that the independent deployment of transaction coordinators in the prior art results in high server performance pressure.
[0006] To achieve the above objectives, according to one aspect of this application, a distributed transaction implementation method based on SAGA is provided, comprising: binding an SAGA transaction coordinator to a composition service to obtain a bound composition service, wherein the SAGA transaction coordinator is used to coordinate the distributed transaction-related layer operations of the composition service and to monitor transactions; and executing distributed transactions using the bound composition service.
[0007] Furthermore, the combined service includes multiple atomic services. Executing a distributed transaction using the bound combined service includes: determining whether an abnormal situation has occurred, the abnormal situation including at least one of the following: the atomic service returning an error code, the atomic service not returning an error, and the combined service being abnormal; if the abnormal situation occurs, triggering a compensation operation using the SAGA transaction coordinator in the bound combined service to compensate for the abnormal situation; and determining that the distributed transaction was successfully executed if all the abnormal situations are successfully compensated.
[0008] Furthermore, in the event of the aforementioned abnormal situation, the SAGA transaction coordinator in the binding combination service is used to trigger a compensation operation to compensate for the abnormal situation, including: in the event of the aforementioned abnormal situation, triggering an immediate compensation mechanism to compensate for the abnormal situation; in the event of immediate compensation failure, triggering a post-event recovery mechanism to compensate for the abnormal situation; in the event of post-event recovery failure, triggering a manual intervention mechanism to compensate for the abnormal situation.
[0009] Furthermore, the execution status of the atomic service is stored in the sub-transaction register. In the event of the abnormal situation, an instant compensation mechanism is triggered to compensate for the abnormal situation, including: in the event of the abnormal situation, querying the sub-transaction register in reverse order and obtaining the compensation service corresponding to each atomic service; and using the compensation service to compensate the atomic service.
[0010] Furthermore, the method further includes compensating the atomic service using the compensation service, and then updating the sub-transaction register based on the first compensation result.
[0011] Furthermore, the execution status of the combined service is stored in the main transaction register. In the event of failure of immediate compensation, a post-event recovery mechanism is triggered to compensate for the abnormal situation, including: in the event of failure of immediate compensation, copying the combined service that was not completed normally from the main transaction register to the transaction register to be compensated; sequentially reading the combined services in the transaction register to be compensated, and compensating the atomic services in each of the combined services.
[0012] Furthermore, after sequentially reading the combined services in the transaction register to be compensated and compensating the atomic services in each of the combined services, the method further includes: updating the master transaction register and the transaction register to be compensated based on the second compensation result.
[0013] According to another aspect of this application, an SAGA-based distributed transaction implementation apparatus is provided, comprising: a binding unit for binding an SAGA transaction coordinator to a composition service to obtain a bound composition service, wherein the SAGA transaction coordinator is used to coordinate the distributed transaction-related layer operations of the composition service and to monitor transactions; and an execution unit for executing distributed transactions using the bound composition service.
[0014] According to another aspect of this application, a computer-readable storage medium is provided, the computer-readable storage medium including a stored program, wherein, when the program is executed, it controls the device on which the computer-readable storage medium is located to perform any of the methods described.
[0015] According to another aspect of this application, a processor is provided for running a program, wherein the program, when running, performs any of the methods described.
[0016] In the SAGA-based distributed transaction implementation method of this application, firstly, the SAGA transaction coordinator is bound to a composition service to obtain a bound composition service. The SAGA transaction coordinator is used to coordinate the distributed transaction-related layer operations of the composition service and to monitor transactions. Then, the bound composition service is used to execute distributed transactions. Binding the SAGA transaction coordinator to the composition service to obtain the bound composition service and execute distributed transactions eliminates the need for a separate transaction coordinator deployment. This solves the problem of high performance pressure on the transaction coordinator server caused by each transaction needing to interact with the transaction coordinator when a large number of transactions occur, and it also eliminates the need to consider non-functional guarantees such as high availability and high performance when the transaction coordinator is deployed independently. Attached Figure Description
[0017] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:
[0018] Figure 1 A schematic flowchart of a distributed transaction implementation method based on SAGA, according to an embodiment of this application, is shown.
[0019] Figure 2 A schematic diagram of a distributed transaction implementation apparatus based on SAGA, according to an embodiment of this application, is shown.
[0020] Figure 3 A flowchart illustrating the distributed transaction execution process in an embodiment of this application is shown;
[0021] Figure 4 A compensation flowchart is shown in an embodiment of this application. Detailed Implementation
[0022] It should be noted that, unless otherwise specified, the embodiments and features described in this application can be combined with each other. This application will now be described in detail with reference to the accompanying drawings and embodiments.
[0023] To enable those skilled in the art to better understand the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present application, and not all embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative effort should fall within the scope of protection of the present application.
[0024] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this application are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate for the embodiments of this application described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0025] It should be understood that when an element (such as a layer, film, region, or substrate) is described as being "on" another element, the element may be directly on the other element, or there may be an intermediate element present. Furthermore, in the specification and claims, when an element is described as being "connected" to another element, the element may be "directly connected" to the other element, or "connected" to the other element via a third element.
[0026] For ease of description, the following explains some of the nouns or terms used in the embodiments of this application:
[0027] SAGA is a long-lived transaction that can be decomposed into a set of interleaved subtransactions. Each subtransaction is a real transaction that maintains database consistency. If a local transaction fails because some business rules cannot be satisfied, SAGA will execute compensatory operations on all transactions that were successfully committed before the failed transaction.
[0028] A transaction generally refers to something that needs to be done or has been done. In computer terminology, it refers to a unit of program execution that accesses and may update various data items in a database. Transactions are typically initiated by the execution of user programs written in high-level database manipulation languages or programming languages (such as SQL, C++, or Java) and are delimited by statements (or function calls) in the form of begintransaction and endtransaction. A transaction consists of all the operations performed between the start (begintransaction) and end (end) points.
[0029] Composite services: Based on service orchestration, add general pre-processing logic and general post-processing logic, which can be deployed independently.
[0030] Distributed transactions refer to transactions where the participants, supporting servers, resource servers, and transaction managers reside on different nodes within a distributed system. Simply put, a large operation consists of smaller operations distributed across different servers and belonging to different applications. Distributed transactions must ensure that these smaller operations either all succeed or all fail.
[0031] Atomic service: A service used to implement a specific business logic, which can be deployed independently.
[0032] According to an embodiment of this application, a distributed transaction implementation method based on SAGA is provided.
[0033] Figure 1 This is a flowchart of a SAGA-based distributed transaction implementation method according to an embodiment of this application. Figure 1 As shown, the method includes the following steps:
[0034] Step S101: Bind the SAGA transaction coordinator to the composite service to obtain the bound composite service. The SAGA transaction coordinator is used to coordinate the distributed transaction-related layer operations of the composite service and to monitor transactions.
[0035] Step S102: Execute distributed transactions using the above-mentioned binding combination service.
[0036] The SAGA-based distributed transaction implementation method described above first binds the SAGA transaction coordinator to the composition service, resulting in a bound composition service. The SAGA transaction coordinator coordinates the distributed transaction-related layer operations of the composition service and monitors transactions. Then, the bound composition service is used to execute the distributed transaction. Binding the SAGA transaction coordinator to the composition service to obtain the bound composition service and execute distributed transactions eliminates the need for a separate transaction coordinator deployment. This solves the performance pressure problem of independently deployed transaction coordinators, where each transaction needs to interact with the coordinator during a large number of transactions, leading to high performance pressure on the transaction coordinator server. Furthermore, it eliminates the need to consider non-functional guarantees such as high availability and high performance required when deploying a separate transaction coordinator.
[0037] It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases the steps shown or described may be executed in a different order than that shown here.
[0038] In one specific embodiment of this application, the SAGA transaction coordinator described above can be bound to a composition service in the form of an SDK to obtain a bound composition service, and then execute distributed transactions.
[0039] In one embodiment of this application, the aforementioned combined service includes multiple atomic services. Executing a distributed transaction using the aforementioned bound combined service includes: determining whether an abnormal situation has occurred, wherein the abnormal situation includes at least one of the following: the atomic service returning an error code, the atomic service not returning an error, and the combined service experiencing an abnormality; if the abnormal situation occurs, triggering a compensation operation using the SAGA transaction coordinator in the aforementioned bound combined service to compensate for the abnormal situation; and determining that the distributed transaction has been successfully executed if all the above-mentioned abnormal situations have been successfully compensated. The distributed transaction execution process is as follows: Figure 3 As shown in the diagram. In the above abnormal situations, the atomic service returning an error code indicates that the distributed transaction failed to execute successfully. If the atomic service does not return an error code, it indicates that the distributed transaction timed out. The SAGA transaction coordinator can compensate for abnormal situations encountered by the atomic service, ensuring that the distributed transaction can execute successfully.
[0040] In another embodiment of this application, in the event of the aforementioned abnormal situation, the SAGA transaction coordinator in the aforementioned binding combination service triggers a compensation operation to compensate for the abnormal situation. This includes: triggering an immediate compensation mechanism to compensate for the abnormal situation when the aforementioned abnormal situation occurs; triggering a post-event recovery mechanism to compensate for the abnormal situation when immediate compensation fails; and triggering a manual intervention mechanism to compensate for the abnormal situation when post-event recovery fails. The SAGA transaction coordinator's compensation mechanism for abnormal situations includes three parts: an immediate compensation mechanism, a post-event recovery mechanism, and a manual intervention mechanism. These three compensation mechanisms can ensure the consistency of transaction data.
[0041] In another embodiment of this application, such as Figure 4 As shown, the execution status of the aforementioned atomic services is stored in the sub-transaction register. In the event of the aforementioned abnormal situation, an immediate compensation mechanism is triggered to compensate for the abnormality. This includes: querying the sub-transaction register in reverse order and obtaining the compensation service corresponding to each of the aforementioned atomic services; and using the compensation service to compensate the aforementioned atomic services. When an abnormal situation occurs, the SAGA transaction coordinator can obtain the compensation service corresponding to the atomic service from the transaction register, enabling rapid compensation for the abnormal situation.
[0042] To maintain data accuracy and prevent compensation execution failure, in one embodiment of this application, the aforementioned compensation service is used to compensate the aforementioned atomic service. Afterwards, the method further includes: updating the aforementioned sub-transaction register based on the first compensation result, such as... Figure 4 As shown.
[0043] In another embodiment of this application, such as Figure 4 As shown, the execution status of the aforementioned combined services is stored in the main transaction register. In the event of failure of immediate compensation, a post-event recovery mechanism is triggered to compensate for the aforementioned anomaly. This includes: copying the incomplete combined services from the main transaction register to the transaction register to be compensated; sequentially reading the combined services in the transaction register to be compensated, and compensating for the atomic services within each of the combined services. The post-event recovery mechanism, in the event of failure of immediate compensation, copies the incomplete combined services from the main transaction register to the transaction register to be compensated, and sequentially reads the atomic services within the combined services in the transaction register to be compensated for compensation. This mechanism further accelerates the speed of compensating for anomalies.
[0044] Similarly, to further maintain data accuracy and prevent compensation execution failure, in another embodiment of this application, after sequentially reading the aforementioned combined services in the transaction register to be compensated and compensating the aforementioned atomic services in each of the aforementioned combined services, the method further includes: updating the aforementioned master transaction register and the aforementioned transaction register to be compensated based on the second compensation result, such as... Figure 4 As shown.
[0045] This application also provides a distributed transaction implementation apparatus based on SAGA. It should be noted that the SAGA-based distributed transaction implementation apparatus of this application can be used to execute the SAGA-based distributed transaction implementation method provided in this application. The SAGA-based distributed transaction implementation apparatus provided in this application will be described below.
[0046] Figure 2 This is a schematic diagram of a distributed transaction implementation device based on SAGA according to an embodiment of this application. Figure 2 As shown, the device includes:
[0047] Binding unit 10 is used to bind the SAGA transaction coordinator to the composition service to obtain the bound composition service. The SAGA transaction coordinator is used to coordinate the distributed transaction-related layer operations of the composition service and to monitor transactions.
[0048] Execution unit 20 is used to execute distributed transactions using the aforementioned binding combination service.
[0049] The aforementioned SAGA-based distributed transaction implementation device binds the SAGA transaction coordinator to the composition service through the binding unit, resulting in a bound composition service. The SAGA transaction coordinator coordinates the distributed transaction-related layer operations of the composition service and monitors transactions. The execution unit then executes the distributed transaction using the bound composition service. Binding the SAGA transaction coordinator to the composition service to obtain the bound composition service and execute distributed transactions eliminates the need for a separate transaction coordinator deployment. This solves the performance pressure problem of independently deployed transaction coordinators, where each transaction needs to interact with the coordinator during a large number of transactions, leading to high performance pressure on the transaction coordinator server. Furthermore, it eliminates the need to consider non-functional guarantees such as high availability and high performance required when deploying a separate transaction coordinator.
[0050] In one specific embodiment of this application, the SAGA transaction coordinator described above can be bound to a composition service in the form of an SDK to obtain a bound composition service, and then execute distributed transactions.
[0051] In one embodiment of this application, the aforementioned combined service includes multiple atomic services, and the aforementioned execution unit includes a first determining subunit, a compensation subunit, and a second determining subunit. The first determining subunit is used to determine whether an abnormal situation has occurred, including at least one of the following: the atomic service returning an error code, the atomic service not returning an error, and the combined service experiencing an abnormality. The compensation subunit is used to compensate for the abnormal situation by triggering a compensation operation using the SAGA transaction coordinator in the aforementioned bound combined service if the abnormal situation occurs. The second determining subunit is used to determine that the distributed transaction has been successfully executed if all the aforementioned abnormal situations have been successfully compensated. The distributed transaction execution process is as follows: Figure 3 As shown in the diagram. In the above abnormal situations, the atomic service returning an error code indicates that the distributed transaction failed to execute successfully. If the atomic service does not return an error code, it indicates that the distributed transaction timed out. The SAGA transaction coordinator can compensate for abnormal situations encountered by the atomic service, ensuring that the distributed transaction can execute successfully.
[0052] In another embodiment of this application, the aforementioned compensation subunit includes a first compensation module, a second compensation module, and a third compensation module. The first compensation module is used to trigger an immediate compensation mechanism to compensate for the aforementioned abnormal situation when it occurs. The second compensation module is used to trigger a post-event recovery mechanism to compensate for the aforementioned abnormal situation when immediate compensation fails. The third compensation module is used to trigger a manual intervention mechanism to compensate for the aforementioned abnormal situation when post-event recovery fails. The SAGA transaction coordinator's compensation mechanism for abnormal situations includes three parts: an immediate compensation mechanism, a post-event compensation mechanism, and a manual intervention mechanism. These three compensation mechanisms can ensure the consistency of transaction data.
[0053] In another embodiment of this application, such as Figure 4 As shown, the execution status of the aforementioned atomic services is stored in the sub-transaction register. The first compensation module includes an acquisition sub-module and a first compensation sub-module. The acquisition sub-module is used to query the sub-transaction register in reverse order and obtain the compensation service corresponding to each of the aforementioned atomic services in the event of the aforementioned abnormal situation. The first compensation sub-module is used to compensate the aforementioned atomic services using the compensation services. In the event of an abnormal situation, the SAGA transaction coordinator can obtain the compensation service corresponding to the atomic service from the transaction register, enabling rapid compensation for the abnormal situation.
[0054] To maintain data accuracy and prevent compensation execution failure, in one embodiment of this application, the compensation submodule further includes updating the sub-transaction register based on the first compensation result, such as... Figure 4 As shown.
[0055] In another embodiment of this application, such as Figure 4 As shown, the execution status of the aforementioned combined services is stored in the main transaction register. The second compensation module includes a copy submodule and a second compensation submodule. The copy submodule is used to copy the incomplete combined services from the main transaction register to the transaction register to be compensated in the event of immediate compensation failure. The second compensation submodule is used to sequentially read the combined services in the transaction register to be compensated and compensate the atomic services within each of the combined services. The post-event recovery mechanism, in the event of immediate compensation failure, copies the incomplete combined services from the main transaction register to the transaction register to be compensated and sequentially reads the atomic services within the combined services in the transaction register to be compensated for compensation. This mechanism further accelerates the speed of compensation for abnormal situations.
[0056] Similarly, to further maintain data accuracy and prevent compensation execution failure, in another embodiment of this application, the second compensation submodule further includes updating the master transaction register and the transaction register to be compensated based on the second compensation result, such as... Figure 4 As shown.
[0057] The aforementioned SAGA-based distributed transaction implementation device includes a processor and a memory. The aforementioned binding unit and execution unit are all stored in the memory as program units, and the processor executes the aforementioned program units stored in the memory to implement the corresponding functions.
[0058] The processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and adjusting kernel parameters can address the issue of excessive server performance pressure caused by independently deploying a transaction coordinator in existing technologies.
[0059] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0060] This invention provides a computer-readable storage medium that includes a stored program, wherein, when the program is executed, it controls the device where the computer-readable storage medium is located to execute the SAGA-based distributed transaction implementation method.
[0061] This invention provides a processor for running a program, wherein the program executes the SAGA-based distributed transaction implementation method.
[0062] This invention provides a device including a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs at least the following steps:
[0063] Step S101: Bind the SAGA transaction coordinator to the composite service to obtain the bound composite service. The SAGA transaction coordinator is used to coordinate the distributed transaction-related layer operations of the composite service and to monitor transactions.
[0064] Step S102: Execute distributed transactions using the above-mentioned binding combination service.
[0065] The devices mentioned in this article can be servers, PCs, tablets, mobile phones, etc.
[0066] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program having at least the following method steps:
[0067] Step S101: Bind the SAGA transaction coordinator to the composite service to obtain the bound composite service. The SAGA transaction coordinator is used to coordinate the distributed transaction-related layer operations of the composite service and to monitor transactions.
[0068] Step S102: Execute distributed transactions using the above-mentioned binding combination service.
[0069] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product embodied on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.
[0070] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart... Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0071] These computer program instructions may also be stored in a computer-readable storage medium that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the computer-readable storage medium produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0072] These computer program instructions may also be loaded onto a computer or other programmable data processing equipment to cause a series of operational steps to be performed on the computer or other programmable equipment to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable equipment for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0073] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0074] Memory may include non-persistent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM. Memory is an example of computer-readable media.
[0075] Computer-readable media includes both permanent and non-permanent, removable and non-removable media that can store information using any method or technology. Information can be computer-readable instructions, data structures, modules of programs, or other data. Examples of computer storage media include, but are not limited to, phase-change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technologies, CD-ROM, digital versatile optical disc (DVD) or other optical storage, magnetic tape, magnetic magnetic disk storage or other magnetic storage devices, or any other non-transferable medium that can be used to store information accessible by a computing device. As defined herein, computer-readable media does not include transient computer-readable media, such as modulated data signals and carrier waves.
[0076] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element.
[0077] As can be seen from the above description, the embodiments of this application achieve the following technical effects:
[0078] 1) The SAGA-based distributed transaction implementation method of this application first binds the SAGA transaction coordinator to the composition service to obtain the bound composition service. The SAGA transaction coordinator is used to coordinate the distributed transaction-related layer operations of the composition service and to monitor transactions. Then, the bound composition service is used to execute distributed transactions. Binding the SAGA transaction coordinator to the composition service to obtain the bound composition service and execute distributed transactions does not require a separate transaction coordinator deployment. This solves the problem of high performance pressure on the transaction coordinator server caused by each transaction needing to interact with the transaction coordinator when a large number of transactions occur, and it also eliminates the need to consider non-functional guarantees such as high availability and high performance when the transaction coordinator is deployed independently.
[0079] 2) The SAGA-based distributed transaction implementation apparatus of this application binds the SAGA transaction coordinator to the composition service through the binding unit to obtain the bound composition service. The SAGA transaction coordinator is used to coordinate the distributed transaction-related layer operations of the composition service and to monitor transactions. Then, the execution unit executes the distributed transaction using the bound composition service. Binding the SAGA transaction coordinator to the composition service to obtain the bound composition service and execute distributed transactions eliminates the need for a separate transaction coordinator deployment. This solves the problem of high performance pressure on the transaction coordinator server caused by each transaction needing to interact with the transaction coordinator when a large number of transactions occur, and it also eliminates the need to consider non-functional guarantees such as high availability and high performance when the transaction coordinator is deployed independently.
[0080] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. A distributed transaction implementation method based on SAGA, characterized in that, include: The SAGA transaction coordinator is bound to the composition service to obtain the bound composition service. The SAGA transaction coordinator is used to coordinate the distributed transaction-related layer operations of the composition service and to monitor transactions. Distributed transactions are executed using the aforementioned binding combination service; The combined service includes multiple atomic services, and the distributed transaction is executed using the bound combined service, including: Determine if any abnormal situation has occurred, including at least one of the following: the atomic service returns an error code, the atomic service does not return an error, and the combined service is abnormal; if any of the abnormal situations occur, use the SAGA transaction coordinator in the bound combined service to trigger a compensation operation to compensate for the abnormal situation; if all the abnormal situations are successfully compensated, determine that the distributed transaction has been executed successfully. In the event of the aforementioned abnormal situation, the SAGA transaction coordinator in the binding combination service is used to trigger a compensation operation to compensate for the abnormal situation, including: triggering an immediate compensation mechanism to compensate for the abnormal situation when the abnormal situation occurs; triggering a post-event recovery mechanism to compensate for the abnormal situation when immediate compensation fails; and triggering a manual intervention mechanism to compensate for the abnormal situation when post-event recovery fails.
2. The method according to claim 1, characterized in that, The execution status of the atomic service is stored in the sub-transaction register. In the event of the aforementioned abnormal situation, an immediate compensation mechanism is triggered to compensate for the abnormal situation, including: In the event of the aforementioned abnormal situation, the sub-transaction register is queried in reverse order, and the compensation service corresponding to each atomic service is obtained; The compensation service is used to compensate the atomic service.
3. The method according to claim 2, characterized in that, The method further includes compensating the atomic service using the compensation service, and then: Update the sub-transaction register based on the first compensation result.
4. The method according to claim 1, characterized in that, The execution status of the combined service is stored in the main transaction register. In the event of failure of immediate compensation, a post-event recovery mechanism is triggered to compensate for the abnormal situation, including: In the event of failure of the immediate compensation, the combined service that was not completed normally is copied from the master transaction register to the transaction register to be compensated; The combined services in the register of transactions to be compensated are read sequentially, and the atomic services in each of the combined services are compensated.
5. The method according to claim 4, characterized in that, After sequentially reading the combined services in the register of transactions to be compensated, and compensating the atomic services in each of the combined services, the method further includes: Based on the second compensation result, update the master transaction register and the transaction register to be compensated.
6. A distributed transaction implementation device based on SAGA, characterized in that, include: The binding unit binds the SAGA transaction coordinator to the composition service to obtain the bound composition service. The SAGA transaction coordinator is used to coordinate the distributed transaction-related layer operations of the composition service and also plays a role in monitoring transactions. An execution unit is used to execute distributed transactions using the binding combination service; The combined service includes multiple atomic services. The execution unit includes a first determining subunit, a compensation subunit, and a second determining subunit. The first determining subunit is used to determine whether an abnormal situation has occurred. The abnormal situation includes at least one of the following: the atomic service returns an error code, the atomic service does not return an error, and the combined service is abnormal. The compensation subunit is used to compensate for the abnormal situation by triggering a compensation operation using the SAGA transaction coordinator in the bound combined service when the abnormal situation occurs. The second determining subunit is used to determine that the distributed transaction has been successfully executed if all the abnormal situations have been successfully compensated. The compensation subunit includes a first compensation module, a second compensation module, and a third compensation module. The first compensation module is used to trigger an immediate compensation mechanism to compensate for the abnormal situation when the abnormal situation occurs. The second compensation module is used to trigger a post-event recovery mechanism to compensate for the abnormal situation when the immediate compensation fails. The third compensation module is used to trigger a manual intervention mechanism to compensate for the abnormal situation when the post-event recovery fails.
7. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, wherein, when the program is executed, it controls the device on which the computer-readable storage medium is located to perform the method according to any one of claims 1 to 5.
8. A processor, characterized in that, The processor is used to run a program, wherein the program executes the method according to any one of claims 1 to 5 when it runs.
Citation Information
Patent Citations
Distributed transaction processing method based on Saga mode
CN111209092A
Instance processing and calling method, device and system and storage medium
CN111240868A