Distributed transaction processing method, system and equipment and storage medium

By introducing transaction coordination points to unified coordinate distributed transactions in the microservice architecture, the problem of difficult distributed transaction coordination is solved, transaction consistency and efficiency improvement is achieved, complex system architectures are adapted to complex system architectures and fault recovery capabilities are enhanced.

CN120492095APending Publication Date: 2025-08-15IMUSIC CULTURE & TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510651762.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-05-20
Publication Date
2025-08-15

AI Technical Summary

Technical Problem

Under the microservice architecture, the coordination and processing of distributed transactions is difficult, resulting in high complexity of the business system, prone to failures, and affecting the user experience.

Method used

The transaction group creation request is initiated to the transaction coordination point through the transaction initiating node, the coordination point creates the transaction group, and by querying the local transaction status of the participating node, the commit instructions are sent uniformly to ensure transaction consistency and efficiency.

Benefits of technology

It realizes the consistency and efficiency of transaction processing in distributed systems, adapts to complex system architectures, enhances fault recovery capabilities, and supports complex business processes and collaborative operations of multiple data sources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN120492095A_ABST
    Figure CN120492095A_ABST
Patent Text Reader

Abstract

The invention discloses a distributed transaction processing method, system and device and a storage medium. A transaction initiating node initiates a transaction group creation request to a transaction coordination node, and the transaction coordination node creates a corresponding transaction group according to the transaction group creation request; the transaction initiating node executes the business code corresponding to the target transaction, and calls a plurality of participating nodes to process the target transaction; the participating node responds to the calling of the transaction initiating node, initiates a request to the transaction coordinating node to be added into the transaction group, and processes the local transaction called by the transaction initiating node; the transaction initiating node sends a transaction processing completion notification to the transaction coordination node, and the transaction coordination node sends an inquiry request to all participating nodes included in the transaction group; and if successful processing notifications fed back by all the participating nodes are received, submission instructions are sent to all the participating nodes. According to the method, the consistency of target transaction processing is ensured, and the transaction processing efficiency is improved. The method can be widely applied to the field of distributed technologies.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] With the development of the internet, related application systems are gradually shifting from monolithic architectures to microservices. In a monolithic architecture, all business functions are contained within a single application, making transaction management relatively simple. Local transactions (such as those in relational databases) can often be used to ensure data consistency. However, in a microservices architecture, each microservice has its own independent database, and a single business process may span multiple microservices and databases, requiring distributed transactions to ensure data correctness.

[0003] In related technologies, as businesses continue to expand, complex business scenarios (such as inter-bank transfers in financial systems and cross-departmental business process integration) all require ensuring the atomicity, consistency, isolation, and durability (i.e., Atomicity-Consistency-Isolation-Durability, ACID) of transactions in a distributed environment. Although there are some ACID-supported databases, these databases are not widely used and are more often used in combination with other database environments. Legacy database systems also commonly have transaction coordination issues. Given the complexity and diversity of business systems currently owned by businesses, transaction coordination is becoming increasingly difficult, and a variety of business issues are prone to occur, leading to service failures and impacting the user's business processing experience.

[0004] Therefore, the problems existing in the existing technology still need to be solved and optimized. Summary of the Invention

[0005] The purpose of this application is to solve one of the technical problems existing in the related art to at least a certain extent.

[0006] To this end, an object of embodiments of the present application is to provide a method, system, device, and storage medium for processing distributed transactions.

[0007] In order to achieve the above technical objectives, the technical solutions adopted in the embodiments of the present application include:

[0008] In one aspect, an embodiment of the present application provides a method for processing distributed transactions, the method comprising:

[0009] The transaction initiating node initiates a transaction group creation request to the transaction coordinating node, and the transaction coordinating node creates a corresponding transaction group according to the transaction group creation request. The transaction group creation request includes information about participating nodes of the target transaction to be processed and transaction identification information corresponding to the target transaction. The target transaction is a distributed transaction.

[0010] The transaction initiating node executes the business code corresponding to the target transaction and calls several participating nodes to process the target transaction;

[0011] The participating node, in response to the call of the transaction initiating node, initiates a request to the transaction coordinating node to join the transaction group, and processes the local transaction called by the transaction initiating node;

[0012] The transaction initiating node sends a transaction processing completion notification to the transaction coordinating node, and the transaction coordinating node sends a query request to all the participating nodes included in the transaction group; wherein the query request is used to inquire the participating nodes whether the local transaction of the target transaction has been successfully processed;

[0013] If the transaction coordination node receives successful processing notifications fed back by all the participating nodes, the transaction coordination node sends a commit indication to all the participating nodes; wherein the commit indication is used to inform the participating nodes to commit the local transaction corresponding to the target transaction.

[0014] In addition, a distributed transaction processing system according to the above embodiment of the present application may also have the following additional technical features:

[0015] Furthermore, in one embodiment of the present application, the transaction coordination node creates a corresponding transaction group according to the transaction group creation request, including:

[0016] The transaction coordination node detects whether there is a transaction group corresponding to the transaction group creation request;

[0017] If the transaction group corresponding to the transaction group creation request does not currently exist, create the transaction group;

[0018] If a transaction group corresponding to the transaction group creation request currently exists, the transaction initiating node is added to the transaction group.

[0019] Furthermore, in one embodiment of the present application, the transaction coordination node is built based on Zookeeper.

[0020] Furthermore, in one embodiment of the present application, the method further includes:

[0021] The participating node monitors the processing status of the local transaction;

[0022] If an abnormality occurs in the processing state, the participating node notifies the transaction coordination node to roll back the local transaction of the participating node.

