CN110888718A - Method and device for realizing distributed transaction - Google Patents

Method and device for realizing distributed transaction Download PDF

Info

Publication number
CN110888718A
CN110888718A CN201911184934.4A CN201911184934A CN110888718A CN 110888718 A CN110888718 A CN 110888718A CN 201911184934 A CN201911184934 A CN 201911184934A CN 110888718 A CN110888718 A CN 110888718A
Authority
CN
China
Prior art keywords
transaction
branch
branch transaction
operation record
distributed
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201911184934.4A
Other languages
Chinese (zh)
Inventor
王涛
伍孟轩
陈浩
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
HONGXU INFORMATION TECHNOLOGY Co Ltd WUHAN
Original Assignee
HONGXU INFORMATION TECHNOLOGY Co Ltd WUHAN
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 HONGXU INFORMATION TECHNOLOGY Co Ltd WUHAN filed Critical HONGXU INFORMATION TECHNOLOGY Co Ltd WUHAN
Priority to CN201911184934.4A priority Critical patent/CN110888718A/en
Publication of CN110888718A publication Critical patent/CN110888718A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/465Distributed object oriented systems
    • 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/242Query formulation
    • G06F16/2433Query languages
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/466Transaction processing

Abstract

The embodiment of the invention provides a method and a device for realizing distributed transactions. The method comprises the following steps: executing a branch transaction according to a pre-configured proxy data source, and writing an operation record of the branch transaction into a MySQL binlog log; registering the branch transaction and releasing the resource lock of the branch transaction. According to the method and the device for realizing the distributed transaction, provided by the embodiment of the invention, the operation record of the branch transaction is written into the MySQL binlog log, the branch transaction is registered, and the resource lock of the branch transaction is released, so that the time for locking resources can be reduced under the condition of ensuring that rollback can be realized, and the system performance can not be obviously reduced when the global transaction is realized. And the agent data source is configured in advance, so that the service code of the original system is not invaded in the whole implementation process of the distributed transaction, and the system performance is not remarkably reduced when the global transaction is implemented.

Description

