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

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

Info

Publication number
CN110502319B
CN110502319B CN201910786076.4A CN201910786076A CN110502319B CN 110502319 B CN110502319 B CN 110502319B CN 201910786076 A CN201910786076 A CN 201910786076A CN 110502319 B CN110502319 B CN 110502319B
Authority
CN
China
Prior art keywords
node
snapshot
target participant
service
participant node
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910786076.4A
Other languages
Chinese (zh)
Other versions
CN110502319A (en
Inventor
曹智颖
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Tencent Technology Shenzhen Co Ltd
Original Assignee
Tencent Technology Shenzhen Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Tencent Technology Shenzhen Co Ltd filed Critical Tencent Technology Shenzhen Co Ltd
Priority to CN201910786076.4A priority Critical patent/CN110502319B/en
Publication of CN110502319A publication Critical patent/CN110502319A/en
Application granted granted Critical
Publication of CN110502319B publication Critical patent/CN110502319B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1471Saving, restoring, recovering or retrying involving logging of persistent data for recovery
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/466Transaction processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q10/00Administration; Management
    • G06Q10/08Logistics, e.g. warehousing, loading or distribution; Inventory or stock management
    • G06Q10/087Inventory or stock management, e.g. order filling, procurement or balancing against orders
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06QINFORMATION AND COMMUNICATION TECHNOLOGY [ICT] SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES; SYSTEMS OR METHODS SPECIALLY ADAPTED FOR ADMINISTRATIVE, COMMERCIAL, FINANCIAL, MANAGERIAL OR SUPERVISORY PURPOSES, NOT OTHERWISE PROVIDED FOR
    • G06Q30/00Commerce
    • G06Q30/06Buying, selling or leasing transactions
    • G06Q30/0601Electronic shopping [e-shopping]
    • G06Q30/0633Lists, e.g. purchase orders, compilation or processing
    • G06Q30/0635Processing of requisition or of purchase orders

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Business, Economics & Management (AREA)
  • General Physics & Mathematics (AREA)
  • Physics & Mathematics (AREA)
  • Accounting & Taxation (AREA)
  • Economics (AREA)
  • Finance (AREA)
  • General Engineering & Computer Science (AREA)
  • General Business, Economics & Management (AREA)
  • Software Systems (AREA)
  • Quality & Reliability (AREA)
  • Databases & Information Systems (AREA)
  • Development Economics (AREA)
  • Marketing (AREA)
  • Strategic Management (AREA)
  • Data Mining & Analysis (AREA)
  • Human Resources & Organizations (AREA)
  • Operations Research (AREA)
  • Entrepreneurship & Innovation (AREA)
  • Tourism & Hospitality (AREA)
  • Computing Systems (AREA)
  • Hardware Redundancy (AREA)

Abstract

The application provides a distributed transaction processing method and device, electronic equipment and a storage medium, and relates to the field of computers. The method comprises the following steps: acquiring a service operation request sent by requester equipment, wherein the service operation request carries an operation identifier of service operation; determining at least two target participant nodes for executing business operation from all participant nodes according to the operation identification; acquiring and storing a snapshot of each target participant node, wherein the snapshot is a snapshot of service data corresponding to service operation in the target participant node; calling each target participant node to respectively execute the sub-operation of the corresponding business operation and obtain the execution result of each target participant node; and if the execution result of one node in each target participant node is execution failure, respectively sending the snapshot corresponding to each node to each target participant node so that each target participant node restores the corresponding service data to the state before the corresponding sub-operation is executed according to the snapshot.

Description

Distributed transaction processing method and device, electronic equipment and storage medium
Technical Field
The present application relates to the field of computer technologies, and in particular, to a method and an apparatus for processing a distributed transaction, an electronic device, and a storage medium.
Background
Distributed transactions are widely present in various internet systems today, as distributed deployment and microservices make their way. The execution process of a distributed transaction generally includes a coordinator and participant nodes, to which the coordinator can send commands to control the participant nodes to perform the operations of the distributed transaction. Currently, there are Two main approaches in the industry, namely Two-Phase Commit protocol (2 PC) and Try-Confirm-Cancel (Try-Confirm-Cancel, TCC).
For the 2PC scheme, each participant node needs to store an Undo log (for recording data before modification) and a Redo log (for recording data after modification) required for performing a transaction operation after receiving an inquiry, and when rollback is required, the participant node needs to perform rollback by using the Undo log. It can be seen that the implementation of the scheme depends on the transaction rollback capability provided by the participant node, and most databases with this capability are relational databases, such as Oracle, MySql, and the like, which are not suitable for databases without services having this feature. For the TCC scheme, it requires that for each transaction operation of the participant node, there must be a corresponding rollback operation, which brings a large development workload and has a large intrusion on the service code.
It can be seen that, the distributed transaction processing scheme in the industry at present partially depends on the transaction processing capability provided by the database, and partially has a large intrusion on the business code, and at present, there is no scheme that is both general and does not have a large intrusion on the business code.
Disclosure of Invention
In order to solve at least one of the problems in the prior art, embodiments of the present application provide a method and an apparatus for processing a distributed transaction, an electronic device, and a storage medium. The technical scheme provided by the embodiment of the application is as follows:
in a first aspect of the embodiments of the present application, a distributed transaction processing method is provided, where the method is applied in a distributed system, the distributed system includes a coordinator node and at least two participant nodes, and the coordinator node is communicatively connected to each of the participant nodes, and the method includes:
acquiring a service operation request sent by requester equipment, wherein the service operation request carries an operation identifier of service operation;
determining at least two target participant nodes for executing business operation from all participant nodes according to the operation identification;
acquiring and storing a snapshot of each target participant node, wherein the snapshot is a snapshot of service data corresponding to service operation in the target participant node;
calling each target participant node to respectively execute the sub-operation of the corresponding business operation, and acquiring the execution result of each target participant node;
and if the execution result of one node in each target participant node is execution failure, respectively sending the snapshot corresponding to each node to each target participant node so that each target participant node restores the corresponding service data to the state before the corresponding sub-operation is executed according to the snapshot.
In an optional embodiment of the first aspect, invoking each target participant node to respectively execute a sub-operation of a corresponding service operation includes:
if the snapshot of each target participant node is obtained, calling each target participant node to respectively execute corresponding sub-operations;
the method further comprises the following steps:
and if the snapshot of one node in each target participant node is not acquired, returning operation failure prompt information to the requesting equipment.
In an optional embodiment of the first aspect, sending a snapshot corresponding to each node to each target participant node, so that each target participant node restores the corresponding service data to a state before the corresponding sub-operation is executed according to the snapshot includes:
and according to the execution result of each target participant node, sending a corresponding snapshot to the target participant node with the successful execution result in each target participant node, so that each target participant node with the successful execution result restores the corresponding service data to the state before the corresponding sub-operation is executed according to the snapshot.
In an optional embodiment of the first aspect, if at least two sub-operations of the service operation are performed by the target participant node, the service data corresponding to the service operation in the target participant node is the service data corresponding to all the sub-operations in the target participant node;
the target participant node restores the corresponding service data to the state before the corresponding sub-operation is executed according to the snapshot, which means that the target participant node restores the service data corresponding to all the sub-operations in the node to the state before all the sub-operations at one time according to the snapshot.
In an optional embodiment of the first aspect, if the service operation request includes at least two service operation requests, and target participant nodes corresponding to different service operation requests in the at least two service operation requests include the same node, snapshots of the target participant nodes corresponding to different service operation requests at the same time include snapshots of service data corresponding to different service operation requests in the node;
if the execution result is that the service operation request which is failed to be executed is an operation request corresponding to a target participant node which simultaneously corresponds to different service operation requests, sending a snapshot corresponding to each node to each target participant node respectively, wherein the snapshot comprises the following steps:
and sending a snapshot corresponding to the service operation request with the execution result of the target participant node being failed to execute to the target participant node simultaneously corresponding to different service operation requests.
In an optional implementation manner of the first aspect, determining, according to the operation identifier, at least two target participant nodes for performing a business operation from all participant nodes includes:
determining at least two target participant nodes for executing business operation according to the operation identifier and a pre-configured service mapping relation;
the service mapping relationship is a corresponding relationship between each operation identifier and node related information of each participant node for executing the business operation corresponding to each operation identifier.
In an optional embodiment of the first aspect, the node-related information includes a service operation interface call address, a snapshot generation interface call address, and a rollback interface call address of the participant node.
In an optional embodiment of the first aspect, if at least two sub-operations of the business operation corresponding to the target participant node are provided, the snapshot generating interface call address and the rollback interface call address satisfy at least one of the following:
the snapshot generating interface calling addresses corresponding to all the sub-operations are the same;
and the call addresses of the rollback interfaces corresponding to all the sub-operations are the same.
In an optional embodiment of the first aspect, if the service operation request includes at least two service operation requests, and target participant nodes corresponding to different service operation requests in the at least two service operation requests include the same node, the snapshot generating interface call address and the rollback interface call address of the target participant node corresponding to different service operation requests simultaneously satisfy at least one of the following:
the target participant node generates the same interface calling address corresponding to the snapshot of different service operation requests;
the call addresses of the rollback interfaces of the target participant node corresponding to different service operation requests are the same.
In an optional embodiment of the first aspect, invoking each target participant node to respectively execute a sub-operation of a corresponding service operation includes:
calling a business operation interface corresponding to the address by calling the business operation interface of each target participant node, and sending a business operation instruction of a corresponding sub-operation to each target participant node so as to enable each target participant node to execute the corresponding sub-operation based on the business operation instruction;
the obtaining the snapshot of each target participant node includes:
for each target participant node, calling an interface corresponding to the snapshot generating interface calling address of each target participant node, sending a snapshot generating instruction to each target participant node, and receiving a snapshot returned by each target participant node according to the snapshot generating instruction;
the method further comprises the following steps:
and calling a rollback interface corresponding to the rollback interface calling address of each target participant node, and sending a rollback instruction to each target participant node so that each target participant node restores the corresponding service data to a state before executing the corresponding sub-operation according to the rollback instruction and the snapshot.
In an alternative implementation form of the first aspect, the participant nodes in the distributed system comprise blockchain nodes.
In a second aspect of the embodiments of the present application, a distributed transaction processing method is provided, where the method is applied to a distributed system, the distributed system includes a coordinator node and at least two participant nodes, and the coordinator node is in communication connection with each participant node; the method comprises the following steps:
when a snapshot generating instruction sent by a coordinator node is received, generating a corresponding snapshot according to the snapshot generating instruction, and sending the snapshot to the coordinator node, wherein the snapshot is a snapshot of service data corresponding to a service operation request in a target participant node, and the target participant node is determined according to an operation identifier of service operation carried in the service operation request when the coordinator node acquires the service operation request sent by a requester device;
when a business operation instruction sent by a coordinator node is received, executing corresponding business operation according to the business operation instruction, and sending an execution result to the coordinator node;
and when receiving the snapshot sent by the coordinator node, restoring the corresponding service data to the state before executing the corresponding service operation according to the snapshot, wherein the snapshot is sent when the coordinator node has an execution result of one target participant node in the received execution result, and the execution result is execution failure.
In an optional embodiment of the second aspect, if generating a corresponding snapshot according to the snapshot generating instruction fails, the method further includes:
sending snapshot generation failure prompt information to the coordinator node, so that the coordinator node returns operation failure prompt information to the requesting equipment when receiving the prompt information.
A third aspect of the present application provides a distributed transaction processing apparatus, which is applied in a distributed system, where the distributed system includes a coordinator node and at least two participant nodes, and the apparatus includes:
the receiving and sending module is used for acquiring a service operation request sent by requesting equipment, wherein the service operation request carries an operation identifier of service operation;
the target node determining module is used for determining at least two target participant nodes for executing business operation from all participant nodes according to the operation identification;
the receiving and sending module is further used for obtaining and storing a snapshot of each target participant node, wherein the snapshot is a snapshot of service data corresponding to the service operation request in the target participant node;
the target node calling module is used for calling each target participant node to respectively execute the sub-operation of the corresponding business operation and acquiring the execution result of each target participant node;
and the transceiver module is further configured to send a snapshot corresponding to each node to each target participant node if an execution result of one node in each target participant node is an execution failure, so that each target participant node restores the corresponding service data to a state before the corresponding sub-operation is executed according to the snapshot.
In an optional embodiment of the third aspect, when the target node invoking module invokes the sub-operations of the respective target participant nodes to execute the corresponding business operations, the target node invoking module is specifically configured to:
if the snapshot of each target participant node is obtained, calling each target participant node to respectively execute corresponding sub-operations;
a transceiver module further configured to:
and if the snapshot of one node in each target participant node is not acquired, returning operation failure prompt information to the requesting equipment.
In an optional embodiment of the third aspect, when the transceiver module sends the snapshot corresponding to each node to each target participant node, so that each target participant node restores the corresponding service data to the state before the corresponding sub-operation is executed according to the snapshot, the transceiver module is specifically configured to:
and according to the execution result of each target participant node, sending a corresponding snapshot to the target participant node with the successful execution result in each target participant node, so that each target participant node with the successful execution result restores the corresponding service data to the state before the corresponding sub-operation is executed according to the snapshot.
In an optional embodiment of the third aspect, if at least two sub-operations of the service operation are performed by the target participant node, the service data corresponding to the service operation in the target participant node is the service data corresponding to all the sub-operations in the target participant node;
the target participant node restores the corresponding service data to the state before the corresponding sub-operation is executed according to the snapshot, which means that the target participant node restores the service data corresponding to all the sub-operations in the node to the state before all the sub-operations at one time according to the snapshot.
In an optional embodiment of the third aspect, if the service operation request includes at least two service operation requests, and target participant nodes corresponding to different service operation requests in the at least two service operation requests include the same node, snapshots of the target participant nodes corresponding to different service operation requests at the same time include snapshots of service data corresponding to different service operation requests in the node;
if the execution result is that the service operation request which is failed to be executed is an operation request corresponding to a target participant node which simultaneously corresponds to different service operation requests, the transceiver module respectively sends snapshots corresponding to the nodes to the target participant nodes, and is specifically configured to:
and sending a snapshot corresponding to the service operation request with the execution result of the target participant node being failed to execute to the target participant node simultaneously corresponding to different service operation requests.
In an optional embodiment of the third aspect, when the target node determining module determines, according to the operation identifier, at least two target participant nodes for performing the service operation, the target node determining module is specifically configured to:
determining at least two target participant nodes for executing business operation according to the operation identifier and a pre-configured service mapping relation;
the service mapping relationship is a corresponding relationship between each operation identifier and node related information of each participant node for executing the business operation corresponding to each operation identifier.
In an alternative embodiment of the third aspect, the node-related information includes a service operation interface call address, a snapshot creation interface call address, and a rollback interface call address of the participant node.
In an optional embodiment of the third aspect, if at least two sub-operations of the business operation corresponding to the target participant node are provided, the snapshot generating interface call address and the rollback interface call address satisfy at least one of the following:
the snapshot generating interface calling addresses corresponding to all the sub-operations are the same;
and the call addresses of the rollback interfaces corresponding to all the sub-operations are the same.
In an optional embodiment of the third aspect, if the service operation request includes at least two service operation requests, and the target participant node corresponding to a different service operation request in the at least two service operation requests includes the same node, the snapshot generating interface call address and the rollback interface call address of the target participant node corresponding to the different service operation requests at the same time satisfy at least one of the following:
the target participant node generates the same interface calling address corresponding to the snapshot of different service operation requests;
the call addresses of the rollback interfaces of the target participant node corresponding to different service operation requests are the same.
In an optional embodiment of the third aspect, when the target node invoking module invokes each target participant node to respectively execute the sub-operation of the corresponding business operation, the method is specifically configured to:
calling a business operation interface corresponding to the address by calling the business operation interface of each target participant node, and sending a business operation instruction of a corresponding sub-operation to each target participant node so as to enable each target participant node to execute the corresponding sub-operation based on the business operation instruction;
when acquiring the snapshot of each target participant node, the transceiver module is specifically configured to:
for each target participant node, calling an interface corresponding to the snapshot generating interface calling address of each target participant node, sending a snapshot generating instruction to each target participant node, and receiving a snapshot returned by each target participant node according to the snapshot generating instruction;
a transceiver module further configured to:
and calling a rollback interface corresponding to the rollback interface calling address of each target participant node, and sending a rollback instruction to each target participant node so that each target participant node restores the corresponding service data to a state before executing the corresponding sub-operation according to the rollback instruction and the snapshot.
In an alternative embodiment of the third aspect, the participant nodes in the distributed system include blockchain nodes.
A fourth aspect of the present application provides a distributed transaction processing apparatus, where the apparatus is applied to a distributed system, and the distributed system includes a coordinator node and at least two participant nodes; the device includes:
the system comprises a snapshot generating module, a coordinator node and a server, wherein the snapshot generating module is used for generating a corresponding snapshot according to a snapshot generating instruction when receiving the snapshot generating instruction sent by the coordinator node and sending the snapshot to the coordinator node, wherein the snapshot is a snapshot of service data corresponding to a service operation request in a target participant node, and the target participant node is determined according to an operation identifier of service operation carried in the service operation request when the coordinator node acquires the service operation request sent by a requester device;
the service operation execution module is used for executing corresponding service operation according to the service operation instruction when receiving the service operation instruction sent by the coordinator node, and sending an execution result to the coordinator node;
and the service operation recovery module is used for recovering the corresponding service data to the state before the corresponding service operation is executed according to the snapshot when the snapshot sent by the coordinator node is received, wherein the snapshot is sent when the execution result of one target participant node in the received execution result of the coordinator node is execution failure.
In an optional embodiment of the fourth aspect, the apparatus further includes a transceiver module, and if the generation of the corresponding snapshot according to the snapshot generating instruction fails, the transceiver module is further configured to:
sending snapshot generation failure prompt information to the coordinator node, so that the coordinator node returns operation failure prompt information to the requesting equipment when receiving the prompt information.
In a fifth aspect of embodiments of the present application, there is provided an electronic device, including a memory and a processor; the memory has a computer program stored therein; the processor is adapted to perform the method of any of the first aspect and its optional embodiments, and the second aspect and its optional embodiments, when running the computer program.
A sixth aspect of the embodiments of the present application provides a computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the method shown in any one of the first aspect and its optional implementation manner, and the second aspect and its optional implementation manner.
The scheme provided by the embodiment of the application has the following beneficial effects:
according to the scheme provided by the embodiment of the application, the coordinator node acquires and stores the snapshot of each target participant node in advance before controlling the business operation corresponding to each target participant node, so that the execution result of one node in each target participant node is an execution failure, each target participant node can respectively roll back the corresponding business operation according to the corresponding snapshot, and the ACID characteristic of the distributed transaction is ensured. According to the scheme of the embodiment of the application, the associated snapshot is generated for all the sub-operations of each target participant node of the distributed transaction, namely one or more sub-operations from one target participant node are bound to one corresponding snapshot, and when the transaction operation of the participant node fails to be executed, the snapshot can be used for executing one rollback operation to complete the recovery of the service data.
Drawings
In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings used in the description of the embodiments of the present application will be briefly described below.
Fig. 1 is a schematic flowchart of a distributed transaction processing method according to an embodiment of the present application;
FIG. 2 is a schematic diagram of a bank transfer process provided by an embodiment of the application;
FIG. 3 is a schematic diagram of an account freeze process provided by an embodiment of the present application;
fig. 4 is a schematic flowchart of a distributed transaction processing method according to an embodiment of the present application;
FIG. 5 is a schematic diagram of a user online shopping process provided in an embodiment of the present application;
FIG. 6 is a schematic diagram of a basic architecture of a distributed system in an example of the present application;
FIG. 7 is a diagram illustrating a service mapping relationship in an example of the present application;
FIG. 8 is a flow chart illustrating a distributed transaction processing method provided in an example of the present application;
fig. 9 is a schematic structural diagram of a distributed transaction processing apparatus according to an embodiment of the present application;
fig. 10 is a schematic structural diagram of a distributed transaction processing apparatus according to an embodiment of the present application;
fig. 11 is a schematic structural diagram of an electronic device according to an embodiment of the present application.
Detailed Description
Reference will now be made in detail to the embodiments of the present application, examples of which are illustrated in the accompanying drawings, wherein like or similar reference numerals refer to the same or similar elements or elements having the same or similar function throughout. The embodiments described below with reference to the drawings are exemplary only for the purpose of explaining the present application and are not to be construed as limiting the present invention.
As used herein, the singular forms "a", "an", "the" and "the" are intended to include the plural forms as well, unless the context clearly indicates otherwise. It will be further understood that the terms "comprises" and/or "comprising," when used in this specification, specify the presence of stated features, steps, operations, elements, and/or components, but do not preclude the presence or addition of one or more other features, steps, operations, elements, components, and/or groups thereof. It will be understood that when an element is referred to as being "connected" or "coupled" to another element, it can be directly connected or coupled to the other element or intervening elements may also be present. Further, "connected" or "coupled" as used herein may include wirelessly connected or wirelessly coupled. As used herein, the term "and/or" includes all or any element and all combinations of one or more of the associated listed items.
First, a few terms referred to in the embodiments of the present application will be introduced and explained:
transaction: an executable unit, which is combined by a series of access and update operations to system data, has four properties of Atomicity (Atomicity), Consistency (Consistency), Isolation (Isolation), and persistence (Duration), which may be abbreviated as ACID. Atomicity means that the operations that make up a transaction are either all successful or all failed, and no intermediate state is possible; consistency means that the integrity and consistency of the database cannot be destroyed by executing the transaction, and the states of all components of the distributed system must be complete and consistent before and after the transaction is executed; isolation refers to that under the scenario of executing transactions concurrently, each transaction must be executed independently without interfering with each other; persistence refers to the fact that the results of execution must be permanently preserved once a transaction operation is successful.
Distributed transaction: each operation constituting the transaction is executed on different nodes of the distributed system, that is, the operation actually executing the transaction may occur on different devices (such as a server/server cluster) or may occur in different applications of the same device, that is, the participant node executing each operation of the transaction may be different devices or may be a computing processing unit corresponding to different applications of the same device. A transaction coordinator (coordinator node in the embodiment of the present application) and a transaction participant node (participant node in the embodiment of the present application) are involved in the distributed system, and the distributed transaction is completed by the participation of the coordinator and the participant node.
The participant node: a node for processing distributed transactions.
Coordinator node: for coordinating the processing of distributed transactions by managing multiple transaction participant nodes.
The technical solution of the present application will be described in detail with reference to the following specific embodiments and accompanying drawings. The following several specific embodiments may be combined with each other, and details of the same or similar concepts or processes may not be repeated in some embodiments.
Fig. 1 shows a flowchart of a processing method for a distributed transaction according to an embodiment of the present application, where the method is applied to a distributed system, where the distributed system includes a coordinator node and at least two participant nodes, and the coordinator node is communicatively connected to each of the participant nodes. The distributed transaction processing method shown in fig. 1 is executed by a coordinator node, and the method may specifically include:
step S101: acquiring a service operation request sent by requester equipment, wherein the service operation request carries an operation identifier of service operation;
step S102: determining at least two target participant nodes for executing business operation from all participant nodes according to the operation identification;
the requesting device is a device that initiates a service operation request, that is, an initiator of a distributed transaction (service operation request), that is, a client, and an actual operator of the client may be a common user or an administrator of the distributed system. In practical applications, the number of the service operation requests may be one or more than one for the coordinator, and the service requested to be processed by the service operation request is a distributed transaction (or referred to as a distributed task).
The service operation request carries an operation identifier of the service operation, and the operation identifier of the service operation can uniquely indicate what kind of service the service operation corresponds to, for example, whether the service is a commodity purchasing service, a transfer service, or other services. The specific form of the operation identifier of the service operation may be configured according to actual requirements, for example, the operation identifier may be specifically a name of the operation.
In practical application, before the distributed system is online, i.e., put into use, a manager or a technician of the system may configure a mapping relationship between each service operation request and each participant node that needs to participate in executing the service operation request together according to an actual service requirement of the system, and store the mapping relationship into a coordinator node. Of course, as an optional manner, the mapping relationship may also be stored in other devices, and the coordinator node determines the target participant node according to the operation identifier by communicating with the other devices, for example, sending the operation identifier to the other devices, receiving the related information of the target participant node returned by the other devices, or obtaining the mapping relationship according to the communication with the other devices, and then determining the related information of the target participant node according to the mapping relationship. It is understood that when there are two or more service operation requests, the target participant nodes determined by different service operation requests may be completely the same, may be completely different, or may be partially the same, which is determined by the actual service configuration.
The target participant node is a participant node that needs to cooperatively complete the service operation corresponding to the certain service operation request. Each target participant node may execute a part of the business operations (hereinafter, sub-operations) in the business operations, and it can be understood that which part of the sub-operations of the business operations that each target participant node specifically executes are configured according to actual business requirements, and after the coordinator node obtains the business operation request, the coordinator node may determine the target participant node and the sub-operations that each target participant node needs to execute according to the operation identifier in the request.
Step S103: acquiring and storing a snapshot of each target participant node, wherein the snapshot is a snapshot of service data corresponding to service operation in the target participant node;
the coordinator node may obtain and store a snapshot of each target participant node by sending a snapshot generating instruction to each target participant node, for example, may store the snapshot in a snapshot cache space of the coordinator node (i.e., a cache space for storing the snapshot).
It can be understood that, for a business operation, the snapshot generating instruction is specifically a snapshot generating instruction of business data related to the business operation that the target participant node needs to perform. The target participant node generates, according to the snapshot generating instruction, a snapshot of the target participant node, where the snapshot is specifically a snapshot of the business data corresponding to the sub-operation of the business operation to be performed by the target participant node in the data stored by the target participant node (for example, a server), and it is understood that, if the target participant node only needs to execute the sub-operation of one business operation, generating a snapshot of the business data corresponding to the sub-operation of the business operation, if the target participant node needs to execute at least two business operations, the target participant node generates corresponding snapshots respectively for each business operation, for example, the target participant node needs to execute a service operation a and a service operation B, a snapshot including service data corresponding to the service operation a in the snapshot of the participant node is generated for the service operation a, and a snapshot including service data corresponding to the service operation B in the snapshot of the participant node is generated for the service operation B.
After receiving the snapshot generating instruction sent by the coordinator node, the target participant node can generate a corresponding snapshot and return the snapshot to the coordinator node.
As an example, as shown in fig. 2, for the scenario of the present application for handling transfer service, assuming that the distributed system is a banking system having independent account services in each province, assuming that account a and account B are located in different provinces, i.e. in different account servers, when transfer from account a to account B is required, it is a typical scenario of distributed transaction, and the transfer service requires that balance changes of account a and account B succeed at the same time. Specifically, the coordinator node (the coordinator shown in the figure) in this example is a node for coordinating and managing account servers of respective provinces, the account servers of the respective provinces are participant nodes in this example, and the account servers where the account a and the account B are located are target participant nodes of the transfer service. When the transfer operation request is received by the coordinator node, the transfer operation request specifically carries an operation identifier, at this time, the coordinator node can determine that the participant node executing the operation is the participant node a corresponding to the account a and the participant node B corresponding to the account B according to the identifier and the configured mapping relationship, the coordinator node can send a snapshot generating instruction corresponding to the transfer operation to the node a and the node B, after the node a and the node B receive the snapshot generating instruction, the node a generates a balance data snapshot of the account a, the node B generates a balance data snapshot of the account B, and after the snapshot generating is completed, the node a and the node B send the snapshot to the coordinator node. So that the node a and/or the node b can perform the recovery operation of the corresponding account balance according to the snapshot when the transfer service fails subsequently.
Step S104: calling each target participant node to respectively execute the sub-operation of the corresponding business operation, and acquiring the execution result of each target participant node;
step S105: and if the execution result of one node in each target participant node is execution failure, respectively sending the snapshot corresponding to each node to each target participant node so that each target participant node restores the corresponding service data to the state before the corresponding sub-operation is executed according to the snapshot.
The coordinator node calls each target participant node to respectively execute the corresponding sub-operation in the at least one business operation, when each target participant node finishes executing, fails executing or cannot execute the corresponding sub-operation, the execution result needs to be sent to the coordinator node, and after the coordinator node obtains the execution result of each target participant node, that is, it can be known whether each target participant node executes successfully, if the coordinator node finds that the execution result of one or more target participant nodes in each target participant node is execution failure, it indicates that there is a service operation request execution failure, and at this time, for the service operation request that fails to be executed, the coordinator node sends, to all or part of the target participant nodes corresponding to the service operation request, snapshots acquired in step S103, where the respective nodes correspond to the service operation request that fails to be executed.
Since the snapshot includes the snapshot of the service data corresponding to the sub-operation to be executed by the target participant node in the target participant node before the service operation is executed, for the target participant node that receives the snapshot, the target participant node can rollback the sub-operation of the service operation executed by the target participant node according to the corresponding snapshot, that is, the target participant node restores the service data to the state before the corresponding sub-operation is executed.
In this embodiment, rolling back the sub-operation of the business operation executed by the target participant node specifically means:
as described above, the number of distributed transactions in the present application may be at least one, and the number of service operation requests may also be at least one. If the target participant node only needs to execute the sub-operation of one business operation, the number of the sub-operations in the business operation corresponding to one target participant node may be at least one, that is, one target participant node may execute one or more sub-operations, and a snapshot of one target participant node may rollback one or more sub-operations, which is equivalent to binding a plurality of sub-operations to the same snapshot, and the snapshot may be used to complete one-time rollback of all sub-operations of the target participant node without performing rollback separately for each operation.
As can be seen, in the scheme of the embodiment of the present application, by introducing the snapshot, a related snapshot is generated for the operation of each subsystem in the distributed transaction (i.e., the snapshot is automatically generated before the target participant node performs the business operation), when the business execution fails, the participant node may perform the rollback operation by using the snapshot, and the business data of all the performed operations may be restored to the state before the execution according to the snapshot sent by the coordinator node. According to the scheme of the embodiment of the application, one or more operations of the target participant node are bound to the same snapshot, and the participant node utilizes the snapshot rollback operation, so that all operations executed by the participant node can be rolled back at one time without independently rolling back for each operation, and therefore the rollback operation can be realized without depending on a database to provide transaction capability, and compared with the existing TCC scheme, the invasion to service codes can be greatly reduced, and extra development workload is reduced.
In an optional embodiment of the present application, invoking each target participant node to respectively execute a sub-operation of a corresponding service operation includes:
if the snapshot of each target participant node is obtained, calling each target participant node to respectively execute corresponding sub-operations;
the method further comprises the following steps:
and if the snapshot of one node in each target participant node is not acquired, returning operation failure prompt information to the requesting equipment.
Taking the case that the coordinator processes the service operation request corresponding to one distributed transaction, the coordinator node calls each target participant node to respectively generate the snapshot of the target participant node, if the target participant nodes generate the snapshots of the target participant nodes successfully, the coordinator node can acquire the snapshots of the target participant nodes, then the coordinator node executes the subsequent steps of calling the target participant nodes to respectively execute corresponding business operations, if one or more than one target participant node in each target participant node fails to generate the snapshot of the target participant node, that is, there is a case that the snapshot of one or more than one target participant node is not acquired, at this time, the coordinator node may directly return an operation failure prompt message to the requesting device, and does not perform the subsequent step of invoking the target participant node to perform the corresponding service operation.
In practical applications, when the execution result of one or more target participant nodes is an execution failure, each target participant node needs to restore the service data to a state before executing the operation according to the corresponding snapshot, and if the snapshot acquisition failure of one or more target participant nodes exists, it indicates that if the execution result of one or more target participant nodes is a failure, the service data cannot be restored according to the snapshot, and at this time, the ACID characteristic of the entire service operation cannot be guaranteed.
In an optional embodiment of the present application, the step of sending the snapshot corresponding to each node to each target participant node, so that each target participant node restores the corresponding service data to the state before the corresponding sub-operation is executed according to the snapshot includes:
and according to the execution result of each target participant node, sending a corresponding snapshot to the target participant node with the successful execution result in each target participant node, so that each target participant node with the successful execution result restores the corresponding service data to the state before the corresponding sub-operation is executed according to the snapshot.
In practical application, as an alternative, for a service operation request, if the execution result of the service operation request is an execution failure, the coordinator node may send snapshots corresponding to each node to all target participant nodes corresponding to the service operation request, after receiving the snapshots, each node may determine whether to execute a rollback operation, if the node does not execute the corresponding service operation, or if the service operation execution fails but the transaction operation of the node satisfies an atomicity characteristic, the rollback operation may not be executed, and if the node executes the corresponding service operation successfully, the corresponding rollback operation needs to be executed according to the received snapshot.
As another optional mode, if the execution of the transaction of each participant node in the distributed system satisfies the atomicity property when executing the transaction, when the participant node executes the transaction operation, if the execution fails, the corresponding service data will automatically roll back to the state before the execution operation, at this time, the coordinator node may only send the corresponding snapshot to the target participant node that executed successfully, and the target participant node that executed successfully recovers the service data. If the transaction execution of the target participant node does not satisfy the atomicity characteristic, if the execution result of the target participant node is execution failure, there may be a case that the operation is executed partially, at this time, the node also needs to recover the service data, and the coordinator node also needs to send corresponding snapshots to the nodes.
That is to say, in practical applications, the coordinator node may determine whether to send a snapshot to the coordinator node according to the known relevant information of each target participant node, or may send corresponding snapshots to all the target participant nodes, and the target participant nodes determine whether to execute a rollback operation according to their own information.
In an optional embodiment of the present application, if at least two sub-operations of the service operation corresponding to the target participant node are provided, the service data corresponding to the service operation in the target participant node is the service data corresponding to all the sub-operations in the target participant node;
the target participant node restores the corresponding service data to the state before the corresponding sub-operation is executed according to the snapshot, which means that the target participant node restores the service data corresponding to all the sub-operations in the node to the state before all the sub-operations at one time according to the snapshot.
In practical applications, for a business operation in a distributed system, among target participant nodes for performing the business operation, the nodes may only need to perform one sub-operation of the business operation, or may need to perform multiple sub-operations in the business operation. According to the scheme provided by the embodiment of the application, because the coordinator node can acquire the snapshots of all the service data corresponding to the service operation in each target participant node, even if the target participant node needs to execute a plurality of sub-operations, the service data corresponding to the sub-operations in the node can be restored to the state before the sub-operations at one time based on the snapshots, that is, the rollback of the sub-operations is completed by one rollback operation. Compared with the existing scheme that each sub-operation needs to be executed once rollback independently, the method can greatly reduce the invasion to the service codes and reduce the development workload.
As can be seen, according to the scheme provided in the embodiment of the present application, for each target participant node, the rollback operation that substantially corresponds to the target participant node to one business operation is bound to the snapshot of all the business data related to the business operation in the target participant node, and no matter how many sub-operations of the business operation need to be executed by the target participant node, the target participant node only needs to execute a rollback operation according to the snapshot to complete the recovery of the business data related to all the sub-operations.
In an optional embodiment of the present application, if the service operation request includes at least two service operation requests, and target participant nodes corresponding to different service operation requests in the at least two service operation requests include the same node, snapshots of the target participant nodes corresponding to different service operation requests at the same time include snapshots of service data corresponding to different service operation requests in the node;
if the execution result is that the service operation request which is failed to be executed is an operation request corresponding to a target participant node which simultaneously corresponds to different service operation requests, sending a snapshot corresponding to each node to each target participant node respectively, wherein the snapshot comprises the following steps:
and sending a snapshot corresponding to the service operation request with the execution result of the target participant node being failed to execute to the target participant node simultaneously corresponding to different service operation requests.
In this embodiment, if the number of distributed transactions processed by the coordinator node is at least two, at least two distributed transactions correspond to at least two service operation requests, and target participant nodes corresponding to different service operation requests may be the same or different. In practical application, when a coordinator node processes a plurality of service operation requests, it is highly likely that the same target participant node simultaneously participates in sub-operations of two or more service operations corresponding to the plurality of service operation requests, and if a certain target participant node simultaneously corresponds to two or more service operation requests, it is necessary to respectively generate a snapshot corresponding to each service operation request, and send the snapshot corresponding to each service operation request to the coordinator node, so that when a subsequent service operation execution failure (a sub-task execution failure of one or more target participant nodes of a service operation request) occurs, the coordinator node can send the snapshot corresponding to the service operation to the target participant node, so that the target participant node performs service data recovery based on the received snapshot.
For example, a certain target participant node a executes a sub-operation of a service operation a and a sub-operation of a service operation B, and if the service operation a is successfully executed and the service operation B is failed to be executed in the subsequent processing process of each service operation, the target participant node only needs to perform data recovery based on the snapshot corresponding to the service operation B. Of course, when the service operation B fails to execute, if the operation performed by the node a by the corresponding sub-operation fails and the operation processed by the node B satisfies the characteristic of atomicity of the transaction, the node B may not execute the data recovery.
In this embodiment, for a node that simultaneously executes sub-operations of multiple service operations, if all execution results of the multiple sub-service operations executed by the node are failures, the node may also complete one-time recovery of service data based on multiple corresponding snapshots.
In an optional embodiment of the present application, determining at least two target participant nodes for performing a business operation from all the participant nodes according to the operation identifier includes:
determining at least two target participant nodes for executing business operation according to the operation identifier and a pre-configured service mapping relation;
the service mapping relationship is a corresponding relationship between each operation identifier and node related information of each participant node for executing the business operation corresponding to each operation identifier.
The node related information may include a node identifier of the participant node, where the node identifier may indicate which participant node is specifically a participant node in the distributed system, and the identifier may be a number of the participant node, or a name of the participant node. The coordinator node can determine the node identifier of each target participant node corresponding to the operation identifier of the current business operation request according to the service mapping relation, namely determine each target participant node.
It is understood that the service mapping relationship is a correspondence relationship between each operation identifier and node-related information of each participant node for performing the business operation corresponding to each operation identifier. As a simple example, it is assumed that the service operation of the distribution system includes operation a, operation B, and operation C, the participant nodes for performing operation a are node a and node B, the nodes for performing operation B are node B, node C, and node d, and the nodes for performing operation C are node a and node C, and then the mapping relationship in this example is the correspondence relationship between operation a and the node-related information of node a and node B, the correspondence relationship between operation B and the node-related information of node B, node C, and node d, and the correspondence relationship between operation C and the node-related information of node a and node C.
In an optional embodiment of the present application, the node-related information includes a service operation interface call address, a snapshot generation interface call address, and a rollback interface call address of the participant node.
Specifically, the service operation interface call address is a call address of an application program interface of the computing unit for completing the corresponding service operation, and based on the address, the coordinator node may send the service operation instruction to the data processing unit corresponding to the target participant node by calling the interface corresponding to the address. Similarly, based on the snapshot generation interface calling address, the coordinator node may send a snapshot generation instruction to the data processing unit corresponding to the target participant node through the snapshot generation interface corresponding to the address, and based on the rollback interface calling address, the coordinator node may send a rollback instruction to the data processing unit corresponding to the target participant node through the rollback interface corresponding to the address.
Correspondingly, the invoking of the sub-operations of each target participant node to respectively execute the corresponding business operation may specifically include:
and calling the service operation interface corresponding to the calling address of the service operation interface of each target participant node, and sending a service operation instruction of the corresponding sub-operation to each target participant node so that each target participant node executes the corresponding sub-operation based on the service operation instruction.
The obtaining the snapshot of each target participant node may specifically include:
and for each target participant node, calling the interface corresponding to the snapshot generating interface calling address of each target participant node, sending a snapshot generating instruction to each target participant node, and receiving the snapshot returned by each target participant node according to the snapshot generating instruction.
That is, the service mapping relationship may further include call address information of each relevant function interface of each target participant node, and when the coordinator node determines each target participant node, the coordinator node may call an interface corresponding to each target participant node according to the call address of each function interface to complete a corresponding operation. As described above, the service operation instruction of the corresponding sub-operation is sent to the target participant node through the service operation interface, the snapshot generating instruction is sent to the target participant node through the snapshot generating interface, and after each target participant node receives each instruction, the corresponding operation can be executed.
In an alternative embodiment of the present application, the method further comprises:
and calling a rollback interface corresponding to the rollback interface calling address of each target participant node, and sending a rollback instruction to each target participant node so that each target participant node restores the corresponding service data to a state before executing the corresponding sub-operation according to the rollback instruction and the snapshot.
Specifically, for a distributed transaction service operation, after receiving execution results returned by each target participant node, if the execution results include execution failure results, the coordinator node needs to recover service data of some or all of the target participant nodes, and at this time, the coordinator node may send a rollback instruction to the target participant node based on a rollback interface determined by the service mapping relationship. After receiving the rollback instruction and the corresponding snapshot, the target participant node may execute a rollback operation of the service data based on the data in the snapshot, and restore the service data to a state before the operation.
In practical application, when the coordinator node sends the snapshots corresponding to the nodes to the target participant nodes, the rollback instruction and the snapshots may be sent to the target participant nodes through the rollback interface, or the rollback instruction and the snapshots may be sent to the target participant nodes respectively, for example, the rollback instruction is sent to the target participant nodes through the rollback interface, and the snapshots are sent to the target participant nodes through other interfaces; or after the rollback instruction is sent to the target participant node, if the participant node determines that the participant node needs to execute the rollback operation, a snapshot obtaining request is sent to the coordinator node, and the coordinator node sends the snapshot to the corresponding target participant node.
In an optional embodiment of the present application, if at least two sub-operations of the service operation corresponding to the target participant node are provided, the snapshot generating interface call address and the rollback interface call address satisfy at least one of the following: the snapshot generating interface calling addresses corresponding to all the sub-operations are the same;
and the call addresses of the rollback interfaces corresponding to all the sub-operations are the same.
In the solution of the embodiment of the application, for any target participant node, when a service operation is executed, regardless of whether the number of sub-operations to be executed by the target participant node is one or more, the recovery of service data, that is, the execution of the rollback operation, is performed according to snapshots of service data corresponding to the sub-operations before the execution of the operation, that is, all related service data related to all sub-operations to be executed by the node are bound to the same snapshot, and therefore, when the node needs to execute the rollback operation, the recovery of the service data related to all sub-operations can be completed only by executing the rollback operation once according to the snapshot. Based on this, in the solution of the embodiment of the present application, the snapshot generating interfaces and/or the rollback interface calling addresses of all sub-operations in one service operation to be completed by the target participant node may use the same address, and when it is necessary to obtain snapshots of all sub-operations of the service operation corresponding to the target participant node or send a rollback instruction to the node, the coordinator node may call an interface corresponding to the address to initiate a snapshot generating instruction and/or a rollback instruction through the snapshot generating interface and/or the rollback interface calling address shared by all the sub-operations.
By the method, for one business operation, all sub-operations of the current business operation related to one target participant node only need to correspond to one unified snapshot generating interface and/or rollback interface, and compared with the existing method that one sub-operation corresponds to one rollback interface, the method greatly reduces intrusion of business codes and greatly reduces extra development workload.
In an optional embodiment of the present application, if the service operation request includes at least two service operation requests, and the target participant node corresponding to a different service operation request in the at least two service operation requests includes the same node, the snapshot generating interface call address and the rollback interface call address of the target participant node corresponding to the different service operation requests at the same time satisfy at least one of the following:
the target participant node generates the same interface calling address corresponding to the snapshot of different service operation requests;
the call addresses of the rollback interfaces of the target participant node corresponding to different service operation requests are the same.
In this embodiment of the present application, the number of distributed transactions, that is, service operation requests, may be multiple, for a target participant node, the call addresses of the snapshot generating interfaces corresponding to all service operations that the node can execute (that is, needs to participate in) may be the same, and similarly, the call addresses of the rollback interfaces of all service operations that the node can execute may be the same, that is, multiplexing of the snapshot generating interfaces and/or the rollback interfaces corresponding to multiple service operations is implemented. Regardless of which business operation or operations the participant node needs to perform, the coordinator node may send snapshot generation instructions and/or rollback instructions to the participant node over the multiplexed interface.
In the embodiment of the application, the coordinator node generates the snapshots corresponding to the multiple service operations of the node by calling one snapshot generating interface of the target participant node, and similarly, a rollback instruction can be sent to the node by calling the same rollback interface from the node. Compared with the existing scheme that one sub-operation of one node needs to correspond to one interface, the method greatly reduces the intrusion to the service code and greatly reduces the extra development workload.
The following describes a scheme of an embodiment of the present application with reference to a specific application scenario.
The application scenario in this example is that for the distrusted person P, the bank needs to freeze all accounts in its name, and there may be a frozen account in the account of the person P before operation, so it is desirable that this operation is also atomic, that is, after the operation fails, all accounts maintain the state before operation. As shown in fig. 3, the coordinator in the graph is a coordinator node, the participant node is a target participant node, the target participant node in this example is an account server where each account of the person P is located, the state of the participant node on the left side of the arrow successfully shown in the figure is the state of each account of the person P before the freezing operation is performed, as can be seen from the figure, the account B before the operation is in the frozen state, the states of other accounts are in the normal state, and the right side of the arrow successfully shown is the state of each account after the freezing operation is successfully performed, that is, the states of all accounts are changed into the frozen state.
For the application scenario shown in this example, if a traditional TCC scheme is used, then for the operation of adjusting the account freeze state, each participant node (account a, account B, account C …, and the account server where account N resides) must have a corresponding rollback state operation. It should be understood that, by way of example only, there are many scenarios in which distributed transactions exist, such as a seller and a loan, and in the conventional TCC scheme, each operation has a corresponding rollback operation in each scenario of distributed transactions, which results in a large extra development workload.
Based on the scheme provided by the embodiment of the application, for each account, the balance, the frozen state and the like of the account can be regarded as the attributes of the account, before the operation related to the account, a snapshot of the account is saved, the snapshot comprises all the attributes related to the account, such as the balance, the frozen state and the like, and if the operation fails, the data can be restored by using the snapshot. Therefore, all operations related to the account only need to correspond to one unified rollback interface, all operations of the account are rolled back at one time by using the snapshot of the account, and therefore additional development workload is greatly reduced. For example, for an account, business operations of transferring out an account balance and freezing two distributed transactions exist at the same time, and the balance and the account state are business data corresponding to the operations, based on the scheme of the embodiment of the present application, for an account balance transferring out the distributed transaction, a snapshot of the account balance needs to be acquired and stored, for an account freezing the distributed transaction, a snapshot of the account state needs to be acquired and stored, and if a rollback business operation needs to be performed after the two business operations are executed, the account server only needs to complete the recovery of the balance and the account state based on the two stored snapshots. Of course, if the service operation of any distributed transaction is successful, for example, the account is successfully frozen, only the data recovery of the account balance needs to be performed with respect to the snapshot of the account state, that is, the coordinator node only needs to transfer the snapshot of the account balance to the target participant node corresponding to the distributed transaction out of the account balance.
Based on the same principle as the method shown in fig. 1, the embodiment of the present application further provides a method for processing a distributed transaction, where the method is applied to a distributed system, the distributed system includes a coordinator node and at least two participant nodes, the coordinator node is connected to each participant node in a communication manner, and the method is executed by a target participant node; as shown in fig. 4, the method may mainly include the following steps:
step S401: when a snapshot generating instruction sent by a coordinator node is received, generating a corresponding snapshot according to the snapshot generating instruction, and sending the snapshot to the coordinator node; the method comprises the steps that a snapshot is a snapshot of service data corresponding to a service operation request in a target participant node, and the target participant node is determined according to an operation identifier of service operation carried in the service operation request when a coordinator node acquires the service operation request sent by requester equipment;
step S402: when a business operation instruction sent by a coordinator node is received, executing corresponding business operation according to the business operation instruction, and sending an execution result to the coordinator node;
step S403: and when receiving the snapshot sent by the coordinator node, restoring the corresponding service data to the state before the corresponding service operation is executed according to the snapshot.
The snapshot is sent when the coordinator node has an execution result of the target participant node in the received execution results, wherein the execution result is execution failure.
It is clear to those skilled in the art that the method shown in fig. 4 is substantially systematic with the method shown in fig. 1, the method shown in fig. 1 is described from the perspective of a coordinator node standing in a distributed system, and the method shown in fig. 4 is described from the perspective of a participant node standing in the distributed system, so that the detailed description of the method shown in fig. 4 and its effect can be referred to the corresponding description of the method shown in fig. 1 and its optional embodiments in the foregoing, and will not be described again here.
In an optional embodiment of the present application, if the generation of the corresponding snapshot according to the snapshot generating instruction fails, the method may further include:
sending snapshot generation failure prompt information to the coordinator node, so that the coordinator node returns operation failure prompt information to the requesting equipment when receiving the prompt information.
For one service operation, because the recovery of the service data needs to be completed according to the snapshot, if the snapshot acquisition of the target participant node fails, the recovery of the corresponding service data cannot be completed subsequently, and at this time, the coordinator node directly returns the prompt information of the operation failure to the operation requester without performing the subsequent operation, so that the flow of the whole service operation is ended.
As can be seen from the foregoing description, for a service operation request initiated by a requesting device, if a target participant node needs to execute multiple sub-operations in the service operation, according to the solution of the embodiment of the present application, the multiple sub-operations of the target participant node may correspond to the same snapshot generating interface and/or rollback operation interface, that is, for a service operation, regardless of the target participant node needs to execute several sub-operations of the service operation, the snapshot generating interface and/or rollback operation interface of the target participant node corresponding to the service operation may be the same.
Likewise, for multiple business operations, regardless of the target participant node needing to perform several sub-operations of the business operation, the snapshot generating interface and/or the rollback operation interface of the target participant node corresponding to the multiple business operations may be the same.
In addition, in this embodiment, for one business operation, if the operation of the distributed transaction performed by the target participant node satisfies the atomicity characteristic, the target participant node that needs to perform the rollback operation (i.e., perform the business data recovery operation) may be the target participant node that successfully performs the sub-operation, and if the sub-operation of the distributed transaction performed by the target participant node does not satisfy the atomicity, the target participant node is any one of all target participant nodes of the business operation.
Distributed transactions exist widely in various internet systems, often strong consistency systems such as payments, transactions, orders, etc. The above solutions provided in the embodiments of the present application are theoretically applicable to all application scenarios in which distributed transactions exist.
The distributed transaction control logic is completely imperceptible to the user, but it ensures that each operation of the user conforms to the ACID 4 basic characteristics. For example, as shown in fig. 5, a user pays for goods on the e-commerce system, and actually comprises several operations of inventory reduction, payment, logistics ordering and the like in the e-commerce system, and the distributed transaction control ensures that the several operations are either successful or failed together, and is simplified to an operation of purchasing goods, either successful or failed in front of the user.
Each participant node in the e-commerce system respectively executes a plurality of operations such as inventory reduction, payment, logistics ordering and the like, before executing the business operation, the participant node executing the inventory reduction operation carries out snapshot on the business data of the inventory reduction operation, the participant node executing the payment operation carries out snapshot on the business data of the payment operation, the participant node executing the logistics ordering operation carries out snapshot on the business data of the logistics ordering operation, if the purchase fails, the participant node executing the inventory reduction operation, the participant node executing the payment operation, and the participant node executing the logistics ordering operation successfully or all the nodes need to carry out rollback by using respective object snapshots, for example, the participant node executing the logistics ordering operation can utilize all the operations involved in the one-time rollback logistics ordering operation, so that all the operations of the participant nodes can be rolled back by utilizing the snapshots of the participant node, compared with the TCC scheme, the method greatly reduces the invasion of the service codes and reduces excessive extra workload.
In fact, one participant node can execute the operation of other distributed tasks besides the operation of the distributed task of paying for and purchasing commodities on the E-commerce system, the same node also calls the same snapshot generating interface to generate corresponding snapshots aiming at the operation of other distributed tasks, and the snapshots can be used for rolling back the operation of other distributed tasks.
In order to better explain the scheme provided by the embodiments of the present application, the following describes the relevant contents of the embodiments of the present application with some examples.
A basic architecture diagram of a distributed system in an example of the present application is shown in fig. 6. The coordinator node in this example is a server cluster including a plurality of coordinators (coordinator 1, coordinator 2, and coordinator 3 shown in the figure), and the participant node service 1, participant node service 2, and participant node service 3 shown in the figure are schematic representations of the participant nodes in this example. The following describes each part of the system in different scenes.
Configuration of service mapping relationships (mapping configuration service shown in the figure)
Before the system is on-line, or the service mapping relation in the system which is on-line is configured. The configuration process mainly comprises:
1. a system manager draws up a service mapping relation of business operation according to an actual business scene and a rule;
specifically, the administrator plans a reasonable operation name (operation identifier in this example) for each distributed business operation, and configures relevant information of all participant nodes corresponding to each business operation, specifically, a business operation interface calling address of a participant node (for example, a calling address of 3 interfaces required for stock reduction, payment and logistics, which are included in purchasing goods), a snapshot generating interface calling address of all participant nodes corresponding to the business operation, and a rollback interface calling address of all participant nodes corresponding to the business operation.
2. A system manager inputs a proposed service mapping relation through a control console (mapping relation editing shown in the figure);
3. after receiving the service mapping relation input by the console, the mapping configuration service stores the service mapping relation and stores the service mapping relation in a mapping relation database;
4. and after the mapping configuration service receives the service mapping relation input by the console, synchronizing the service mapping relation to all the coordinators, and storing the service mapping relation into a cache of the coordinators.
In this example, the service mapping relationship may include the following four parts:
operation name (operation identification in this example), a reasonable name is drawn for the overall operation;
the calling addresses of the business operation interfaces of all the participant nodes involved in the operation, such as 3 interfaces for stock reduction, payment and logistics ordering, which need to be included for purchasing goods;
the snapshot of all participant nodes corresponding to the business operation generates an interface call address;
the rollback interface call addresses of all participant nodes corresponding to the business operation.
The configuration of the service mapping relationship is described below with reference to a specific example.
As shown in fig. 7, a schematic diagram of a service mapping relationship in an intelligent dialog platform service is shown in this example. As shown in the figure, the service registration information in this example needs to include names and addresses (calling addresses of the business operation interfaces) of all participant node services (i.e., business services provided by the participant nodes), snapshot generating addresses of all participant nodes, and rollback calling addresses of all participant nodes, i.e., rollback interface calling addresses. Specifically, all the participant node services in this example include the metadata service, the a algorithm platform service, and the B algorithm platform service shown in the figure, the nodes (robots in this example) where these services are located are the participant nodes, and the robot information (i.e., all the business data related to the business operation request in this example) needs to be simultaneously stored in three parties, namely the metadata service, the a algorithm platform service, and the B algorithm platform service (as the business develops, it may also be stored in more algorithm platforms). When the robot information needs to be modified, the robot providing the metadata service, the A algorithm platform service and the B algorithm platform service needs to be modified at the same time. Therefore, for the operation of modifying robot information, it is necessary to configure the call address of the modified robot information served at 3 points, that is, the robot information modification address at 3 points shown in the figure (i.e., the service operation interface call address), the snapshot generation interface call address of each robot (i.e., the snapshot generation address shown in the figure), and the rollback interface call address of each robot (i.e., the information rollback address shown in the figure), and to set up the overall operation name as "UpdateRobot (modified robot information)".
In the intelligent dialogue platform, virtually all business operations are directed at the robot, that is, the snapshot generating interface and the rollback interface corresponding to substantially all business operations (for example, tens of business operations) can be the same, even if new business operations are subsequently added, the current snapshot generating interface and rollback interface can be directly reused in a large probability, after the new interfaces are developed, only a proposed service mapping relation needs to be entered by a console, a distributed transaction can be started, the multiplexing of the snapshot generating interface and the rollback interface is realized, and the development workload is reduced.
After the configuration of the service mapping relationship is completed, the distributed transaction processing may be performed based on the scheme provided in the embodiment of the present application, and a processing flow of the distributed transaction is described below, where the processing flow mainly includes:
1. client request flow
Since the coordinator (i.e., coordinator node) helps the client to complete the call of all the participant nodes (i.e., participant nodes), for the client, it is equivalent to a plurality of operations are combined into one atomic operation, so the client only needs to send a call request to the coordinator cluster (e.g., the coordinator cluster (i.e., coordinator node) formed by the coordinator 1, the coordinator 2, and the coordinator 3 in fig. 6), but an operation name (an optional manner of operation identifier) needs to be additionally transmitted in the request body, and the coordinator needs to obtain a corresponding service mapping relationship according to the operation name.
2. Coordinator processing request flow
As shown in fig. 8, the flow of the coordinator processing the request may include:
2.1, after receiving a business operation request of a requesting device, a coordinator firstly acquires a corresponding service mapping relation according to an operation name in the request, wherein the acquired service mapping relation comprises business operation interface calling addresses, snapshot generating interface calling addresses and rollback interface calling addresses corresponding to all target participant nodes;
2.2, the coordinator generates an interface corresponding to the interface calling address through the snapshot of each target participant node, sends a snapshot generating instruction to each target participant node so that each target participant node generates a snapshot, each target participant node returns the snapshot generated by the coordinator, and the coordinator caches the snapshot of each target participant node (namely, the coordinator calls the target participant node to generate an object snapshot of each target participant node in a corresponding graph and stores the object snapshot in the snapshot cache process);
2.3, when all snapshots are stored, the coordinator calls the service operation interfaces corresponding to all the participant nodes at the same time, and sends service operation instructions to all the participant nodes, namely calls all the target participant nodes to execute the service operation corresponding to all the nodes;
and 2.4, when all the target participant nodes successfully execute the service operation, the coordinator returns call success information to the requesting equipment.
In the above processing flow, in the process of obtaining the snapshot, if the snapshot generation of any participant node fails, the coordinator may directly return an operation failure prompt message to the requesting device, and end the entire operation flow.
If the snapshot corresponding to each target participant node is successfully acquired, in a subsequent processing flow, if business operation of any one or more target participant nodes fails, namely, the execution result of the target participant node is execution failure, the coordinator calls a rollback interface of all the target participant nodes or the target participant nodes of which the execution result is successful, sends a rollback instruction to each target participant node, and sends the corresponding snapshot to the corresponding node, so that the corresponding target participant node executes a rollback operation according to the corresponding snapshot to complete recovery of business data.
In an alternative embodiment of the present application, the participant nodes in the distributed system include blockchain nodes.
The distributed system according to the embodiment of the present application may be a distributed system based on a blockchain technology, where a blockchain is essentially a decentralized database, and multiple tasks may be executed on different blockchain nodes, and a node in the blockchain system may be on one server, or multiple nodes are on the same server, and at this time, a node in each blockchain corresponds to one participant node. When a task in a blockchain (i.e., a service operation request in a blockchain system) needs to be executed each time, a blockchain link point that needs to participate in the task is a target participant node, and in the blockchain system, the target participant node may be a part or all of nodes in the blockchain, and may correspond to different configurations according to different actual application requirements.
It should be understood that the coordinator node in the embodiment of the present application may also be a blockchain node, and in this case, the blockchain node serving as the coordinator node is equivalent to a management node in a blockchain system, and is used for management and coordination of the participant nodes.
Corresponding to the method provided by the embodiment of the present application, an embodiment of the present application further provides a distributed transaction processing apparatus, where the apparatus is applied to a distributed system, and the distributed system includes a coordinator node and at least two participant nodes, as shown in fig. 9, the distributed transaction processing apparatus 900 may include a transceiver module 901, a target node determining module 902, and a target node invoking module 903, where:
a transceiver module 901, configured to acquire a service operation request sent by a requester device, where the service operation request carries an operation identifier of a service operation;
a target node determining module 902, configured to determine, according to the operation identifier, at least two target participant nodes used for performing a service operation from all participant nodes;
the transceiving module 901 is further configured to obtain and store a snapshot of each target participant node, where the snapshot is a snapshot of service data corresponding to the service operation request in the target participant node;
a target node calling module 903, configured to call each target participant node to execute a sub-operation of the corresponding service operation, and obtain an execution result of each target participant node;
the transceiving module 901 is further configured to send, if there is an execution result of one node in each target participant node that is an execution failure, a snapshot corresponding to each node to each target participant node, so that each target participant node restores the corresponding service data to a state before the corresponding sub-operation is executed according to the snapshot.
Optionally, the target node invoking module 903, when invoking each target participant node to respectively execute the sub-operation of the corresponding service operation, is specifically configured to:
if the snapshot of each target participant node is obtained, calling each target participant node to respectively execute corresponding sub-operations;
a transceiver module 901, further configured to:
and if the snapshot of one node in each target participant node is not acquired, returning operation failure prompt information to the requesting equipment.
Optionally, when the transceiver module 901 sends the snapshot corresponding to each node to each target participant node, so that each target participant node restores the corresponding service data to the state before executing the corresponding sub-operation according to the snapshot, specifically, the transceiver module is configured to:
and according to the execution result of each target participant node, sending a corresponding snapshot to the target participant node with the successful execution result in each target participant node, so that each target participant node with the successful execution result restores the corresponding service data to the state before the corresponding sub-operation is executed according to the snapshot.
Optionally, if the number of the sub-operations of the service operation corresponding to the target participant node is at least two, the service data corresponding to the service operation in the target participant node is the service data corresponding to all the sub-operations in the target participant node; the target participant node restores the corresponding service data to the state before the corresponding sub-operation is executed according to the snapshot, which means that the target participant node restores the service data corresponding to all the sub-operations in the node to the state before all the sub-operations at one time according to the snapshot.
Optionally, if the service operation request includes at least two service operation requests, and the target participant node corresponding to a different service operation request in the at least two service operation requests includes the same node, the snapshot of the target participant node corresponding to the different service operation request at the same time includes the snapshot of the service data corresponding to the different service operation request in the node;
if the execution result is that the service operation request which is failed to be executed is an operation request corresponding to a target participant node which simultaneously corresponds to different service operation requests, the transceiver module respectively sends snapshots corresponding to the nodes to the target participant nodes, and is specifically configured to:
and sending a snapshot corresponding to the service operation request with the execution result of the target participant node being failed to execute to the target participant node simultaneously corresponding to different service operation requests.
Optionally, when determining, according to the operation identifier, at least two target participant nodes for performing the service operation, the target node determining module 902 is specifically configured to:
determining at least two target participant nodes for executing business operation according to the operation identifier and a pre-configured service mapping relation;
the service mapping relationship is a corresponding relationship between each operation identifier and node related information of each participant node for executing the business operation corresponding to each operation identifier.
Optionally, the node-related information includes a service operation interface calling address, a snapshot generating interface calling address, and a rollback interface calling address of the participant node.
Optionally, if at least two sub-operations of the service operation corresponding to the target participant node are performed, the snapshot generating interface call address and the rollback interface call address satisfy at least one of the following:
the snapshot generating interface calling addresses corresponding to all the sub-operations are the same;
and the call addresses of the rollback interfaces corresponding to all the sub-operations are the same.
Optionally, if the service operation request includes at least two service operation requests, and the target participant node corresponding to a different service operation request in the at least two service operation requests includes the same node, the snapshot generating interface call address and the rollback interface call address of the target participant node corresponding to the different service operation requests simultaneously satisfy at least one of the following:
the target participant node generates the same interface calling address corresponding to the snapshot of different service operation requests;
the call addresses of the rollback interfaces of the target participant node corresponding to different service operation requests are the same.
Optionally, the target node invoking module 903, when invoking each target participant node to respectively execute the sub-operation of the corresponding service operation, is specifically configured to:
calling a business operation interface corresponding to the address by calling the business operation interface of each target participant node, and sending a business operation instruction of a corresponding sub-operation to each target participant node so as to enable each target participant node to execute the corresponding sub-operation based on the business operation instruction;
when acquiring a snapshot of each target participant node, the transceiver module 901 is specifically configured to:
for each target participant node, calling an interface corresponding to the snapshot generating interface calling address of each target participant node, sending a snapshot generating instruction to each target participant node, and receiving a snapshot returned by each target participant node according to the snapshot generating instruction;
the transceiver module 901 is further configured to: and calling a rollback interface corresponding to the rollback interface calling address of each target participant node, and sending a rollback instruction to each target participant node so that each target participant node restores the corresponding service data to a state before executing the corresponding sub-operation according to the rollback instruction and the snapshot.
Optionally, the participant nodes in the distributed system include blockchain nodes.
Corresponding to the method provided by the embodiment of the application, the embodiment of the application also provides a distributed transaction processing device, the device is applied to a distributed system, and the distributed system also comprises a coordinator node and at least two participant nodes;
as shown in fig. 10, the distributed transaction processing apparatus 1000 includes a snapshot generating module 1001, a business operation executing module 1002, and a business operation restoring module 1003:
a snapshot generating module 1001, configured to generate a corresponding snapshot according to a snapshot generating instruction when receiving a snapshot generating instruction sent by a coordinator node, and send the snapshot to the coordinator node, where the snapshot is a snapshot of service data corresponding to a service operation request in a target participant node, and the target participant node is determined according to an operation identifier of a service operation carried in the service operation request when the coordinator node acquires the service operation request sent by a requester device;
the service operation execution module 1002 is configured to, when receiving a service operation instruction sent by a coordinator node, execute a corresponding service operation according to the service operation instruction, and send an execution result to the coordinator node;
the service operation recovery module 1003 is configured to, when receiving a snapshot sent by a coordinator node, recover corresponding service data to a state before executing a corresponding service operation according to the snapshot, where the snapshot is sent when an execution result of a target participant node in the received execution result is an execution failure.
Optionally, the apparatus further includes a prompt information sending module, where the prompt information sending module is configured to:
when the snapshot generating module 1001 fails to generate a corresponding snapshot according to the snapshot generating instruction, snapshot generation failure prompt information is sent to the coordinator node, so that the coordinator node returns operation failure prompt information to the requester device when receiving the prompt information.
Since the apparatus provided in the embodiment of the present invention is an apparatus capable of executing the method corresponding to the embodiment of the present invention, based on the method provided in the embodiment of the present invention, a specific implementation manner of the apparatus in the embodiment of the present invention and various modifications thereof can be understood by those skilled in the art, and therefore, how to implement the method in the embodiment of the present invention by the apparatus is not described in detail herein. The apparatus used by those skilled in the art to implement the method of the embodiments of the present invention is within the scope of the present application.
Based on the same principle as the method provided by the embodiment of the present application, the embodiment of the present application also provides an electronic device, which includes a memory and a processor; the memory has a computer program stored therein; the processor is adapted to perform the method provided in any of the alternative embodiments of the present application when executing the computer program.
Embodiments of the present application further provide a computer-readable storage medium, on which a computer program is stored, and when the computer program is executed by a processor, the computer program can implement the method provided in any optional embodiment of the present application.
As an example, fig. 11 shows a schematic structural diagram of an electronic device to which the present application may be applied, where the electronic device may specifically be a server or may be another device, the electronic device 8000 includes a memory 8003 and a processor 8001, the memory 8003 stores a computer program, and the processor 8001 is configured to execute any one of the methods when the computer program is executed. In particular, fig. 11 illustrates only an alternative schematic structure of the electronic device. The structure of the electronic device 8000 shown in fig. 11 is not limited to the embodiment of the present application.
Processor 8001 is coupled to memory 8003, such as via bus 8002. Optionally, the electronic device 8000 may also include a transceiver 8004. It should be noted that the transceiver 8004 is not limited to one in practical applications, and the transceiver 8004 may be specifically used for communication between the electronic device 8000 and other devices.
Processor 8001 may be a CPU (Central Processing Unit), general purpose Processor, DSP (Digital Signal Processor), ASIC (Application Specific Integrated Circuit), FPGA (Field Programmable Gate Array), or other Programmable logic device, transistor logic device, hardware component, or any combination thereof. Which may implement or perform the various illustrative logical blocks, modules, and circuits described in connection with the disclosure. Processor 8001 may also be a combination that implements computing functionality, e.g., comprising one or more microprocessor combinations, DSP and microprocessor combinations, and so forth.
Bus 8002 may include a path to transfer information between the aforementioned components. The bus 8002 may be a PCI (Peripheral Component Interconnect) bus, an EISA (Extended Industry Standard Architecture) bus, or the like. The bus 8002 may be divided into an address bus, a data bus, a control bus, and the like. For ease of illustration, only one thick line is shown in FIG. 11, but this is not intended to represent only one bus or type of bus.
The Memory 8003 may be a ROM (Read Only Memory) or other type of static storage device that can store static information and instructions, a RAM (Random Access Memory) or other type of dynamic storage device that can store information and instructions, an EEPROM (Electrically Erasable Programmable Read Only Memory), a CD-ROM (Compact Disc Read Only Memory) or other optical Disc storage, optical Disc storage (including Compact Disc, laser Disc, optical Disc, digital versatile Disc, blu-ray Disc, etc.), a magnetic Disc storage medium or other magnetic storage device, or any other medium that can be used to carry or store desired program code in the form of instructions or data structures and that can be accessed by a computer, but is not limited to these.
The memory 8003 is used for storing application program codes for executing the scheme of the present application, and the execution is controlled by the processor 8001. Processor 8001 is configured to execute application program code stored in memory 8003 to implement what is shown in any of the method embodiments above.
It should be understood that, although the steps in the flowcharts of the figures are shown in order as indicated by the arrows, the steps are not necessarily performed in order as indicated by the arrows. The steps are not performed in the exact order shown and may be performed in other orders unless explicitly stated herein. Moreover, at least a portion of the steps in the flow chart of the figure may include multiple sub-steps or multiple stages, which are not necessarily performed at the same time, but may be performed at different times, which are not necessarily performed in sequence, but may be performed alternately or alternately with other steps or at least a portion of the sub-steps or stages of other steps.
The foregoing is only a partial embodiment of the present invention, and it should be noted that, for those skilled in the art, various modifications and decorations can be made without departing from the principle of the present invention, and these modifications and decorations should also be regarded as the protection scope of the present invention.

Claims (15)

1. A method for processing a distributed transaction, the method being applied to a distributed system, the distributed system including a coordinator node and at least two participant nodes, the coordinator node being communicatively connected to each of the participant nodes, the method comprising:
acquiring a service operation request sent by requester equipment, wherein the service operation request carries an operation identifier of service operation;
determining at least two target participant nodes for executing the business operation from all participant nodes according to the operation identification;
acquiring and storing a snapshot of each target participant node, wherein the snapshot is a snapshot of service data corresponding to the service operation in the target participant node;
calling each target participant node to respectively execute corresponding sub-operations of the business operation, and acquiring the execution result of each target participant node;
if the execution result of one node in each target participant node is execution failure, sending a snapshot corresponding to each node to each target participant node respectively so that each target participant node restores the corresponding service data to the state before executing the corresponding sub-operation according to the snapshot;
wherein, the sending the snapshot corresponding to each node to each target participant node respectively so that each target participant node restores the corresponding service data to the state before executing the corresponding sub-operation according to the snapshot includes:
and if the service operation meets the atomicity characteristic, sending a corresponding snapshot to a target participant node which is successfully executed, and if the service operation does not meet the atomicity characteristic, sending the corresponding snapshot to the target participant node which is successfully executed and successfully executes the partial progress.
2. The method of claim 1, wherein said invoking each of said target participant nodes to perform a corresponding sub-operation of said business operation, respectively, comprises:
if the snapshot of each target participant node is obtained, calling each target participant node to respectively execute corresponding sub-operations;
the method further comprises the following steps:
and if the snapshot of one node in each target participant node is not acquired, returning operation failure prompt information to the requesting equipment.
3. The method according to claim 1, wherein the sending the snapshot corresponding to each node to each target participant node, so that each target participant node restores the corresponding service data to the state before the corresponding sub-operation is performed according to the snapshot, comprises:
and sending corresponding snapshots to target participant nodes with successful execution results in the target participant nodes according to the execution results of the target participant nodes, so that the target participant nodes with successful execution results restore the corresponding service data to the state before the corresponding sub-operation is executed according to the snapshots.
4. The method according to claim 1, wherein if the number of the sub-operations of the business operation corresponding to the target participant node is at least two, the business data corresponding to the business operation in the target participant node is the business data corresponding to all the sub-operations in the target participant node;
the target participant node restores the corresponding service data to the state before the corresponding sub-operation is executed according to the snapshot, which means that the target participant node restores the service data corresponding to all the sub-operations in the node to the state before all the sub-operations at one time according to the snapshot.
5. The method according to claim 1, wherein if the at least two service operation requests include at least two service operation requests, and the target participant nodes corresponding to different service operation requests in the at least two service operation requests include the same node, then snapshots of the target participant nodes corresponding to different service operation requests at the same time include snapshots of service data corresponding to different service operation requests in the node;
if the execution result is that the service operation request which is failed to be executed is an operation request corresponding to a target participant node which simultaneously corresponds to different service operation requests, the sending the snapshot corresponding to each node to each target participant node respectively comprises the following steps:
and sending a snapshot corresponding to the service operation request with the execution result of the target participant node being failed to execute to the target participant node simultaneously corresponding to different service operation requests.
6. The method according to any one of claims 1 to 5, wherein the determining, according to the operation identifier, at least two target participant nodes for performing the business operation from all participant nodes comprises:
determining at least two target participant nodes for executing the business operation according to the operation identifier and a pre-configured service mapping relation;
the service mapping relationship is a corresponding relationship between each operation identifier and node related information of each participant node for executing the business operation corresponding to each operation identifier.
7. The method of claim 6, wherein the node-related information comprises a business operation interface call address, a snapshot generation interface call address, and a rollback interface call address of the participant node.
8. The method according to claim 7, wherein if the number of the sub-operations of the business operation corresponding to the target participant node is at least two, the snapshot generation interface call address and the rollback interface call address satisfy at least one of the following:
the snapshot generating interface calling addresses corresponding to all the sub-operations are the same;
and the call addresses of the rollback interfaces corresponding to all the sub-operations are the same.
9. The method according to claim 7, wherein if the at least two service operation requests include at least two service operation requests, and the target participant node corresponding to a different service operation request in the at least two service operation requests includes the same node, the snapshot generating interface calling address and the rollback interface calling address of the target participant node corresponding to the different service operation requests at the same time satisfy at least one of:
the target participant node generates the same interface calling address corresponding to the snapshot of different service operation requests;
the call addresses of the rollback interfaces of the target participant node corresponding to different service operation requests are the same.
10. The method of any of claims 1 to 5, wherein participant nodes in the distributed system comprise blockchain nodes.
11. A method for processing a distributed transaction, wherein the method is applied to a distributed system, the distributed system comprises a coordinator node and at least two participant nodes, and the coordinator node is connected with each participant node in a communication way; the method comprises the following steps:
when a snapshot generating instruction sent by the coordinator node is received, generating a corresponding snapshot according to the snapshot generating instruction, and sending the snapshot to the coordinator node, wherein the snapshot is a snapshot of service data corresponding to a service operation request in a target participant node, and the target participant node is determined according to an operation identifier of a service operation carried in the service operation request when the coordinator node acquires the service operation request sent by a requester device;
when a business operation instruction sent by the coordinator node is received, executing corresponding business operation according to the business operation instruction, and sending an execution result to the coordinator node;
when the snapshot sent by the coordinator node is received, restoring the corresponding service data to a state before the corresponding service operation is executed according to the snapshot, wherein the snapshot is sent when the coordinator node has an execution result of a target participant node in the received execution result, and the execution result is an execution failure;
the snapshot is sent by the coordinator node according to whether the service operation meets the atomicity characteristics and the execution result of the target participant node;
if the service operation meets the atomicity characteristic, when the participant node does not execute the service operation or the service operation is failed to execute, the rollback operation is not executed, and when the participant node executes the service operation successfully, the rollback operation is executed.
12. An apparatus for processing a distributed transaction, the apparatus being applied in a distributed system, the distributed system including a coordinator node and at least two participant nodes, the apparatus comprising:
the system comprises a receiving and sending module, a sending and receiving module and a sending and receiving module, wherein the receiving and sending module is used for obtaining a service operation request sent by requesting party equipment, and the service operation request carries an operation identifier of service operation;
a target node determining module, configured to determine, according to the operation identifier, at least two target participant nodes used for performing the service operation from all participant nodes;
the transceiver module is further configured to obtain and store a snapshot of each target participant node, where the snapshot is a snapshot of service data corresponding to the service operation request in the target participant node;
the target node calling module is used for calling each target participant node to respectively execute the sub-operation of the corresponding business operation and obtain the execution result of each target participant node;
the transceiver module is further configured to send the snapshot corresponding to each node to each target participant node if an execution result of one node in each target participant node is an execution failure, so that each target participant node restores the corresponding service data to a state before the corresponding sub-operation is executed according to the snapshot;
the snapshot is sent by the coordinator node according to whether the service operation meets the atomicity characteristics and the execution result of the target participant node;
if the service operation meets the atomicity characteristic, when the participant node does not execute the service operation or the service operation is failed to execute, the rollback operation is not executed, and when the participant node executes the service operation successfully, the rollback operation is executed.
13. A distributed transaction processing apparatus, wherein the apparatus is applied in a distributed system, the distributed system comprises a coordinator node and at least two participant nodes; the device comprises:
a snapshot generating module, configured to generate a corresponding snapshot according to a snapshot generating instruction sent by the coordinator node when the snapshot generating instruction is received, and send the snapshot to the coordinator node, where the snapshot is a snapshot of service data corresponding to a service operation request in a target participant node, and the target participant node is determined according to an operation identifier of a service operation carried in the service operation request when the coordinator node acquires the service operation request sent by a requester device;
the service operation execution module is used for executing corresponding service operation according to the service operation instruction and sending an execution result to the coordinator node when receiving the service operation instruction sent by the coordinator node;
a service operation recovery module, configured to, when receiving the snapshot sent by the coordinator node, recover the corresponding service data to a state before the corresponding service operation is executed according to the snapshot, where the snapshot is sent when an execution result of a target participant node in a received execution result of the coordinator node is an execution failure;
the snapshot is sent by the coordinator node according to whether the service operation meets the atomicity characteristics and the execution result of the target participant node;
if the service operation meets the atomicity characteristic, when the participant node does not execute the service operation or the service operation is failed to execute, the rollback operation is not executed, and when the participant node executes the service operation successfully, the rollback operation is executed.
14. An electronic device, comprising a memory and a processor;
the memory has stored therein a computer program;
the processor, when running the computer program, is configured to perform the method of any of claims 1-11.
15. A computer-readable storage medium, characterized in that the storage medium has stored thereon a computer program which, when being executed by a processor, carries out the method of any one of claims 1-11.
CN201910786076.4A 2019-08-23 2019-08-23 Distributed transaction processing method and device, electronic equipment and storage medium Active CN110502319B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910786076.4A CN110502319B (en) 2019-08-23 2019-08-23 Distributed transaction processing method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910786076.4A CN110502319B (en) 2019-08-23 2019-08-23 Distributed transaction processing method and device, electronic equipment and storage medium

Publications (2)

Publication Number Publication Date
CN110502319A CN110502319A (en) 2019-11-26
CN110502319B true CN110502319B (en) 2021-10-12

Family

ID=68589149

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910786076.4A Active CN110502319B (en) 2019-08-23 2019-08-23 Distributed transaction processing method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN110502319B (en)

Families Citing this family (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111143040A (en) * 2019-12-30 2020-05-12 北京三快在线科技有限公司 Transaction processing method, device, system and storage medium
CN111210350A (en) * 2020-01-03 2020-05-29 平安科技(深圳)有限公司 Block chain transaction method and device, computer equipment and storage medium
CN113495872A (en) * 2020-04-08 2021-10-12 北京万里开源软件有限公司 Transaction processing method and system in distributed database
CN111818305B (en) * 2020-07-09 2021-12-10 杭州海康威视数字技术股份有限公司 Distributed system, service control method and device
CN111984439A (en) * 2020-09-03 2020-11-24 深圳壹账通智能科技有限公司 Data processing method and device based on block chain and storage medium
CN112069258B (en) * 2020-09-08 2024-04-19 北京金山云网络技术有限公司 Transaction progress management method and device and distributed database
CN112907276A (en) * 2021-01-22 2021-06-04 北京达佳互联信息技术有限公司 Task processing method and device and storage medium

Family Cites Families (20)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US7730286B2 (en) * 2005-12-30 2010-06-01 Intel Corporation Software assisted nested hardware transactions
US8650155B2 (en) * 2008-02-26 2014-02-11 Oracle International Corporation Apparatus and method for log based replication of distributed transactions using globally acknowledged commits
US8752054B2 (en) * 2010-03-11 2014-06-10 Avaya Inc. Intelligent merging of transactions based on a variety of criteria
CN102103518B (en) * 2011-02-23 2013-11-13 运软网络科技(上海)有限公司 System for managing resources in virtual environment and implementation method thereof
CN103200147B (en) * 2012-01-04 2018-04-27 中兴通讯股份有限公司 The requesting method and device of third party's business
CN103345420B (en) * 2013-06-03 2017-12-22 百度在线网络技术(北京)有限公司 Batch calls the mthods, systems and devices of api interface
US20150120645A1 (en) * 2013-10-31 2015-04-30 Futurewei Technologies, Inc. System and Method for Creating a Distributed Transaction Manager Supporting Repeatable Read Isolation level in a MPP Database
CN106155832B (en) * 2015-03-30 2019-03-22 Tcl集团股份有限公司 A kind of method, apparatus and Android device that data are restored
CN106302611A (en) * 2015-06-09 2017-01-04 深圳市腾讯计算机系统有限公司 Service request distribution system, method and apparatus
CN106325978B (en) * 2015-06-19 2020-06-30 阿里巴巴集团控股有限公司 Distributed transaction processing method and device
CN105573828B (en) * 2015-12-17 2019-04-12 布比(北京)网络技术有限公司 A kind of operation processing method and device
CN106502769B (en) * 2016-09-30 2019-11-05 华为技术有限公司 Distributed transaction processing method, apparatus and system
CN106775959B (en) * 2016-12-06 2017-12-22 上海壹账通金融科技有限公司 distributed transaction processing method and system
CN106790501B (en) * 2016-12-15 2020-06-09 咪咕音乐有限公司 Service processing method and device based on interface skip
US10585873B2 (en) * 2017-05-08 2020-03-10 Sap Se Atomic processing of compound database transactions that modify a metadata entity
CN106998370A (en) * 2017-06-15 2017-08-01 北京微影时代科技有限公司 Access control method, device and system
CN109976881B (en) * 2017-12-28 2022-11-08 腾讯科技(深圳)有限公司 Transaction identification method and apparatus, storage medium, and electronic apparatus
CN108733457B (en) * 2018-04-12 2021-07-20 创新先进技术有限公司 Method and device for realizing distributed transaction
CN109542428B (en) * 2018-10-16 2024-06-11 北京神州数码云科信息技术有限公司 Service processing method, device, computer equipment and storage medium
CN109491767A (en) * 2018-11-13 2019-03-19 上海联寓智能科技有限公司 The processing method and distributed system of distributed transaction

Also Published As

Publication number Publication date
CN110502319A (en) 2019-11-26

Similar Documents

Publication Publication Date Title
CN110502319B (en) Distributed transaction processing method and device, electronic equipment and storage medium
CN109003078B (en) Intelligent contract calling method and device based on block chain and electronic equipment
US7904567B2 (en) Method, apparatus and computer program product for integrating heterogeneous systems
US20070143299A1 (en) Commitment of transactions in a distributed system
CN110163755B (en) Block chain-based data compression and query method and device and electronic equipment
CN103473318A (en) Distributed transaction security method for memory data grid
CN112817995B (en) Data processing method and device, electronic equipment and storage medium
CN117056116B (en) Flow management method and electronic equipment
CN113672350B (en) Application processing method and device and related equipment
CN111046110A (en) Method, node and computing device for node management of blockchain system
CN112685391B (en) Service data migration method and device, computer equipment and storage medium
CN112446786A (en) Abnormal transaction processing method and device, electronic equipment and readable storage medium
US6574750B1 (en) Preserving consistency of passively-replicated non-deterministic objects
KR20140047230A (en) Method for optimizing distributed transaction in distributed system and distributed system with optimized distributed transaction
CN112995262B (en) Distributed transaction submission method, system and computing equipment
CN112015595A (en) Master-slave database switching method, computing device and storage medium
CN111311360A (en) Resource return method and device, storage medium and electronic device
US7284018B1 (en) Logless transaction coordination
JPH10149286A (en) Method and device for executing efficient common object request broker architecture transaction
CN110717756B (en) Payment data processing device and method based on contract
CN116319241A (en) Transaction processing method, transaction processing device and electronic equipment
CN114217911A (en) Cross-chain transaction processing method, device, computing equipment and medium
CN113762939A (en) Asset management method and device based on block chain and electronic equipment
CN112950183A (en) Cross-link data interchange method, system, device and electronic equipment
CN111061576A (en) Method and system for creating entity object

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
REG Reference to a national code

Ref country code: HK

Ref legal event code: DE

Ref document number: 40016255

Country of ref document: HK

SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
GR01 Patent grant
GR01 Patent grant