WO2021169243A1 - Method, apparatus and system for processing distributed transaction - Google Patents

Method, apparatus and system for processing distributed transaction Download PDF

Info

Publication number
WO2021169243A1
WO2021169243A1 PCT/CN2020/114407 CN2020114407W WO2021169243A1 WO 2021169243 A1 WO2021169243 A1 WO 2021169243A1 CN 2020114407 W CN2020114407 W CN 2020114407W WO 2021169243 A1 WO2021169243 A1 WO 2021169243A1
Authority
WO
WIPO (PCT)
Prior art keywords
transaction
business
database
service
database operation
Prior art date
Application number
PCT/CN2020/114407
Other languages
French (fr)
Chinese (zh)
Inventor
姜宇
张伟
Original Assignee
华为技术有限公司
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 华为技术有限公司 filed Critical 华为技术有限公司
Publication of WO2021169243A1 publication Critical patent/WO2021169243A1/en

Links

Images

Classifications

    • 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/23Updating
    • G06F16/2379Updates performed during online database operations; commit processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/10File systems; File servers
    • G06F16/18File system types
    • 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/23Updating
    • 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/23Updating
    • G06F16/2308Concurrency control
    • G06F16/2336Pessimistic concurrency control approaches, e.g. locking or multiple versions without time stamps
    • G06F16/2343Locking methods, e.g. distributed locking or locking implementation details
    • 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/24Querying
    • G06F16/245Query processing
    • G06F16/2458Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
    • 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/24Querying
    • G06F16/245Query processing
    • G06F16/2458Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
    • G06F16/2471Distributed queries
    • 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/25Integrating or interfacing systems involving database management systems

Definitions

  • This application relates to the field of distributed technology, and in particular to a method, device and system for processing distributed transactions.
  • Transaction refers to a sequence of operations composed of one or more resource management operations.
  • Distributed transaction refers to a transaction involving multiple databases (DB) in an operation sequence. Since distributed transactions involve operations on multiple databases, it is necessary to ensure the consistency of operations on each database.
  • try-confirm-cancel (TCC) technology is usually used to process distributed transactions.
  • the business clients in the resource server (also called business server) that adopt the TCC technology are deployed with try and confirm. And cancel three interfaces.
  • the processing process of the TCC technology includes the following two stages: In the first stage (also called the try stage), the main business client that initiates the distributed transaction calls the try interfaces of the other slave business clients involved in the distributed transaction. To request the reservation of business resources from the business client.
  • the main business client determines that the business resources of each slave business client are successfully reserved, it can send a commit instruction to the transaction server, and the transaction server can then call The confirm interface of each slave business client instructs each slave business client to perform an operation on the reserved business resources, that is, to perform a submit operation. If the master business client determines that the reservation of the business resources of any slave business client fails, it can send a rollback instruction to the transaction server, and the transaction server can then call the cancel interface of each slave business client to instruct each slave business The client cancels the operation on the reserved business resources, that is, performs a rollback operation to release the reserved business resources.
  • This application provides a method, device, and system for processing distributed transactions, which can solve the technical problem of high development cost when implementing distributed transactions by business clients in related technologies.
  • a distributed transaction processing method is provided.
  • the method is applied to a distributed transaction processing system.
  • the distributed transaction processing system includes a plurality of business servers, a transaction server, and a business database, and each business server includes a network agent node. And a business client, and the method is executed by the network agent node; the method includes: obtaining one or more database operation instructions sent by the business client, each database operation instruction includes: a database operation statement and the context of a distributed transaction , Wherein the database operation instructions included in the one or more database operation instructions are used to implement the transaction branch of the distributed transaction, and the context of the distributed transaction includes the identification of the distributed transaction; each database is executed in the business database
  • the operation instruction includes a database operation statement, and a transaction branch creation request is sent to the transaction server, and the transaction branch creation request includes the identifier of the distributed transaction.
  • the database operation instruction sent by the business client carries the context of the distributed transaction, so that the network agent node can create and process transaction branches based on the database operation instruction. Since there is no need for the business client to create and process transaction branches, the impact on the original business logic of the business client is small, thereby effectively reducing the development cost of the business client applied to the distributed transaction processing system.
  • the method further includes: acquiring lock information of a data set that is targeted by a database operation statement included in the one or more database operation instructions, and the lock information of the data set is used in the business database Identify the data set; correspondingly, the transaction branch creation request also includes the lock information of the data set.
  • Carrying the lock information of the data set in the transaction branch creation request can facilitate whether the data set is locked by the transaction server, and then determine whether the transaction branch can be created.
  • the network agent node confirms that the automatic submission function of the service database is in the on state, and the network agent node may, after receiving the first creation response sent by the transaction server to indicate that the transaction branch is successfully created, then perform the service The database operation statement included in each database operation instruction is executed in the database.
  • the network agent node may also send a first commit instruction for the transaction branch of the distributed transaction to the service database in response to the first creation response, where the first commit instruction is used to instruct the service database to submit the transaction branch.
  • the network agent node After the network agent node determines that the transaction branch is created successfully, it executes the database operation statement, which can avoid the problem that the previously executed database operation statement is invalid if it determines that the transaction branch creation fails after executing the database operation statement. That is, in the scenario where the creation of the transaction branch fails, the database operation statement is no longer executed, which can avoid wasting the computing resources of the business server.
  • the network agent node may also receive a second creation response sent by the transaction server to indicate that the creation of the transaction branch fails; and, in response to the second creation response, send to the service database the transaction branch of the distributed transaction
  • the first rollback instruction is used to instruct the business database to roll back the transaction branch.
  • the network agent node confirms that the automatic submission function of the business database is in the off state, and may send the execution result of the database operation statement to the business client after each execution of a database operation statement in a database operation instruction;
  • the network agent node may obtain the lock information of the data set after obtaining the second commit instruction for the transaction branch of the distributed transaction sent by the business client; wherein, if the data set is used to implement the distributed transaction The number of database operation statements of the transaction branch is greater than 1, then the automatic submission function of the business database is set to the off state by the business client; the second commit instruction is the execution result sent by the business client according to the network agent node It is determined that the database operation statements included in each database operation instruction used to implement the transaction branch of the distributed transaction are sent after the execution is successful.
  • the network agent node Since the network agent node detects that the automatic submission function of the business database is in the off state, it can determine that the database operation instructions used to implement the transaction branch include multiple, so the network agent node can perform the second submission instruction after receiving the second submission instruction. Obtain the lock information of the data set, and then send a transaction branch creation request.
  • the network agent node sends the execution result of the database operation statement included in each database operation instruction to the business client, if it obtains the second transaction branch for the distributed transaction sent by the business client Rollback instruction, you can also delete the lock information of the data set, and send the second rollback instruction to the business database; wherein, the second rollback instruction is the task of the business client when determining to implement the transaction branch. Sent after the execution of a database operation sentence included in a database operation instruction fails.
  • the network agent node If the network agent node receives the second rollback instruction, it can determine that the transaction branch has failed to execute, and therefore can delete the lock information of the stored data set to avoid the lock information of the data set from occupying too much storage space.
  • the network agent node may obtain the first setting instruction sent by the business client, and may record the automatic submission function of the business database as the on state according to the first setting instruction.
  • the network agent node may obtain the second setting instruction sent by the business client, and may record the automatic submission function of the business database as closed according to the second setting instruction; wherein, the first setting instruction is the business client Sent when it is determined that the number of database operation statements used to implement the transaction branch is equal to 1; the second setting instruction is when the business client determines that the number of database operation statements used to implement the transaction branch is greater than 1 Sent when.
  • the network agent node records the status of the automatic submission function of the business database according to the acquired first setting instruction or the second setting instruction, which can ensure that when a transaction branch is created, the automatic submission of the business database can be accurately determined according to the recorded status Whether the function is turned on.
  • the first creation response may carry an identifier assigned by the transaction server to the transaction branch; the network agent node receives the first creation sent by the transaction server to indicate that the transaction branch of the distributed transaction is successfully created.
  • the identifier of the transaction branch and the corresponding relationship of the data set can also be stored in the transaction log of the distributed transaction; afterwards, the network proxy node can receive the third commit instruction for the transaction branch sent by the transaction server, And clean up the transaction branch identifier and the data set recorded in the transaction log; or, the network agent node may receive the third rollback instruction for the transaction branch sent by the transaction server, and then obtain the transaction branch from the transaction according to the transaction branch identifier. Obtain the data set from the log, and roll back the transaction branch according to the data set.
  • the third commit instruction is sent by the transaction server after receiving the commit instruction for the distributed transaction sent by the business client
  • the third rollback instruction is sent by the transaction server after the transaction server receives the commit instruction for the distributed transaction. Sent after the rollback instruction of the distributed transaction.
  • the network agent node after the network agent node sends the first commit instruction for the transaction branch of the distributed transaction to the service database, it can also delete the lock information of the data set; and, if the network agent node determines that the transaction branch is submitted successfully, Then, it can send a commit result indicating that the transaction branch of the distributed transaction is successfully submitted to the business client; if the network agent node determines that the transaction branch of the distributed transaction has failed, it can send an instruction to the business client If the transaction branch of the distributed transaction fails to submit the commit result, the fourth rollback instruction for the transaction branch of the distributed transaction is sent to the business database, and the transaction branch carrying the identifier of the distributed transaction is sent to the transaction server The notification message is used to instruct the transaction server to delete the lock information of the data set corresponding to the transaction branch of the distributed transaction.
  • the network agent node After the network agent node sends the first commit instruction for the transaction branch, it feeds back the commit result of the transaction branch to the business client, which can facilitate the business client to determine to commit or roll back the distributed transaction according to the commit result.
  • the network proxy node can intercept the data packet sent by the business client, and if it is detected that the recipient of the data packet sent by the business client is the business database, the network proxy node can obtain and parse the data packet; if it is detected that the receiver of the data packet sent by the service client is not the service database, the network proxy node may directly forward the data packet to the receiver.
  • the network proxy node since the network proxy node only needs to parse the data packets sent by the business client to the business database, and the business clients interact with the business database based on the database protocol, the network proxy node only needs to support the database protocol It can be adapted to business clients developed in different programming languages. That is, the solution provided in this application can be applied to a cross-programming language distributed transaction processing system.
  • the distributed transaction processing system includes multiple business servers, transaction servers, and business databases.
  • Each business server includes a network agent node and Business client, and the method may be executed by a first business client; the method may include: generating a transaction branch for realizing the distributed transaction according to the transaction branch to be executed by the first business client in the distributed transaction
  • One or more database operation statements one or more database operation instructions are generated according to the one or more database operation statements, each database operation instruction includes at least one database operation statement and the context of a distributed transaction, and the context of the distributed transaction Including the identification of the distributed transaction; sending the one or more database operation instructions to the first service database, where the first network agent node and the first service client are deployed on the same service server.
  • the network agent node that has obtained the database operation instruction can create and process the transaction branch based on the database operation statement and the context of the distributed transaction. Since there is no need for the business client to create and process transaction branches, the impact on the original business logic of the business client is small, thereby effectively reducing the development cost of the business client applied to the distributed transaction processing system.
  • the first business client may be the main business client that initiates the distributed transaction.
  • the first business client may also send the creation request of the distributed transaction to the transaction server in response to the service request. ; Receive the identifier of the distributed transaction sent by the transaction server; and send a service invocation request to the second business client participating in the distributed transaction, the service invocation request carries the identifier of the distributed transaction; and, the first A business client can determine the transaction branch to be executed by the first business client in the distributed transaction according to the business request.
  • the first business client as the main business client may also perform the following operations: receive the commit result of the transaction branch sent by the first network proxy node; and receive the second business client's response to the service invocation The service invocation response requested to be sent; then, according to the commit result and the service invocation response, a commit instruction or a rollback instruction for the distributed transaction is sent to the transaction server; wherein, the commit instruction for the distributed transaction is used to indicate Submit each transaction branch included in the distributed transaction, and a commit instruction for the distributed transaction is used to instruct to roll back each transaction branch included in the distributed transaction.
  • the first business client as the main business client only needs to send the creation request of the distributed transaction, generate the database operation instruction, and send the commit instruction or reply of the distributed transaction in the process of realizing the distributed transaction.
  • the above operations have little impact on the original business logic of the main business client, that is, the business of the main business client is less intrusive, so it can effectively reduce the adaptation of the main business client to the distributed transaction processing architecture to achieve business Cost of distributed transformation.
  • the first business client can also be a slave business client participating in a distributed transaction.
  • the first business client can also receive a service call sent by a second business client (ie, the main business client) Request, the service invocation request carries the context of the distributed transaction; according to the service invocation request, the transaction branch to be executed by the first business client in the distributed transaction is determined.
  • the first business client as the slave business client only needs to generate database operation instructions, which can effectively reduce the adaptation of the distributed transaction processing architecture from the business client to realize the distributed business.
  • the cost of retrofitting is the cost of retrofitting.
  • the method may further include: the first business client determines that the number of database operation statements used to implement the transaction branch of the distributed transaction is equal to 1, and sends to the first business database an instruction to automatically submit a function The first setting instruction set to the on state; or, the first business client determines that the number of database operation statements used to implement the transaction branch of the distributed transaction is greater than 1, and sends to the first business database an instruction to automatically Submit the second setting instruction in which the function is set to the off state.
  • the above-mentioned first setting instruction and second setting instruction can be intercepted by the first network agent node, and the first network agent node can accurately determine the state of the automatic submission function of the first service database based on the first setting instruction or the second setting instruction, That is, it can be accurately determined whether the number of database operation statements used to implement the transaction branch of the distributed transaction is greater than one.
  • the first service client may also receive each database operation sent by the first network proxy node The execution result of the database operation statement included in the instruction; if it is determined according to the execution result that the database operation statement included in each database operation instruction used to implement the transaction branch of the distributed transaction is executed successfully, the first business client can send the The first service database sends a second commit instruction for the transaction branch of the distributed transaction; if it is determined according to the execution result that any database operation instruction used to implement the transaction branch of the distributed transaction includes a database operation statement that fails to execute, then The first service client may send a second rollback instruction for the transaction branch of the distributed transaction to the first service database.
  • the aforementioned second commit instruction and second rollback instruction may be intercepted by the first network agent node, and the first network agent node may create a transaction branch based on the second commit instruction, or may roll back the transaction branch based on the second rollback instruction.
  • a network agent node which is applied to a distributed transaction processing system.
  • the distributed transaction processing system includes multiple business servers, transaction servers, and business databases.
  • Each business server includes a network agent node and a business client.
  • the network agent node includes:
  • the parsing module is used to obtain one or more database operation instructions sent by the business client.
  • Each database operation instruction includes: a database operation statement and the context of the distributed transaction, and the one or more database operation instructions include database operations
  • the statement is used to implement the transaction branch of the distributed transaction, and the context of the distributed transaction includes the identifier of the distributed transaction;
  • the transaction branch processing module is used to execute database operation statements included in each database operation instruction in the business database, and send a transaction branch creation request to the transaction server, and the transaction branch creation request includes the identifier of the distributed transaction.
  • the transaction branch processing module is further used to obtain lock information of a data set, the data set being targeted by a database operation statement included in the one or more database operation instructions, and the lock information of the data set used in The data set is identified in the business database; the transaction branch creation request also includes lock information of the data set.
  • the transaction branch processing module is configured to: confirm that the automatic submission function of the business database is in the on state; after receiving the first creation response sent by the transaction server indicating that the transaction branch is successfully created, in the The business database executes database operation statements included in each database operation instruction; the transaction branch processing module is further configured to: in response to the first creation response, send a first commit instruction for the transaction branch to the business database.
  • the transaction branch processing module is further configured to: receive a second creation response sent by the transaction server for indicating that the transaction branch creation fails; in response to the second creation response, send to the business database a response to the transaction The first rollback instruction of the branch.
  • the transaction branch processing module is further used to: confirm that the automatic submission function of the business database is in the off state; send the execution result of the database operation statement included in each database operation instruction to the business client; After the second commit instruction for the transaction branch sent by the business client, the lock information of the data set is acquired; where the second commit instruction is the business client determining the database included in each database operation instruction according to the execution result Sent after the operation statements are executed successfully.
  • the transaction branch processing module is further configured to: after sending the execution result of the database operation statement included in each database operation instruction to the business client, obtain the second transaction branch sent by the business client.
  • Rollback instruction delete the lock information of the data set; send the second rollback instruction to the business database; wherein, the second rollback instruction is executed by the business client in determining the database operation statement included in any database operation instruction Sent after failure.
  • the transaction branch processing module is further configured to: obtain the first setting instruction sent by the business client; according to the first setting instruction, record that the automatic submission function of the business database is turned on; wherein, the first setting The instruction is sent when the business client determines that the number of database operation statements used to implement the transaction branch is equal to 1.
  • the transaction branch processing module is further configured to: obtain a second setting instruction sent by the business client; according to the second setting instruction, record that the automatic submission function of the business database is off; wherein, the second setting The instruction is sent when the business client determines that the number of database operation statements used to implement the transaction branch is greater than one.
  • the first creation response carries an identifier assigned by the transaction server to the transaction branch; the transaction branch processing module is further configured to: upon receiving a message sent by the transaction server indicating that the transaction branch is successfully created After the first response is created, the identifier of the transaction branch and the corresponding relationship of the data set are stored in the transaction log of the distributed transaction; the third commit instruction for the transaction branch sent by the transaction server is received, and the transaction log is cleaned The recorded identifier of the transaction branch and the data set; wherein, the third commit instruction is sent by the transaction server after receiving the commit instruction for the distributed transaction sent by the business client.
  • the first creation response carries an identifier assigned by the transaction server to the transaction branch; the transaction branch processing module is further configured to: upon receiving a message sent by the transaction server indicating that the transaction branch is successfully created After the first response is created, the identifier of the transaction branch and the corresponding relationship of the data set are stored in the transaction log of the distributed transaction; the third rollback instruction for the transaction branch sent by the transaction server is received, according to the transaction branch The identifier of obtains the data set from the transaction log, and rolls back the transaction branch according to the data set; wherein, the third rollback instruction is that the transaction server receives the distributed transaction sent by the business client Sent after the rollback instruction.
  • a business client is provided, which is applied to a distributed transaction processing system.
  • the distributed transaction processing system includes a plurality of business servers, a transaction server, and a business database.
  • Each business server includes a network agent node and a business client.
  • the business client includes:
  • the processing module is used to generate one or more database operation statements for implementing the transaction branch according to the transaction branch to be executed by the business client in the distributed transaction;
  • the application program interface module is used to generate one or more database operation instructions according to the one or more database operation statements, and each database operation instruction includes: at least one database operation statement and the context of the distributed transaction, and the distributed transaction The context of includes the identity of the distributed transaction;
  • the database driver is used to send the one or more database operation instructions to the first network agent node, where the first network agent node and the service client are deployed on the same service server.
  • the application program interface module is further configured to: in response to a service request, send a creation request of the distributed transaction to the transaction server; receive an identifier of the distributed transaction sent by the transaction server;
  • the business client further includes: a service invocation module for sending a service invocation request to a second business client participating in the distributed transaction, and the service invocation request carries the identifier of the distributed transaction; the processing module also uses Based on the business request, determine the transaction branch to be executed by the business client in the distributed transaction.
  • the processing module is further configured to: receive the commit result of the transaction branch sent by the first network agent node; receive the service invocation response sent by the second business client in response to the service invocation request; and according to the commit Result and the service call response, send a commit instruction or rollback instruction for the distributed transaction to the transaction server; wherein, the commit instruction for the distributed transaction is used to instruct to submit each transaction branch included in the distributed transaction, and for The commit instruction of the distributed transaction is used to instruct to roll back each transaction branch included in the distributed transaction.
  • the processing module is further configured to: receive a service invocation request sent by a second business client, the service invocation request carries the context of the distributed transaction; according to the service invocation request, determine that the distributed transaction is The branch of the transaction to be executed by the business client.
  • the processing module is further configured to: determine that the number of database operation statements is equal to 1, and instruct the database driver to send a first setting instruction to the first business database, and the first setting instruction instructs to set the automatic submission function to Open state.
  • the processing module is further configured to: determine that the number of database operation statements is greater than 1, and instruct the database driver to send a second setting instruction to the first business database, and the second setting instruction instructs to set the automatic submission function to Disabled.
  • the processing module is further configured to: receive the execution result of the database operation statement included in each database operation instruction; determine according to the execution result that the database operation statement included in each database operation instruction is executed successfully, and instruct the database driver Send a second commit instruction for the transaction branch to the first service database.
  • the business client further includes: receiving the execution result of the database operation statement included in each database operation instruction; determining, according to the execution result, that the execution of the database operation statement included in any database operation instruction has failed, and instructing the database driver to The first service database sends a second rollback instruction for the transaction branch.
  • a network agent node in another aspect, includes a memory, a processor, and a computer program stored in the memory and running on the processor, and the processor implements the foregoing when the computer program is executed.
  • the distributed transaction processing method performed by the network agent node provided by the aspect.
  • a business client in another aspect, includes a memory, a processor, and a computer program stored in the memory and running on the processor, and the processor implements the foregoing when the computer program is executed.
  • the distributed transaction processing method performed by the first business client provided by the aspect.
  • a computer-readable storage medium stores instructions.
  • the instructions are executed by a processor, the distributed transaction executed by the network agent node as provided in the above aspect is realized. ⁇ Treatment methods.
  • a computer-readable storage medium stores instructions.
  • the instructions are executed by a processor, the distributed system executed by the first business client as provided in the above aspect is implemented. The processing method of the transaction.
  • a distributed transaction processing system includes: a transaction server, a plurality of business servers, and a plurality of business databases;
  • Each service server includes the network agent node provided in the above-mentioned aspect, and the service client provided in the above-mentioned aspect.
  • this application provides a method, device, and system for processing distributed transactions.
  • the solution provided in this application can be carried in the database operation instructions sent by the business client to the business database.
  • the network agent node can create and process transaction branches based on the distributed transaction context and the database operation statement. Since transaction branches can be created and processed through network proxy nodes, there is no need for the business client to deploy interfaces for creating and processing transaction branches (such as try, confirm, and cancel interfaces), thereby effectively reducing the application of business clients to distributed The development cost of the transaction processing system.
  • FIG. 1 is a schematic structural diagram of a distributed transaction processing system provided by an embodiment of the present application
  • FIG. 2 is a schematic structural diagram of another distributed transaction processing system provided by an embodiment of the present application.
  • FIG. 3 is a flowchart of a method for processing distributed transactions according to an embodiment of the present application
  • FIG. 4 is a flowchart of another distributed transaction processing method provided by an embodiment of the present application.
  • FIG. 5 is a flowchart of a method for a network proxy node to intercept data packets according to an embodiment of the present application
  • FIG. 6 is a schematic structural diagram of another distributed transaction processing system provided by an embodiment of the present application.
  • Fig. 7 is a schematic structural diagram of yet another distributed transaction processing system provided by an embodiment of the present application.
  • FIG. 1 is a schematic structural diagram of a distributed transaction processing system provided by an embodiment of the present application.
  • the system may include: multiple business servers 01, transaction servers 02, and multiple business databases 03.
  • each business database 03 corresponds to a business server 01
  • each business database 03 is used to store the business data of its corresponding business server 01.
  • each business database 03 is deployed in a database server.
  • the distributed transaction processing system may adopt a service mesh architecture to implement communication between business servers 01, so as to ensure that the services running in the business client 011 in each business server 01 can be Reliable call.
  • each service server 01 in the system may be deployed with a network agent node 012 in addition to a service client 011.
  • the network agent nodes 012 in each business server 01 can form a service grid, which can realize the communication between the business clients 011 in different business servers 01, the communication between the business clients 011 and the transaction server 02, and the business clients
  • the terminal 011 communicates with the service database 03.
  • each service server 01 may run one or more virtual machines, and the service client 011 and the network proxy node 012 may be deployed in the same virtual machine, or they may be deployed in different virtual machines.
  • each service server 01 may run one or more containers, and the service client 011 and the network agent node 012 may be deployed in the same container, or they may be deployed in different containers.
  • Each of the business server 01, the transaction server 02, and the database server on which the business database 03 is deployed can be a physical server, or a physical server cluster composed of several physical servers, or a cloud computing center.
  • any two of the multiple service servers 01, the transaction server 02, and the database server where the service database 03 is deployed may be independent physical servers. That is, the transaction server 02, each service client 011, and each service database 03 are physically isolated, thereby ensuring the operational performance of the transaction server 02, each service client 011, and each service database 03.
  • At least two of the multiple service servers 01, the transaction server 02, and the database server where the service database 03 is deployed may be deployed in the same physical server.
  • multiple service servers 01 can be deployed in the same physical server.
  • Each business server 01 in the distributed transaction processing system can participate in implementing the same distributed transaction (also called a global transaction), and each business server 01 can implement a transaction branch in the distributed transaction (for this For the business server 01, it can also be referred to as the local transaction of the business server 01).
  • the transaction server 02 is responsible for coordinating the processing of the entire distributed transaction. For example, it can handle the initiation of distributed transactions, the creation of transaction branches, the commit or rollback of distributed transactions, and the timeout check of distributed transactions.
  • FIG. 2 is a schematic structural diagram of another distributed transaction processing system provided by an embodiment of the present application.
  • the system may include a first service server 01a for implementing distributed transactions, and at least A second service server 01b. Only one second service server 01b is schematically shown in FIG. 2.
  • the first service server 01a may be a service server used to initiate the distributed transaction, and therefore may also be referred to as a main service server.
  • each second service server 01b can also be referred to as a slave service server.
  • the business data of the first business client 011a in the first business server 01a can be stored in the first business database 03a
  • the business data of the second business client 011b in the second business server 01b It can be stored in the second service database 03b.
  • each business server 01 can implement one transaction branch by performing one or more operations on the business data in its corresponding business database 03.
  • the transaction branch may be a transaction branch of a distributed transaction, or may not be a branch of a distributed transaction, that is, the transaction branch may not participate in a distributed transaction.
  • the business client 011 in the business server 01 needs to generate a database operation statement, and execute the database operation statement in the business database 03.
  • the business database 03 After the business database 03 receives the commit instruction sent by the business client 011, it will persistently update its business data based on the execution result of the database operation statement, that is, execute the commit operation.
  • a transaction branch contains only one operation for the business database 03
  • the business client 011 in the business server 01 only needs to generate and execute a database operation statement in order to implement the transaction branch, and the database operation statement can be executed.
  • Commit the transaction branch If a transaction branch contains multiple operations on the business database, the business client 011 in the business server 01 needs to generate and execute multiple database operation statements in order to implement the transaction branch, and the multiple database operation statements must be executed before they are completed. Commit the transaction branch.
  • the business client 011 in each business server 01 provided in the embodiment of the present application if it is determined that the number of database operation statements used to implement the transaction branch to be executed is equal to 1, the corresponding business database The auto-commit function of 03 is set to the on state, that is, the business database 03 can automatically commit the transaction branch. If the business client 011 determines that the number of database operation statements used to implement the transaction branch to be executed is greater than 1, then the automatic submission function of its corresponding business database 03 can be set to the off state, that is, the business database 03 needs to receive After the commit instruction sent by the business client 011, the transaction branch can be committed.
  • FIG. 3 is a flowchart of a distributed transaction processing method provided by an embodiment of the present application.
  • the method can be applied to the system shown in FIG. 1 or FIG. 2.
  • the method is applied to the system shown in FIG. 2 and the transaction branch to be executed by the first business client includes only one operation on the database as an example for description.
  • the method may include:
  • Step 101 The first business client sends a creation request of a distributed transaction to the transaction server.
  • the first service client After the first service client receives the service request, if it is determined that the service requested by the service request needs to be realized through the joint participation of the first service client and at least one second service client, it may respond to the service request and send The transaction server sends a request to create a distributed transaction.
  • the business request is a transfer request for transferring money from the first account of Bank A to the second account of Bank B. Since the transfer service requested by the transfer request requires the business client of Bank A and the business client of Bank B to participate in the implementation, the business client of Bank A can respond to the business request by sending distributed transaction information to the transaction server. Create a request.
  • Step 102 The transaction server sends the identification of the distributed transaction to the first service client.
  • the transaction server After the transaction server receives the creation request of the distributed transaction, it can assign an identification (identification, ID) to the distributed transaction, and send the identification of the distributed transaction to the first service client.
  • ID identification
  • an application programming interface (application programming interface, API) module 0111 may be deployed in the first service client 011a, and the API module 0111 includes a Begin Transaction (Begin Transaction) API.
  • the first service client 011a may send a distributed transaction creation request R1 to the transaction server 02 by calling the Begin Transaction API to obtain the ID of the distributed transaction, and then construct the context of the distributed transaction.
  • the input parameter of the Begin Transaction API may include the address of the transaction server 02, and the return value may include the ID of the distributed transaction. If the ID allocation fails due to factors such as the failure of the transaction server 02, the return value can be -1.
  • the address of the transaction server 02 is stored locally by the first business client 011a, and the address of the transaction server 02 may include the Internet protocol (IP) address and port number of the transaction server.
  • IP Internet protocol
  • the data type of the input parameter of the Begin Transaction API can be string, and the data type of the return value can be long.
  • the first service client 011a also includes a communication module 0112.
  • the creation request R1 of a distributed transaction sent by the API module 0111 can be sent to the first network agent node 012a through the communication module 0112, and then The first network agent node 012a transparently transmits to the transaction server 02.
  • the distributed transaction ID returned by the transaction server 02 can also be transparently transmitted by the first network agent node 012a to the communication module 0112 of the first service client 011a, and then transmitted by the communication module 0112 to the API module 0111.
  • Step 103 The first business client generates a database operation statement for implementing the transaction branch to be executed in the distributed transaction.
  • the first business client After the first business client receives the ID of the distributed transaction, it can determine the transaction branch to be executed by the first business client in the distributed transaction according to the business request, and generate the transaction branch to be executed in the distributed transaction.
  • the first business database corresponding to the first business client may be a relational database, and the database operation statement may be a structured query language (SQL) statement.
  • the first business client 011a further includes a processing module 0115, which can generate a database operation statement for implementing the transaction branch to be executed in the distributed transaction.
  • the business client of Bank A can determine that the branch of the transaction to be executed is: 1,000 yuan will be deducted from the balance of the account.
  • the business client of the bank A can generate a database operation statement for instructing to reduce the balance of the first account by 1000.
  • Step 104 The first service client sends a first setting instruction to the first service database.
  • the first business client can determine that the database operation statement is executed and can submit the transaction branch, and then can send the first setting to the first business database Instruction, the first setting instruction is used to instruct to set the automatic submission function of the first service database to an on state.
  • the first service client 011a further includes a database driver (DB driver) 0113.
  • the processing module 0115 can instruct the database driver 0113 to send the first setting instruction to the first service database 03 through the communication module 0112 when detecting that the number of database operation sentences is equal to 1.
  • Step 105 The first network agent node obtains the first setting instruction, and records that the automatic submission function of the first service database is turned on.
  • the first network proxy node can obtain the first setting instruction and record it according to the first setting instruction The automatic submission function of the first business database is turned on.
  • the first network agent node may forward the first setting instruction to the first service database after completing the status recording.
  • the first network agent node By recording the status of the automatic submission function of the first service database, the first network agent node can ensure that when a transaction branch is subsequently created, it can accurately determine whether the automatic submission function of the first service database is enabled according to the recorded status. Furthermore, the first network agent node can determine whether the number of database operation statements used to implement transaction branching is greater than 1 according to the state of the automatic submission function, and can obtain it in different ways according to the number of database operation statements. The lock information of the transaction branch, and the transaction branch is created.
  • the first network agent node may record the status identifier of the first service database, and the first network agent node may set the status identifier to true after obtaining the first setting instruction to indicate the first service
  • the automatic submission function of the database is turned on.
  • the first network agent node 012a may include a connection management module 0121, a parsing module 0122, and a transparent transmission module 0123.
  • the connection management module 0121 can intercept each data packet sent by the first service client 011a, and detect whether the recipient of each data packet is the first service database 03a. If the recipient of the data packet is the first service database 03a, the connection management module 0121 can send the data packet to the parsing module 0122, and the parsing module 0122 can parse the data packet. If the recipient of the data packet is not the first service database 03a, the connection management module 0121 can send the data packet to the transparent transmission module 0123, and the transparent transmission module 0123 can directly transparently transmit the data packet.
  • transparent transmission means that the data packet is directly transmitted to the destination address without analyzing the content of the data packet or making any changes to the content of the data packet.
  • the transparent transmission module 0123 of the first network agent node 012a can directly transparently transmit the creation request R1 of the distributed transaction to the transaction server 02.
  • Step 106 The first business client generates a database operation instruction based on the database operation statement and the context of the distributed transaction.
  • the first business client may combine the context of the distributed transaction with the database operation statement to generate a database operation instruction.
  • the context of the distributed transaction includes the identification of the distributed transaction.
  • the address of the transaction server may also be included, and the address of the transaction server is pre-stored in the first service client.
  • the first network agent node can create and process transaction branches based on the database operation instruction. Since there is no need for the first business client to create and process transaction branches, the impact on the original business logic of the first business client is small, thereby effectively reducing the development cost of the first business client applied to the distributed transaction processing system.
  • the first business client may add the context of the distributed transaction as a hint to the database operation statement according to the syntax format corresponding to the database type (DB type) of the first business database, thereby obtaining A database operation instruction.
  • the API module 0111 of the first business client 011a further includes an operation instruction creation API, and the first business client 011a can generate a database operation instruction L1 by calling the operation instruction creation API.
  • the input parameters of the operation instruction creation API may include: database operation statement, database type, and context of distributed transaction.
  • the data type of the database operation statement and the data type of the database type may both be string, and the context of the distributed transaction
  • the data type can be long.
  • the return value of the operation instruction creation API is the database operation instruction carrying the context of the distributed transaction. If the operation instruction creation API fails to execute, the return value is empty.
  • the data type of the return value can be string.
  • the first business client may also add a distributed transaction keyword to the database operation instruction, and the distributed transaction keyword can be used The context of distributed transaction is added to the instruction to indicate the database operation.
  • the identifier of the distributed transaction is ID1
  • the IP address of the transaction server is xxxx
  • the database operation statement used to indicate that the balance of the first account "yy" is reduced by 1000
  • the generated database operation instruction can be:
  • Step 107 The first service client sends the database operation instruction to the first service database.
  • the first business client After the first business client generates the database operation instruction, it can send the database operation instruction to the first business database.
  • the database driver 0113 in the first service client 011a may send the database operation instruction L1 generated by the API module 0111 to the first service database 03a. Since the first network agent node 012a can intercept the data packet sent by the first service client 011a, as shown in FIG. 2, the first network agent node 012a can obtain the database operation instruction L1 sent by the first service client 011a .
  • the database operation instruction L1 can be used for the first network agent node that has obtained the database operation instruction to create and process the transaction branch.
  • Step 108 The first business client sends a service invocation request to the second business client.
  • the service call request may carry the context of the distributed transaction.
  • the service call request may be a remote procedure call (remote procedure call, RPC) request.
  • the first business client 011a further includes a service invocation module 0114.
  • the service invocation module 0114 can send a service invocation request Q1 to the second business client 011b, and the service invocation request Q1 can be proxied through the first network agent.
  • the node 012a and the second network agent node 012b transparently transmit to the second service client 011b.
  • the first network agent node 012a can recognize that the recipient of the service call request Q1 is not the first service database 03a, so the first network agent node 012a can directly send the second The service client 011b forwards the data packet.
  • the business client of Bank A can send the business client of Bank B to the business customer of Bank B.
  • the terminal sends a service call request for instructing to increase the balance of the second account by 1000.
  • Step 109 The first network agent node obtains the database operation instruction, and obtains the data set targeted by the database operation statement from the first service database.
  • the first network agent node can obtain the database operation instruction and obtain the data set targeted by the database operation statement from the first service database.
  • the first network agent node can parse out the database operation statement from the database operation instruction, and then create and run the data set acquisition statement, so that the data set targeted by the database operation statement can be obtained from the first business database .
  • the first network agent node 012a further includes a transaction branch processing module 0124 and a database driver 0125.
  • the parsing module 0122 can parse out database operation statements (such as SQL statements) and the context of distributed transactions from the database operation instructions, and send the database operation statements and the context of distributed transactions to the transaction branch processing module 0124.
  • the transaction branch processing module 0124 can create a data set acquisition statement.
  • the data set acquisition statement created by the transaction branch processing module 0124 may be: Select for update.
  • the transaction branch processing module 0124 can run the data set acquisition statement: Select for update through the database driver 0125, so as to obtain the data set targeted by the database operation statement.
  • the first network agent node may also first detect whether the database operation instruction carries the context of distributed transactions. If the database operation instruction carries the context of the distributed transaction, the data set targeted by the database operation statement can be obtained and subsequent operations can be continued.
  • the first network agent node can determine that the database operation statement in the database operation instruction is not used to implement the transaction branch in the distributed transaction, so it can directly send to the first
  • the business database transparently transmits the database operation instructions without obtaining the data set and performing subsequent operations.
  • Step 110 The first network agent node obtains the lock information of the data set.
  • the first network agent node Since in step 105, the first network agent node has determined that the automatic submission function of the first service database is turned on according to the first setting instruction, it can be determined that the database operation statement in the database operation instruction can independently implement a transaction branch. . Furthermore, the first network agent node can obtain the lock information of the data set targeted by the database operation statement, and the lock information of the data set is the lock information of the transaction branch. For example, referring to FIG. 2, the transaction branch processing module 0124 in the first network agent node 012a can obtain the lock information of the data set targeted by the database operation statement.
  • the data set targeted by the database operation statement may refer to a collection of data operated by the database operation statement.
  • the lock information of the data set can be used to uniquely identify the data set targeted by the database operation statement in the first business database.
  • the lock information of the data set may include the table name of the data table where the data set is located, and the primary key of the row where the data set is located.
  • Step 111 The first network agent node sends a transaction branch creation request to the transaction server.
  • the first network agent node After the first network agent node obtains the lock information of the data set, that is, the lock information of the transaction branch, it can send a transaction branch creation request to the transaction server.
  • the transaction branch creation request may include the lock information of the data set and the identification of the distributed transaction.
  • the transaction branch processing module 0124 in the first network agent node 012a may send a transaction branch creation request S1 to the transaction server 02.
  • the automatic submission function for the first service database is turned on, and the transaction branch to be executed by the first service client participates in a distributed transaction scenario.
  • the first network agent node needs to execute database operation statements in the first business database, it also needs to perform operations such as obtaining data sets, obtaining lock information of the data sets, and requesting to create a transaction branch, and the above operations can be submitted only after successful execution Transaction branch. Therefore, before the first network agent node applies to the transaction server to create a transaction branch of a distributed transaction, it also needs to send a second setting instruction to the first service database.
  • the second setting instruction is used to instruct the first service database to
  • the automatic submission function is set to off.
  • the first service database will not automatically submit the transaction branch after the execution of the database operation statement is completed, but can be used in the first network agent node after the first network agent node determines that the transaction branch is successfully created.
  • the second setting instruction may be sent by the transaction branch processing module 0124 to the first service database 03a through the database driver 0125.
  • Step 112 The transaction server sends a creation response to the first network agent node.
  • the transaction server After receiving the transaction branch creation request, the transaction server can detect whether the transaction branch can be created based on the lock information of the data set.
  • the transaction server detects that the lock information of the data set in the creation request is different from the lock information of other transaction branches stored in it, it can determine that the data set targeted by the database operation statement used to implement the transaction branch is not locked. Therefore, it can be determined that the transaction branch can be created.
  • the transaction server may then assign an identifier to the transaction branch, and send a first creation response indicating that the transaction branch is successfully created to the first network agent node, and the first creation response carries the identifier of the transaction branch.
  • the transaction server may also store the lock information of the data set in the creation request, that is, lock the data set targeted by the database operation statement.
  • the transaction server detects that the lock information of the data set in the creation request is the same as the lock information of some other transaction branch stored in it, it can determine that the data set targeted by the database operation statement used to implement the transaction branch has been added Lock, so it can be determined that the transaction branch cannot be created.
  • the transaction server may further send to the first network agent node a second creation response indicating that the creation of the transaction branch fails.
  • Step 113 The first network agent node detects whether the transaction branch is successfully created.
  • the first network agent node After the first network agent node receives the creation response sent by the transaction server, it can detect whether the transaction branch is successfully created according to the creation response. If the creation response received by the first network proxy node is the second creation response used to indicate that the transaction branch creation failed, the first network proxy node can perform step 114; if the creation response received by the first network proxy node is If the second creation response is used to indicate that the transaction branch is successfully created, the first network agent node may execute step 115. For example, the transaction branch processing module 0124 in the first network agent node 011a may detect whether the transaction branch is successfully created according to the received creation response.
  • Step 114 The first network agent node sends a first rollback instruction for the transaction branch to the first service database.
  • the first network agent node receives the second creation response sent by the transaction server, it can be determined that the transaction branch has failed to be created, and then the first rollback instruction for the transaction branch can be sent to the first service database.
  • the first service database may perform a rollback operation in response to the first rollback instruction.
  • the first service database may respond to the first rollback instruction to restore its automatic submission function to the on state.
  • the transaction branch processing module 0124 in the first network agent node 011a may send the first rollback instruction for the transaction branch to the first service database 03a through the database driver 0125.
  • Step 115 The first network agent node executes the database operation statement in the first service data.
  • the first network agent node receives the first creation response sent by the transaction server, it can be determined that the transaction branch is successfully created, and the database operation statement can be executed in the first service data.
  • the transaction branch processing module 0124 in the first network agent node 012a can execute SQL statements in the first service data 03a through the database driver 0125.
  • Step 116 The first network agent node stores the identifier of the transaction branch and the corresponding relationship of the data set in the transaction log of the distributed transaction.
  • the first network agent node After the first network agent node executes and completes the database operation statement, it can also record the transaction branch identifier and the corresponding relationship of the data set targeted by the database operation statement in the transaction log of the distributed transaction, so that the subsequent need to roll back the database operation statement When a transaction is branched, a rollback operation can be performed based on the data set recorded in the transaction log.
  • the transaction log may be a log table created in the first business database for recording related data of distributed transactions.
  • the transaction branch processing module 0124 in the first network agent node 011a may correspondingly store the identifier of the transaction branch and the data set in the transaction log of the distributed transaction.
  • the above steps 115 and 116 can also be performed after step 109 and before step 111, that is, the first network agent node can also execute the database operation statement first, and then request the creation of a transaction branch.
  • the first business database when the first business database performs a rollback operation, it also needs to roll back its business data to the state before the database operation statement is executed. It can be seen that by executing the database operation statement after determining that the transaction branch is successfully created, it is possible to avoid the problem that the previously executed database operation statement is invalid if it is determined that the transaction branch creation fails after the database operation statement is executed. That is, in a scenario where the creation of a transaction branch fails, the database operation statement is no longer executed, which can avoid wasting the computing resources of the first business server.
  • Step 117 The first network agent node sends a first commit instruction for the transaction branch to the first service database.
  • the first network agent node After the first network agent node determines that the transaction branch is successfully created, and records the identifier of the transaction branch and the corresponding data set in the transaction log of the distributed transaction, the first network agent node can send the first commit instruction for the transaction branch to the first service database ,
  • the first commit instruction is used to instruct the first business database to commit the transaction branch.
  • the transaction branch processing module 0124 in the first network agent node 011a may send the first commit instruction for the transaction branch to the first service database 03a through the database driver 0125.
  • Step 118 The first network proxy node sends the commit result of the transaction branch to the first service client.
  • the first network agent node may also receive the commit response returned by the first service database. If the first service database normally completes the commit of the transaction branch, the commit response may indicate that the commit of the transaction branch is successful. Correspondingly, the first network agent node may send to the first service client a submission result indicating that the transaction branch is successfully submitted. If the first service database fails to commit the transaction branch due to factors such as failure, the commit response may indicate that the transaction branch fails to commit. Correspondingly, the first network agent node may send to the first service client a submission result indicating that the transaction branch fails to be submitted. For example, the transaction branch processing module 0124 in the first network agent node 011a may send the commit result of the transaction branch to the first service client 011a.
  • the first network proxy node may also delete its cached lock information.
  • the first network agent node may also send a fourth rollback instruction for the transaction branch to the first service database, and send a notification carrying the transaction branch identifier to the transaction server information.
  • the fourth rollback instruction may be used to instruct the first business database to perform a rollback operation
  • the notification message may be used to instruct the transaction server to delete the lock information of the transaction branch, that is, to instruct the transaction server to release the transaction branch for the transaction. Lock.
  • the first network agent node can complete the first phase of the distributed transaction after sending the completion of the first rollback instruction to the first service database or sending the commit result of the transaction branch to the first service client.
  • This first stage may also be referred to as the request stage or the voting stage. Because in the process of implementing the first phase of the distributed transaction operation, the creation and processing of transaction branches can be implemented by the network agent node, and the business client only needs to call the transaction start API and the operation instruction creation API. The call has little impact on the original business logic of the business client, so it can effectively reduce the cost of adapting the business client to the distributed transaction processing architecture.
  • Step 119 The second business client sends a service invocation response to the first business client.
  • the second business client may determine that the second business client is to be executed based on the service invocation request
  • the transaction branch can then be used to generate the database operation statement used to implement the transaction branch.
  • the second business client is the business client of Bank B
  • the service call request received by the business client of Bank B is used to indicate that the balance of the second account is increased by 1000
  • the balance of the B bank may generate a database operation statement used to instruct the balance of the second account to increase by 1000.
  • the API module 0111, the communication module 0112, the database driver 0113, the service invocation module 0114, and the processing module 0115 are also deployed in the second service client 011b.
  • the processing module 0115 of the second business client 011b can generate a database operation instruction L2 by calling the API module 0111, and send the database operation instruction L2 to the second business database 03b through the database driver 0113.
  • the connection management module 0121 in the second network agent node 012b can obtain the database operation instruction L2, and the analysis module 0122 can parse the database operation instruction L2.
  • the transaction branch processing module 0124 can send a transaction branch creation request S2 to the transaction server 01 based on the parsed database operation instruction L2 to create and process the transaction branch. After the transaction branch processing module 0124 of the second network agent node 012b completes the transaction branch, it can return the commit result of the transaction branch to the second service client 011b.
  • processing module 0115 of the second business client 011b may send a service invocation response indicating the success of the service invocation to the first business client 011a. If the processing module 0115 of the second business client 011b determines that the transaction branch has failed to be submitted according to the submission result, it may send a service invocation response indicating the failure of the service invocation to the first business client 011a.
  • the service invocation response can be transparently transmitted to the first service client 011a through the second network agent node 012b and the first network agent node 012a.
  • the second service client 011b can perform the methods shown in step 103, step 104, and step 106 to step 108, and the second network proxy node 012b can perform step 105 and step 109. Go to the method shown in step 118.
  • the operations performed by the second service client 011b and the second network proxy node 012b reference may be made to the relevant descriptions of the foregoing step 103 to step 118, which will not be repeated here.
  • the processing module 0115 of the second business client 011b receives the service invocation request sent by the first business client 011a, if it is determined that it can run its own service to implement the transaction branch to be executed, there is no need to Invoking the services of other business clients, that is, there is no need to perform the method shown in step 108 above. If the processing module 0115 of the second service client 011b determines that the service of the third service client in the third service server needs to be invoked, the service invocation module 0114 may be instructed to execute the method shown in step 108 above. Correspondingly, the third service client and the third network proxy node in the third service server also need to execute the methods shown in step 103 to step 118 above. That is, in addition to the first service server and the second service server, the third service server is also one of the participants of the distributed transaction.
  • the first business client may also send the service invocation request to the second business client after determining that its transaction branch is successfully submitted. That is, the above step 108 can also be executed after step 118.
  • the context of the distributed transaction carried in the service invocation request sent by the first business client to the second business client may further include: the identifier of the transaction branch executed by the first network proxy node. The identifier of the transaction branch may be sent to the first service client after the first network agent node receives the first creation response.
  • the transaction branch creation request sent by the second network agent node to the transaction server can carry the identifier of the distributed transaction and the identifier of the transaction branch executed by the first network agent node.
  • the transaction server After the transaction server receives the transaction branch creation request, it can determine that the first business client has invoked the service of the second business client. That is, the transaction server can clarify the service invocation status between various business clients based on the identifier of the transaction branch carried in the transaction branch creation request.
  • the first business client may also generate a database operation statement after determining that the service call of the second business client is successful. That is, the above step 108 and step 109 can also be executed before step 103. Alternatively, the above step 108 can also be performed synchronously with step 103, that is, the first service server and the second service server can process the transaction branch synchronously, thereby ensuring the processing efficiency of the distributed transaction.
  • the first business client sends a service call request after processing its transaction branch
  • the first business client determines that its transaction branch creation fails, or the transaction branch submission fails, it can be determined in advance that the distributed transaction execution failed . Therefore, the first business client does not need to send a service invocation request to the second business client, that is, the first business client may not need to perform step 108 again. In this way, it is possible to avoid wasting the computing resources of the second service server.
  • the distribution can also be determined in advance The execution of the typed transaction failed. Therefore, the first service client does not need to perform step 103, step 104, step 106, and step 107. Therefore, it is possible to avoid wasting the computing resources of the first service server.
  • Step 120 The first business client sends a commit instruction or a rollback instruction for the distributed transaction to the transaction server according to the commit result and the service invocation response.
  • the first business client After the first business client receives the commit result of the transaction branch sent by the first network proxy node and the service call response sent by the second business client, if it is determined that the transaction branch in the first business server is successfully submitted, and the first Second, if the service call of the business client is successful, it can be determined that each transaction branch used to implement the distributed transaction is submitted successfully, and therefore, a commit instruction for the distributed transaction can be sent to the transaction server.
  • the commit instruction is used to instruct to commit each transaction branch included in the distributed transaction.
  • the first business client determines that the transaction branch commit in the first business server fails, or the service call of the second business client fails, it can send a rollback instruction for the distributed transaction to the transaction server, the rollback instruction Used to instruct to roll back each transaction branch included in the distributed transaction.
  • the commit instruction or the rollback instruction for the distributed transaction both carry the context of the distributed transaction.
  • the first business client may call services of multiple second business clients.
  • the first service client can receive the service invocation response sent by the multiple second service clients.
  • the first business client needs to determine that the transaction branch in the first business server is submitted successfully and the services of each second business client are successfully invoked before it can determine that the transaction branches used to implement the distributed transaction are all The commit is successful, and a commit instruction for the distributed transaction is sent.
  • the first business client determines that the transaction branch submission in the first business server fails, or the service invocation of any second business client fails, it may send a rollback instruction for the distributed transaction.
  • the API module 0111 in the first business client 011a may also include a commit/rollback transaction API.
  • the processing module 0115 of the first business client 011a can send a commit instruction R2 for the distributed transaction to the transaction server 02 by calling the commit transaction (Commit Transaction) API, or can call the rollback transaction (Rollback Transaction) API , Send a rollback instruction R2 for the distributed transaction to the transaction server 02.
  • the commit or rollback instruction R2 for the distributed transaction can be transparently transmitted to the transaction server 02 by the transparent transmission module 0123 of the first network agent node 012a.
  • the input parameters of each API in the commit transaction API and the rollback transaction API may include the address of the transaction server and the identifier of the distributed transaction. And the return value of the commit transaction API is 0 to indicate that the commit is successful, and the return value of -1 can indicate that the commit failed. In the same way, the return value of the rollback transaction API is 0 to indicate that the rollback is successful, and the return value of -1 can indicate that the rollback failed.
  • the data type of the return value of each API in the commit transaction API and the rollback transaction API may be an integer (int).
  • the first business client can determine that the distributed transaction has failed to execute according to the received submission result or the received partial service call response, it can directly send a rollback for the distributed transaction to the transaction server Command without waiting for all submission results and service call responses to be received before sending the rollback command.
  • the processing efficiency of distributed transactions can be effectively improved.
  • Step 121 The transaction server sends a third commit instruction or a third rollback instruction for the transaction branch to the network agent node in each business server participating in the distributed transaction.
  • the transaction server After the transaction server receives the commit instruction or rollback instruction for the distributed transaction sent by the first business client, it may first determine the various business servers participating in the distributed transaction and the transaction branch executed by each business server. Furthermore, the third commit instruction or the third rollback instruction for the transaction branch executed by the business server may be sent to the network agent node in each business server respectively. Both the third commit instruction and the third rollback instruction may carry an identifier of the transaction branch executed by the business server.
  • the business servers participating in a distributed transaction include a first business server 01a and a second business server 01b, and the first business server 01a executes transaction branch 1 of the distributed transaction, and the second business server 01b Transaction branch 2 of the distributed transaction is executed.
  • the transaction server 02 receives the commit instruction for the distributed transaction sent by the first business client 011a, it can send the third commit instruction Z1 for the transaction branch 1 to the first network proxy node 012a, and can send The second network agent node 012b sends a third commit instruction Z2 for the transaction branch 2.
  • the second service server 01b also invokes the service client in the third service server to execute transaction branch 3
  • the transaction server 02 also needs to send the first transaction branch 3 to the network agent node 012b in the third service server.
  • Step 122 The first network agent node processes the received instruction.
  • the first network agent node If the first network agent node receives the third commit instruction for the transaction branch sent by the transaction server, it can clear the transaction log of the distributed transaction according to the transaction branch identifier carried in the third commit instruction The identifier of the transaction branch and the corresponding data set.
  • the first network agent node receives the third rollback instruction for the transaction branch sent by the transaction server, it can obtain it from the transaction log of the distributed transaction according to the transaction branch identifier carried in the third rollback instruction The corresponding data set. Then the first network agent node can create a data set rollback statement based on the data set, and execute the data set rollback statement in the first business database, thereby rolling back the transaction branch. That is, the first network agent node can restore the business data in the first business database to the state before executing the transaction branch by executing the data set rollback statement.
  • the data set rollback statement created by the first network agent node may also be an update statement. If the database operation statement used to implement the transaction branch is an insert statement, the data set rollback statement created by the first network agent node may be a delete statement. If the database operation statement used to implement the transaction branch is a delete statement, the data set rollback statement created by the first network agent node may be an insert statement.
  • the second network proxy node may also process the received instruction through the method shown in step 122 above. This will not be repeated here.
  • the transaction branch processing module 0124 in each network agent node may be used to process the received instructions.
  • Each network agent node can complete the second phase of the distributed transaction after processing the third commit instruction or third rollback instruction sent by the transaction server. This second phase may also be referred to as the commit phase or the execution phase.
  • the commit or rollback of the transaction branch can be implemented by the network proxy node, and the business client only needs to call the commit/rollback transaction API ,
  • the API call is less intrusive to the business, that is, it has less impact on the original business logic of the business client, so it can effectively reduce the adaptation of the business client to the distributed transaction processing architecture to achieve distributed transformation. cost.
  • the network agent node may no longer need to process the first step.
  • Three rollback instructions if a certain network agent node has already performed a rollback operation due to a transaction branch creation failure or a transaction branch commit failure before the above step 122, then in the above step 122, the network agent node may no longer need to process the first step. Three rollback instructions.
  • each network agent node may also send the commit result of the transaction branch to the transaction server after the above step 117, and the transaction server may then determine whether the transaction branch in each business server is executed successfully according to the commit result.
  • the transaction server may only send the third rollback instruction to the network agent node in the business server that has successfully executed the transaction branch, and does not need to send the third rollback instruction to the network agent node in the business server that has failed to execute the transaction branch. Send the third rollback instruction.
  • the embodiments of the present application provide a distributed transaction processing method.
  • the database operation instructions sent by the business client to the business database can carry the context of the distributed transaction.
  • the network agent node can create and process transaction branches based on the context of the distributed transaction and the database operation statement. Since transaction branches can be created and processed through network proxy nodes, there is no need for the business client to deploy interfaces for creating and processing transaction branches (such as try, confirm, and cancel interfaces), thereby effectively reducing the application of business clients to distributed The development cost of the transaction processing system.
  • the creation and processing of transaction branches can be realized by network proxy nodes, and the business client only needs to call to start the transaction.
  • API, operation instruction creation API, and submit/roll back transaction API The invocation of the above API is less intrusive to the business, that is, it has less impact on the original business logic of the business client, so it can effectively reduce the business client’s platform
  • the distributed transaction processing architecture is adapted to the platform as a service (platform as a service, PaaS) platform to realize the cost of the distributed transformation of the service and improve the efficiency of the distributed transformation of the business client.
  • the above-mentioned startup transaction API, operation instruction creation API, and commit/rollback transaction API can all be provided by the PaaS platform. Since the functions of the above-mentioned API are relatively simple, multiple programming languages can be supported. This can ensure that business clients developed and implemented in different programming languages can deploy the above APIs when performing distributed transformations, so that a distributed transaction processing system across programming languages can be realized at a lower development cost.
  • the network agent node can create and process transaction branches through database operation instructions that carry the context of distributed transactions. Therefore, even if each business client in the distributed transaction processing system is developed and implemented using different programming languages, it will not affect the creation and processing of transaction branches by the network agent node. That is, based on the solution provided by the embodiment of the present application, the network agent node only needs to support the database protocol to adapt to the business client developed using different programming languages. It can be seen from this that the solution of the embodiment of the present application can enable the distributed transaction processing system across programming languages to achieve data consistency of distributed transactions at a lower cost.
  • FIG. 4 is a flowchart of another distributed transaction processing method provided by an embodiment of the present application, and the method can be applied to the system shown in FIG. 1 or FIG. 2.
  • the method is applied to the system shown in FIG. 2 and the transaction branch to be executed by the first business client includes multiple operations on the database as an example for description.
  • the method may include:
  • Step 201 The first business client sends a creation request of a distributed transaction to the transaction server.
  • step 201 For the implementation process of step 201, reference may be made to the related description of step 101 in the embodiment shown in FIG. 3, which will not be repeated here.
  • Step 202 The transaction server sends an identifier assigned to the distributed transaction to the first service client.
  • step 202 For the implementation process of step 202, reference may be made to the related description of step 102 in the embodiment shown in FIG. 3, which will not be repeated here.
  • Step 203 The first business client generates multiple database operation statements for implementing transaction branches to be executed in the distributed transaction.
  • step 203 For the implementation process of step 203, reference may be made to the related description of step 103 in the embodiment shown in FIG. 3, which will not be repeated here.
  • Step 204 The first service client sends a second setting instruction to the first service database.
  • the first business client can determine that the multiple database operation statements are all executed before submitting the transaction branch, and then can send to the first business database
  • the second setting instruction is used to instruct to set the automatic submission function of the first business database to the closed state.
  • the processing module 0115 of the first service client 011a may instruct the database driver 0113 to send the second setting instruction to the first service database 03a when detecting that the number of database operation sentences is greater than one.
  • Step 205 The first network agent node obtains the second setting instruction, and records that the automatic submission function of the first service database is in a closed state.
  • the first network proxy node can obtain the second setting instruction and record it according to the second setting instruction
  • the automatic submission function of the first business database is closed.
  • the first network agent node may forward the second setting instruction to the first service database after completing the status recording.
  • the first network agent node records that the automatic submission function of the first business database is in the off state, and can determine that the number of database operation statements used to implement transaction branching is greater than one.
  • the first network agent node can determine which method should be used to obtain the lock information of the transaction branch, and create the transaction branch.
  • the first network agent node may record the status identifier of the first service database, and the first network agent node may set the status identifier to false after obtaining the second setting instruction to indicate the first service
  • the automatic submission function of the database is closed.
  • the transaction branch processing module 0124 in the first network agent node 012a may record the status identifier of the first service database.
  • Step 206 The first business client generates a plurality of database operation instructions based on the plurality of database operation statements and the context of the distributed transaction.
  • each database operation instruction includes at least one database operation statement and the context of the distributed transaction.
  • at least one refers to one or more, and multiple refers to two or more.
  • each database operation instruction may include a database operation statement.
  • Step 207 The first service client sends multiple database operation instructions to the first service database.
  • the first business client After the first business client generates the multiple database operation instructions, it can send the multiple database operation instructions to the first business database in sequence.
  • the database driver 0113 in the first network agent node 012a may send multiple database operation instructions to the first service database 03a.
  • Step 208 The first business client sends a service invocation request to the second business client.
  • step 208 For the implementation process of step 208, reference may be made to the related description of step 108 in the embodiment shown in FIG. 3, which will not be repeated here.
  • Step 209 The first network agent node obtains the multiple database operation instructions, and obtains the data set targeted by each database operation statement from the first service database.
  • the first network agent node can parse the database operation statement from the database operation instruction, and then obtain the data set targeted by the database operation statement from the first business database.
  • the process of obtaining the data set targeted by each database operation sentence reference may be made to the related description of step 109 in the embodiment shown in FIG. 3, which will not be repeated here.
  • Step 210 The first network agent node obtains lock information of the data set targeted by each database operation statement.
  • the lock information of the data set targeted by each database operation statement may include the table name of the data table where the data set is located, and the primary key of the row where the data set is located.
  • the transaction branch processing module 0124 in the first network agent node 012a can obtain the lock information of the data set targeted by each database operation statement.
  • Step 211 The first network agent node stores the data set targeted by each database operation statement and the lock information of the data set targeted by each database operation statement.
  • the first network agent node determines that the automatic submission function of the first service database is in the off state, it can determine that the number of database operation statements used to implement transaction branching is greater than one. Furthermore, the first network agent node can determine that only after the multiple database operation statements used to implement the transaction branch are executed successfully, can the transaction branch be created according to the acquired lock information request. Therefore, the first network agent node needs to store The data set targeted by each database operation statement and the lock information of the data set targeted by each database operation statement.
  • the first network agent node may use the identifier of the distributed transaction to implement the data set targeted by the multiple database operation statements of the transaction branch, and the lock information of the data set Perform corresponding storage. That is, the first network agent node can merge and store the data sets targeted by multiple database operation statements used to implement the same transaction branch, and can lock the data sets targeted by the multiple database operation statements. Information is merged and stored.
  • the transaction branch processing module 0124 in the first network agent node 012a may store the data set targeted by each database operation statement and the lock information of the data set targeted by each database operation statement.
  • the database operation statements generated by the first business client to implement the transaction branch to be executed include Y1, Y2, and Y3.
  • the three database operation statements are
  • the targeted data sets are D1, D2, and D3, and the lock information of the three data sets are S1, S2, and S3, respectively.
  • the first network agent node can store the identification ID1 of the distributed transaction, the corresponding relationship with the collection of data sets D1, D2, and D3, and the collection of lock information S1, S2, and S3.
  • Step 212 The first network agent node executes each database operation statement in the first service database.
  • the transaction branch processing module 0124 in the first network agent node 012a stores the data set targeted by each database operation statement and the lock information of the data set targeted by each database operation statement, it can use the database driver 0125 to access In the first service data 03a, the database operation statement in each database operation instruction is executed.
  • Step 213 The first network agent node sends the execution result of each database operation statement to the first service client.
  • the first network agent node can send the execution result of the database operation sentence to the first business client.
  • the execution result may be used to indicate the success or failure of the execution of the database operation statement.
  • the transaction branch processing module 0124 in the first network agent node 012a may send the execution result of each database operation statement to the first service client 011a.
  • Step 214 The first business client detects whether each database operation statement is executed successfully.
  • the first service client can detect whether each database operation statement used to implement the transaction branch is executed successfully according to the execution result sent by the first network agent node. If the execution of any database operation statement fails, the first business client can execute step 215; if each database operation statement is executed successfully, the first business client can execute step 218. For example, the processing module 0115 in the first business client 011a can detect whether each database operation statement is executed successfully.
  • Step 215 The first service client sends a second rollback instruction for the transaction branch to the first service database.
  • the first business client detects that any database operation statement has failed to execute, it can determine that the transaction branch has not been executed successfully, and therefore can send a second rollback instruction for the transaction branch to the first business database.
  • the processing module 0115 in the first business client 011a may instruct the database driver 0113 to send the second rollback instruction when it detects that any database operation statement fails to execute.
  • Step 216 The first network agent node deletes the stored data set and lock information.
  • the first network agent node obtains the second rollback instruction for the transaction branch sent by the first business client, it can determine that the transaction branch has failed to execute, so it can delete the stored database operation statement for each The data set, and the lock information of the data set targeted by each database operation statement, to avoid the data set and lock information occupying too much storage space.
  • the transaction branch processing module 0124 in the first network agent node 012a can delete the stored data set for each database operation statement and the lock information of the data set for each database operation statement.
  • Step 217 The first network proxy node sends the second rollback instruction to the first service database.
  • the first network proxy node may also forward the second rollback instruction to the first service database.
  • the transaction branch can be rolled back.
  • the transaction branch processing module 0124 in the first network agent node 012a may send the second rollback instruction to the first service database 03a through the database driver 0125.
  • Step 218 The first service client sends a second commit instruction for the transaction branch to the first service database.
  • the first business client detects that multiple database operation statements used to implement the transaction branch are executed successfully, it can determine that the transaction branch is executed successfully, and therefore can send a second commit instruction for the transaction branch to the first business database .
  • the processing module 0115 of the first business client 011a may instruct the database driver 0113 to send the second commit instruction when detecting that multiple database operation statements used to implement the transaction branch are executed successfully.
  • Step 219 The first network agent node obtains the lock information of the data set targeted by each stored database operation statement.
  • the first network agent node obtains the second commit instruction for the transaction branch sent by the first service client, it can obtain the lock information of the data set for each database operation statement stored in step 211.
  • the lock information of the data set targeted by the multiple database operation statements acquired by the first network agent node is the lock information of the transaction branch.
  • the transaction branch processing module 0124 in the first network agent node 012a may obtain the lock information of the data set for which each database operation statement is stored.
  • the first network agent node does not change the data in the first service database, for example, when the database operation statement is a query statement. Therefore, after the first network agent node obtains the second submission instruction, if it does not obtain the lock information of its pre-stored data set, that is, the first network agent node does not store any data set before receiving the second submission instruction If the lock information is displayed, the first network agent node can directly forward the second submission instruction without performing subsequent operations.
  • Step 220 The first network agent node sends a transaction branch creation request to the transaction server.
  • the first network agent node After obtaining the lock information of the transaction branch, the first network agent node can send a transaction branch creation request to the transaction server.
  • the transaction branch creation request may include the lock information of the data set and the identification of the distributed transaction.
  • the transaction branch processing module 0124 in the first network agent node 012a may send a transaction branch creation request to the transaction server 02.
  • the transaction server can detect whether the transaction branch can be created according to the lock information carried in the creation request.
  • the lock information of the transaction branch carried in the creation request includes the lock information of multiple data sets, so the transaction server can determine that the lock information of each data set is different from the lock information of other transaction branches stored in it. , Make sure that the transaction branch can be created. If the transaction server detects that the lock information of any data set is the same as the lock information of other transaction branches stored in it, it can determine that the transaction branch cannot be created.
  • step 220 the distributed transaction processing system can continue to execute the method shown in step 112 to step 122 in the embodiment shown in FIG. 3, so it will not be repeated here.
  • the embodiment of the present application provides a distributed transaction processing method.
  • the network agent node can accurately determine the status of the automatic submission function of the service database to implement the transaction. Whether the number of branched database operation statements is greater than 1.
  • the network agent node can obtain lock information and create transaction branches in different ways according to the number of database operation statements, thereby effectively improving the flexibility of creating transaction branches.
  • the network agent node in each service server can intercept the data packet sent by the service client in the service server, and can detect the data packet sent by the service client. Whether the receiver is a business database, and if the receiver of the data packet is a business database, the network proxy node can obtain the data packet and analyze the data packet. If the receiver of the data packet is not the service database, the network proxy node can directly forward the data packet.
  • the network agent node in each business server can also perform the following operations:
  • Step 301 Intercept the data packet sent by the service client.
  • Step 302 Detect whether the data packet is a new connection request.
  • the network proxy node For each data packet sent by the business client, the network proxy node can detect whether the data packet is a new connection request. If the data packet is a new connection request, the network proxy node can perform step 303; if the data packet is not a new connection request, the network proxy node can perform step 306.
  • Step 303 Create a new connection.
  • the network proxy node can establish a new connection with the connecting party requested by the new connection request. For example, the network proxy node can create a socket connection with the connecting party. After that, the network agent node may perform step 304.
  • Step 304 Detect whether the connection is a connection with a service database.
  • the network agent node can continue to detect whether the connection is a connection with the service database. If the connection is a connection with a service database, step 305 can be executed. If the connection is not a connection to the service database, then step 301 can be continued, that is, the data packet sent by the service client is continued to be intercepted. For example, if the connection is a connection with a transaction server, the network agent node may continue to perform step 301.
  • the network agent node may detect whether the connection is a connection with the service database according to the connection agreement between the service client and the connection party.
  • Step 305 Mark the connection.
  • the network agent node If the network agent node detects that the connection is a connection to the service database, it can mark the connection. For example, the network agent node can add a detection mark in the attribute description field of the connection, so as to mark the connection. By marking the connection to the service database, it is convenient to quickly detect whether the receiver of the data packet sent by the service client is the service database. After that, the network agent node can continue to perform step 301, that is, continue to intercept data packets sent by the service client.
  • Step 306 Detect whether the data packet belongs to the marked connection.
  • the network agent node if it detects that the data packet is not a new connection request, it can continue to detect whether the data packet belongs to a marked connection, that is, continue to detect whether the data packet is sent to the service database data pack. For example, the network agent node can detect whether a detection mark is added in the attribute description field of the connection to which the data packet belongs. If the detection mark is added, it can be determined that the data packet belongs to the marked connection; if the detection mark is not added, it can be determined that the data packet does not belong to the marked connection.
  • the network proxy node can determine that the data packet is a data packet sent to the service database, so step 307 can be performed; if the data packet does not belong to a marked connection, the network proxy node can determine the The data packet is not a data packet sent to the service database, so step 308 can be executed.
  • each network agent node may include a connection management module 0121, and the above steps 301 to 306 may be implemented by the connection management module 0121.
  • Step 307 Obtain and parse the data packet.
  • each network agent node may include a parsing module 0122, and the parsing module 0122 may parse the data packet.
  • the network proxy node may first detect whether the data packet is a setting instruction for setting the automatic submission status of the business database. If the data packet is the setting instruction, the network proxy node may execute the above step 105 or step 205. Indicates the method. If the data packet is not the setting instruction, the network agent node can continue to detect whether the data packet is a commit instruction or a rollback instruction for a transaction branch.
  • the network proxy node can execute the methods shown in steps 218 and 219; if the data packet is a rollback instruction for a transaction branch, the network proxy node can perform the above steps 216 shows the method. If the data packet is not a commit instruction or a rollback instruction for a transaction branch, the network agent node can continue to detect whether the data packet is a database operation instruction carrying the context of a distributed transaction.
  • the network agent node can directly forward the data packet to the service database; if the data packet is a database operation instruction carrying the context of the distributed transaction, the network agent node can Perform the method shown in step 109 or step 209 above.
  • the network proxy node since the network proxy node only needs to parse the data packets sent by the business client to the business database, and the business clients all interact with the business database based on the database protocol, the network proxy node only needs to support the database protocol It can be adapted to business clients developed in different programming languages. That is, the solutions provided by the embodiments of the present application can be applied to a distributed transaction processing system across programming languages.
  • Step 308 Transparently transmit the data packet.
  • each network agent node may include a transparent transmission module 0123, and the transparent transmission module 0123 may transparently transmit the data packet.
  • the network agent node can mark the connection when establishing a new connection with the service database, it can facilitate the subsequent rapid detection of the data sent by the service client Whether the receiver of the packet is the service database, thereby effectively improving the efficiency of detecting the receiver of the data packet.
  • the network proxy node since the network proxy node can realize the creation and processing of transaction branches according to the data packets sent by the business client to the business database, the network proxy node only needs to parse the data packets sent by the business client to the business database. Data packets to other receivers can be directly transmitted transparently. This can avoid increasing the number of data packets parsed by the network proxy node, and improve the efficiency of the network proxy node in parsing data packets.
  • step 106 can be performed before step 105
  • step 206 can be performed before step 205
  • step 108 can be performed before step 107
  • step 208 can be performed before step 207.
  • step 115 and step 116 can be performed before step 111.
  • step 119 may also be performed before step 118.
  • step 108 may be performed after step 109, and step 208 may also be performed after step 209.
  • step 108 may be performed after step 118, and step 208 may be performed after step 218. Any person familiar with the technical field can easily think of a method of change within the technical scope disclosed in this application, which should be covered by the protection scope of this application, and therefore will not be repeated.
  • the embodiments of the present application provide a distributed transaction processing method.
  • the database operation instructions sent by the business client to the business database can carry the context of the distributed transaction.
  • the network agent node can create and process transaction branches based on the context of the distributed transaction and the database operation statement. Since transaction branches can be created and processed through network proxy nodes, there is no need for the business client to deploy interfaces for creating and processing transaction branches (such as try, confirm, and cancel interfaces), thereby effectively reducing the application of business clients to distributed The development cost of the transaction processing system.
  • the creation and processing of transaction branches can be realized by network proxy nodes, and the business client only needs to call to start the transaction.
  • API, operation instruction creation API, and submit/roll back transaction API The invocation of the above API is less intrusive to the business, that is, it has less impact on the original business logic of the business client, so it can effectively reduce the business client’s platform
  • the distributed transaction processing architecture is adapted to the PaaS platform as a service to realize the cost of the distributed transformation of the business and improve the efficiency of the distributed transformation of the business client.
  • the above-mentioned startup transaction API, operation instruction creation API, and commit/rollback transaction API can all be provided by the PaaS platform. Since the functions of the above-mentioned API are relatively simple, multiple programming languages can be supported. This can ensure that business clients developed and implemented in different programming languages can deploy the above APIs when performing distributed transformations, so that a distributed transaction processing system across programming languages can be realized at a lower development cost.
  • the network agent node can create and process transaction branches through database operation instructions that carry the context of distributed transactions. Therefore, even if each business client in the distributed transaction processing system is developed and implemented using different programming languages, it will not affect the creation and processing of transaction branches by the network agent node. That is, based on the solution provided by the embodiment of the present application, the network agent node only needs to support the database protocol to adapt to the business client developed using different programming languages. It can be seen from this that the solution of the embodiment of the present application can enable the distributed transaction processing system across programming languages to achieve data consistency of distributed transactions at a lower cost.
  • the embodiment of the present application provides a network agent node, which can be deployed in a business server of a distributed transaction processing system, for example, can be deployed in a business server of a distributed transaction processing system as shown in FIG. 1 or FIG. 2 01 in.
  • the distributed transaction processing system further includes a transaction server 02 and a plurality of service databases 03, and a service client 011 is also deployed in the service server 01.
  • the network agent node includes: a connection management module 0121, a parsing module 0122, a transparent transmission module 0123, a transaction branch processing module 0124, and a database driver 0125.
  • connection management module 0121 is configured to receive one or more database operation instructions sent by the business client, and send the one or more database operation instructions to the analysis module 0122.
  • the parsing module 0122 is used to obtain and analyze each database operation instruction sent by the business client.
  • Each database operation instruction includes: a database operation statement and a distributed transaction context, wherein the one or more database operation instructions
  • the included database operation statement is used to implement the transaction branch of the distributed transaction, and the context of the distributed transaction includes the identifier of the distributed transaction.
  • the parsing module 0122 is also used to send the parsed database operation statement and the context of the distributed transaction to the transaction branch processing module 0124.
  • the transaction branch processing module 0124 is configured to: execute the database operation statement in the business database; and send a transaction branch creation request to the transaction server, and the transaction branch creation request includes the identifier of the distributed transaction.
  • the transaction branch processing module 0124 For the functional realization of the transaction branch processing module 0124, reference may be made to the related description of step 111 and step 220 in the foregoing method embodiment.
  • the transaction branch processing module 0124 is also used to: obtain lock information of a data set, the data set being targeted by a database operation statement included in the one or more database operation instructions, and the lock information of the data set
  • the data set is identified in the business database; correspondingly, the transaction branch creation request also includes the lock information of the data set.
  • the transaction branch processing module 0124 may be used to: determine that the automatic submission function of the business database is in an on state, and after receiving the first creation response sent by the transaction server indicating that the transaction branch is successfully created, The database operation statements included in each database operation instruction are executed in the business database.
  • the transaction branch processing module 0124 reference may also be made to the related description of step 115 in the foregoing method embodiment.
  • the transaction branch processing module 0124 may be further configured to: after receiving the first creation response sent by the transaction server indicating that the transaction branch is successfully created, send the first commit instruction for the transaction branch to the business database.
  • the transaction branch processing module 0124 may be further configured to: after receiving a second creation response sent by the transaction server indicating that the transaction branch creation fails, send to the business database the first creation response for the transaction branch. A rollback instruction.
  • the transaction branch processing module 0124 reference may also be made to the related descriptions of step 112 to step 114 and step 117 in the foregoing method embodiment.
  • the transaction branch processing module 0124 can also be used to determine that the automatic submission function of the business database is turned off, and send the execution result of the database operation statement included in each database operation instruction to the business client; After the second commit instruction for the transaction branch sent by the business client, the lock information of the data set is acquired.
  • the automatic submission function of the business database is set to the closed state by the business client; the second submission instruction is that the business client is The execution result is determined to be sent after each database operation statement used to implement the transaction branch is successfully executed.
  • the transaction branch processing module 0124 reference may also be made to the related descriptions of step 210 to step 213 and step 219 in the foregoing method embodiment.
  • the transaction branch processing module 0124 can also be used to obtain the transaction branch sent by the business client after the execution result of the database operation statement included in each database operation instruction is sent to the business client.
  • the second rollback instruction is to delete the lock information of the data set, and send the second rollback instruction to the business database; wherein, the second rollback instruction is that the business client determines any one of the transaction branches used to implement the transaction branch. Sent after the execution of the database operation statement fails.
  • both the second commit instruction and the second rollback instruction may be sent to the transaction branch processing module 0124 through the connection management module 0121 and the parsing module 0122.
  • the transaction branch processing module 0124 may be used to: obtain the first setting instruction sent by the business client, and record the automatic submission function of the business database as the on state according to the first setting instruction; wherein, the first setting The instruction is sent when the business client determines that the number of database operation statements used to implement the transaction branch is equal to 1.
  • the transaction branch processing module 0124 may be used to: obtain a second setting instruction sent by the business client, and record according to the second setting instruction that the automatic submission function of the business database is turned off; the second setting instruction is Sent when the business client determines that the number of database operation statements used to implement the transaction branch is greater than 1.
  • the transaction branch processing module 0124 reference may also be made to the related descriptions of step 105 and step 205 in the foregoing method embodiment.
  • the first creation response carries an identifier assigned by the transaction server to the transaction branch; the transaction branch processing module 0124 can also be used to:
  • the third commit instruction is sent by the transaction server after receiving the commit instruction for the distributed transaction sent by the business client
  • the third rollback instruction is sent by the transaction server after receiving the business client. Sent after the rollback instruction for the distributed transaction.
  • transaction branch processing module 0124 can also be used to:
  • the lock information of the data set is deleted. If it is determined that the transaction branch is submitted successfully, then send to the business client a commit result indicating that the transaction branch is submitted successfully; if it is determined that the transaction branch has failed to commit, then send to the business client to indicate that the transaction branch failed to commit Send the fourth rollback instruction for the transaction branch to the business database, and send a notification message carrying the transaction branch identifier to the transaction server, and the notification message is used to instruct the transaction server to delete the transaction branch Lock information.
  • the transaction branch processing module 0124 reference may also be made to the related description of step 118 in the foregoing method embodiment.
  • connection management module 0121 can be used to: if it is detected that the recipient of the data packet sent by the service client is the service database, send the data packet to the parsing module 0122; if the service client is detected If the recipient of the sent data packet is not the service database, the data packet is sent to the transparent transmission module 0123.
  • the connection management module 0121 For the function implementation of the connection management module 0121, reference may be made to the related descriptions of step 301 to step 306 in the foregoing method embodiment.
  • the parsing module 0122 is used for parsing the data packet.
  • the parsing module 0122 reference may be made to the related description of step 307 in the foregoing method embodiment.
  • the transparent transmission module 0123 is configured to forward the data packet to the receiver, that is, transparently transmit the data packet.
  • the transparent transmission module 0123 For the function implementation of the transparent transmission module 0123, reference may be made to the related description of step 308 in the foregoing method embodiment.
  • the embodiments of the present application provide a network agent node, which can create and process transaction branches according to the context of distributed transactions and database operation statements carried in database operation instructions. Since network agent nodes can create and process transaction branches, there is no need for business clients to deploy interfaces for creating and processing transaction branches (such as try, confirm, and cancel interfaces), thereby effectively reducing the application of business clients to distributed transaction processing systems Development costs.
  • the embodiment of the present application provides a business client, which can be deployed in a business server of a distributed transaction processing system, for example, can be deployed in a business server of a distributed transaction processing system as shown in FIG. 1 or FIG. 2 01.
  • the distributed transaction processing system further includes a transaction server 02 and a plurality of service databases 03, and a network agent node is also deployed in the service server 01.
  • the business client may include: an API module 0111, a communication module 0112, a database driver 0113, a service calling module 0114, and a processing module 0115.
  • the service client is the first service client 011a in the first service server 01a, and the first service server 01a further includes the first network proxy node 012a as an example.
  • the processing module 0115 is configured to generate one or more database operation statements for implementing the transaction branch according to the transaction branch to be executed by the first business client in the distributed transaction.
  • the processing module 0115 For the functional realization of the processing module 0115, reference may be made to the related descriptions of step 103 and step 203 in the foregoing method embodiment.
  • the API module 0111 is used to generate one or more database operation instructions based on the one or more database operation statements and the context of the distributed transaction, wherein each database operation instruction includes: at least one database operation statement and the distributed transaction
  • the context which includes the identity of the distributed transaction.
  • the database driver 0113 is configured to send the one or more database operation instructions to the first service database, and the one or more database operation instructions are used for the first network agent node that obtains the one or more database operation instructions Create and process the transaction branch.
  • the database driver 0113 For the function implementation of the database driver 0113, reference may be made to the related descriptions of step 107 and step 207 in the foregoing method embodiment.
  • the API module 0111 is further configured to send the creation request of the distributed transaction to the transaction server in response to the service request; and receive the identifier of the distributed transaction sent by the transaction server.
  • the API module 0111 For the functional realization of the API module 0111, reference may also be made to the related descriptions of step 101, step 102, step 201, and step 202 in the foregoing method embodiment.
  • the service invocation module 0114 is configured to send a service invocation request to a second business client participating in the distributed transaction, and the service invocation request carries an identifier of the distributed transaction.
  • the service calling module 0114 For the function implementation of the service calling module 0114, reference may be made to the related descriptions of step 108 and step 208 in the foregoing method embodiment.
  • processing module 0115 is further configured to determine the transaction branch to be executed by the first business client in the distributed transaction according to the business request.
  • the processing module 0115 is further configured to receive the commit result of the transaction branch sent by the first network proxy node, and receive the service invocation response sent by the second business client in response to the service invocation request.
  • the processing module 0115 can also be used to instruct the API module 0111 to send a commit instruction or a rollback instruction for the distributed transaction to the transaction server according to the commit result and the service call response.
  • the commit instruction is used to instruct to submit each transaction branch included in the distributed transaction
  • the commit instruction for the distributed transaction is used to instruct to roll back each transaction branch included in the distributed transaction.
  • the processing module 0115 can also be used to: receive a service invocation request sent by a second business client, the service invocation request carries the context of the distributed transaction; according to the service invocation request, determine the distributed transaction The transaction branch to be executed by the first business client in the transaction.
  • processing module 0115 can also be used to:
  • the database driver 0113 is instructed to send a first setting instruction to the first business database, and the first setting instruction is used to instruct to set the automatic commit function to the on state of.
  • the processing module 0115 For the functional realization of the processing module 0115, reference may also be made to the related descriptions of step 104 and step 204 in the foregoing method embodiment.
  • processing module 0115 can also be used to:
  • each database operation statement used to implement the transaction branch is executed successfully, and the database driver 0113 is instructed to send a second commit instruction for the transaction branch to the first service database.
  • each request or instruction sent by the API module 0111 and the database driver 0113 in the business client is sent through the communication module 0112.
  • the embodiments of the present application provide a business client.
  • the database operation instructions sent by the business client to the business database can carry the context of the distributed transaction, so that the network proxy node can be based on the distributed transaction. Context, and the database operation statement to create and process transaction branches. Since transaction branches can be created and processed through network proxy nodes, there is no need for the business client to deploy interfaces for creating and processing transaction branches (such as try, confirm, and cancel interfaces), thereby effectively reducing the application of business clients to distributed The development cost of the transaction processing system.
  • the network proxy node and service client provided in the embodiments of the present application can also be implemented by an application-specific integrated circuit (ASIC) or a programmable logic device (PLD).
  • the PLD can be a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL) or any combination thereof.
  • the distributed transaction processing method provided by the foregoing method embodiment can also be implemented by software.
  • the distributed transaction processing method provided by the foregoing method embodiment is implemented by software, the various modules in the network proxy node and the business client can also be implemented. It is a software module.
  • the distributed transaction processing system may be a server cluster.
  • the server cluster includes at least one server 1000, and each server 1000 Establish a communication path through the communication network.
  • Each server 1000 includes a bus 1001, a processor 1002, a communication interface 1003, and a memory 1004.
  • the processor 1002, the memory 1004, and the communication interface 1003 communicate with each other through the bus 1001.
  • the processor 1002 may be composed of one or more general-purpose processors, such as a central processing unit (CPU), or a combination of a CPU and a hardware chip.
  • the above-mentioned hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof.
  • the above-mentioned PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a general array logic (generic array logic, GAL), or any combination thereof.
  • the memory 1004 may include a volatile memory (volatile memory), such as random access memory (RAM).
  • volatile memory such as random access memory (RAM).
  • the memory 1004 may also include non-volatile memory (NVM), such as read-only memory (read-only memory, ROM), flash memory, hard disk drive (HDD), or solid-state drive (solid-disk drive, HDD). state drive, SSD).
  • NVM non-volatile memory
  • ROM read-only memory
  • HDD hard disk drive
  • SSD solid-state drive
  • the memory 1004 may also include a combination of the above types.
  • the memory 1004 stores executable codes, and the processor 1002 can read the executable codes in the memory 1004 to implement functions, and can also communicate with other servers through the communication interface 1003.
  • the processor 1002 in each server 1000 can implement one or more of the following functions: the function of at least one service client 011, the function of at least one network agent node 012, and the transaction server 02 The functions of at least one business database 03. That is, the processor 1002 in each server 1000 may only implement the functions of one node in the business client 011, the network agent node 012, the transaction server 02, and the business database 03, or may also implement the functions of multiple nodes. .
  • the memory 1004 stores modules for realizing the functions of the processor 1002.
  • the processors 1001 in the multiple servers 1000 may coordinate work to execute the distributed transaction processing method provided in the embodiment of the present application.
  • the distributed transaction processing system may include multiple service servers 2000, one transaction server 3000, and multiple database servers 4000. Only two service servers 2000 and two database servers 4000 are schematically shown in FIG. 7.
  • each service server 2000 includes a bus 2001, a processor 2002, a communication interface 2003, and a memory 2004.
  • the processor 2002, the memory 2004 and the communication interface 2003 communicate through a bus 2001.
  • the transaction server 3000 includes a bus 3001, a processor 3002, a communication interface 3003, and a memory 3004.
  • the processor 3002, the memory 3004, and the communication interface 3003 communicate with each other through the bus 3001.
  • Each database service server 4000 includes a bus 4001, a processor 4002, a communication interface 4003, and a memory 4004.
  • the processor 4002, the memory 4004, and the communication interface 4003 communicate with each other through the bus 4001.
  • the types of the processor 2002, the processor 3002, and the processor 4002 reference may be made to the relevant description of the processor 1002, which will not be repeated here.
  • the types of the memory 2004, the memory 3004, and the memory 4004, please refer to the relevant description of the memory 1004, which will not be repeated here.
  • the processor 2002 in each service server 2000 can realize the function of a service client 011 and the function of a network agent node 012 by running a computer program in the memory 2004.
  • the memory 2004 in each service server 2000 stores various modules of the service client 011 (for example, the API module 0111, the communication module 0112, the database driver 0113, and the service calling module 0114), and the network
  • the various modules of the proxy node 012 for example, the connection management module 0121, the analysis module 0122, the transparent transmission module 0123, the transaction branch processing module 0124, and the database driver 0125).
  • the processor 3002 in the transaction server 3000 can implement the functions of the transaction server 02 in the foregoing embodiment by running a computer program in the memory 3004.
  • the processor 4002 in each database server 4000 can implement the function of the service database 03 in the foregoing embodiment by running the computer program in the memory 4004.
  • each service server in the system includes a service client and a network agent node.
  • the network agent node can intercept data packets sent by the service client.
  • the database operation instruction sent by the business client to the business database may carry the context of the distributed transaction, so that the network agent node can create and process the transaction branch based on the context of the distributed transaction and the database operation statement. Since the transaction branch can be created and processed through the network proxy node, there is no need for the business client to deploy an interface for creating and processing the transaction branch, thereby effectively reducing the development cost of the business client applied to the distributed transaction processing system.
  • the embodiment of the present application also provides a computer-readable storage medium that stores instructions in the computer-readable storage medium, and the instructions are executed by a processor to implement the steps executed by the network agent node in the foregoing method embodiments.
  • the embodiment of the present application also provides a computer-readable storage medium that stores instructions in the computer-readable storage medium, and the instructions are executed by a processor to implement the steps executed by the business client in the foregoing method embodiments.
  • the embodiments of the present application also provide a computer program product containing instructions, which when the computer program product runs on a computer, cause the computer to execute the steps performed by the network agent node in the foregoing method embodiments.
  • the embodiments of the present application also provide a computer program product containing instructions, which when the computer program product runs on a computer, cause the computer to execute the steps executed by the business client in the foregoing method embodiments.
  • the above-mentioned embodiments may be implemented in whole or in part by software, hardware, firmware or any other combination.
  • the above-mentioned embodiments may be implemented in the form of a computer program product in whole or in part.
  • the computer program product includes one or more computer instructions.
  • the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices.
  • the computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website, computer, server, or data center.
  • the computer-readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server or a data center that includes one or more sets of available media.
  • the usable medium may be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium.
  • the semiconductor medium may be a solid state drive (SSD).

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • General Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • Mathematical Physics (AREA)
  • Computational Linguistics (AREA)
  • Software Systems (AREA)
  • Probability & Statistics with Applications (AREA)
  • Fuzzy Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

A method, apparatus and system for processing a distributed transaction, which belong to the technical field of distribution. A database operation instruction sent by a service client to a service database may carry the context of a distributed transaction, such that a network agent node can create and process transaction branches on the basis of the context of the distributed transaction and a database operation statement. Since transaction branches can be created and processed by means of a network agent node, a service client does not need to deploy an interface used for creating and processing the transaction branches, thereby effectively reducing the development cost of the application of the service client to a distributed transaction processing system.

Description

分布式事务的处理方法、装置及系统Distributed transaction processing method, device and system
本申请要求于2020年2月29日提交的申请号为202010132037.5、发明名称为“一种事务处理系统”的中国专利申请的优先权,以及要求于2020年6月15日提交的申请号为202010544092.5、发明名称为“分布式事务的处理方法、装置及系统”的中国专利申请的优先权,其全部内容通过引用结合在本申请中。This application claims the priority of the Chinese patent application filed on February 29, 2020 with the application number 202010132037.5 and the invention title of "a transaction processing system", and the application number filed on June 15, 2020 as 202010544092.5 , The priority of the Chinese patent application with the title of "Distributed Transaction Processing Method, Device and System", the entire content of which is incorporated into this application by reference.
技术领域Technical field
本申请涉及分布式技术领域,特别涉及一种分布式事务的处理方法、装置及系统。This application relates to the field of distributed technology, and in particular to a method, device and system for processing distributed transactions.
背景技术Background technique
事务(transaction)是指由一个或多个资源管理操作构成的一个操作序列。分布式事务是指操作序列中的操作涉及多个数据库(database,DB)的事务。由于分布式事务涉及对多个数据库的操作,因此需保证对各个数据库的操作的一致性。Transaction refers to a sequence of operations composed of one or more resource management operations. Distributed transaction refers to a transaction involving multiple databases (DB) in an operation sequence. Since distributed transactions involve operations on multiple databases, it is necessary to ensure the consistency of operations on each database.
相关技术中,通常采用请求确认取消(try-confirm-cancel,TCC)技术来处理分布式事务,采用该TCC技术的资源服务器(也称为业务服务器)中的业务客户端均部署有try、confirm以及cancel三个接口。该TCC技术的处理过程包括如下两个阶段:在第一阶段(也可以称为try阶段),发起分布式事务的主业务客户端调用该分布式事务涉及的其他各个从业务客户端的try接口,以请求从业务客户端预留业务资源。在第二阶段(也可以称为confirm/cancel阶段),主业务客户端若确定各个从业务客户端的业务资源均预留成功,则可以向事务服务器发送提交(commit)指令,事务服务器进而可以调用各个从业务客户端的confirm接口,以指示各个从业务客户端执行对预留的业务资源的操作,即执行提交操作。主业务客户端若确定任一从业务客户端的业务资源均预留失败,则可以向事务服务器发送回滚(rollback)指令,事务服务器进而可以调用各个从业务客户端的cancel接口,以指示各个从业务客户端取消执行对预留的业务资源的操作,即执行回滚操作以释放预留的业务资源。In related technologies, try-confirm-cancel (TCC) technology is usually used to process distributed transactions. The business clients in the resource server (also called business server) that adopt the TCC technology are deployed with try and confirm. And cancel three interfaces. The processing process of the TCC technology includes the following two stages: In the first stage (also called the try stage), the main business client that initiates the distributed transaction calls the try interfaces of the other slave business clients involved in the distributed transaction. To request the reservation of business resources from the business client. In the second stage (also known as the confirm/cancel stage), if the main business client determines that the business resources of each slave business client are successfully reserved, it can send a commit instruction to the transaction server, and the transaction server can then call The confirm interface of each slave business client instructs each slave business client to perform an operation on the reserved business resources, that is, to perform a submit operation. If the master business client determines that the reservation of the business resources of any slave business client fails, it can send a rollback instruction to the transaction server, and the transaction server can then call the cancel interface of each slave business client to instruct each slave business The client cancels the operation on the reserved business resources, that is, performs a rollback operation to release the reserved business resources.
但是,由于该TCC技术需要参与分布式事务的各个业务客户端均部署try、confirm以及cancel三个接口,导致业务客户端的开发成本较高。However, because the TCC technology needs to deploy try, confirm, and cancel three interfaces for each business client participating in a distributed transaction, the development cost of the business client is high.
发明内容Summary of the invention
本申请提供了一种分布式事务的处理方法、装置及系统,可以解决相关技术中的业务客户端在实现分布式事务时开发成本较高的技术问题。This application provides a method, device, and system for processing distributed transactions, which can solve the technical problem of high development cost when implementing distributed transactions by business clients in related technologies.
一方面,提供了一种分布式事务的处理方法,该方法应用于分布式事务处理系统,该分布式事务处理系统包括多个业务服务器、事务服务器和业务数据库,每个业务服务器包括网络代理节点和业务客户端,且该方法由该网络代理节点执行;该方法包括:获取该业务客户端发送的一个或多个数据库操作指令,每个数据库操作指令包括:数据库操作语句以及分布式事务的上下文,其中,该一个或多个数据库操作指令包括的数据库操作指令用于实现该分布式事务的事务分支,该分布式事务的上下文包括该分布式事务的标识;在该业务数据库中执行每个数据库操作指令包括的数据库操作语句,并向该事务服务器发送事务分支创建请求,该事务分支创建请求包括该分布式事务的标识。On the one hand, a distributed transaction processing method is provided. The method is applied to a distributed transaction processing system. The distributed transaction processing system includes a plurality of business servers, a transaction server, and a business database, and each business server includes a network agent node. And a business client, and the method is executed by the network agent node; the method includes: obtaining one or more database operation instructions sent by the business client, each database operation instruction includes: a database operation statement and the context of a distributed transaction , Wherein the database operation instructions included in the one or more database operation instructions are used to implement the transaction branch of the distributed transaction, and the context of the distributed transaction includes the identification of the distributed transaction; each database is executed in the business database The operation instruction includes a database operation statement, and a transaction branch creation request is sent to the transaction server, and the transaction branch creation request includes the identifier of the distributed transaction.
本申请提供的分布式事务的处理方法,业务客户端发送的数据库操作指令中携带有分布 式事务的上下文,使得网络代理节点可以基于该数据库操作指令来创建和处理事务分支。由于无需业务客户端创建和处理事务分支,因此对业务客户端原有业务逻辑的影响较小,从而有效降低了业务客户端应用于分布式事务处理系统的开发成本。In the distributed transaction processing method provided by this application, the database operation instruction sent by the business client carries the context of the distributed transaction, so that the network agent node can create and process transaction branches based on the database operation instruction. Since there is no need for the business client to create and process transaction branches, the impact on the original business logic of the business client is small, thereby effectively reducing the development cost of the business client applied to the distributed transaction processing system.
可选的,该方法还包括:获取数据集的锁信息,该数据集是该一个或多个数据库操作指令包括的数据库操作语句所针对的,该数据集的锁信息用于在该业务数据库中标识该数据集;相应的,该事务分支创建请求还包括该数据集的锁信息。Optionally, the method further includes: acquiring lock information of a data set that is targeted by a database operation statement included in the one or more database operation instructions, and the lock information of the data set is used in the business database Identify the data set; correspondingly, the transaction branch creation request also includes the lock information of the data set.
在事务分支创建请求中携带数据集的锁信息,可以便于事务服务器该数据集是否被加锁,进而判断是否能够创建该事务分支。Carrying the lock information of the data set in the transaction branch creation request can facilitate whether the data set is locked by the transaction server, and then determine whether the transaction branch can be created.
可选的,网络代理节点确认该业务数据库的自动提交功能处于开启状态,该网络代理节点可以在接收到该事务服务器发送的用于指示事务分支创建成功的第一创建响应后,再在该业务数据库中执行每个数据库操作指令所包括的数据库操作语句。并且,网络代理节点还可以响应于该第一创建响应,向业务数据库发送针对该分布式事务的事务分支的第一提交指令,该第一提交指令用于指示该业务数据库提交该事务分支。Optionally, the network agent node confirms that the automatic submission function of the service database is in the on state, and the network agent node may, after receiving the first creation response sent by the transaction server to indicate that the transaction branch is successfully created, then perform the service The database operation statement included in each database operation instruction is executed in the database. In addition, the network agent node may also send a first commit instruction for the transaction branch of the distributed transaction to the service database in response to the first creation response, where the first commit instruction is used to instruct the service database to submit the transaction branch.
网络代理节点在确定事务分支创建成功后,再执行该数据库操作语句,可以避免在执行该数据库操作语句之后,若又确定事务分支创建失败,导致之前执行的数据库操作语句无效的问题。也即是,在事务分支创建失败的场景中不再执行数据库操作语句,可以避免浪费业务服务器的计算资源。After the network agent node determines that the transaction branch is created successfully, it executes the database operation statement, which can avoid the problem that the previously executed database operation statement is invalid if it determines that the transaction branch creation fails after executing the database operation statement. That is, in the scenario where the creation of the transaction branch fails, the database operation statement is no longer executed, which can avoid wasting the computing resources of the business server.
可选的,网络代理节点还可以接收事务服务器发送的用于指示事务分支创建失败的第二创建响应;并且,响应于该第二创建响应,向业务数据库发送针对该分布式事务的事务分支的第一回滚指令,该第一回滚指令用于指示业务数据库回滚该事务分支。Optionally, the network agent node may also receive a second creation response sent by the transaction server to indicate that the creation of the transaction branch fails; and, in response to the second creation response, send to the service database the transaction branch of the distributed transaction The first rollback instruction is used to instruct the business database to roll back the transaction branch.
可选的,网络代理节点确认该业务数据库的自动提交功能处于关闭状态,并可以在每执行完成一个数据库操作指令中的数据库操作语句后,向该业务客户端发送该数据库操作语句的执行结果;并且,该网络代理节点可以在获取到该业务客户端发送的针对该分布式事务的事务分支的第二提交指令后,获取该数据集的锁信息;其中,若用于实现该分布式事务的事务分支的数据库操作语句的个数大于1,则该业务数据库的自动提交功能被该业务客户端设置为关闭状态;该第二提交指令是该业务客户端在根据该网络代理节点发送的执行结果确定用于实现该分布式事务的事务分支的每个数据库操作指令所包括的数据库操作语句均执行成功后发送的。Optionally, the network agent node confirms that the automatic submission function of the business database is in the off state, and may send the execution result of the database operation statement to the business client after each execution of a database operation statement in a database operation instruction; In addition, the network agent node may obtain the lock information of the data set after obtaining the second commit instruction for the transaction branch of the distributed transaction sent by the business client; wherein, if the data set is used to implement the distributed transaction The number of database operation statements of the transaction branch is greater than 1, then the automatic submission function of the business database is set to the off state by the business client; the second commit instruction is the execution result sent by the business client according to the network agent node It is determined that the database operation statements included in each database operation instruction used to implement the transaction branch of the distributed transaction are sent after the execution is successful.
由于网络代理节点在检测到该业务数据库的自动提交功能处于关闭状态时,可以确定用于实现该事务分支的数据库操作指令包括多个,因此网络代理节点可以在接收到第二提交指令后,再获取数据集的锁信息,进而发送事务分支创建请求。Since the network agent node detects that the automatic submission function of the business database is in the off state, it can determine that the database operation instructions used to implement the transaction branch include multiple, so the network agent node can perform the second submission instruction after receiving the second submission instruction. Obtain the lock information of the data set, and then send a transaction branch creation request.
可选的,网络代理节点在向该业务客户端发送每个数据库操作指令包括的数据库操作语句的执行结果之后,若获取到该业务客户端发送的针对该分布式事务的事务分支的第二回滚指令,则还可以删除该数据集的锁信息,并向该业务数据库发送该第二回滚指令;其中,该第二回滚指令是该业务客户端在确定用于实现该事务分支的任一数据库操作指令包括的数据库操作语句执行失败后发送的。Optionally, after the network agent node sends the execution result of the database operation statement included in each database operation instruction to the business client, if it obtains the second transaction branch for the distributed transaction sent by the business client Rollback instruction, you can also delete the lock information of the data set, and send the second rollback instruction to the business database; wherein, the second rollback instruction is the task of the business client when determining to implement the transaction branch. Sent after the execution of a database operation sentence included in a database operation instruction fails.
网络代理节点若接收到第二回滚指令,则可以确定该事务分支执行失败,因此可以删除其存储的数据集的锁信息,避免该数据集的锁信息占用过多的存储空间。If the network agent node receives the second rollback instruction, it can determine that the transaction branch has failed to execute, and therefore can delete the lock information of the stored data set to avoid the lock information of the data set from occupying too much storage space.
可选的,该网络代理节点可以获取该业务客户端发送的第一设置指令,并可以根据该第一设置指令记录该业务数据库的自动提交功能为开启状态。或者,网络代理节点可以获取该业务客户端发送的第二设置指令,并可以根据该第二设置指令记录该业务数据库的自动提交 功能为关闭状态;其中,该第一设置指令是该业务客户端在确定用于实现该事务分支的该数据库操作语句的个数等于1时发送的;该第二设置指令是该业务客户端在确定用于实现该事务分支的该数据库操作语句的个数大于1时发送的。Optionally, the network agent node may obtain the first setting instruction sent by the business client, and may record the automatic submission function of the business database as the on state according to the first setting instruction. Alternatively, the network agent node may obtain the second setting instruction sent by the business client, and may record the automatic submission function of the business database as closed according to the second setting instruction; wherein, the first setting instruction is the business client Sent when it is determined that the number of database operation statements used to implement the transaction branch is equal to 1; the second setting instruction is when the business client determines that the number of database operation statements used to implement the transaction branch is greater than 1 Sent when.
网络代理节点根据获取到的第一设置指令或第二设置指令,记录该业务数据库的自动提交功能的状态,可以确保在创建事务分支时,能够根据记录的状态准确地确定该业务数据库的自动提交功能是否开启。The network agent node records the status of the automatic submission function of the business database according to the acquired first setting instruction or the second setting instruction, which can ensure that when a transaction branch is created, the automatic submission of the business database can be accurately determined according to the recorded status Whether the function is turned on.
可选的,该第一创建响应中可以携带有该事务服务器为该事务分支分配的标识;网络代理节点在接收到该事务服务器发送的用于指示分布式事务的事务分支创建成功的第一创建响应之后,还可以在该分布式事务的事务日志中存储该事务分支的标识以及该数据集的对应关系;之后,网络代理节点可以接收该事务服务器发送的针对该事务分支的第三提交指令,并清理该事务日志中记录的该事务分支的标识以及该数据集;或者,网络代理节点可以接收该事务服务器发送的针对该事务分支的第三回滚指令,根据该事务分支的标识从该事务日志中获取该数据集,并根据该数据集回滚该事务分支。Optionally, the first creation response may carry an identifier assigned by the transaction server to the transaction branch; the network agent node receives the first creation sent by the transaction server to indicate that the transaction branch of the distributed transaction is successfully created. After the response, the identifier of the transaction branch and the corresponding relationship of the data set can also be stored in the transaction log of the distributed transaction; afterwards, the network proxy node can receive the third commit instruction for the transaction branch sent by the transaction server, And clean up the transaction branch identifier and the data set recorded in the transaction log; or, the network agent node may receive the third rollback instruction for the transaction branch sent by the transaction server, and then obtain the transaction branch from the transaction according to the transaction branch identifier. Obtain the data set from the log, and roll back the transaction branch according to the data set.
其中,该第三提交指令是该事务服务器在接收到业务客户端发送的针对该分布式事务的提交指令后发送的,该第三回滚指令是该事务服务器在接收到业务客户端发送的针对该分布式事务的回滚指令后发送的。Wherein, the third commit instruction is sent by the transaction server after receiving the commit instruction for the distributed transaction sent by the business client, and the third rollback instruction is sent by the transaction server after the transaction server receives the commit instruction for the distributed transaction. Sent after the rollback instruction of the distributed transaction.
可选的,网络代理节点在向该业务数据库发送针对分布式事务的事务分支的第一提交指令之后,还可以删除该数据集的锁信息;并且,网络代理节点若确定该事务分支提交成功,则可以向该业务客户端发送用于指示该分布式事务的事务分支提交成功的提交结果;网络代理节点若确定该分布式事务的事务分支提交失败,则可以向该业务客户端发送用于指示该分布式事务的事务分支提交失败的提交结果,向该业务数据库发送针对该分布式事务的事务分支的第四回滚指令,并向该事务服务器发送携带有该分布式事务的事务分支的标识的通知消息,该通知消息用于指示该事务服务器删除该分布式事务的事务分支所对应的数据集的锁信息。Optionally, after the network agent node sends the first commit instruction for the transaction branch of the distributed transaction to the service database, it can also delete the lock information of the data set; and, if the network agent node determines that the transaction branch is submitted successfully, Then, it can send a commit result indicating that the transaction branch of the distributed transaction is successfully submitted to the business client; if the network agent node determines that the transaction branch of the distributed transaction has failed, it can send an instruction to the business client If the transaction branch of the distributed transaction fails to submit the commit result, the fourth rollback instruction for the transaction branch of the distributed transaction is sent to the business database, and the transaction branch carrying the identifier of the distributed transaction is sent to the transaction server The notification message is used to instruct the transaction server to delete the lock information of the data set corresponding to the transaction branch of the distributed transaction.
网络代理节点发送针对事务分支的第一提交指令后,向该业务客户端反馈事务分支的提交结果,可以便于业务客户端根据该提交结果确定提交或回滚分布式事务。After the network agent node sends the first commit instruction for the transaction branch, it feeds back the commit result of the transaction branch to the business client, which can facilitate the business client to determine to commit or roll back the distributed transaction according to the commit result.
可选的,该网络代理节点可以拦截业务客户端发送的数据包,若检测到该业务客户端发送的数据包的接收方为该业务数据库,则网络代理节点可以获取并解析该数据包;若检测到该业务客户端发送的数据包的接收方不为该业务数据库,则网络代理节点可以直接向该接收方转发该数据包。Optionally, the network proxy node can intercept the data packet sent by the business client, and if it is detected that the recipient of the data packet sent by the business client is the business database, the network proxy node can obtain and parse the data packet; if If it is detected that the receiver of the data packet sent by the service client is not the service database, the network proxy node may directly forward the data packet to the receiver.
本申请提供的方案中,由于网络代理节点仅需解析业务客户端发送至业务数据库的数据包,而业务客户端均基于数据库协议与业务数据库进行数据交互,因此该网络代理节点仅需支持数据库协议即可适配于不同编程语言开发得到的业务客户端。也即是,本申请提供的方案可以应用于跨编程语言的分布式事务处理系统中。In the solution provided in this application, since the network proxy node only needs to parse the data packets sent by the business client to the business database, and the business clients interact with the business database based on the database protocol, the network proxy node only needs to support the database protocol It can be adapted to business clients developed in different programming languages. That is, the solution provided in this application can be applied to a cross-programming language distributed transaction processing system.
另一方面,提供了一种分布式事务的处理方法,应用于分布式事务处理系统,该分布式事务处理系统包括多个业务服务器、事务服务器和业务数据库,每个业务服务器包括网络代理节点和业务客户端,并且该方法可以由第一业务客户端执行;该方法可以包括:根据分布式事务中该第一业务客户端待执行的事务分支,生成用于实现该分布式事务的事务分支的一个或多个数据库操作语句;根据该一个或多个数据库操作语句生成一个或多个数据库操作指令,每个数据库操作指令包括至少一个数据库操作语句以及分布式事务的上下文,该分布式事务的上下文包括该分布式事务的标识;向第一业务数据库发送该一个或多个数据库操作指 令,其中,第一网络代理节点和第一业务客户端部署于同一业务服务器。On the other hand, a distributed transaction processing method is provided, which is applied to a distributed transaction processing system. The distributed transaction processing system includes multiple business servers, transaction servers, and business databases. Each business server includes a network agent node and Business client, and the method may be executed by a first business client; the method may include: generating a transaction branch for realizing the distributed transaction according to the transaction branch to be executed by the first business client in the distributed transaction One or more database operation statements; one or more database operation instructions are generated according to the one or more database operation statements, each database operation instruction includes at least one database operation statement and the context of a distributed transaction, and the context of the distributed transaction Including the identification of the distributed transaction; sending the one or more database operation instructions to the first service database, where the first network agent node and the first service client are deployed on the same service server.
由于业务客户端发送的数据库操作指令中携带有分布式事务的上下文,因此获取到该数据库操作指令的网络代理节点即可基于该数据库操作语句以及分布式事务的上下文来创建和处理事务分支。由于无需业务客户端创建和处理事务分支,因此对业务客户端原有业务逻辑的影响较小,从而有效降低了业务客户端应用于分布式事务处理系统的开发成本。Since the database operation instruction sent by the business client carries the context of the distributed transaction, the network agent node that has obtained the database operation instruction can create and process the transaction branch based on the database operation statement and the context of the distributed transaction. Since there is no need for the business client to create and process transaction branches, the impact on the original business logic of the business client is small, thereby effectively reducing the development cost of the business client applied to the distributed transaction processing system.
可选的,该第一业务客户端可以为发起分布式事务的主业务客户端,相应的,该第一业务客户端还可以响应于业务请求,向该事务服务器发送该分布式事务的创建请求;接收该事务服务器发送的该分布式事务的标识;并向参与该分布式事务的第二业务客户端发送服务调用请求,该服务调用请求中携带有该分布式事务的标识;并且,该第一业务客户端可以根据该业务请求,确定该分布式事务中该第一业务客户端待执行的事务分支。Optionally, the first business client may be the main business client that initiates the distributed transaction. Correspondingly, the first business client may also send the creation request of the distributed transaction to the transaction server in response to the service request. ; Receive the identifier of the distributed transaction sent by the transaction server; and send a service invocation request to the second business client participating in the distributed transaction, the service invocation request carries the identifier of the distributed transaction; and, the first A business client can determine the transaction branch to be executed by the first business client in the distributed transaction according to the business request.
可选的,作为主业务客户端的该第一业务客户端还可以执行如下操作:接收该第一网络代理节点发送的该事务分支的提交结果;并接收该第二业务客户端响应于该服务调用请求发送的服务调用响应;之后,根据该提交结果和该服务调用响应,向该事务服务器发送针对该分布式事务的提交指令或者回滚指令;其中,针对该分布式事务的提交指令用于指示提交该分布式事务包括的各个事务分支,针对该分布式事务的提交指令用于指示回滚该分布式事务包括的各个事务分支。Optionally, the first business client as the main business client may also perform the following operations: receive the commit result of the transaction branch sent by the first network proxy node; and receive the second business client's response to the service invocation The service invocation response requested to be sent; then, according to the commit result and the service invocation response, a commit instruction or a rollback instruction for the distributed transaction is sent to the transaction server; wherein, the commit instruction for the distributed transaction is used to indicate Submit each transaction branch included in the distributed transaction, and a commit instruction for the distributed transaction is used to instruct to roll back each transaction branch included in the distributed transaction.
本申请提供的方案中,作为主业务客户端的第一业务客户端在实现分布式事务的过程中,仅需发送分布式事务的创建请求、生成数据库操作指令以及发送分布式事务的提交指令或者回滚指令。上述操作对主业务客户端原有业务逻辑的影响较小,即对该主业务客户端的业务的侵入性较低,因此可以有效减小主业务客户端适配分布式事务处理架构,以实现业务分布式化改造时的成本。In the solution provided by this application, the first business client as the main business client only needs to send the creation request of the distributed transaction, generate the database operation instruction, and send the commit instruction or reply of the distributed transaction in the process of realizing the distributed transaction. Roll instructions. The above operations have little impact on the original business logic of the main business client, that is, the business of the main business client is less intrusive, so it can effectively reduce the adaptation of the main business client to the distributed transaction processing architecture to achieve business Cost of distributed transformation.
可选的,第一业务客户端也可以为参与分布式事务的从业务客户端,相应的,该第一业务客户端还可以接收第二业务客户端(即主业务客户端)发送的服务调用请求,该服务调用请求中携带有该分布式事务的上下文;根据该服务调用请求,确定该分布式事务中该第一业务客户端待执行的事务分支。Optionally, the first business client can also be a slave business client participating in a distributed transaction. Correspondingly, the first business client can also receive a service call sent by a second business client (ie, the main business client) Request, the service invocation request carries the context of the distributed transaction; according to the service invocation request, the transaction branch to be executed by the first business client in the distributed transaction is determined.
作为从业务客户端的该第一业务客户端在实现分布式事务的过程中,仅需生成数据库操作指令,从而可以有效减小从业务客户端适配分布式事务处理架构,以实现业务分布式化改造时的成本。In the process of realizing distributed transactions, the first business client as the slave business client only needs to generate database operation instructions, which can effectively reduce the adaptation of the distributed transaction processing architecture from the business client to realize the distributed business. The cost of retrofitting.
可选的,该方法还可以包括:第一业务客户端确定用于实现该分布式事务的事务分支的数据库操作语句的个数等于1,向该第一业务数据库发送用于指示将自动提交功能设置为开启状态的第一设置指令;或者,第一业务客户端确定用于实现该分布式事务的事务分支的数据库操作语句的个数大于1,向该第一业务数据库发送用于指示将自动提交功能设置为关闭状态的第二设置指令。Optionally, the method may further include: the first business client determines that the number of database operation statements used to implement the transaction branch of the distributed transaction is equal to 1, and sends to the first business database an instruction to automatically submit a function The first setting instruction set to the on state; or, the first business client determines that the number of database operation statements used to implement the transaction branch of the distributed transaction is greater than 1, and sends to the first business database an instruction to automatically Submit the second setting instruction in which the function is set to the off state.
上述第一设置指令和第二设置指令可以被第一网络代理节点拦截,第一网络代理节点可以基于该第一设置指令或第二设置指令准确地确定第一业务数据库的自动提交功能的状态,也即是,可以准确地确定用于实现分布式事务的事务分支的数据库操作语句的个数是否大于1。The above-mentioned first setting instruction and second setting instruction can be intercepted by the first network agent node, and the first network agent node can accurately determine the state of the automatic submission function of the first service database based on the first setting instruction or the second setting instruction, That is, it can be accurately determined whether the number of database operation statements used to implement the transaction branch of the distributed transaction is greater than one.
可选的,第一业务客户端在向该第一业务数据库发送用于指示将自动提交功能设置为关闭状态的第二设置指令之后,还可以接收该第一网络代理节点发送的每个数据库操作指令包括的数据库操作语句的执行结果;若根据该执行结果确定用于实现该分布式事务的事务分支的每个数据库操作指令包括的数据库操作语句均执行成功,则第一业务客户端可以向该第一业务数据库发送针对该分布式事务的事务分支的第二提交指令;若根据该执行结果确定用于 实现该分布式事务的事务分支的任一数据库操作指令包括的数据库操作语句执行失败,则第一业务客户端可以向该第一业务数据库发送针对该分布式事务的事务分支的第二回滚指令。Optionally, after sending a second setting instruction for instructing the automatic submission function to be turned off to the first service database, the first service client may also receive each database operation sent by the first network proxy node The execution result of the database operation statement included in the instruction; if it is determined according to the execution result that the database operation statement included in each database operation instruction used to implement the transaction branch of the distributed transaction is executed successfully, the first business client can send the The first service database sends a second commit instruction for the transaction branch of the distributed transaction; if it is determined according to the execution result that any database operation instruction used to implement the transaction branch of the distributed transaction includes a database operation statement that fails to execute, then The first service client may send a second rollback instruction for the transaction branch of the distributed transaction to the first service database.
上述第二提交指令和第二回滚指令可以被第一网络代理节点拦截,第一网络代理节点可以基于该第二提交指令创建事务分支,或者可以基于该第二回滚指令回滚事务分支。The aforementioned second commit instruction and second rollback instruction may be intercepted by the first network agent node, and the first network agent node may create a transaction branch based on the second commit instruction, or may roll back the transaction branch based on the second rollback instruction.
又一方面,提供了一种网络代理节点,应用于分布式事务处理系统,该分布式事务处理系统包括多个业务服务器、事务服务器和业务数据库,每个业务服务器包括网络代理节点和业务客户端,该网络代理节点包括:In another aspect, a network agent node is provided, which is applied to a distributed transaction processing system. The distributed transaction processing system includes multiple business servers, transaction servers, and business databases. Each business server includes a network agent node and a business client. , The network agent node includes:
解析模块,用于获取该业务客户端发送的一个或多个数据库操作指令,每个数据库操作指令包括:数据库操作语句以及该分布式事务的上下文,该一个或多个数据库操作指令包括的数据库操作语句用于实现该分布式事务的事务分支,该分布式事务的上下文包括该分布式事务的标识;The parsing module is used to obtain one or more database operation instructions sent by the business client. Each database operation instruction includes: a database operation statement and the context of the distributed transaction, and the one or more database operation instructions include database operations The statement is used to implement the transaction branch of the distributed transaction, and the context of the distributed transaction includes the identifier of the distributed transaction;
事务分支处理模块,用于在该业务数据库中执行每个数据库操作指令包括的数据库操作语句,以及向该事务服务器发送事务分支创建请求,该事务分支创建请求包括该分布式事务的标识。The transaction branch processing module is used to execute database operation statements included in each database operation instruction in the business database, and send a transaction branch creation request to the transaction server, and the transaction branch creation request includes the identifier of the distributed transaction.
可选的,该事务分支处理模块还用于:获取数据集的锁信息,该数据集是该一个或多个数据库操作指令包括的数据库操作语句所针对的,该数据集的锁信息用于在该业务数据库中标识该数据集;该事务分支创建请求还包括该数据集的锁信息。Optionally, the transaction branch processing module is further used to obtain lock information of a data set, the data set being targeted by a database operation statement included in the one or more database operation instructions, and the lock information of the data set used in The data set is identified in the business database; the transaction branch creation request also includes lock information of the data set.
可选的,该事务分支处理模块,用于:确认该业务数据库的自动提交功能处于开启状态;在接收到该事务服务器发送的用于指示该事务分支创建成功的第一创建响应后,在该业务数据库中执行每个数据库操作指令包括的数据库操作语句;该事务分支处理模块,还用于:响应于该第一创建响应,向该业务数据库发送针对该事务分支的第一提交指令。Optionally, the transaction branch processing module is configured to: confirm that the automatic submission function of the business database is in the on state; after receiving the first creation response sent by the transaction server indicating that the transaction branch is successfully created, in the The business database executes database operation statements included in each database operation instruction; the transaction branch processing module is further configured to: in response to the first creation response, send a first commit instruction for the transaction branch to the business database.
可选的,该事务分支处理模块,还用于:接收该事务服务器发送的用于指示该事务分支创建失败的第二创建响应;响应于该第二创建响应,向该业务数据库发送针对该事务分支的第一回滚指令。Optionally, the transaction branch processing module is further configured to: receive a second creation response sent by the transaction server for indicating that the transaction branch creation fails; in response to the second creation response, send to the business database a response to the transaction The first rollback instruction of the branch.
可选的,该事务分支处理模块,还用于:确认该业务数据库的自动提交功能处于关闭状态;向该业务客户端发送每个数据库操作指令包括的数据库操作语句的执行结果;在获取到该业务客户端发送的针对该事务分支的第二提交指令后,获取该数据集的锁信息;其中,该第二提交指令是该业务客户端在根据该执行结果确定每个数据库操作指令包括的数据库操作语句均执行成功后发送的。Optionally, the transaction branch processing module is further used to: confirm that the automatic submission function of the business database is in the off state; send the execution result of the database operation statement included in each database operation instruction to the business client; After the second commit instruction for the transaction branch sent by the business client, the lock information of the data set is acquired; where the second commit instruction is the business client determining the database included in each database operation instruction according to the execution result Sent after the operation statements are executed successfully.
可选的,该事务分支处理模块,还用于:在向该业务客户端发送每个数据库操作指令包括的数据库操作语句的执行结果之后,获取该业务客户端发送的针对该事务分支的第二回滚指令,删除该数据集的锁信息;向该业务数据库发送该第二回滚指令;其中,该第二回滚指令是该业务客户端在确定任一数据库操作指令包括的数据库操作语句执行失败后发送的。Optionally, the transaction branch processing module is further configured to: after sending the execution result of the database operation statement included in each database operation instruction to the business client, obtain the second transaction branch sent by the business client. Rollback instruction, delete the lock information of the data set; send the second rollback instruction to the business database; wherein, the second rollback instruction is executed by the business client in determining the database operation statement included in any database operation instruction Sent after failure.
可选的,该事务分支处理模块,还用于:获取该业务客户端发送的第一设置指令;根据该第一设置指令记录该业务数据库的自动提交功能为开启状态;其中,该第一设置指令是该业务客户端在确定用于实现该事务分支的数据库操作语句的个数等于1时发送的。Optionally, the transaction branch processing module is further configured to: obtain the first setting instruction sent by the business client; according to the first setting instruction, record that the automatic submission function of the business database is turned on; wherein, the first setting The instruction is sent when the business client determines that the number of database operation statements used to implement the transaction branch is equal to 1.
可选的,该事务分支处理模块,还用于:获取该业务客户端发送的第二设置指令;根据该第二设置指令记录该业务数据库的自动提交功能为关闭状态;其中,该第二设置指令是该业务客户端在确定用于实现该事务分支的数据库操作语句的个数大于1时发送的。Optionally, the transaction branch processing module is further configured to: obtain a second setting instruction sent by the business client; according to the second setting instruction, record that the automatic submission function of the business database is off; wherein, the second setting The instruction is sent when the business client determines that the number of database operation statements used to implement the transaction branch is greater than one.
可选的,该第一创建响应中携带有该事务服务器为该事务分支分配的标识;该事务分支处理模块,还用于:在接收到该事务服务器发送的用于指示该事务分支创建成功的第一创建 响应后,在该分布式事务的事务日志中存储该事务分支的标识以及该数据集的对应关系;接收该事务服务器发送的针对该事务分支的第三提交指令,清理该事务日志中记录的该事务分支的标识以及该数据集;其中,该第三提交指令是该事务服务器在接收到该业务客户端发送的针对该分布式事务的提交指令后发送的。Optionally, the first creation response carries an identifier assigned by the transaction server to the transaction branch; the transaction branch processing module is further configured to: upon receiving a message sent by the transaction server indicating that the transaction branch is successfully created After the first response is created, the identifier of the transaction branch and the corresponding relationship of the data set are stored in the transaction log of the distributed transaction; the third commit instruction for the transaction branch sent by the transaction server is received, and the transaction log is cleaned The recorded identifier of the transaction branch and the data set; wherein, the third commit instruction is sent by the transaction server after receiving the commit instruction for the distributed transaction sent by the business client.
可选的,该第一创建响应中携带有该事务服务器为该事务分支分配的标识;该事务分支处理模块,还用于:在接收到该事务服务器发送的用于指示该事务分支创建成功的第一创建响应后,在该分布式事务的事务日志中存储该事务分支的标识以及该数据集的对应关系;接收该事务服务器发送的针对该事务分支的第三回滚指令,根据该事务分支的标识从该事务日志中获取该数据集,并根据该数据集回滚该事务分支;其中,该第三回滚指令是该事务服务器在接收到该业务客户端发送的针对该分布式事务的回滚指令后发送的。Optionally, the first creation response carries an identifier assigned by the transaction server to the transaction branch; the transaction branch processing module is further configured to: upon receiving a message sent by the transaction server indicating that the transaction branch is successfully created After the first response is created, the identifier of the transaction branch and the corresponding relationship of the data set are stored in the transaction log of the distributed transaction; the third rollback instruction for the transaction branch sent by the transaction server is received, according to the transaction branch The identifier of obtains the data set from the transaction log, and rolls back the transaction branch according to the data set; wherein, the third rollback instruction is that the transaction server receives the distributed transaction sent by the business client Sent after the rollback instruction.
再一方面,提供了一种业务客户端,应用于分布式事务处理系统,该分布式事务处理系统包括多个业务服务器、事务服务器和业务数据库,每个业务服务器包括网络代理节点和业务客户端,该业务客户端包括:In another aspect, a business client is provided, which is applied to a distributed transaction processing system. The distributed transaction processing system includes a plurality of business servers, a transaction server, and a business database. Each business server includes a network agent node and a business client. , The business client includes:
处理模块,用于根据该分布式事务中该业务客户端待执行的事务分支,生成用于实现该事务分支一个或多个数据库操作语句;The processing module is used to generate one or more database operation statements for implementing the transaction branch according to the transaction branch to be executed by the business client in the distributed transaction;
应用程序接口模块,用于根据该一个或多个数据库操作语句,生成一个或多个数据库操作指令,每个数据库操作指令包括:至少一个数据库操作语句以及该分布式事务的上下文,该分布式事务的上下文包括该分布式事务的标识;The application program interface module is used to generate one or more database operation instructions according to the one or more database operation statements, and each database operation instruction includes: at least one database operation statement and the context of the distributed transaction, and the distributed transaction The context of includes the identity of the distributed transaction;
数据库驱动器,用于向第一网络代理节点发送该一个或多个数据库操作指令,其中,该第一网络代理节点和该业务客户端部署于同一业务服务器。The database driver is used to send the one or more database operation instructions to the first network agent node, where the first network agent node and the service client are deployed on the same service server.
可选的,该应用程序接口模块,还用于:响应于业务请求,向该事务服务器发送该分布式事务的创建请求;接收该事务服务器发送的该分布式事务的标识;Optionally, the application program interface module is further configured to: in response to a service request, send a creation request of the distributed transaction to the transaction server; receive an identifier of the distributed transaction sent by the transaction server;
该业务客户端还包括:服务调用模块,用于向参与该分布式事务的第二业务客户端发送服务调用请求,该服务调用请求中携带有该分布式事务的标识;该处理模块,还用于根据该业务请求,确定该分布式事务中该业务客户端待执行的事务分支。The business client further includes: a service invocation module for sending a service invocation request to a second business client participating in the distributed transaction, and the service invocation request carries the identifier of the distributed transaction; the processing module also uses Based on the business request, determine the transaction branch to be executed by the business client in the distributed transaction.
可选的,该处理模块,还用于:接收该第一网络代理节点发送的该事务分支的提交结果;接收该第二业务客户端响应于该服务调用请求发送的服务调用响应;根据该提交结果和该服务调用响应,向该事务服务器发送针对该分布式事务的提交指令或者回滚指令;其中,针对该分布式事务的提交指令用于指示提交该分布式事务包括的各个事务分支,针对该分布式事务的提交指令用于指示回滚该分布式事务包括的各个事务分支。Optionally, the processing module is further configured to: receive the commit result of the transaction branch sent by the first network agent node; receive the service invocation response sent by the second business client in response to the service invocation request; and according to the commit Result and the service call response, send a commit instruction or rollback instruction for the distributed transaction to the transaction server; wherein, the commit instruction for the distributed transaction is used to instruct to submit each transaction branch included in the distributed transaction, and for The commit instruction of the distributed transaction is used to instruct to roll back each transaction branch included in the distributed transaction.
可选的,该处理模块,还用于:接收第二业务客户端发送的服务调用请求,该服务调用请求中携带有该分布式事务的上下文;根据该服务调用请求,确定该分布式事务中该业务客户端待执行的事务分支。Optionally, the processing module is further configured to: receive a service invocation request sent by a second business client, the service invocation request carries the context of the distributed transaction; according to the service invocation request, determine that the distributed transaction is The branch of the transaction to be executed by the business client.
可选的,该处理模块,还用于:确定该数据库操作语句的个数等于1,指示该数据库驱动器向第一业务数据库发送第一设置指令,该第一设置指令指示将自动提交功能设置为开启状态。Optionally, the processing module is further configured to: determine that the number of database operation statements is equal to 1, and instruct the database driver to send a first setting instruction to the first business database, and the first setting instruction instructs to set the automatic submission function to Open state.
可选的,该处理模块,还用于:确定该数据库操作语句的个数大于1,指示该数据库驱动器向第一业务数据库发送第二设置指令,该第二设置指令指示将自动提交功能设置为关闭状态。Optionally, the processing module is further configured to: determine that the number of database operation statements is greater than 1, and instruct the database driver to send a second setting instruction to the first business database, and the second setting instruction instructs to set the automatic submission function to Disabled.
可选的,该处理模块,还用于:接收每个数据库操作指令包括的数据库操作语句的执行结果;根据该执行结果确定每个数据库操作指令包括的数据库操作语句均执行成功,指示该 数据库驱动器向该第一业务数据库发送针对该事务分支的第二提交指令。Optionally, the processing module is further configured to: receive the execution result of the database operation statement included in each database operation instruction; determine according to the execution result that the database operation statement included in each database operation instruction is executed successfully, and instruct the database driver Send a second commit instruction for the transaction branch to the first service database.
可选的,该业务客户端还包括:接收每个数据库操作指令包括的数据库操作语句的执行结果;根据该执行结果确定任一数据库操作指令包括的数据库操作语句执行失败,指示该数据库驱动器向该第一业务数据库发送针对该事务分支的第二回滚指令。Optionally, the business client further includes: receiving the execution result of the database operation statement included in each database operation instruction; determining, according to the execution result, that the execution of the database operation statement included in any database operation instruction has failed, and instructing the database driver to The first service database sends a second rollback instruction for the transaction branch.
再一方面,提供了一种网络代理节点,该网络代理节点包括:存储器,处理器及存储在该存储器上并可在该处理器上运行的计算机程序,该处理器执行该计算机程序时实现上述方面所提供的由该网络代理节点执行的分布式事务的处理方法。In another aspect, a network agent node is provided. The network agent node includes a memory, a processor, and a computer program stored in the memory and running on the processor, and the processor implements the foregoing when the computer program is executed. The distributed transaction processing method performed by the network agent node provided by the aspect.
再一方面,提供了一种业务客户端,该业务客户端包括:存储器,处理器及存储在该存储器上并可在该处理器上运行的计算机程序,该处理器执行该计算机程序时实现上述方面所提供的由第一业务客户端执行的分布式事务的处理方法。In another aspect, a business client is provided. The business client includes a memory, a processor, and a computer program stored in the memory and running on the processor, and the processor implements the foregoing when the computer program is executed. The distributed transaction processing method performed by the first business client provided by the aspect.
再一方面,提供了一种计算机可读存储介质,该计算机可读存储介质中存储有指令,当该指令由处理器执行以实现如上述方面所提供的由该网络代理节点执行的分布式事务的处理方法。In yet another aspect, a computer-readable storage medium is provided. The computer-readable storage medium stores instructions. When the instructions are executed by a processor, the distributed transaction executed by the network agent node as provided in the above aspect is realized.的处理方法。 Treatment methods.
再一方面,提供了一种计算机可读存储介质,该计算机可读存储介质中存储有指令,当该指令由处理器执行以实现如上述方面所提供的由第一业务客户端执行的分布式事务的处理方法。In yet another aspect, a computer-readable storage medium is provided. The computer-readable storage medium stores instructions. When the instructions are executed by a processor, the distributed system executed by the first business client as provided in the above aspect is implemented. The processing method of the transaction.
再一方面,提供了一种分布式事务处理系统,该分布式事务处理系统包括:事务服务器,多个业务服务器,以及多个业务数据库;In another aspect, a distributed transaction processing system is provided. The distributed transaction processing system includes: a transaction server, a plurality of business servers, and a plurality of business databases;
每个业务服务器包括如上述方面所提供的网络代理节点,以及如上述方面所提供的业务客户端。Each service server includes the network agent node provided in the above-mentioned aspect, and the service client provided in the above-mentioned aspect.
综上所述,本申请提供了一种分布式事务的处理方法、装置及系统,本申请提供的方案在处理分布式事务的过程中,业务客户端发送至业务数据库的数据库操作指令中可以携带有分布式事务的上下文,使得网络代理节点可以基于该分布式事务的上下文,以及该数据库操作语句来创建和处理事务分支。由于可以通过网络代理节点来创建和处理事务分支,因此无需该业务客户端部署用于创建和处理事务分支的接口(例如try、confirm和cancel接口),从而有效降低了业务客户端应用于分布式事务处理系统的开发成本。In summary, this application provides a method, device, and system for processing distributed transactions. In the process of processing distributed transactions, the solution provided in this application can be carried in the database operation instructions sent by the business client to the business database. There is a distributed transaction context, so that the network agent node can create and process transaction branches based on the distributed transaction context and the database operation statement. Since transaction branches can be created and processed through network proxy nodes, there is no need for the business client to deploy interfaces for creating and processing transaction branches (such as try, confirm, and cancel interfaces), thereby effectively reducing the application of business clients to distributed The development cost of the transaction processing system.
附图说明Description of the drawings
图1是本申请实施例提供的一种分布式事务处理系统的结构示意图;FIG. 1 is a schematic structural diagram of a distributed transaction processing system provided by an embodiment of the present application;
图2是本申请实施例提供的另一种分布式事务处理系统的结构示意图;Figure 2 is a schematic structural diagram of another distributed transaction processing system provided by an embodiment of the present application;
图3是本申请实施例提供的一种分布式事务的处理方法的流程图;FIG. 3 is a flowchart of a method for processing distributed transactions according to an embodiment of the present application;
图4是本申请实施例提供的另一种分布式事务的处理方法的流程图;FIG. 4 is a flowchart of another distributed transaction processing method provided by an embodiment of the present application;
图5是本申请实施例提供的一种网络代理节点拦截数据包的方法流程图;FIG. 5 is a flowchart of a method for a network proxy node to intercept data packets according to an embodiment of the present application;
图6是本申请实施例提供的又一种分布式事务处理系统的结构示意图;FIG. 6 is a schematic structural diagram of another distributed transaction processing system provided by an embodiment of the present application;
图7是本申请实施例提供的再一种分布式事务处理系统的结构示意图。Fig. 7 is a schematic structural diagram of yet another distributed transaction processing system provided by an embodiment of the present application.
具体实施方式Detailed ways
下面结合附图详细介绍本申请实施例提供的分布式事务的处理方法、装置及系统。The following describes in detail the distributed transaction processing method, device, and system provided by the embodiments of the present application with reference to the accompanying drawings.
图1是本申请实施例提供的一种分布式事务处理系统的结构示意图,如图1所示,该系统可以包括:多个业务服务器01,事务服务器02,以及多个业务数据库03。其中,每个业务数据库03对应于一个业务服务器01,每个业务数据库03用于存储其对应的业务服务器01的业务 数据。并且,每个业务数据库03部署在一个数据库服务器中。FIG. 1 is a schematic structural diagram of a distributed transaction processing system provided by an embodiment of the present application. As shown in FIG. 1, the system may include: multiple business servers 01, transaction servers 02, and multiple business databases 03. Among them, each business database 03 corresponds to a business server 01, and each business database 03 is used to store the business data of its corresponding business server 01. In addition, each business database 03 is deployed in a database server.
在本申请实施例中,该分布式事务处理系统可以采用服务网格(service mesh)架构来实现业务服务器01之间的通信,从而确保各个业务服务器01中业务客户端011内运行的服务能够被可靠调用。如图1所示,该系统中的每个业务服务器01中除了部署有业务客户端011,还可以部署有网络代理节点012。各个业务服务器01中的网络代理节点012可以组成服务网格,该服务网格可以实现不同业务服务器01中的业务客户端011之间的通信,业务客户端011与事务服务器02的通信以及业务客户端011与业务数据库03的通信。In the embodiment of the present application, the distributed transaction processing system may adopt a service mesh architecture to implement communication between business servers 01, so as to ensure that the services running in the business client 011 in each business server 01 can be Reliable call. As shown in Figure 1, each service server 01 in the system may be deployed with a network agent node 012 in addition to a service client 011. The network agent nodes 012 in each business server 01 can form a service grid, which can realize the communication between the business clients 011 in different business servers 01, the communication between the business clients 011 and the transaction server 02, and the business clients The terminal 011 communicates with the service database 03.
可选的,该每个业务服务器01中可以运行有一个或多个虚拟机,业务客户端011和网络代理节点012可以部署在相同虚拟机中,也可以分别部署在不同虚拟机中。或者,该每个业务服务器01中可以运行有一个或多个容器,业务客户端011和网络代理节点012可以部署在相同容器中,也可以分别部署在不同容器中。Optionally, each service server 01 may run one or more virtual machines, and the service client 011 and the network proxy node 012 may be deployed in the same virtual machine, or they may be deployed in different virtual machines. Alternatively, each service server 01 may run one or more containers, and the service client 011 and the network agent node 012 may be deployed in the same container, or they may be deployed in different containers.
该业务服务器01、该事务服务器02以及部署业务数据库03的数据库服务器中的每个服务器可以是一台物理服务器,或者可以是由若干台物理服务器组成的物理服务器集群,又或者可以是一个云计算中心。Each of the business server 01, the transaction server 02, and the database server on which the business database 03 is deployed can be a physical server, or a physical server cluster composed of several physical servers, or a cloud computing center.
可选的,该多个业务服务器01、该事务服务器02以及部署业务数据库03的数据库服务器中的任意两个服务器均可以为相互独立的物理服务器。即事务服务器02、各个业务客户端011和各个业务数据库03之间均物理隔离,由此可以确保该事务服务器02、每个业务客户端011以及每个业务数据库03的运行性能。Optionally, any two of the multiple service servers 01, the transaction server 02, and the database server where the service database 03 is deployed may be independent physical servers. That is, the transaction server 02, each service client 011, and each service database 03 are physically isolated, thereby ensuring the operational performance of the transaction server 02, each service client 011, and each service database 03.
或者,该多个业务服务器01、该事务服务器02以及部署业务数据库03的数据库服务器中的至少两个服务器可以部署在同一个物理服务器中。例如,多个业务服务器01可以部署在同一个物理服务器中。Alternatively, at least two of the multiple service servers 01, the transaction server 02, and the database server where the service database 03 is deployed may be deployed in the same physical server. For example, multiple service servers 01 can be deployed in the same physical server.
该分布式事务处理系统中的多个业务服务器01可以参与实现同一个分布式事务(也可以称为全局事务),其中每个业务服务器01可以实现该分布式事务中的一个事务分支(针对该业务服务器01而言,也可以称为该业务服务器01的本地事务)。事务服务器02则负责协调整个分布式事务的处理过程,例如,可以处理分布式事务的发起、事务分支的创建、分布式事务的提交或回滚、以及分布式事务的超时检查等工作。 Multiple business servers 01 in the distributed transaction processing system can participate in implementing the same distributed transaction (also called a global transaction), and each business server 01 can implement a transaction branch in the distributed transaction (for this For the business server 01, it can also be referred to as the local transaction of the business server 01). The transaction server 02 is responsible for coordinating the processing of the entire distributed transaction. For example, it can handle the initiation of distributed transactions, the creation of transaction branches, the commit or rollback of distributed transactions, and the timeout check of distributed transactions.
可选的,图2是本申请实施例提供的另一种分布式事务处理系统的结构示意图,如图2所示,该系统可以包括用于实现分布式事务的第一业务服务器01a,以及至少一个第二业务服务器01b。图2中仅示意性示出了一个第二业务服务器01b。其中,该第一业务服务器01a可以为用于启动该分布式事务的业务服务器,因此也可以称为主业务服务器。每个第二业务服务器01b作为该分布式事务的参与者之一,也可以称为从业务服务器。并且,参考图2可以看出,该第一业务服务器01a中第一业务客户端011a的业务数据可以存储在第一业务数据库03a中,第二业务服务器01b中第二业务客户端011b的业务数据可以存储在第二业务数据库03b中。Optionally, FIG. 2 is a schematic structural diagram of another distributed transaction processing system provided by an embodiment of the present application. As shown in FIG. 2, the system may include a first service server 01a for implementing distributed transactions, and at least A second service server 01b. Only one second service server 01b is schematically shown in FIG. 2. Wherein, the first service server 01a may be a service server used to initiate the distributed transaction, and therefore may also be referred to as a main service server. As one of the participants of the distributed transaction, each second service server 01b can also be referred to as a slave service server. And, referring to FIG. 2, it can be seen that the business data of the first business client 011a in the first business server 01a can be stored in the first business database 03a, and the business data of the second business client 011b in the second business server 01b It can be stored in the second service database 03b.
在本申请实施例中,每个业务服务器01可以通过对其对应的业务数据库03中的业务数据执行一次或多次操作,来实现一个事务分支。该事务分支可以是分布式事务的一个事务分支,也可以不是分布式事务的分支,即该事务分支也可以不参与分布式事务。其中,对业务数据库03中的业务数据每执行一次操作,业务服务器01中的业务客户端011均需生成一条数据库操作语句,并在业务数据库03中执行该数据库操作语句。当业务数据库03接收到业务客户端011发送的提交指令后,才会基于数据库操作语句的执行结果持久化更新其业务数据,即执行提交操作。In the embodiment of the present application, each business server 01 can implement one transaction branch by performing one or more operations on the business data in its corresponding business database 03. The transaction branch may be a transaction branch of a distributed transaction, or may not be a branch of a distributed transaction, that is, the transaction branch may not participate in a distributed transaction. Among them, every time an operation is performed on the business data in the business database 03, the business client 011 in the business server 01 needs to generate a database operation statement, and execute the database operation statement in the business database 03. After the business database 03 receives the commit instruction sent by the business client 011, it will persistently update its business data based on the execution result of the database operation statement, that is, execute the commit operation.
因此,若一个事务分支仅包含一次针对业务数据库03的操作,则业务服务器01中的业务 客户端011为了实现该事务分支,仅需生成并执行一条数据库操作语句,该数据库操作语句执行完成即可提交该事务分支。若一个事务分支包含多次针对业务数据库的操作,则业务服务器01中的业务客户端011为了实现该事务分支,需生成并执行多个数据库操作语句,该多个数据库操作语句均执行完成才可以提交该事务分支。Therefore, if a transaction branch contains only one operation for the business database 03, the business client 011 in the business server 01 only needs to generate and execute a database operation statement in order to implement the transaction branch, and the database operation statement can be executed. Commit the transaction branch. If a transaction branch contains multiple operations on the business database, the business client 011 in the business server 01 needs to generate and execute multiple database operation statements in order to implement the transaction branch, and the multiple database operation statements must be executed before they are completed. Commit the transaction branch.
基于此,本申请实施例提供的每个业务服务器01中的业务客户端011,若确定用于实现其待执行的事务分支的数据库操作语句的个数等于1,则可以将其对应的业务数据库03的自动提交功能设置为开启状态,即业务数据库03可以自动提交事务分支。若业务客户端011确定用于实现其待执行的事务分支的数据库操作语句的个数大于1,则可以将其对应的业务数据库03的自动提交功能设置为关闭状态,即业务数据库03需要在接收到业务客户端011发送的提交指令后,才可以提交事务分支。Based on this, the business client 011 in each business server 01 provided in the embodiment of the present application, if it is determined that the number of database operation statements used to implement the transaction branch to be executed is equal to 1, the corresponding business database The auto-commit function of 03 is set to the on state, that is, the business database 03 can automatically commit the transaction branch. If the business client 011 determines that the number of database operation statements used to implement the transaction branch to be executed is greater than 1, then the automatic submission function of its corresponding business database 03 can be set to the off state, that is, the business database 03 needs to receive After the commit instruction sent by the business client 011, the transaction branch can be committed.
图3是本申请实施例提供的一种分布式事务的处理方法的流程图,该方法可以应用于如图1或图2所示的系统中。本申请实施例以该方法应用于如图2所示的系统,且以该第一业务客户端待执行的事务分支中仅包含一次针对数据库的操作为例进行说明。参考图3,该方法可以包括:FIG. 3 is a flowchart of a distributed transaction processing method provided by an embodiment of the present application. The method can be applied to the system shown in FIG. 1 or FIG. 2. In the embodiment of the present application, the method is applied to the system shown in FIG. 2 and the transaction branch to be executed by the first business client includes only one operation on the database as an example for description. Referring to Figure 3, the method may include:
步骤101、第一业务客户端向事务服务器发送分布式事务的创建请求。Step 101: The first business client sends a creation request of a distributed transaction to the transaction server.
第一业务客户端在接收到业务请求后,若确定该业务请求所请求的服务需要通过该第一业务客户端以及至少一个第二业务客户端共同参与实现,则可以响应于该业务请求,向事务服务器发送分布式事务的创建请求。After the first service client receives the service request, if it is determined that the service requested by the service request needs to be realized through the joint participation of the first service client and at least one second service client, it may respond to the service request and send The transaction server sends a request to create a distributed transaction.
示例的,假设该第一业务客户端为A银行的业务客户端,该业务请求为从A银行的第一账户向B银行的第二账户进行转账的转账请求。由于该转账请求所请求的转账服务需要该A银行的业务客户端以及B银行的业务客户端共同参与实现,因此A银行的业务客户端可以响应于该业务请求,向事务服务器发送分布式事务的创建请求。For example, suppose that the first business client is a business client of Bank A, and the business request is a transfer request for transferring money from the first account of Bank A to the second account of Bank B. Since the transfer service requested by the transfer request requires the business client of Bank A and the business client of Bank B to participate in the implementation, the business client of Bank A can respond to the business request by sending distributed transaction information to the transaction server. Create a request.
步骤102、事务服务器向第一业务客户端发送该分布式事务的标识。Step 102: The transaction server sends the identification of the distributed transaction to the first service client.
事务服务器接收到分布式事务的创建请求后,可以为该分布式事务分配标识(identification,ID),并将该分布式事务的标识发送至第一业务客户端。After the transaction server receives the creation request of the distributed transaction, it can assign an identification (identification, ID) to the distributed transaction, and send the identification of the distributed transaction to the first service client.
可选的,如图2所示,该第一业务客户端011a中可以部署有应用程序接口(application programming interface,API)模块0111,该API模块0111包括启动事务(Begin Transaction)API。第一业务客户端011a可以通过调用该Begin Transaction API来向事务服务器02发送分布式事务的创建请求R1,以获取该分布式事务的ID,进而构建该分布式事务的上下文。该Begin Transaction API的输入参数可以包括该事务服务器02的地址,返回值可以包括该分布式事务的ID。若由于事务服务器02故障等因素导致分配ID失败,则该返回值可以为-1。其中,事务服务器02的地址为第一业务客户端011a本地存储的,且该事务服务器02的地址可以包括该事务服务器的互联网协议(Internet protocol,IP)地址和端口号。该Begin Transaction API的输入参数的数据类型可以为字符串型(string),返回值的数据类型可以为长整型(long)。Optionally, as shown in FIG. 2, an application programming interface (application programming interface, API) module 0111 may be deployed in the first service client 011a, and the API module 0111 includes a Begin Transaction (Begin Transaction) API. The first service client 011a may send a distributed transaction creation request R1 to the transaction server 02 by calling the Begin Transaction API to obtain the ID of the distributed transaction, and then construct the context of the distributed transaction. The input parameter of the Begin Transaction API may include the address of the transaction server 02, and the return value may include the ID of the distributed transaction. If the ID allocation fails due to factors such as the failure of the transaction server 02, the return value can be -1. The address of the transaction server 02 is stored locally by the first business client 011a, and the address of the transaction server 02 may include the Internet protocol (IP) address and port number of the transaction server. The data type of the input parameter of the Begin Transaction API can be string, and the data type of the return value can be long.
参考图2还可以看出,第一业务客户端011a还包括通信模块0112,该API模块0111发送的分布式事务的创建请求R1可以通过该通信模块0112发送至第一网络代理节点012a,然后再由该第一网络代理节点012a透传至事务服务器02。相应的,该事务服务器02返回的分布式事务的ID也可以由该第一网络代理节点012a透传至第一业务客户端011a的通信模块0112,然后再由通信模块0112传输至API模块0111。It can also be seen with reference to FIG. 2 that the first service client 011a also includes a communication module 0112. The creation request R1 of a distributed transaction sent by the API module 0111 can be sent to the first network agent node 012a through the communication module 0112, and then The first network agent node 012a transparently transmits to the transaction server 02. Correspondingly, the distributed transaction ID returned by the transaction server 02 can also be transparently transmitted by the first network agent node 012a to the communication module 0112 of the first service client 011a, and then transmitted by the communication module 0112 to the API module 0111.
步骤103、第一业务客户端生成用于实现该分布式事务中待执行的事务分支的一个数据库 操作语句。Step 103: The first business client generates a database operation statement for implementing the transaction branch to be executed in the distributed transaction.
第一业务客户端接收到分布式事务的ID后,即可根据该业务请求,确定分布式事务中第一业务客户端待执行的事务分支,并生成用于实现该分布式事务中待执行的事务分支的一个数据库操作语句。其中,该第一业务客户端对应的第一业务数据库可以为关系型数据库,该数据库操作语句可以为结构化查询语言(structured query language,SQL)语句。After the first business client receives the ID of the distributed transaction, it can determine the transaction branch to be executed by the first business client in the distributed transaction according to the business request, and generate the transaction branch to be executed in the distributed transaction. A database operation statement of the transaction branch. The first business database corresponding to the first business client may be a relational database, and the database operation statement may be a structured query language (SQL) statement.
参考图2还可以看出,第一业务客户端011a还包括处理模块0115,该处理模块0115可以生成用于实现该分布式事务中待执行的事务分支的一个数据库操作语句。It can also be seen with reference to FIG. 2 that the first business client 011a further includes a processing module 0115, which can generate a database operation statement for implementing the transaction branch to be executed in the distributed transaction.
示例的,假设该业务请求为从A银行的第一账户向B银行的第二账户转账1000元的转账请求,则该A银行的业务客户端可以确定其待执行的事务分支为:将第一账户的余额扣款1000元。相应的,该A银行的业务客户端可以生成用于指示将第一账户的余额减少1000的数据库操作语句。For example, suppose the service request is a transfer request of 1000 yuan from the first account of Bank A to the second account of Bank B, then the business client of Bank A can determine that the branch of the transaction to be executed is: 1,000 yuan will be deducted from the balance of the account. Correspondingly, the business client of the bank A can generate a database operation statement for instructing to reduce the balance of the first account by 1000.
步骤104、第一业务客户端向第一业务数据库发送第一设置指令。Step 104: The first service client sends a first setting instruction to the first service database.
由于用于实现该事务分支的数据库操作语句的个数等于1,因此第一业务客户端可以确定该数据库操作语句执行完成后即可提交该事务分支,进而可以向第一业务数据库发送第一设置指令,该第一设置指令用于指示将该第一业务数据库的自动提交功能设置为开启状态。Since the number of database operation statements used to implement the transaction branch is equal to 1, the first business client can determine that the database operation statement is executed and can submit the transaction branch, and then can send the first setting to the first business database Instruction, the first setting instruction is used to instruct to set the automatic submission function of the first service database to an on state.
示例的,参考图2,该第一业务客户端011a还包括数据库驱动器(DB driver)0113。该处理模块0115可以在检测到数据库操作语句的个数等于1时,指示该数据库驱动器0113通过通信模块0112向第一业务数据库03发送第一设置指令。For example, referring to FIG. 2, the first service client 011a further includes a database driver (DB driver) 0113. The processing module 0115 can instruct the database driver 0113 to send the first setting instruction to the first service database 03 through the communication module 0112 when detecting that the number of database operation sentences is equal to 1.
步骤105、第一网络代理节点获取该第一设置指令,并记录第一业务数据库的自动提交功能为开启状态。Step 105: The first network agent node obtains the first setting instruction, and records that the automatic submission function of the first service database is turned on.
由于第一业务客户端发送至第一业务数据库的第一设置指令需要通过第一网络代理节点转发,因此第一网络代理节点可以获取到该第一设置指令,并可以根据该第一设置指令记录第一业务数据库的自动提交功能为开启状态。并且,第一网络代理节点可以在完成状态记录后,再将该第一设置指令转发至该第一业务数据库。Since the first setting instruction sent by the first service client to the first service database needs to be forwarded by the first network proxy node, the first network proxy node can obtain the first setting instruction and record it according to the first setting instruction The automatic submission function of the first business database is turned on. In addition, the first network agent node may forward the first setting instruction to the first service database after completing the status recording.
第一网络代理节点通过记录该第一业务数据库的自动提交功能的状态,可以确保在后续创建事务分支时,能够根据记录的状态准确地确定该第一业务数据库的自动提交功能是否开启。进而,该第一网络代理节点可以根据该自动提交功能的状态确定用于实现事务分支的数据库操作语句的个数是否大于1,并可以根据数据库操作语句的个数的不同,采用不同的方式获取该事务分支的锁信息,并创建该事务分支。By recording the status of the automatic submission function of the first service database, the first network agent node can ensure that when a transaction branch is subsequently created, it can accurately determine whether the automatic submission function of the first service database is enabled according to the recorded status. Furthermore, the first network agent node can determine whether the number of database operation statements used to implement transaction branching is greater than 1 according to the state of the automatic submission function, and can obtain it in different ways according to the number of database operation statements. The lock information of the transaction branch, and the transaction branch is created.
示例的,第一网络代理节点中可以记录有第一业务数据库的状态标识,第一网络代理节点可以在获取到该第一设置指令后,将该状态标识设置为true,以指示该第一业务数据库的自动提交功能为开启状态。For example, the first network agent node may record the status identifier of the first service database, and the first network agent node may set the status identifier to true after obtaining the first setting instruction to indicate the first service The automatic submission function of the database is turned on.
在本申请实施例中,如图2所示,该第一网络代理节点012a可以包括连接管理模块0121,解析模块0122以及透传模块0123。该连接管理模块0121可以拦截第一业务客户端011a发送的每个数据包,并检测每个数据包的接收方是否为该第一业务数据库03a。若数据包的接收方为该第一业务数据库03a,则连接管理模块0121可以将该数据包发送至解析模块0122,解析模块0122可以解析该数据包。若该数据包的接收方不为该第一业务数据库03a,则连接管理模块0121可以将该数据包发送至透传模块0123,透传模块0123可以直接透传该数据包。其中,透传是指将数据包直接传输到目的地址,而不解析数据包的内容,也不对数据包的内容做任何改变。In the embodiment of the present application, as shown in FIG. 2, the first network agent node 012a may include a connection management module 0121, a parsing module 0122, and a transparent transmission module 0123. The connection management module 0121 can intercept each data packet sent by the first service client 011a, and detect whether the recipient of each data packet is the first service database 03a. If the recipient of the data packet is the first service database 03a, the connection management module 0121 can send the data packet to the parsing module 0122, and the parsing module 0122 can parse the data packet. If the recipient of the data packet is not the first service database 03a, the connection management module 0121 can send the data packet to the transparent transmission module 0123, and the transparent transmission module 0123 can directly transparently transmit the data packet. Among them, transparent transmission means that the data packet is directly transmitted to the destination address without analyzing the content of the data packet or making any changes to the content of the data packet.
以图2为例,假设第一网络代理节点012a接收到第一业务客户端011a发送的分布式事务的 创建请求R1,则由于该分布式事务的创建请求R1的接收方为事务服务器02,而并非是第一业务数据库03a,因此第一网络代理节点012a的透传模块0123可以直接向事务服务器02透传该分布式事务的创建请求R1。Taking Figure 2 as an example, suppose that the first network proxy node 012a receives the distributed transaction creation request R1 sent by the first service client 011a, then since the recipient of the distributed transaction creation request R1 is the transaction server 02, and It is not the first service database 03a, so the transparent transmission module 0123 of the first network agent node 012a can directly transparently transmit the creation request R1 of the distributed transaction to the transaction server 02.
步骤106、第一业务客户端基于该一个数据库操作语句和该分布式事务的上下文生成一个数据库操作指令。Step 106: The first business client generates a database operation instruction based on the database operation statement and the context of the distributed transaction.
在本申请实施例中,第一业务客户端可以将分布式事务的上下文与该数据库操作语句组合,从而生成一个数据库操作指令。该分布式事务的上下文包括该分布式事务的标识。并且,还可以包括该事务服务器的地址,该事务服务器的地址是第一业务客户端中预先存储的。In the embodiment of the present application, the first business client may combine the context of the distributed transaction with the database operation statement to generate a database operation instruction. The context of the distributed transaction includes the identification of the distributed transaction. In addition, the address of the transaction server may also be included, and the address of the transaction server is pre-stored in the first service client.
由于该数据库操作指令中携带有分布式事务的上下文,使得第一网络代理节点可以基于该数据库操作指令来创建和处理事务分支。由于无需第一业务客户端创建和处理事务分支,因此对第一业务客户端原有业务逻辑的影响较小,从而有效降低了第一业务客户端应用于分布式事务处理系统的开发成本。Since the database operation instruction carries the context of distributed transactions, the first network agent node can create and process transaction branches based on the database operation instruction. Since there is no need for the first business client to create and process transaction branches, the impact on the original business logic of the first business client is small, thereby effectively reducing the development cost of the first business client applied to the distributed transaction processing system.
可选的,第一业务客户端可以根据该第一业务数据库的数据库类型(DB type)所对应的语法格式,将分布式事务的上下文作为注释(hint)添加在该数据库操作语句中,从而得到一个数据库操作指令。例如,参考图2,该第一业务客户端011a的API模块0111还包括操作指令创建API,第一业务客户端011a可以通过调用该操作指令创建API生成数据库操作指令L1。其中,该操作指令创建API的输入参数可以包括:数据库操作语句、数据库类型以及分布式事务的上下文,该数据库操作语句的数据类型和数据库类型的数据类型可以均为string,该分布式事务的上下文的数据类型可以为long。该操作指令创建API的返回值即为携带有分布式事务的上下文的数据库操作指令。若操作指令创建API执行失败,则返回值为空。该返回值的数据类型可以为string。Optionally, the first business client may add the context of the distributed transaction as a hint to the database operation statement according to the syntax format corresponding to the database type (DB type) of the first business database, thereby obtaining A database operation instruction. For example, referring to FIG. 2, the API module 0111 of the first business client 011a further includes an operation instruction creation API, and the first business client 011a can generate a database operation instruction L1 by calling the operation instruction creation API. Among them, the input parameters of the operation instruction creation API may include: database operation statement, database type, and context of distributed transaction. The data type of the database operation statement and the data type of the database type may both be string, and the context of the distributed transaction The data type can be long. The return value of the operation instruction creation API is the database operation instruction carrying the context of the distributed transaction. If the operation instruction creation API fails to execute, the return value is empty. The data type of the return value can be string.
并且,为了便于该第一网络代理节点识别该数据库操作指令中的分布式事务的上下文,第一业务客户端还可以在数据库操作指令中添加分布式事务关键字,该分布式事务关键字可以用于指示该数据库操作指令中添加有分布式事务的上下文。In addition, in order to facilitate the first network agent node to recognize the context of the distributed transaction in the database operation instruction, the first business client may also add a distributed transaction keyword to the database operation instruction, and the distributed transaction keyword can be used The context of distributed transaction is added to the instruction to indicate the database operation.
示例的,假设该分布式事务关键字为AA,该分布式事务的标识为ID1,事务服务器的IP地址为x.x.x.x,并且该用于指示将第一账户“yy”的余额减少1000的数据库操作语句为SQL语句:For example, suppose the distributed transaction keyword is AA, the identifier of the distributed transaction is ID1, the IP address of the transaction server is xxxx, and the database operation statement used to indicate that the balance of the first account "yy" is reduced by 1000 For the SQL statement:
UPDATE table1 SET a1=a1-1000 WHERE b1='yy';UPDATE table1 SET a1=a1-1000 WHERE b1='yy';
则第一业务客户端通过操作指令创建API对该SQL语句和分布式事务的上下文进行组合后,生成的数据库操作指令可以为:Then, after the first business client combines the SQL statement and the context of the distributed transaction through the operation instruction creation API, the generated database operation instruction can be:
/*AA;ID:ID1;IP:x.x.x.x*/UPDATE table1 SET a1=a1-1000 WHERE b1='yy'。/*AA; ID: ID1; IP: x.x.x.x*/UPDATE table1 SET a1=a1-1000 WHERE b1='yy'.
步骤107、第一业务客户端向第一业务数据库发送该数据库操作指令。Step 107: The first service client sends the database operation instruction to the first service database.
第一业务客户端生成该数据库操作指令后,即可向第一业务数据库发送该数据库操作指令。After the first business client generates the database operation instruction, it can send the database operation instruction to the first business database.
可选的,参考图2,该第一业务客户端011a中的数据库驱动器0113可以将API模块0111生成的数据库操作指令L1发送至第一业务数据库03a。由于第一网络代理节点012a可以拦截第一业务客户端011a发送的数据包,因此如图2所示,该第一网络代理节点012a可以获取到该第一业务客户端011a发送的数据库操作指令L1。该数据库操作指令L1可以用于供获取到该数据库操作指令的第一网络代理节点创建并处理该事务分支。Optionally, referring to FIG. 2, the database driver 0113 in the first service client 011a may send the database operation instruction L1 generated by the API module 0111 to the first service database 03a. Since the first network agent node 012a can intercept the data packet sent by the first service client 011a, as shown in FIG. 2, the first network agent node 012a can obtain the database operation instruction L1 sent by the first service client 011a . The database operation instruction L1 can be used for the first network agent node that has obtained the database operation instruction to create and process the transaction branch.
步骤108、第一业务客户端向第二业务客户端发送服务调用请求。Step 108: The first business client sends a service invocation request to the second business client.
由于该分布式事务还需要第二业务服务器中的第二业务客户端参与实现,因此第一业务 客户端还需要向该第二业务客户端发送服务调用请求。该服务调用请求中可以携带有该分布式事务的上下文。其中,该服务调用请求可以为远程过程调用(remote procedure call,RPC)请求。Since the distributed transaction also requires the second service client in the second service server to participate in the implementation, the first service client also needs to send a service invocation request to the second service client. The service call request may carry the context of the distributed transaction. Wherein, the service call request may be a remote procedure call (remote procedure call, RPC) request.
示例的,参考图2,第一业务客户端011a还包括服务调用模块0114,该服务调用模块0114可以向第二业务客户端011b发送服务调用请求Q1,该服务调用请求Q1可以通过第一网络代理节点012a以及第二网络代理节点012b透传至第二业务客户端011b。其中,第一网络代理节点012a在拦截到该服务调用请求Q1后,可以识别出该服务调用请求Q1的接收方不为该第一业务数据库03a,因此第一网络代理节点012a可以直接向第二业务客户端011b转发该数据包。For example, referring to FIG. 2, the first business client 011a further includes a service invocation module 0114. The service invocation module 0114 can send a service invocation request Q1 to the second business client 011b, and the service invocation request Q1 can be proxied through the first network agent. The node 012a and the second network agent node 012b transparently transmit to the second service client 011b. Wherein, after intercepting the service call request Q1, the first network agent node 012a can recognize that the recipient of the service call request Q1 is not the first service database 03a, so the first network agent node 012a can directly send the second The service client 011b forwards the data packet.
假设该第一业务客户端011a接收到的业务请求为从A银行的第一账户向B银行的第二账户转账1000元的转账请求,则该A银行的业务客户端可以向B银行的业务客户端发送用于指示将该第二账户的余额增加1000的服务调用请求。Assuming that the business request received by the first business client 011a is a transfer request of 1000 yuan from the first account of Bank A to the second account of Bank B, then the business client of Bank A can send the business client of Bank B to the business customer of Bank B. The terminal sends a service call request for instructing to increase the balance of the second account by 1000.
步骤109、第一网络代理节点获取该数据库操作指令,并从第一业务数据库中获取该数据库操作语句所针对的数据集。Step 109: The first network agent node obtains the database operation instruction, and obtains the data set targeted by the database operation statement from the first service database.
由于该数据库操作指令的接收方为第一业务数据库,因此第一网络代理节点可以获取该数据库操作指令,并从第一业务数据库中获取该数据库操作语句所针对的数据集。可选的,第一网络代理节点可以从该数据库操作指令中解析出数据库操作语句,然后创建并运行数据集获取语句,从而可以从第一业务数据库中获取到该数据库操作语句所针对的数据集。Since the receiver of the database operation instruction is the first service database, the first network agent node can obtain the database operation instruction and obtain the data set targeted by the database operation statement from the first service database. Optionally, the first network agent node can parse out the database operation statement from the database operation instruction, and then create and run the data set acquisition statement, so that the data set targeted by the database operation statement can be obtained from the first business database .
示例的,如图2所示,该第一网络代理节点012a还包括事务分支处理模块0124以及数据库驱动器0125。该解析模块0122可以从数据库操作指令中解析出数据库操作语句(例如SQL语句)和分布式事务的上下文,并将数据库操作语句和分布式事务的上下文发送至事务分支处理模块0124。该事务分支处理模块0124可以创建数据集获取语句。例如,该事务分支处理模块0124创建的数据集获取语句可以为:Select for update。之后,事务分支处理模块0124可以通过数据库驱动器0125运行该数据集获取语句:Select for update,从而得到该数据库操作语句所针对的数据集。For example, as shown in FIG. 2, the first network agent node 012a further includes a transaction branch processing module 0124 and a database driver 0125. The parsing module 0122 can parse out database operation statements (such as SQL statements) and the context of distributed transactions from the database operation instructions, and send the database operation statements and the context of distributed transactions to the transaction branch processing module 0124. The transaction branch processing module 0124 can create a data set acquisition statement. For example, the data set acquisition statement created by the transaction branch processing module 0124 may be: Select for update. After that, the transaction branch processing module 0124 can run the data set acquisition statement: Select for update through the database driver 0125, so as to obtain the data set targeted by the database operation statement.
可选的,在本申请实施例中,第一网络代理节点在获取到该第一业务客户端发送的数据库操作指令后,还可以先检测该数据库操作指令中是否携带有分布式事务的上下文。若该数据库操作指令中携带有该分布式事务的上下文,则可以获取该数据库操作语句所针对的数据集并继续执行后续操作。Optionally, in the embodiment of the present application, after obtaining the database operation instruction sent by the first service client, the first network agent node may also first detect whether the database operation instruction carries the context of distributed transactions. If the database operation instruction carries the context of the distributed transaction, the data set targeted by the database operation statement can be obtained and subsequent operations can be continued.
若该数据库操作指令中并未携带分布式事务的上下文,则第一网络代理节点可以确定该数据库操作指令中的数据库操作语句并非用于实现分布式事务中的事务分支,因此可以直接向第一业务数据库透传该数据库操作指令,而无需获取该数据集,也无需再执行后续操作。If the database operation instruction does not carry the context of the distributed transaction, the first network agent node can determine that the database operation statement in the database operation instruction is not used to implement the transaction branch in the distributed transaction, so it can directly send to the first The business database transparently transmits the database operation instructions without obtaining the data set and performing subsequent operations.
步骤110、第一网络代理节点获取该数据集的锁信息。Step 110: The first network agent node obtains the lock information of the data set.
由于在上述步骤105中,第一网络代理节点已经根据第一设置指令确定该第一业务数据库的自动提交功能为开启状态,因此可以确定该数据库操作指令中的数据库操作语句可独立实现一个事务分支。进而,该第一网络代理节点可以获取该数据库操作语句所针对的数据集的锁信息,该数据集的锁信息即为该事务分支的锁信息。例如,参考图2,第一网络代理节点012a中的事务分支处理模块0124可以获取该数据库操作语句所针对的数据集的锁信息。Since in step 105, the first network agent node has determined that the automatic submission function of the first service database is turned on according to the first setting instruction, it can be determined that the database operation statement in the database operation instruction can independently implement a transaction branch. . Furthermore, the first network agent node can obtain the lock information of the data set targeted by the database operation statement, and the lock information of the data set is the lock information of the transaction branch. For example, referring to FIG. 2, the transaction branch processing module 0124 in the first network agent node 012a can obtain the lock information of the data set targeted by the database operation statement.
其中,该数据库操作语句所针对的数据集可以是指该数据库操作语句所操作的数据的集合。该数据集的锁信息可以用于在第一业务数据库中唯一标识该数据库操作语句所针对的数据集。例如,该数据集的锁信息可以包括该数据集所在数据表的表名,以及该数据集所在行的主键。Wherein, the data set targeted by the database operation statement may refer to a collection of data operated by the database operation statement. The lock information of the data set can be used to uniquely identify the data set targeted by the database operation statement in the first business database. For example, the lock information of the data set may include the table name of the data table where the data set is located, and the primary key of the row where the data set is located.
步骤111、第一网络代理节点向该事务服务器发送事务分支创建请求。Step 111: The first network agent node sends a transaction branch creation request to the transaction server.
第一网络代理节点获取到数据集的锁信息,即事务分支的锁信息后,即可向事务服务器发送事务分支创建请求。该事务分支创建请求中可以包括该数据集的锁信息以及该分布式事务的标识。例如,参考图2,第一网络代理节点012a中的事务分支处理模块0124可以向事务服务器02发送事务分支创建请求S1。After the first network agent node obtains the lock information of the data set, that is, the lock information of the transaction branch, it can send a transaction branch creation request to the transaction server. The transaction branch creation request may include the lock information of the data set and the identification of the distributed transaction. For example, referring to FIG. 2, the transaction branch processing module 0124 in the first network agent node 012a may send a transaction branch creation request S1 to the transaction server 02.
在本申请实施例中,对于该第一业务数据库的自动提交功能为开启状态,且第一业务客户端待执行的事务分支参与了分布式事务的场景。由于第一网络代理节点除了需要在第一业务数据库中执行数据库操作语句,还需要执行获取数据集,获取数据集的锁信息,以及请求创建事务分支等操作,且上述操作均执行成功后才能提交事务分支。因此,第一网络代理节点在向事务服务器申请创建分布式事务的事务分支之前,还需要向该第一业务数据库发送第二设置指令,该第二设置指令用于指示该第一业务数据库将其自动提交功能设置为关闭状态。由此,可以确保该第一业务数据库不会在数据库操作语句执行完成后自动提交事务分支,而是能够在该第一网络代理节点确定该事务分支创建成功后,再在该第一网络代理节点的指示下提交该事务分支。其中,该第二设置指令可以是事务分支处理模块0124通过数据库驱动器0125发送至第一业务数据库03a的。In the embodiment of the present application, the automatic submission function for the first service database is turned on, and the transaction branch to be executed by the first service client participates in a distributed transaction scenario. Since the first network agent node needs to execute database operation statements in the first business database, it also needs to perform operations such as obtaining data sets, obtaining lock information of the data sets, and requesting to create a transaction branch, and the above operations can be submitted only after successful execution Transaction branch. Therefore, before the first network agent node applies to the transaction server to create a transaction branch of a distributed transaction, it also needs to send a second setting instruction to the first service database. The second setting instruction is used to instruct the first service database to The automatic submission function is set to off. As a result, it can be ensured that the first service database will not automatically submit the transaction branch after the execution of the database operation statement is completed, but can be used in the first network agent node after the first network agent node determines that the transaction branch is successfully created. Commit the transaction branch under the instructions of. Wherein, the second setting instruction may be sent by the transaction branch processing module 0124 to the first service database 03a through the database driver 0125.
步骤112、事务服务器向第一网络代理节点发送创建响应。Step 112: The transaction server sends a creation response to the first network agent node.
事务服务器接收到该事务分支的创建请求后,可以基于该数据集的锁信息检测是否能够创建该事务分支。After receiving the transaction branch creation request, the transaction server can detect whether the transaction branch can be created based on the lock information of the data set.
若事务服务器检测到该创建请求中数据集的锁信息与其所存储的其他事务分支的锁信息均不同,则可以确定用于实现该事务分支的数据库操作语句所针对的数据集未被加锁,因此可以确定能够创建该事务分支。该事务服务器进而可以为该事务分支分配标识,并向第一网络代理节点发送用于指示该事务分支创建成功的第一创建响应,该第一创建响应携带该事务分支的标识。并且,事务服务器还可以存储该创建请求中的数据集的锁信息,即为该数据库操作语句所针对的数据集进行加锁。If the transaction server detects that the lock information of the data set in the creation request is different from the lock information of other transaction branches stored in it, it can determine that the data set targeted by the database operation statement used to implement the transaction branch is not locked. Therefore, it can be determined that the transaction branch can be created. The transaction server may then assign an identifier to the transaction branch, and send a first creation response indicating that the transaction branch is successfully created to the first network agent node, and the first creation response carries the identifier of the transaction branch. In addition, the transaction server may also store the lock information of the data set in the creation request, that is, lock the data set targeted by the database operation statement.
若事务服务器检测到该创建请求中的数据集的锁信息与其所存储的其他某个事务分支的锁信息相同,则可以确定用于实现该事务分支的数据库操作语句所针对的数据集已被加锁,因此可以确定无法创建该事务分支。该事务服务器进而可以向第一网络代理节点发送用于指示该事务分支创建失败的第二创建响应。If the transaction server detects that the lock information of the data set in the creation request is the same as the lock information of some other transaction branch stored in it, it can determine that the data set targeted by the database operation statement used to implement the transaction branch has been added Lock, so it can be determined that the transaction branch cannot be created. The transaction server may further send to the first network agent node a second creation response indicating that the creation of the transaction branch fails.
步骤113、第一网络代理节点检测事务分支是否创建成功。Step 113: The first network agent node detects whether the transaction branch is successfully created.
第一网络代理节点接收到事务服务器发送的创建响应后,即可根据该创建响应检测事务分支是否创建成功。若该第一网络代理节点接收到的创建响应为用于指示该事务分支创建失败的第二创建响应,则第一网络代理节点可以执行步骤114;若第一网络代理节点接收到的创建响应为用于指示该事务分支创建成功的第二创建响应,则第一网络代理节点可以执行步骤115。例如,第一网络代理节点011a中的事务分支处理模块0124可以根据接收到的创建响应,检测事务分支是否创建成功。After the first network agent node receives the creation response sent by the transaction server, it can detect whether the transaction branch is successfully created according to the creation response. If the creation response received by the first network proxy node is the second creation response used to indicate that the transaction branch creation failed, the first network proxy node can perform step 114; if the creation response received by the first network proxy node is If the second creation response is used to indicate that the transaction branch is successfully created, the first network agent node may execute step 115. For example, the transaction branch processing module 0124 in the first network agent node 011a may detect whether the transaction branch is successfully created according to the received creation response.
步骤114、第一网络代理节点向该第一业务数据库发送针对该事务分支的第一回滚指令。Step 114: The first network agent node sends a first rollback instruction for the transaction branch to the first service database.
若第一网络代理节点接收到了事务服务器发送的第二创建响应,则可以确定该事务分支创建失败,进而可以向第一业务数据库发送针对该事务分支的第一回滚指令。第一业务数据库可以响应于该第一回滚指令,执行回滚操作。示例的,第一业务数据库可以响应于该第一回滚指令,将其自动提交功能恢复至开启状态。If the first network agent node receives the second creation response sent by the transaction server, it can be determined that the transaction branch has failed to be created, and then the first rollback instruction for the transaction branch can be sent to the first service database. The first service database may perform a rollback operation in response to the first rollback instruction. For example, the first service database may respond to the first rollback instruction to restore its automatic submission function to the on state.
例如,第一网络代理节点011a中的事务分支处理模块0124可以通过数据库驱动器0125向 第一业务数据库03a发送针对该事务分支的第一回滚指令。For example, the transaction branch processing module 0124 in the first network agent node 011a may send the first rollback instruction for the transaction branch to the first service database 03a through the database driver 0125.
步骤115、第一网络代理节点在该第一业务数据中执行该数据库操作语句。Step 115: The first network agent node executes the database operation statement in the first service data.
若第一网络代理节点接收到了事务服务器发送的第一创建响应,则可以确定该事务分支创建成功,进而可以在该第一业务数据中执行该数据库操作语句。If the first network agent node receives the first creation response sent by the transaction server, it can be determined that the transaction branch is successfully created, and the database operation statement can be executed in the first service data.
例如,参考图2,第一网络代理节点012a中的事务分支处理模块0124可以通过数据库驱动器0125在该第一业务数据03a中执行SQL语句。For example, referring to FIG. 2, the transaction branch processing module 0124 in the first network agent node 012a can execute SQL statements in the first service data 03a through the database driver 0125.
步骤116、第一网络代理节点在该分布式事务的事务日志中存储该事务分支的标识以及该数据集的对应关系。Step 116: The first network agent node stores the identifier of the transaction branch and the corresponding relationship of the data set in the transaction log of the distributed transaction.
第一网络代理节点执行完成该数据库操作语句后,还可以在该分布式事务的事务日志中记录该事务分支的标识以及该数据库操作语句所针对的数据集的对应关系,以便后续需要回滚该事务分支时,可以基于该事务日志中记录的数据集执行回滚操作。其中,该事务日志可以为该第一业务数据库中创建的用于记录分布式事务的相关数据的日志表。例如,第一网络代理节点011a中的事务分支处理模块0124可以在该分布式事务的事务日志中对应存储该事务分支的标识以及该数据集。After the first network agent node executes and completes the database operation statement, it can also record the transaction branch identifier and the corresponding relationship of the data set targeted by the database operation statement in the transaction log of the distributed transaction, so that the subsequent need to roll back the database operation statement When a transaction is branched, a rollback operation can be performed based on the data set recorded in the transaction log. Wherein, the transaction log may be a log table created in the first business database for recording related data of distributed transactions. For example, the transaction branch processing module 0124 in the first network agent node 011a may correspondingly store the identifier of the transaction branch and the data set in the transaction log of the distributed transaction.
可选的,上述步骤115和步骤116也可以在步骤109之后且在步骤111之前执行,也即是,该第一网络代理节点也可以先执行数据库操作语句,然后再请求创建事务分支。相应的,在上述步骤114中,该第一业务数据库在执行回滚操作时,还需要将其业务数据回滚至执行该数据库操作语句之前的状态。由此可知,通过在确定事务分支创建成功之后再执行该数据库操作语句,可以避免在执行该数据库操作语句之后,若又确定该事务分支创建失败,导致之前执行的数据库操作语句无效的问题。也即是,在事务分支创建失败的场景中不再执行数据库操作语句,可以避免浪费第一业务服务器的计算资源。Optionally, the above steps 115 and 116 can also be performed after step 109 and before step 111, that is, the first network agent node can also execute the database operation statement first, and then request the creation of a transaction branch. Correspondingly, in the above step 114, when the first business database performs a rollback operation, it also needs to roll back its business data to the state before the database operation statement is executed. It can be seen that by executing the database operation statement after determining that the transaction branch is successfully created, it is possible to avoid the problem that the previously executed database operation statement is invalid if it is determined that the transaction branch creation fails after the database operation statement is executed. That is, in a scenario where the creation of a transaction branch fails, the database operation statement is no longer executed, which can avoid wasting the computing resources of the first business server.
步骤117、第一网络代理节点向该第一业务数据库发送针对该事务分支的第一提交指令。Step 117: The first network agent node sends a first commit instruction for the transaction branch to the first service database.
第一网络代理节点在确定事务分支创建成功,并将该事务分支的标识以及数据集对应记录至分布式事务的事务日志之后,即可向第一业务数据库发送针对该事务分支的第一提交指令,该第一提交指令用于指示第一业务数据库提交该事务分支。例如,第一网络代理节点011a中的事务分支处理模块0124可以通过数据库驱动器0125向第一业务数据库03a发送针对该事务分支的第一提交指令。After the first network agent node determines that the transaction branch is successfully created, and records the identifier of the transaction branch and the corresponding data set in the transaction log of the distributed transaction, the first network agent node can send the first commit instruction for the transaction branch to the first service database , The first commit instruction is used to instruct the first business database to commit the transaction branch. For example, the transaction branch processing module 0124 in the first network agent node 011a may send the first commit instruction for the transaction branch to the first service database 03a through the database driver 0125.
步骤118、第一网络代理节点向该第一业务客户端发送该事务分支的提交结果。Step 118: The first network proxy node sends the commit result of the transaction branch to the first service client.
第一网络代理节点向该第一业务数据库发送针对该事务分支的第一提交指令之后,还可以接收该第一业务数据库返回的提交响应。若第一业务数据库正常完成事务分支的提交,则该提交响应可以指示事务分支提交成功。相应的,第一网络代理节点可以向该第一业务客户端发送用于指示该事务分支提交成功的提交结果。若第一业务数据库由于故障等因素导致事务分支提交失败,则该提交响应可以指示事务分支提交失败。相应的,第一网络代理节点可以向该第一业务客户端发送用于指示该事务分支提交失败的提交结果。例如,第一网络代理节点011a中的事务分支处理模块0124可以向第一业务客户端011a发送该事务分支的提交结果。After sending the first commit instruction for the transaction branch to the first service database, the first network agent node may also receive the commit response returned by the first service database. If the first service database normally completes the commit of the transaction branch, the commit response may indicate that the commit of the transaction branch is successful. Correspondingly, the first network agent node may send to the first service client a submission result indicating that the transaction branch is successfully submitted. If the first service database fails to commit the transaction branch due to factors such as failure, the commit response may indicate that the transaction branch fails to commit. Correspondingly, the first network agent node may send to the first service client a submission result indicating that the transaction branch fails to be submitted. For example, the transaction branch processing module 0124 in the first network agent node 011a may send the commit result of the transaction branch to the first service client 011a.
可选的,第一网络代理节点在发送该第一提交指令之后,还可以删除其缓存的锁信息。并且,第一网络代理节点若确定该事务分支提交失败,则还可以向该第一业务数据库发送针对该事务分支的第四回滚指令,并向事务服务器发送携带有该事务分支的标识的通知消息。其中,该第四回滚指令可以用于指示该第一业务数据库执行回滚操作,该通知消息可以用于指示该事务服务器删除该事务分支的锁信息,即指示该事务服务器为该事务分支放锁。Optionally, after sending the first submission instruction, the first network proxy node may also delete its cached lock information. In addition, if the first network agent node determines that the transaction branch commit failed, it may also send a fourth rollback instruction for the transaction branch to the first service database, and send a notification carrying the transaction branch identifier to the transaction server information. Wherein, the fourth rollback instruction may be used to instruct the first business database to perform a rollback operation, and the notification message may be used to instruct the transaction server to delete the lock information of the transaction branch, that is, to instruct the transaction server to release the transaction branch for the transaction. Lock.
第一网络代理节点在向第一业务数据库发送完成该第一回滚指令,或者向第一业务客户 端发送该事务分支的提交结果之后,即可完成该分布式事务的第一阶段的操作。该第一阶段也可以称为请求阶段或者表决阶段。由于在实现分布式事务的第一阶段的操作的过程中,事务分支的创建和处理均可以由网络代理节点来实现,而业务客户端仅需要调用启动事务API和操作指令创建API,上述API的调用对业务客户端原有的业务逻辑的影响较小,因此可以有效降低业务客户端适配分布式事务处理架构的成本。The first network agent node can complete the first phase of the distributed transaction after sending the completion of the first rollback instruction to the first service database or sending the commit result of the transaction branch to the first service client. This first stage may also be referred to as the request stage or the voting stage. Because in the process of implementing the first phase of the distributed transaction operation, the creation and processing of transaction branches can be implemented by the network agent node, and the business client only needs to call the transaction start API and the operation instruction creation API. The call has little impact on the original business logic of the business client, so it can effectively reduce the cost of adapting the business client to the distributed transaction processing architecture.
步骤119、第二业务客户端向该第一业务客户端发送服务调用响应。Step 119: The second business client sends a service invocation response to the first business client.
在本申请实施例中,第二业务客户端在接收到第一业务客户端发送的携带有分布式事务的上下文的服务调用请求后,可以基于该服务调用请求确定该第二业务客户端待执行的事务分支,进而可以生成用于实现该事务分支的数据库操作语句。In the embodiment of the present application, after the second business client receives the service invocation request carrying the context of the distributed transaction sent by the first business client, it may determine that the second business client is to be executed based on the service invocation request The transaction branch can then be used to generate the database operation statement used to implement the transaction branch.
示例的,假设该第二业务客户端为B银行的业务客户端,且该B银行的业务客户端接收到的服务调用请求用于指示将该第二账户的余额增加1000,则该B银行的业务客户端可以生成用于指示该第二账户的余额增加1000的数据库操作语句。For example, suppose the second business client is the business client of Bank B, and the service call request received by the business client of Bank B is used to indicate that the balance of the second account is increased by 1000, then the balance of the B bank The business client may generate a database operation statement used to instruct the balance of the second account to increase by 1000.
参考图2可以看出,该第二业务客户端011b中也部署有API模块0111、通信模块0112、数据库驱动器0113、服务调用模块0114以及处理模块0115。该第二业务客户端011b的处理模块0115可以通过调用该API模块0111生成数据库操作指令L2,并通过数据库驱动器0113向第二业务数据库03b发送该数据库操作指令L2。如图2所示,该第二网络代理节点012b中的连接管理模块0121可以获取该数据库操作指令L2,解析模块0122可以解析该数据库操作指令L2。进而事务分支处理模块0124可以基于解析后的数据库操作指令L2,向事务服务器01发送事务分支创建请求S2,以创建并处理事务分支。该第二网络代理节点012b的事务分支处理模块0124处理完成事务分支后,可以向第二业务客户端011b返回事务分支的提交结果。It can be seen with reference to FIG. 2 that the API module 0111, the communication module 0112, the database driver 0113, the service invocation module 0114, and the processing module 0115 are also deployed in the second service client 011b. The processing module 0115 of the second business client 011b can generate a database operation instruction L2 by calling the API module 0111, and send the database operation instruction L2 to the second business database 03b through the database driver 0113. As shown in FIG. 2, the connection management module 0121 in the second network agent node 012b can obtain the database operation instruction L2, and the analysis module 0122 can parse the database operation instruction L2. Furthermore, the transaction branch processing module 0124 can send a transaction branch creation request S2 to the transaction server 01 based on the parsed database operation instruction L2 to create and process the transaction branch. After the transaction branch processing module 0124 of the second network agent node 012b completes the transaction branch, it can return the commit result of the transaction branch to the second service client 011b.
该第二业务客户端011b的处理模块0115若根据该提交结果确定该事务分支提交成功,则可以向第一业务客户端011a发送用于指示服务调用成功的服务调用响应。第二业务客户端011b的处理模块0115若根据该提交结果确定该事务分支提交失败,则可以向第一业务客户端011a发送用于指示服务调用失败的服务调用响应。该服务调用响应可以通过第二网络代理节点012b和第一网络代理节点012a透传至该第一业务客户端011a。If the processing module 0115 of the second business client 011b determines that the transaction branch is submitted successfully according to the submission result, it may send a service invocation response indicating the success of the service invocation to the first business client 011a. If the processing module 0115 of the second business client 011b determines that the transaction branch has failed to be submitted according to the submission result, it may send a service invocation response indicating the failure of the service invocation to the first business client 011a. The service invocation response can be transparently transmitted to the first service client 011a through the second network agent node 012b and the first network agent node 012a.
也即是,在上述步骤108之后,第二业务客户端011b可以执行上述步骤103、步骤104以及步骤106至步骤108所示的方法,第二网络代理节点012b可以执行上述步骤105,以及步骤109至步骤118所示的方法。其中,该第二业务客户端011b以及第二网络代理节点012b执行的操作可以参考上述步骤103至步骤118的相关描述,此处不再赘述。That is, after step 108, the second service client 011b can perform the methods shown in step 103, step 104, and step 106 to step 108, and the second network proxy node 012b can perform step 105 and step 109. Go to the method shown in step 118. For the operations performed by the second service client 011b and the second network proxy node 012b, reference may be made to the relevant descriptions of the foregoing step 103 to step 118, which will not be repeated here.
可选的,第二业务客户端011b的处理模块0115在接收到第一业务客户端011a发送的服务调用请求后,若确定其运行自身的服务即可实现该待执行的事务分支,则可以无需调用其他业务客户端的服务,即无需执行上述步骤108所示的方法。若第二业务客户端011b的处理模块0115确定还需要调用第三业务服务器中的第三业务客户端的服务,则可以指示服务调用模块0114执行上述步骤108所示的方法。相应的,该第三业务服务器中的第三业务客户端和第三网络代理节点也需执行上述步骤103至步骤118所示的方法。也即是,除了该第一业务服务器和第二业务服务器之外,该第三业务服务器也是该分布式事务的参与者之一。Optionally, after the processing module 0115 of the second business client 011b receives the service invocation request sent by the first business client 011a, if it is determined that it can run its own service to implement the transaction branch to be executed, there is no need to Invoking the services of other business clients, that is, there is no need to perform the method shown in step 108 above. If the processing module 0115 of the second service client 011b determines that the service of the third service client in the third service server needs to be invoked, the service invocation module 0114 may be instructed to execute the method shown in step 108 above. Correspondingly, the third service client and the third network proxy node in the third service server also need to execute the methods shown in step 103 to step 118 above. That is, in addition to the first service server and the second service server, the third service server is also one of the participants of the distributed transaction.
可选的,第一业务客户端也可以在确定其事务分支提交成功后再向第二业务客户端发送该服务调用请求。也即是,上述步骤108也可以在步骤118之后执行。相应的,该第一业务客户端向第二业务客户端发送的服务调用请求中携带的分布式事务的上下文还可以包括:该第一网络代理节点执行的事务分支的标识。该事务分支的标识可以是该第一网络代理节点接收到第一创建响应后发送至第一业务客户端的。Optionally, the first business client may also send the service invocation request to the second business client after determining that its transaction branch is successfully submitted. That is, the above step 108 can also be executed after step 118. Correspondingly, the context of the distributed transaction carried in the service invocation request sent by the first business client to the second business client may further include: the identifier of the transaction branch executed by the first network proxy node. The identifier of the transaction branch may be sent to the first service client after the first network agent node receives the first creation response.
若第二业务客户端接收到的服务调用请求中所携带的分布式事务的上下文还包括该第一网络代理节点执行的事务分支的标识,则该第二业务客户端生成的数据库操作指令中携带的分布式事务的上下文也包括该第一网络代理节点执行的事务分支的标识。由此,该第二网络代理节点向事务服务器发送的事务分支创建请求中即可携带该分布式事务的标识,以及该第一网络代理节点执行的事务分支的标识。事务服务器接收到该事务分支创建请求后,即可确定该第一业务客户端调用了第二业务客户端的服务。也即是,事务服务器可以基于事务分支创建请求中携带的事务分支的标识,明确各个业务客户端之间的服务调用情况。If the distributed transaction context carried in the service invocation request received by the second business client also includes the identifier of the transaction branch executed by the first network proxy node, then the database operation instruction generated by the second business client carries The context of the distributed transaction also includes the identifier of the transaction branch executed by the first network agent node. Therefore, the transaction branch creation request sent by the second network agent node to the transaction server can carry the identifier of the distributed transaction and the identifier of the transaction branch executed by the first network agent node. After the transaction server receives the transaction branch creation request, it can determine that the first business client has invoked the service of the second business client. That is, the transaction server can clarify the service invocation status between various business clients based on the identifier of the transaction branch carried in the transaction branch creation request.
可选的,第一业务客户端也可以在确定第二业务客户端的服务调用成功后,再生成数据库操作语句。即上述步骤108和步骤109也可以在步骤103之前执行。或者,上述步骤108也可以与步骤103同步执行,即第一业务服务器和第二业务服务器可以同步处理事务分支,由此可以确保分布式事务的处理效率。Optionally, the first business client may also generate a database operation statement after determining that the service call of the second business client is successful. That is, the above step 108 and step 109 can also be executed before step 103. Alternatively, the above step 108 can also be performed synchronously with step 103, that is, the first service server and the second service server can process the transaction branch synchronously, thereby ensuring the processing efficiency of the distributed transaction.
对于第一业务客户端处理完其事务分支后再发送服务调用请求的场景,若该第一业务客户端确定其事务分支创建失败,或者事务分支提交失败,则可以提前确定该分布式事务执行失败。因此,第一业务客户端也无需再向第二业务客户端发送服务调用请求,即第一业务客户端可以无需再执行该步骤108。由此,可以避免浪费第二业务服务器的计算资源。For the scenario where the first business client sends a service call request after processing its transaction branch, if the first business client determines that its transaction branch creation fails, or the transaction branch submission fails, it can be determined in advance that the distributed transaction execution failed . Therefore, the first business client does not need to send a service invocation request to the second business client, that is, the first business client may not need to perform step 108 again. In this way, it is possible to avoid wasting the computing resources of the second service server.
同理,对于第一业务客户端先调用第二业务客户端的服务,然后再处理其事务分支的场景,若该第一业务客户端确定第二业务客户端的服务调用失败,也可以提前确定该分布式事务执行失败。因此,第一业务客户端也无需再执行上述步骤103、步骤104、步骤106和步骤107。由此,可以避免浪费该第一业务服务器的计算资源。Similarly, for the scenario where the first business client first calls the service of the second business client and then processes its transaction branch, if the first business client determines that the service call of the second business client fails, the distribution can also be determined in advance The execution of the typed transaction failed. Therefore, the first service client does not need to perform step 103, step 104, step 106, and step 107. Therefore, it is possible to avoid wasting the computing resources of the first service server.
步骤120、第一业务客户端根据该提交结果和该服务调用响应,向该事务服务器发送针对该分布式事务的提交指令或者回滚指令。Step 120: The first business client sends a commit instruction or a rollback instruction for the distributed transaction to the transaction server according to the commit result and the service invocation response.
第一业务客户端接收到第一网络代理节点发送的事务分支的提交结果,以及第二业务客户端发送的服务调用响应后,若确定该第一业务服务器中的事务分支提交成功,且该第二业务客户端的服务调用成功,则可以确定用于实现该分布式事务的各个事务分支均提交成功,因此可以向事务服务器发送针对该分布式事务的提交指令。该提交指令用于指示提交该分布式事务包括的各个事务分支。After the first business client receives the commit result of the transaction branch sent by the first network proxy node and the service call response sent by the second business client, if it is determined that the transaction branch in the first business server is successfully submitted, and the first Second, if the service call of the business client is successful, it can be determined that each transaction branch used to implement the distributed transaction is submitted successfully, and therefore, a commit instruction for the distributed transaction can be sent to the transaction server. The commit instruction is used to instruct to commit each transaction branch included in the distributed transaction.
若第一业务客户端确定该第一业务服务器中的事务分支提交失败,或者该第二业务客户端的服务调用失败,则可以向事务服务器发送针对该分布式事务的回滚指令,该回滚指令用于指示回滚该分布式事务包括的各个事务分支。其中,针对该分布式事务的提交指令或者回滚指令中均携带有该分布式事务的上下文。If the first business client determines that the transaction branch commit in the first business server fails, or the service call of the second business client fails, it can send a rollback instruction for the distributed transaction to the transaction server, the rollback instruction Used to instruct to roll back each transaction branch included in the distributed transaction. Wherein, the commit instruction or the rollback instruction for the distributed transaction both carry the context of the distributed transaction.
可选的,在本申请实施例中,该第一业务客户端可以调用多个第二业务客户端的服务。相应的,第一业务客户端可以接收到该多个第二业务客户端发送的服务调用响应。则第一业务客户端需要在确定该第一业务服务器中的事务分支提交成功,且每个第二业务客户端的服务均调用成功后,才可以确定用于实现该分布式事务的各个事务分支均提交成功,并发送针对该分布式事务的提交指令。同理,第一业务客户端若确定该第一业务服务器中的事务分支提交失败,或者任一第二业务客户端的服务调用失败,则可以发送针对该分布式事务的回滚指令。Optionally, in this embodiment of the present application, the first business client may call services of multiple second business clients. Correspondingly, the first service client can receive the service invocation response sent by the multiple second service clients. Then, the first business client needs to determine that the transaction branch in the first business server is submitted successfully and the services of each second business client are successfully invoked before it can determine that the transaction branches used to implement the distributed transaction are all The commit is successful, and a commit instruction for the distributed transaction is sent. In the same way, if the first business client determines that the transaction branch submission in the first business server fails, or the service invocation of any second business client fails, it may send a rollback instruction for the distributed transaction.
示例的,如图2所示,该第一业务客户端011a中的API模块0111还可以包括提交/回滚事务API。第一业务客户端011a的处理模块0115可以通过调用该提交事务(Commit Transaction)API,向事务服务器02发送针对该分布式事务的提交指令R2,或者可以通过调用该回滚事务(Rollback Transaction)API,向事务服务器02发送针对该分布式事务的回滚指令R2。参考图 2可以看出,该针对该分布式事务的提交或回滚指令R2可以由第一网络代理节点012a的透传模块0123透传至事务服务器02。For example, as shown in FIG. 2, the API module 0111 in the first business client 011a may also include a commit/rollback transaction API. The processing module 0115 of the first business client 011a can send a commit instruction R2 for the distributed transaction to the transaction server 02 by calling the commit transaction (Commit Transaction) API, or can call the rollback transaction (Rollback Transaction) API , Send a rollback instruction R2 for the distributed transaction to the transaction server 02. Referring to FIG. 2, it can be seen that the commit or rollback instruction R2 for the distributed transaction can be transparently transmitted to the transaction server 02 by the transparent transmission module 0123 of the first network agent node 012a.
该提交事务API以及该回滚事务API中每个API的输入参数均可以包括事务服务器的地址,以及该分布式事务的标识。且该提交事务API的返回值为0可以表示提交成功,返回值为-1可以表示提交失败。同理,该回滚事务API的返回值为0可以表示回滚成功,返回值为-1可以表示回滚失败。其中,该提交事务API以及该回滚事务API中每个API的返回值的数据类型可以为整型(int)。The input parameters of each API in the commit transaction API and the rollback transaction API may include the address of the transaction server and the identifier of the distributed transaction. And the return value of the commit transaction API is 0 to indicate that the commit is successful, and the return value of -1 can indicate that the commit failed. In the same way, the return value of the rollback transaction API is 0 to indicate that the rollback is successful, and the return value of -1 can indicate that the rollback failed. The data type of the return value of each API in the commit transaction API and the rollback transaction API may be an integer (int).
可选的,若第一业务客户端根据已接收的提交结果或者已接收到的部分服务调用响应即可确定该分布式事务执行失败,则可以直接向事务服务器发送针对该分布式事务的回滚指令,而无需再等待所有的提交结果和服务调用响应均接收到后再发送该回滚指令。由此,可以有效提高分布式事务的处理效率。Optionally, if the first business client can determine that the distributed transaction has failed to execute according to the received submission result or the received partial service call response, it can directly send a rollback for the distributed transaction to the transaction server Command without waiting for all submission results and service call responses to be received before sending the rollback command. As a result, the processing efficiency of distributed transactions can be effectively improved.
步骤121、事务服务器向每个参与该分布式事务的业务服务器中的网络代理节点发送针对事务分支的第三提交指令或者第三回滚指令。Step 121: The transaction server sends a third commit instruction or a third rollback instruction for the transaction branch to the network agent node in each business server participating in the distributed transaction.
事务服务器接收到第一业务客户端发送的针对该分布式事务的提交指令或者回滚指令后,可以先确定参与该分布式事务各个业务服务器,以及每个业务服务器所执行的事务分支。进而可以分别向每个业务服务器中的网络代理节点发送针对该业务服务器所执行的事务分支的第三提交指令或者第三回滚指令。该第三提交指令和第三回滚指令中均可以携带有该业务服务器所执行的事务分支的标识。After the transaction server receives the commit instruction or rollback instruction for the distributed transaction sent by the first business client, it may first determine the various business servers participating in the distributed transaction and the transaction branch executed by each business server. Furthermore, the third commit instruction or the third rollback instruction for the transaction branch executed by the business server may be sent to the network agent node in each business server respectively. Both the third commit instruction and the third rollback instruction may carry an identifier of the transaction branch executed by the business server.
示例的,参考图2,假设参与分布式事务的业务服务器包括第一业务服务器01a和第二业务服务器01b,并且第一业务服务器01a执行了该分布式事务的事务分支1,第二业务服务器01b执行了该分布式事务的事务分支2。则事务服务器02在接收到该第一业务客户端011a发送的针对该分布式事务的提交指令后,可以向第一网络代理节点012a发送针对该事务分支1的第三提交指令Z1,并可以向第二网络代理节点012b发送针对该事务分支2的第三提交指令Z2。若第二业务服务器01b还调用第三业务服务器中的业务客户端执行了事务分支3,则该事务服务器02还需要向该第三业务服务器中的网络代理节点012b发送针对该事务分支3的第三提交指令。For example, referring to FIG. 2, it is assumed that the business servers participating in a distributed transaction include a first business server 01a and a second business server 01b, and the first business server 01a executes transaction branch 1 of the distributed transaction, and the second business server 01b Transaction branch 2 of the distributed transaction is executed. Then, after the transaction server 02 receives the commit instruction for the distributed transaction sent by the first business client 011a, it can send the third commit instruction Z1 for the transaction branch 1 to the first network proxy node 012a, and can send The second network agent node 012b sends a third commit instruction Z2 for the transaction branch 2. If the second service server 01b also invokes the service client in the third service server to execute transaction branch 3, the transaction server 02 also needs to send the first transaction branch 3 to the network agent node 012b in the third service server. 3. Submit instructions.
步骤122、第一网络代理节点处理接收到的指令。Step 122: The first network agent node processes the received instruction.
第一网络代理节点若接收到该事务服务器发送的针对该事务分支的第三提交指令,则可以根据该第三提交指令中携带的事务分支的标识,清理该分布式事务的事务日志中记录的该事务分支的标识以及对应的数据集。If the first network agent node receives the third commit instruction for the transaction branch sent by the transaction server, it can clear the transaction log of the distributed transaction according to the transaction branch identifier carried in the third commit instruction The identifier of the transaction branch and the corresponding data set.
第一网络代理节点若接收到该事务服务器发送的针对该事务分支的第三回滚指令,则可以根据该第三回滚指令中携带的事务分支的标识,从分布式事务的事务日志中获取对应的数据集。然后第一网络代理节点可以基于该数据集创建数据集回滚语句,并在第一业务数据库中执行该数据集回滚语句,从而回滚该事务分支。也即是,第一网络代理节点可以通过执行该数据集回滚语句,将该第一业务数据库中的业务数据恢复至执行事务分支之前的状态。If the first network agent node receives the third rollback instruction for the transaction branch sent by the transaction server, it can obtain it from the transaction log of the distributed transaction according to the transaction branch identifier carried in the third rollback instruction The corresponding data set. Then the first network agent node can create a data set rollback statement based on the data set, and execute the data set rollback statement in the first business database, thereby rolling back the transaction branch. That is, the first network agent node can restore the business data in the first business database to the state before executing the transaction branch by executing the data set rollback statement.
示例的,若用于实现该事务分支的数据库操作语句为更新(update)语句,则该第一网络代理节点创建的数据集回滚语句也可以为update语句。若用于实现该事务分支的数据库操作语句为插入(insert)语句,则该第一网络代理节点创建的数据集回滚语句可以为删除(delete)语句。若用于实现该事务分支的数据库操作语句为delete语句,则该第一网络代理节点创建的数据集回滚语句可以为insert语句。For example, if the database operation statement used to implement the transaction branch is an update statement, the data set rollback statement created by the first network agent node may also be an update statement. If the database operation statement used to implement the transaction branch is an insert statement, the data set rollback statement created by the first network agent node may be a delete statement. If the database operation statement used to implement the transaction branch is a delete statement, the data set rollback statement created by the first network agent node may be an insert statement.
可选的,第二网络代理节点接收到该事务服务器发送的第三提交指令或第三回滚指令后,也可以通过上述步骤122所示的方法处理其接收到的指令,本申请实施例对此不再赘述。例如, 参考图2,每个网络代理节点中的事务分支处理模块0124可以用于处理接收到的指令。各个网络代理节点在处理完成事务服务器发送的第三提交指令或第三回滚指令之后,即可完成该分布式事务的第二阶段的操作。该第二阶段也可以称为提交阶段或者执行阶段。Optionally, after receiving the third commit instruction or third rollback instruction sent by the transaction server, the second network proxy node may also process the received instruction through the method shown in step 122 above. This will not be repeated here. For example, referring to FIG. 2, the transaction branch processing module 0124 in each network agent node may be used to process the received instructions. Each network agent node can complete the second phase of the distributed transaction after processing the third commit instruction or third rollback instruction sent by the transaction server. This second phase may also be referred to as the commit phase or the execution phase.
基于上文描述可知,在实现分布式事务的第二阶段的操作的过程中,事务分支的提交或回滚均可以由网络代理节点来实现,而业务客户端仅需要调用提交/回滚事务API,该API的调用对业务的侵入性较低,即对业务客户端原有的业务逻辑的影响较小,因此可以有效降低业务客户端适配分布式事务处理架构,以实现分布式改造时的成本。Based on the above description, in the process of implementing the second phase of the distributed transaction, the commit or rollback of the transaction branch can be implemented by the network proxy node, and the business client only needs to call the commit/rollback transaction API , The API call is less intrusive to the business, that is, it has less impact on the original business logic of the business client, so it can effectively reduce the adaptation of the business client to the distributed transaction processing architecture to achieve distributed transformation. cost.
可选的,若某个网络代理节点在上述步骤122之前,由于事务分支创建失败或者事务分支提交失败已经执行过回滚操作,则在上述步骤122中,该网络代理节点可以无需再处理该第三回滚指令。Optionally, if a certain network agent node has already performed a rollback operation due to a transaction branch creation failure or a transaction branch commit failure before the above step 122, then in the above step 122, the network agent node may no longer need to process the first step. Three rollback instructions.
或者,每个网络代理节点也可以在上述步骤117后,向事务服务器发送事务分支的提交结果,事务服务器进而可以根据该提交结果确定每个业务服务器中的事务分支是否执行成功。相应的,在上述步骤121中,事务服务器可以仅向事务分支执行成功的业务服务器中的网络代理节点发送该第三回滚指令,而无需再向事务分支执行失败的业务服务器中的网络代理节点发送该第三回滚指令。Alternatively, each network agent node may also send the commit result of the transaction branch to the transaction server after the above step 117, and the transaction server may then determine whether the transaction branch in each business server is executed successfully according to the commit result. Correspondingly, in the above step 121, the transaction server may only send the third rollback instruction to the network agent node in the business server that has successfully executed the transaction branch, and does not need to send the third rollback instruction to the network agent node in the business server that has failed to execute the transaction branch. Send the third rollback instruction.
综上所述,本申请实施例提供了一种分布式事务的处理方法,该分布式事务的处理方法中,业务客户端发送至业务数据库的数据库操作指令中可以携带有分布式事务的上下文,使得网络代理节点可以基于该分布式事务的上下文,以及该数据库操作语句来创建和处理事务分支。由于可以通过网络代理节点来创建和处理事务分支,因此无需该业务客户端部署用于创建和处理事务分支的接口(例如try、confirm和cancel接口),从而有效降低了业务客户端应用于分布式事务处理系统的开发成本。In summary, the embodiments of the present application provide a distributed transaction processing method. In the distributed transaction processing method, the database operation instructions sent by the business client to the business database can carry the context of the distributed transaction. The network agent node can create and process transaction branches based on the context of the distributed transaction and the database operation statement. Since transaction branches can be created and processed through network proxy nodes, there is no need for the business client to deploy interfaces for creating and processing transaction branches (such as try, confirm, and cancel interfaces), thereby effectively reducing the application of business clients to distributed The development cost of the transaction processing system.
并且,相比于传统的TCC技术,本申请实施例提供的方案在实现分布式事务的过程中,事务分支的创建和处理均可以由网络代理节点来实现,而业务客户端仅需要调用启动事务API、操作指令创建API以及提交/回滚事务API,上述API的调用对业务的侵入性较低,即对业务客户端原有的业务逻辑的影响较小,因此可以有效降低业务客户端在平台即服务(platform as a service,PaaS)平台中适配分布式事务处理架构,以实现务分布式改造时的成本,提高了业务客户端进行分布式改造时的效率。而且,上述启动事务API、操作指令创建API以及提交/回滚事务API均可以由PaaS平台提供,由于上述API的功能较为简单,因此可以支持多种编程语言。由此可以确保采用不同编程语言开发实现的业务客户端在进行分布式改造时,都可以部署上述API,从而能够以较低的开发成本实现跨编程语言的分布式事务处理系统。Moreover, compared with the traditional TCC technology, in the solution provided by the embodiments of this application, in the process of realizing distributed transactions, the creation and processing of transaction branches can be realized by network proxy nodes, and the business client only needs to call to start the transaction. API, operation instruction creation API, and submit/roll back transaction API. The invocation of the above API is less intrusive to the business, that is, it has less impact on the original business logic of the business client, so it can effectively reduce the business client’s platform The distributed transaction processing architecture is adapted to the platform as a service (platform as a service, PaaS) platform to realize the cost of the distributed transformation of the service and improve the efficiency of the distributed transformation of the business client. Moreover, the above-mentioned startup transaction API, operation instruction creation API, and commit/rollback transaction API can all be provided by the PaaS platform. Since the functions of the above-mentioned API are relatively simple, multiple programming languages can be supported. This can ensure that business clients developed and implemented in different programming languages can deploy the above APIs when performing distributed transformations, so that a distributed transaction processing system across programming languages can be realized at a lower development cost.
此外,由于该分布式事务处理系统中的各个业务客户端均采用数据库协议与业务数据库进行数据交互,而网络代理节点可以通过携带有分布式事务的上下文的数据库操作指令来创建和处理事务分支,因此即使该分布式事务处理系统中的各个业务客户端采用不同的编程语言开发实现,也不会对网络代理节点创建和处理事务分支造成影响。也即是,基于本申请实施例提供的方案,网络代理节点仅需支持数据库协议即可适配于采用不同编程语言开发得到的业务客户端。由此可知,本申请实施例的方案能够以较低的成本,使得跨编程语言的分布式事务处理系统实现分布式事务的数据一致性。In addition, since each business client in the distributed transaction processing system uses a database protocol to interact with the business database, the network agent node can create and process transaction branches through database operation instructions that carry the context of distributed transactions. Therefore, even if each business client in the distributed transaction processing system is developed and implemented using different programming languages, it will not affect the creation and processing of transaction branches by the network agent node. That is, based on the solution provided by the embodiment of the present application, the network agent node only needs to support the database protocol to adapt to the business client developed using different programming languages. It can be seen from this that the solution of the embodiment of the present application can enable the distributed transaction processing system across programming languages to achieve data consistency of distributed transactions at a lower cost.
图4是本申请实施例提供的另一种分布式事务的处理方法的流程图,该方法可以应用于如图1或图2所示的系统中。本申请实施例以该方法应用于如图2所示的系统,且以该第一业务客户端待执行的事务分支包含多次针对数据库的操作为例进行说明。参考图4,该方法可以包括:FIG. 4 is a flowchart of another distributed transaction processing method provided by an embodiment of the present application, and the method can be applied to the system shown in FIG. 1 or FIG. 2. In the embodiment of the present application, the method is applied to the system shown in FIG. 2 and the transaction branch to be executed by the first business client includes multiple operations on the database as an example for description. Referring to Figure 4, the method may include:
步骤201、第一业务客户端向事务服务器发送分布式事务的创建请求。Step 201: The first business client sends a creation request of a distributed transaction to the transaction server.
步骤201的实现过程可以参考图3所示实施例中步骤101的相关描述,此处不再赘述。For the implementation process of step 201, reference may be made to the related description of step 101 in the embodiment shown in FIG. 3, which will not be repeated here.
步骤202、事务服务器向第一业务客户端发送为该分布式事务分配的标识。Step 202: The transaction server sends an identifier assigned to the distributed transaction to the first service client.
步骤202的实现过程可以参考图3所示实施例中步骤102的相关描述,此处不再赘述。For the implementation process of step 202, reference may be made to the related description of step 102 in the embodiment shown in FIG. 3, which will not be repeated here.
步骤203、第一业务客户端生成用于实现该分布式事务中待执行的事务分支的多个数据库操作语句。Step 203: The first business client generates multiple database operation statements for implementing transaction branches to be executed in the distributed transaction.
步骤203的实现过程可以参考图3所示实施例中步骤103的相关描述,此处不再赘述。For the implementation process of step 203, reference may be made to the related description of step 103 in the embodiment shown in FIG. 3, which will not be repeated here.
步骤204、第一业务客户端向第一业务数据库发送第二设置指令。Step 204: The first service client sends a second setting instruction to the first service database.
由于用于实现该事务分支的数据库操作语句的个数大于1,因此第一业务客户端可以确定该多个数据库操作语句均执行完成后才可以提交该事务分支,进而可以向第一业务数据库发送第二设置指令,该第二设置指令用于指示将第一业务数据库的自动提交功能设置为关闭状态。例如,参考图2,第一业务客户端011a的处理模块0115可以在检测到数据库操作语句的个数大于1时,指示数据库驱动器0113向第一业务数据库03a发送第二设置指令。Since the number of database operation statements used to implement the transaction branch is greater than 1, the first business client can determine that the multiple database operation statements are all executed before submitting the transaction branch, and then can send to the first business database The second setting instruction is used to instruct to set the automatic submission function of the first business database to the closed state. For example, referring to FIG. 2, the processing module 0115 of the first service client 011a may instruct the database driver 0113 to send the second setting instruction to the first service database 03a when detecting that the number of database operation sentences is greater than one.
步骤205、第一网络代理节点获取该第二设置指令,并记录第一业务数据库的自动提交功能为关闭状态。Step 205: The first network agent node obtains the second setting instruction, and records that the automatic submission function of the first service database is in a closed state.
由于第一业务客户端发送至第一业务数据库的第二设置指令需要通过第一网络代理节点转发,因此第一网络代理节点可以获取到该第二设置指令,并可以根据该第二设置指令记录第一业务数据库的自动提交功能为关闭状态。并且,第一网络代理节点可以在完成状态记录后,将该第二设置指令转发至该第一业务数据库。该第一网络代理节点记录第一业务数据库的自动提交功能为关闭状态,可以确定用于实现事务分支的数据库操作语句的个数大于1。进而,该第一网络代理节点在接收到数据库操作指令后,即可确定应采用何种方式获取事务分支的锁信息,并创建事务分支。Since the second setting instruction sent by the first service client to the first service database needs to be forwarded by the first network proxy node, the first network proxy node can obtain the second setting instruction and record it according to the second setting instruction The automatic submission function of the first business database is closed. In addition, the first network agent node may forward the second setting instruction to the first service database after completing the status recording. The first network agent node records that the automatic submission function of the first business database is in the off state, and can determine that the number of database operation statements used to implement transaction branching is greater than one. Furthermore, after receiving the database operation instruction, the first network agent node can determine which method should be used to obtain the lock information of the transaction branch, and create the transaction branch.
示例的,第一网络代理节点中可以记录有第一业务数据库的状态标识,第一网络代理节点可以在获取到该第二设置指令后,将该状态标识设置为false,以指示该第一业务数据库的自动提交功能为关闭状态。例如,第一网络代理节点012a中的事务分支处理模块0124可以记录该第一业务数据库的状态标识。For example, the first network agent node may record the status identifier of the first service database, and the first network agent node may set the status identifier to false after obtaining the second setting instruction to indicate the first service The automatic submission function of the database is closed. For example, the transaction branch processing module 0124 in the first network agent node 012a may record the status identifier of the first service database.
步骤206、第一业务客户端基于该多个数据库操作语句和该分布式事务的上下文生成多个数据库操作指令。Step 206: The first business client generates a plurality of database operation instructions based on the plurality of database operation statements and the context of the distributed transaction.
在本申请实施例中,对于用于实现该事务分支的每个数据库操作语句,第一业务客户端均可以将分布式事务的上下文与该数据库操作语句组合,从而生成一个数据库操作指令。由于在本实施例中,用于实现该事务分支的数据库操作语句的个数大于1,因此第一业务客户端基于该多个数据库操作语句可以生成多个数据库操作指令。其中,每个数据库操作指令均包括至少一个数据库操作语句以及该分布式事务的上下文。在本申请实施例中,至少一个是指一个或多个,多个是指两个或两个以上。例如,该每个数据库操作指令可以包括一个数据库操作语句。生成每个数据库操作指令的过程可以参考图3所示实施例中步骤106的相关描述,此处不再赘述。In the embodiment of the present application, for each database operation statement used to implement the transaction branch, the first business client can combine the context of the distributed transaction with the database operation statement to generate a database operation instruction. Since in this embodiment, the number of database operation statements used to implement the transaction branch is greater than 1, the first business client can generate multiple database operation instructions based on the multiple database operation statements. Wherein, each database operation instruction includes at least one database operation statement and the context of the distributed transaction. In the embodiments of the present application, at least one refers to one or more, and multiple refers to two or more. For example, each database operation instruction may include a database operation statement. For the process of generating each database operation instruction, reference may be made to the related description of step 106 in the embodiment shown in FIG. 3, which will not be repeated here.
步骤207、第一业务客户端向第一业务数据库发送多个数据库操作指令。Step 207: The first service client sends multiple database operation instructions to the first service database.
第一业务客户端生成该多个数据库操作指令后,即可将该多个数据库操作指令依次发送至该第一业务数据库。After the first business client generates the multiple database operation instructions, it can send the multiple database operation instructions to the first business database in sequence.
例如,参考图2,第一网络代理节点012a中的数据库驱动器0113可以向第一业务数据库03a发送多个数据库操作指令。For example, referring to FIG. 2, the database driver 0113 in the first network agent node 012a may send multiple database operation instructions to the first service database 03a.
步骤208、第一业务客户端向第二业务客户端发送服务调用请求。Step 208: The first business client sends a service invocation request to the second business client.
步骤208的实现过程可以参考图3所示实施例中步骤108的相关描述,此处不再赘述。For the implementation process of step 208, reference may be made to the related description of step 108 in the embodiment shown in FIG. 3, which will not be repeated here.
步骤209、第一网络代理节点获取该多个数据库操作指令,并从第一业务数据库中获取每个数据库操作语句所针对的数据集。Step 209: The first network agent node obtains the multiple database operation instructions, and obtains the data set targeted by each database operation statement from the first service database.
对于获取到的每个数据库操作指令,第一网络代理节点均可以从该数据库操作指令中解析出数据库操作语句,进而从第一业务数据库中获取该数据库操作语句所针对的数据集。其中,获取每个数据库操作语句所针对的数据集的过程可以参考图3所示实施例中步骤109的相关描述,此处不再赘述。For each acquired database operation instruction, the first network agent node can parse the database operation statement from the database operation instruction, and then obtain the data set targeted by the database operation statement from the first business database. For the process of obtaining the data set targeted by each database operation sentence, reference may be made to the related description of step 109 in the embodiment shown in FIG. 3, which will not be repeated here.
步骤210、第一网络代理节点获取每个数据库操作语句所针对的数据集的锁信息。Step 210: The first network agent node obtains lock information of the data set targeted by each database operation statement.
该每个数据库操作语句所针对的数据集的锁信息可以包括该数据集所在数据表的表名,以及该数据集所在行的主键。例如,第一网络代理节点012a中的事务分支处理模块0124可以获取每个数据库操作语句所针对的数据集的锁信息。The lock information of the data set targeted by each database operation statement may include the table name of the data table where the data set is located, and the primary key of the row where the data set is located. For example, the transaction branch processing module 0124 in the first network agent node 012a can obtain the lock information of the data set targeted by each database operation statement.
步骤211、第一网络代理节点存储每个数据库操作语句所针对的数据集以及该每个数据库操作语句所针对的数据集的锁信息。Step 211: The first network agent node stores the data set targeted by each database operation statement and the lock information of the data set targeted by each database operation statement.
在本申请实施例中,第一网络代理节点若确定该第一业务数据库的自动提交功能处于关闭状态,则可以确定用于实现事务分支的数据库操作语句的个数大于1。进而,第一网络代理节点可以确定在用于实现事务分支的多个数据库操作语句均执行成功后,才可以根据获取到的锁信息请求创建该事务分支,因此该第一网络代理节点需先存储该每个数据库操作语句所针对的数据集以及该每个数据库操作语句所针对的数据集的锁信息。并且,为了便于后续创建或回滚事务分支,第一网络代理节点可以将分布式事务的标识,用于实现该事务分支的多个数据库操作语句所针对的数据集,以及该数据集的锁信息进行对应存储。也即是,该第一网络代理节点可以将用于实现同一个事务分支的多个数据库操作语句所针对的数据集进行合并存储,并可以将该多个数据库操作语句所针对的数据集的锁信息进行合并存储。例如,第一网络代理节点012a中的事务分支处理模块0124可以存储该每个数据库操作语句所针对的数据集以及该每个数据库操作语句所针对的数据集的锁信息。In this embodiment of the application, if the first network agent node determines that the automatic submission function of the first service database is in the off state, it can determine that the number of database operation statements used to implement transaction branching is greater than one. Furthermore, the first network agent node can determine that only after the multiple database operation statements used to implement the transaction branch are executed successfully, can the transaction branch be created according to the acquired lock information request. Therefore, the first network agent node needs to store The data set targeted by each database operation statement and the lock information of the data set targeted by each database operation statement. In addition, in order to facilitate subsequent creation or rollback of a transaction branch, the first network agent node may use the identifier of the distributed transaction to implement the data set targeted by the multiple database operation statements of the transaction branch, and the lock information of the data set Perform corresponding storage. That is, the first network agent node can merge and store the data sets targeted by multiple database operation statements used to implement the same transaction branch, and can lock the data sets targeted by the multiple database operation statements. Information is merged and stored. For example, the transaction branch processing module 0124 in the first network agent node 012a may store the data set targeted by each database operation statement and the lock information of the data set targeted by each database operation statement.
示例的,假设分布式事务的标识为ID1,在上述步骤203中,第一业务客户端生成的用于实现待执行的事务分支的数据库操作语句包括Y1、Y2和Y3,该三条数据库操作语句所针对的数据集分别为D1、D2和D3,该三个数据集的锁信息分别为S1、S2和S3。则该第一网络代理节点可以存储分布式事务的标识ID1,与数据集D1、D2和D3的合集,以及锁信息S1、S2和S3的合集的对应关系。For example, assuming that the identifier of the distributed transaction is ID1, in the above step 203, the database operation statements generated by the first business client to implement the transaction branch to be executed include Y1, Y2, and Y3. The three database operation statements are The targeted data sets are D1, D2, and D3, and the lock information of the three data sets are S1, S2, and S3, respectively. Then the first network agent node can store the identification ID1 of the distributed transaction, the corresponding relationship with the collection of data sets D1, D2, and D3, and the collection of lock information S1, S2, and S3.
步骤212、第一网络代理节点在该第一业务数据库中执行每个数据库操作语句。Step 212: The first network agent node executes each database operation statement in the first service database.
例如,第一网络代理节点012a中的事务分支处理模块0124在存储每个数据库操作语句所针对的数据集和每个数据库操作语句所针对的数据集的锁信息之后,即可通过数据库驱动器0125在该第一业务数据03a中执行每个数据库操作指令中的数据库操作语句。For example, after the transaction branch processing module 0124 in the first network agent node 012a stores the data set targeted by each database operation statement and the lock information of the data set targeted by each database operation statement, it can use the database driver 0125 to access In the first service data 03a, the database operation statement in each database operation instruction is executed.
步骤213、第一网络代理节点向第一业务客户端发送每个数据库操作语句的执行结果。Step 213: The first network agent node sends the execution result of each database operation statement to the first service client.
第一网络代理节点每执行完成一条数据库操作语句,即可向第一业务客户端发送该数据库操作语句的执行结果。该执行结果可以用于指示该数据库操作语句执行成功或者执行失败。例如,第一网络代理节点012a中的事务分支处理模块0124可以向第一业务客户端011a发送每个数据库操作语句的执行结果。Each time the first network agent node completes a database operation sentence, it can send the execution result of the database operation sentence to the first business client. The execution result may be used to indicate the success or failure of the execution of the database operation statement. For example, the transaction branch processing module 0124 in the first network agent node 012a may send the execution result of each database operation statement to the first service client 011a.
步骤214、第一业务客户端检测每个数据库操作语句是否均执行成功。Step 214: The first business client detects whether each database operation statement is executed successfully.
第一业务客户端可以根据第一网络代理节点发送的执行结果,检测用于实现该事务分支 的每个数据库操作语句是否均执行成功。若任一数据库操作语句执行失败,则第一业务客户端可以执行步骤215;若每个数据库操作语句均执行成功,则第一业务客户端可以执行步骤218。例如,第一业务客户端011a中的处理模块0115可以检测每个数据库操作语句是否均执行成功。The first service client can detect whether each database operation statement used to implement the transaction branch is executed successfully according to the execution result sent by the first network agent node. If the execution of any database operation statement fails, the first business client can execute step 215; if each database operation statement is executed successfully, the first business client can execute step 218. For example, the processing module 0115 in the first business client 011a can detect whether each database operation statement is executed successfully.
步骤215、第一业务客户端向第一业务数据库发送针对该事务分支的第二回滚指令。Step 215: The first service client sends a second rollback instruction for the transaction branch to the first service database.
第一业务客户端若检测到任一数据库操作语句执行失败,则可以确定该事务分支未执行成功,因此可以向第一业务数据库发送针对该事务分支的第二回滚指令。例如,第一业务客户端011a中的处理模块0115可以在检测到任一数据库操作语句执行失败时,指示数据库驱动器0113发送该第二回滚指令。If the first business client detects that any database operation statement has failed to execute, it can determine that the transaction branch has not been executed successfully, and therefore can send a second rollback instruction for the transaction branch to the first business database. For example, the processing module 0115 in the first business client 011a may instruct the database driver 0113 to send the second rollback instruction when it detects that any database operation statement fails to execute.
步骤216、第一网络代理节点删除存储的数据集和锁信息。Step 216: The first network agent node deletes the stored data set and lock information.
第一网络代理节点若获取到该第一业务客户端发送的针对该事务分支的第二回滚指令,则可以确定该事务分支执行失败,因此可以删除其存储的每个数据库操作语句所针对的数据集,以及每个数据库操作语句所针对的数据集的锁信息,避免该数据集和锁信息占用过多的存储空间。例如,第一网络代理节点012a中的事务分支处理模块0124可以删除存储的每个数据库操作语句所针对的数据集,以及每个数据库操作语句所针对的数据集的锁信息。If the first network agent node obtains the second rollback instruction for the transaction branch sent by the first business client, it can determine that the transaction branch has failed to execute, so it can delete the stored database operation statement for each The data set, and the lock information of the data set targeted by each database operation statement, to avoid the data set and lock information occupying too much storage space. For example, the transaction branch processing module 0124 in the first network agent node 012a can delete the stored data set for each database operation statement and the lock information of the data set for each database operation statement.
步骤217、第一网络代理节点向第一业务数据库发送该第二回滚指令。Step 217: The first network proxy node sends the second rollback instruction to the first service database.
第一网络代理节点接收到该第二回滚指令后,还可以将该第二回滚指令转发至该第一业务数据库。该第一业务数据库接收到该第二回滚指令后,即可回滚该事务分支。例如,第一网络代理节点012a中的事务分支处理模块0124可以通过数据库驱动器0125向第一业务数据库03a发送该第二回滚指令。After receiving the second rollback instruction, the first network proxy node may also forward the second rollback instruction to the first service database. After the first service database receives the second rollback instruction, the transaction branch can be rolled back. For example, the transaction branch processing module 0124 in the first network agent node 012a may send the second rollback instruction to the first service database 03a through the database driver 0125.
步骤218、第一业务客户端向第一业务数据库发送针对该事务分支的第二提交指令。Step 218: The first service client sends a second commit instruction for the transaction branch to the first service database.
第一业务客户端若检测到用于实现该事务分支的多个数据库操作语句均执行成功,则可以确定该事务分支执行成功,因此可以向第一业务数据库发送针对该事务分支的第二提交指令。例如,第一业务客户端011a的处理模块0115可以在检测到用于实现该事务分支的多个数据库操作语句均执行成功时,指示数据库驱动器0113发送该第二提交指令。If the first business client detects that multiple database operation statements used to implement the transaction branch are executed successfully, it can determine that the transaction branch is executed successfully, and therefore can send a second commit instruction for the transaction branch to the first business database . For example, the processing module 0115 of the first business client 011a may instruct the database driver 0113 to send the second commit instruction when detecting that multiple database operation statements used to implement the transaction branch are executed successfully.
步骤219、第一网络代理节点获取存储的每个数据库操作语句所针对的数据集的锁信息。Step 219: The first network agent node obtains the lock information of the data set targeted by each stored database operation statement.
第一网络代理节点若获取到该第一业务客户端发送的针对该事务分支的第二提交指令,则可以获取通过上述步骤211存储的每个数据库操作语句所针对的数据集的锁信息。该第一网络代理节点获取到的多个数据库操作语句所针对的数据集的锁信息即为事务分支的锁信息。例如,第一网络代理节点012a中的事务分支处理模块0124可以获取存储的每个数据库操作语句所针对的数据集的锁信息。If the first network agent node obtains the second commit instruction for the transaction branch sent by the first service client, it can obtain the lock information of the data set for each database operation statement stored in step 211. The lock information of the data set targeted by the multiple database operation statements acquired by the first network agent node is the lock information of the transaction branch. For example, the transaction branch processing module 0124 in the first network agent node 012a may obtain the lock information of the data set for which each database operation statement is stored.
可选的,若第一网络代理节点接收到的数据库操作指令中的数据库操作语句不会更改第一业务数据库中的数据,例如当该数据库操作语句为查询语句时,则第一网络代理节点不会获取并存储该数据库操作语句所针对的数据集的锁信息。因此,第一网络代理节点在获取到该第二提交指令后,若未获取到其预先存储数据集的锁信息,即第一网络代理节点在接收到第二提交指令之前并未存储任何数据集的锁信息,则第一网络代理节点可以直接转发该第二提交指令,而无需再执行后续操作。Optionally, if the database operation statement in the database operation instruction received by the first network agent node does not change the data in the first service database, for example, when the database operation statement is a query statement, the first network agent node does not The lock information of the data set targeted by the database operation statement will be acquired and stored. Therefore, after the first network agent node obtains the second submission instruction, if it does not obtain the lock information of its pre-stored data set, that is, the first network agent node does not store any data set before receiving the second submission instruction If the lock information is displayed, the first network agent node can directly forward the second submission instruction without performing subsequent operations.
步骤220、第一网络代理节点向该事务服务器发送事务分支创建请求。Step 220: The first network agent node sends a transaction branch creation request to the transaction server.
第一网络代理节点获取到事务分支的锁信息后,即可向事务服务器发送事务分支创建请求。该事务分支创建请求中可以包括该数据集的锁信息以及该分布式事务的标识。例如,第一网络代理节点012a中的事务分支处理模块0124可以向该事务服务器02发送事务分支创建请求。After obtaining the lock information of the transaction branch, the first network agent node can send a transaction branch creation request to the transaction server. The transaction branch creation request may include the lock information of the data set and the identification of the distributed transaction. For example, the transaction branch processing module 0124 in the first network agent node 012a may send a transaction branch creation request to the transaction server 02.
在该第一网络代理节点发送事务分支创建请求之后,事务服务器可以根据该创建请求中所携带的锁信息检测是否能够创建事务分支。由于该场景中,创建请求中携带的事务分支的锁信息包括多个数据集的锁信息,因此事务服务器可以在确定每个数据集的锁信息均与其所存储的其他事务分支的锁信息不同时,确定能够创建该事务分支。若事务服务器检测到任一数据集的锁信息与其所存储的其他事务分支的锁信息相同,则可以确定无法创建该事务分支。After the first network agent node sends the transaction branch creation request, the transaction server can detect whether the transaction branch can be created according to the lock information carried in the creation request. In this scenario, the lock information of the transaction branch carried in the creation request includes the lock information of multiple data sets, so the transaction server can determine that the lock information of each data set is different from the lock information of other transaction branches stored in it. , Make sure that the transaction branch can be created. If the transaction server detects that the lock information of any data set is the same as the lock information of other transaction branches stored in it, it can determine that the transaction branch cannot be created.
在步骤220之后,该分布式事务处理系统即可继续执行上述图3所示实施例中步骤112至步骤122所示的方法,故此处不再赘述。After step 220, the distributed transaction processing system can continue to execute the method shown in step 112 to step 122 in the embodiment shown in FIG. 3, so it will not be repeated here.
综上所述,本申请实施例提供了一种分布式事务的处理方法,该分布式事务的处理方法中,网络代理节点可以基于业务数据库的自动提交功能的状态,准确地确定用于实现事务分支的数据库操作语句的个数是否大于1。进而,该网络代理节点可以根据该数据库操作语句的个数的不同,采用不同的方式获取锁信息并创建事务分支,从而有效提高了创建事务分支的灵活性。In summary, the embodiment of the present application provides a distributed transaction processing method. In the distributed transaction processing method, the network agent node can accurately determine the status of the automatic submission function of the service database to implement the transaction. Whether the number of branched database operation statements is greater than 1. Furthermore, the network agent node can obtain lock information and create transaction branches in different ways according to the number of database operation statements, thereby effectively improving the flexibility of creating transaction branches.
在本申请实施例提供的分布式事务处理系统中,每个业务服务器中的网络代理节点均可以拦截该业务服务器中业务客户端发送的数据包,并可以检测该业务客户端发送的数据包的接收方是否为业务数据库,若该数据包的接收方为业务数据库,则网络代理节点可以获取该数据包,并对该数据包进行解析。若该数据包的接收方不为该业务数据库,则网络代理节点可以直接转发该数据包。In the distributed transaction processing system provided by the embodiment of the present application, the network agent node in each service server can intercept the data packet sent by the service client in the service server, and can detect the data packet sent by the service client. Whether the receiver is a business database, and if the receiver of the data packet is a business database, the network proxy node can obtain the data packet and analyze the data packet. If the receiver of the data packet is not the service database, the network proxy node can directly forward the data packet.
为了实现对业务客户端发送至业务数据库的数据包的有效拦截,参考图5,每个业务服务器中的网络代理节点还可以执行如下操作:In order to effectively intercept the data packets sent by the business client to the business database, referring to Figure 5, the network agent node in each business server can also perform the following operations:
步骤301、拦截业务客户端发送的数据包。Step 301: Intercept the data packet sent by the service client.
步骤302、检测该数据包是否为新建连接请求。Step 302: Detect whether the data packet is a new connection request.
对于业务客户端发送的每个数据包,网络代理节点均可以检测该数据包是否为新建连接请求。若该数据包为新建连接请求,则网络代理节点可以执行步骤303;若该数据包不为新建连接请求,则网络代理节点可以执行步骤306。For each data packet sent by the business client, the network proxy node can detect whether the data packet is a new connection request. If the data packet is a new connection request, the network proxy node can perform step 303; if the data packet is not a new connection request, the network proxy node can perform step 306.
步骤303、新建连接。Step 303: Create a new connection.
若该业务客户端发送的数据包为新建连接请求,则网络代理节点可以与该新建连接请求所请求的连接方新建连接。例如,网络代理节点可以创建与该连接方的套接字(socket)连接。之后,网络代理节点可以执行步骤304。If the data packet sent by the service client is a new connection request, the network proxy node can establish a new connection with the connecting party requested by the new connection request. For example, the network proxy node can create a socket connection with the connecting party. After that, the network agent node may perform step 304.
步骤304、检测该连接是否为与业务数据库的连接。Step 304: Detect whether the connection is a connection with a service database.
在完成与连接方的连接后,网络代理节点可以继续检测该连接是否为与业务数据库的连接。若该连接为与业务数据库的连接,则可以执行步骤305。若该连接不为与业务数据库的连接,则可以继续执行步骤301,即继续拦截业务客户端发送的数据包。例如,若该连接为与事务服务器的连接,则网络代理节点可以继续执行步骤301。After completing the connection with the connecting party, the network agent node can continue to detect whether the connection is a connection with the service database. If the connection is a connection with a service database, step 305 can be executed. If the connection is not a connection to the service database, then step 301 can be continued, that is, the data packet sent by the service client is continued to be intercepted. For example, if the connection is a connection with a transaction server, the network agent node may continue to perform step 301.
可选的,网络代理节点可以根据业务客户端与该连接方之间的连接协议,检测该连接是否为与业务数据库的连接。Optionally, the network agent node may detect whether the connection is a connection with the service database according to the connection agreement between the service client and the connection party.
步骤305、标记该连接。Step 305: Mark the connection.
若网络代理节点检测到该连接为与业务数据库的连接,则可以标记该连接。例如,网络代理节点可以在该连接的属性描述字段中添加检测标记,从而实现对该连接的标记。通过标记该与业务数据库的连接,可以便于后续快速检测业务客户端发送的数据包的接收方是否为该业务数据库。之后,网络代理节点可以继续执行步骤301,即继续拦截业务客户端发送的数 据包。If the network agent node detects that the connection is a connection to the service database, it can mark the connection. For example, the network agent node can add a detection mark in the attribute description field of the connection, so as to mark the connection. By marking the connection to the service database, it is convenient to quickly detect whether the receiver of the data packet sent by the service client is the service database. After that, the network agent node can continue to perform step 301, that is, continue to intercept data packets sent by the service client.
步骤306、检测该数据包是否属于标记的连接。Step 306: Detect whether the data packet belongs to the marked connection.
在上述步骤302中,若网络代理节点检测到该数据包不为新建连接请求,则可以继续检测该数据包是否属于标记的连接,也即是,继续检测该数据包是否为发送至业务数据库的数据包。例如,该网络代理节点可以检测该数据包所属的连接的属性描述字段中是否添加有检测标记。若添加有该检测标记,则可以确定该数据包属于标记的连接;若未添加检测标记,则可以确定该数据包不属于标记的连接。In the above step 302, if the network agent node detects that the data packet is not a new connection request, it can continue to detect whether the data packet belongs to a marked connection, that is, continue to detect whether the data packet is sent to the service database data pack. For example, the network agent node can detect whether a detection mark is added in the attribute description field of the connection to which the data packet belongs. If the detection mark is added, it can be determined that the data packet belongs to the marked connection; if the detection mark is not added, it can be determined that the data packet does not belong to the marked connection.
若该数据包属于标记的连接,则网络代理节点可以确定该数据包为发送至业务数据库的数据包,因此可以执行步骤307;若该数据包不属于标记的连接,则网络代理节点可以确定该数据包不为发送至业务数据库的数据包,因此可以执行步骤308。If the data packet belongs to a marked connection, the network proxy node can determine that the data packet is a data packet sent to the service database, so step 307 can be performed; if the data packet does not belong to a marked connection, the network proxy node can determine the The data packet is not a data packet sent to the service database, so step 308 can be executed.
示例的,参考图2,每个网络代理节点可以包括连接管理模块0121,上述步骤301至步骤306可以由该连接管理模块0121实现。For example, referring to FIG. 2, each network agent node may include a connection management module 0121, and the above steps 301 to 306 may be implemented by the connection management module 0121.
步骤307、获取并解析该数据包。Step 307: Obtain and parse the data packet.
若网络代理节点检测到该数据包属于标记的连接,则可以获取并解析该数据包。例如,网络代理节点可以基于数据库协议解析该数据包。参考图2,每个网络代理节点可以包括解析模块0122,该解析模块0122可以解析该数据包。If the network agent node detects that the data packet belongs to a marked connection, it can obtain and parse the data packet. For example, the network agent node can parse the data packet based on the database protocol. Referring to FIG. 2, each network agent node may include a parsing module 0122, and the parsing module 0122 may parse the data packet.
可选的,网络代理节点可以先检测该数据包是否为用于设置业务数据库的自动提交状态的设置指令,若该数据包为该设置指令,则网络代理节点可以执行上述步骤105或者步骤205所示的方法。若该数据包不为该设置指令,则网络代理节点可以继续检测该数据包是否为针对事务分支的提交指令或回滚指令。Optionally, the network proxy node may first detect whether the data packet is a setting instruction for setting the automatic submission status of the business database. If the data packet is the setting instruction, the network proxy node may execute the above step 105 or step 205. Indicates the method. If the data packet is not the setting instruction, the network agent node can continue to detect whether the data packet is a commit instruction or a rollback instruction for a transaction branch.
若该数据包为针对事务分支的提交指令,则网络代理节点可以执行上述步骤218和步骤219所示的方法;若该数据包为针对事务分支的回滚指令,则网络代理节点可以执行上述步骤216所示的方法。若该数据包不为针对事务分支的提交指令或回滚指令,则网络代理节点可以继续检测该数据包是否为携带有分布式事务的上下文的数据库操作指令。If the data packet is a commit instruction for a transaction branch, the network proxy node can execute the methods shown in steps 218 and 219; if the data packet is a rollback instruction for a transaction branch, the network proxy node can perform the above steps 216 shows the method. If the data packet is not a commit instruction or a rollback instruction for a transaction branch, the network agent node can continue to detect whether the data packet is a database operation instruction carrying the context of a distributed transaction.
若该数据包中并未携带分布式事务的上下文,则网络代理节点可以直接向业务数据库转发该数据包;若该数据包为携带有分布式事务的上下文的数据库操作指令,则网络代理节点可以执行上述步骤109或步骤209所示的方法。If the data packet does not carry the context of the distributed transaction, the network agent node can directly forward the data packet to the service database; if the data packet is a database operation instruction carrying the context of the distributed transaction, the network agent node can Perform the method shown in step 109 or step 209 above.
在本申请实施例中,由于网络代理节点仅需解析业务客户端发送至业务数据库的数据包,而业务客户端均基于数据库协议与业务数据库进行数据交互,因此该网络代理节点仅需支持数据库协议即可适配于不同编程语言开发得到的业务客户端。也即是,本申请实施例提供的方案可以应用于跨编程语言的分布式事务处理系统中。In the embodiment of this application, since the network proxy node only needs to parse the data packets sent by the business client to the business database, and the business clients all interact with the business database based on the database protocol, the network proxy node only needs to support the database protocol It can be adapted to business clients developed in different programming languages. That is, the solutions provided by the embodiments of the present application can be applied to a distributed transaction processing system across programming languages.
步骤308、透传该数据包。Step 308: Transparently transmit the data packet.
若网络代理节点检测到该数据包不属于标记的连接,则可以直接透传该数据包。例如,若该数据包为发送至事务服务器或者其他业务服务器的数据包,则网络代理节点可以直接透传该数据包。参考图2,每个网络代理节点可以包括透传模块0123,该透传模块0123可以透传该数据包。If the network agent node detects that the data packet does not belong to the marked connection, it can directly transparently transmit the data packet. For example, if the data packet is a data packet sent to a transaction server or other business servers, the network agent node can directly transparently transmit the data packet. Referring to FIG. 2, each network agent node may include a transparent transmission module 0123, and the transparent transmission module 0123 may transparently transmit the data packet.
综上所述,本申请实施例提供的网络代理节点拦截数据包的方法中,由于网络代理节点可以在新建与业务数据库的连接时标记该连接,因此可以便于后续快速检测业务客户端发送的数据包的接收方是否为该业务数据库,从而有效提高了检测数据包的接收方的效率。并且,由于网络代理节点根据业务客户端发送至业务数据库的数据包即可实现事务分支的创建和处理,因此网络代理节点仅需对业务客户端发送至业务数据库的数据包进行解析,而对于发送 至其他接收方的数据包则可以直接透传。由此可以避免增加网络代理节点解析的数据包的数量,提高网络代理节点解析数据包的效率。In summary, in the method for the network agent node to intercept data packets provided by the embodiments of the present application, since the network agent node can mark the connection when establishing a new connection with the service database, it can facilitate the subsequent rapid detection of the data sent by the service client Whether the receiver of the packet is the service database, thereby effectively improving the efficiency of detecting the receiver of the data packet. In addition, since the network proxy node can realize the creation and processing of transaction branches according to the data packets sent by the business client to the business database, the network proxy node only needs to parse the data packets sent by the business client to the business database. Data packets to other receivers can be directly transmitted transparently. This can avoid increasing the number of data packets parsed by the network proxy node, and improve the efficiency of the network proxy node in parsing data packets.
可选的,本申请实施例提供的分布式事务的处理方法的步骤先后顺序可以进行适当调整,步骤也可以根据情况进行相应增减。例如,步骤106可以在步骤105之前执行,步骤206可以在步骤205之前执行;步骤108可以在步骤107之前执行,步骤208可以在步骤207之前执行。或者步骤115和步骤116可以在步骤111之前执行。又或者,步骤119也可以在步骤118之前执行。再或者,步骤108也可以在步骤109之后执行,步骤208也可以在步骤209之后执行,例如步骤108可以在步骤118之后执行,步骤208可以在步骤218之后执行。任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到变化的方法,都应涵盖在本申请的保护范围之内,因此不再赘述。Optionally, the sequence of the steps of the distributed transaction processing method provided in the embodiment of the present application can be adjusted appropriately, and the steps can also be increased or decreased accordingly according to the situation. For example, step 106 can be performed before step 105, step 206 can be performed before step 205; step 108 can be performed before step 107, and step 208 can be performed before step 207. Or step 115 and step 116 can be performed before step 111. Alternatively, step 119 may also be performed before step 118. Alternatively, step 108 may be performed after step 109, and step 208 may also be performed after step 209. For example, step 108 may be performed after step 118, and step 208 may be performed after step 218. Any person familiar with the technical field can easily think of a method of change within the technical scope disclosed in this application, which should be covered by the protection scope of this application, and therefore will not be repeated.
综上所述,本申请实施例提供了一种分布式事务的处理方法,该分布式事务的处理方法中,业务客户端发送至业务数据库的数据库操作指令中可以携带有分布式事务的上下文,使得网络代理节点可以基于该分布式事务的上下文,以及该数据库操作语句来创建和处理事务分支。由于可以通过网络代理节点来创建和处理事务分支,因此无需该业务客户端部署用于创建和处理事务分支的接口(例如try、confirm和cancel接口),从而有效降低了业务客户端应用于分布式事务处理系统的开发成本。In summary, the embodiments of the present application provide a distributed transaction processing method. In the distributed transaction processing method, the database operation instructions sent by the business client to the business database can carry the context of the distributed transaction. The network agent node can create and process transaction branches based on the context of the distributed transaction and the database operation statement. Since transaction branches can be created and processed through network proxy nodes, there is no need for the business client to deploy interfaces for creating and processing transaction branches (such as try, confirm, and cancel interfaces), thereby effectively reducing the application of business clients to distributed The development cost of the transaction processing system.
并且,相比于传统的TCC技术,本申请实施例提供的方案在实现分布式事务的过程中,事务分支的创建和处理均可以由网络代理节点来实现,而业务客户端仅需要调用启动事务API、操作指令创建API以及提交/回滚事务API,上述API的调用对业务的侵入性较低,即对业务客户端原有的业务逻辑的影响较小,因此可以有效降低业务客户端在平台即服务PaaS平台中适配分布式事务处理架构,以实现业务分布式改造时的成本,提高了业务客户端进行分布式改造时的效率。而且,上述启动事务API、操作指令创建API以及提交/回滚事务API均可以由PaaS平台提供,由于上述API的功能较为简单,因此可以支持多种编程语言。由此可以确保采用不同编程语言开发实现的业务客户端在进行分布式改造时,都可以部署上述API,从而能够以较低的开发成本实现跨编程语言的分布式事务处理系统。Moreover, compared with the traditional TCC technology, in the solution provided by the embodiments of this application, in the process of realizing distributed transactions, the creation and processing of transaction branches can be realized by network proxy nodes, and the business client only needs to call to start the transaction. API, operation instruction creation API, and submit/roll back transaction API. The invocation of the above API is less intrusive to the business, that is, it has less impact on the original business logic of the business client, so it can effectively reduce the business client’s platform The distributed transaction processing architecture is adapted to the PaaS platform as a service to realize the cost of the distributed transformation of the business and improve the efficiency of the distributed transformation of the business client. Moreover, the above-mentioned startup transaction API, operation instruction creation API, and commit/rollback transaction API can all be provided by the PaaS platform. Since the functions of the above-mentioned API are relatively simple, multiple programming languages can be supported. This can ensure that business clients developed and implemented in different programming languages can deploy the above APIs when performing distributed transformations, so that a distributed transaction processing system across programming languages can be realized at a lower development cost.
此外,由于该分布式事务处理系统中的各个业务客户端均采用数据库协议与业务数据库进行数据交互,而网络代理节点可以通过携带有分布式事务的上下文的数据库操作指令来创建和处理事务分支,因此即使该分布式事务处理系统中的各个业务客户端采用不同的编程语言开发实现,也不会对网络代理节点创建和处理事务分支造成影响。也即是,基于本申请实施例提供的方案,网络代理节点仅需支持数据库协议即可适配于采用不同编程语言开发得到的业务客户端。由此可知,本申请实施例的方案能够以较低的成本,使得跨编程语言的分布式事务处理系统实现分布式事务的数据一致性。In addition, since each business client in the distributed transaction processing system uses a database protocol to interact with the business database, the network agent node can create and process transaction branches through database operation instructions that carry the context of distributed transactions. Therefore, even if each business client in the distributed transaction processing system is developed and implemented using different programming languages, it will not affect the creation and processing of transaction branches by the network agent node. That is, based on the solution provided by the embodiment of the present application, the network agent node only needs to support the database protocol to adapt to the business client developed using different programming languages. It can be seen from this that the solution of the embodiment of the present application can enable the distributed transaction processing system across programming languages to achieve data consistency of distributed transactions at a lower cost.
本申请实施例提供了一种网络代理节点,该网络代理节点可以部署于分布式事务处理系统的业务服务器中,例如可以部署于如图1或图2所示的分布式事务处理系统的业务服务器01中。参考图1和图2可以看出,该分布式事务处理系统还包括事务服务器02和多个业务数据库03,且该业务服务器01中还部署有业务客户端011。如图2所示,该网络代理节点包括:连接管理模块0121、解析模块0122、透传模块0123、事务分支处理模块0124以及数据库驱动器0125。The embodiment of the present application provides a network agent node, which can be deployed in a business server of a distributed transaction processing system, for example, can be deployed in a business server of a distributed transaction processing system as shown in FIG. 1 or FIG. 2 01 in. It can be seen with reference to FIGS. 1 and 2 that the distributed transaction processing system further includes a transaction server 02 and a plurality of service databases 03, and a service client 011 is also deployed in the service server 01. As shown in FIG. 2, the network agent node includes: a connection management module 0121, a parsing module 0122, a transparent transmission module 0123, a transaction branch processing module 0124, and a database driver 0125.
该连接管理模块0121,用于接收业务客户端发送的一个或多个数据库操作指令,并将该一个或多个数据库操作指令发送至解析模块0122。The connection management module 0121 is configured to receive one or more database operation instructions sent by the business client, and send the one or more database operation instructions to the analysis module 0122.
该解析模块0122,用于获取并解析该业务客户端发送的每个数据库操作指令,该每个数 据库操作指令包括:数据库操作语句以及分布式事务的上下文,其中,该一个或多个数据库操作指令包括的数据库操作语句用于实现该分布式事务的事务分支,该分布式事务的上下文包括该分布式事务的标识。该解析模块0122还用于将解析得到的数据库操作语句以及分布式事务的上下文发送至事务分支处理模块0124。该解析模块0122的功能实现可以参考上述方法实施例中步骤109和步骤209的相关描述。The parsing module 0122 is used to obtain and analyze each database operation instruction sent by the business client. Each database operation instruction includes: a database operation statement and a distributed transaction context, wherein the one or more database operation instructions The included database operation statement is used to implement the transaction branch of the distributed transaction, and the context of the distributed transaction includes the identifier of the distributed transaction. The parsing module 0122 is also used to send the parsed database operation statement and the context of the distributed transaction to the transaction branch processing module 0124. For the functional realization of the parsing module 0122, reference may be made to the related descriptions of step 109 and step 209 in the foregoing method embodiment.
该事务分支处理模块0124,用于:在该业务数据库中执行该数据库操作语句;以及向该事务服务器发送事务分支创建请求,该事务分支创建请求包括该分布式事务的标识。该事务分支处理模块0124的功能实现可以参考上述方法实施例中步骤111和步骤220的相关描述。The transaction branch processing module 0124 is configured to: execute the database operation statement in the business database; and send a transaction branch creation request to the transaction server, and the transaction branch creation request includes the identifier of the distributed transaction. For the functional realization of the transaction branch processing module 0124, reference may be made to the related description of step 111 and step 220 in the foregoing method embodiment.
可选的,该事务分支处理模块0124,还用于:获取数据集的锁信息,该数据集是该一个或多个数据库操作指令包括的数据库操作语句所针对的,该数据集的锁信息用于在该业务数据库中标识该数据集;相应的,该事务分支创建请求还包括该数据集的锁信息。Optionally, the transaction branch processing module 0124 is also used to: obtain lock information of a data set, the data set being targeted by a database operation statement included in the one or more database operation instructions, and the lock information of the data set The data set is identified in the business database; correspondingly, the transaction branch creation request also includes the lock information of the data set.
可选的,该事务分支处理模块0124可以用于:确定该业务数据库的自动提交功能处于开启状态,在接收到该事务服务器发送的用于指示该事务分支创建成功的第一创建响应后,在该业务数据库中执行每个数据库操作指令包括的数据库操作语句。该事务分支处理模块0124的功能实现还可以参考上述方法实施例中步骤115的相关描述。Optionally, the transaction branch processing module 0124 may be used to: determine that the automatic submission function of the business database is in an on state, and after receiving the first creation response sent by the transaction server indicating that the transaction branch is successfully created, The database operation statements included in each database operation instruction are executed in the business database. For the functional realization of the transaction branch processing module 0124, reference may also be made to the related description of step 115 in the foregoing method embodiment.
该事务分支处理模块0124,还可以用于:在接收到该事务服务器发送的用于指示该事务分支创建成功的第一创建响应后,向该业务数据库发送针对该事务分支的第一提交指令。The transaction branch processing module 0124 may be further configured to: after receiving the first creation response sent by the transaction server indicating that the transaction branch is successfully created, send the first commit instruction for the transaction branch to the business database.
可选的,该事务分支处理模块0124,还可以用于:在接收到该事务服务器发送的用于指示该事务分支创建失败的第二创建响应后,向该业务数据库发送针对该事务分支的第一回滚指令。该事务分支处理模块0124的功能实现还可以参考上述方法实施例中步骤112至步骤114以及步骤117的相关描述。Optionally, the transaction branch processing module 0124 may be further configured to: after receiving a second creation response sent by the transaction server indicating that the transaction branch creation fails, send to the business database the first creation response for the transaction branch. A rollback instruction. For the functional realization of the transaction branch processing module 0124, reference may also be made to the related descriptions of step 112 to step 114 and step 117 in the foregoing method embodiment.
可选的,该事务分支处理模块0124,还可以用于确定该业务数据库的自动提交功能处于关闭状态,向该业务客户端发送每个数据库操作指令包括的数据库操作语句的执行结果;在获取到该业务客户端发送的针对该事务分支的第二提交指令后,获取该数据集的锁信息。Optionally, the transaction branch processing module 0124 can also be used to determine that the automatic submission function of the business database is turned off, and send the execution result of the database operation statement included in each database operation instruction to the business client; After the second commit instruction for the transaction branch sent by the business client, the lock information of the data set is acquired.
其中,若用于实现该事务分支的该数据库操作语句的个数大于1,则该业务数据库的自动提交功能被该业务客户端设置为关闭状态;该第二提交指令是该业务客户端在根据该执行结果确定用于实现该事务分支的每个数据库操作语句均执行成功后发送的。该事务分支处理模块0124的功能实现还可以参考上述方法实施例中步骤210至步骤213,以及步骤219的相关描述。Wherein, if the number of database operation statements used to implement the transaction branch is greater than 1, the automatic submission function of the business database is set to the closed state by the business client; the second submission instruction is that the business client is The execution result is determined to be sent after each database operation statement used to implement the transaction branch is successfully executed. For the functional realization of the transaction branch processing module 0124, reference may also be made to the related descriptions of step 210 to step 213 and step 219 in the foregoing method embodiment.
可选的,该事务分支处理模块0124,还可以用于在向该业务客户端发送每个数据库操作指令包括的数据库操作语句的执行结果之后,获取该业务客户端发送的针对该事务分支的第二回滚指令,删除该数据集的锁信息,并向该业务数据库发送该第二回滚指令;其中,该第二回滚指令是该业务客户端在确定用于实现该事务分支的任一该数据库操作语句执行失败后发送的。其中,该第二提交指令和第二回滚指令均可以是通过连接管理模块0121和解析模块0122发送至事务分支处理模块0124的。该事务分支处理模块0124的功能实现还可以参考上述方法实施例中步骤216和步骤217的相关描述。Optionally, the transaction branch processing module 0124 can also be used to obtain the transaction branch sent by the business client after the execution result of the database operation statement included in each database operation instruction is sent to the business client. The second rollback instruction is to delete the lock information of the data set, and send the second rollback instruction to the business database; wherein, the second rollback instruction is that the business client determines any one of the transaction branches used to implement the transaction branch. Sent after the execution of the database operation statement fails. Wherein, both the second commit instruction and the second rollback instruction may be sent to the transaction branch processing module 0124 through the connection management module 0121 and the parsing module 0122. For the functional realization of the transaction branch processing module 0124, reference may also be made to the related description of step 216 and step 217 in the foregoing method embodiment.
可选的,该事务分支处理模块0124可以用于:获取该业务客户端发送的第一设置指令,根据该第一设置指令记录该业务数据库的自动提交功能为开启状态;其中,该第一设置指令是该业务客户端在确定用于实现该事务分支的该数据库操作语句的个数等于1时发送的。Optionally, the transaction branch processing module 0124 may be used to: obtain the first setting instruction sent by the business client, and record the automatic submission function of the business database as the on state according to the first setting instruction; wherein, the first setting The instruction is sent when the business client determines that the number of database operation statements used to implement the transaction branch is equal to 1.
可选的,该事务分支处理模块0124可以用于:获取该业务客户端发送的第二设置指令,根据该第二设置指令记录该业务数据库的自动提交功能为关闭状态;该第二设置指令是该业务客户端在确定用于实现该事务分支的该数据库操作语句的个数大于1时发送的。该事务分支 处理模块0124的功能实现还可以参考上述方法实施例中步骤105和步骤205的相关描述。Optionally, the transaction branch processing module 0124 may be used to: obtain a second setting instruction sent by the business client, and record according to the second setting instruction that the automatic submission function of the business database is turned off; the second setting instruction is Sent when the business client determines that the number of database operation statements used to implement the transaction branch is greater than 1. For the functional realization of the transaction branch processing module 0124, reference may also be made to the related descriptions of step 105 and step 205 in the foregoing method embodiment.
可选的,该第一创建响应中携带有该事务服务器为该事务分支分配的标识;该事务分支处理模块0124还可以用于:Optionally, the first creation response carries an identifier assigned by the transaction server to the transaction branch; the transaction branch processing module 0124 can also be used to:
在接收到该第一创建响应后,在该分布式事务的事务日志中存储该事务分支的标识以及该数据集的对应关系;接收该事务服务器发送的针对该事务分支的第三提交指令,清理该事务日志中记录的该事务分支的标识以及该数据集。或者,接收该事务服务器发送的针对该事务分支的第三回滚指令,根据该事务分支的标识从该事务日志中获取该数据集,并根据该数据集回滚该事务分支。After receiving the first creation response, store the identifier of the transaction branch and the corresponding relationship of the data set in the transaction log of the distributed transaction; receive the third commit instruction for the transaction branch sent by the transaction server, and clean up The identifier of the transaction branch and the data set recorded in the transaction log. Or, receiving the third rollback instruction for the transaction branch sent by the transaction server, obtaining the data set from the transaction log according to the identifier of the transaction branch, and rolling back the transaction branch according to the data set.
其中,该第三提交指令是该事务服务器在接收到该业务客户端发送的针对该分布式事务的提交指令后发送的,该第三回滚指令是该事务服务器在接收到该业务客户端发送的针对该分布式事务的回滚指令后发送的。该事务分支处理模块0124的功能实现还可以参考上述方法实施例中步骤116和步骤122的相关描述。Wherein, the third commit instruction is sent by the transaction server after receiving the commit instruction for the distributed transaction sent by the business client, and the third rollback instruction is sent by the transaction server after receiving the business client. Sent after the rollback instruction for the distributed transaction. For the functional implementation of the transaction branch processing module 0124, reference may also be made to the related descriptions of step 116 and step 122 in the foregoing method embodiment.
可选的,该事务分支处理模块0124还可以用于:Optionally, the transaction branch processing module 0124 can also be used to:
在向该业务数据库发送针对事务分支的第一提交指令之后,删除该数据集的锁信息。若确定该事务分支提交成功,则向该业务客户端发送用于指示该事务分支提交成功的提交结果;若确定该事务分支提交失败,则向该业务客户端发送用于指示该事务分支提交失败的提交结果,向该业务数据库发送针对该事务分支的第四回滚指令,并向该事务服务器发送携带有该事务分支的标识的通知消息,该通知消息用于指示该事务服务器删除该事务分支的锁信息。该事务分支处理模块0124的功能实现还可以参考上述方法实施例中步骤118的相关描述。After sending the first commit instruction for the transaction branch to the service database, the lock information of the data set is deleted. If it is determined that the transaction branch is submitted successfully, then send to the business client a commit result indicating that the transaction branch is submitted successfully; if it is determined that the transaction branch has failed to commit, then send to the business client to indicate that the transaction branch failed to commit Send the fourth rollback instruction for the transaction branch to the business database, and send a notification message carrying the transaction branch identifier to the transaction server, and the notification message is used to instruct the transaction server to delete the transaction branch Lock information. For the functional realization of the transaction branch processing module 0124, reference may also be made to the related description of step 118 in the foregoing method embodiment.
可选的,该连接管理模块0121可以用于:若检测到该业务客户端发送的数据包的接收方为该业务数据库,则将该数据包发送至解析模块0122;若检测到该业务客户端发送的数据包的接收方不为该业务数据库,则将该数据包发送至透传模块0123。该连接管理模块0121的功能实现可以参考上述方法实施例中步骤301至步骤306的相关描述。Optionally, the connection management module 0121 can be used to: if it is detected that the recipient of the data packet sent by the service client is the service database, send the data packet to the parsing module 0122; if the service client is detected If the recipient of the sent data packet is not the service database, the data packet is sent to the transparent transmission module 0123. For the function implementation of the connection management module 0121, reference may be made to the related descriptions of step 301 to step 306 in the foregoing method embodiment.
该解析模块0122,用于解析该数据包。该解析模块0122的功能实现可以参考上述方法实施例中步骤307的相关描述。The parsing module 0122 is used for parsing the data packet. For the functional realization of the parsing module 0122, reference may be made to the related description of step 307 in the foregoing method embodiment.
该透传模块0123,用于向该接收方转发该数据包,即透传该数据包。该透传模块0123的功能实现可以参考上述方法实施例中步骤308的相关描述。The transparent transmission module 0123 is configured to forward the data packet to the receiver, that is, transparently transmit the data packet. For the function implementation of the transparent transmission module 0123, reference may be made to the related description of step 308 in the foregoing method embodiment.
综上所述,本申请实施例提供了一种网络代理节点,该网络代理节点可以根据数据库操作指令中携带的分布式事务的上下文以及数据库操作语句来创建和处理事务分支。由于网络代理节点可以创建和处理事务分支,因此无需业务客户端部署用于创建和处理事务分支的接口(例如try、confirm和cancel接口),从而有效降低了业务客户端应用于分布式事务处理系统的开发成本。In summary, the embodiments of the present application provide a network agent node, which can create and process transaction branches according to the context of distributed transactions and database operation statements carried in database operation instructions. Since network agent nodes can create and process transaction branches, there is no need for business clients to deploy interfaces for creating and processing transaction branches (such as try, confirm, and cancel interfaces), thereby effectively reducing the application of business clients to distributed transaction processing systems Development costs.
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的网络代理节点中的各模块的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and conciseness of description, the specific working process of each module in the network agent node described above can refer to the corresponding process in the foregoing method embodiment, which will not be repeated here.
本申请实施例提供了一种业务客户端,该业务客户端可以部署于分布式事务处理系统的业务服务器中,例如可以部署于如图1或图2所示的分布式事务处理系统的业务服务器01。参考图1和图2可以看出,该分布式事务处理系统还包括事务服务器02和多个业务数据库03,且该业务服务器01中还部署有网络代理节点。如图2所示,该业务客户端可以包括:API模块0111、通信模块0112、数据库驱动器0113、服务调用模块0114以及处理模块0115。下文以该业务客户端为第一业务服务器01a中的第一业务客户端011a,且该第一业务服务器01a还包括第一网 络代理节点012a为例进行说明。The embodiment of the present application provides a business client, which can be deployed in a business server of a distributed transaction processing system, for example, can be deployed in a business server of a distributed transaction processing system as shown in FIG. 1 or FIG. 2 01. It can be seen with reference to Fig. 1 and Fig. 2 that the distributed transaction processing system further includes a transaction server 02 and a plurality of service databases 03, and a network agent node is also deployed in the service server 01. As shown in FIG. 2, the business client may include: an API module 0111, a communication module 0112, a database driver 0113, a service calling module 0114, and a processing module 0115. In the following description, the service client is the first service client 011a in the first service server 01a, and the first service server 01a further includes the first network proxy node 012a as an example.
该处理模块0115,用于根据分布式事务中该第一业务客户端待执行的事务分支,生成用于实现该事务分支的一个或多个数据库操作语句。该处理模块0115的功能实现可以参考上述方法实施例中步骤103以及步骤203的相关描述。The processing module 0115 is configured to generate one or more database operation statements for implementing the transaction branch according to the transaction branch to be executed by the first business client in the distributed transaction. For the functional realization of the processing module 0115, reference may be made to the related descriptions of step 103 and step 203 in the foregoing method embodiment.
该API模块0111,用于基于该一个或多个数据库操作语句和该分布式事务的上下文生成一个或多个数据库操作指令,其中每个数据库操作指令包括:至少一个数据库操作语句以及该分布式事务的上下文,该上下文包括该分布式事务的标识。该API模块0111的功能实现可以参考上述方法实施例中步骤106以及步骤206的相关描述。The API module 0111 is used to generate one or more database operation instructions based on the one or more database operation statements and the context of the distributed transaction, wherein each database operation instruction includes: at least one database operation statement and the distributed transaction The context, which includes the identity of the distributed transaction. For the functional realization of the API module 0111, reference may be made to the related descriptions of step 106 and step 206 in the foregoing method embodiment.
该数据库驱动器0113,用于向第一业务数据库发送该一个或多个数据库操作指令,该一个或多个数据库操作指令用于供获取到该一个或多个数据库操作指令的该第一网络代理节点创建并处理该事务分支。该数据库驱动器0113的功能实现可以参考上述方法实施例中步骤107以及步骤207的相关描述。The database driver 0113 is configured to send the one or more database operation instructions to the first service database, and the one or more database operation instructions are used for the first network agent node that obtains the one or more database operation instructions Create and process the transaction branch. For the function implementation of the database driver 0113, reference may be made to the related descriptions of step 107 and step 207 in the foregoing method embodiment.
可选的,该API模块0111,还用于响应于业务请求,向该事务服务器发送该分布式事务的创建请求;以及接收该事务服务器发送的该分布式事务的标识。该API模块0111的功能实现还可以参考上述方法实施例中步骤101、步骤102、步骤201以及步骤202的相关描述。Optionally, the API module 0111 is further configured to send the creation request of the distributed transaction to the transaction server in response to the service request; and receive the identifier of the distributed transaction sent by the transaction server. For the functional realization of the API module 0111, reference may also be made to the related descriptions of step 101, step 102, step 201, and step 202 in the foregoing method embodiment.
该服务调用模块0114,用于向参与该分布式事务的第二业务客户端发送服务调用请求,该服务调用请求中携带有该分布式事务的标识。该服务调用模块0114的功能实现可以参考上述方法实施例中步骤108以及步骤208的相关描述。The service invocation module 0114 is configured to send a service invocation request to a second business client participating in the distributed transaction, and the service invocation request carries an identifier of the distributed transaction. For the function implementation of the service calling module 0114, reference may be made to the related descriptions of step 108 and step 208 in the foregoing method embodiment.
可选的,该处理模块0115,还用于根据该业务请求,确定该分布式事务中该第一业务客户端待执行的事务分支。Optionally, the processing module 0115 is further configured to determine the transaction branch to be executed by the first business client in the distributed transaction according to the business request.
该处理模块0115,还用于接收该第一网络代理节点发送的该事务分支的提交结果,以及接收该第二业务客户端响应于该服务调用请求发送的服务调用响应。The processing module 0115 is further configured to receive the commit result of the transaction branch sent by the first network proxy node, and receive the service invocation response sent by the second business client in response to the service invocation request.
该处理模块0115,还可以用于根据该提交结果和该服务调用响应,指示该API模块0111向该事务服务器发送针对该分布式事务的提交指令或者回滚指令,其中,针对该分布式事务的提交指令用于指示提交该分布式事务包括的各个事务分支,针对该分布式事务的提交指令用于指示回滚该分布式事务包括的各个事务分支。该处理模块0115的功能实现还可以参考上述方法实施例中步骤118至步骤120的相关描述。The processing module 0115 can also be used to instruct the API module 0111 to send a commit instruction or a rollback instruction for the distributed transaction to the transaction server according to the commit result and the service call response. The commit instruction is used to instruct to submit each transaction branch included in the distributed transaction, and the commit instruction for the distributed transaction is used to instruct to roll back each transaction branch included in the distributed transaction. For the functional realization of the processing module 0115, reference may also be made to the related description of step 118 to step 120 in the foregoing method embodiment.
可选的,该处理模块0115,还可以用于:接收第二业务客户端发送的服务调用请求,该服务调用请求中携带有该分布式事务的上下文;根据该服务调用请求,确定该分布式事务中该第一业务客户端待执行的事务分支。Optionally, the processing module 0115 can also be used to: receive a service invocation request sent by a second business client, the service invocation request carries the context of the distributed transaction; according to the service invocation request, determine the distributed transaction The transaction branch to be executed by the first business client in the transaction.
可选的,该处理模块0115还可以用于:Optionally, the processing module 0115 can also be used to:
确定用于实现该事务分支的数据库操作语句的个数等于1,指示该数据库驱动器0113向该第一业务数据库发送第一设置指令,该第一设置指令用于指示将自动提交功能设置为开启状态的。It is determined that the number of database operation statements used to implement the transaction branch is equal to 1, and the database driver 0113 is instructed to send a first setting instruction to the first business database, and the first setting instruction is used to instruct to set the automatic commit function to the on state of.
或者,确定用于实现该事务分支的数据库操作语句的个数大于1,指示该数据库驱动器0113向该第一业务数据库发送第二设置指令,该第二设置指令用于指示将自动提交功能设置为关闭状态的。该处理模块0115的功能实现还可以参考上述方法实施例中步骤104以及步骤204的相关描述。Or, determining that the number of database operation statements used to implement the transaction branch is greater than 1, instructing the database driver 0113 to send a second setting instruction to the first business database, and the second setting instruction is used to instruct to set the automatic commit function to Closed. For the functional realization of the processing module 0115, reference may also be made to the related descriptions of step 104 and step 204 in the foregoing method embodiment.
可选的,该处理模块0115还可以用于:Optionally, the processing module 0115 can also be used to:
在指示数据库驱动器0113向该第一业务数据库发送用于指示将自动提交功能设置为关闭状态的第二设置指令之后,接收该第一网络代理节点发送的每个数据库操作指令包括的数据 库操作语句的执行结果;After instructing the database driver 0113 to send to the first service database the second setting instruction for instructing the automatic submission function to be set to the off state, the database operation statement included in each database operation instruction sent by the first network agent node is received Results of the;
根据该执行结果确定用于实现该事务分支的每个数据库操作语句均执行成功,指示该数据库驱动器0113向该第一业务数据库发送针对该事务分支的第二提交指令。According to the execution result, it is determined that each database operation statement used to implement the transaction branch is executed successfully, and the database driver 0113 is instructed to send a second commit instruction for the transaction branch to the first service database.
或者,根据该执行结果确定用于实现该事务分支的任一该数据库操作语句执行失败,指示该数据库驱动器0113向该第一业务数据库发送针对该事务分支的第二回滚指令。该处理模块0115的功能实现还可以参考上述方法实施例中步骤213至步骤215,以及步骤218的相关描述。Or, according to the execution result, it is determined that the execution of any of the database operation statements used to implement the transaction branch fails, and the database driver 0113 is instructed to send the second rollback instruction for the transaction branch to the first service database. For the functional realization of the processing module 0115, reference may also be made to the related descriptions of step 213 to step 215 and step 218 in the foregoing method embodiment.
可选的,该业务客户端中的API模块0111和数据库驱动器0113发送的各个请求或指令均通过该通信模块0112发送。Optionally, each request or instruction sent by the API module 0111 and the database driver 0113 in the business client is sent through the communication module 0112.
综上所述,本申请实施例提供了一种业务客户端,该业务客户端发送至业务数据库的数据库操作指令中可以携带有分布式事务的上下文,使得网络代理节点可以基于该分布式事务的上下文,以及该数据库操作语句来创建和处理事务分支。由于可以通过网络代理节点来创建和处理事务分支,因此无需该业务客户端部署用于创建和处理事务分支的接口(例如try、confirm和cancel接口),从而有效降低了业务客户端应用于分布式事务处理系统的开发成本。In summary, the embodiments of the present application provide a business client. The database operation instructions sent by the business client to the business database can carry the context of the distributed transaction, so that the network proxy node can be based on the distributed transaction. Context, and the database operation statement to create and process transaction branches. Since transaction branches can be created and processed through network proxy nodes, there is no need for the business client to deploy interfaces for creating and processing transaction branches (such as try, confirm, and cancel interfaces), thereby effectively reducing the application of business clients to distributed The development cost of the transaction processing system.
所属领域的技术人员可以清楚地了解到,为描述的方便和简洁,上述描述的业务客户端中的各模块的具体工作过程,可以参考前述方法实施例中的对应过程,在此不再赘述。Those skilled in the art can clearly understand that, for the convenience and concise description, the specific working process of each module in the business client described above can refer to the corresponding process in the foregoing method embodiment, which will not be repeated here.
应理解的是,本申请实施例提供的网络代理节点和业务客户端还可以用专用集成电路(application-specific integrated circuit,ASIC)实现,或可编程逻辑器件(programmable logic device,PLD)实现,上述PLD可以是复杂程序逻辑器件(complex programmable logical device,CPLD),现场可编程门阵列(field-programmable gate array,FPGA),通用阵列逻辑(generic array logic,GAL)或其任意组合。也可以通过软件实现上述方法实施例提供的分布式事务的处理方法,当通过软件实现上述方法实施例提供的分布式事务的处理方法时,该网络代理节点和业务客户端中的各个模块也可以为软件模块。It should be understood that the network proxy node and service client provided in the embodiments of the present application can also be implemented by an application-specific integrated circuit (ASIC) or a programmable logic device (PLD). The PLD can be a complex programmable logical device (CPLD), a field-programmable gate array (FPGA), a generic array logic (GAL) or any combination thereof. The distributed transaction processing method provided by the foregoing method embodiment can also be implemented by software. When the distributed transaction processing method provided by the foregoing method embodiment is implemented by software, the various modules in the network proxy node and the business client can also be implemented. It is a software module.
下面对本申请实施例提供的分布式事务处理系统的架构进行说明,如图6所示,该分布式事务处理系统可以为一种服务器集群,该服务器集群中包括至少一个服务器1000,各个服务器1000间通过通信网络建立通信通路。The following describes the architecture of the distributed transaction processing system provided by the embodiments of the present application. As shown in FIG. 6, the distributed transaction processing system may be a server cluster. The server cluster includes at least one server 1000, and each server 1000 Establish a communication path through the communication network.
每个服务器1000中包括总线1001、处理器1002、通信接口1003以及存储器1004。处理器1002、存储器1004和通信接口1003之间通过总线1001通信。Each server 1000 includes a bus 1001, a processor 1002, a communication interface 1003, and a memory 1004. The processor 1002, the memory 1004, and the communication interface 1003 communicate with each other through the bus 1001.
其中,处理器1002可以由一个或者多个通用处理器构成,例如中央处理器(central processing unit,CPU),或者CPU和硬件芯片的组合。上述硬件芯片可以是专用集成电路(application-specific integrated circuit,ASIC)、可编程逻辑器件(programmable logic device,PLD)或其组合。上述PLD可以是复杂可编程逻辑器件(complex programmable logic device,CPLD)、现场可编程逻辑门阵列(field-programmable gate array,FPGA)、通用阵列逻辑(generic array logic,GAL)或其任意组合。The processor 1002 may be composed of one or more general-purpose processors, such as a central processing unit (CPU), or a combination of a CPU and a hardware chip. The above-mentioned hardware chip may be an application-specific integrated circuit (ASIC), a programmable logic device (PLD), or a combination thereof. The above-mentioned PLD may be a complex programmable logic device (CPLD), a field-programmable gate array (FPGA), a general array logic (generic array logic, GAL), or any combination thereof.
存储器1004可以包括易失性存储器(volatile memory),例如随机存取存储器(random access memory,RAM)。存储器1004还可以包括非易失性存储器(non-volatile memory,NVM),例如只读存储器(read-only memory,ROM),快闪存储器,硬盘(hard disk drive,HDD)或固态硬盘(solid-state drive,SSD)。存储器1004还可以包括上述种类的组合。The memory 1004 may include a volatile memory (volatile memory), such as random access memory (RAM). The memory 1004 may also include non-volatile memory (NVM), such as read-only memory (read-only memory, ROM), flash memory, hard disk drive (HDD), or solid-state drive (solid-disk drive, HDD). state drive, SSD). The memory 1004 may also include a combination of the above types.
存储器1004中存储存可执行代码,处理器1002可以读取存储器1004中的该可执行代码实现功能,还可以通过通信接口1003与其他服务器进行通信。The memory 1004 stores executable codes, and the processor 1002 can read the executable codes in the memory 1004 to implement functions, and can also communicate with other servers through the communication interface 1003.
在本申请实施例中,每个服务器1000中的处理器1002可以实现下述功能中的一种或多种:至少一个业务客户端011的功能,至少一个网络代理节点012的功能,事务服务器02的功能,以及至少一个业务数据库03的功能。也即是,该每个服务器1000中的处理器1002可以仅实现业务客户端011、网络代理节点012、事务服务器02和业务数据库03中的一个节点的功能,或者也可以实现多个节点的功能。相应的,存储器1004中存储有用于实现该处理器1002的功能的模块。In the embodiment of the present application, the processor 1002 in each server 1000 can implement one or more of the following functions: the function of at least one service client 011, the function of at least one network agent node 012, and the transaction server 02 The functions of at least one business database 03. That is, the processor 1002 in each server 1000 may only implement the functions of one node in the business client 011, the network agent node 012, the transaction server 02, and the business database 03, or may also implement the functions of multiple nodes. . Correspondingly, the memory 1004 stores modules for realizing the functions of the processor 1002.
在本申请实施例中,多个服务器1000中的处理器1001可以协调工作,执行本申请实施例提供的分布式事务的处理方法。In the embodiment of the present application, the processors 1001 in the multiple servers 1000 may coordinate work to execute the distributed transaction processing method provided in the embodiment of the present application.
可选的,如图7所示,该分布式事务处理系统可以包括多个业务服务器2000,一个事务服务器3000以及多个数据库服务器4000。图7中仅示意性示出了两个业务服务器2000以及两个数据库服务器4000。Optionally, as shown in FIG. 7, the distributed transaction processing system may include multiple service servers 2000, one transaction server 3000, and multiple database servers 4000. Only two service servers 2000 and two database servers 4000 are schematically shown in FIG. 7.
其中,每个业务服务器2000包括总线2001、处理器2002、通信接口2003以及存储器2004。处理器2002、存储器2004和通信接口2003之间通过总线2001通信。该事务服务器3000包括总线3001、处理器3002、通信接口3003以及存储器3004。处理器3002、存储器3004和通信接口3003之间通过总线3001通信。每个数据库务服务器4000包括总线4001、处理器4002、通信接口4003以及存储器4004。处理器4002、存储器4004和通信接口4003之间通过总线4001通信。上述处理器2002、处理器3002以及处理器4002的类型可以参见处理器1002的相关说明,此处不再赘述。上述存储器2004、存储器3004以及存储器4004的类型可以参见存储器1004的相关说明,此处不再赘述。Among them, each service server 2000 includes a bus 2001, a processor 2002, a communication interface 2003, and a memory 2004. The processor 2002, the memory 2004 and the communication interface 2003 communicate through a bus 2001. The transaction server 3000 includes a bus 3001, a processor 3002, a communication interface 3003, and a memory 3004. The processor 3002, the memory 3004, and the communication interface 3003 communicate with each other through the bus 3001. Each database service server 4000 includes a bus 4001, a processor 4002, a communication interface 4003, and a memory 4004. The processor 4002, the memory 4004, and the communication interface 4003 communicate with each other through the bus 4001. For the types of the processor 2002, the processor 3002, and the processor 4002, reference may be made to the relevant description of the processor 1002, which will not be repeated here. For the types of the memory 2004, the memory 3004, and the memory 4004, please refer to the relevant description of the memory 1004, which will not be repeated here.
在本申请实施例中,每个业务服务器2000中的处理器2002可以通过运行存储器2004中的计算机程序来实现一个业务客户端011的功能,以及一个网络代理节点012的功能。相应的,如图7所示,每个业务服务器2000中的存储器2004中存储有业务客户端011的各个模块(例如API模块0111、通信模块0112、数据库驱动器0113以及服务调用模块0114),以及网络代理节点012的各个模块(例如连接管理模块0121、解析模块0122、透传模块0123、事务分支处理模块0124以及数据库驱动器0125)。In the embodiment of the present application, the processor 2002 in each service server 2000 can realize the function of a service client 011 and the function of a network agent node 012 by running a computer program in the memory 2004. Correspondingly, as shown in FIG. 7, the memory 2004 in each service server 2000 stores various modules of the service client 011 (for example, the API module 0111, the communication module 0112, the database driver 0113, and the service calling module 0114), and the network The various modules of the proxy node 012 (for example, the connection management module 0121, the analysis module 0122, the transparent transmission module 0123, the transaction branch processing module 0124, and the database driver 0125).
事务服务器3000中的处理器3002可以通过运行存储器3004中的计算机程序来实现上述实施例中事务服务器02的功能。每个数据库服务器4000中的处理器4002可以通过运行存储器4004中的计算机程序来实现上述实施例中业务数据库03的功能。The processor 3002 in the transaction server 3000 can implement the functions of the transaction server 02 in the foregoing embodiment by running a computer program in the memory 3004. The processor 4002 in each database server 4000 can implement the function of the service database 03 in the foregoing embodiment by running the computer program in the memory 4004.
综上所述,本申请实施例提供了一种分布式事务处理系统,该系统中的每个业务服务器均包括业务客户端和网络代理节,该网络代理节点可以拦截业务客户端发送的数据包。其中,业务客户端发送至业务数据库的数据库操作指令中可以携带有分布式事务的上下文,使得网络代理节点可以基于该分布式事务的上下文,以及该数据库操作语句来创建和处理事务分支。由于可以通过网络代理节点来创建和处理事务分支,因此无需该业务客户端部署用于创建和处理事务分支的接口,从而有效降低了业务客户端应用于分布式事务处理系统的开发成本。In summary, the embodiment of the present application provides a distributed transaction processing system. Each service server in the system includes a service client and a network agent node. The network agent node can intercept data packets sent by the service client. . Among them, the database operation instruction sent by the business client to the business database may carry the context of the distributed transaction, so that the network agent node can create and process the transaction branch based on the context of the distributed transaction and the database operation statement. Since the transaction branch can be created and processed through the network proxy node, there is no need for the business client to deploy an interface for creating and processing the transaction branch, thereby effectively reducing the development cost of the business client applied to the distributed transaction processing system.
本申请实施例还提供了一种计算机可读存储介质,该计算机可读存储介质中存储有指令,该指令由处理器执行以实现如上述方法实施例中由该网络代理节点执行的步骤。The embodiment of the present application also provides a computer-readable storage medium that stores instructions in the computer-readable storage medium, and the instructions are executed by a processor to implement the steps executed by the network agent node in the foregoing method embodiments.
本申请实施例还提供了一种计算机可读存储介质,该计算机可读存储介质中存储有指令,该指令由处理器执行以实现如上述方法实施例中由该业务客户端执行的步骤。The embodiment of the present application also provides a computer-readable storage medium that stores instructions in the computer-readable storage medium, and the instructions are executed by a processor to implement the steps executed by the business client in the foregoing method embodiments.
本申请实施例还提供了一种包含指令的计算机程序产品,当该计算机程序产品在计算机 上运行时,使得计算机执行上述方法实施例中由该网络代理节点执行的步骤。The embodiments of the present application also provide a computer program product containing instructions, which when the computer program product runs on a computer, cause the computer to execute the steps performed by the network agent node in the foregoing method embodiments.
本申请实施例还提供了一种包含指令的计算机程序产品,当该计算机程序产品在计算机上运行时,使得计算机执行上述方法实施例中由该业务客户端执行的步骤。The embodiments of the present application also provide a computer program product containing instructions, which when the computer program product runs on a computer, cause the computer to execute the steps executed by the business client in the foregoing method embodiments.
上述实施例,可以全部或部分地通过软件、硬件、固件或其他任意组合来实现。当使用软件实现时,上述实施例可以全部或部分地以计算机程序产品的形式实现。所述计算机程序产品包括一个或多个计算机指令。在计算机上加载或执行所述计算机程序指令时,全部或部分地产生按照本申请实施例所述的流程或功能。所述计算机可以为通用计算机、专用计算机、计算机网络、或者其他可编程装置。所述计算机指令可以存储在计算机可读存储介质中,或者从一个计算机可读存储介质向另一个计算机可读存储介质传输,例如,所述计算机指令可以从一个网站站点、计算机、服务器或数据中心通过有线(例如同轴电缆、光纤、数字用户线(DSL))或无线(例如红外、无线、微波等)方式向另一个网站站点、计算机、服务器或数据中心进行传输。所述计算机可读存储介质可以是计算机能够存取的任何可用介质或者是包含一个或多个可用介质集合的服务器、数据中心等数据存储设备。所述可用介质可以是磁性介质(例如,软盘、硬盘、磁带)、光介质(例如,DVD)、或者半导体介质。半导体介质可以是固态硬盘(solid state drive,SSD)。The above-mentioned embodiments may be implemented in whole or in part by software, hardware, firmware or any other combination. When implemented using software, the above-mentioned embodiments may be implemented in the form of a computer program product in whole or in part. The computer program product includes one or more computer instructions. When the computer program instructions are loaded or executed on a computer, the processes or functions described in the embodiments of the present application are generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website, computer, server, or data center. Transmission to another website, computer, server or data center via wired (such as coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (such as infrared, wireless, microwave, etc.). The computer-readable storage medium may be any available medium that can be accessed by a computer or a data storage device such as a server or a data center that includes one or more sets of available media. The usable medium may be a magnetic medium (for example, a floppy disk, a hard disk, a magnetic tape), an optical medium (for example, a DVD), or a semiconductor medium. The semiconductor medium may be a solid state drive (SSD).
以上所述仅为本申请的可选实施例,并不用以限制本申请,任何熟悉本技术领域的技术人员在本申请揭露的技术范围内,可轻易想到各种等效的修改、等同替换、改进等,均应包含在本申请的保护范围之内。The foregoing descriptions are only optional embodiments of the application, and are not intended to limit the application. Any person skilled in the art can easily think of various equivalent modifications, equivalent substitutions, and equivalents within the technical scope disclosed in the application. Improvements, etc., should all be included in the scope of protection of this application.

Claims (32)

  1. 一种分布式事务的处理方法,其特征在于,应用于分布式事务处理系统,所述分布式事务处理系统包括多个业务服务器、事务服务器和业务数据库,每个业务服务器包括网络代理节点和业务客户端;所述方法包括:A method for processing distributed transactions is characterized in that it is applied to a distributed transaction processing system. The distributed transaction processing system includes multiple service servers, transaction servers, and service databases, and each service server includes a network agent node and a service database. Client; the method includes:
    所述网络代理节点获取所述业务客户端发送的一个或多个数据库操作指令,每个数据库操作指令包括:数据库操作语句以及所述分布式事务的上下文,所述一个或多个数据库操作指令包括的数据库操作语句用于实现所述分布式事务的事务分支,所述分布式事务的上下文包括所述分布式事务的标识;The network agent node obtains one or more database operation instructions sent by the business client, each database operation instruction includes: a database operation statement and the context of the distributed transaction, and the one or more database operation instructions include The database operation statement of is used to implement the transaction branch of the distributed transaction, and the context of the distributed transaction includes the identifier of the distributed transaction;
    所述网络代理节点在所述业务数据库中执行每个数据库操作指令包括的数据库操作语句;The network agent node executes a database operation statement included in each database operation instruction in the service database;
    所述网络代理节点向所述事务服务器发送事务分支创建请求,所述事务分支创建请求包括所述分布式事务的标识。The network agent node sends a transaction branch creation request to the transaction server, and the transaction branch creation request includes an identifier of the distributed transaction.
  2. 根据权利要求1所述的方法,其特征在于,所述方法还包括:The method according to claim 1, wherein the method further comprises:
    所述网络代理节点获取数据集的锁信息,所述数据集是所述一个或多个数据库操作指令包括的数据库操作语句所针对的,所述数据集的锁信息用于在所述业务数据库中标识所述数据集;The network agent node obtains lock information of a data set, where the data set is targeted by a database operation statement included in the one or more database operation instructions, and the lock information of the data set is used in the service database Identify the data set;
    所述事务分支创建请求还包括所述数据集的锁信息。The transaction branch creation request also includes lock information of the data set.
  3. 根据权利要求1或2所述的方法,其特征在于,所述网络代理节点在所述业务数据库中执行每个数据库操作指令包括的数据库操作语句,包括:The method according to claim 1 or 2, wherein the execution of the database operation statement included in each database operation instruction by the network agent node in the service database comprises:
    所述网络代理节点确认所述业务数据库的自动提交功能处于开启状态;The network agent node confirms that the automatic submission function of the service database is in an on state;
    所述网络代理节点在接收到所述事务服务器发送的用于指示所述事务分支创建成功的第一创建响应后,在所述业务数据库中执行每个数据库操作指令包括的数据库操作语句;After receiving the first creation response sent by the transaction server for indicating that the transaction branch is successfully created, the network agent node executes the database operation statement included in each database operation instruction in the business database;
    所述方法还包括:所述网络代理节点响应于所述第一创建响应,向所述业务数据库发送针对所述事务分支的第一提交指令。The method further includes: in response to the first creation response, the network agent node sends a first commit instruction for the transaction branch to the service database.
  4. 根据权利要求1或2所述的方法,其特征在于,所述方法还包括:The method according to claim 1 or 2, wherein the method further comprises:
    所述网络代理节点接收所述事务服务器发送的用于指示所述事务分支创建失败的第二创建响应;Receiving, by the network proxy node, a second creation response sent by the transaction server and used to indicate that the transaction branch creation failed;
    所述网络代理节点响应于所述第二创建响应,向所述业务数据库发送针对所述事务分支的第一回滚指令。In response to the second creation response, the network agent node sends a first rollback instruction for the transaction branch to the service database.
  5. 根据权利要求2所述的方法,其特征在于,所述方法还包括:The method according to claim 2, wherein the method further comprises:
    所述网络代理节点确认所述业务数据库的自动提交功能处于关闭状态;The network agent node confirms that the automatic submission function of the service database is in a closed state;
    所述网络代理节点向所述业务客户端发送每个数据库操作指令包括的数据库操作语句的执行结果;Sending, by the network agent node, the execution result of the database operation sentence included in each database operation instruction to the business client;
    所述网络代理节点获取数据集的锁信息,包括:The acquiring of lock information of the data set by the network agent node includes:
    所述网络代理节点在获取到所述业务客户端发送的针对所述事务分支的第二提交指令后,获取所述数据集的锁信息;The network agent node acquires the lock information of the data set after acquiring the second commit instruction for the transaction branch sent by the business client;
    其中,所述第二提交指令是所述业务客户端在根据所述执行结果确定每个数据库操作指 令包括的数据库操作语句均执行成功后发送的。Wherein, the second submission instruction is sent by the business client after determining, according to the execution result, that the database operation statements included in each database operation instruction are executed successfully.
  6. 根据权利要求5所述的方法,其特征在于,在所述网络代理节点向所述业务客户端发送每个数据库操作指令包括的数据库操作语句的执行结果之后,所述方法还包括:The method according to claim 5, wherein after the network agent node sends the execution result of the database operation sentence included in each database operation instruction to the service client, the method further comprises:
    所述网络代理节点获取所述业务客户端发送的针对所述事务分支的第二回滚指令,删除所述数据集的锁信息;Acquiring, by the network proxy node, a second rollback instruction for the transaction branch sent by the business client, and deleting the lock information of the data set;
    所述网络代理节点向所述业务数据库发送所述第二回滚指令;Sending, by the network agent node, the second rollback instruction to the service database;
    其中,所述第二回滚指令是所述业务客户端在确定任一数据库操作指令包括的数据库操作语句执行失败后发送的。Wherein, the second rollback instruction is sent by the business client after determining that any database operation statement included in any database operation instruction has failed to execute.
  7. 根据权利要求3或5或6所述的方法,其特征在于,所述方法还包括:The method according to claim 3 or 5 or 6, wherein the method further comprises:
    所述网络代理节点获取所述业务客户端发送的第一设置指令;Acquiring, by the network agent node, the first setting instruction sent by the service client;
    所述网络代理节点根据所述第一设置指令记录所述业务数据库的自动提交功能为开启状态;The network agent node records, according to the first setting instruction, that the automatic submission function of the service database is turned on;
    其中,所述第一设置指令是所述业务客户端在确定用于实现所述事务分支的数据库操作语句的个数等于1时发送的。Wherein, the first setting instruction is sent when the business client determines that the number of database operation statements used to implement the transaction branch is equal to one.
  8. 根据权利要求3或5或6所述的方法,其特征在于,所述方法还包括:The method according to claim 3 or 5 or 6, wherein the method further comprises:
    所述网络代理节点获取所述业务客户端发送的第二设置指令;Acquiring, by the network agent node, a second setting instruction sent by the service client;
    所述网络代理节点根据所述第二设置指令记录所述业务数据库的自动提交功能为关闭状态;The network agent node records, according to the second setting instruction, that the automatic submission function of the service database is in a closed state;
    其中,所述第二设置指令是所述业务客户端在确定用于实现所述事务分支的数据库操作语句的个数大于1时发送的。Wherein, the second setting instruction is sent when the business client determines that the number of database operation statements used to implement the transaction branch is greater than one.
  9. 根据权利要求1至8任一所述的方法,其特征在于,所述第一创建响应中携带有所述事务服务器为所述事务分支分配的标识;所述方法还包括:The method according to any one of claims 1 to 8, wherein the first creation response carries an identifier assigned by the transaction server to the transaction branch; the method further comprises:
    所述网络代理节点在接收到所述事务服务器发送的用于指示所述事务分支创建成功的第一创建响应后,在所述分布式事务的事务日志中存储所述事务分支的标识以及所述数据集的对应关系;After the network agent node receives the first creation response sent by the transaction server for indicating the successful creation of the transaction branch, the network agent node stores the identifier of the transaction branch and the transaction log in the transaction log of the distributed transaction. Correspondence of data sets;
    所述网络代理节点接收所述事务服务器发送的针对所述事务分支的第三提交指令,清理所述事务日志中记录的所述事务分支的标识以及所述数据集;The network agent node receives the third commit instruction for the transaction branch sent by the transaction server, and clears the transaction branch identifier and the data set recorded in the transaction log;
    其中,所述第三提交指令是所述事务服务器在接收到所述业务客户端发送的针对所述分布式事务的提交指令后发送的。Wherein, the third commit instruction is sent by the transaction server after receiving the commit instruction for the distributed transaction sent by the business client.
  10. 根据权利要求1至8任一所述的方法,其特征在于,所述第一创建响应中携带有所述事务服务器为所述事务分支分配的标识;所述方法还包括:The method according to any one of claims 1 to 8, wherein the first creation response carries an identifier assigned by the transaction server to the transaction branch; the method further comprises:
    所述网络代理节点在接收到所述事务服务器发送的用于指示所述事务分支创建成功的第一创建响应后,在所述分布式事务的事务日志中存储所述事务分支的标识以及所述数据集的对应关系;After the network agent node receives the first creation response sent by the transaction server for indicating the successful creation of the transaction branch, the network agent node stores the identifier of the transaction branch and the transaction log in the transaction log of the distributed transaction. Correspondence of data sets;
    所述网络代理节点接收所述事务服务器发送的针对所述事务分支的第三回滚指令,根据所述事务分支的标识从所述事务日志中获取所述数据集,并根据所述数据集回滚所述事务分 支;The network agent node receives the third rollback instruction for the transaction branch sent by the transaction server, obtains the data set from the transaction log according to the identifier of the transaction branch, and returns according to the data set Roll the transaction branch;
    其中,所述第三回滚指令是所述事务服务器在接收到所述业务客户端发送的针对所述分布式事务的回滚指令后发送的。Wherein, the third rollback instruction is sent by the transaction server after receiving the rollback instruction for the distributed transaction sent by the business client.
  11. 一种分布式事务的处理方法,其特征在于,应用于分布式事务处理系统,所述分布式事务处理系统包括多个业务服务器、事务服务器和业务数据库,每个业务服务器包括网络代理节点和业务客户端;所述方法包括:A method for processing distributed transactions is characterized in that it is applied to a distributed transaction processing system. The distributed transaction processing system includes multiple service servers, transaction servers, and service databases, and each service server includes a network agent node and a service database. Client; the method includes:
    第一业务客户端根据所述分布式事务中所述第一业务客户端待执行的事务分支,生成用于实现所述事务分支一个或多个数据库操作语句;The first business client generates one or more database operation statements for implementing the transaction branch according to the transaction branch to be executed by the first business client in the distributed transaction;
    所述第一业务客户端根据所述一个或多个数据库操作语句,生成一个或多个数据库操作指令,每个数据库操作指令包括:至少一个数据库操作语句以及所述分布式事务的上下文,所述分布式事务的上下文包括所述分布式事务的标识;The first business client generates one or more database operation instructions according to the one or more database operation statements, and each database operation instruction includes: at least one database operation statement and the context of the distributed transaction. The context of the distributed transaction includes the identifier of the distributed transaction;
    所述第一业务客户端向第一网络代理节点发送所述一个或多个数据库操作指令,其中,所述第一网络代理节点和所述第一业务客户端部署于同一业务服务器。The first service client sends the one or more database operation instructions to a first network agent node, where the first network agent node and the first service client are deployed on the same service server.
  12. 根据权利要求11所述的方法,其特征在于,所述方法还包括:The method according to claim 11, wherein the method further comprises:
    所述第一业务客户端响应于业务请求,向所述事务服务器发送所述分布式事务的创建请求;The first service client sends the creation request of the distributed transaction to the transaction server in response to the service request;
    所述第一业务客户端接收所述事务服务器发送的所述分布式事务的标识;Receiving, by the first service client, the identifier of the distributed transaction sent by the transaction server;
    所述第一业务客户端向参与所述分布式事务的第二业务客户端发送服务调用请求,所述服务调用请求中携带有所述分布式事务的标识;Sending, by the first business client, a service invocation request to a second business client participating in the distributed transaction, and the service invocation request carries an identifier of the distributed transaction;
    所述第一业务客户端根据所述业务请求,确定所述分布式事务中所述第一业务客户端待执行的事务分支。The first business client determines the transaction branch to be executed by the first business client in the distributed transaction according to the business request.
  13. 根据权利要求12所述的方法,其特征在于,所述方法还包括:The method according to claim 12, wherein the method further comprises:
    所述第一业务客户端接收所述第一网络代理节点发送的所述事务分支的提交结果;Receiving, by the first service client, the commit result of the transaction branch sent by the first network proxy node;
    所述第一业务客户端接收所述第二业务客户端响应于所述服务调用请求发送的服务调用响应;Receiving, by the first business client, a service invocation response sent by the second business client in response to the service invocation request;
    所述第一业务客户端根据所述提交结果和所述服务调用响应,向所述事务服务器发送针对所述分布式事务的提交指令或者回滚指令;Sending, by the first business client, a commit instruction or a rollback instruction for the distributed transaction to the transaction server according to the commit result and the service invocation response;
    其中,针对所述分布式事务的提交指令用于指示提交所述分布式事务包括的各个事务分支,针对所述分布式事务的提交指令用于指示回滚所述分布式事务包括的各个事务分支。Wherein, the commit instruction for the distributed transaction is used to instruct to submit each transaction branch included in the distributed transaction, and the commit instruction for the distributed transaction is used to instruct to roll back each transaction branch included in the distributed transaction. .
  14. 根据权利要求11所述的方法,其特征在于,所述方法还包括:The method according to claim 11, wherein the method further comprises:
    所述第一业务客户端接收第二业务客户端发送的服务调用请求,所述服务调用请求中携带有所述分布式事务的上下文;Receiving, by the first business client, a service invocation request sent by a second business client, the service invocation request carrying the context of the distributed transaction;
    所述第一业务客户端根据所述服务调用请求,确定所述分布式事务中所述第一业务客户端待执行的事务分支。The first business client determines the transaction branch to be executed by the first business client in the distributed transaction according to the service invocation request.
  15. 根据权利要求11至14任一所述的方法,其特征在于,所述方法还包括:The method according to any one of claims 11 to 14, wherein the method further comprises:
    所述第一业务客户端确定所述数据库操作语句的个数等于1,向第一业务数据库发送第一 设置指令,所述第一设置指令指示将自动提交功能设置为开启状态。The first business client determines that the number of the database operation statements is equal to 1, and sends a first setting instruction to the first business database, where the first setting instruction indicates that the automatic submission function is set to an on state.
  16. 根据权利要求11至14任一所述的方法,其特征在于,所述方法还包括:The method according to any one of claims 11 to 14, wherein the method further comprises:
    所述第一业务客户端确定所述数据库操作语句的个数大于1,向第一业务数据库发送第二设置指令,所述第二设置指令指示将自动提交功能设置为关闭状态。The first business client determines that the number of the database operation statements is greater than 1, and sends a second setting instruction to the first business database, where the second setting instruction indicates that the automatic submission function is set to a closed state.
  17. 根据权利要求16所述的方法,其特征在于,所述方法还包括:The method according to claim 16, wherein the method further comprises:
    所述第一业务客户端接收每个数据库操作指令包括的数据库操作语句的执行结果;The first business client receives the execution result of the database operation sentence included in each database operation instruction;
    所述第一业务客户端根据所述执行结果确定每个数据库操作指令包括的数据库操作语句均执行成功,向所述第一业务数据库发送针对所述事务分支的第二提交指令。The first business client determines, according to the execution result, that the database operation statements included in each database operation instruction are executed successfully, and sends a second commit instruction for the transaction branch to the first business database.
  18. 根据权利要求16所述的方法,其特征在于,所述方法还包括:The method according to claim 16, wherein the method further comprises:
    所述第一业务客户端接收每个数据库操作指令包括的数据库操作语句的执行结果;The first business client receives the execution result of the database operation sentence included in each database operation instruction;
    所述第一业务客户端根据所述执行结果确定任一数据库操作指令包括的数据库操作语句执行失败,向所述第一业务数据库发送针对所述事务分支的第二回滚指令。The first business client determines, according to the execution result, that the execution of a database operation sentence included in any database operation instruction fails, and sends a second rollback instruction for the transaction branch to the first business database.
  19. 一种网络代理节点,其特征在于,应用于分布式事务处理系统,所述分布式事务处理系统包括多个业务服务器、事务服务器和业务数据库,每个业务服务器包括网络代理节点和业务客户端;所述网络代理节点包括:A network agent node is characterized by being applied to a distributed transaction processing system. The distributed transaction processing system includes a plurality of business servers, transaction servers and business databases, and each business server includes a network agent node and a business client; The network agent node includes:
    解析模块,用于获取所述业务客户端发送的一个或多个数据库操作指令,每个数据库操作指令包括:数据库操作语句以及所述分布式事务的上下文,所述一个或多个数据库操作指令包括的数据库操作语句用于实现所述分布式事务的事务分支,所述分布式事务的上下文包括所述分布式事务的标识;The parsing module is used to obtain one or more database operation instructions sent by the business client, each database operation instruction includes: a database operation statement and the context of the distributed transaction, and the one or more database operation instructions include The database operation statement of is used to implement the transaction branch of the distributed transaction, and the context of the distributed transaction includes the identifier of the distributed transaction;
    事务分支处理模块,用于在所述业务数据库中执行每个数据库操作指令包括的数据库操作语句,以及向所述事务服务器发送事务分支创建请求,所述事务分支创建请求包括所述分布式事务的标识。The transaction branch processing module is used to execute database operation statements included in each database operation instruction in the business database, and send a transaction branch creation request to the transaction server, the transaction branch creation request including the distributed transaction Logo.
  20. 根据权利要求19所述的网络代理节点,其特征在于,所述事务分支处理模块还用于:The network agent node according to claim 19, wherein the transaction branch processing module is further configured to:
    获取数据集的锁信息,所述数据集是所述一个或多个数据库操作指令包括的数据库操作语句所针对的,所述数据集的锁信息用于在所述业务数据库中标识所述数据集;Acquire lock information of a data set, the data set being targeted by a database operation statement included in the one or more database operation instructions, and the lock information of the data set is used to identify the data set in the business database ;
    所述事务分支创建请求还包括所述数据集的锁信息。The transaction branch creation request also includes lock information of the data set.
  21. 根据权利要求19或20所述的网络代理节点,其特征在于,所述事务分支处理模块,用于:The network agent node according to claim 19 or 20, wherein the transaction branch processing module is configured to:
    确认所述业务数据库的自动提交功能处于开启状态;Confirming that the automatic submission function of the business database is in an on state;
    在接收到所述事务服务器发送的用于指示所述事务分支创建成功的第一创建响应后,在所述业务数据库中执行每个数据库操作指令包括的数据库操作语句;After receiving the first creation response sent by the transaction server for indicating that the transaction branch is successfully created, execute the database operation statement included in each database operation instruction in the business database;
    所述事务分支处理模块,还用于:响应于所述第一创建响应,向所述业务数据库发送针对所述事务分支的第一提交指令。The transaction branch processing module is further configured to: in response to the first creation response, send a first commit instruction for the transaction branch to the business database.
  22. 根据权利要求19或20所述的网络代理节点,其特征在于,所述事务分支处理模块, 还用于:The network agent node according to claim 19 or 20, wherein the transaction branch processing module is further configured to:
    接收所述事务服务器发送的用于指示所述事务分支创建失败的第二创建响应;Receiving a second creation response sent by the transaction server and used to indicate that the creation of the transaction branch fails;
    响应于所述第二创建响应,向所述业务数据库发送针对所述事务分支的第一回滚指令。In response to the second creation response, a first rollback instruction for the transaction branch is sent to the service database.
  23. 根据权利要求20所述的网络代理节点,其特征在于,所述事务分支处理模块,还用于:The network agent node according to claim 20, wherein the transaction branch processing module is further configured to:
    确认所述业务数据库的自动提交功能处于关闭状态;Confirm that the automatic submission function of the business database is in a closed state;
    向所述业务客户端发送每个数据库操作指令包括的数据库操作语句的执行结果;Sending the execution result of the database operation sentence included in each database operation instruction to the business client;
    在获取到所述业务客户端发送的针对所述事务分支的第二提交指令后,获取所述数据集的锁信息;After acquiring the second commit instruction for the transaction branch sent by the business client, acquiring the lock information of the data set;
    其中,所述第二提交指令是所述业务客户端在根据所述执行结果确定每个数据库操作指令包括的数据库操作语句均执行成功后发送的。Wherein, the second submission instruction is sent by the business client after determining, according to the execution result, that the database operation statements included in each database operation instruction are executed successfully.
  24. 一种业务客户端,其特征在于,应用于分布式事务处理系统,所述分布式事务处理系统包括多个业务服务器、事务服务器和业务数据库,每个业务服务器包括网络代理节点和业务客户端;所述业务客户端包括:A business client, characterized in that it is applied to a distributed transaction processing system, the distributed transaction processing system includes a plurality of business servers, a transaction server and a business database, and each business server includes a network agent node and a business client; The business client includes:
    处理模块,用于根据所述分布式事务中所述业务客户端待执行的事务分支,生成用于实现所述事务分支一个或多个数据库操作语句;A processing module, configured to generate one or more database operation statements for implementing the transaction branch according to the transaction branch to be executed by the business client in the distributed transaction;
    应用程序接口模块,用于根据所述一个或多个数据库操作语句,生成一个或多个数据库操作指令,每个数据库操作指令包括:至少一个数据库操作语句以及所述分布式事务的上下文,所述分布式事务的上下文包括所述分布式事务的标识;The application program interface module is used to generate one or more database operation instructions according to the one or more database operation statements. Each database operation instruction includes: at least one database operation statement and the context of the distributed transaction. The context of the distributed transaction includes the identifier of the distributed transaction;
    数据库驱动器,用于向第一网络代理节点发送所述一个或多个数据库操作指令,其中,所述第一网络代理节点和所述业务客户端部署于同一业务服务器。The database driver is configured to send the one or more database operation instructions to the first network agent node, wherein the first network agent node and the service client are deployed on the same service server.
  25. 根据权利要求24所述的业务客户端,其特征在于,所述应用程序接口模块,还用于:The business client according to claim 24, wherein the application program interface module is further used for:
    响应于业务请求,向所述事务服务器发送所述分布式事务的创建请求;In response to the service request, sending the creation request of the distributed transaction to the transaction server;
    接收所述事务服务器发送的所述分布式事务的标识;Receiving the identifier of the distributed transaction sent by the transaction server;
    所述业务客户端还包括:The business client also includes:
    服务调用模块,用于向参与所述分布式事务的第二业务客户端发送服务调用请求,所述服务调用请求中携带有所述分布式事务的标识;The service invocation module is configured to send a service invocation request to a second business client participating in the distributed transaction, and the service invocation request carries an identifier of the distributed transaction;
    所述处理模块,还用于根据所述业务请求,确定所述分布式事务中所述业务客户端待执行的事务分支。The processing module is further configured to determine the transaction branch to be executed by the business client in the distributed transaction according to the business request.
  26. 根据权利要求25所述的业务客户端,其特征在于,所述处理模块,还用于:The service client according to claim 25, wherein the processing module is further configured to:
    接收所述第一网络代理节点发送的所述事务分支的提交结果;Receiving the commit result of the transaction branch sent by the first network proxy node;
    接收所述第二业务客户端响应于所述服务调用请求发送的服务调用响应;Receiving a service invocation response sent by the second business client in response to the service invocation request;
    根据所述提交结果和所述服务调用响应,向所述事务服务器发送针对所述分布式事务的提交指令或者回滚指令;Sending a commit instruction or a rollback instruction for the distributed transaction to the transaction server according to the commit result and the service invocation response;
    其中,针对所述分布式事务的提交指令用于指示提交所述分布式事务包括的各个事务分支,针对所述分布式事务的提交指令用于指示回滚所述分布式事务包括的各个事务分支。Wherein, the commit instruction for the distributed transaction is used to instruct to submit each transaction branch included in the distributed transaction, and the commit instruction for the distributed transaction is used to instruct to roll back each transaction branch included in the distributed transaction. .
  27. 根据权利要求24所述的业务客户端,其特征在于,所述处理模块,还用于:The service client according to claim 24, wherein the processing module is further configured to:
    接收第二业务客户端发送的服务调用请求,所述服务调用请求中携带有所述分布式事务的上下文;Receiving a service invocation request sent by a second business client, where the service invocation request carries the context of the distributed transaction;
    根据所述服务调用请求,确定所述分布式事务中所述业务客户端待执行的事务分支。According to the service invocation request, determine the transaction branch to be executed by the business client in the distributed transaction.
  28. 一种网络代理节点,其特征在于,所述网络代理节点包括:存储器,处理器及存储在所述存储器上并能够在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现如权利要求1至10任一所述的分布式事务的处理方法。A network agent node, characterized in that the network agent node includes a memory, a processor, and a computer program stored on the memory and capable of running on the processor, and the processor executes the computer program Realize the distributed transaction processing method according to any one of claims 1 to 10.
  29. 一种业务客户端,其特征在于,所述业务客户端包括:存储器,处理器及存储在所述存储器上并能够在所述处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现如权利要求11至18任一所述的分布式事务的处理方法。A business client, wherein the business client includes a memory, a processor, and a computer program stored in the memory and capable of running on the processor, and the processor executes the computer program Realize the distributed transaction processing method according to any one of claims 11 to 18.
  30. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质中存储有指令,所述指令由处理器执行以实现如权利要求1至10任一所述的分布式事务的处理方法。A computer-readable storage medium, characterized in that instructions are stored in the computer-readable storage medium, and the instructions are executed by a processor to implement the distributed transaction processing method according to any one of claims 1 to 10 .
  31. 一种计算机可读存储介质,其特征在于,所述计算机可读存储介质中存储有指令,所述指令由处理器执行以实现如权利要求11至18任一所述的分布式事务的处理方法。A computer-readable storage medium, characterized in that instructions are stored in the computer-readable storage medium, and the instructions are executed by a processor to implement the distributed transaction processing method according to any one of claims 11 to 18 .
  32. 一种分布式事务处理系统,其特征在于,所述分布式事务处理系统包括:多个业务服务器,事务服务器,以及多个业务数据库;A distributed transaction processing system, characterized in that the distributed transaction processing system includes: multiple business servers, transaction servers, and multiple business databases;
    每个所述业务服务器包括如权利要求19至23,以及28任一所述的网络代理节点,以及如权利要求24至27,以及29任一所述的业务客户端。Each of the service servers includes the network agent node according to any one of claims 19 to 23 and 28, and the service client according to any one of claims 24 to 27, and 29.
PCT/CN2020/114407 2020-02-29 2020-09-10 Method, apparatus and system for processing distributed transaction WO2021169243A1 (en)

Applications Claiming Priority (4)

Application Number Priority Date Filing Date Title
CN202010132037 2020-02-29
CN202010132037.5 2020-02-29
CN202010544092.5 2020-06-15
CN202010544092.5A CN113326272A (en) 2020-02-29 2020-06-15 Distributed transaction processing method, device and system

Publications (1)

Publication Number Publication Date
WO2021169243A1 true WO2021169243A1 (en) 2021-09-02

Family

ID=77413409

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/114407 WO2021169243A1 (en) 2020-02-29 2020-09-10 Method, apparatus and system for processing distributed transaction

Country Status (2)

Country Link
CN (1) CN113326272A (en)
WO (1) WO2021169243A1 (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114356888A (en) * 2021-12-30 2022-04-15 中国民航信息网络股份有限公司 Transaction processing method and device, storage medium and electronic equipment
CN117632140A (en) * 2023-12-07 2024-03-01 易方达基金管理有限公司 Business process processing method, device and storage medium

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113947434A (en) * 2021-10-21 2022-01-18 北京沃东天骏信息技术有限公司 Business processing method and device for multi-business component combination scene
CN117453750B (en) * 2023-12-21 2024-03-15 平凯星辰(北京)科技有限公司 Data processing method, device, electronic equipment and storage medium

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106033437A (en) * 2015-03-13 2016-10-19 阿里巴巴集团控股有限公司 Method and system for processing distributed transaction
CN107797850A (en) * 2016-08-30 2018-03-13 阿里巴巴集团控股有限公司 The method, apparatus and system of distributing real time system
US20190108162A1 (en) * 2010-10-20 2019-04-11 Microsoft Technology Licensing, Llc Distributed transaction management
CN110019443A (en) * 2017-09-08 2019-07-16 阿里巴巴集团控股有限公司 Non-relational database transaction methods, device and electronic equipment
CN110765178A (en) * 2019-10-18 2020-02-07 京东数字科技控股有限公司 Distributed transaction processing method and device and computer storage medium

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20190108162A1 (en) * 2010-10-20 2019-04-11 Microsoft Technology Licensing, Llc Distributed transaction management
CN106033437A (en) * 2015-03-13 2016-10-19 阿里巴巴集团控股有限公司 Method and system for processing distributed transaction
CN107797850A (en) * 2016-08-30 2018-03-13 阿里巴巴集团控股有限公司 The method, apparatus and system of distributing real time system
CN110019443A (en) * 2017-09-08 2019-07-16 阿里巴巴集团控股有限公司 Non-relational database transaction methods, device and electronic equipment
CN110765178A (en) * 2019-10-18 2020-02-07 京东数字科技控股有限公司 Distributed transaction processing method and device and computer storage medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114356888A (en) * 2021-12-30 2022-04-15 中国民航信息网络股份有限公司 Transaction processing method and device, storage medium and electronic equipment
CN117632140A (en) * 2023-12-07 2024-03-01 易方达基金管理有限公司 Business process processing method, device and storage medium

Also Published As

Publication number Publication date
CN113326272A (en) 2021-08-31

Similar Documents

Publication Publication Date Title
WO2021169243A1 (en) Method, apparatus and system for processing distributed transaction
US8433676B2 (en) Solution method of in-doubt state in two-phase commit protocol of distributed transaction
US9251194B2 (en) Automatic data request recovery after session failure
JP5841177B2 (en) Method and system for synchronization mechanism in multi-server reservation system
WO2021217986A1 (en) Distributed message transmission method and apparatus, computer device and storage medium
CN103473318B (en) A kind of distributed transaction support method towards memory data grid
US20100030880A1 (en) Failover in proxy server networks
WO2021120995A1 (en) Data synchronization method and device for databases, and storage medium
CN105512266A (en) Method and device for achieving operational consistency of distributed database
CN113010549B (en) Data processing method based on remote multi-activity system, related equipment and storage medium
CN113268471B (en) Method, proxy connection pool, system, device and medium for processing distributed transaction
CN111694873B (en) Virtual resource package processing method and device and database server
US12032952B2 (en) Service upgrade method, apparatus, and system
CN112738294B (en) Domain name resolution method and device based on block chain, electronic equipment and storage medium
US9069632B2 (en) Message processing
CN114730314A (en) Transaction submitting system and method and related equipment
CN113515352B (en) Distributed transaction different-library mode anti-transaction calling method and device
CN116204239A (en) Service processing method, device and computer readable storage medium
WO2021093671A1 (en) Task processing method, system, apparatus and device, and computer readable storage medium
WO2022206429A1 (en) Distributed transaction implementation method and distributed system
WO2022206426A1 (en) Distributed transaction processing method and system, and related device
WO2022199229A1 (en) Suspended transaction inspection method and apparatus, electronic device and storage medium
WO2022121492A1 (en) File transmission method and apparatus, computer device, and storage medium
WO2003003244A1 (en) Method of rapidly eliminating different information in databases
CN114466071B (en) MQ PaaS-based transaction message processing method and device

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20920960

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

122 Ep: pct application non-entry in european phase

Ref document number: 20920960

Country of ref document: EP

Kind code of ref document: A1