Distributed Transaction Processing Method, Device, Electronic Device and Storage Medium
By deploying coordination procedures separately on distributed transaction initiators and participants, generating and coordinating global and branch transaction identifiers, the problems of high resource occupation and low reliability of distributed transaction coordinators are solved, and more efficient resource utilization and reliability are achieved.
Patent Information
- Application Number
- CN202211500930.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-28
- Publication Date
- 2025-07-25
- Estimated Expiration
- 2042-11-28
AI Technical Summary
The distributed transaction coordinator has high system resource utilization, high hardware cost and low reliability, and the network interaction process is unreliable.
The distributed transaction initiator and participant are used to deploy the first and second coordination programs respectively, generate global and branch transaction identifiers, coordinate the processing of distributed transactions, detect branch transaction status, and store the results when committing.
It reduces system resource usage, reduces hardware costs, and improves the reliability of network interaction.
Smart Images

Figure CN116166387B_ABST
Abstract
Description
Technical Field
[0001] The present disclosure relates to the technical field, and in particular, to a distributed transaction processing method, a distributed transaction processing apparatus, an electronic device, and a storage medium. Background Art
[0002] A transaction refers to a sequence of operations composed of one or more resource management operations. A distributed transaction refers to a transaction in which the operations in the operation sequence involve multiple databases.
[0003] In the related art, in order to ensure that all data of a transaction remains in a consistent state, that is, data consistency, an independent distributed transaction coordinator is deployed. The distributed transaction coordinator interacts with the distributed transaction initiator and multiple distributed transaction participants to coordinate the processing results of the multiple distributed transaction participants and promote the progress of the distributed transaction. However, in the process of processing a distributed transaction, due to the influence of the distributed transaction coordinator itself, there are problems of high system resource occupancy and high hardware cost, and the interaction process between the distributed transaction coordinator, the distributed transaction initiator, and multiple distributed transaction participants is greatly affected by the network and has low reliability.
[0004] It should be noted that the information disclosed in the above background art section is only used to enhance the understanding of the background of the present disclosure, and thus may include information that does not constitute the prior art known to those of ordinary skill in the art. Summary of the Invention
[0005] The purpose of the present disclosure is to provide a distributed transaction processing method, a distributed transaction processing apparatus, an electronic device, and a storage medium, which can reduce system resource occupancy and improve reliability.
[0006] According to one aspect of the present disclosure, a distributed transaction processing method is provided, including: a distributed transaction initiator sends transaction information of a distributed transaction and a global transaction identifier to at least two distributed transaction participants through a first coordinator; wherein, the first coordinator is deployed on the server where the distributed transaction initiator is located, and the first coordinator is used to coordinate the processing of the distributed transaction, and the global transaction identifier is an identifier generated by the first coordinator for indicating the distributed transaction; after each distributed transaction participant sends the global transaction identifier to a plurality of second coordinators, each second coordinator generates a plurality of branch transaction identifiers; wherein, the second coordinator is deployed on the server where the distributed transaction participant is located, and the second coordinator is used to coordinate the processing of the branch transaction on the server where the second coordinator is located, and the branch transaction identifier is an identifier for indicating a branch transaction, and the distributed transaction includes branch transactions; each distributed transaction participant processes the branch transaction to obtain a processing result, so that the distributed transaction initiator adjusts the status of the branch transaction identifier according to the processing result; wherein, the status of the branch transaction identifier is used to indicate the processing stage of the branch transaction; when it is detected that the branch transaction identifier is in a committed state, the processing result is stored in the database, so that the branch transaction processing is completed; wherein, the committed state means that the distributed transaction participant determines that the processing result is correct.
[0007] In an exemplary embodiment of the present disclosure, before the distributed transaction initiator sends the transaction information of the distributed transaction and the global transaction identifier to at least two distributed transaction participants through the first coordinator, the method further includes: the distributed transaction initiator sends a transaction start request to the first coordinator; the first coordinator generates a global transaction identifier according to the transaction information, and sends the global transaction identifier and the transaction information to the distributed transaction initiator.
[0008] In an exemplary embodiment of the present disclosure, to store the processing result in the database so that the branch transaction processing is completed, the method further includes: the first coordinator stores the transaction information in the database; updates the transaction information according to the processing result, so that the branch transaction processing is completed; wherein, the processing result is an addition, deletion, or change to the transaction information.
[0009] In an exemplary embodiment of the present disclosure, for each second coordinator to generate a plurality of branch transaction identifiers, the method further includes: each distributed transaction participant sends the global transaction identifier to each second coordinator; a plurality of second coordinators generate a plurality of branch transaction identifiers according to the global transaction identifier; the second coordinator stores the plurality of branch transaction identifiers in the database, and updates the status of each branch transaction identifier to an execution state; wherein, the execution state is a state indicating the processing stage of each distributed transaction participant for each branch transaction.
[0010] In an exemplary embodiment of the present disclosure, when it is detected that the branch transaction identifier is in the committed state, the processing result is stored in the database. The method further includes: after each distributed transaction participant completes each branch transaction according to the transaction information, sending the processing result to the distributed transaction initiator; after the distributed transaction initiator confirms that the processing result is correct, the distributed transaction initiator sends a transaction commit instruction to the first coordinator; the first coordinator updates the state of the branch transaction identifier in the database from the execution state to the committed state; after the second coordinator detects that the state of the branch transaction identifier is the committed state, sending a commit instruction to the distributed transaction participants; in response to the commit instruction, each distributed transaction participant stores the processing result in the database.
[0011] In an exemplary embodiment of the present disclosure, after sending the processing result to the distributed transaction initiator after each branch transaction is completed according to the transaction information, the method further includes: when the distributed transaction initiator detects that the processing result is incorrect, the distributed transaction initiator sends a transaction rollback instruction to the first coordinator; the first coordinator updates the state of the branch transaction identifier in the database from the execution state to the rollback state; wherein, the rollback state is a stage indicating that each distributed transaction participant deletes the processing result; after the second coordinator detects that the state of the branch transaction identifier is the rollback state, sending a rollback instruction to the distributed transaction participants; in response to the rollback instruction, each distributed transaction participant deletes the processing result.
[0012] In an exemplary embodiment of the present disclosure, the method further includes: at the beginning of the distributed transaction, the distributed transaction initiator sends a preset time to the first coordinator; when the first coordinator does not receive a transaction commit instruction within the preset time, the first coordinator updates the state of the branch transaction identifier in the database from the execution state to the rollback state.
[0013] In an exemplary embodiment of the present disclosure, the method further includes: the second coordination program stores multiple branch transaction identifiers in a database; when the target second coordination program detects a faulty distributed transaction participant, the target second coordination program obtains the faulty branch transaction identifier through the database; wherein, the target second coordination program is the second coordination program of the server where the target distributed transaction participant is located, the target distributed transaction participant is one of at least one healthy distributed transaction participant, the faulty branch transaction identifier is the branch transaction identifier corresponding to the faulty distributed transaction participant, the faulty branch transaction identifier contains a faulty identity identifier, and the faulty identity identifier is the identifier of the second coordination program of the server where the faulty distributed transaction participant is located; the target second coordination program deletes the faulty identity identifier from the faulty branch transaction identifier and inserts a healthy identity identifier into the faulty branch transaction identifier; wherein, the healthy identity identifier is the identity identifier of the second coordination program; the database updates the second coordination program corresponding to the faulty branch transaction identifier to the target second coordination program, so that the target distributed transaction participant processes the branch transaction corresponding to the faulty distributed transaction participant.
[0014] According to one aspect of the present disclosure, there is provided a distributed transaction processing apparatus, including a transmission module configured to send transaction information of a distributed transaction and a global transaction identifier by a first coordination program from a distributed transaction initiator to at least two distributed transaction participants; wherein, the first coordination program is deployed on the server where the distributed transaction initiator is located, and the first coordination program is configured to coordinate and process the distributed transaction, and the global transaction identifier is an identifier generated by the first coordination program for indicating the distributed transaction; a generation module configured to, after each distributed transaction participant sends the global transaction identifier to multiple second coordination programs, each second coordination program generates multiple branch transaction identifiers; wherein, the second coordination program is deployed on the server where the distributed transaction participant is located, the second coordination program is configured to coordinate and process the branch transaction of the server where the second coordination program is located, the branch transaction identifier is an identifier for indicating a branch transaction, and the distributed transaction includes branch transactions; a processing module configured to each distributed transaction participant processes the branch transaction to obtain a processing result, so that the distributed transaction initiator adjusts the status of the branch transaction identifier according to the processing result; wherein, the status of the branch transaction identifier is used to indicate the processing stage of the branch transaction; an update module configured to, when it is detected that the branch transaction identifier is in a committed state, store the processing result in a database, so that the branch transaction processing is completed; wherein, the committed state means that the distributed transaction participant determines that the processing result is correct.
[0015] According to one aspect of the present disclosure, there is provided an electronic device, including: a processor; and a memory configured to store executable instructions of the processor; wherein, the processor is configured to execute the executable instructions to perform the distributed transaction processing method of any one of the above embodiments.
[0016] According to one aspect of the present disclosure, there is provided a computer-readable storage medium. When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the distributed transaction processing method of any one of the above embodiments.
[0017] The exemplary embodiments of the present disclosure may have some or all of the following beneficial effects:
[0018] In the distributed transaction processing method provided by the exemplary embodiment of the present disclosure, the distributed transaction initiator sends the transaction information of the distributed transaction and the global transaction identifier to at least two distributed transaction participants through a first coordinator; after each distributed transaction participant sends the global transaction identifier to a plurality of second coordinators, each second coordinator generates a plurality of branch transaction identifiers; each distributed transaction participant processes the branch transaction to obtain a processing result, so that the distributed transaction initiator adjusts the status of the branch transaction identifier according to the processing result; when it is detected that the branch transaction identifier is in a committed state, the processing result is stored in the database, so that the branch transaction processing is completed. On the one hand, a coordinator is installed in the servers where the distributed transaction initiator and each distributed transaction participant are located. This coordinator only focuses on the transactions of the current node, reduces the processing of other transactions, and reduces the resource occupation; on the other hand, the coordinator is installed on the same server as the distributed transaction initiator or the distributed transaction participant, and there is no additional loss at the network level, improving the interaction reliability; on the further hand, the coordinator is a micro program, reducing the deployment cost.
[0019] It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and cannot limit the present disclosure. BRIEF DESCRIPTION OF THE DRAWINGS
[0020] The accompanying drawings herein are incorporated into the specification and constitute a part of this specification, showing embodiments consistent with the present disclosure and used together with the specification to explain the principles of the present disclosure. Obviously, the accompanying drawings in the following description are only some embodiments of the present disclosure, and those of ordinary skill in the art can obtain other drawings based on these drawings without creative efforts.
[0021] Figure 1 Schematically shows a schematic diagram of the system architecture of the distributed transaction processing method according to an embodiment of the present disclosure.
[0022] Figure 2 Schematically shows a flowchart of the distributed transaction processing method according to an embodiment of the present disclosure.
[0023] Figure 3 Schematically shows a flowchart of the method for transmitting transaction information according to an embodiment of the present disclosure.
[0024] Figure 4 Schematically shows a flowchart of a method for updating transaction information according to an embodiment of the present disclosure.
[0025] Figure 5 Schematically shows a flowchart of a method for generating a branch transaction identifier according to an embodiment of the present disclosure.
[0026] Figure 6 Schematically shows a schematic diagram of a distributed transaction preparation phase according to an embodiment of the present disclosure.
[0027] Figure 7 Schematically shows a flowchart of a distributed transaction commit phase according to an embodiment of the present disclosure.
[0028] Figure 8 Schematically shows a schematic diagram of a distributed transaction commit phase according to an embodiment of the present disclosure.
[0029] Figure 9 Schematically shows a flowchart of a rollback transaction processing result according to an embodiment of the present disclosure.
[0030] Figure 10 Schematically shows a schematic diagram of a distributed transaction rollback phase according to an embodiment of the present disclosure.
[0031] Figure 11 Schematically shows a schematic diagram of a rollback transaction processing result according to a preset time according to an embodiment of the present disclosure.
[0032] Figure 12 Schematically shows a schematic diagram of a distributed transaction rollback according to a preset time according to an embodiment of the present disclosure.
[0033] Figure 13 Schematically shows a flowchart of a disaster recovery master selection according to an embodiment of the present disclosure.
[0034] Figure 14 Schematically shows a schematic diagram of a coordinator declaring sovereignty over a branch transaction according to an embodiment of the present disclosure.
[0035] Figure 15 Schematically shows a schematic diagram of a coordinator disaster recovery master selection according to an embodiment of the present disclosure.
[0036] Figure 16 Schematically shows a block diagram of a distributed transaction processing apparatus according to an embodiment of the present disclosure.
[0037] Figure 17 Shows a schematic diagram of the structure of a computer system of an electronic device suitable for implementing the embodiments of the present disclosure. Detailed implementation manners
[0038] Example embodiments will now be described more fully with reference to the accompanying drawings. However, the example embodiments can be implemented in various forms and should not be construed as limited to the examples set forth herein; rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the concept of the example embodiments to those skilled in the art. The features, structures, or characteristics described may be combined in any suitable manner in one or more embodiments. In the following description, numerous specific details are provided to give a thorough understanding of the embodiments of the present disclosure. However, those skilled in the art will recognize that the technical solutions of the present disclosure may be practiced without one or more of the specific details, or may be implemented using other methods, components, devices, steps, etc. In other instances, well-known technical solutions are not shown or described in detail to avoid obscuring aspects of the present disclosure.
[0039] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagram may represent a module, a segment of code, or a part of code that contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions noted in the blocks may occur in a different order than noted in the drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, or they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram or flowchart, and combinations of blocks in the block diagram or flowchart, can be implemented by a dedicated hardware-based system that performs the specified function or operation, or can be implemented by a combination of dedicated hardware and computer instructions.
[0040] The units described in the embodiments of the present disclosure can be implemented in software or in hardware, and the described units can also be provided in a processor. Among them, the names of these units do not, in some cases, constitute a limitation on the unit itself.
[0041] Figure 1 A schematic diagram of a system architecture of an exemplary application environment of a distributed transaction processing method and apparatus to which the embodiments of the present disclosure can be applied is shown.
[0042] As Figure 1As shown, the system architecture 100 may include a distributed transaction initiator (TM, Transaction Manager) 101, one or more of distributed transaction participants (RM, Resource Manager) 102, 103, 104, a network 105, and a database 106. The network 105 is used to provide a medium for communication links between the TM, RM, and the database 106. Among them, the distributed transaction initiator can be any electronic device with the function of initiating a distributed transaction. For example, it can be a terminal device or a server. Terminal devices include but are not limited to smartphones, tablets, laptop computers, computers, intelligent voice interaction devices, smart home appliances, vehicle-mounted terminals, etc.; the server can be a server that provides various services. It can be an independent physical server, a server cluster or a distributed system 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. This is not limited here. The distributed transaction participant can be any electronic device with the function of processing branch transactions. For example, it can be the above terminal device and server.
[0043] The distributed transaction processing method provided by the embodiments of the present disclosure can be executed in 100. Specifically, the distributed transaction initiator sends the transaction information of the distributed transaction and the global transaction identifier to at least two distributed transaction participants through a first coordinator. After each distributed transaction participant sends the global transaction identifier to multiple second coordinators, each second coordinator generates multiple branch transaction identifiers. Each distributed transaction participant processes the branch transaction to obtain a processing result, so that the distributed transaction initiator adjusts the status of the branch transaction identifier according to the processing result. When it is detected that the branch transaction identifier is in the committed state, the processing result is stored in the database, so that the branch transaction processing is completed.
[0044] A transaction refers to a sequence of operations consisting of one or more resource management operations. A distributed transaction refers to a transaction in which the operations in the operation sequence involve multiple databases. In related technologies, in order to ensure that all data of a transaction maintains a consistent state, that is, data consistency, an independent distributed transaction coordinator is deployed. The distributed transaction coordinator interacts with the distributed transaction initiator and multiple distributed transaction participants to coordinate the processing results of multiple distributed transaction participants and promote the progress of the distributed transaction. However, in the process of processing a distributed transaction, limited by the influence of the distributed transaction coordinator itself, there are problems of high system resource occupancy and high hardware cost, and the interaction process between the distributed transaction coordinator, the distributed transaction initiator, and multiple distributed transaction participants is greatly affected by the network and has unreliability.
[0045] The distributed transaction processing method provided by the embodiments of the present disclosure is applicable to various distributed transaction modes, such as the AT (Auto Transaction) mode, the TCC (Try-Confirm-Cancel) mode, the XA (Extended Architecture) mode, and other distributed transaction modes, which are not limited herein.
[0046] In an exemplary embodiment of the present disclosure, a distributed transaction processing method is provided. Refer to Figure 2 As shown, the distributed transaction processing method may include the following steps:
[0047] Step S210, the distributed transaction initiator sends the transaction information of the distributed transaction and the global transaction identifier to at least two distributed transaction participants through a first coordinator; wherein, the first coordinator is deployed on the server where the distributed transaction initiator is located, and the first coordinator is used to coordinate the processing of the distributed transaction, and the global transaction identifier is an identifier generated by the first coordinator for indicating the distributed transaction;
[0048] Step S220, after each distributed transaction participant sends the global transaction identifier to multiple second coordinators, each second coordinator generates multiple branch transaction identifiers; wherein, the second coordinator is deployed on the server where the distributed transaction participant is located, and the second coordinator is used to coordinate the processing of the branch transaction on the server where the second coordinator is located. The branch transaction identifier is an identifier for indicating the branch transaction, and the distributed transaction includes branch transactions;
[0049] Step S230, each distributed transaction participant processes the branch transaction to obtain a processing result, so that the distributed transaction initiator adjusts the status of the branch transaction identifier according to the processing result; wherein, the status of the branch transaction identifier is used to indicate the processing stage of the branch transaction.
[0050] In step S240, when it is detected that the branch transaction identifier is in the committed state, the processing result is stored in the database to complete the branch transaction processing; wherein, the committed state means that the distributed transaction participant determines that the processing result is correct.
[0051] Next, the above steps will be described in more detail.
[0052] In an exemplary embodiment of the present disclosure, a distributed transaction processing method is provided. Referring to Figure 2 As shown, the distributed transaction processing method includes the following steps S210 to S240:
[0053] In step S210, the distributed transaction initiator sends the transaction information of the distributed transaction and the global transaction identifier to at least two distributed transaction participants through a first coordinator.
[0054] In an exemplary embodiment of the present disclosure, the distributed transaction initiator sends the transaction information of the distributed transaction and the global transaction identifier to at least two distributed transaction participants through a first coordinator. Among them, the first coordinator is deployed on the server where the distributed transaction initiator is located, and the first coordinator is used to coordinate and process the distributed transaction. The global transaction identifier is an identifier generated by the first coordinator to indicate the distributed transaction. For example, the first coordinator can be a sidecar auxiliary program for coordinating and processing the distributed transaction. The distributed transaction can be a transfer service. The global transaction identifier can be XID = 123. The distributed transaction initiator and the distributed transaction participants can be application programs for processing transfer services. The distributed transaction information can be transfer service information such as the balance of the transfer-out account being 100 yuan, the balance of the transfer-in account being 100 yuan, and the transfer amount being 10 yuan.
[0055] Specifically, after the distributed transaction starts, the distributed transaction initiator will obtain the transaction information and the global transaction identifier of the distributed transaction, and send the above transaction information and the global transaction identifier to all distributed transaction participants through the first coordinator deployed on the same server as the distributed transaction initiator.
[0056] For example, the first coordination program can be a sidecar auxiliary program for implementing coordinated processing of distributed transactions. The distributed transaction can be a fund transfer service, the global transaction identifier can be XID = 123, the distributed transaction initiator and the distributed transaction participants can be application programs for processing fund transfer services, and the distributed transaction information can be fund transfer service information such as the balance of the transfer-out account being 100 yuan, the balance of the transfer-in account being 100 yuan, and the transfer amount being 10 yuan. After the fund transfer service starts, the distributed service participants obtain service information such as the balance of the transfer-out account being 100 yuan, the balance of the transfer-in account being 100 yuan, and the transfer amount being 10 yuan, as well as the global transaction identifier XID = 123, and send the above service information and global transaction identifier to all distributed service participants through the sidecar program deployed on the same server as the distributed transaction initiator.
[0057] In step S220, after each distributed transaction participant sends the global transaction identifier to multiple second coordination programs, each second coordination program generates multiple branch transaction identifiers.
[0058] In an exemplary embodiment of the present disclosure, after each distributed transaction participant sends the global transaction identifier to multiple second coordination programs, each second coordination program generates multiple branch transaction identifiers. Among them, the second coordination program is deployed on the server where the distributed transaction participant is located. The second coordination program is used to coordinate and process the branch transactions on the server where the second coordination program is located. The branch transaction identifier is an identifier used to indicate a branch transaction, and the distributed transaction includes branch transactions. For example, the distributed transaction consists of multiple branch transactions, and the fund transfer service consists of deducting the corresponding amount from the transfer-out account and adding the corresponding amount to the transfer-in account. The second coordination program can be a sidecar auxiliary program, and the branch transaction identifier can be one or more of branchid = 1 and branchid = 2.
[0059] Specifically, after the second coordination program on the server where each distributed transaction participant is located receives the transaction information and the global transaction identifier sent by the distributed transaction initiator, it generates corresponding branch transaction identifiers according to the global transaction identifier.
[0060] For example, the distributed transaction is a fund transfer operation, which consists of two sub - transactions: deducting the corresponding amount from the transfer - out account and adding the corresponding amount to the transfer - in account. The second coordinator is a sidecar assistant program deployed on the same server as the distributed transaction participants. The sub - transaction identifiers can be branchid = 1 and branchid = 2. After receiving the global transaction identifier XID = 123 of the fund transfer operation, the second coordinator on the server where each distributed transaction participant is located generates the corresponding sub - transaction identifier for the distributed transaction participant according to XID = 123. For example, the sidecar assistant program deployed on the server where the distributed service participant responsible for deducting the balance of the transfer - out account is located generates the sub - transaction identifier branchid = 1, and the sidecar assistant program deployed on the server where the distributed service participant responsible for adding the balance of the transfer - in account is located generates the sub - transaction identifier branchid = 2.
[0061] In step S230, each distributed transaction participant processes the sub - transaction to obtain a processing result, so that the distributed transaction initiator adjusts the status of the sub - transaction identifier according to the processing result.
[0062] In an exemplary embodiment of the present disclosure, each distributed transaction participant processes the sub - transaction to obtain a processing result, so that the distributed transaction initiator adjusts the status of the sub - transaction identifier according to the processing result. Wherein, the status of the sub - transaction identifier is used to indicate the processing stage of the sub - transaction. For example, the status of the sub - transaction identifier can be one of the execution status, the commit status, and the rollback status.
[0063] Specifically, each distributed original transaction participant processes each sub - transaction to obtain a processing result, and the distributed transaction initiator changes the status of the sub - transaction identifier to the commit status or the rollback status according to the processing result.
[0064] For example, the status of the sub - transaction identifier can be one of the execution status, the commit status, and the rollback status. After each distributed transaction participant processes each sub - transaction to obtain a processing result, the distributed transaction initiator checks the processing result. If the processing results of all sub - transactions are correct, the status of the sub - transaction identifier is changed to the commit status; if the processing result of any sub - transaction is incorrect, the status of the sub - transaction identifier is changed to the rollback status.
[0065] In step S240, when it is detected that the sub - transaction identifier is in the commit status, the processing result is stored in the database to complete the processing of the sub - transaction.
[0066] In an exemplary embodiment of the present disclosure, when each distributed transaction participant detects that the branch transaction identifier is in a committed state, the processing result is stored in a database so that the branch transaction processing is completed. Among them, the committed state means that the distributed transaction participant determines that the processing result is correct. For example, the database can be one of distributed memories such as redis (Remote Dictionary Server), zookeeper (a distributed, open-source distributed application coordination service), mysql, etc. The branch transaction is to deduct 10 yuan based on the balance of 100 yuan in the transfer-out account and add 10 yuan based on the balance of 100 yuan in the transfer-in account. The processing result is that the balance of the transfer-out account is 90 yuan and the balance of the transfer-in account is 110 yuan.
[0067] Specifically, after each second coordinator detects that the branch transaction identifier is in a committed state, a commit instruction is sent to the distributed transaction participant of the server where the second coordinator is located. After receiving the commit instruction, the distributed transaction participant stores the processing result in the database.
[0068] For example, the database is a zookeeper distributed memory. The branch transaction is to deduct 10 yuan based on the balance of 100 yuan in the transfer-out account and add 10 yuan based on the balance of 100 yuan in the transfer-in account. The processing result is that the balance of the transfer-out account is 90 yuan and the balance of the transfer-in account is 110 yuan. When the sidecar auxiliary program (second coordinator) of the server where each distributed transaction participant is located detects that the status of branchid = 1 and branchid = 2 is in a committed state, a commit instruction is sent to the distributed transaction participant. After receiving the commit instruction, the distributed transaction participant stores the data with the balance of 90 yuan in the transfer-out account and the balance of 110 yuan in the transfer-in account in the zookeeper distributed memory.
[0069] In an exemplary embodiment of the present disclosure, the distributed transaction initiator sends a transaction start request to the first coordinator. The first coordinator generates a global transaction identifier based on the transaction information and sends the global transaction identifier and the transaction information to the distributed transaction initiator. Specifically, as shown in Figure 3 shown, passing the transaction information may include the following steps S310 to S320:
[0070] In step S310, the distributed transaction initiator sends a transaction start request to the first coordinator.
[0071] In an exemplary embodiment of the present disclosure, the distributed transaction initiator sends a transaction start request to the first coordinator. Among them, the transaction start request is a message containing information related to the start of the transaction. For example, the transaction start request is a begin request.
[0072] Specifically, at the beginning of a distributed transaction, the client sends a request to process the distributed transaction to the initiator of the distributed transaction. After receiving the request to process the distributed transaction, the initiator of the distributed transaction generates a begin request and sends the begin request to the first coordinator.
[0073] In step S320, the first coordinator generates a global transaction identifier based on the transaction information, and sends the global transaction identifier and the transaction information to the initiator of the distributed transaction.
[0074] In an exemplary embodiment of the present disclosure, the first coordinator generates a global transaction identifier based on the transaction information, and sends the global transaction identifier and the transaction information to the initiator of the distributed transaction. Wherein, the global transaction identifier is a unique identifier globally indicating the distributed transaction. For example, the global transaction identifier XID may be a UUID (Universally Unique Identifier).
[0075] Specifically, after receiving the transaction start request sent by the initiator of the distributed transaction, the first coordinator generates a global transaction identifier according to the transaction start request and returns it to the initiator of the distributed transaction.
[0076] For example, the transaction start request is a begin request. At the beginning of a transfer business (distributed transaction), the client sends a request to process the distributed transaction to the initiator of the distributed transaction. After receiving the request to process the distributed transaction, the initiator of the distributed transaction generates a begin request and sends the begin request to the sidecar helper program of the server where the initiator of the distributed transaction is located. After receiving the begin request sent by the initiator of the distributed transaction, the sidecar helper program of the server where the initiator of the distributed transaction is located generates a global transaction identifier XID according to the begin request and returns it to the initiator of the distributed transaction.
[0077] Through the above steps S310 - S320, the initiator of the distributed transaction sends the transaction start request to the first coordinator. The first coordinator generates a global transaction identifier based on the transaction information, and sends the global transaction identifier and the transaction information to the initiator of the distributed transaction. The first coordinator and the initiator of the distributed transaction are deployed on the same server, which helps to reduce communication consumption at the network level and improve communication efficiency.
[0078] In an exemplary embodiment of the present disclosure, the first coordinator stores the transaction information in a database, and updates the transaction information according to the processing result to complete the processing of the branch transaction. Specifically, referring to Figure 4 As shown, updating the transaction information may include the following steps S410 - S420:
[0079] In step S410, the first coordinator stores the transaction information in the database.
[0080] In an exemplary embodiment of the present disclosure, the first coordinator stores the transaction information in the database. The database is a distributed memory. For example, the database can be any one of distributed memories such as zookeeper, redis, and setnx.
[0081] Specifically, after receiving the transaction start request sent by the distributed transaction initiator, the first coordinator stores the transaction information in the database.
[0082] In step S420, the database updates the transaction information according to the processing result to complete the processing of the branch transaction.
[0083] In an exemplary embodiment of the present disclosure, the database updates the transaction information according to the processing result. The processing result is to add, delete, or change the transaction information. For example, if the distributed service is a transfer service where an account with a balance of 100 yuan transfers 10 yuan to an account with a balance of 100 yuan, the processing result can be data information with the balance of the transfer-out account being 90 yuan and the balance of the transfer-in account being 110 yuan.
[0084] Specifically, the distributed transaction participant updates the transaction information data stored in the database according to the processing result.
[0085] For example, the distributed transaction is a transfer service. The transaction information can be service-related data information such as the balance of the transfer-out account being 100 yuan and the balance of the transfer-in account being 100 yuan. The processing result can be data information with the balance of the transfer-out account being 90 yuan and the balance of the transfer-in account being 110 yuan. The database is a zookeeper distributed memory. After receiving the begin request for the transfer service sent by the distributed initiator, the sidecar assistant program on the server where the distributed transaction initiator is located stores service-related data information such as the balance of the transfer-out account being 100 yuan and the balance of the transfer-in account being 100 yuan in the zookeeper distributed memory. The distributed transaction participant updates the data with the balance of the transfer-out account being 100 yuan and the balance of the transfer-in account being 100 stored in the zookeeper distributed memory to data with the balance of the transfer-out account being 90 yuan and the balance of the transfer-in account being 110 yuan according to the processing result.
[0086] Through the above steps S410 - S420, the first coordinator stores the transaction information in the database, and the database updates the transaction information according to the processing result to complete the processing of the branch transaction.
[0087] In an exemplary embodiment of the present disclosure, each distributed transaction participant sends the global transaction identifier to each second coordinator. The multiple second coordinators generate multiple branch transaction identifiers based on the global transaction identifier. The second coordinators store the multiple branch transaction identifiers in the database and update the status of each branch transaction identifier to the execution status. Specifically, referring to Figure 5 as shown, generating the branch transaction identifier may include the following steps S510 to S530:
[0088] In step S510, each distributed transaction participant sends the global transaction identifier to each second coordinator.
[0089] In an exemplary embodiment of the present disclosure, each distributed transaction participant sends the global transaction identifier to each second coordinator. Among them, the second coordinator is deployed on the server where each distributed transaction participant is located, and each distributed transaction participant sends the global transaction identifier to each second coordinator.
[0090] For example, the global transaction identifier is XID = 123, and the second coordinator is the sidecar assistant program deployed on the same server as the distributed transaction participant. After each distributed participant receives the global transaction identifier of XID = 123, it sends the global transaction identifier to the sidecar assistant program of its respective server.
[0091] In step S520, the multiple second coordinators generate multiple branch transaction identifiers based on the global transaction identifier.
[0092] In an exemplary embodiment of the present disclosure, the multiple second coordinators generate multiple branch transaction identifiers based on the global transaction identifier. Among them, each second coordinator generates a corresponding branch transaction identifier according to the type of the distributed transaction participant on the server where it is located. For example, if the distributed transaction participant is a log management program, after the sidecar assistant program on the server where the log management program is located receives the global transaction identifier of XID = 123, it will generate a branch transaction identifier branchid = 1 corresponding to the log management based on this global transaction identifier.
[0093] Specifically, after each second coordinator receives the global transaction identifier sent by the distributed transaction participant on the server where it is located, it generates a branch transaction identifier corresponding to the distributed transaction participant according to the global transaction identifier and the type of the distributed transaction participant on the server where it is located.
[0094] For example, the distributed transaction participants are the log management program, the order management program, and the commodity management program. After receiving the global transaction identifier with XID = 123, the sidecar assistant programs (the second coordinator) of the servers where each distributed transaction participant is located generate branch transaction identifiers corresponding to the distributed transaction participants based on the global transaction identifier and the type of the distributed transaction participant in the server. The sidecar assistant program of the server where the log management program is located generates a branch transaction identifier with branchid = 1 to indicate the log management branch transaction. The sidecar assistant program of the server where the order management program is located generates a branch transaction identifier with branchid = 2 to indicate the order management branch transaction. The sidecar assistant program of the server where the commodity management program is located generates a branch transaction identifier with branchid = 3 to indicate the commodity management branch transaction.
[0095] In step S530, the second coordinator stores the multiple branch transaction identifiers in the database and updates the status of each branch transaction identifier to the execution status.
[0096] In an exemplary embodiment of the present disclosure, the second coordinator stores the multiple branch transaction identifiers in the database and updates the status of each branch transaction identifier to the execution status. Here, the execution status is the status indicating the stage at which each distributed transaction participant processes each branch transaction.
[0097] Specifically, after generating the branch transaction identifier, the second coordinator stores the branch transaction identifier in the database, updates the status of the branch transaction identifier to the execution status in the database, and keeps listening to the status of the branch transaction identifier.
[0098] For example, the second coordinator is the sidecar assistant program deployed on the server where the distributed transaction participant is located. After generating the branch transaction identifier, each sidecar assistant program stores the branch transaction identifier under the name of XID = 123 (the global transaction identifier) in the zookeeper distributed storage, realizes the correspondence between the global transaction identifier and the branch transaction identifier, updates the status of the branch transaction identifier to the execution status, and listens to the change of the status of the branch transaction identifier in real time.
[0099] Through the above steps S510 - S530, each distributed transaction participant sends the global transaction identifier to each second coordinator. The multiple second coordinators generate multiple branch transaction identifiers based on the global transaction identifier. The second coordinator stores the multiple branch transaction identifiers in the database and updates the status of each branch transaction identifier to the execution status. The second coordinator and the distributed transaction participant are deployed on the same server, which helps to reduce the communication consumption at the network level and improve the communication efficiency.
[0100] In an exemplary embodiment of the present disclosure, with reference to Figure 6 As shown, when a distributed transaction is started, the participating party sends a begin request (transaction start request) to the sidecar assistant program (the first coordinator) on the local machine of the participating party. The sidecar assistant program stores the transaction information in the database. After the storage is completed, an xid (global transaction identifier) is directly generated and informed to the distributed transaction initiator. Subsequently, when the distributed transaction initiator remotely calls the distributed transaction participating party, the xid and the transaction information will be passed to the distributed transaction participating party. The distributed transaction participating party will register the branch transaction to the sidecar assistant program (the second coordinator) on the local machine of the distributed transaction participating party. The sidecar assistant program generates a branchid (branch transaction identifier) and stores the branch transaction information in the database, and then can monitor the status of the branch transaction.
[0101] In an exemplary embodiment of the present disclosure, after each distributed transaction participating party completes each branch transaction according to the transaction information, the processing result is sent to the distributed transaction initiator. After the distributed transaction initiator confirms that the processing result is correct, the distributed transaction initiator sends a transaction commit instruction to the first coordinator. The first coordinator updates the status of the branch transaction identifier in the database from the execution status to the commit status. After the second coordinator detects that the status of the branch transaction identifier is the commit status, it sends a commit instruction to the distributed transaction participating party. Each distributed transaction participating party responds to the commit instruction and stores the processing result in the database. Specifically, with reference to Figure 7 As shown, submitting the transaction processing result may include the following steps S710 to S750:
[0102] In step S710, after each distributed transaction participating party completes each branch transaction according to the transaction information, the processing result is sent to the distributed transaction initiator.
[0103] In an exemplary embodiment of the present disclosure, after each distributed transaction participating party completes each branch transaction according to the transaction information, the processing result is sent to the distributed transaction initiator. Among them, the processing result is an addition, deletion, or change to the transaction information. For example, if the transaction information is data of an account balance of 100 yuan, the processing result can be changing the account balance of 100 yuan to 90 yuan, or changing the account balance of 100 yuan to 80 yuan.
[0104] Specifically, after the distributed participating party processes each branch transaction to obtain the processing result, the processing result is sent to the distributed transaction initiator.
[0105] In step S720, after the distributed transaction initiator confirms that the processing result is correct, the distributed transaction initiator sends a transaction commit instruction to the first coordinator.
[0106] In an exemplary embodiment of the present disclosure, after the distributed transaction initiator confirms that the processing result is correct, the distributed transaction initiator sends a transaction submission instruction to the first coordinator. Among them, the distributed transaction initiator checks the processing result, and after confirming that the processing result is correct, sends a transaction submission instruction to the first coordinator. The transaction submission instruction is used to inform the first coordinator to change the status of each branch transaction identifier under the global transaction identifier in the database to the committed state. For example, the distributed transaction is a transfer operation where the balance of the transfer-out account is 100 yuan, the balance of the transfer-in account is 100 yuan, and the transfer amount is 10 yuan. The processing result is that the balance of the transfer-out account is 90 yuan and the balance of the transfer-in account is 110 yuan. Then the processing result passes the check, and the distributed transaction initiator confirms that the processing result is correct.
[0107] Specifically, after the distributed transaction initiator receives the processing results sent by each distributed transaction participant, it checks each processing result. After confirming that all processing results are correct, it sends a transaction submission instruction to the first coordinator.
[0108] In step S730, the first coordinator updates the status of the branch transaction identifier in the database from the execution state to the committed state.
[0109] In an exemplary embodiment of the present disclosure, the first coordinator updates the status of the branch transaction identifier in the database from the execution state to the committed state. Among them, the first coordinator finds each branch transaction identifier according to the global transaction identifier in the database and changes the status of each branch transaction identifier to the committed state.
[0110] Specifically, after the first coordinator receives the transaction submission instruction sent by the transaction initiator, it finds each branch transaction identifier in the database according to the global transaction identifier and updates the status of each branch transaction identifier from the execution state to the committed state.
[0111] In step S740, after the second coordinator detects that the status of the branch transaction identifier is the committed state, it sends a submission instruction to the distributed transaction participants.
[0112] In an exemplary embodiment of the present disclosure, after the second coordinator detects that the status of the branch transaction identifier is the committed state, it sends a submission instruction to the distributed transaction participants. Among them, the second coordinator monitors the status change of the branch transaction identifier in the database in real time.
[0113] Specifically, after the second coordinator detects that the status of the branch transaction identifier in the database is updated from the execution state to the committed state, it sends a submission instruction to the transaction initiator of its own server.
[0114] In step S750, each distributed transaction participant stores the processing result in the database in response to the submission instruction.
[0115] In an exemplary embodiment of the present disclosure, each distributed transaction participant stores the processing result in a database in response to a commit instruction. Wherein, the processing result is an operation of adding, deleting, or modifying transaction information. For example, the processing result may be changing the balance of the transfer-out account from 100 yuan to 90 yuan.
[0116] Specifically, after receiving the commit instruction from the second coordinator, each distributed transaction participant stores the processing result in the database according to the commit instruction.
[0117] For example, the distributed transaction is a transfer operation with a transfer-out account balance of 100 yuan, a transfer-in account balance of 100 yuan, and a transfer amount of 10 yuan. The transaction information is the data information of a transfer-out account balance of 100 yuan, a transfer-in account balance of 100 yuan, and a transfer amount of 10 yuan. The processing result is a transfer-out account balance of 90 yuan and a transfer-in account balance of 110 yuan. The global transaction identifier is XID = 123, and the branch transaction identifiers are branchid = 1 and branchid = 2. After obtaining the processing result according to the transaction information, the distributed transaction participant sends the processing result of a transfer-out account balance of 90 yuan and a transfer-in account balance of 110 yuan to the distributed transaction participant.
[0118] After the distributed transaction initiator receives the processing results of a transfer-out account balance of 90 yuan and a transfer-in account balance of 110 yuan sent by each distributed transaction participant, it checks the two processing results. After confirming that all processing results are correct, it sends a transaction commit instruction to the sidecar helper program of the server where the transaction initiator is located.
[0119] The sidecar helper program (the first coordinator) of the server where the transaction initiator is located, after receiving the transaction commit instruction sent by the transaction initiator, finds the branch transaction identifiers of branchid = 1 and branchid = 2 in the database according to XID = 123, and updates the status of the two branch transaction identifiers from the execution status to the committed status.
[0120] The sidecar helper program (the second coordinator) of the server where the distributed transaction participant is located, after detecting that branchid = 1 and branchid = 2 are in the committed status, sends a commit instruction to the distributed transaction participant of its respective server.
[0121] After receiving the commit instruction from the sidecar helper program (the second coordinator), each distributed transaction participant stores the data of a transfer-out account balance of 90 yuan and a transfer-in account balance of 110 yuan in the database according to the commit instruction.
[0122] Through the above steps S710 - S750, after each distributed transaction participant completes each sub - transaction according to the transaction information, the processing result is sent to the distributed transaction initiator. After the distributed transaction initiator confirms that the processing result is correct, the distributed transaction initiator sends a transaction commit instruction to the first coordinator. The first coordinator updates the status of the branch transaction identifier in the database from the execution status to the commit status. After the second coordinator detects that the status of the branch transaction identifier is the commit status, it sends a commit instruction to the distributed transaction participants. In response to the commit instruction, each distributed transaction participant stores the processing result in the database. Since the first coordinator and the second coordinator only need to execute the transactions on their respective nodes without caring about other transactions, lightweight first and second coordinators can be adopted, reducing the hardware deployment cost.
[0123] In an exemplary embodiment of the present disclosure, referring to Figure 8 as shown, after each distributed transaction participant transfers its respective processing result to the distributed transaction initiator, the distributed transaction initiator checks the processing result. After confirming that all processing results are correct, the sidecar auxiliary program (the first coordinator) of the local machine modifies the status of branchid1, branchid2, and branchid3 (branch transaction identifiers) belonging to xid123 (global transaction identifier) to the commit status. When the sidecar auxiliary program (the second coordinator) of each distributed transaction participant detects that branchid1, branchid2, and branchid3 are in the commit status, it sends a commit instruction (submission instruction) to the transaction participants of the server where it is located, so that the transaction participants can submit the processing result.
[0124] In an exemplary embodiment of the present disclosure, after the distributed transaction initiator detects an error in the processing result, the distributed transaction initiator sends a transaction rollback instruction to the first coordinator. The first coordinator updates the status of the branch transaction identifier in the database from the execution status to the rollback status. After the second coordinator detects that the status of the branch transaction identifier is the rollback status, it sends a rollback instruction to the distributed transaction participants. In response to the rollback instruction, each distributed transaction participant deletes the processing result. Specifically, referring to Figure 9 as shown, the steps for rolling back the transaction processing result may include the following steps S910 - S940:
[0125] In step S910, after the distributed transaction initiator detects an error in the processing result, the distributed transaction initiator sends a transaction rollback instruction to the first coordinator.
[0126] In an exemplary embodiment of the present disclosure, after the distributed transaction initiator detects an error in the processing result, the distributed transaction initiator sends a transaction rollback instruction to the first coordinator. Among them, the distributed transaction initiator checks the processing result, and after detecting an error in the processing result of any branch transaction, it sends a transaction rollback instruction to the first coordinator. The transaction rollback instruction is used to inform the first coordinator to change the status of each branch transaction identifier under the global transaction identifier in the database to the rollback status. For example, the distributed transaction is a transfer operation with a balance of 100 yuan in the transfer-out account, a balance of 100 yuan in the transfer-in account, and a transfer amount of 10 yuan. The processing result shows that the balance of the transfer-out account is 80 yuan and the balance of the transfer-in account is 120 yuan. Then the processing result fails the check, and the distributed transaction initiator detects an error in the processing result.
[0127] Specifically, after the distributed transaction initiator receives the processing results sent by each distributed transaction participant, it checks each processing result. After confirming an error in the processing result of any branch transaction, it sends a transaction rollback instruction to the first coordinator.
[0128] In step S920, the first coordinator updates the status of the branch transaction identifier in the database from the execution status to the rollback status.
[0129] In an exemplary embodiment of the present disclosure, the first coordinator updates the status of the branch transaction identifier in the database from the execution status to the rollback status. Among them, the first coordinator finds each branch transaction identifier according to the global transaction identifier in the database and changes the status of each branch transaction identifier to the rollback status.
[0130] Specifically, after the first coordinator receives the transaction rollback instruction sent by the transaction initiator, it finds each branch transaction identifier in the database according to the global transaction identifier and updates the status of each branch transaction identifier from the execution status to the rollback status.
[0131] In step S930, after the second coordinator detects that the status of the branch transaction identifier is the rollback status, it sends a rollback instruction to the distributed transaction participant.
[0132] In an exemplary embodiment of the present disclosure, after the second coordinator detects that the status of the branch transaction identifier is the rollback status, it sends a rollback instruction to the distributed transaction participant. Among them, (wherein, the second coordinator monitors the status change of the branch transaction identifier in the database in real time.
[0133] Specifically, after the second coordinator detects that the status of the branch transaction identifier in the database is updated from the execution status to the rollback status, it sends a rollback instruction to the transaction initiator of its own server.
[0134] In step S940, each distributed transaction participant deletes the processing result in response to the rollback instruction.
[0135] In an exemplary embodiment of the present disclosure, each distributed transaction participant deletes the processing result in response to the rollback instruction. Among them, deleting the processing result means that the distributed transaction participant deletes the processing result so that the transaction information is restored to the initial loading before the transaction starts.
[0136] Specifically, after each distributed transaction participant receives the rollback instruction from the second coordinator, it deletes the processing result according to the rollback instruction.
[0137] For example, the distributed transaction is a transfer operation with a transfer-out account balance of 100 yuan, a transfer-in account balance of 100 yuan, and a transfer amount of 10 yuan. The processing result is that the transfer-out account balance is 80 yuan, the transfer-in account balance is 120 yuan, the global transaction identifier is XID = 123, and the branch transaction identifiers are branchid = 1 and branchid = 2. After the distributed transaction initiator receives the processing results of the transfer-out account balance of 80 yuan and the transfer-in account balance of 120 yuan sent by each distributed transaction participant, it checks the two processing results. After confirming that the two processing results are incorrect, it sends a transaction rollback instruction to the sidecar assistant program of the server where the transaction initiator is located.
[0138] After the sidecar assistant program (the first coordinator) of the server where the transaction initiator is located receives the transaction rollback instruction sent by the transaction initiator, it finds the branch transaction identifiers of branchid = 1 and branchid = 2 in the database according to XID = 123, and updates the status of the two branch transaction identifiers from the execution status to the rollback status.
[0139] After the sidecar assistant program (the second coordinator) of the server where the distributed transaction participant is located detects that branchid = 1 and branchid = 2 are in the rollback status, it sends a rollback instruction to the distributed transaction participants of their respective servers.
[0140] After each distributed transaction participant receives the rollback instruction from the sidecar assistant program (the second coordinator), it deletes the data of the transfer-out account balance of 80 yuan and the transfer-in account balance of 120 yuan according to the rollback instruction, so that the balance of the transfer-out account is restored to 100 yuan and the balance of the transfer-in account is restored to 100 yuan.
[0141] Through the above steps S910 to S940, after the distributed transaction initiator detects that the processing result is wrong, the distributed transaction initiator sends a transaction rollback instruction to the first coordinator, and the first coordinator updates the state of the branch transaction identifier in the database from the execution state to the rollback state. After the second coordinator detects that the state of the branch transaction identifier is the rollback state, it sends a rollback instruction to the distributed transaction participants, and each distributed transaction participant responds to the rollback instruction and deletes the processing result.
[0142] In an exemplary embodiment of the present disclosure, referring to Figure 10 As shown, after each distributed transaction participant passes its own processing result to the distributed transaction initiator, the distributed transaction initiator checks the processing result. After detecting an error in the processing result of any branch transaction, the local sidecar auxiliary program (first coordination program) modifies branchid1, branchid2 and branchid3 (branch transaction identifier) under xid123 (global transaction identifier) to a rollback state (rollback state). When the local sidecar auxiliary program (second coordination program) of each distributed transaction participant detects that branchid1, branchid2 and branchid3 are in a rollback state, it sends a rollback instruction (rollback instruction) to the transaction participant on the server where it is located, so that the transaction participant rolls back the processing result.
[0143] In an exemplary embodiment of the present disclosure, when a distributed transaction starts, the distributed transaction initiator sends a preset time to the first coordinator. When the first coordinator does not receive a transaction commit instruction within the preset time, the first coordinator updates the state of the branch transaction identifier in the database from the execution state to the rollback state. Figure 11 As shown, rolling back a transaction according to a preset time may include the following steps S1110 to S1120:
[0144] In step S1110 , the distributed transaction initiator sends a preset time period to the first coordination program.
[0145] In an exemplary embodiment of the present disclosure, the distributed transaction initiator sends a preset time period to the first coordination program, wherein the preset time period may be any preset time period, for example, 10 seconds, or 1 minute, or any other time period.
[0146] Specifically, when a transaction starts, the distributed transaction initiator sends a preset time period together with a begin request to the first coordination program.
[0147] In step S1120, when the first coordinator does not receive a transaction commit instruction within a preset time period, the first coordinator updates the state of the branch transaction identifier in the database from an execution state to a rollback state.
[0148] In an exemplary embodiment of the present disclosure, when the first coordinator does not receive a transaction commit instruction within a preset time period, the first coordinator updates the state of the branch transaction identifier in the database from the execution state to the rollback state. After receiving the preset time period, the first coordinator determines whether to change the state of each branch transaction identifier to the rollback state according to whether a transaction commit instruction is received from the distributed transaction initiator within the preset time period.
[0149] For example, the preset time period is 10 seconds. At the beginning of the transaction, the distributed transaction initiator sends the preset time period of 10 seconds together with the begin request to the sidecar auxiliary program (first coordination program) of the server where the distributed transaction initiator is located. After receiving the preset time period of 10 seconds, if the first coordination program does not receive a transaction commit instruction from the distributed transaction initiator within 10 seconds, it changes the status of each branch transaction identifier to a rollback state.
[0150] Through the above steps S1110 to S1120, when the distributed transaction starts, the distributed transaction initiator sends a preset time period to the first coordinator. When the first coordinator does not receive a transaction commit instruction within the preset time period, the first coordinator updates the state of the branch transaction identifier in the database from the execution state to the rollback state.
[0151] In an exemplary embodiment of the present disclosure, referring to Figure 12 As shown, when a distributed transaction is started, the participant sends a begin request together with a preset time period = 10 seconds to the sidecar auxiliary program (first coordination program) of the participant's local computer. When the first coordination program does not receive a transaction commit instruction from the distributed transaction initiator within 10 seconds, the branchid1, branchid2, and branchid3 (branch transaction identifiers) under xid123 (global transaction identifier) are modified to a rollback state (rollback state). When the sidecar auxiliary program (second coordination program) of each distributed transaction participant detects that branchid1, branchid2, and branchid3 are in a rollback state, it sends a rollback instruction (rollback instruction) to the transaction participant on the server where it is located, so that the transaction participant rolls back the processing result.
[0152] In an exemplary embodiment of the present disclosure, the second coordinator stores multiple branch transaction identifiers in a database. When the target second coordinator detects a faulty distributed transaction participant, the target second coordinator obtains the faulty branch transaction identifiers through the database. The target second coordinator deletes the faulty identity identifier from the faulty branch transaction identifiers and inserts a healthy identity identifier into the faulty branch transaction identifiers. The database updates the second coordinator corresponding to the faulty branch transaction identifiers to the target second coordinator, so that the target distributed transaction participant processes the branch transactions corresponding to the faulty distributed transaction participant. Specifically, referring to Figure 13 as shown, the disaster recovery and master selection of the second coordinator may include the following steps S1310 to S1340:
[0153] In step S1310, the second coordinator stores multiple branch transaction identifiers in a database.
[0154] In an exemplary embodiment of the present disclosure, the second coordinator stores multiple branch transaction identifiers in a database.
[0155] For example, the second coordinator is a sidecar auxiliary program deployed on the server where the distributed transaction participant is located. After each sidecar auxiliary program generates a branch transaction identifier, it stores the branch transaction identifier under the name of XID = 123 (global transaction identifier) in the zookeeper distributed memory, realizing the correspondence between the global transaction identifier and the branch transaction identifier.
[0156] In step S1320, when the target second coordinator detects a faulty distributed transaction participant, the target second coordinator obtains the faulty branch transaction identifiers through the database.
[0157] In an exemplary embodiment of the present disclosure, when the target second coordinator detects a faulty distributed transaction participant, the target second coordinator obtains the faulty branch transaction identifiers through the database. Among them, the target second coordinator is the second coordinator of the server where the target distributed transaction participant is located, the target distributed transaction participant is one of at least one healthy distributed transaction participant, the faulty branch transaction identifier is the branch transaction identifier corresponding to the faulty distributed transaction participant, the faulty branch transaction identifier contains a faulty identity identifier, and the faulty identity identifier is the identifier of the second coordinator of the server where the faulty distributed transaction participant is located. For example, the distributed transaction participants are a log management program, an order management program, and a commodity management program. The faulty distributed transaction participant may be the log management program, then the healthy distributed transaction participants are the order management program and the commodity management program, then the faulty transaction identifier is the branch transaction identifier of the log management program, and the target distributed participant is one of the order management program and the commodity management program.
[0158] Specifically, each second coordination program periodically sends a sovereignty signal to the branch transaction identifier in the database to declare sovereignty over the branch transaction. At the same time, it will detect each other's sovereignty signals. When a faulty distributed transaction participant is detected, the target second coordination program obtains the faulty branch transaction identifier through the database.
[0159] For example, the distributed transaction participants are a log management program, an order management program, and a commodity management program. The faulty distributed transaction participant is the log management program, the healthy distributed transaction participants are the order management program and the commodity management program, and the target distributed transaction participant is the order management program. The sidecar auxiliary program (second coordination program) of each server where the distributed transaction participants are located will periodically send a sovereignty signal to the branch transaction identifier in the database to declare sovereignty over the branch transaction. At the same time, it will detect each other's sovereignty signals. When the sidecar auxiliary program of the order management program detects that the log management program does not send a sovereignty signal regularly, it determines that the log management program has failed. The sidecar auxiliary program of the order management program obtains the branch transaction identifier of the log management transaction in the database.
[0160] In step S1330, the target second coordination program deletes the faulty identity identifier from the faulty branch transaction identifier and inserts the healthy identity identifier into the faulty branch transaction identifier.
[0161] In an exemplary embodiment of the present disclosure, the target second coordination program deletes the faulty identity identifier from the faulty branch transaction identifier and inserts the healthy identity identifier into the faulty branch transaction identifier. Wherein, the healthy identity identifier is the identity identifier of the second coordination program. For example, the healthy identity identifier can be sidecarid.
[0162] Specifically, after detecting the faulty distributed transaction participant and obtaining the faulty branch transaction identifier, the target second coordination program deletes the faulty identity identifier from the faulty branch transaction identifier and inserts the healthy identity identifier into the faulty branch transaction identifier.
[0163] For example, the distributed transaction participants are a log management program, an order management program, and a commodity management program. The faulty distributed transaction participant is the log management program, the healthy distributed transaction participants are the order management program and the commodity management program, and the target distributed transaction participant is the order management program. After detecting that the log management program has failed and obtaining the branch transaction identifier of the log management, the order management program deletes the sidecarid of the log management program from the branch transaction identifier of the log management and inserts the sidecarid of the order management program into the branch transaction identifier of the log management.
[0164] In this embodiment, both the deletion of the fault identity identifier and the insertion of the healthy identity identifier are performed in the database. Since the database itself has exclusivity and does not allow concurrent modification of the same data, after deleting the fault identity identifier from the fault branch transaction identifier of the target second coordinator and inserting the healthy identity identifier into the fault branch transaction identifier, the second coordinators of other healthy distributed transaction participants cannot insert their own healthy identity identifiers into the fault branch transaction identifier.
[0165] For example, referring to Figure 14 as shown, the first participant inserts a global transaction identifier with branchid = 1 and belonging to xid = 123, then listens to the record status of branchid = 1, and additionally adds a control right record with the management right of branchid being sidecarid = 1 (identity flag). Finally, the sovereignty signal sending time is 2022-09-28 15:23:20. When the first participant fails, referring to Figure 15 as shown, the first participant is unable to send the sovereignty signal due to the fault. The second participant and the third participant continue to send the sovereignty signal regularly and detect that sidecar1 is disconnected, and attempt to obtain the sovereignty of branchid = 1 (fault transaction identifier). After the second participant obtains the sovereignty of branchid = 1, it changes the sidecarid corresponding to branchid = 1 from sidecar = 1 to sidecar = 2, completing the sovereignty seizure.
[0166] In step S1340, the database updates the second coordinator corresponding to the fault branch transaction identifier to the target second coordinator, so that the target distributed transaction participant processes the branch transaction corresponding to the faulty distributed transaction participant.
[0167] In an exemplary embodiment of the present disclosure, the database updates the second coordinator corresponding to the fault branch transaction identifier to the target second coordinator, so that the target distributed transaction participant processes the branch transaction corresponding to the faulty distributed transaction participant. Among them, the target distributed transaction participant will process both the faulty distributed transaction and the target distributed transaction simultaneously.
[0168] For example, the distributed transaction participants are a log management program, an order management program, and a commodity management program. The faulty distributed transaction participant is the log management program, and the target distributed transaction participant is the order management program. After the database modifies the distributed transaction participant corresponding to the branch transaction identifier of the log management program from the log management program to the order management program, the order management program will perform both the log management transaction and the order management transaction simultaneously.
[0169] Through the above steps S1310 - S1340, the second coordination program stores multiple branch transaction identifiers in the database. When the target second coordination program detects a faulty distributed transaction participant, the target second coordination program obtains the faulty branch transaction identifiers from the database, deletes the faulty identity identifier from the faulty branch transaction identifiers, inserts the healthy identity identifier into the faulty branch transaction identifiers, and the database updates the second coordination program corresponding to the faulty branch transaction identifiers to the target second coordination program, so that the target distributed transaction participant processes the branch transactions corresponding to the faulty distributed transaction participant. When a distributed transaction participant fails, it avoids the sovereignty seizure operations of multiple healthy distributed transaction participants on the faulty branch transactions simultaneously, protecting the idempotency security and data consistency of the transactions.
[0170] In the distributed transaction processing method provided by the exemplary embodiment of the present disclosure, the distributed transaction initiator sends the transaction information and the global transaction identifier of the distributed transaction to at least two distributed transaction participants through the first coordination program; after each distributed transaction participant sends the global transaction identifier to multiple second coordination programs, each second coordination program generates multiple branch transaction identifiers; each distributed transaction participant processes the branch transactions to obtain a processing result, so that the distributed transaction initiator adjusts the status of the branch transaction identifier according to the processing result; when it is detected that the branch transaction identifier is in the committed state, the processing result is stored in the database to complete the processing of the branch transaction. On the one hand, a coordination program is installed in the servers where the distributed transaction initiator and each distributed transaction participant are located. This coordination program only focuses on the transactions of the current node, reduces the processing of other transactions, and reduces resource occupancy. On the other hand, the coordination program is installed on the same server as the distributed transaction initiator or the distributed transaction participant, without additional loss at the network level, improving the interaction reliability. On the further hand, the coordination program is a micro program, reducing the deployment cost.
[0171] Figure 16 is a block diagram of a distributed transaction processing device shown according to an exemplary embodiment. Referring to Figure 16 FIG. 9, the distributed transaction processing device 1600 includes a transmission module 1610, a generation module 1620, a processing module 1630, and an update module 1640. Among them:
[0172] The transmission module 1610 is used for the distributed transaction initiator to send the transaction information and the global transaction identifier of the distributed transaction to at least two distributed transaction participants through the first coordination program; wherein, the first coordination program is deployed on the server where the distributed transaction initiator is located, and the first coordination program is used to coordinate and process the distributed transaction, and the global transaction identifier is an identifier generated by the first coordination program for indicating the distributed transaction;
[0173] The generation module 1620 is used for each participant in the distributed transaction to send the global transaction identifier to multiple second coordinators, and then each second coordinator generates multiple branch transaction identifiers. Among them, the second coordinator is deployed on the server where the participant in the distributed transaction is located, and the second coordinator is used to coordinate and process the branch transactions on the server where the second coordinator is located. The branch transaction identifier is an identifier used to indicate a branch transaction, and the distributed transaction includes branch transactions.
[0174] The processing module 1630 is used for each participant in the distributed transaction to process the branch transaction to obtain a processing result, so that the initiator of the distributed transaction adjusts the status of the branch transaction identifier according to the processing result. Among them, the status of the branch transaction identifier is used to indicate the processing stage of the branch transaction.
[0175] The update module 1640 is used to store the processing result in the database when it is detected that the branch transaction identifier is in the committed state, so that the branch transaction processing is completed. Among them, the committed state means that the participant in the distributed transaction determines that the processing result is correct.
[0176] In an exemplary embodiment of the present disclosure, based on the foregoing solution, before the initiator of the distributed transaction sends the transaction information of the distributed transaction and the global transaction identifier to at least two participants in the distributed transaction through the first coordinator, the device further includes a first sending unit, configured to send a transaction start request to the first coordinator by the initiator of the distributed transaction; and a second sending unit, configured to generate a global transaction identifier by the first coordinator according to the transaction information, and send the global transaction identifier and the transaction information to the initiator of the distributed transaction.
[0177] In an exemplary embodiment of the present disclosure, based on the foregoing solution, to store the processing result in the database so that the branch transaction processing is completed, the device further includes: a transaction information storage unit, configured to store the transaction information in the database by the first coordinator; and a transaction information update unit, configured to update the transaction information according to the processing result so that the branch transaction processing is completed. Among them, the processing result is to add, delete, or change the transaction information.
[0178] In an exemplary embodiment of the present disclosure, based on the foregoing solution, when each second coordinator generates multiple branch transaction identifiers, the device further includes: a global transaction identifier sending unit, configured to send the global transaction identifier to each second coordinator by each participant in the distributed transaction; a branch transaction identifier generation unit, configured to generate multiple branch transaction identifiers by multiple second coordinators according to the global transaction identifier; and a first branch transaction identifier storage unit, configured to store multiple branch transaction identifiers in the database by the second coordinator, and update the status of each branch transaction identifier to the execution state. Among them, the execution state is a state indicating the processing stage of each participant in the distributed transaction for each branch transaction.
[0179] In an exemplary embodiment of the present disclosure, based on the foregoing solution, when it is detected that the branch transaction identifier is in the committed state, the processing result is stored in the database. The apparatus further includes: a processing result sending unit, configured to send the processing result to the distributed transaction initiator after each distributed transaction participant completes each branch transaction according to the transaction information; a first commit instruction sending unit, configured to, after the distributed transaction initiator confirms that the processing result is correct, the distributed transaction initiator sends a transaction commit instruction to the first coordinator; a commit status update unit, configured to update the status of the branch transaction identifier in the database from the execution state to the committed state by the first coordinator; a first commit instruction sending unit, configured to, after the second coordinator detects that the status of the branch transaction identifier is the committed state, send a commit instruction to the distributed transaction participant; a commit unit, configured to store the processing result in the database in response to the commit instruction by each distributed transaction participant.
[0180] In an exemplary embodiment of the present disclosure, based on the foregoing solution, after the processing result is sent to the distributed transaction initiator after each branch transaction is completed according to the transaction information, the apparatus further includes: a first rollback instruction sending unit, configured to, after the distributed transaction initiator detects that the processing result is incorrect, the distributed transaction initiator sends a transaction rollback instruction to the first coordinator; a rollback status update unit, configured to update the status of the branch transaction identifier in the database from the execution state to the rollback state by the first coordinator; wherein the rollback state is a stage indicating that each distributed transaction participant deletes the processing result; a second rollback instruction sending unit, configured to, after the second coordinator detects that the status of the branch transaction identifier is the rollback state, send a rollback instruction to the distributed transaction participant; a rollback unit, configured to delete the processing result in response to the rollback instruction by each distributed transaction participant.
[0181] In an exemplary embodiment of the present disclosure, based on the foregoing solution, the apparatus further includes: a time sending unit, configured to, when the distributed transaction starts, the distributed transaction initiator sends a preset time to the first coordinator; a timing rollback status update unit, configured to, when the first coordinator does not receive a transaction commit instruction within the preset time, the first coordinator updates the status of the branch transaction identifier in the database from the execution state to the rollback state.
[0182] In an exemplary embodiment of the present disclosure, based on the foregoing solution, the apparatus further includes: a second branch transaction identifier storage unit for storing, by a second coordinator, a plurality of branch transaction identifiers in a database; a failed branch transaction identifier acquisition unit for, when a target second coordinator detects a failed distributed transaction participant, the target second coordinator acquiring, through the database, the failed branch transaction identifier; wherein the target second coordinator is the second coordinator of the server where the target distributed transaction participant is located, the target distributed transaction participant is one of at least one healthy distributed transaction participant, the failed branch transaction identifier is the branch transaction identifier corresponding to the failed distributed transaction participant, the failed branch transaction identifier includes a failure identity identifier, and the failure identity identifier is the identifier of the second coordinator of the server where the failed distributed transaction participant is located; a healthy identity identifier insertion unit for the target second coordinator deleting the failure identity identifier from the failed branch transaction identifier and inserting the healthy identity identifier into the failed branch transaction identifier; wherein the healthy identity identifier is the identity identifier of the second coordinator; and a coordinator update unit for the database updating the second coordinator corresponding to the failed branch transaction identifier to the target second coordinator, so that the target distributed transaction participant processes the branch transaction corresponding to the failed distributed transaction participant.
[0183] Since the various functional modules of the distributed transaction processing apparatus in the exemplary embodiment of the present disclosure correspond to the steps in the exemplary embodiment of the above-mentioned distributed transaction processing apparatus generation method, for details not disclosed in the apparatus embodiment of the present disclosure, please refer to the embodiment of the above-mentioned distributed transaction processing apparatus generation method of the present disclosure.
[0184] It should be noted that although several modules or units of a device for action execution are mentioned in the foregoing detailed description, this division is not mandatory. In fact, according to the embodiments of the present disclosure, the features and functions of the two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by a plurality of modules or units.
[0185] Figure 17 FIG. shows a schematic structural diagram of a computer system of an electronic device suitable for implementing the embodiments of the present disclosure.
[0186] It should be noted that Figure 17 The computer system 1700 of the electronic device shown is only an example and should not impose any limitation on the functions and usage scope of the embodiments of the present disclosure.
[0187] As Figure 17As shown, computer system 1700 includes a central processing unit (CPU) 1701, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 1702 or a program loaded from a storage section 1708 into a random access memory (RAM) 1703. In the RAM 1703, various programs and data required for system operation are also stored. The CPU 1701, ROM 1702, and RAM 1703 are connected to each other via a bus 1704. An input / output (I / O) interface 1705 is also connected to the bus 1704.
[0188] The following components are connected to the I / O interface 1705: an input section 1706 including a keyboard, a mouse, etc.; an output section 1707 including, for example, a cathode ray tube (CRT), a liquid crystal display (LCD), etc. and a speaker, etc.; a storage section 1708 including a hard disk, etc.; and a communication section 1709 including a network interface card such as a LAN card, a modem, etc. The communication section 1709 performs communication processing via a network such as the Internet. A drive 1710 is also connected to the I / O interface 1705 as needed. A removable medium 1711, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 1710 as needed so that a computer program read from it can be installed into the storage section 1708 as needed.
[0189] In particular, according to an embodiment of the present disclosure, the processes described below with reference to the flowcharts can be implemented as computer software programs. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes program code for performing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network via the communication section 1709, and / or installed from the removable medium 1711. When the computer program is executed by the central processing unit (CPU) 1701, various functions defined in the method and apparatus of the present application are executed.
[0190] In an exemplary embodiment of the present disclosure, a computer-readable storage medium is also provided, on which a program product capable of implementing the above method of this specification is stored. In some possible implementation manners, various aspects of the present disclosure can also be implemented in the form of a program product, including program code, which, when the program product runs on a terminal, is used to cause the terminal device to execute the "exemplary method" part of this specification described according to various exemplary embodiments and steps of the present disclosure.
[0191] A program product for implementing the above method according to an embodiment of the present disclosure may be a portable compact disc read-only memory (CD-ROM), include program code, and may run on a terminal device, such as a personal computer. However, the program product of the present disclosure is not limited thereto, and the readable storage medium may be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device.
[0192] The program product may adopt any combination of one or more readable media. The readable media may be a readable signal medium or a readable storage medium. The readable media may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples (a non-exhaustive list) of the readable storage medium include: an electrical connection having one or more wires, a portable disk, 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 above.
[0193] The computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries the readable program code. Such a propagated data signal may take various forms, including but not limited to an electromagnetic signal, an optical signal, or any suitable combination of the above. The readable signal medium may also be any readable medium other than the readable storage medium, which can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device.
[0194] The program code contained in the readable medium may be used for transmission through any appropriate medium, including but not limited to wireless, wired, optical fiber, RF, etc., or any suitable combination of the above.
[0195] In addition, the above drawings are only schematic illustrations of the processes included in the method according to the exemplary embodiments of the present disclosure, rather than for limiting purposes. It is easy to understand that the processes shown in the above drawings do not indicate or limit the chronological order of these processes. Additionally, it is also easy to understand that these processes may be executed synchronously or asynchronously, for example, in multiple modules.
[0196] Those skilled in the art will readily think of other embodiments of the present disclosure after considering the specification and practicing the invention disclosed herein. This application is intended to cover any variations, uses, or adaptations of the present disclosure, which follow the general principles of the present disclosure and include common general knowledge or conventional technical means in the technical field not disclosed in the present disclosure. The specification and embodiments are only regarded as exemplary, and the true scope and spirit of the present disclosure are pointed out by the claims.
Claims
1. A distributed transaction processing method, characterized in that, The method includes: The distributed transaction initiator sends the transaction information of the distributed transaction and the global transaction identifier to at least two distributed transaction participants through a first coordinator; wherein, the first coordinator is deployed on the server where the distributed transaction initiator is located, the first coordinator is used to coordinate the processing of the distributed transaction, and the global transaction identifier is an identifier generated by the first coordinator for indicating the distributed transaction; After each of the distributed transaction participants sends the global transaction identifier to a plurality of second coordinators, each of the second coordinators generates a plurality of branch transaction identifiers; wherein, the second coordinator is deployed on the server where the distributed transaction participant is located, the second coordinator is used to coordinate the processing of the branch transaction on the server where the second coordinator is located, the branch transaction identifier is an identifier for indicating the branch transaction, and the distributed transaction includes the branch transaction; Each of the distributed transaction participants processes the branch transaction to obtain a processing result, so that the distributed transaction initiator adjusts the status of the branch transaction identifier according to the processing result; wherein, the status of the branch transaction identifier is used to indicate the processing stage of the branch transaction; When it is detected that the branch transaction identifier is in the committed state, the processing result is stored in the database, so that the branch transaction is processed; wherein, the committed state is when the distributed transaction participant determines that the processing result is correct.
2. The method according to claim 1, wherein Before the distributed transaction initiator sends the transaction information of the distributed transaction and the global transaction identifier to at least two distributed transaction participants through the first coordinator, the method further includes: The distributed transaction initiator sends a transaction start request to the first coordinator; The first coordinator generates the global transaction identifier based on the transaction information, and sends the global transaction identifier and the transaction information to the distributed transaction initiator.
3. The method according to claim 2, characterized in that The storing the processing result in the database so that the branch transaction is processed includes: The first coordinator stores the transaction information in the database; Updating the transaction information according to the processing result, so that the branch transaction is processed; wherein, the processing result is to add, delete or change the transaction information.
4. The method according to claim 1, wherein The generating, by each of the second coordinators, a plurality of branch transaction identifiers includes: Each of the distributed transaction participants sends the global transaction identifier to each of the second coordinators; A plurality of the second coordinators generate a plurality of the branch transaction identifiers based on the global transaction identifier; The second coordinator stores a plurality of the branch transaction identifiers in the database, and updates the status of each of the branch transaction identifiers to the executing state; wherein, the executing state is a state for indicating the processing stage of each branch transaction by each of the distributed transaction participants.
5. The method according to claim 4, characterized in that, The storing the processing result in the database when it is detected that the branch transaction identifier is in the committed state includes: After each of the distributed transaction participants completes each branch transaction according to the transaction information, the processing result is sent to the distributed transaction initiator; After the initiator of the distributed transaction confirms that the processing result is correct, the initiator of the distributed transaction sends a transaction commit instruction to the first coordinator; The first coordinator updates the status of the branch transaction identifier in the database from the execution status to the commit status; After the second coordinator detects that the status of the branch transaction identifier is the commit status, the second coordinator sends a commit instruction to the distributed transaction participant; In response to the commit instruction, each of the distributed transaction participants stores the processing result in the database.
6. The method according to claim 5, characterized in that, After the processing result is sent to the initiator of the distributed transaction after each branch transaction is completed according to the transaction information, the method further includes: After the initiator of the distributed transaction detects that the processing result is incorrect, the initiator of the distributed transaction sends a transaction rollback instruction to the first coordinator; The first coordinator updates the status of the branch transaction identifier in the database from the execution status to the rollback status; wherein, the rollback status is a stage indicating that each of the distributed transaction participants deletes the processing result; After the second coordinator detects that the status of the branch transaction identifier is the rollback status, the second coordinator sends a rollback instruction to the distributed transaction participant; In response to the rollback instruction, each of the distributed transaction participants deletes the processing result.
7. The method according to claim 6, wherein The method further includes: At the beginning of the distributed transaction, the initiator of the distributed transaction sends a preset time to the first coordinator; When the first coordinator does not receive the transaction commit instruction within the preset time, the first coordinator updates the status of the branch transaction identifier in the database from the execution status to the rollback status.
8. The method according to claim 1, characterized in that The method further includes: The second coordinator stores a plurality of the branch transaction identifiers in the database; When the target second coordinator detects a faulty distributed transaction participant, the target second coordinator obtains the faulty branch transaction identifier through the database; wherein, the target second coordinator is the second coordinator of the server where the target distributed transaction participant is located, the target distributed transaction participant is one of at least one healthy distributed transaction participant, the faulty branch transaction identifier is the branch transaction identifier corresponding to the faulty distributed transaction participant, the faulty branch transaction identifier includes a faulty identity identifier, and the faulty identity identifier is the identifier of the second coordinator of the server where the faulty distributed transaction participant is located; The target second coordinator deletes the faulty identity identifier from the faulty branch transaction identifier and inserts a healthy identity identifier into the faulty branch transaction identifier; wherein, the healthy identity identifier is the identity identifier of the second coordinator; The database updates the second coordinator corresponding to the faulty branch transaction identifier to the target second coordinator, so that the target distributed transaction participant processes the branch transaction corresponding to the faulty distributed transaction participant.
9. A distributed transaction processing device, characterized in that, Including: A transmission module, configured to send transaction information of a distributed transaction and a global transaction identifier to at least two distributed transaction participants by a first coordinator by a distributed transaction initiator; wherein, the first coordinator is deployed on a server where the distributed transaction initiator is located, and the first coordinator is configured to coordinate and process the distributed transaction, and the global transaction identifier is an identifier generated by the first coordinator for indicating the distributed transaction; A generation module, configured to, after each of the distributed transaction participants sends the global transaction identifier to a plurality of second coordinators, each of the second coordinators generates a plurality of branch transaction identifiers; wherein, the second coordinator is deployed on a server where the distributed transaction participant is located, the second coordinator is configured to coordinate and process a branch transaction of the server where the second coordinator is located, the branch transaction identifier is an identifier for indicating a branch transaction, and the distributed transaction includes the branch transaction; A processing module, configured to each of the distributed transaction participants processes the branch transaction to obtain a processing result, so that the distributed transaction initiator adjusts a status of the branch transaction identifier according to the processing result; wherein, the status of the branch transaction identifier is used to indicate a processing stage of the branch transaction; An update module, configured to, when it is detected that the branch transaction identifier is in a committed state, store the processing result in a database, so that the branch transaction is processed; wherein, the committed state is that the distributed transaction participant determines that the processing result is correct.
10. An electronic device, characterized in that, Comprising: A processor; And A memory, configured to store executable instructions of the processor; Wherein, the processor is configured to execute the distributed transaction processing method according to any one of claims 1-8 by executing the executable instructions.
11. A non-transitory computer-readable storage medium, characterized in that, When the instructions in the storage medium are executed by a processor of an electronic device, the electronic device is enabled to execute the distributed transaction processing method according to any one of claims 1-8.
Citation Information
Patent Citations
Distribution transaction processing method and device
CN108845866A
Guaranteed commit outcome in a distributed transaction processing system
US20170220621A1