Distributed transaction processing method, apparatus and medium based on independent transaction coordinator
By adopting a distributed transaction processing method based on an independent transaction coordinator, the atomicity, consistency, and isolation issues of transaction processing in a distributed environment are solved, achieving high availability and data consistency, and reducing failure rate and development cost.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-24
- Publication Date
- 2026-03-06
AI Technical Summary
In a distributed environment, traditional single-machine database transactions cannot guarantee atomicity, consistency, and isolation. Existing XA two-phase commit and three-phase commit protocols suffer from synchronous blocking, single point of failure, and data inconsistency issues.
A distributed transaction processing method based on an independent transaction coordinator is adopted. The transaction coordinator monitors and manages the distributed system, uses the Raft protocol for log data storage, and automatically commits transactions using TCC and SAGA modes. Resource lock control and data consistency are achieved by annotating transaction resources.
It reduces the failure rate of distributed transaction processing, avoids single points of failure and long-term synchronization blocking, achieves eventual data consistency and non-intrusive business logic, and reduces development costs.
Smart Images

Figure CN114528073B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of computer technology, and in particular to a distributed transaction processing method, apparatus and medium based on an independent transaction coordinator. Background Technology
[0002] With the rapid growth in traffic and data volume, microservices, SOA, and database sharding are being widely adopted. To complete a business function, it may be necessary to span multiple services or multiple data nodes. The handling of transactions inevitably faces the following challenges:
[0003] 1. Atomicity cannot be guaranteed. Atomicity in a transaction is an indivisible unit. In a distributed environment, traditional single-machine database transactions cannot ensure that operations across multiple service nodes either all succeed or all fail.
[0004] 2. Inability to guarantee consistency: Traditional single-machine database transactions can only guarantee the data consistency of business logic on a single node. They cannot guarantee that the intermediate state of business data on multiple nodes in a distributed environment is unobservable. Therefore, there is a possibility of reading dirty data, which can lead to data inconsistency.
[0005] 3. Isolation cannot be guaranteed. Transaction isolation of traditional single-machine databases can only be applied to a single database. In a distributed environment, there are multiple nodes and multiple databases coexisting, so it is impossible to control the global security isolation of the data used during concurrency.
[0006] To address the inability of traditional single-machine database transactions to handle distributed transactions in a distributed environment, current solutions mainly include:
[0007] 1. Reference Figure 1 The XA protocol, based on two-phase commit (2PC), establishes a communication bridge between the transaction manager and one or more resource managers by defining an interface between them. The transaction manager controls the global transaction, manages its lifecycle, and coordinates multiple resources (such as databases and queues) to prepare in the first phase and commit or rollback in the second phase. XA two-phase commit suffers from a synchronous blocking problem: when one participant node experiences a communication timeout, the remaining participants are passively blocked, occupying resources that cannot be released.
[0008] 2. Reference Figure 2 The system uses a three-phase commit (3PC) approach, an optimization proposed to address the shortcomings of two-phase commit. It introduces timeout mechanisms for both the coordinator and participants, and inserts a preparation phase between the first and second phases of the two-phase commit (2PC) to ensure that the state of all participating nodes is consistent before the final commit phase.
[0009] 3. Reference Figure 3 Using the Flexible Transactions Controlled Confirmation (TCC) two-phase compensation pattern, it is stipulated that all transaction participants must implement three interfaces: try, confirm, and cancel. The try interface attempts to execute the transaction, completes business checks, and reserves necessary resources; the confirm interface actually executes the business logic without checking business resources; and the cancel interface releases the business resources reserved in the try phase.
[0010] The disadvantages of existing technology are:
[0011] 1. XA two-phase commit has a synchronous blocking problem. When a participant node experiences a communication timeout, the other participants will be passively blocked and occupy resources that cannot be released.
[0012] 2. XA two-phase commit has a single point of failure problem. When the coordinator fails during the two-phase commit process, the participants (RMs) will be locked and blocked, unable to continue to complete the transaction operation.
[0013] 3. The XA two-phase commit protocol suffers from data inconsistency. In phase two of the two-phase commit, after the coordinator sends the commit request to the participants, a local network anomaly occurs, resulting in only a portion of the participants receiving the commit request. These participants execute the commit operation upon receiving the request. However, the other machines that did not receive the commit request are unable to commit the transaction. This leads to data inconsistency in the entire distributed system.
[0014] 4. The data inconsistency problem of the three-phase commit protocol (3PC) still exists. When a participant receives the preCommit request and waits for the doCommit instruction, if the coordinator requests to interrupt the transaction and the coordinator cannot communicate normally with the participant, the participant will continue to commit the transaction, resulting in data inconsistency. Summary of the Invention
[0015] The main objective of this invention is to propose a distributed transaction processing method, apparatus, and medium based on an independent transaction coordinator, thereby reducing the failure rate of distributed transaction processing.
[0016] One aspect of the present invention provides: 1. A distributed transaction processing method based on an independent transaction coordinator, characterized in that it includes:
[0017] Create clusters, each cluster including a corresponding transaction coordinator, through which log data generated in the distributed system is stored, and the distributed system is monitored;
[0018] The SDK enables the definition of transaction boundaries, registration of transaction branches, registration of transaction resources, and management of global transaction locks in a distributed system. It also allows querying and reporting of transaction resources in the distributed system upon request.
[0019] The transaction is committed automatically.
[0020] According to the distributed transaction processing method based on an independent transaction coordinator, a cluster is created, each cluster including a corresponding transaction coordinator. The transaction coordinator stores the log data generated in the distributed system. Monitoring the distributed system includes: storing log data based on the Raft protocol, forming a stateful cluster with at least three odd-numbered nodes, and synchronizing transaction messages between clusters through log replication; or forming a stateless cluster with more than one node, and performing centralized storage of the logs through the stateless cluster; and monitoring resources, JVM parameters, network, and transaction execution status in the distributed system, while simultaneously connecting to a monitoring and early warning platform to monitor the running status of the transaction coordinator in real time.
[0021] According to the distributed transaction processing method based on an independent transaction coordinator, the transaction coordinator is an independent process, and the nodes of the transaction coordinator belong to a cluster, and a cluster belongs to a service group.
[0022] According to the distributed transaction processing method based on an independent transaction coordinator, the process of defining transaction boundaries, registering transaction branches, registering transaction resources and managing global transaction locks in the distributed system, and querying and reporting the transaction resources of the distributed system according to a request, further includes: automatically scanning all the transaction resources of the distributed system according to a request, and coordinating each transaction resource to perform corresponding processing when the global transaction reaches the commit or rollback stage.
[0023] According to the distributed transaction processing method based on an independent transaction coordinator, the automatic execution of transaction commit includes: generating a corresponding data mirror query statement based on the database operation request received by the transaction resource; using the data mirror query statement to query the data before the operation request and saving the data before the operation request; after the data before the operation request is saved, executing the operation request; and subsequently querying and saving the data after the operation request is saved, and executing the local commit of the branch transaction; when the branch transaction receives a notification of global transaction commit, deleting the data before and after the operation request is executed, the deletion method can be asynchronous; when a global rollback request is received, the transaction resource of the branch transaction queries whether the data in the current database is consistent with the data recorded in the data after the operation request through the mirror query statement. If they are consistent, the data before the operation request is used to roll back the relevant data; otherwise, an alarm is triggered. The global transaction includes multiple branch transactions.
[0024] According to the distributed transaction processing method based on an independent transaction coordinator, the transaction commit also includes adopting the TCC mode. The TCC mode includes: annotating TCC transaction resources by adding annotations before methods during business code; scanning the annotation during application startup and registering the transaction branch resource through the transaction coordinator; when initiating a global transaction and calling the transaction branch resource, recognizing the annotation and registering the transaction branch information according to the annotation; when the transaction corresponding to the business executes the commit or rollback phase, initiating the commit or rollback of the transaction branch; when the transaction resource manager receives the branch commit or rollback request, it coordinates the TCC transaction resource to perform the corresponding processing.
[0025] According to the distributed transaction processing method based on an independent transaction coordinator, the transaction commit also includes adopting the SAGA mode. The SAGA mode includes: adding annotations to the method to mark SAGA transaction resources during business coding; scanning the annotation during application startup and registering the transaction branch resource; when initiating a global transaction and calling the transaction branch resource, the transaction manager recognizes the annotation and registers the transaction branch information; if the forward operation of any transaction branch fails, the reverse rollback is performed to execute the reverse compensation operations of the previous participants, rollback the committed participants, and return the distributed transaction to the initial state.
[0026] The technical solution of the present invention also includes a distributed transaction processing device based on an independent transaction coordinator, comprising: a transaction coordination module, used to create clusters, each cluster including a corresponding transaction coordinator, storing log data generated in the distributed system through the transaction coordinator, and monitoring the distributed system; a transaction management module, used to define transaction boundaries, register transaction branches, register transaction resources and manage global transaction locks in the distributed system through an SDK, and query and report the transaction resources of the distributed system according to a request; and a transaction commit module, used to commit the transactions automatically.
[0027] Another aspect of the present invention provides an electronic device, including a processor and a memory;
[0028] The memory is used to store programs;
[0029] The processor executes the program to implement the method as described above.
[0030] This invention also discloses a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device can read the computer instructions from the computer-readable storage medium and execute the computer instructions, causing the computer device to perform the methods described above.
[0031] The beneficial effects of this invention are as follows: This invention treats the transaction coordinator as an independent process, allowing applications to easily and conveniently access distributed transaction management via an SDK. The transaction coordinator can be deployed in a cluster, avoiding single points of failure like the XA protocol. Furthermore, the transaction coordinator has a timeout mechanism, ensuring that transaction resources do not experience prolonged synchronous blocking. It implements an auto-commit transaction mode without intruding on business logic, significantly reducing the development and learning costs compared to the XA protocol's embedding of business code. Annotation-based implementation of TCC and SAGA transaction resources allows for rapid implementation, delegating resource lock control to specific business logic. The granularity of resource locks is controllable, preventing the entire resource from being locked. Simultaneously, the business logic implements idempotency based on the Confirm and Cancel interfaces, ensuring data consistency upon final confirmation or cancellation of the transaction. Compared to the XA and three-phase commit protocols, eventual data consistency is controllable, reducing the failure rate of transaction processing.
[0032] Additional aspects and advantages of the invention will be set forth in part in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. Attached Figure Description
[0033] The above and / or additional aspects and advantages of the present invention will become apparent and readily understood from the description of the embodiments taken in conjunction with the following drawings, in which:
[0034] Figure 1 This is a schematic diagram of the XA protocol for two-phase submission in existing technology.
[0035] Figure 2 This is a schematic diagram of the three-phase commit protocol in the prior art.
[0036] Figure 3 This is a schematic diagram of the existing TCC two-stage compensation mode.
[0037] Figure 4 This is a flowchart illustrating a distributed transaction processing method based on an independent transaction coordinator according to an embodiment of the present invention.
[0038] Figure 5a , Figure 5b This is a schematic diagram of transaction information storage according to an embodiment of the present invention.
[0039] Figure 6 This is a schematic diagram of a cluster according to an embodiment of the present invention.
[0040] Figure 7 This is a schematic diagram of a transaction monitoring system according to an embodiment of the present invention.
[0041] Figure 8 This is a schematic diagram of SDK management according to an embodiment of the present invention.
[0042] Figure 9a Figures 9b and 9c are flowcharts illustrating different states of global and branch transactions in an embodiment of the present invention.
[0043] Figure 10 This is a schematic diagram of the TCC transaction mode according to an embodiment of the present invention.
[0044] Figure 11 This is a schematic diagram of the SAGA transaction mode according to an embodiment of the present invention.
[0045] Figure 12 This is a diagram of a distributed transaction processing analysis device based on an independent transaction coordinator, according to an embodiment of the present invention. Detailed Implementation
[0046] The embodiments of the present invention are described in detail below, examples of which are shown in the accompanying drawings. Throughout the description, the same or similar reference numerals denote the same or similar elements or elements having the same or similar functions. In the following description, suffixes such as "module," "part," or "unit" used to denote elements are used only for the purpose of illustrative purposes and have no specific meaning in themselves. Therefore, "module," "part," or "unit" can be used interchangeably. Terms such as "first," "second," etc., are used only to distinguish technical features and should not be construed as indicating or implying relative importance, or implicitly indicating the number of indicated technical features, or implicitly indicating the sequential relationship of the indicated technical features. In the following description, the consecutive reference numerals for method steps are for ease of review and understanding. Adjusting the implementation order of steps, in conjunction with the overall technical solution of the present invention and the logical relationship between the various steps, will not affect the technical effect achieved by the technical solution of the present invention. The embodiments described below with reference to the accompanying drawings are exemplary and are only used to explain the present invention, and should not be construed as limiting the present invention.
[0047] Figure 4 This is a flowchart illustrating a distributed transaction processing method based on an independent transaction coordinator according to an embodiment of the present invention. The process includes:
[0048] S100 creates clusters, each cluster including a corresponding transaction coordinator. The transaction coordinator stores the log data generated by the distributed system and monitors the distributed system.
[0049] S200 defines transaction boundaries, registers transaction branches, registers transaction resources, and manages global transaction locks in the distributed system. It also queries and reports the transaction resources of the distributed system according to requests.
[0050] S300 uses an automatic method to commit transactions.
[0051] Figure 5a , Figure 5b This is a schematic diagram illustrating transaction information storage according to an embodiment of the present invention. (Reference) Figure 5a and Figure 5b In this embodiment of the invention, the transaction coordinator (Server) is designed as a standalone process, featuring high availability and scalability. The transaction manager and resource manager (SDK) communicate with the transaction coordinator over the network to complete the initiation, commit, and rollback of transactions. The main modules of the transaction coordinator are as follows:
[0052] Transaction information storage module: This module is responsible for storing transaction information. The storage methods are mainly divided into two categories, see reference... Figure 5aOne approach is to store log files based on the Raft protocol, using an odd number of nodes (at least three) to form a stateful cluster. Transaction messages between clusters are synchronized through log replication. (See reference...) Figure 5b Secondly, based on centralized storage, such as relational databases or NoSQL such as Redis, a stateless cluster is formed by grouping more than one node.
[0053] Figure 6 This is a schematic diagram of a cluster in an embodiment of the present invention. The module in this embodiment is responsible for building the cluster. A node of a transaction coordinator process belongs to a cluster, and a cluster belongs to a service group. There are two cluster modes: stateful Raft cluster and stateless cluster.
[0054] Figure 7 This is a schematic diagram of a transaction monitoring system according to an embodiment of the present invention. The module in this embodiment is responsible for monitoring system resources, JVM parameters, network, and the execution status of corresponding transactions during operation. At the same time, it connects to the monitoring and early warning platform to monitor the internal operation status of the transaction coordinator in real time. By observing the monitoring indicators, it can predict possible problems and issue early warnings to quickly notify relevant personnel to handle the problem when the system or service fails, thereby minimizing the impact of the problem.
[0055] Figure 8 This is a schematic diagram of SDK management according to an embodiment of the present invention. The SDK includes a transaction manager, a resource manager, and a basic function layer. The basic function layer provides basic functional support for the transaction manager and the resource manager. In addition to their respective core functions, the transaction manager is also responsible for the lifecycle management of the resource manager.
[0056] Transaction Manager: Plays the role of transaction management in transaction processing. Its main functions are to define transaction boundaries, register transaction branches, register transaction resources, and manage global transaction locks.
[0057] Resource Manager: Primarily responsible for automatically scanning all transaction resources in its runtime environment, such as relational database DataSource, TCC service, SAGA service, etc., and coordinating the various transaction resources to take appropriate actions when the global transaction reaches the commit or rollback stage. For example, when the global transaction is committed, the TCC transaction resource should be CONFIRM processed.
[0058] Figure 9a Figures 9b and 9c are flowcharts illustrating different states of global and branch transactions in an embodiment of the present invention.
[0059] refer to Figure 9aIn a global transaction, the transaction resources corresponding to each transaction branch generate corresponding data image query statements based on the SQL statements they receive. The data image query statements are used to query the front image of the data before the SQL operation, and the front image data is saved in the branch database. After the front image data is saved, the branch SQL is executed, and then the after image of the data is queried and saved in the database. Finally, the local commit of the branch transaction is executed.
[0060] refer to Figure 9b When a branch transaction receives a notification of a global transaction commit, it only needs to delete the preceding and following mirror data, and this can be done asynchronously.
[0061] refer to Figure 9c When a global rollback request is received, the transaction resources of the branch transaction use a mirror query statement to check whether the data in the current database is consistent with the records in the subsequent mirror. If they are consistent, the data in the previous mirror is used to roll back the relevant data; otherwise, an alarm is triggered and manual intervention is required.
[0062] Figure 10 This is a schematic diagram of the TCC transaction mode in an embodiment of the present invention. TCC is a two-phase commit distributed transaction solution that can be used to solve data consistency problems in cross-database and cross-service business operations. The three methods of TCC, Try, Confirm, and Cancel, are all implemented by business code. Generally, the Try operation is the first phase and is responsible for checking and reserving resources. The Confirm operation is the second phase commit operation and executes the actual business. Cancel is the second phase rollback operation, which cancels the reserved resources and returns the resources to their initial state.
[0063] The TCC mode operates as follows: During business logic coding, a TCC transaction resource is marked by adding the @TCC annotation before a method. The transaction resource manager scans for this annotation during application startup and registers a transaction branch resource with the transaction coordinator. When a global transaction is initiated and the transaction branch resource is called, the transaction manager recognizes the @TCC annotation and registers the transaction branch information with the transaction coordinator. When the transaction manager reaches the commit or rollback phase, it notifies the transaction coordinator to initiate the commit or rollback of the transaction branch. When the transaction resource manager receives a commit or rollback request, it coordinates the TCC transaction resource to handle it accordingly. If the request is for commit, the Confirm method is called; if the request is for rollback, the Cancel method is called.
[0064] Figure 11This is a schematic diagram of the SAGA transaction mode in an embodiment of the present invention. SAGA is a compensation protocol. In the SAGA mode, there are multiple participants in the distributed transaction. Each participant has a compensation service that can reverse the transaction. Users need to implement its forward operation and reverse rollback operation according to the business scenario.
[0065] The SAGA mode operates as follows: During business logic coding, a SAGA transaction resource is marked by adding the @SAGA annotation before a method. When the application starts, the transaction resource manager scans for this annotation and registers a transaction branch resource with the transaction coordinator. When a global transaction is initiated and the transaction branch resource is called, the transaction manager recognizes the @SAGA annotation and registers the transaction branch information with the transaction coordinator. If the forward operation of any transaction branch fails, the transaction manager notifies the transaction coordinator to synchronously reverse and execute the reverse compensation operations of the previous participants, rolling back the committed participants and returning the distributed transaction to its initial state.
[0066] Figure 12 This is a diagram of a distributed transaction processing analysis device based on an independent transaction coordinator according to an embodiment of the present invention. As shown, this embodiment of the present invention also provides a distributed transaction processing analysis device based on an independent transaction coordinator, which includes a transaction coordination module 1201, a transaction management module 1202, and a transaction commit module 1203.
[0067] The transaction coordination module is used to create clusters. Each cluster includes a corresponding transaction coordinator. The transaction coordinator stores the log data generated by the distributed system and monitors the distributed system.
[0068] The transaction management module is used to define transaction boundaries, register transaction branches, register transaction resources and manage global transaction locks in the distributed system through the SDK, and query and report the transaction resources of the distributed system according to the request.
[0069] The transaction commit module is used to commit transactions automatically.
[0070] For example, with the collaboration of the transaction coordination module, transaction management module, and transaction commit module in the device, the embodiment device can implement any of the aforementioned distributed transaction processing methods based on an independent transaction coordinator. This involves creating clusters, each cluster including a corresponding transaction coordinator, storing distributed log data through the transaction coordinator, monitoring the distributed system, defining transaction boundaries, registering transaction branches, registering transaction resources, and managing global transaction locks for transactions in the distributed system, querying transaction resources in the distributed system according to requests and reporting them, and automatically committing transactions. This invention treats the transaction coordinator as an independent process, allowing applications to easily and conveniently access distributed transaction management via an SDK. The transaction coordinator can be deployed in a cluster, avoiding the single point of failure problem of the XA protocol. Furthermore, the transaction coordinator has a timeout mechanism to ensure that transaction resources do not experience prolonged synchronous blocking. This invention also implements an auto-commit transaction mode without intruding on business logic, significantly reducing the development and learning costs compared to the XA protocol's embedding of business code. Based on annotations, this invention provides rapid implementation of TCC and SAGA transaction resources, thereby delegating resource lock control to specific business logic. The granularity of resource locks is controllable, preventing the entire resource from being locked. Simultaneously, the business logic achieves idempotency based on the Confirm and Cancel interfaces, ensuring data consistency upon final confirmation or cancellation of the transaction. Compared to the XA protocol and the three-phase commit protocol, eventual data consistency is controllable.
[0071] This invention also provides an electronic device, which includes a processor and a memory;
[0072] The memory stores the program;
[0073] The processor executes the program to perform the aforementioned distributed transaction processing method based on an independent transaction coordinator; the electronic device has the function of carrying and running the software system for distributed transaction processing based on an independent transaction coordinator provided in the embodiments of the present invention, such as a personal computer (PC), mobile phone, smartphone, personal digital assistant (PDA), wearable device, handheld computer (PPC), tablet computer, etc.
[0074] This invention also provides a computer-readable storage medium storing a program that is executed by a processor to implement the distributed transaction processing method based on an independent transaction coordinator as described above.
[0075] In some alternative embodiments, the functions / operations mentioned in the block diagrams may not occur in the order shown in the operation diagrams. For example, depending on the functions / operations involved, two consecutively shown blocks may actually be executed substantially simultaneously, or the blocks may sometimes be executed in reverse order. Furthermore, the embodiments presented and described in the flowcharts of this invention are provided by way of example to provide a more comprehensive understanding of the technology. The disclosed methods are not limited to the operations and logic flows presented herein. Alternative embodiments are contemplated in which the order of various operations is altered and sub-operations described as part of a larger operation are executed independently.
[0076] This invention also discloses a computer program product or computer program, which includes computer instructions stored in a computer-readable storage medium. A processor of a computer device can read the computer instructions from the computer-readable storage medium and execute the computer instructions, causing the computer device to perform the aforementioned distributed transaction processing method based on an independent transaction coordinator.
[0077] Furthermore, although the invention has been described in the context of functional modules, it should be understood that, unless otherwise stated, one or more of the described functions and / or features may be integrated into a single physical device and / or software module, or one or more functions and / or features may be implemented in a separate physical device or software module. It is also understood that a detailed discussion of the actual implementation of each module is unnecessary for understanding the invention. Rather, given the properties, functions, and internal relationships of the various functional modules in the apparatus disclosed herein, the actual implementation of the module will be understood within the scope of conventional skill of an engineer. Therefore, those skilled in the art can implement the invention as set forth in the claims using ordinary techniques without excessive experimentation. It is also understood that the specific concepts disclosed are merely illustrative and not intended to limit the scope of the invention, which is determined by the full scope of the appended claims and their equivalents.
[0078] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, essentially, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0079] The logic and / or steps represented in the flowchart or otherwise described herein, for example, can be considered as a sequenced list of executable instructions for implementing logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, apparatus, or device (such as a computer-based system, a processor-included system, or other system that can fetch and execute instructions from, an instruction execution system, apparatus, or device). For the purposes of this specification, "computer-readable medium" can be any means that can contain, store, communicate, propagate, or transmit programs for use by, or in conjunction with, an instruction execution system, apparatus, or device.
[0080] More specific examples of computer-readable media (a non-exhaustive list) include: electrical connections (electronic devices) having one or more wires, portable computer disk drives (magnetic devices), random access memory (RAM), read-only memory (ROM), erasable and editable read-only memory (EPROM or flash memory), fiber optic devices, and portable optical disc read-only memory (CDROM). Furthermore, computer-readable media can even be paper or other suitable media on which the program can be printed, since the program can be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, interpreting, or otherwise processing as necessary, and then stored in computer memory.
[0081] It should be understood that various parts of the present invention can be implemented in hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented in software or firmware stored in memory and executed by a suitable instruction execution system. For example, if implemented in hardware, as in another embodiment, it can be implemented using any one or a combination of the following techniques known in the art: discrete logic circuits having logic gates for implementing logical functions on data signals, application-specific integrated circuits (ASICs) having suitable combinational logic gates, programmable gate arrays (PGAs), field-programmable gate arrays (FPGAs), etc.
[0082] In the description of this specification, references to terms such as "one embodiment," "some embodiments," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of the invention. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.
[0083] Although embodiments of the invention have been shown and described, those skilled in the art will understand that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of the invention, the scope of which is defined by the claims and their equivalents.
[0084] The above is a detailed description of the preferred embodiments of the present invention, but the present invention is not limited to the embodiments described. Those skilled in the art can make various equivalent modifications or substitutions without departing from the spirit of the present invention, and these equivalent modifications or substitutions are all included within the scope defined by the claims of this application.
Claims
1. A method of processing a distributed transaction based on an independent transaction coordinator, characterized by, The method comprises the following steps: creating clusters, each of which comprises a corresponding transaction coordinator, storing log data generated by distribution through the transaction coordinator, and monitoring the distributed system; defining transaction boundaries, registering transaction branches, registering transaction resources, and managing global transaction lock management for transactions in the distributed system through an SDK, and querying transaction resources of the distributed system and reporting according to requests; adopting an automatic way to execute commit for the transaction; the creating clusters, each of which comprises a corresponding transaction coordinator, storing log data generated by distribution through the transaction coordinator, and monitoring the distributed system comprises: based on the Raft protocol, log data is stored, at least three nodes form an odd number of nodes to form a stateful cluster, and transaction messages between clusters are synchronized through log replication; or, a node group with a number greater than one forms a stateless cluster, and the centralized storage of the log is executed through the stateless cluster; and monitoring resources, JVM parameters, networks, and transaction execution states in the distributed system, while connecting to a monitoring and early warning platform to monitor the running state of the transaction coordinator in real time; the transaction coordinator is an independent process, and the nodes of the transaction coordinator belong to a cluster, and a cluster belongs to a service group; the adopting an automatic way to execute commit for the transaction comprises: generating a corresponding data mirror query statement according to a database operation request received by the transaction resource, querying a pre-image of the data before the operation request using the data mirror query statement, and saving the pre-image data, and after the pre-image data is saved, executing the operation request; and in the subsequent query, the post-image data is saved, and the local commit of the branch transaction is executed; when the branch transaction receives a notification of global transaction commit, the pre-image data and the post-image data are deleted, and the deletion is performed in an asynchronous manner; when a global rollback request is received, the transaction resource of the branch transaction queries whether the data in the current database is consistent with the record in the post-image through the mirror query statement, if yes, the pre-image data is used to roll back the related data, otherwise, an alarm is given, wherein the global transaction comprises multiple branch transactions.
2. The method of claim 1, wherein the method further comprises: The method further comprises the following steps: according to requests, automatically scanning all the transaction resources of the distributed system, and coordinating each of the transaction resources to perform corresponding processing when the global transaction is in the commit or rollback phase.
3. The independent transaction coordinator based distributed transaction processing method of claim 1, wherein, The commit of the transaction further comprises adopting a TCC mode, wherein the TCC mode comprises: annotating a TCC transaction resource by adding an annotation before a method during business coding; scanning the annotation during application startup, and registering a transaction branch resource through a transaction coordinator; when a global transaction is initiated and the transaction branch resource is called, the annotation is identified, and transaction branch information is registered according to the annotation; When a business corresponding to a transaction execution commits or rolls back, a transaction branch is initiated to commit or roll back, and when the transaction resource manager receives a branch commit or rollback request, the transaction resource manager coordinates the corresponding processing of the TCC transaction resource execution.
4. The independent transaction coordinator based distributed transaction processing method of claim 1, wherein, The commit of the transaction further includes a SAGA mode, wherein the SAGA mode includes: When the business is coded, a SAGA transaction resource is marked by adding an annotation before a method; During application startup, the annotation is scanned to register the transaction branch resource; When a global transaction is initiated and the transaction branch resource is called, the transaction manager identifies the annotation and registers the transaction branch information; If the forward operation of any transaction branch fails, the reverse compensation operation of the previous participants is executed, the committed participants are rolled back, and the distributed transaction is returned to the initial state.
5. An apparatus for processing a distributed transaction based on an independent transaction coordinator, the apparatus comprising: a transaction manager configured to: receive a request for a transaction; and initiate a transaction based on the request. The distributed transaction processing device based on the independent transaction coordinator is used to execute the distributed transaction processing method based on the independent transaction coordinator as claimed in claim 1; the device includes: A transaction coordination module is configured to create clusters, each of the clusters including a corresponding transaction coordinator, store log data generated by the distributed system through the transaction coordinator, and monitor the distributed system; A transaction management module is configured to define a transaction boundary, register a transaction branch, register a transaction resource, and manage a global transaction lock through an SDK for transaction execution in the distributed system, and according to a request, query a transaction resource of the distributed system and report. A transaction commit module is configured to automatically commit the transaction.
6. An electronic device, comprising: The device includes a processor and a memory; The memory is configured to store a program; The processor executes the program to implement the distributed transaction processing method based on the independent transaction coordinator as claimed in any one of claims 1-4.
7. A computer-readable storage medium, characterized in that, The storage medium stores a program, and the program is executed by the processor to implement the distributed transaction processing method based on the independent transaction coordinator as claimed in any one of claims 1-4. The storage medium stores a program, and the program is executed by the processor to implement the distributed transaction processing method based on the independent transaction coordinator as claimed in any one of claims 1-4.
Citation Information
Patent Citations
MongoDB-based distributed transaction processing system and method
CN113032421A