Method and device for realizing distributed transaction
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method and an apparatus for implementing a distributed transaction.
Background
Most of traditional Web systems are single-body applications, one system only needs one data source, the ACID characteristic of database operation is controlled by database local transactions, along with the high-speed development of the Internet, the service logic of the system is more and more complex, the user quantity is rapidly increased, single-body applications cannot meet the maintainability of services, and face performance bottlenecks, so that service splitting and database splitting are generated, different services operate different databases, different databases are even on different servers, the traditional database local transactions cannot process the transactions crossing databases, and distributed transactions are generated.
The existing distributed transaction implementation mainly includes three methods: firstly, based on an XA protocol, a database is required to support the realization of an XA interface, no code invasion exists in use, but resources are locked in the whole process of business execution and transaction submission, so that low efficiency and even deadlock occur; secondly, based on the final consistency of the reliable message middleware, only the reliable storage of the final service message certificate is ensured, and a rollback method is required to be realized by self; thirdly, based on the TCC framework mode, the try, confirm and cancel methods are required to be realized by all the interfaces, and the service intrusion is serious. In summary, in the existing distributed transaction implementation system, the system performance is significantly reduced when a global transaction is implemented.
Disclosure of Invention
Embodiments of the present invention provide a method and an apparatus for implementing a distributed transaction, so as to solve or at least partially solve a defect that system performance is significantly reduced when a global transaction is implemented in the prior art.
In a first aspect, an embodiment of the present invention provides a method for implementing a distributed transaction, where the method includes:
executing a branch transaction according to a pre-configured proxy data source, and writing an operation record of the branch transaction into a MySQL binlog log;
registering the branch transaction and releasing the resource lock of the branch transaction.
Preferably, after registering the branch transaction, the method further includes:
receiving a rollback request for the branch transaction;
acquiring an operation record of the branch transaction in a MySQL binlog log;
and re-executing the branch transaction according to the operation record of the branch transaction.
Preferably, the step of re-executing the branch transaction according to the operation record of the branch transaction includes:
generating a reverse SQL statement according to the operation record of the branch transaction;
executing the reverse SQL statement;
the branch transaction is executed according to a pre-configured proxy data source.
Preferably, before executing the branch transaction according to the pre-configured proxy data source, the method further includes:
and opening a binlog log of the MySQL database, and setting the format of the MySQL binlog into a ROW mode.
Preferably, the step of registering the branch transaction includes:
and sending the identifier of the branch transaction and the identifier of the global transaction to which the branch transaction belongs to a transaction registration center module.
Preferably, the specific step of obtaining the operation record of the branch transaction in the MySQL binlog log includes:
and inquiring the MySQL binlog log according to the identifier of the branch transaction, and acquiring the operation record of the branch transaction.
In a second aspect, an embodiment of the present invention provides an apparatus for implementing a distributed transaction, including:
the operation module is used for executing a branch transaction according to a pre-configured proxy data source and writing an operation record of the branch transaction into a MySQL binlog log;
and the submitting module is used for registering the branch transaction and releasing the resource lock of the branch transaction.
Preferably, the apparatus for implementing distributed transaction further comprises:
a receiving module, configured to receive a rollback request of the branch transaction;
the query module is used for acquiring the operation record of the branch transaction in the MySQL binlog log;
the operation module is further configured to re-execute the branch transaction according to the operation record of the branch transaction.
In a third aspect, an embodiment of the present invention provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and when executing the computer program, the steps of the method for implementing a distributed transaction provided in any one of the various possible implementations of the first aspect are implemented.
In a fourth aspect, an embodiment of the present invention provides a non-transitory computer-readable storage medium, on which a computer program is stored, where the computer program, when executed by a processor, implements the steps of the method for implementing a distributed transaction as provided in any one of the various possible implementations of the first aspect.
According to the method and the device for realizing the distributed transaction, provided by the embodiment of the invention, the operation record of the branch transaction is written into the MySQL binlog log, the branch transaction is registered, and the resource lock of the branch transaction is released, so that the time for locking resources can be reduced under the condition of ensuring that rollback can be realized, and the system performance can not be obviously reduced when the global transaction is realized. And the agent data source is configured in advance, so that the service code of the original system is not invaded in the whole implementation process of the distributed transaction, and the system performance is not remarkably reduced when the global transaction is implemented.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and those skilled in the art can also obtain other drawings according to the drawings without creative efforts.
Fig. 1 is a schematic flow chart of an implementation method of a distributed transaction provided according to an embodiment of the present invention;
fig. 2 is a schematic structural diagram of an apparatus for implementing a distributed transaction according to an embodiment of the present invention;
fig. 3 is a schematic physical structure diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In order to overcome the above problems in the prior art, embodiments of the present invention provide a method and an apparatus for implementing distributed transactions, and the inventive concept is that an operation record of a branch transaction is stored in a MySQL binlog log, and after the branch transaction is registered, a transaction registration center can release a resource lock of a global transaction, and even if rollback is required, the resource lock can be implemented according to the MySQL binlog log, so that resource locking time can be reduced, and concurrency performance of a system can be improved.
Fig. 1 is a schematic flow chart of an implementation method of a distributed transaction according to an embodiment of the present invention. As shown in fig. 1, the method includes: and step S101, executing a branch transaction according to a pre-configured proxy data source, and writing an operation record of the branch transaction into a MySQL binlog log.
It should be noted that the execution subject of the embodiment of the present invention is a branch server.
To facilitate an understanding of embodiments of the present invention, a system for implementing distributed transactions is described. The implementation system of the distributed transaction comprises a global server and a branch server.
And the global server comprises a transaction registration center module and a global transaction manager module.
And the transaction registration center module is used for managing the global transaction and all the branch transactions nested in the global transaction.
And the global transaction manager module is used for registering global transactions with the transaction registration center module.
And the branch server is used for executing the branch transaction and registering the branch transaction with the transaction registration center module. The branch server may be implemented as a branch transaction manager.
In the embodiment of the invention, the branch server adopts the MySQL database and opens the binlog log of the MySQL database (namely the MySQL binlog log). The branch server uses a proxy data source (contained in the branch transaction manager) to proxy the original data source of the system implementing the distributed transaction.
The proxy data source can be pre-configured through the jar data packet, the service code of the original system is not invaded in the whole distributed transaction implementation process, and the performance of the system is not influenced.
The global transaction is a distributed transaction. And the implementation of the global transaction is realized based on all branch transactions nested in the global transaction.
The implementation of a distributed transaction includes two phases: a business execution phase and a transaction commit (rollback) phase.
And in the service execution phase, the opening of global transactions and the registration of branch transactions are mainly realized.
The transaction commit (rollback) phase, which primarily controls the commit or rollback of global transactions.
When a certain global transaction needs to be realized, the global transaction manager module generates a global transaction identifier Xid, and sends the global transaction identifier Xid to a transaction registration center through NIO communication to prompt the start of the global transaction identified by the identifier Xid.
And the global transaction manager module sends an instruction to the corresponding branch server, and the instruction branch server executes a certain branch transaction nested in the global transaction.
And the branch server performs operation corresponding to the branch transaction on the MySQL database on the branch server so as to realize the branch transaction. Specifically, the MySQL database may be operated by a certain micro service.
And recording the operation corresponding to the branch transaction to the MySQL database on the branch server, wherein the operation is recorded in the branch transaction.
And after the operation on the MySQL database is completed, writing the operation record of the branch transaction into a MySQL binlog log for storage.
And S102, registering the branch transaction and releasing the resource lock of the branch transaction.
Specifically, a transaction Identifier (ID) for performing an operation corresponding to the branch transaction on the MySQL database on the branch server may be used as a unique identifier branch _ ID of the branch transaction, and sent to the transaction registration center module together with the global transaction identifier Xid to complete registration of the branch transaction, and after the operation is successful, the local transaction is submitted, and the resource lock of the branch transaction is released, so that the local transaction is submitted in the service execution phase.
And the branch server returns an identifier indicating whether the database operation is successful to the transaction registration center module.
If the identifiers returned by all the branch transactions to the transaction registration center module are successful, the global transaction can be submitted because the local branch transaction is submitted in the service execution phase, and the transaction registration center module only needs to close the current global transaction and release the resource lock of the global transaction; if the identification returned by any branch transaction to the transaction registry module is unsuccessful (e.g., an exception is thrown), the transaction registry module sends a rollback request for the branch transaction to each branch server instructing the branch server to rollback the previously executed branch transaction.
The transaction registration center module collects the rollback identifications returned by all the branch servers, if all the rollback identifications are successful, the transaction is closed, the global transaction is ended, and the resource lock of the global transaction is released; if the branch rollback fails, the rollback operation is retried until successful, and the resource lock of the global transaction is released.
If there is a Call between the branch transactions, the first branch transaction may be implemented by a first micro-service on the first branch server, and a second micro-service on the second branch server may be invoked by a Remote Procedure Call (RPC) to implement the second branch transaction, and the global transaction identifier Xid is passed when the Call is made. The first branch server registers the first branch transaction and the second branch server registers the second branch transaction.
It should be noted that, in the embodiment of the present invention, in the service execution phase, after the operation corresponding to the branch transaction is completed on the MySQL database, the resource lock of the branch transaction may be released, and the local transaction is submitted, so that the resource may be used to implement the next transaction, and therefore, the performance of the system may not be significantly reduced when the global transaction is started. If rollback is needed, the rollback can be realized according to the MySQL binlog log.
The MySQL binlog log is a binary log of the MySQL database and is used for recording SQL statement (except for data query statement) information of the database operated by the user. Therefore, according to the MySQL binlog log, it can be known which operations are performed on the database in order to implement the branch transaction, so that the state before the operations are executed can be returned, and the operations can be executed again to implement rollback.
In a transaction commit (rollback) phase, a local transaction is also committed when a global transaction is committed, a resource lock of the global transaction and a resource lock of each branch transaction are released, the resource lock time is long, and the performance of a system is significantly influenced under the condition that the global transaction is started.
The embodiment of the invention writes the operation record of the branch transaction into the MySQL binlog log, registers the branch transaction and releases the resource lock of the branch transaction, so that the time for locking the resource can be reduced under the condition of ensuring that rollback can be realized, and the system performance can not be obviously reduced when the global transaction is realized. And the agent data source is configured in advance, so that the service code of the original system is not invaded in the whole implementation process of the distributed transaction, and the system performance is not remarkably reduced when the global transaction is implemented.
Based on the content of the foregoing embodiments, after registering the branch transaction, the method further includes: a rollback request for a branch transaction is received.
Specifically, if rollback is required, the transaction registry module sends a rollback request of a branch transaction to each branch server involved in the global transaction, indicating that the branch server executed before rollback is nested in the global transaction.
And acquiring the operation record of the branch transaction in the MySQL binlog log.
Specifically, by querying the MySQL binlog log, the record of the operation performed in the service execution phase and corresponding to the branch transaction performed on the MySQL database on the branch server may be obtained.
And re-executing the branch transaction according to the operation record of the branch transaction.
Specifically, according to the operation record of the branch transaction, the state before the operation is executed is returned, and the operation is re-executed, so that rollback is realized.
The embodiment of the invention realizes rollback by acquiring the operation record of the branch transaction in the MySQL binlog log, and can not cause the system performance to be remarkably reduced when the global transaction is realized.
Based on the content of the foregoing embodiments, the specific step of re-executing the branch transaction according to the operation record of the branch transaction includes: and generating a reverse SQL statement according to the operation record of the branch transaction.
Specifically, because the MySQL binlog records SQL statement (except for data query statement) information of the user on the database operation, according to the operation record of the branch transaction, the operation condition of the forward SQL statement of the operation MySQL database in the service execution phase can be obtained.
According to the operation condition of the forward SQL statement, the forward SQL statement can be analyzed.
According to the forward SQL statement, a reverse SQL statement of the forward SQL statement can be generated.
The reverse SQL statement is executed.
Specifically, a reverse SQL statement is executed, so that the MySQL database on the branch server is restored to the state before the forward SQL statement is executed.
The branch transaction is executed according to a pre-configured proxy data source.
Specifically, according to a pre-configured proxy data source, the forward SQL statement is re-executed, so that the branch transaction is re-executed.
According to the embodiment of the invention, the reverse SQL statement is generated through the operation record of the branch transaction, and the reverse SQL statement is executed to realize rollback, so that the system performance can not be obviously reduced when the global transaction is realized.
Based on the content of the foregoing embodiments, before executing the branch transaction according to the pre-configured proxy data source, the method further includes: and opening a binlog log of the MySQL database, and setting the format of the MySQL binlog into a ROW mode.
Specifically, in a typical distributed transaction implementation system, the binlog log on the branch server is in a closed state. In an embodiment of the present invention, before executing a branch transaction according to a preconfigured proxy data source, the branch server opens a binlog log on the branch server.
When the MySQL binlog log is opened, the format needs to be set to ROW mode.
There are also three formats for the MySQLbrinlog log: STATEMENT, ROW, MIXED are provided.
In the ROW mode, the MySQL binlog log does not record the context information of each SQL statement, and only needs to record which data is modified and what the data is modified.
According to the embodiment of the invention, the operation of recording the branch transaction by starting the MySQL binlog log can be realized based on rollback, and the system performance can not be remarkably reduced when the global transaction is realized.
Based on the content of the above embodiments, the specific step of registering the branch transaction includes: and sending the identifier of the branch transaction and the identifier of the global transaction to which the branch transaction belongs to a transaction registration center module.
Specifically, when registering a branch transaction, the branch _ id of the branch transaction and the id Xid of the global transaction to which the branch transaction belongs are sent to the transaction registration center module together, and the registration of the branch transaction is completed.
The embodiment of the invention completes the registration of the branch transaction by sending the identifier of the branch transaction and the identifier of the global transaction to which the branch transaction belongs to the transaction registration center module, thereby realizing rollback according to the registration information and the MySQL binlog log and not causing the system performance to be remarkably reduced when the global transaction is realized.
Based on the content of the above embodiments, the specific step of obtaining the operation record of the branch transaction in the MySQL binlog log includes: and inquiring the MySQL binlog according to the identifier of the branch transaction, and acquiring the operation record of the branch transaction.
Specifically, the rollback request of a branch transaction carries the branch _ id of the branch transaction.
The MySQL binlog log is queried according to the branch _ id of the branch transaction, and the operation record corresponding to the branch _ id can be obtained as the operation record of the branch transaction.
According to the embodiment of the invention, the MySQL binlog log is inquired according to the identifier of the branch transaction, and the operation record of the branch transaction can be more accurately and quickly acquired, so that rollback can be realized, and the system performance can not be remarkably reduced when the global transaction is realized.
To facilitate an understanding of the above-described embodiments of the present invention, the following description is given by way of an example.
The application scenario of the example is a distributed order system, account service and order service are respectively operated on different servers, respective MySQL databases are operated, remote call is performed between the services through RPC, and when rollback is needed due to other abnormalities after account deduction is successful and order generation is successful, the account deduction operation needs to be rolled back, and meanwhile, the order generation operation needs to be rolled back.
The initial data table is as follows
The user account table user _ account (id primary key, user _ id user id, Money account balance) is
Id User_id Money
1 U001 1000
The order form (id main key, user _ id user id, order _ count order quantity, Money order amount) is
Id User_id Order_count Money
The branch transaction manager is used for replacing an original data source, the transaction registry service is started, and the order service is additionally provided with a global transaction manager for controlling the opening of the transaction and the control of the transaction boundary.
The user initiates a ordering request, calls the account service module, the global transaction manager generates a global transaction identifier Xid, and sends the global transaction identifier Xid to the transaction registration center module through NIO communication to prompt the starting of the global transaction with the identifier Xid.
And executing user deduction (setting the amount of an order as 200 and the amount of a placed order as 1), using a branch transaction manager to perform deduction operation by the database operation, writing operation records into binlog logs, acquiring a transaction id of the operation as a branch _ id of the branch transaction unique identifier, carrying a global transaction identifier Xid and sending the transaction id to a transaction registration center, completing branch transaction registration, and submitting a local transaction after the operation is successful.
At this time, the user account table record is updated as follows:
Id User_id Money
1 U001 800
after the user successfully deducts money, the user calls order service by carrying a global transaction identifier Xid, a branch transaction manager executes money deduction operation, an operation record is written into a binlog log, the transaction id of the operation is obtained and used as a branch _ id of the branch transaction unique identifier, the branch _ id and the global transaction identifier Xid are sent to a transaction registration center together, the registration of the branch transaction is completed, and a local transaction is submitted after the operation is successful.
At this time, the bill table record is updated as follows:
Id User_id Order_count Money
1 U001 1 200
if the two steps of operation are successful, the global transaction manager sends an Xid and a transaction submitting signal to the transaction registration center, after the transaction registration center receives the signal, all branch transaction ids contained under the global transaction id are obtained according to the Xid, the resource lock is released, the Xid and the branch _ id records recorded by the transaction registration center are deleted asynchronously, and the global transaction is ended.
If other abnormity occurs after the two steps of operations, the user account deduction operation and the order form generation operation need to be rolled back. The global transaction manager sends an Xid and a transaction rollback signal to the transaction registration center, and after receiving the signal, the transaction registration center obtains all branch transaction ids contained under the global transaction id according to the Xid and sends the rollback signal and the branch transaction ids to the corresponding branch transaction manager.
After receiving the rollback signal and the branch transaction id, the branch transaction manager queries the binlog according to the branch transaction id to obtain database operations in corresponding transactions, and obtains the following records from the binlog according to the branch transaction id and analyzes the records into sql by the account branch transaction manager: the Update user _ account set money is 800where user _ id is U001.
Acquiring a money value of 1000 before the transaction operation from a binlog according to the user _ id; the account branch transaction manager generates a reverse SQL statement accordingly: the Update user _ account set money is 1000where user _ id is U001.
And the account branch transaction manager executes the reverse sql, and sends a rollback success identifier to the transaction registration center after the execution is successful and the Xid and the branch _ id are carried.
The user account table records after successful execution are as follows:
Id User_id Money
1 U001 1000
after receiving the rollback signal and the branch transaction id, the order branch transaction manager acquires a data operation record from the binlog according to the branch transaction id and analyzes the data operation record into a forward SQL statement: inser inter orders (id, user _ id, order _ count, money) values (1, U001,1, 200);
generating a reverse SQL statement according to the data:
Delete from order where id=1;
and executing the SQL statement to complete the deletion of the order, and sending a rollback success identifier to the transaction registration center by carrying the Xid and the branch _ id after the execution is successful. The order form after execution is as follows:
Id User_id Order_count Money
and the transaction registration center receives all rollback success identifications sent by the branch transaction managers under the Xid, releases all resource locks under the Xid, closes the global transaction and finishes the rollback of the global transaction.
If the rollback failure occurs, the transaction registration center sends a retry rollback signal to the branch transaction manager, and the branch transaction manager retries the rollback until the rollback is successful, and the resource lock is not released.
Fig. 2 is a schematic structural diagram of an apparatus for implementing a distributed transaction according to an embodiment of the present invention. Based on the content of the above embodiments, as shown in fig. 2, the apparatus includes:
the operation module 201 is configured to execute a branch transaction according to a preconfigured proxy data source, and write an operation record of the branch transaction into a MySQL binlog log;
a commit module 202, configured to register the branch transaction and release the resource lock of the branch transaction.
Specifically, the operation module 201 and the commit module 202 are electrically connected.
The operation module 201 performs an operation corresponding to the branch transaction on the MySQL database on the branch server to implement the branch transaction; and after the operation on the MySQL database is completed, writing the operation record of the branch transaction into a MySQLbrinlog log for storage.
The commit module 202 may use a transaction Identifier (ID) for performing an operation corresponding to the branch transaction on the MySQL database on the branch server as a unique identifier branch _ ID of the branch transaction, and send the unique identifier branch _ ID and the global transaction identifier Xid to the transaction registration center module together, complete registration of the branch transaction, commit the local transaction after the operation is successful, release a resource lock of the branch transaction, and implement committing the local transaction in the service execution phase.
The specific method and flow for implementing the corresponding function by each module included in the apparatus for implementing the distributed transaction according to the embodiments of the present invention are described in detail in the above embodiments of the method for implementing the distributed transaction, and details are not described herein again.
The distributed transaction implementation device is used for the distributed transaction implementation method of the foregoing embodiments. Therefore, the description and definition in the implementation method of the distributed transaction in the foregoing embodiments may be used for understanding the operation modules in the embodiments of the present invention.
The embodiment of the invention writes the operation record of the branch transaction into the MySQL binlog log, registers the branch transaction and releases the resource lock of the branch transaction, so that the time for locking the resource can be reduced under the condition of ensuring that rollback can be realized, and the system performance can not be obviously reduced when the global transaction is realized. And the agent data source is configured in advance, so that the service code of the original system is not invaded in the whole implementation process of the distributed transaction, and the system performance is not remarkably reduced when the global transaction is implemented.
Based on the content of the foregoing embodiments, the apparatus for implementing a distributed transaction further includes: the device comprises a receiving module and a query module. Wherein:
a receiving module, configured to receive a rollback request of a branch transaction;
and the query module is used for acquiring the operation record of the branch transaction in the MySQL binlog log.
And the operation module is also used for re-executing the branch transaction according to the operation record of the branch transaction.
Specifically, the transaction registry module sends a rollback request of a branch transaction to each branch server involved in the global transaction, indicating that the branch server rolled back a previously executed branch transaction nested in the global transaction.
The receive module receives a rollback request for the branch transaction.
The query module can acquire the record of the operation corresponding to the branch transaction performed by the MySQL database on the branch server in the service execution phase by querying the MySQL binlog log.
And the operation module retreats the state before the operation is executed according to the operation record of the branch transaction, and executes the operation again to realize rollback.
The embodiment of the invention realizes rollback by acquiring the operation record of the branch transaction in the MySQL binlog log, and can not cause the system performance to be remarkably reduced when the global transaction is realized.
Fig. 3 is a schematic physical structure diagram of an electronic device according to an embodiment of the present invention. Based on the content of the above embodiment, as shown in fig. 3, the electronic device may include: a processor (processor)301, a memory (memory)302, and a bus 303; wherein, the processor 301 and the memory 302 complete the communication with each other through the bus 303; the processor 301 is configured to invoke computer program instructions stored in the memory 302 and executable on the processor 301 to perform a method for implementing a distributed transaction provided by the above-described method embodiments, including, for example: executing a branch transaction according to a pre-configured proxy data source, and writing an operation record of the branch transaction into a MySQL binlog log; registering the branch transaction and releasing the resource lock of the branch transaction.
Another embodiment of the present invention discloses a computer program product, the computer program product includes a computer program stored on a non-transitory computer readable storage medium, the computer program includes program instructions, when the program instructions are executed by a computer, the computer can execute an implementation method of a distributed transaction provided by the above-mentioned method embodiments, for example, the method includes: executing a branch transaction according to a pre-configured proxy data source, and writing an operation record of the branch transaction into a MySQL binlog log; registering the branch transaction and releasing the resource lock of the branch transaction.
Furthermore, the logic instructions in the memory 302 may be implemented in software functional units and stored in a computer readable storage medium when sold or used as a stand-alone product. Based on such understanding, the technical solutions of the embodiments of the present invention may be essentially implemented or make a contribution to the prior art, or may be implemented in the form of a software product stored in a storage medium and including instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the methods of the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
Another embodiment of the present invention provides a non-transitory computer-readable storage medium, which stores computer instructions, the computer instructions causing a computer to execute a method for implementing a distributed transaction provided by the foregoing method embodiments, for example, the method includes: executing a branch transaction according to a pre-configured proxy data source, and writing an operation record of the branch transaction into a MySQL binlog log; registering the branch transaction and releasing the resource lock of the branch transaction.
The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and the parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. It is understood that the above-described technical solutions may be embodied in the form of a software product, which may be stored in a computer-readable storage medium, such as ROM/RAM, magnetic disk, optical disk, etc., and includes several instructions for enabling a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method of the above-described embodiments or some parts of the embodiments.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (10)

1. A method for implementing a distributed transaction, comprising:
executing a branch transaction according to a pre-configured proxy data source, and writing an operation record of the branch transaction into a MySQLbrinlog log;
registering the branch transaction and releasing the resource lock of the branch transaction.
2. The method for implementing distributed transaction according to claim 1, wherein after registering the branch transaction, the method further comprises:
receiving a rollback request for the branch transaction;
acquiring an operation record of the branch transaction in a MySQL binlog log;
and re-executing the branch transaction according to the operation record of the branch transaction.
3. The method for implementing distributed transaction according to claim 2, wherein the step of re-executing the branch transaction according to the operation record of the branch transaction includes:
generating a reverse SQL statement according to the operation record of the branch transaction;
executing the reverse SQL statement;
the branch transaction is executed according to a pre-configured proxy data source.
4. The method for implementing distributed transaction according to any one of claims 1 to 3, wherein before executing the branch transaction according to the pre-configured proxy data source, the method further comprises:
and opening a binlog log of the MySQL database, and setting the format of the MySQL binlog into a ROW mode.
5. The method for implementing distributed transaction according to claim 2, wherein the step of registering the branch transaction includes:
and sending the identifier of the branch transaction and the identifier of the global transaction to which the branch transaction belongs to a transaction registration center module.
6. The method of claim 5, wherein the step of obtaining the operation record of the branch transaction in the MySQL binlog log comprises:
and inquiring the MySQL binlog log according to the identifier of the branch transaction, and acquiring the operation record of the branch transaction.
7. An apparatus for implementing a distributed transaction, comprising:
the operation module is used for executing a branch transaction according to a pre-configured proxy data source and writing an operation record of the branch transaction into a MySQL binlog log;
and the submitting module is used for registering the branch transaction and releasing the resource lock of the branch transaction.
8. The apparatus for implementing distributed transaction according to claim 7, further comprising:
a receiving module, configured to receive a rollback request of the branch transaction;
the query module is used for acquiring the operation record of the branch transaction in the MySQL binlog log;
the operation module is further configured to re-execute the branch transaction according to the operation record of the branch transaction.
9. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the steps of the method for implementing distributed transactions according to any one of claims 1 to 6 when executing the program.
10. A non-transitory computer readable storage medium, on which a computer program is stored, which, when being executed by a processor, implements the steps of a method for implementing a distributed transaction according to any one of claims 1 to 6.
CN201911184934.4A 2019-11-27 2019-11-27 Method and device for realizing distributed transaction Pending CN110888718A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201911184934.4A CN110888718A (en) 2019-11-27 2019-11-27 Method and device for realizing distributed transaction

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201911184934.4A CN110888718A (en) 2019-11-27 2019-11-27 Method and device for realizing distributed transaction

Publications (1)

Publication Number Publication Date
CN110888718A true CN110888718A (en) 2020-03-17

Family

ID=69749114

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201911184934.4A Pending CN110888718A (en) 2019-11-27 2019-11-27 Method and device for realizing distributed transaction

Country Status (1)

Country Link
CN (1) CN110888718A (en)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111522631A (en) * 2020-03-23 2020-08-11 支付宝(杭州)信息技术有限公司 Distributed transaction processing method, device, server and medium
CN112559140A (en) * 2020-12-17 2021-03-26 江苏满运物流信息有限公司 Transaction control method, system, equipment and storage medium for data consistency
CN112598520A (en) * 2020-12-28 2021-04-02 中国农业银行股份有限公司 Transaction management method, device, electronic equipment and storage medium
CN112817798A (en) * 2021-02-26 2021-05-18 北京车和家信息技术有限公司 Data recovery method, device, medium and electronic equipment
CN113296896A (en) * 2020-06-09 2021-08-24 阿里巴巴集团控股有限公司 Distributed transaction processing method, device and equipment
CN113872781A (en) * 2020-06-30 2021-12-31 阿里巴巴集团控股有限公司 Transaction processing method, device, equipment and storage medium
CN114327799A (en) * 2021-12-23 2022-04-12 杭州博盾习言科技有限公司 Distributed transaction processing method and device, electronic equipment and storage medium

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110041006A1 (en) * 2009-08-12 2011-02-17 New Technology/Enterprise Limited Distributed transaction processing
CN103902560A (en) * 2012-12-25 2014-07-02 中国移动通信集团福建有限公司 Distributed transaction processing method and system
CN106033437A (en) * 2015-03-13 2016-10-19 阿里巴巴集团控股有限公司 Method and system for processing distributed transaction
CN106557514A (en) * 2015-09-29 2017-04-05 中兴通讯股份有限公司 A kind of distributed transaction rollback method and device

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20110041006A1 (en) * 2009-08-12 2011-02-17 New Technology/Enterprise Limited Distributed transaction processing
CN103902560A (en) * 2012-12-25 2014-07-02 中国移动通信集团福建有限公司 Distributed transaction processing method and system
CN106033437A (en) * 2015-03-13 2016-10-19 阿里巴巴集团控股有限公司 Method and system for processing distributed transaction
CN106557514A (en) * 2015-09-29 2017-04-05 中兴通讯股份有限公司 A kind of distributed transaction rollback method and device

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
HONGWEI YI: "Seata AT Mode", 《GITHUB》 *
YOUNG_BLOG: "Seata AT模式分布式事务源码分析", 《微信公众号YOUNGCHEN的博客》 *

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111522631A (en) * 2020-03-23 2020-08-11 支付宝(杭州)信息技术有限公司 Distributed transaction processing method, device, server and medium
CN111522631B (en) * 2020-03-23 2024-02-06 支付宝(杭州)信息技术有限公司 Distributed transaction processing method, device, server and medium
CN113296896A (en) * 2020-06-09 2021-08-24 阿里巴巴集团控股有限公司 Distributed transaction processing method, device and equipment
CN113296896B (en) * 2020-06-09 2022-05-06 阿里巴巴集团控股有限公司 Distributed transaction processing method, device and equipment
CN113872781A (en) * 2020-06-30 2021-12-31 阿里巴巴集团控股有限公司 Transaction processing method, device, equipment and storage medium
CN112559140A (en) * 2020-12-17 2021-03-26 江苏满运物流信息有限公司 Transaction control method, system, equipment and storage medium for data consistency
CN112559140B (en) * 2020-12-17 2022-07-26 江苏满运物流信息有限公司 Transaction control method, system, equipment and storage medium for data consistency
CN112598520A (en) * 2020-12-28 2021-04-02 中国农业银行股份有限公司 Transaction management method, device, electronic equipment and storage medium
CN112817798A (en) * 2021-02-26 2021-05-18 北京车和家信息技术有限公司 Data recovery method, device, medium and electronic equipment
CN114327799A (en) * 2021-12-23 2022-04-12 杭州博盾习言科技有限公司 Distributed transaction processing method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN110888718A (en) Method and device for realizing distributed transaction
US10942823B2 (en) Transaction processing system, recovery subsystem and method for operating a recovery subsystem
US8898109B2 (en) Automatic transaction retry after session failure
WO2016180164A1 (en) Method and apparatus for rolling back distributed transaction
KR101993432B1 (en) Systems and methods for supporting transaction recovery based on a strict ordering of two-phase commit calls
US7917651B2 (en) Apparatus, system, and method for asynchronous complex inbound transactions from SAP applications using service oriented architecture
CN107766080B (en) Transaction message processing method, device, equipment and system
US11681683B2 (en) Transaction compensation for single phase resources
KR20140047580A (en) Method and system for synchronization mechanism on multi-server reservation system
KR20140147812A (en) Systems and methods for supporting inline delegation of middle-tier transaction logs to database
CN112988883B (en) Database data synchronization method and device and storage medium
CN111522631A (en) Distributed transaction processing method, device, server and medium
CN111225012A (en) Transaction processing method, device and equipment
KR20080042881A (en) Transaction consistency and problematic states
US20200314078A1 (en) Inter-system linking method and node
US20190243820A1 (en) Utilizing nonce table to resolve concurrent blockchain transaction failure
CN108415758B (en) Distributed transaction coordination method and device
CN115220876A (en) Virtual resource creating method, device, program product, medium and electronic equipment
US8380679B2 (en) Method of handling transaction in a service oriented architecture environment
US20120142330A1 (en) System and Method For Transactional Application Lifecycle Management For Mobile Devices
CN112995262B (en) Distributed transaction submission method, system and computing equipment
CN111143041B (en) Data consistency method, distributed coordinator and central coordinator
CN112632093A (en) Work order processing method, device, system, storage medium and program product
US8799347B2 (en) System and method for resolving a unit of work
CA2679021C (en) System and method for transactional application lifecycle management for mobile devices

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
RJ01 Rejection of invention patent application after publication

Application publication date: 20200317

RJ01 Rejection of invention patent application after publication