[0023] Furthermore, in one embodiment of the present application, the method further includes:

[0024] If the transaction coordination node receives the failure processing notification fed back by the participating node, detecting the total number of the failure processing notifications;

[0025] Determining the proportion of participating nodes that failed processing based on the total number;

[0026] If the ratio is less than or equal to a preset ratio threshold, a retry instruction is sent to a target node; wherein the target node is the participating node that feeds back the failure processing notification, and the retry instruction is used to instruct to reprocess the local transaction;

[0027] If the ratio is greater than the preset ratio threshold, the retry indication is sent to all the participating nodes.

[0028] Furthermore, in one embodiment of the present application, sending a retry indication to the target node includes:

[0029] Detecting the historical number of times the target node feeds back the failure processing notification;

[0030] If the historical number of times is less than or equal to a preset number threshold, sending a first retry instruction to the target node; wherein the first retry instruction is used to instruct the target node to reprocess the local transaction;

[0031] If the historical number is greater than the preset number threshold, a second retry instruction is sent to the administrator corresponding to the target node; wherein the second retry instruction is used to instruct the administrator to manually intervene in the target node and reprocess the local transaction.

[0032] Furthermore, in one embodiment of the present application, the transaction coordination node implements distributed transaction consistency between the transaction initiating node and each of the participating nodes through a TCC mode.

[0033] On the other hand, an embodiment of the present application provides a distributed transaction processing system, the system including a transaction initiating node, a transaction coordinating node, and several participating nodes;

[0034] The transaction initiation node is used to initiate a transaction group creation request to the transaction coordination node, and the transaction coordination node is used to create a corresponding transaction group according to the transaction group creation request; wherein the transaction group creation request includes the participating node information of the target transaction to be processed and the transaction identification information corresponding to the target transaction, and the target transaction is a distributed transaction;

[0035] The transaction initiating node is used to execute the business code corresponding to the target transaction and call several participating nodes to process the target transaction;

[0036] The participating node is used to, in response to the call of the transaction initiating node, initiate a request to the transaction coordinating node to join the transaction group, and process the local transaction called by the transaction initiating node;

[0037] The transaction initiating node is used to send a transaction processing completion notification to the transaction coordinating node, and the transaction coordinating node is used to send a query request to all the participating nodes included in the transaction group; wherein the query request is used to inquire the participating nodes whether the local transaction of the target transaction has been successfully processed;

[0038] The transaction coordination node is used to send a commit instruction to all the participating nodes when the transaction coordination node receives a successful processing notification fed back by all the participating nodes; wherein the commit instruction is used to inform the participating nodes to commit the local transaction corresponding to the target transaction.

[0039] In another aspect, an embodiment of the present application provides a computer device, including:

[0040] at least one processor;

[0041] at least one memory for storing at least one program;

[0042] When the at least one program is executed by the at least one processor, the at least one processor implements the above-mentioned distributed transaction processing method.

[0043] On the other hand, an embodiment of the present application further provides a computer-readable storage medium, which stores a program executable by a processor. When the program executable by the processor is executed by the processor, it is used to implement the above-mentioned distributed transaction processing method.

[0044] The advantages and benefits of this application will be partially given in the following description, and partially become apparent from the following description, or learned through practice of this application:

[0045] An embodiment of the present application discloses a method for processing distributed transactions. A transaction initiating node initiates a transaction group creation request to a transaction coordinating node, and the transaction coordinating node creates a corresponding transaction group based on the transaction group creation request. The transaction group creation request includes participating node information of a target transaction to be processed and transaction identification information corresponding to the target transaction, where the target transaction is a distributed transaction. The transaction initiating node executes business code corresponding to the target transaction and calls several participating nodes to process the target transaction. In response to the call by the transaction initiating node, the participating nodes initiate a request to the transaction coordinating node to join the transaction group and process the local transaction called by the transaction initiating node. The transaction initiating node sends a transaction processing completion notification to the transaction coordinating node, and the transaction coordinating node sends a query request to all participating nodes included in the transaction group. The query request is used to inquire whether the participating nodes have successfully processed the local transaction of the target transaction. If the transaction coordinating node receives a successful processing notification from all participating nodes, the transaction coordinating node sends a commit indication to all participating nodes. The commit indication is used to instruct the participating nodes to commit the local transaction corresponding to the target transaction. This method coordinates the local transactions of each node in the distributed system through the transaction coordination node, which can ensure the consistency of target transaction processing and improve the efficiency of transaction processing. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the following introduction is made to the drawings of the embodiments of the present application or the related technical solutions in the prior art. It should be understood that the drawings introduced below are only for the convenience of clearly describing some embodiments of the technical solutions of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without any creative work.

[0047] Figure 1 A schematic diagram of an implementation environment of a distributed transaction processing method provided in an embodiment of the present application;

[0048] Figure 2 A schematic diagram of a process flow of a distributed transaction processing method provided in an embodiment of the present application;

[0049] Figure 3 A schematic diagram of the processing sequence of a distributed transaction provided in an embodiment of the present application;

[0050] Figure 4 This is a schematic diagram of the architecture of a distributed system based on Zookeeper provided in an embodiment of the present application;

[0051] Figure 5A schematic diagram of a tree structure of a distributed transaction provided in an embodiment of the present application;

[0052] Figure 6 A flowchart of a Java interceptor-based business method provided in an embodiment of the present application;

[0053] Figure 7 This is a schematic diagram of the structure of a computer device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0054] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application is further described in detail below with reference to the accompanying drawings and examples. It should be understood that the specific embodiments described herein are only used to explain the present application and are not intended to limit the present application. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the embodiments of the present application. They are merely examples of devices and methods consistent with some aspects of the embodiments of the present application as detailed in the appended claims.

