CN117632384A - Distributed transaction processing method, device, equipment and storage medium - Google Patents

Distributed transaction processing method, device, equipment and storage medium Download PDF

Info

Publication number
CN117632384A
CN117632384A CN202311635597.2A CN202311635597A CN117632384A CN 117632384 A CN117632384 A CN 117632384A CN 202311635597 A CN202311635597 A CN 202311635597A CN 117632384 A CN117632384 A CN 117632384A
Authority
CN
China
Prior art keywords
transaction
branch
global
chain
transactions
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311635597.2A
Other languages
Chinese (zh)
Inventor
梁向东
曾皓
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Agricultural Bank of China
Original Assignee
Agricultural Bank of China
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Agricultural Bank of China filed Critical Agricultural Bank of China
Priority to CN202311635597.2A priority Critical patent/CN117632384A/en
Publication of CN117632384A publication Critical patent/CN117632384A/en
Pending legal-status Critical Current

Links

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention discloses a distributed transaction processing method, a device, equipment and a storage medium, which are applied to a transaction coordinator, wherein the method comprises the following steps: acquiring a global transaction opening request sent by a transaction manager, and generating a first global transaction identifier according to the global transaction opening request; acquiring a plurality of branch transactions registered by a resource manager, and generating a second global transaction identifier according to transaction modes corresponding to the branch transactions; distributing each branch transaction to a first transaction chain corresponding to a first global transaction identifier and a second transaction chain corresponding to a second global transaction identifier; the transaction processing request sent by the transaction manager is acquired, all the transactions in the first transaction chain and all the transactions in the second transaction chain are sequentially processed according to the transaction processing request, and the method can be suitable for the situation that SAGA mode branch transactions and TCC mode branch transactions exist in distributed transactions at the same time, ensures the consistency of the distributed transactions, and reduces the complexity and cost of the distributed transaction processing.

Description