[0055] It will be understood that the terms "first", "second", etc. used in this application may be used herein to describe various concepts, but unless otherwise specified, these concepts are not limited by these terms. These terms are only used to distinguish one concept from another. For example, without departing from the scope of the embodiments of the present application, the first information may also be referred to as the second information, and similarly, the second information may also be referred to as the first information. Depending on the context, the words "if" and "if" as used herein may be interpreted as "at the time of" or "when" or "in response to determining".

[0056] The terms "at least one", "plurality", "each", "any", etc. used in this application include "at least one", "two" or more, "plurality" or "each", "any" or "any one", "each" or "any one" as used herein.

[0057] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by those skilled in the art to which this application pertains. The terms used herein are for the purpose of describing the embodiments of this application only and are not intended to limit this application.

[0058] With the development of the internet, related application systems are gradually shifting from monolithic architectures to microservices. In a monolithic architecture, all business functions are contained within a single application, making transaction management relatively simple. Local transactions (such as those in relational databases) can often be used to ensure data consistency. However, in a microservices architecture, each microservice has its own independent database, and a single business process may span multiple microservices and databases, requiring distributed transactions to ensure data correctness.

[0059] In related technologies, as businesses continue to expand, complex business scenarios (such as inter-bank transfers in financial systems and cross-departmental business process integration) all require ensuring the atomicity, consistency, isolation, and durability (i.e., Atomicity-Consistency-Isolation-Durability, ACID) of transactions in a distributed environment. Although there are some ACID-supported databases, these databases are not widely used and are more often used in combination with other database environments. Legacy database systems also commonly have transaction coordination issues. Given the complexity and diversity of business systems currently owned by businesses, transaction coordination is becoming increasingly difficult, and a variety of business issues are prone to occur, leading to service failures and impacting the user's business processing experience.

[0060] In view of this, an embodiment of the present application provides a method for processing distributed transactions, wherein a transaction initiating node initiates a transaction group creation request to a transaction coordinating node, and the transaction coordinating node creates a corresponding transaction group based on the transaction group creation request; wherein the transaction group creation request includes participating node information of a target transaction to be processed and transaction identification information corresponding to the target transaction, and the target transaction is a distributed transaction; the transaction initiating node executes the business code corresponding to the target transaction and calls several participating nodes to process the target transaction; the participating nodes, in response to the call by the transaction initiating node, initiate a request to the transaction coordinating node to join the transaction group and process the local transaction called by the transaction initiating node; the transaction initiating node sends a transaction processing completion notification to the transaction coordinating node, and the transaction coordinating node sends a query request to all the participating nodes included in the transaction group; wherein the query request is used to query the participating nodes whether the local transaction of the target transaction is successfully processed; if the transaction coordinating node receives a successful processing notification from all the participating nodes, the transaction coordinating node sends a commit indication to all the participating nodes; wherein the commit indication is used to inform the participating nodes to commit the local transaction corresponding to the target transaction. This method coordinates the local transactions of each node in the distributed system through the transaction coordination node, which can ensure the consistency of target transaction processing and improve the efficiency of transaction processing.

[0061] Below, we first introduce the implementation environment involved in the distributed transaction processing method provided in the embodiment of this application. Figure 1 , Figure 1 A schematic diagram of the implementation environment of a distributed transaction processing method is given. The software and hardware components of the implementation environment mainly include a transaction initiating node 110, a transaction coordinating node 120 and a participating node 130. Among them, the transaction initiating node 110 and the participating node 130 can be the original business systems used to handle various types of business, and the transaction coordinating node 120 is a coordination intermediate node newly added in the distributed system interface call in the embodiment of the present application. It can coordinate the execution status of various related business systems in the network, perform centralized management in a unified manner, and notify each business system of the corresponding execution results to ensure the consistency of transaction data of each business system.

[0062] Specifically, in an embodiment of the present application, the transaction initiating node 110, the transaction coordinating node 120, and the participating node 130 may be nodes constructed by related computer devices. For example, each node may be an independent physical server, or a server cluster composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN (Content Delivery Network), and big data and artificial intelligence platforms. A communication connection can be established between each node through a wireless network or a wired network. The wireless network or wired network uses standard communication technology and / or protocols. The network can be set to the Internet or any other network, such as but not limited to a local area network (LAN), a metropolitan area network (MAN), a wide area network (WAN), any combination of mobile, wired or wireless networks, private networks, or virtual private networks.

[0063] It should be noted that in the embodiments of this application, the identity of the transaction coordinating node 120 can be fixed; however, the identities of the transaction initiating node 110 and the participating nodes 130 can change based on actual needs. For example, in some scenarios, a business system may belong to the transaction initiating node 110, but in other scenarios, the business system may belong to the participating node 130. This application does not impose any restrictions on this. In a specific single embodiment, the number of transaction initiating node 110 and transaction coordinating node 120 is generally one, while the number of participating nodes 130 can be one or more.

[0064] Of course, it is understandable that Figure 1The implementation environment in the embodiment of the present application is only an optional application scenario of the distributed transaction processing method provided in the embodiment of the present application. The actual application is not fixed to Figure 1 The hardware and software environment shown.

[0065] The following combination Figure 1 The implementation environment shown is used to describe in detail the distributed transaction processing method provided in the embodiments of the present application.

[0066] Please refer to Figure 2 , Figure 2 This is a flow chart of a distributed transaction processing method provided by an embodiment of the present application, with reference to Figure 2 , a distributed transaction processing method provided by this application includes but is not limited to:

[0067] Step 210: The transaction initiating node initiates a transaction group creation request to the transaction coordinating node. The transaction coordinating node creates a corresponding transaction group according to the transaction group creation request. The transaction group creation request includes information about participating nodes of the target transaction to be processed and transaction identification information corresponding to the target transaction.

[0068] Step 220: The transaction initiating node executes the business code corresponding to the target transaction and calls several participating nodes to process the target transaction.

[0069] Step 230: In response to the call of the transaction initiating node, the participating node initiates a request to the transaction coordinating node to join the transaction group and executes the local transaction called by the transaction initiating node.

[0070] Step 240: The transaction initiating node sends a transaction execution completion notification to the transaction coordinating node, and the transaction coordinating node sends a query request to all the participating nodes included in the transaction group; wherein the query request is used to inquire the participating nodes whether the local transaction of the target transaction has been successfully executed;

[0071] Step 250: If the transaction coordination node receives successful execution notifications fed back by all the participating nodes, the transaction coordination node sends a commit instruction to all the participating nodes; wherein the commit instruction is used to inform the participating nodes to commit the local transaction corresponding to the target transaction.

[0072] In the embodiment of the present application, when processing distributed transactions, the transaction initiating node can request the transaction coordinating node to establish a corresponding transaction group before starting to execute the business. Figure 3 , Figure 3 A schematic diagram of the processing sequence of a distributed transaction provided in an embodiment of the present application is shown. Figure 3In the embodiment of the present application, the transaction initiator is the transaction initiation node, and the transaction coordinator is the transaction coordination node in the embodiment of the present application. The relevant processing flow involves two participating nodes, namely participating system A and participating system B. In the embodiment of the present application, when creating a transaction group, the transaction initiation node can initiate a transaction group creation request to the transaction coordination node. In this request, key information of the target transaction to be processed can be carried, such as the participating node information of the target transaction and the transaction identification information corresponding to the target transaction. Among them, the transaction identification information can be used to globally and uniquely identify a corresponding transaction, and different transactions have different corresponding transaction identification information.

[0073] After the transaction initiating node initiates a transaction group creation request to the transaction coordinating node, it will wait for the transaction coordinating node to respond to the request, establish the corresponding transaction group, and add the transaction initiating node to the transaction group. Then, it can feedback the response to the transaction initiating node. After the transaction initiating node receives the response message from the transaction coordinating node, it can start executing the business code corresponding to the target transaction. In the embodiment of the present application, the target transaction is a distributed transaction, which requires the coordinated processing of the transaction initiating node and several participating nodes. Specifically, when the transaction initiating node executes the business code corresponding to the target transaction, it will call each participating node according to the business code to perform some tasks. When calling the participating node, the transaction initiating node will transmit the transaction identification information to the participating node to facilitate the participating node to determine which tasks need to be performed locally.

[0074] Each participating node can execute the corresponding local transaction in response to the call from the transaction initiating node. In an embodiment of the present application, before executing a local transaction, each participating node needs to initiate a request to the transaction coordination node to join the transaction group corresponding to the target transaction. The transaction coordination node adds each participating node to the transaction group. In this way, all execution nodes corresponding to the target transaction: the transaction initiating node and each participating node are added to the transaction group. The transaction coordination node can then feedback the response result to the participating nodes, allowing each participating node to execute the local transaction.

[0075] In an embodiment of the present application, after the business code corresponding to the target transaction is executed at the transaction initiation node, other participating nodes will no longer be called. In other words, the matters of the target transaction at the participating nodes have also been executed. At this time, the transaction initiation node can send a transaction processing completion notification to the transaction coordination node, informing the transaction coordination node that all matters of the target transaction have been processed. After receiving the notification, the transaction coordination node will determine whether the global target transaction is successfully executed based on the processing status of the local transactions of each participant. Specifically, the transaction coordination node can send an inquiry request to all participating nodes included in the transaction group, inquiring whether they have successfully processed the local transactions of the target transaction. If the participating node processes successfully, a successful processing notification can be fed back to the transaction coordination node. If the participating node processes unsuccessfully, a failed processing notification can be fed back to the transaction coordination node.

[0076] After receiving the successful processing notification from all participating nodes, the transaction coordination node can send a commit instruction to all participating nodes. After receiving the commit instruction, the participating nodes will submit the processing results corresponding to the local transaction. In this way, the distributed processing of the target transaction can be achieved on multiple nodes.

[0077] It can be understood that in an embodiment of the present application, a method for processing distributed transactions is provided, in which a transaction initiating node initiates a transaction group creation request to a transaction coordinating node, and the transaction coordinating node creates a corresponding transaction group according to the transaction group creation request; wherein the transaction group creation request includes participating node information of a target transaction to be processed and transaction identification information corresponding to the target transaction, and the target transaction is a distributed transaction; the transaction initiating node executes the business code corresponding to the target transaction and calls several participating nodes to process the target transaction; the participating nodes, in response to the call of the transaction initiating node, initiate a request to the transaction coordinating node to join the transaction group and process the local transaction called by the transaction initiating node; the transaction initiating node sends a transaction processing completion notification to the transaction coordinating node, and the transaction coordinating node sends a query request to all the participating nodes included in the transaction group; wherein the query request is used to inquire whether the participating nodes have successfully processed the local transaction of the target transaction; if the transaction coordinating node receives a successful processing notification fed back by all the participating nodes, the transaction coordinating node sends a commit indication to all the participating nodes; wherein the commit indication is used to inform the participating nodes to commit the local transaction corresponding to the target transaction. This method coordinates the local transactions of each node in the distributed system through the transaction coordination node, which can ensure the consistency of target transaction processing and improve the efficiency of transaction processing.

[0078] Specifically, in some embodiments, the transaction coordination node creates a corresponding transaction group according to the transaction group creation request, including:

[0079] The transaction coordination node detects whether there is a transaction group corresponding to the transaction group creation request;

[0080] If the transaction group corresponding to the transaction group creation request does not currently exist, create the transaction group;

[0081] If a transaction group corresponding to the transaction group creation request currently exists, the transaction initiating node is added to the transaction group.

[0082] In an embodiment of the present application, when a transaction coordination node creates a corresponding transaction group according to a transaction group creation request, it can detect whether a transaction group corresponding to the transaction group creation request currently exists. If not, the transaction group can be established; if a transaction group corresponding to the transaction group creation request already exists, the transaction initiation node can be added to the transaction group.

[0083] Specifically, in some embodiments, the transaction coordination node is built based on Zookeeper.

[0084] In the embodiment of the present application, the transaction coordination node can be built based on Zookeeper, which is a distributed, open source coordination service framework. Figure 4 , Figure 4 A schematic diagram of the architecture of a distributed system based on Zookeeper provided in an embodiment of the present application is shown. Zookeeper is mainly used to maintain configuration information, naming services, distributed locks and other functions. Its core is a hierarchical file system directory tree structure (similar to the Linux file system), and each node is called a znode. These znodes can store data and are of different types, such as persistent nodes, temporary nodes, etc. Zookeeper itself has a mature data consistency protocol (ZAB protocol), which can ensure that in a distributed environment, multiple nodes have consistent understanding of the transaction status. For example, when multiple participants access and update transaction status information at the same time, Zookeeper can ensure the sequentiality and atomicity of these operations to avoid data inconsistency.

[0085] In distributed transaction scenarios, Zookeeper can act as a coordinator (i.e., transaction coordination node) to manage transaction status. For example, during a two-phase commit or three-phase commit, Zookeeper can be used to record the status information of each participant and ensure transaction status consistency through its atomic operations (such as creating, updating, and deleting znodes). When the business initiator (i.e., transaction initiating node) and participating systems A and B (i.e., participating nodes) process local transactions, they submit the status of their respective local transactions to the transaction coordinator. The transaction coordinator then centrally manages global transactions, makes the final decision, and informs each participant whether to commit or rollback the transaction, ensuring transaction consistency.

[0086] Specifically, when the transaction initiating node initiates a distributed global transaction instruction to Zookeeper, since Zookeeper is based on the znode tree structure, Zookeeper will create a parent node based on this transaction and save the participating nodes as leaf nodes in the tree structure. Figure 5 , Figure 5 A tree structure diagram of a distributed transaction provided in an embodiment of the present application is shown. When the first transaction initiating node initiates a transaction group creation request to the transaction coordination node, Zookeeper will create a corresponding parent node and create leaf nodes corresponding to each participating node; when other participating nodes submit transaction notifications to the transaction coordination node, Zookeeper will delete the leaf nodes corresponding to the participating nodes. If a participating node fails to submit a transaction notification to the transaction coordination node due to local downtime, network jitter, system anomalies, etc., the leaf nodes will always exist. When all participating nodes successfully execute local transactions, Zookeeper will delete all leaf nodes and parent nodes of the transaction. If a participating node fails to execute a local transaction, Zookeeper will not delete the leaf node. The transaction coordination node can judge the final status of the global transaction execution based on the leaf node.

[0087] Specifically, in some embodiments, the method further includes:

[0088] The participating node monitors the processing status of the local transaction;

[0089] If an abnormality occurs in the processing state, the participating node notifies the transaction coordination node to roll back the local transaction of the participating node.

[0090] In the embodiments of the present application, each participating node can monitor the processing status of its local transaction in real time while processing the target transaction. It is understood that the processing status of a local transaction can include a normal state and an abnormal state. If the current state is normal, processing can continue. If the current state is abnormal, the transaction coordination node can be notified to roll back the local transaction of the participating node.

[0091] Specifically, in some embodiments, the method further includes:

[0092] If the transaction coordination node receives the failure processing notification fed back by the participating node, detecting the total number of the failure processing notifications;

[0093] Determining the proportion of participating nodes that failed processing based on the total number;

[0094] If the ratio is less than or equal to a preset ratio threshold, a retry instruction is sent to a target node; wherein the target node is the participating node that feeds back the failure processing notification, and the retry instruction is used to instruct to reprocess the local transaction;

[0095] If the ratio is greater than the preset ratio threshold, the retry indication is sent to all the participating nodes.

[0096] In an embodiment of the present application, if a participating node fails to process a local transaction, a failure notification may be fed back to the transaction coordinator node. Upon receiving the failure notifications from the participating nodes, the transaction coordinator node may detect the total number of failure notifications and, based on this total number, determine the proportion of participating nodes that failed to process the transaction among all participating nodes. In an embodiment of the present application, a threshold ratio may be pre-set, for example, 50%.

[0097] The participating nodes that feedback the failed processing notification are recorded as target nodes. If the proportion of target nodes is less than or equal to a preset proportion threshold, a retry instruction can be sent only to the target nodes; conversely, if the proportion of target nodes is greater than the preset proportion threshold, a retry instruction is sent to all participating nodes. In this embodiment of the present application, the retry instruction is used to instruct the corresponding node to re-execute the local transaction.

[0098] Specifically, in some embodiments, sending a retry indication to the target node includes:

[0099] Detecting the historical number of times the target node feeds back the failure processing notification;

[0100] If the historical number of times is less than or equal to a preset number threshold, sending a first retry instruction to the target node; wherein the first retry instruction is used to instruct the target node to reprocess the local transaction;

[0101] If the historical number is greater than the preset number threshold, a second retry instruction is sent to the administrator corresponding to the target node; wherein the second retry instruction is used to instruct the administrator to manually intervene in the target node and reprocess the local transaction.

[0102] In an embodiment of the present application, when sending a retry indication, the specific circumstances of the retry indication can be selected according to the execution failure of the target node. For example, the historical number of failed processing notifications fed back by each target node can be detected, and a corresponding number threshold can be set in advance for the historical number. If the historical number corresponding to the target node is less than or equal to the preset number threshold, it means that its current number of retries is low, and the target node can continue to automatically perform the retry task. At this time, a first retry indication can be sent to the target node. In an embodiment of the present application, the first retry indication is used to instruct the target node to perform the retry task on its own, that is, to reprocess the local transaction. Relatively speaking, if the historical number is greater than the preset number threshold, it means that the target node has currently performed multiple retries and there are still failures. At this time, manual intervention can be requested, such as sending a second retry indication to the manager corresponding to the target node; the second retry indication can be used to instruct the manager to manually intervene in the target node so that it can reprocess the local transaction. For example, the second retry indication can be a text message sent to the corresponding manager, which is not limited in the embodiment of the present application.

[0103] It is understood that in the embodiments of the present application, the transaction coordination node coordinates the local transaction status of each node in the distributed system. If the local business processing of each participating node is successful, the transaction coordination node notifies each participating node to commit the local transaction. If the local business processing of a participating node fails, the transaction coordination node notifies it to retry locally until it succeeds. If the number of failures exceeds a certain limit, manual intervention can be performed. If the local business processing of more than half of the participating nodes fails, all participants are notified to roll back the transaction.

[0104] Specifically, in some embodiments, the transaction coordination node implements distributed transaction consistency between the transaction initiating node and each of the participating nodes through a TCC mode.

[0105] In the embodiment of the present application, according to the characteristics of distributed transactions, the transaction coordination node can adopt the TCC mode to achieve distributed transaction consistency. The TCC mode includes three phases: Try-Confirm-Cancel:

[0106] Try phase: This phase attempts to execute business operations, primarily checking and reserving business resources. For example, in an e-commerce system, the inventory system checks for sufficient inventory and reserves the required inventory, while the payment system freezes the required payment amount. All operations in this phase can be rolled back.

[0107] Confirmation phase: Confirms the execution of business operations. If all operations in the Try phase are successful, business operations are officially executed in this phase, such as reducing inventory and completing payments. This phase is irreversible.

[0108] Cancel stage: Cancels the business operation. If an operation fails in the Try stage or an exception occurs in the Confirm stage, resources reserved in the Try stage are rolled back in this stage, such as releasing reserved inventory and unfreezing frozen payment amounts.

[0109] The TCC mode can cope well with high-concurrency scenarios. It requires business code to implement the three logical parts of Try, Confirm, and Cancel. Specifically, the business method can be intercepted based on the interceptor method. The transaction identification information of the global transaction is generated based on the snowflake algorithm. It will be propagated to all microservices (that is, each participating node) through the interceptor and the transaction coordination node will be notified before the method is executed. According to the transaction identification information, if it is a brand new transaction, a new transaction group will be created. If the transaction already exists, the participating nodes participating in the same transaction will be added to the transaction group.

[0110] Please refer to Figure 6 , Figure 6 A flow chart of a business method implemented based on a Java interceptor provided in an embodiment of the present application is shown. In the embodiment of the present application, if no exception occurs in the transaction during the Try phase, the Zookeeper coordination node will notify the transaction participating nodes to execute the Confirm method; if no exception occurs in the Confirm phase, the transaction ends; if an exception occurs in the Confirm phase, the Zookeeper coordination node notifies the transaction participating nodes to execute the Cancel method; if an exception occurs in the Cancel phase, no operation is performed to prevent entering an infinite loop, and subsequent abnormal transactions are recovered through scheduled tasks.

[0111] Before executing the Confirm or Cancel methods, the transaction coordination node records the pre-stored transaction log in Redis and serializes and saves the transaction. If the Confirm or Cancel method successfully executes, the pre-stored transaction log is deleted from Redis. If it fails, the transaction log is not deleted. If an exception occurs during the Confirm or Cancel method, a timer searches for the remaining transaction log, deserializes the transaction object through reflection, and executes the Confirm or Cancel method to recover the transaction. If recovery attempts exceed a configurable number of times, manual recovery is recommended, and the transaction coordination node will not perform further recovery operations.

[0112] The technical solution of this application has at least the following advantages:

[0113] 1. Achieving data consistency across distributed transactions in complex system architectures: In a microservices architecture, business functions are split into multiple small, independently deployed microservices, each of which may have its own database. Distributed transactions ensure the consistency of business operations across multiple microservices and databases.

[0114] 2. Enhanced fault recovery and fault tolerance mechanisms: Distributed transactions usually have fault recovery mechanisms. When the system encounters node failures, network failures, or software anomalies, transactions can be recovered through compensating transactions, retry mechanisms, and other methods.

[0115] 3. Support business innovation and complex business processes: For some complex and long-running business processes, the distributed transaction TCC model provides an effective solution.

[0116] 4. Collaboration among multiple data sources: In the era of big data and artificial intelligence, data sources are becoming increasingly diverse, potentially including relational databases, non-relational databases, file systems, and other data sources. Distributed transactions can enable collaborative operations across these multiple data sources, ensuring consistency in data updates and integration operations across different data sources.

[0117] In an embodiment of the present application, a distributed transaction processing system is also proposed, including a transaction initiating node, a transaction coordinating node, and several participating nodes;