Distributed transaction processing method, device, equipment and storage medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a distributed transaction processing method, apparatus, device, and storage medium.
Background
A distributed system is a system whose components reside on different networked computers, communicating and coordinating by passing messages to each other. Under the distributed micro-service architecture, how to ensure that transactions distributed in different computing nodes are all successful or all failed is a problem that the distributed transaction needs to solve.
In the prior art, distributed transactions are typically handled by a simple scalable autonomous transaction framework (Simple Extensibl e Autonomous Transaction Architecture, seata). The basic components in the Seata include a transaction Manager (Transaction Manager, TM), a transaction coordinator (Transaction Coordinator, TC), and a Resource Manager (RM). Currently, seata can support SAGA and resource reservation-acknowledgement-revocation (TCC) transaction modes.
However, existing Seata only supports distributed transactions in a single transaction mode. When SAGA mode transaction and TCC mode transaction exist in the transaction processing chain at the same time, the SAGA transaction and TCC transaction can only be manually submitted by a teller, so that the method is complicated and complex, and the workload of the teller is increased. For scenarios like SAGA transactions invoking TCC transactions, the entire transaction processing chain needs to be changed to TCC mode entirely, resulting in wasted program development resources.
Disclosure of Invention
The invention provides a distributed transaction processing method, a device, equipment and a storage medium, which can be suitable for the condition that SAGA mode branch transaction and TCC mode branch transaction exist in distributed transaction at the same time, ensure the consistency of the distributed transaction, save program development resources and reduce the complexity and cost of processing the distributed transaction.
In a first aspect, an embodiment of the present invention provides a distributed transaction processing method, including:
acquiring a global transaction opening request sent by a transaction manager, and generating a first global transaction identifier according to the global transaction opening request;
acquiring a plurality of branch transactions registered by a resource manager, and generating a second global transaction identifier according to transaction modes corresponding to the branch transactions;
the transaction mode is SAGA mode or TTC mode;
distributing each branch transaction to a first transaction chain corresponding to a first global transaction identifier and a second transaction chain corresponding to a second global transaction identifier;
and acquiring transaction processing requests sent by the transaction managers according to the states of the resource managers, and sequentially processing all the transactions in the first transaction chain and all the transactions in the second transaction chain according to the transaction processing requests.
Optionally, before generating the second global transaction identifier according to the transaction mode corresponding to each branch transaction, the method further includes:
and acquiring the service characteristics corresponding to each branch transaction, and determining the transaction mode corresponding to each branch transaction according to the service characteristics corresponding to each branch transaction.
Optionally, generating the second global transaction identifier according to the transaction mode corresponding to each branch transaction includes:
acquiring transaction modes corresponding to historical branch transactions, and judging whether the transaction mode corresponding to the current branch transaction is the same as the transaction mode corresponding to each historical branch transaction;
if not, a second global transaction identification is generated.
Optionally, allocating each branch transaction to a first transaction chain and a second transaction chain corresponding to the first global transaction identifier includes:
judging whether a transaction mode corresponding to the current branch transaction is a first branch transaction or not;
if yes, distributing the current branch transaction to a first transaction chain;
if not, judging whether the transaction mode corresponding to the current branch transaction is the same as the transaction mode corresponding to the first branch transaction;
if yes, distributing the current branch transaction to a first transaction chain;
if not, distributing the current branch transaction to a second transaction chain;
Wherein the first branch transaction is the first branch transaction registered by the resource manager.
Optionally, assigning the current branch transaction to the second transaction chain includes:
establishing an association relation table, wherein the association relation table comprises a corresponding relation between a first global transaction identifier and a second global transaction identifier;
and distributing the current branch transaction to a second transaction chain corresponding to the second global transaction identifier according to the corresponding relation between the first global transaction identifier and the second global transaction identifier.
Optionally, the transaction request includes a global transaction commit request and a global transaction undo request, and according to the transaction request, processing all the transactions in the first transaction chain and all the transactions in the second transaction chain sequentially according to the transaction request includes:
determining a transaction chain processing sequence according to the transaction mode of the branch transaction corresponding to each transaction chain;
and processing the distributed transactions in each transaction chain according to the transaction chain processing sequence and the transaction processing request.
In a second aspect, an embodiment of the present invention further provides a distributed transaction processing apparatus, including:
the first identifier generation module is used for acquiring a global transaction opening request sent by the transaction manager and generating a first global transaction identifier according to the global transaction opening request;
The second identifier generation module is used for acquiring a plurality of branch transactions registered by the resource manager and generating a second global transaction identifier according to the transaction mode corresponding to each branch transaction; the transaction mode is SAGA mode or TTC mode;
the branch transaction allocation module is used for allocating each branch transaction to a first transaction chain corresponding to the first global transaction identifier and a second transaction chain corresponding to the second global transaction identifier;
and the branch transaction processing module is used for acquiring transaction processing requests sent by the transaction managers according to the states of the resource managers and sequentially processing all the transactions in the first transaction chain and all the transactions in the second transaction chain according to the transaction processing requests.
Optionally, the apparatus further comprises:
the transaction mode determining module is used for acquiring the service characteristics corresponding to each branch transaction and determining the transaction mode corresponding to each branch transaction according to the service characteristics corresponding to each branch transaction.
In a third aspect, an embodiment of the present invention further provides an electronic device, including:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein,
the memory stores a computer program executable by the at least one processor to enable the at least one processor to perform the distributed transaction method provided by any one of the embodiments of the present invention.
In a fourth aspect, embodiments of the present invention further provide a computer readable storage medium storing computer instructions for causing a processor to execute the distributed transaction method provided in any of the embodiments of the present invention.
According to the technical scheme provided by the embodiment of the invention, the global transaction starting request sent by the transaction manager is obtained, and the first global transaction identifier is generated according to the global transaction starting request; acquiring a plurality of branch transactions registered by a resource manager, and generating a second global transaction identifier according to transaction modes corresponding to the branch transactions; distributing each branch transaction to a first transaction chain corresponding to a first global transaction identifier and a second transaction chain corresponding to a second global transaction identifier; the technical means for processing all branch transactions in the second transaction chain after the transaction managers acquire transaction processing requests sent by the transaction managers according to the states of the resource managers and sequentially process all branch transactions in the first transaction chain according to the transaction processing requests can be suitable for the condition that SAGA mode branch transactions and TCC mode branch transactions exist in distributed transactions at the same time, the consistency of the distributed transactions is ensured, program development resources are saved, and the complexity and cost for processing the distributed transactions are reduced.
It should be understood that the description in this section is not intended to identify key or critical features of the embodiments of the invention or to delineate the scope of the invention. Other features of the present invention will become apparent from the description that follows.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings required for the description of the embodiments will be briefly described below, and it is apparent that the drawings in the following description are only some embodiments of the present invention, and other drawings may be obtained according to these drawings without inventive effort for a person skilled in the art.
FIG. 1 is a flow chart of a distributed transaction processing method according to a first embodiment of the present invention;
FIG. 2 is a flow chart of another distributed transaction processing method according to a second embodiment of the present invention;
FIG. 3 is a schematic diagram of a distributed transaction processing apparatus according to a third embodiment of the present invention;
fig. 4 is a schematic structural diagram of an electronic device according to a fourth embodiment of the present invention.
Detailed Description
In order that those skilled in the art will better understand the present invention, a technical solution in the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings in which it is apparent that the described embodiments are only some embodiments of the present invention, not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the present invention without making any inventive effort, shall fall within the scope of the present invention.
It should be noted that the terms "first," "second," and the like in the description and the claims of the present invention and the above figures are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that the embodiments of the invention described herein may be implemented in sequences other than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," and "having," and any variations thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed but may include other steps or elements not expressly listed or inherent to such process, method, article, or apparatus.
Example 1
Fig. 1 is a flowchart of a distributed transaction processing method according to an embodiment of the present invention, where the method may be performed by a distributed transaction processing device, and the distributed transaction processing device may be implemented in hardware and/or software, and the distributed transaction processing device may be configured in an electronic device, such as a computer.
As shown in fig. 1, the distributed transaction processing method disclosed in this embodiment is applied to a transaction coordinator, and the method includes:
s110, acquiring a global transaction opening request sent by a transaction manager, and generating a first global transaction identifier according to the global transaction opening request.
In this embodiment, the transaction manager may be used to open, commit or revoke distributed transactions. A distributed transaction (i.e., a global transaction) may be made up of multiple branch transactions. The transaction manager can ensure the transaction consistency of the distributed system by uniformly coordinating all branch transactions.
At this step, specifically, a global transaction initiation request may be sent to the transaction coordinator by the transaction manager after the application sends a distributed transaction request to the transaction manager. Then, a first global transaction identification is generated by the transaction coordinator according to the global transaction initiation request. The first global transaction identification may be used to associate a plurality of branch transactions.
S120, acquiring a plurality of branch transactions registered by the resource manager, and generating a second global transaction identifier according to the transaction mode corresponding to each branch transaction.
Wherein the transaction mode is SAGA mode or TTC mode.
In this embodiment, the first global transaction identifier and the second global transaction identifier may be used to partition branch transactions of different transaction modes. The transaction pattern of each branch transaction corresponding to the second global transaction identification is different from the transaction pattern of each branch transaction corresponding to the first global identification.
At this step, specifically, a second global transaction identifier may be generated according to the registration order and transaction mode of each branch transaction.
For example, after the resource manager registers the first branch transaction, a first global transaction identification may be set for the first branch transaction. After the resource manager registers the second branch transaction, whether to generate the second global transaction identifier can be judged according to the transaction mode corresponding to the second branch transaction. And if the transaction mode corresponding to the second branch transaction is the same as the transaction mode corresponding to the first branch transaction, setting a second global transaction identifier for the second branch transaction. If the transaction pattern corresponding to the second branch transaction is different from the transaction pattern corresponding to the first branch transaction, a second global transaction identification may be generated.
S130, distributing each branch transaction to a first transaction chain corresponding to the first global transaction identifier and a second transaction chain corresponding to the second global transaction identifier.
In this embodiment, the first transaction chain and the second transaction chain may be micro-service invocation links.
In this step, specifically, each branch transaction may be allocated to the first transaction chain or the second transaction chain according to the global transaction identifier corresponding to each branch transaction.
S140, acquiring transaction processing requests sent by the transaction managers according to the states of the resource managers, and processing all the transactions in the first transaction chain and all the transactions in the second transaction chain in sequence according to the transaction processing requests.
In this embodiment, the state of the resource manager may include the preparation of completed and completed branch transactions. The transaction request may include global transaction commit, global transaction undo, and the like. Since the SAGA mode is not suitable for a scenario requiring a risk of funds, and the TCC mode is suitable for a scenario requiring a risk of funds, the branch transactions of the TCC mode may be processed after all the branch transactions of the SAGA mode have been processed.
In one embodiment, the status of each resource manager may be sent to the resource manager. Then, a global transaction commit request or a global transaction undo request may be sent to the transaction coordinator by the resource managers according to the state of each resource manager. For example, if each resource manager has completed preparation for the corresponding branch transaction, a global commit request may be sent. If any resource manager does not complete preparation of the corresponding branch transaction, a global revocation request may be sent.
If the transaction mode of the branch transaction in the first transaction chain is SAGA mode and the transaction mode of the branch transaction in the second transaction chain is TCC mode, all the branch transactions in the first transaction chain can be processed in sequence according to the sequence of the distribution of each branch transaction to the first transaction chain. After all the branch transactions in the first transaction chain are processed, all the branch transactions in the second transaction chain are processed according to the sequence of the distribution of the branch transactions to the second transaction chain.
Illustratively, it is assumed that the combined transaction (i.e., the distributed transaction) includes the following branching transactions: 1000 yuan of deduction is carried out from an account A, 1000 yuan of cash is stored in a user counter, the user counter is transferred to a user account 1980 yuan, and a 20 yuan of commission is charged, so that the account deduction operation is S1, the counter cash deposit operation is S21, the cash box transaction is S22, the user counter is transferred to the user account to be T1, and the commission charge is S3. Because the account deduction operation, counter cash deposit operation, cash box transaction and commission charge are no fund risk for the internal account transaction, and the fund risk exists for transferring into the user account, the transaction mode corresponding to S1, S21, S22 and S3 can be set as SAGA mode, and the transaction mode corresponding to T1 is set as TCC mode. Then, S1, S21, S22, and S3 may be sequentially added to the first transaction chain, and T1 may be added to the second transaction chain. Finally, T1 may be processed after processing S1, S21, S22, and S3 in order. When the transaction request is a global transaction retraction request, T1 may be retracted after submitting the compensation transactions of S3, S22, S21 and S1 in reverse order according to the first transaction chain.
The advantage of setting like this is that, because SAGA mode has the program development volume little, nevertheless has trade inconsistent probably, is unsuitable for the characteristics of the scene that requires fund safety, and TCC mode has the program development volume big, does not have trade inconsistent risk, is suitable for the characteristics of the scene that requires fund safety. Therefore, in practical applications, it is generally required to implement in SAGA mode in a non-funding risk scenario to reduce the development amount of the program, and in TCC mode in a funding risk scenario to avoid the funding risk. According to the technical scheme, the first global transaction identifier and the second global transaction identifier are generated through the transaction mode corresponding to each branch transaction, each branch transaction is distributed to the first transaction chain corresponding to the first global transaction identifier and the second transaction chain corresponding to the second global transaction identifier, all transactions in the first transaction chain and all transactions in the second transaction chain are sequentially processed, and the method can be suitable for the situation that SAGA mode branch transactions and TCC mode branch transactions exist in distributed transactions at the same time, the consistency of the distributed transactions is guaranteed, and the complexity and cost of processing the distributed transactions are reduced. Secondly, compared with the prior art that the distributed implementation mode of the whole distributed transaction is required to be changed into the TCC mode, the technical scheme of the embodiment saves program development resources.
According to the technical scheme of the embodiment, a global transaction starting request sent by a transaction manager is obtained, and a first global transaction identifier is generated according to the global transaction starting request; acquiring a plurality of branch transactions registered by a resource manager, and generating a second global transaction identifier according to transaction modes corresponding to the branch transactions; the transaction mode is SAGA mode or TTC mode; distributing each branch transaction to a first transaction chain corresponding to a first global transaction identifier and a second transaction chain corresponding to a second global transaction identifier; the technical means that transaction managers sequentially process all transactions in a first transaction chain and all transactions in a second transaction chain according to transaction processing requests, and the technical means that the conventional Seata only supports single-mode distributed transactions is solved, so that when SAGA mode transactions and TCC mode transactions exist in a transaction processing chain at the same time, the problem that SAGA transactions and TCC transactions can only be submitted manually by a teller is solved.
Example two
Fig. 2 is a flowchart of another distributed transaction processing method according to a second embodiment of the present invention, which is based on further optimization and expansion of the above embodiments and may be combined with various alternative solutions in the above embodiments.
As shown in fig. 2, a distributed transaction processing method disclosed in this embodiment includes:
s210, acquiring a global transaction opening request sent by a transaction manager, and generating a first global transaction identifier according to the global transaction opening request.
S220, acquiring service characteristics corresponding to each branch transaction registered by the resource manager, and determining a transaction mode corresponding to each branch transaction according to the service characteristics corresponding to each branch transaction.
In this embodiment, the business characteristics may include a risk of having funds, a risk of not having funds, and the like. Branch transactions without a risk of funds may include individual account deductions, counter cash deposits, cash box transactions, and commission authorizations, among others. The funding branch transaction may include a personal account posting, or the like. In practical applications, a branch transaction that does not involve user funds may be referred to as a SAGA mode branch transaction, and a branch transaction that involves user funds may be referred to as a TCC mode branch transaction.
In this step, specifically, if the branch transaction registered by the resource manager has a fund risk, it may be determined that the transaction mode corresponding to the branch transaction is a SAGA mode. If the branch transaction registered by the resource manager has no fund risk, the transaction mode corresponding to the branch transaction can be determined to be TCC mode.
S230, generating a second global transaction identifier according to the transaction mode corresponding to each branch transaction.
In an optional implementation manner of the embodiment of the present invention, generating the second global transaction identifier according to the transaction mode corresponding to each branch transaction includes: acquiring transaction modes corresponding to historical branch transactions, and judging whether the transaction mode corresponding to the current branch transaction is the same as the transaction mode corresponding to each historical branch transaction; if not, a second global transaction identification is generated.
In this embodiment, the historical branch transactions may be branch transactions registered by the resource manager prior to the current branch transaction. Specifically, if the transaction pattern corresponding to the branch transaction before the branch transaction is the same as the transaction pattern corresponding to each historical branch transaction, only the first global transaction identifier may be generated.
Optionally, in the case that the first global transaction identifier and the second global transaction identifier have been generated, if the transaction mode of the current branch transaction is different from the transaction mode corresponding to the historical branch transaction, a third global transaction identifier may be generated.
S240, judging whether the transaction mode corresponding to the current branch transaction is the first branch transaction, if so, executing S250, and if not, executing S260.
In this embodiment, the first branch transaction is the first branch transaction registered by the resource manager.
S250, distributing the current branch transaction to a first transaction chain.
S260, if the transaction mode corresponding to the current branch transaction is the same as the transaction mode corresponding to the first branch transaction, distributing the current branch transaction to a first transaction chain; and if the transaction mode corresponding to the current branch transaction is different from the transaction mode corresponding to the first branch transaction, distributing the current branch transaction to a second transaction chain.
For example, in the case that the transaction mode corresponding to the first branch transaction is the SAGA mode, if the transaction mode corresponding to the current branch transaction is also the SAGA mode, the current branch transaction may be allocated to the first transaction chain. If the transaction mode corresponding to the current branch transaction is TCC mode, the current branch transaction may be assigned to the second transaction chain.
In an alternative implementation of the embodiment of the present invention, the allocating the current branch transaction to the second transaction chain includes: establishing an association relation table, wherein the association relation table comprises a corresponding relation between a first global transaction identifier and a second global transaction identifier; and distributing the current branch transaction to a second transaction chain corresponding to the second global transaction identifier according to the corresponding relation between the first global transaction identifier and the second global transaction identifier.
In this embodiment, optionally, after the first global transaction identifier has been registered by the transaction coordinator, the first branch transaction may be registered by the resource manager with the transaction coordinator, and allocated to the first transaction chain. The transaction mode corresponding to the first branch transaction is SAGA mode. Then, the second branch transaction can be registered with the transaction coordinator through the resource manager, if the transaction mode corresponding to the second branch transaction is TCC mode, an association relation table containing the corresponding relation between the first global transaction identifier and the second global transaction identifier can be established, and the second branch transaction is distributed to a second transaction chain.
And registering the third branch transaction with the transaction coordinator through the resource manager, and judging whether the first global transaction identifier is associated with the second global transaction identifier or not if the transaction mode corresponding to the current branch transaction is the TCC mode. If yes, the current branch transaction can be distributed to a second transaction chain corresponding to the second global transaction identification.
S270, acquiring transaction processing requests sent by the transaction managers according to the states of the resource managers.
S280, determining a transaction chain processing sequence according to the transaction mode of the branch transaction corresponding to each transaction chain; and processing the distributed transactions in each transaction chain according to the transaction chain processing sequence and the transaction processing request.
In this embodiment, the transaction chain processing order may be that all the branch transactions in the first transaction chain are processed, then all the branch transactions in the second transaction chain are processed, or all the branch transactions in the first transaction chain are processed after all the branch transactions in the second transaction chain are processed.
In this step, specifically, if the transaction mode of the first transaction chain corresponding to the branch transaction is the SAGA mode and the transaction mode of the first transaction chain corresponding to the branch transaction is the TCC mode, it may be determined that the transaction chain processing order is that all the branch transactions in the first transaction chain are processed, and then all the branch transactions in the second transaction chain are processed. When the transaction request is a global transaction commit, all branch transactions in the first transaction chain may be committed first, and then all branch transactions in the second transaction chain may be committed. When the transaction request is global transaction retraction, all the branch transactions in the first transaction chain may be retracted after all the branch transactions in the second transaction chain are retracted.
Taking the scenario of TCC transaction nest invoking SAGA transactions as an example, assuming that the distributed transaction includes a retail multi-loan branch transaction (TCC mode) and a cash box branch transaction (SAGA mode), a global transaction in TCC mode may be first started, and a first branch transaction in TCC mode may be allocated to a first transaction chain. And when the second branch transaction called by the first branch transaction is in the SAGA mode, inquiring whether a second global transaction identifier exists or not through the association relation table, wherein the second global transaction identifier corresponds to the SAGA mode. If there is a second global transaction identification (i.e., there is a second transaction chain for SAGA mode), then a second branch transaction may be assigned to the second transaction chain.
In an optional implementation manner of the embodiment of the present invention, when the transaction processing request is global transaction retraction, the transaction mode of the first transaction chain corresponding to the branch transaction is TCC mode, and the transaction mode of the first transaction chain corresponding to the branch transaction is SAGA mode, if any branch transaction in the second transaction chain fails to retract, a retraction failure prompt is sent to the user. Then, all the branch transactions in the second transaction chain are manually reprocessed, and according to the reprocessing result, all the branch transactions in the second transaction chain are processed. The reprocessing result may be that all the branch transactions in the second transaction chain are cancelled successfully or all the branch transactions in the second transaction chain are committed successfully. If all the branch transactions in the second transaction chain are revoked successfully, all the branch transactions in the second transaction chain may be revoked. If all of the branch transactions in the second transaction chain commit successfully, all of the branch transactions in the second transaction chain may be committed.
The advantage of this arrangement is that by processing all the branch transactions in the second transaction chain according to the reprocessing result of all the branch transactions in the second transaction chain, it is possible to achieve synergistic association of the first transaction chain and the second transaction chain with either all success or all failure, ensuring the fund security and consistency of the distributed transactions.
According to the technical scheme of the embodiment, a first global transaction identifier is generated according to a global transaction starting request; acquiring service characteristics corresponding to each branch transaction registered by a resource manager, and determining a transaction mode corresponding to each branch transaction according to the service characteristics corresponding to each branch transaction; generating a second global transaction identifier according to the transaction mode corresponding to each branch transaction; judging whether a transaction mode corresponding to the current branch transaction is a first branch transaction or not; if yes, distributing the current branch transaction to a first transaction chain; if not, if the transaction mode corresponding to the current branch transaction is the same as the transaction mode corresponding to the first branch transaction, distributing the current branch transaction to a first transaction chain; if the transaction mode corresponding to the current branch transaction is different from the transaction mode corresponding to the first branch transaction, distributing the current branch transaction to a second transaction chain; acquiring a transaction request sent by a transaction manager according to the state of each resource manager; determining a transaction chain processing sequence according to the transaction mode of the branch transaction corresponding to each transaction chain; according to the transaction chain processing sequence and the transaction processing request, the technical means of processing the distributed transactions in each transaction chain is achieved, the problem that SAGA mode transaction and TCC mode transaction can only be manually submitted by a teller when the conventional Seata only supports single-mode distributed transactions, so that the SAGA mode branch transaction and TCC mode branch transaction can be manually submitted respectively in the transaction processing chain is solved, the transaction mode of the branch transaction is supported by a developer, the developer only needs to determine the transaction mode of the branch transaction according to the service characteristics of the branch transaction, whether the branch transactions in different transaction modes can be mutually called is not considered, and the cost and complexity of processing the distributed transactions are reduced.
In the technical scheme of the disclosure, the related processes of collecting, storing, using, processing, transmitting, providing, disclosing and the like of the personal information of the user accord with the regulations of related laws and regulations, and the public order colloquial is not violated.
Example III
Fig. 3 is a schematic structural diagram of a distributed transaction processing apparatus according to a third embodiment of the present invention, where the present embodiment is applicable to a case of processing a distributed transaction, and the distributed transaction processing apparatus may be implemented in a form of hardware and/or software and may be configured in an electronic device such as a computer.
As shown in fig. 3, the distributed transaction processing apparatus disclosed in this embodiment includes:
the first identifier generating module 31 is configured to obtain a global transaction start request sent by the transaction manager, and generate a first global transaction identifier according to the global transaction start request;
a second identifier generating module 32, configured to obtain a plurality of branch transactions registered by the resource manager, and generate a second global transaction identifier according to a transaction mode corresponding to each branch transaction; the transaction mode is SAGA mode or TTC mode;
a branch transaction allocation module 33, configured to allocate each branch transaction to a first transaction chain corresponding to the first global transaction identifier and a second transaction chain corresponding to the second global transaction identifier;
And the branch transaction processing module 34 is configured to obtain transaction processing requests sent by the transaction managers according to the states of the resource managers, and sequentially process all transactions in the first transaction chain and all transactions in the second transaction chain according to the transaction processing requests.
According to the technical scheme, through the mutual matching of the first identifier generation module, the second identifier generation module, the branch transaction distribution module and the branch transaction processing module, the problem that when SAGA mode transaction and TCC mode transaction exist in a transaction processing chain at the same time, SAGA transaction and TCC transaction can only be submitted manually by a teller is solved, the method and the device can be applied to the situation that SAGA mode branch transaction and TCC mode branch transaction exist in the distributed transaction at the same time, the consistency of the distributed transaction is ensured, program development resources are saved, and the complexity and cost for processing the distributed transaction are reduced.
Optionally, the device further includes a transaction mode determining module, where the transaction mode determining module is configured to obtain service characteristics corresponding to each branch transaction, and determine a transaction mode corresponding to each branch transaction according to the service characteristics corresponding to each branch transaction.
Optionally, the second identifier generating module 32 includes:
the second identifier generating unit is used for acquiring transaction modes corresponding to the historical branch transactions and judging whether the transaction mode corresponding to the current branch transaction is the same as the transaction mode corresponding to each historical branch transaction; if not, a second global transaction identification is generated.
Optionally, the branching transaction allocation module 33 includes:
the first branch transaction judging unit is used for judging whether the transaction mode corresponding to the current branch transaction is the first branch transaction or not;
the first branch transaction allocation unit is used for allocating the current branch transaction to the first transaction chain if the transaction mode corresponding to the current branch transaction is the first branch transaction;
the transaction pattern matching unit is used for judging whether the transaction pattern corresponding to the current branch transaction is the same as the transaction pattern corresponding to the first branch transaction if the transaction pattern corresponding to the current branch transaction is not the first branch transaction; if yes, distributing the current branch transaction to a first transaction chain; if not, distributing the current branch transaction to a second transaction chain;
wherein the first branch transaction is the first branch transaction registered by the resource manager;
the association relation table establishing unit is used for establishing an association relation table, and the association relation table comprises a corresponding relation between a first global transaction identifier and a second global transaction identifier;
The current transaction allocation unit is used for allocating the current branch transaction to a second transaction chain corresponding to the second global transaction identifier according to the corresponding relation between the first global transaction identifier and the second global transaction identifier.
Optionally, the branching transaction module 34 includes:
the transaction chain processing sequence determining unit is used for determining the transaction chain processing sequence according to the transaction mode of the corresponding branch transaction of each transaction chain;
and the branch transaction processing unit is used for processing the distributed transactions in each transaction chain according to the transaction chain processing sequence and the transaction processing request.
The distributed transaction processing device provided by the embodiment of the invention can execute the distributed transaction processing method provided by any embodiment of the invention, and has the corresponding functional modules and beneficial effects of the execution method. Reference may be made to the description of any method embodiment herein for details not described in this embodiment.
Example IV
Fig. 4 shows a schematic diagram of the structure of an electronic device 10 that may be used to implement an embodiment of the invention. The electronic device 10 is intended to represent various forms of digital computers, such as laptops, desktops, workstations, personal digital assistants, servers, blade servers, mainframes, and other appropriate computers. The electronic device 10 may also represent various forms of mobile equipment, such as personal digital assistants, cellular telephones, smartphones, wearable devices (e.g., helmets, eyeglasses, watches, etc.), and other similar computing equipment. The components shown herein, their connections and relationships, and their functions, are meant to be exemplary only, and are not meant to limit implementations of the inventions described and/or claimed herein.
As shown in fig. 4, the electronic device 10 includes at least one processor 11, and a memory, such as a Read Only Memory (ROM) 12, a Random Access Memory (RAM) 13, etc., communicatively connected to the at least one processor 11, in which the memory stores a computer program executable by the at least one processor, and the processor 11 may perform various appropriate actions and processes according to the computer program stored in the Read Only Memory (ROM) 12 or the computer program loaded from the storage unit 18 into the Random Access Memory (RAM) 13. In the RAM 13, various programs and data required for the operation of the electronic device 10 may also be stored. The processor 11, the ROM 12 and the RAM 13 are connected to each other via a bus 14. An input/output (I/O) interface 15 is also connected to bus 14.
Various components in the electronic device 10 are connected to the I/O interface 15, including: an input unit 16 such as a keyboard, a mouse, etc.; an output unit 17 such as various types of displays, speakers, and the like; a storage unit 18 such as a magnetic disk, an optical disk, or the like; and a communication unit 19 such as a network card, modem, wireless communication transceiver, etc. The communication unit 19 allows the electronic device 10 to exchange information/data with other devices via a computer network, such as the internet, and/or various telecommunication networks.
The processor 11 may be a variety of general and/or special purpose processing components having processing and computing capabilities. Some examples of processor 11 include, but are not limited to, a Central Processing Unit (CPU), a Graphics Processing Unit (GPU), various specialized Artificial Intelligence (AI) computing chips, various processors running machine learning model algorithms, digital Signal Processors (DSPs), and any suitable processor, controller, microcontroller, etc. The processor 11 performs the various methods and processes described above, such as a distributed transaction method.
In some embodiments, the distributed transaction method may be implemented as a computer program tangibly embodied on a computer-readable storage medium, such as storage unit 18. In some embodiments, part or all of the computer program may be loaded and/or installed onto the electronic device 10 via the ROM 12 and/or the communication unit 19. One or more of the steps of the distributed transaction method described above may be performed when the computer program is loaded into RAM 13 and executed by processor 11. Alternatively, in other embodiments, the processor 11 may be configured to perform the distributed transaction method in any other suitable way (e.g., by means of firmware).
Various implementations of the systems and techniques described here above may be implemented in digital electronic circuitry, integrated circuit systems, field Programmable Gate Arrays (FPGAs), application Specific Integrated Circuits (ASICs), application Specific Standard Products (ASSPs), systems On Chip (SOCs), complex Programmable Logic Devices (CPLDs), computer hardware, firmware, software, and/or combinations thereof. These various embodiments may include: implemented in one or more computer programs, the one or more computer programs may be executed and/or interpreted on a programmable system including at least one programmable processor, which may be a special purpose or general-purpose programmable processor, that may receive data and instructions from, and transmit data and instructions to, a storage system, at least one input device, and at least one output device.
A computer program for carrying out methods of the present invention may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general purpose computer, special purpose computer, or other programmable data processing apparatus, such that the computer programs, when executed by the processor, cause the functions/acts specified in the flowchart and/or block diagram block or blocks to be implemented. The computer program may execute entirely on the machine, partly on the machine, as a stand-alone software package, partly on the machine and partly on a remote machine or entirely on the remote machine or server.
In the context of the present invention, a computer-readable storage medium may be a tangible medium that can contain, or store a computer program for use by or in connection with an instruction execution system, apparatus, or device. The computer readable storage medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any suitable combination of the foregoing. Alternatively, the computer readable storage medium may be a machine readable signal medium. More specific examples of a machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
To provide for interaction with a user, the systems and techniques described here can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to a user; and a keyboard and a pointing device (e.g., a mouse or a trackball) through which a user can provide input to the electronic device. Other kinds of devices may also be used to provide for interaction with a user; for example, feedback provided to the user may be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user may be received in any form, including acoustic input, speech input, or tactile input.
The systems and techniques described here can be implemented in a computing system that includes a background component (e.g., as a data server), or that includes a middleware component (e.g., an application server), or that includes a front-end component (e.g., a user computer having a graphical user interface or a web browser through which a user can interact with an implementation of the systems and techniques described here), or any combination of such background, middleware, or front-end components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: local Area Networks (LANs), wide Area Networks (WANs), blockchain networks, and the internet.
The computing system may include clients and servers. The client and server are typically remote from each other and typically interact through a communication network. The relationship of client and server arises by virtue of computer programs running on the respective computers and having a client-server relationship to each other. The server can be a cloud server, also called a cloud computing server or a cloud host, and is a host product in a cloud computing service system, so that the defects of high management difficulty and weak service expansibility in the traditional physical hosts and VPS service are overcome.
It should be appreciated that various forms of the flows shown above may be used to reorder, add, or delete steps. For example, the steps described in the present invention may be performed in parallel, sequentially, or in a different order, so long as the desired results of the technical solution of the present invention are achieved, and the present invention is not limited herein.
The above embodiments do not limit the scope of the present invention. It will be apparent to those skilled in the art that various modifications, combinations, sub-combinations and alternatives are possible, depending on design requirements and other factors. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the scope of the present invention.