[0118] The transaction initiation node is used to initiate a transaction group creation request to the transaction coordination node, and the transaction coordination node is used to create a corresponding transaction group according to the transaction group creation request; wherein the transaction group creation request includes the participating node information of the target transaction to be processed and the transaction identification information corresponding to the target transaction, and the target transaction is a distributed transaction;

[0119] The transaction initiating node is used to execute the business code corresponding to the target transaction and call several participating nodes to process the target transaction;

[0120] The participating node is used to, in response to the call of the transaction initiating node, initiate a request to the transaction coordinating node to join the transaction group, and process the local transaction called by the transaction initiating node;

[0121] The transaction initiating node is used to send a transaction processing completion notification to the transaction coordinating node, and the transaction coordinating node is used to send a query request to all the participating nodes included in the transaction group; wherein the query request is used to inquire the participating nodes whether the local transaction of the target transaction has been successfully processed;

[0122] The transaction coordination node is used to send a commit instruction to all the participating nodes when the transaction coordination node receives a successful processing notification fed back by all the participating nodes; wherein the commit instruction is used to inform the participating nodes to commit the local transaction corresponding to the target transaction.

[0123] It can be understood that the contents of the above method embodiments are all applicable to the present system embodiments, the functions specifically implemented by the present system embodiments are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.

[0124] Reference Figure 7 , an embodiment of the present application provides a computer device, including:

[0125] at least one processor 710;

[0126] at least one memory 720, for storing at least one program;

[0127] When at least one program is executed by at least one processor 710, the at least one processor 710 implements Figure 2 A distributed transaction processing method is shown.

[0128] Similarly, the contents of the above method embodiments are applicable to the present computer device embodiment. The functions specifically implemented by the present computer device embodiment are the same as those of the above method embodiments, and the beneficial effects achieved are also the same as those achieved by the above method embodiments.

[0129] An embodiment of the present application further provides a computer-readable storage medium storing a program executable by the processor 710 . The program executable by the processor 710 is used to execute the above-mentioned distributed transaction processing method when executed by the processor 710 .

[0130] The present application also discloses a computer-readable storage medium in which a program executable by a processor is stored. When the program is executed by the processor, it is used to implement the following Figure 2 An embodiment of a distributed transaction processing method is shown.

[0131] It is understandable that if Figure 2 The contents of the embodiment of a distributed transaction processing method shown in FIG. 1 are applicable to the embodiment of this computer-readable storage medium. The functions specifically implemented by this computer-readable storage medium embodiment are similar to those in FIG. Figure 2 The embodiment of the method for processing a distributed transaction shown is the same as that shown in FIG. Figure 2 The beneficial effects achieved by the embodiment of the distributed transaction processing method shown are also the same.

[0132] In some optional embodiments, the functions / operations mentioned in the block diagram may not occur in the order mentioned in the operation diagram. For example, depending on the functions / operations involved, the two boxes shown in succession may actually be executed substantially simultaneously or the boxes can sometimes be executed in reverse order. In addition, the embodiments presented and described in the flow chart of the present application are provided in an exemplary manner for the purpose of providing a more comprehensive understanding of the technology. The disclosed method is not limited to the operations and logic flows presented herein. Optional embodiments are contemplated in which the order of the various operations is changed and the sub-operations described as a part of a larger operation are performed independently.

[0133] In addition, although the present application is described in the context of functional modules, it should be understood that, unless otherwise stated, one or more of the functions and / or features can be integrated into a single physical system and / or software module, or one or more functions and / or features can be implemented in separate physical systems or software modules. It is also understood that a detailed discussion of the actual implementation of each module is not necessary for understanding the present application. More specifically, given the properties, functions, and internal relationships of the various functional modules in the system disclosed herein, the actual implementation of the module will be understood within the conventional skills of an engineer. Therefore, those skilled in the art can implement the present application as set forth in the claims using ordinary techniques without undue experimentation. It is also understood that the specific concepts disclosed are merely illustrative and are not intended to limit the scope of the present application, which is determined by the full scope of the appended claims and their equivalents.

[0134] If the function is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present application, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server, or network device, etc.) to execute all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: various media that can store program codes, such as a USB flash drive, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk.

[0135] The logic and / or steps represented in the flowcharts or otherwise described herein, for example, can be considered as an ordered list of executable instructions for implementing the logical functions, and can be embodied in any computer-readable medium for use by, or in conjunction with, an instruction execution system, system, or device (e.g., a computer-based system, a system including a processor, or other system that can fetch instructions from and execute instructions on an instruction execution system, system, or device). For purposes of this specification, a "computer-readable medium" can be any system that can contain, store, communicate, propagate, or transport a program for use by, or in conjunction with, an instruction execution system, system, or device.

[0136] More specific examples (a non-exhaustive list) of computer-readable media include the following: an electrical connection with one or more wires (electronic systems), a portable computer disk cartridge (magnetic systems), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), a fiber optic system, 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, followed by editing, deciphering, or processing in another suitable manner as necessary, and then stored in a computer memory.

[0137] It should be understood that various parts of the present application can be implemented using hardware, software, firmware, or a combination thereof. In the above embodiments, multiple steps or methods can be implemented using software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented using 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 on a data signal, an application-specific integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.

[0138] In the above description of this specification, reference to the terms "one embodiment / example," "another embodiment / example," or "certain embodiments / examples" 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 application. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described can be combined in any appropriate manner in any one or more embodiments or examples.

[0139] Although the embodiments of the present application have been shown and described, those skilled in the art will appreciate that various changes, modifications, substitutions, and variations may be made to the embodiments without departing from the principles and intent of the present application, and that the scope of the present application is defined by the claims and their equivalents.

[0140] The above is a detailed description of the preferred implementation of the present application, but the present application is not limited to the embodiments. Those skilled in the art can make various equivalent modifications or substitutions without violating the spirit of the present application. These equivalent modifications or substitutions are all included in the scope defined by the claims of the present application.

[0141] In the description of this specification, reference to the terms "one embodiment," "another embodiment," or "certain embodiments" 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 application. In this specification, the schematic representation of the above terms does not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials, or characteristics described can be combined in any appropriate manner in any one or more embodiments or examples.

[0142] Although the embodiments of the present application have been shown and described, those skilled in the art will appreciate that various changes, modifications, substitutions, and variations may be made to the embodiments without departing from the principles and intent of the present application, and that the scope of the present application is defined by the claims and their equivalents.

Claims

1. A method for processing distributed transactions, characterized in that: The method comprises: The transaction initiating node initiates a transaction group creation request to the transaction coordinating node, and the transaction coordinating node creates a corresponding transaction group according to the transaction group creation request. The transaction group creation request includes information about participating nodes of the target transaction to be processed and transaction identification information corresponding to the target transaction. The target transaction is a distributed transaction. The transaction initiating node executes the business code corresponding to the target transaction and calls several participating nodes to process the target transaction; The participating node, in response to the call of the transaction initiating node, initiates a request to the transaction coordinating node to join the transaction group, and processes the local transaction called by the transaction initiating node; The transaction initiating node sends a transaction processing completion notification to the transaction coordinating node, and the transaction coordinating node sends a query request to all the participating nodes included in the transaction group; wherein the query request is used to inquire the participating nodes whether the local transaction of the target transaction has been successfully processed; If the transaction coordination node receives successful processing notifications fed back by all the participating nodes, the transaction coordination node sends a commit indication to all the participating nodes; wherein the commit indication is used to inform the participating nodes to commit the local transaction corresponding to the target transaction.

2. A distributed transaction processing method according to claim 1, characterized in that: The transaction coordination node creates a corresponding transaction group according to the transaction group creation request, including: The transaction coordination node detects whether there is a transaction group corresponding to the transaction group creation request; If the transaction group corresponding to the transaction group creation request does not currently exist, create the transaction group; If a transaction group corresponding to the transaction group creation request currently exists, the transaction initiating node is added to the transaction group.

3. A distributed transaction processing method according to claim 1, characterized in that: The transaction coordination node is built based on Zookeeper.

4. A distributed transaction processing method according to any one of claims 1 to 3, characterized in that: The method further comprises: The participating node monitors the processing status of the local transaction; If an abnormality occurs in the processing state, the participating node notifies the transaction coordination node to roll back the local transaction of the participating node.

5. A distributed transaction processing method according to claim 1, characterized in that: The method further comprises: If the transaction coordination node receives the failure processing notification fed back by the participating node, detecting the total number of the failure processing notifications; Determining the proportion of participating nodes that failed processing based on the total number; If the ratio is less than or equal to a preset ratio threshold, a retry instruction is sent to a target node; wherein the target node is the participating node that feeds back the failure processing notification, and the retry instruction is used to instruct to reprocess the local transaction; If the ratio is greater than the preset ratio threshold, the retry indication is sent to all the participating nodes.

6. A distributed transaction processing method according to claim 5, characterized in that: The sending a retry indication to the target node includes: Detecting the historical number of times the target node feeds back the failure processing notification; If the historical number of times is less than or equal to a preset number threshold, sending a first retry instruction to the target node; wherein the first retry instruction is used to instruct the target node to reprocess the local transaction; If the historical number is greater than the preset number threshold, a second retry instruction is sent to the administrator corresponding to the target node; wherein the second retry instruction is used to instruct the administrator to manually intervene in the target node and reprocess the local transaction.

7. A distributed transaction processing method according to claim 1, characterized in that: The transaction coordination node implements distributed transaction consistency between the transaction initiating node and each of the participating nodes through the TCC mode.

8. A distributed transaction processing system, characterized in that: The system includes a transaction initiating node, a transaction coordinating node, and several participating nodes; The transaction initiation node is used to initiate a transaction group creation request to the transaction coordination node, and the transaction coordination node is used to create a corresponding transaction group according to the transaction group creation request; wherein the transaction group creation request includes the participating node information of the target transaction to be processed and the transaction identification information corresponding to the target transaction, and the target transaction is a distributed transaction; The transaction initiating node is used to execute the business code corresponding to the target transaction and call several participating nodes to process the target transaction; The participating node is used to, in response to the call of the transaction initiating node, initiate a request to the transaction coordinating node to join the transaction group, and process the local transaction called by the transaction initiating node; The transaction initiating node is used to send a transaction processing completion notification to the transaction coordinating node, and the transaction coordinating node is used to send a query request to all the participating nodes included in the transaction group; wherein the query request is used to inquire the participating nodes whether the local transaction of the target transaction has been successfully processed; The transaction coordination node is used to send a commit instruction to all the participating nodes when the transaction coordination node receives a successful processing notification fed back by all the participating nodes; wherein the commit instruction is used to inform the participating nodes to commit the local transaction corresponding to the target transaction.

9. A computer device, characterized in that: include: at least one processor; at least one memory for storing at least one program; When the at least one program is executed by the at least one processor, the at least one processor implements a distributed transaction processing method according to any one of claims 1 to 7.

10. A computer-readable storage medium storing a program executable by a processor, characterized in that: The processor-executable program is used to implement a distributed transaction processing method according to any one of claims 1 to 7 when executed by the processor.