Claims (10)

1. A distributed transaction processing method, for use in a transaction coordinator, the method comprising:
acquiring a global transaction starting request sent by a transaction manager, and generating a first global transaction identifier according to the global transaction starting request;
acquiring a plurality of branch transactions registered by a resource manager, and generating a second global transaction identifier according to transaction modes corresponding to the branch transactions;
Wherein the transaction mode is a long transaction solution SAGA mode or a resource reservation-confirmation-revocation TTC mode;
distributing each branch transaction to a first transaction chain corresponding to a first global transaction identifier and a second transaction chain corresponding to a second global transaction identifier;
and acquiring transaction requests sent by the transaction managers according to the states of the resource managers, and processing all the transactions in the first transaction chain and all the transactions in the second transaction chain in sequence according to the transaction requests.
2. The method of claim 1, further comprising, prior to generating the second global transaction identification based on the transaction pattern corresponding to each of the branch transactions:
and acquiring the service characteristics corresponding to the branch transactions, and determining the transaction mode corresponding to the branch transactions according to the service characteristics corresponding to the branch transactions.
3. The method of claim 1, wherein generating the second global transaction identifier according to the transaction pattern corresponding to each branch transaction comprises:
acquiring transaction modes corresponding to historical branch transactions, and judging whether the transaction mode corresponding to the current branch transaction is the same as the transaction mode corresponding to each historical branch transaction;
If not, a second global transaction identification is generated.
4. A method according to claim 3, wherein said assigning each of said branch transactions to a first transaction chain and a second transaction chain corresponding to a first global transaction identity comprises:
judging whether a transaction mode corresponding to the current branch transaction is a first branch transaction or not;
if yes, distributing the current branch transaction to a first transaction chain;
if not, judging whether the transaction mode corresponding to the current branch transaction is the same as the transaction mode corresponding to the first branch transaction;
if yes, distributing the current branch transaction to a first transaction chain;
if not, distributing the current branch transaction to a second transaction chain;
wherein the first branch transaction is the first branch transaction registered by the resource manager.
5. The method of claim 4, wherein said assigning the current branch transaction to a second transaction chain comprises:
establishing an association relation table, wherein the association relation table comprises a corresponding relation between a first global transaction identifier and a second global transaction identifier;
and distributing the current branch transaction to a second transaction chain corresponding to a second global transaction identifier according to the corresponding relation between the first global transaction identifier and the second global transaction identifier.
6. The method of claim 1, wherein the transaction request comprises a global transaction commit request and a global transaction undo request, wherein the sequentially processing all transactions in the first transaction chain and all transactions in the second transaction chain according to the transaction request comprises:
determining a transaction chain processing sequence according to the transaction mode of the branch transaction corresponding to each transaction chain;
and processing the distributed transaction in each transaction chain according to the transaction chain processing sequence and the transaction processing request.
7. A distributed transaction processing apparatus for use with a transaction coordinator, the apparatus comprising:
the first identifier generation module is used for acquiring a global transaction opening request sent by the transaction manager and generating a first global transaction identifier according to the global transaction opening request;
the second identifier generation module is used for acquiring a plurality of branch transactions registered by the resource manager and generating a second global transaction identifier according to the transaction mode corresponding to each branch transaction; wherein the transaction mode is a long transaction solution SAGA mode or a resource reservation-confirmation-revocation TTC mode;
The branch transaction allocation module is used for allocating each branch transaction to a first transaction chain corresponding to the first global transaction identifier and a second transaction chain corresponding to the second global transaction identifier;
and the branch transaction processing module is used for acquiring transaction processing requests sent by the transaction managers according to the states of the resource managers and sequentially processing all transactions in the first transaction chain and all transactions in the second transaction chain according to the transaction processing requests.
8. The apparatus of claim 7, wherein the apparatus further comprises:
the transaction mode determining module is used for obtaining the service characteristics corresponding to the branch transactions and determining the transaction modes corresponding to the branch transactions according to the service characteristics corresponding to the branch transactions.
9. An electronic device, the electronic device comprising:
at least one processor; and
a memory communicatively coupled to the at least one processor; wherein,
the memory stores a computer program executable by the at least one processor to enable the at least one processor to perform the distributed transaction method of any of claims 1-6.
10. A computer readable storage medium storing computer instructions for causing a processor to perform the distributed transaction method of any of claims 1-6.
CN202311635597.2A 2023-11-30 2023-11-30 Distributed transaction processing method, device, equipment and storage medium Pending CN117632384A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311635597.2A CN117632384A (en) 2023-11-30 2023-11-30 Distributed transaction processing method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311635597.2A CN117632384A (en) 2023-11-30 2023-11-30 Distributed transaction processing method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN117632384A true CN117632384A (en) 2024-03-01

Family

ID=90017840

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311635597.2A Pending CN117632384A (en) 2023-11-30 2023-11-30 Distributed transaction processing method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN117632384A (en)

Similar Documents

Publication Publication Date Title
US9055065B2 (en) Managing participant order in distributed transactions
CN114564435A (en) Inter-core communication method, device and medium for heterogeneous multi-core chip
CN115544044A (en) Data consistency keeping method, device, equipment and storage medium
CN113377875B (en) Cross-chain data processing method and device, electronic equipment and readable storage medium
CN114327799A (en) Distributed transaction processing method and device, electronic equipment and storage medium
CN113297329A (en) Transaction processing method, device, equipment, storage medium and program product
CN112819638A (en) Transaction weight judging method, device, equipment and computer readable medium
CN115328621B (en) Transaction processing method, device, equipment and storage medium based on block chain
CN111143040A (en) Transaction processing method, device, system and storage medium
CN117632384A (en) Distributed transaction processing method, device, equipment and storage medium
CN112988738B (en) Data slicing method and device for block chain
CN114579311A (en) Method, apparatus, device and storage medium for executing distributed computing task
US20210240698A1 (en) Asynchronous remote calls with undo data structures
CN115145997A (en) Distributed transaction implementation method and distributed system
CN111866171B (en) Message processing method, device, electronic equipment and medium
CN114584605B (en) Service distribution method and device, electronic equipment and storage medium
CN114896258B (en) Transaction data synchronization method and device, computer equipment and storage medium
CN117520362B (en) Data management system, method, equipment and storage medium based on distributed lock
CN113110921B (en) Operation method, device, equipment and storage medium of block chain system
CN116302368A (en) Distributed transaction processing method, device, equipment and storage medium
CN115913954A (en) Cluster management information interaction method, device, equipment and storage medium
CN114637738A (en) Data visibility judgment method and device, database node and medium
CN115237968A (en) Node management method, device, equipment and storage medium in database system
CN115907779A (en) Transaction proposal verification method, device, server and storage medium
CN116301634A (en) Method, device, equipment and medium for detecting resource interaction state

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination