WO2016180164A1 - Method and apparatus for rolling back distributed transaction - Google Patents
Method and apparatus for rolling back distributed transaction Download PDFInfo
- Publication number
- WO2016180164A1 WO2016180164A1 PCT/CN2016/079487 CN2016079487W WO2016180164A1 WO 2016180164 A1 WO2016180164 A1 WO 2016180164A1 CN 2016079487 W CN2016079487 W CN 2016079487W WO 2016180164 A1 WO2016180164 A1 WO 2016180164A1
- Authority
- WO
- WIPO (PCT)
- Prior art keywords
- transaction
- branch
- rollback
- manager
- request
- Prior art date
Links
Images
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F16/00—Information retrieval; Database structures therefor; File system structures therefor
- G06F16/20—Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
- G06F16/25—Integrating or interfacing systems involving database management systems
Definitions
- This document relates to, but is not limited to, the field of distributed databases, and in particular, to a distributed transaction rollback method and apparatus.
- Transaction is the unit of concurrency control, which is a user-defined sequence of operations. These operations are either done or not done and are an inseparable unit of work.
- Distributed transaction processing means that a transaction may involve multiple database operations.
- the key to distributed transaction processing is that there must be a way to know all the actions that the transaction does anywhere. The decision to commit or roll back the transaction must produce uniform results. (all submitted or all rolled back).
- AP Application
- which operations belong to a transaction which is defined by the AP.
- RM Resource Manager
- resource Manager generally a database, or other resource managers, such as message queues, such as JMS (Java Message Service) data sources, file systems, and so on.
- JMS Java Message Service
- TM Transaction Manager
- TM Transaction Manager
- receiving AP transaction requests managing global transactions
- managing transaction branch status managing transaction branch status
- coordinating RM processing notifying RM which operations belong to which global transactions and transaction branches. It is the core part of the entire transaction scheduling model.
- the XA protocol is a two-phase commit protocol defined by the X/Open DTP organization that uses a two-phase commit approach to manage distributed transactions.
- the TM requests all RMs to prepare to commit (ie, pre-submit) their respective transaction branches to confirm if all relevant RMs can submit their respective transaction branches.
- the partial RM receives the pre-submission, if it can submit its own transaction branch, it will record the operation itself in the transaction branch and give the TM a consent to submit the reply.
- the RM will no longer be in the Any operation is added to the transaction branch, but at this time the RM does not actually commit the transaction, and the RM operation on the shared resource has not been released (ie, it is in a locked state). If for some reason RM is unable to commit its own transaction branch, it will roll back all of its operations, release the lock on the shared resource, and return to the TM failure response.
- the TM reviews all pre-submitted results returned by the RM. If all RMs can be submitted, the TM will require all RMs to be formally submitted so that the global transaction is committed. And if any RM pre-reply returns fail, the TM will ask all other RMs to roll back their operations so that the global transaction is rolled back.
- the embodiment of the invention provides a novel distributed transaction rollback solution, which can effectively solve the defects of the current distributed transaction commit rollback technology, thereby improving the reliability and submission of distributed transactions. effectiveness.
- a distributed transaction rollback method comprising:
- the transaction manager initiates a commit request for the branch transaction of the first transaction to the resource manager of the database node associated with the first transaction;
- the transaction manager when receiving a response from any of the resource managers that fails to submit the branch transaction of the first transaction, commits to the other branch transaction that is submitting the first transaction, or submits the A branch transaction of a transaction A successful resource manager initiates a rollback request for a branch transaction of the first transaction.
- the transaction manager further includes: before the resource manager of the database node associated with the first transaction initiates the submit request of the branch transaction of the first transaction:
- the transaction manager generates a globally unique transaction identifier for the first transaction
- the method further includes: the transaction manager carrying a transaction identifier of the first transaction in a commit request of a branch transaction of the first transaction; carrying a location in a rollback request of a branch transaction of the first transaction The transaction identifier of the first transaction, and the time of submitting the request for the branch transaction of the first transaction.
- the method further includes:
- the transaction manager summarizes the rollback result fed back by the resource manager; if there is a resource manager that fails to roll back, the connection corresponds to the database node corresponding to the failed resource manager, and locks the table involved in the rollback failure.
- a distributed transaction rollback method comprising:
- the resource manager After the resource manager receives the rollback request of the branch transaction of the first transaction sent by the transaction manager, if the branch transaction of the first transaction has been committed, the transaction log corresponding to the branch transaction of the first transaction is filtered out;
- a reverse execution statement is generated, and the generated reverse execution statement is executed in reverse order as a transaction.
- the reverse execution statement refers to a statement that implements the opposite function to the original execution statement; the reverse execution refers to an execution order opposite to that at the time of submission.
- the rollback request of the branch transaction of the first transaction carries the transaction identifier of the first transaction, and the time when the submission request of the branch transaction of the first transaction is initiated;
- the transaction log corresponding to the branch transaction that filters out the first transaction includes:
- the time at which the commit request of the branch transaction of the first transaction is initiated in the parsed request, the start position of each transaction log block and the time when the first event occurs in the transaction log block Select the transaction log block in the list to determine the starting position of the selected transaction log block;
- Scanning is started from the determined start position of the transaction log block, and the transaction log block corresponding to the transaction identifier of the first transaction is found.
- the method further includes:
- the executing the reverse execution statement as a transaction in reverse order includes:
- the resource manager connects to the corresponding database node, and submits the generated reverse execution statement in units of transactions;
- the resource manager executes the generated reverse execution statement in reverse order on the corresponding database node, and receives an execution result of the reverse execution statement from the database node.
- the method before the resource manager receives the rollback request of the branch transaction of the first transaction sent by the transaction manager, the method further includes:
- the resource manager After receiving the commit request of the branch transaction initiated by the transaction manager, the resource manager submits the branch transaction to the corresponding database node, and feedbacks the branch transaction execution result response to the transaction according to the result of executing the branch transaction. Manager.
- a distributed transaction rollback device which is set in a transaction manager, and includes:
- Rollback initiation module configured to, when receiving a response from any of the resource managers that fails to submit the first transaction, to another branch transaction or submitting the first transaction
- the resource manager of the first transaction of the first transaction initiates a rollback request for the branch transaction of the first transaction.
- the identifier generating module is configured to generate a globally unique transaction identifier for the first transaction
- the commit initiating module is further configured to carry a transaction identifier of the first transaction in a commit request of a branch transaction of the first transaction;
- the rollback initiation module is further configured to carry a transaction identifier of the first transaction and a time of initiating a submission request of a branch transaction of the first transaction in a rollback request of a branch transaction of the first transaction.
- the device further includes:
- the rollback result processing module is configured to summarize the rollback result fed back by the resource manager; if there is a resource manager that fails to roll back, the database node corresponding to the resource manager that fails to roll back the connection, the lock rollback failure is involved Table.
- a distributed transaction rollback device which is set in the resource manager, and includes:
- Selecting a module configured to receive a rollback request of a branch transaction of the first transaction sent by the transaction manager, and if the branch transaction of the first transaction has been committed, filter out a transaction corresponding to the branch transaction of the first transaction Log
- the execution module is rolled back, and is set to generate a reverse execution statement according to the data and the execution statement recorded in the filtered transaction log, and execute the generated reverse execution statement as a transaction in reverse order.
- the reverse execution statement refers to a statement that implements the opposite function to the original execution statement; the reverse execution refers to an execution order opposite to that at the time of submission.
- the rollback request of the branch transaction of the first transaction carries the transaction identifier of the first transaction, and the time when the submission request of the branch transaction of the first transaction is initiated;
- the selection module filters out the transaction log corresponding to the branch transaction of the first transaction, including:
- the selecting module saves the first event in the start position of each transaction log block and the transaction log block by the time of initiating the submit request of the branch transaction of the first transaction in the parsed request Selecting a transaction log block in the list of occurrence moments, determining a start position of the selected transaction log block; starting from the determined start position of the transaction log block, finding a transaction corresponding to the transaction identifier of the first transaction
- the log is chunked.
- the device further includes:
- a feedback module configured to: when the reverse execution statement is all executed successfully, feed back to the transaction manager a rollback result indicating that the rollback is successful; and when the reverse execution statement is not all executed successfully, to the transaction
- the manager feedback indicates that the rollback result of the rollback failed, and carries the reverse execution statement that failed the execution and the table involved.
- the rollback execution module executes the generated reverse execution statement as a transaction in reverse order, including:
- the rollback execution module connects the corresponding database node, submits the generated reverse execution statement in units of transactions, executes the generated reverse execution statement in reverse order on the corresponding database node, and receives the reverse statement from the database node. The execution result to the execution statement.
- the device further includes:
- And submitting an execution module configured to submit the branch transaction to the corresponding database node after receiving the branch transaction commit request initiated by the transaction manager, and feedback the branch transaction execution result response to the transaction according to the result of executing the branch transaction Manager.
- a computer readable storage medium storing computer executable instructions for performing the above method.
- the beneficial effects of the embodiment of the present invention mainly reflect three aspects:
- the embodiment of the invention adopts a direct submission method, The original two-phase commit method of distributed transactions is abandoned, which reduces the redundant message interaction overhead and fundamentally improves the submission performance.
- FIG. 1 is a schematic flowchart of a distributed transaction rollback method according to Embodiment 1;
- Embodiment 2 is a schematic flowchart of a distributed transaction rollback method in Embodiment 2;
- Embodiment 3 is a schematic flowchart of a distributed transaction commit and rollback method in Embodiment 3;
- FIG. 4 is a schematic diagram of a distributed transaction rollback apparatus of Embodiment 4.
- FIG. 5 is a schematic diagram of a distributed transaction rollback device of Embodiment 5;
- FIG. 6 is a schematic diagram of a distributed transaction rollback system of Embodiment 6.
- Embodiment 1 A distributed transaction rollback method, as shown in FIG. 1, includes:
- the transaction manager initiates a commit request of the branch transaction of the first transaction to the resource manager of the database node associated with the first transaction; it can be seen that the embodiment discards the two-phase commit method and uses the direct commit method;
- the transaction manager if the transaction manager receives a response from all resource managers submitting the branch transaction of the first transaction successfully, it determines that the entire first transaction is successfully submitted.
- the transaction manager before the transaction manager of the database node associated with the first transaction initiates the commit request of the branch transaction of the first transaction, the transaction manager further includes: the transaction manager generating a global unique for the first transaction Transaction ID (identification);
- the method further includes: the transaction manager carrying a transaction ID of the first transaction in a commit request of a branch transaction of the first transaction; carrying a location in a rollback request of a branch transaction of the first transaction The transaction identifier of the first transaction, and the time of submitting the request for the branch transaction of the first transaction.
- the transaction manager further summarizes the rollback result fed back by the resource manager, and summarizes the result and feeds back to the client.
- the transaction manager summarizes the rollback result of the resource manager feedback (only the resource manager feedback rollback result of receiving the rollback request), and if all the rollback is successful, returning to the client, indicating that the rollback is successful As a result, the process ends; optionally, if there is a resource manager that fails to roll back, the transaction manager connection rolls back the database node corresponding to the failed resource manager, locks the table involved in the rollback failure, and waits for manual intervention, so that Ensure transactional consistency.
- Embodiment 2 A distributed transaction rollback method, as shown in FIG. 2, includes:
- S220 Generate a reverse execution statement according to the data and the execution statement recorded in the selected transaction log, and execute the reverse execution statement as a transaction in reverse order, thereby completing rollback of the local resource.
- the execution statement may be, but not limited to, a SQL (Structured Query Language) statement.
- the reverse execution statement may refer to a statement that implements the opposite function from the original execution statement; for example, if the original execution statement is plus 5, the corresponding reverse execution statement is subtracted by 5; and if the original execution statement is saved, the corresponding The reverse execution statement is read.
- the reverse execution may be performed in the reverse order of execution, such as executing SQL statements in sequence: X, Y, Z; the reverse SQL statement generated for X is X', and the reverse SQL statement generated for Y is Y', the reverse SQL statement generated for Z is Z', and the reverse execution means sequential execution: Z', Y', X'.
- the resource manager scans the transaction log when idle, and generates an index file according to the block size of the transaction log, records the start position of each transaction log block and the time when the first event in the transaction log block occurs. , thus forming a list in memory that saves these records in chronological order.
- the rollback request of the branch transaction of the first transaction carries the transaction identifier of the first transaction, and the time when the submission request of the branch transaction of the first transaction is initiated;
- the transaction log corresponding to the branch transaction that filters out the first transaction includes:
- Scanning is started from the start position of the determined transaction log block, and the transaction log block corresponding to the transaction ID of the first transaction is found.
- the method may further include:
- the executing the reverse execution statement as a transaction in reverse order includes:
- the resource manager connects to the corresponding database node, and submits the generated reverse execution statement in units of transactions;
- the resource manager performs the generated reverse verbs in reverse order on the corresponding database node a sentence, and receiving an execution result of the reverse execution statement from the database node.
- the method before the resource manager receives the rollback request of the branch transaction of the first transaction sent by the transaction manager, the method further includes:
- the resource manager After receiving the commit request of the branch transaction initiated by the transaction manager, the resource manager submits the branch transaction to the corresponding database node, and feedbacks the branch transaction execution result response according to the result of executing the branch transaction (ie, submitting The branch transaction successfully responds or submits a response to the branch transaction failure) to the transaction manager.
- Embodiment 3 This embodiment takes the MariaDB distributed system as an example.
- the process of distributed transaction submission and rollback is as follows, as shown in FIG. 3, including steps 301-306:
- the transaction manager After receiving the request for executing the transaction, the transaction manager first generates a globally unique transaction ID for the operation, and then obtains the node information list and the branch transaction of each database node according to the distribution policy, and directly to the resource manager of the related database node. Request to submit their own branch transaction. In this embodiment, it is assumed that there are two branch transactions corresponding to the database node 1 and the database node 2 respectively; the transaction manager initiates a branch transaction commit request to the resource manager 1 of the database node 1 and the resource manager 2 of the database node 2, respectively. . The resource manager 1 submits a branch transaction to the database node 1, and the resource manager 2 submits a branch transaction to the database node 2.
- the resource manager 1 feeds back a response of the branch transaction execution result (assuming that the commit branch transaction succeeds) to the transaction manager according to the result of executing the branch transaction by the database node 1, and the resource manager 2 performs the branch feedback result of the branch transaction according to the database node 2.
- the transaction execution result (assuming the commit branch transaction failed) is sent to the transaction manager.
- the transaction manager will initiate a distributed transaction back to the resource manager of the database node that has successfully submitted and is submitting (the branch transaction execution result response is not received).
- the rollback request is initiated to the resource manager 1; the rollback request mainly carries the transaction ID to be rolled back and the initiation time of the submission request (using the time to determine the transaction log range).
- the resource manager 1 connects to the database node 1, and submits the generated reverse SQL statement in units of transactions.
- the resource manager periodically scans MariaDB's current transaction log, binlog, logically splits the transaction log according to the size, records the starting position of each partition and the time of the first event, thus forming a memory. Save a list of these records in chronological order.
- the transaction log block that needs to be scanned and analyzed is initially determined from the above list (can be in the form of a list) Save) and the starting position of each transaction log partition determined.
- the binlog log is scanned according to the initially determined start position of the transaction log block, and the corresponding transaction log is filtered in the initially determined transaction log block by rolling back the transaction ID in the request.
- a reverse SQL statement is generated and written into the memory or file in units of transactions.
- the resource manager 1 feeds back the rollback result to the transaction manager: if all the reverse SQL statements are executed successfully, the resource manager 1 replies to the transaction manager to roll back the success command. If the reverse SQL statement fails to execute, the transaction manager will be replied to the reverse SQL statement and related table that failed to execute.
- the transaction manager collects the rollback results of all resource manager feedback that initiates the rollback request. If there is a rollback failure message, the related table is locked to ensure transaction consistency.
- the operational transaction will be divided into two branch transactions of the deduction of the A account and the addition of the B account, and the transaction manager first generates a globally unique transaction ID for the operational transaction, and then simultaneously to A, The resource manager of the database node where the B account is located directly initiates the corresponding score A commit request for a transaction, which carries the transaction ID.
- the transaction manager will initiate a rollback request to the resource manager of the database node where the A account that has successfully submitted the A account, and the rollback request carries this The transaction ID of the secondary branch transaction and the time point t1 at which the commit request is initiated.
- the resource manager After receiving the rollback request, the resource manager obtains the transaction log partition to be scanned according to t1 and the determined start position of each transaction log block, and then filters the filtered transaction log block by the transaction ID. Corresponding transaction log; analyze the transaction log sequentially, and generate reverse SQL statements based on the data and execution statements recorded in the transaction log, stored in memory or file (depending on the size of the reverse SQL statement), and finally by transaction These SQL statements are reversed for the unit to complete the rollback operation of the A account, and the transaction manager returns successfully after completion.
- the operation transaction will be divided into an update of the number of remaining tickets of the relevant train and an update of the ticket information of the account purchase.
- the transaction manager first generates a globally unique transaction ID for the operation transaction, and then simultaneously initiates a commit request for the corresponding branch transaction to the resource managers of the two database nodes, and the commit request carries the transaction ID.
- a database node fails to perform a branch transaction, such as the failure to perform the update of the purchase ticket information for the account, the transaction manager will initiate a rollback request to the resource manager of the database node where the remaining number of votes of the relevant train has been successfully submitted, and roll back The request carries the transaction ID of the branch transaction and the time point t1 at which the commit request is initiated.
- the resource manager After receiving the rollback request, the resource manager obtains the transaction log partition to be scanned according to t1 and the determined start position of each transaction log block, and then filters the filtered transaction log block by the transaction ID. Obtain the corresponding transaction log; analyze the transaction log sequentially, and generate reverse SQL statements based on the data and execution statements recorded in the transaction log, that is, increase the number of remaining tickets for the corresponding train The added statement is saved in the memory or file, and finally the reverse SQL statement is executed as a transaction (because it belongs to the branch transaction), thereby completing the rollback operation of the remaining ticket information of the relevant train, and replying to the transaction management after completion The rollback was successful.
- the operation transaction will be divided into an update of the remaining item quantity and a save of the user and the item's one order relationship.
- the transaction manager first generates a globally unique transaction ID for the operation transaction, and then simultaneously requests the resource manager of the database node where the relationship and the remaining commodity quantity are respectively in the user to initiate the submission request of the corresponding branch transaction, and the transaction is carried in the submission request. ID.
- a database node fails to perform a branch transaction, such as the failure to save the subscription relationship between the user and the commodity, the transaction manager will initiate a rollback request to the resource manager of the database node where the remaining commodity quantity information has been successfully submitted.
- the rollback request carries the transaction ID of the branch transaction and the time point t1 at which the commit request is initiated.
- the resource manager After receiving the rollback request, the resource manager obtains the transaction log partition to be scanned according to t1 and the determined start position of each transaction log block, and then filters the filtered transaction log block by the transaction ID.
- Corresponding transaction log ; analyze the transaction log sequentially, and generate reverse SQL statements according to the data and execution statements recorded in the transaction log, that is, delete the SQL statement of the subscription relationship between the user and the commodity, and save the reverse SQL statement in In the memory or file, the reverse SQL statement is executed in reverse by the transaction unit, thereby completing the rollback operation on the remaining item quantity information, and the global transaction manager returns successfully after completion.
- the operational transaction will be divided into two branch transactions in which the account holds the stock and the remaining funds of the account are reduced.
- the transaction manager first generates a globally unique transaction ID for the operational transaction, and then directly initiates a commit request for the corresponding branch transaction to the resource manager of the database node where the account holding stock and the remaining funds of the account are located, and the commit request carries the transaction ID. .
- the transaction manager will initiate a rollback request to the resource manager of the database node where the account has the stock quantity information that has been successfully submitted, and roll back the request.
- the resource manager After receiving the rollback request, the resource manager obtains the transaction log partition to be scanned according to t1 and the determined start position of each transaction log block, and then filters the filtered transaction log block by the transaction ID.
- Corresponding transaction log ; analyze the transaction log sequentially, and generate reverse SQL statements according to the data and execution statements recorded in the transaction log, that is, clear the SQL statement of the number of shares purchased by the user from the user account, and the reverse SQL
- the statement is stored in the memory or file, and finally these reverse SQL statements are reversely executed in units of transactions, thereby completing the rollback operation of the stock quantity information held by the account, and the global transaction manager returns successfully after completion.
- Embodiment 4 is a distributed transaction rollback device, which is disposed in a transaction manager, as shown in FIG. 4, and includes:
- the commit initiating module 41 is configured to initiate a commit request of the branch transaction of the first transaction to the resource manager of the database node associated with the first transaction;
- the rollback initiation module 42 is configured to, when receiving a response from any of the resource managers that fails to submit the branch transaction of the first transaction, to another branch transaction that is submitting the first transaction, or submit The resource manager of the branch transaction of the first transaction initiates a rollback request for the branch transaction of the first transaction.
- the device further includes:
- An identifier generation module configured to generate a globally unique transaction identifier for the first transaction
- the commit initiation module 41 is further configured to submit a request for a branch transaction of the first transaction Carrying the transaction identifier of the first transaction;
- the rollback initiation module 42 is further configured to carry a transaction identifier of the first transaction and a time of initiating a submission request of the branch transaction of the first transaction in a rollback request of a branch transaction of the first transaction.
- the device further includes:
- the rollback result processing module is configured to summarize the rollback result fed back by the resource manager; if there is a resource manager that fails to roll back, the database node corresponding to the resource manager that fails to roll back the connection, the lock rollback failure is involved Table.
- the fifth embodiment is a distributed transaction rollback device, which is disposed in the resource manager, as shown in FIG. 5, and includes:
- the selecting module 51 is configured to: after receiving the rollback request of the branch transaction of the first transaction sent by the transaction manager, if the branch transaction of the first transaction has been submitted, filtering out the branch transaction corresponding to the first transaction Transaction log
- the rollback execution module 52 is configured to generate a reverse execution statement according to the data and the execution statement recorded in the filtered transaction log, and execute the generated reverse execution statement as a transaction reverse order.
- the reverse execution statement refers to a statement that implements the opposite function to the original execution statement; the reverse execution refers to an execution order opposite to that at the time of submission.
- the rollback request of the branch transaction of the first transaction carries the transaction identifier of the first transaction, and the time when the submission request of the branch transaction of the first transaction is initiated;
- the selection module 51 filters out the transaction log corresponding to the branch transaction of the first transaction, including:
- the selection module 51 by parsing the time of submitting the commit request of the branch transaction of the first transaction in the rollback request, saves the first position in the start position of each transaction log block and the first in the transaction log block Selecting a transaction log block in the list of times when the event occurs, determining a start position of the selected transaction log block; starting from the determined start position of the transaction log block, finding a transaction identifier corresponding to the first transaction
- the transaction log is chunked.
- the device further includes:
- a feedback module configured to: when the reverse execution statement is all executed successfully, feed back to the transaction manager a rollback result indicating that the rollback is successful; and when the reverse execution statement is not all executed successfully, to the transaction
- the manager feedback indicates that the rollback result of the rollback failed, and carries the reverse execution statement that failed the execution and the table involved.
- the rollback execution module 52 executes the generated reverse execution statement as a transaction in reverse order, including:
- the rollback execution module 52 connects the corresponding database node, submits the generated reverse execution statement in units of transactions, executes the generated reverse execution statement in reverse order on the corresponding database node, and receives the reverse from the database node. Execute the execution result of the statement.
- the device further includes:
- And submitting an execution module configured to submit the branch transaction to the corresponding database node after receiving the branch transaction commit request initiated by the transaction manager, and feedback the branch transaction execution result response to the transaction according to the result of executing the branch transaction Manager.
- Embodiment 6 A distributed transaction rollback system, as shown in FIG. 6, includes:
- the transaction manager 61 is configured to receive a transaction request of the upper layer service, manage the global transaction, manage the transaction branch state, coordinate the processing of the resource manager 62, notify the resource manager 62 of which global transactions and transaction branches belong to, and the like. Transaction manager 61 is also a core part of the overall transaction scheduling model. The transaction manager 61 also includes the distributed transaction rollback device of the fourth embodiment in this embodiment.
- a plurality of resource managers 62 usually upper layer agents of database nodes, are local database monitoring programs that perform complex operations on the corresponding database nodes 63 in response to upper layer requests.
- the resource manager 62 further includes the distributed transaction rollback device in the fifth embodiment.
- the transaction manager 61 after receiving the transaction request, the transaction manager 61 initiates a branch transaction commit request to the branch manager at the resource manager 62 of the database node 63, and receives the branch transaction execution result; when there is a branch transaction that fails to commit A resource rollback request is initiated to the resource manager 62 that submitted the success and is being submitted; the resource manager 62 that received the rollback request performs a rollback operation on the corresponding database node 63 and feeds back the rollback result to the transaction manager 61.
- Embodiment 7 A computer readable storage medium storing computer executable instructions for performing the methods of Embodiment 1 and/or Embodiment 2 above.
- the embodiment of the invention adopts the direct submission method, and discards the original two-phase commit mode of the distributed transaction, thereby reducing redundant message interaction overhead, and fundamentally improving the submission performance; and adopting the direct commit transaction method and the branch transaction
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Databases & Information Systems (AREA)
- Data Mining & Analysis (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Information Retrieval, Db Structures And Fs Structures Therefor (AREA)
Abstract
A method and apparatus for rolling back a distributed transaction. The method comprises: a transaction manager initiates a request for submitting branch transactions of a first transaction, to resource managers of database nodes related to the first transaction; and when receiving a response that is sent by any resource manager and that indicates that the submission of the branch transactions of the first transaction fails, the transaction manager initiates a request for rolling back the branch transactions of the first transaction, to other resource managers that are submitting the branch transactions of the first transaction or have successfully submitted the branch transactions of the first transaction.
Description
本文涉及但不限于分布式数据库领域,尤其涉及一种分布式事务回滚方法及装置。This document relates to, but is not limited to, the field of distributed databases, and in particular, to a distributed transaction rollback method and apparatus.
事务(Transaction)是并发控制的单位,是用户定义的一个操作序列。这些操作要么都做,要么都不做,是一个不可分割的工作单位。分布式事务处理是指一个事务可能涉及多个数据库操作,分布式事务处理的关键是必须有一种方法可以知道事务在任何地方所做的所有动作,提交或回滚事务的决定必须产生统一的结果(全部提交或全部回滚)。Transaction is the unit of concurrency control, which is a user-defined sequence of operations. These operations are either done or not done and are an inseparable unit of work. Distributed transaction processing means that a transaction may involve multiple database operations. The key to distributed transaction processing is that there must be a way to know all the actions that the transaction does anywhere. The decision to commit or roll back the transaction must produce uniform results. (all submitted or all rolled back).
目前,大部分主流单机数据库都能很好的保证事务的特性,但是在分布式数据库中实现分布式事务却面临着很多难题,其中关键的一个难题是如何有效地回滚分布式事务。分布式事务有别于单机事务最大的不同是要在多个数据库节点同时进行提交,如果都能够成功,那么不需要进行其他后续操作;但一旦某个数据库节点因某种异常造成提交失败,那么其他数据库节点也要保证提交给它们的事务能停止执行或者及时回滚。由于数据库节点发生错误的随机性和发生异常的类型众多,因此如何能有效的回滚分布式事务成为保证事务一致性的一个关键问题。At present, most mainstream stand-alone databases can guarantee the characteristics of transactions well, but implementing distributed transactions in distributed databases faces many challenges. One of the key problems is how to effectively roll back distributed transactions. The biggest difference between distributed transactions and stand-alone transactions is that they are committed at the same time on multiple database nodes. If they are successful, no further operations are required. However, once a database node fails to submit due to some abnormality, then Other database nodes also ensure that transactions submitted to them can be stopped or rolled back in time. Due to the randomness of the database nodes and the types of exceptions, how to effectively roll back distributed transactions becomes a key issue to ensure transaction consistency.
目前业界使用的最多的就是由X/Open组织定义的X/Open DTP(Distributed Transaction Processing,分布事务处理)模型。该模型中有三个角色:The most commonly used in the industry is the X/Open DTP (Distributed Transaction Processing) model defined by the X/Open organization. There are three roles in this model:
AP(Application,应用程序),也就是业务层。哪些操作属于一个事务,就是AP定义的。AP (Application), which is the business layer. Which operations belong to a transaction, which is defined by the AP.
RM(Resource Manager,资源管理器),一般是数据库,也可以是其他的资源管理器,如消息队列,例如JMS(Java Message Service,Java消息服务)数据源、文件系统等。
RM (Resource Manager), generally a database, or other resource managers, such as message queues, such as JMS (Java Message Service) data sources, file systems, and so on.
TM(Transaction Manager,事务管理器),接收AP的事务请求,对全局事务进行管理,管理事务分支状态,协调RM的处理,通知RM哪些操作属于哪些全局事务以及事务分支等。是整个事务调度模型的核心部分。TM (Transaction Manager), receiving AP transaction requests, managing global transactions, managing transaction branch status, coordinating RM processing, notifying RM which operations belong to which global transactions and transaction branches. It is the core part of the entire transaction scheduling model.
XA协议是X/Open DTP组织定义的两阶段提交协议,采用两阶段提交方式来管理分布式事务。The XA protocol is a two-phase commit protocol defined by the X/Open DTP organization that uses a two-phase commit approach to manage distributed transactions.
在第一阶段,TM请求所有RM准备提交(即预提交)各自的事务分支,以确认是否所有相关RM都可以提交各自的事务分支。当局部RM收到预提交后,如果可以提交属于自己的事务分支,则将自己在该事务分支中所做的操作固定记录下来,并给TM一个同意提交的应答,此时RM将不能再在该事务分支中加入任何操作,但此时RM并没有真正提交该事务,RM对共享资源的操作还未释放(即处于锁定状态)。如果由于某种原因RM无法提交属于自己的事务分支,它将回滚自己的所有操作,释放对共享资源的锁定,并返回给TM失败应答。In the first phase, the TM requests all RMs to prepare to commit (ie, pre-submit) their respective transaction branches to confirm if all relevant RMs can submit their respective transaction branches. When the partial RM receives the pre-submission, if it can submit its own transaction branch, it will record the operation itself in the transaction branch and give the TM a consent to submit the reply. At this time, the RM will no longer be in the Any operation is added to the transaction branch, but at this time the RM does not actually commit the transaction, and the RM operation on the shared resource has not been released (ie, it is in a locked state). If for some reason RM is unable to commit its own transaction branch, it will roll back all of its operations, release the lock on the shared resource, and return to the TM failure response.
在第二阶段,TM审查所有RM返回的预提交结果,如所有RM都可以提交,TM将要求所有RM做正式提交,这样该全局事务被提交。而如果有任一RM预提交返回失败,TM将要求所有其它RM回滚其操作,这样该全局事务被回滚。In the second phase, the TM reviews all pre-submitted results returned by the RM. If all RMs can be submitted, the TM will require all RMs to be formally submitted so that the global transaction is committed. And if any RM pre-reply returns fail, the TM will ask all other RMs to roll back their operations so that the global transaction is rolled back.
但这种模式有几个明显的缺点,首先虽然采用这种两阶段提交的方式,但是仍然无法避免第二阶段时数据库节点发生异常,从而导致数据不一致的情况;其次,由于每次事务都采用两阶段提交,因此系统在提交事务时对每个相关的数据库节点要多产生一次交互过程,使得提交性能下降;再者,使用该模式必须要保证所有数据库节点支持XA协议。However, this model has several obvious shortcomings. First of all, although this two-phase commit method is adopted, it is still impossible to avoid the abnormality of the database node in the second phase, which leads to data inconsistency. Secondly, since each transaction is adopted Two-phase commit, so the system will generate an interaction process for each related database node when committing the transaction, which will reduce the submission performance. Moreover, the use of this mode must ensure that all database nodes support the XA protocol.
发明内容Summary of the invention
以下是对本文详细描述的主题的概述。本概述并非是为了限制权利要求的保护范围。The following is an overview of the topics detailed in this document. This Summary is not intended to limit the scope of the claims.
本发明实施例提供一种新型的分布式事务回滚方案,能够有效解决目前分布式事务提交回滚技术方面的缺陷,从而提升分布式事务的可靠性和提交
效率。The embodiment of the invention provides a novel distributed transaction rollback solution, which can effectively solve the defects of the current distributed transaction commit rollback technology, thereby improving the reliability and submission of distributed transactions.
effectiveness.
本发明实施例采用如下技术方案。The embodiments of the present invention adopt the following technical solutions.
一种分布式事务回滚方法,包括:A distributed transaction rollback method, comprising:
事务管理器向和第一事务相关的数据库节点的资源管理器发起第一事务的分支事务的提交请求;The transaction manager initiates a commit request for the branch transaction of the first transaction to the resource manager of the database node associated with the first transaction;
所述事务管理器当收到任一所述资源管理器发来的提交所述第一事务的分支事务失败的响应时,向其它正在提交所述第一事务的分支事务、或者提交所述第一事务的分支事务成功的资源管理器发起所述第一事务的分支事务的回滚请求。The transaction manager, when receiving a response from any of the resource managers that fails to submit the branch transaction of the first transaction, commits to the other branch transaction that is submitting the first transaction, or submits the A branch transaction of a transaction A successful resource manager initiates a rollback request for a branch transaction of the first transaction.
可选地,所述事务管理器向和第一事务相关的数据库节点的资源管理器发起第一事务的分支事务的提交请求前还包括:Optionally, the transaction manager further includes: before the resource manager of the database node associated with the first transaction initiates the submit request of the branch transaction of the first transaction:
所述事务管理器为所述第一事务生成全局唯一的事务标识;The transaction manager generates a globally unique transaction identifier for the first transaction;
所述方法还包括:所述事务管理器在所述第一事务的分支事务的提交请求中携带所述第一事务的事务标识;在所述第一事务的分支事务的回滚请求中携带所述第一事务的事务标识,以及发起所述第一事务的分支事务的提交请求的时刻。The method further includes: the transaction manager carrying a transaction identifier of the first transaction in a commit request of a branch transaction of the first transaction; carrying a location in a rollback request of a branch transaction of the first transaction The transaction identifier of the first transaction, and the time of submitting the request for the branch transaction of the first transaction.
可选地,所述向其它正在提交第一事务的分支事务、或者提交第一事务的分支事务成功的资源管理器发起第一事务的分支事务的回滚请求后还包括:Optionally, after the rollback request of the branch transaction of the first transaction is initiated by the resource manager that successfully submits the branch transaction of the first transaction or the branch transaction that submits the first transaction, the method further includes:
所述事务管理器汇总所述资源管理器反馈的回滚结果;如果存在回滚失败的资源管理器,则连接回滚失败的资源管理器对应的数据库节点,锁定回滚失败所涉及的表。The transaction manager summarizes the rollback result fed back by the resource manager; if there is a resource manager that fails to roll back, the connection corresponds to the database node corresponding to the failed resource manager, and locks the table involved in the rollback failure.
一种分布式事务回滚方法,包括:A distributed transaction rollback method, comprising:
资源管理器收到事务管理器发送的第一事务的分支事务的回滚请求后,如果所述第一事务的分支事务已经提交,则筛选出所述第一事务的分支事务对应的事务日志;
After the resource manager receives the rollback request of the branch transaction of the first transaction sent by the transaction manager, if the branch transaction of the first transaction has been committed, the transaction log corresponding to the branch transaction of the first transaction is filtered out;
根据筛选出的事务日志中记录的数据和执行语句,生成反向执行语句,将生成的反向执行语句作为一个事务逆序执行。According to the data and execution statement recorded in the filtered transaction log, a reverse execution statement is generated, and the generated reverse execution statement is executed in reverse order as a transaction.
可选地,所述反向执行语句是指和原执行语句实现相反功能的语句;所述逆序执行是指和提交时的执行顺序相反。Optionally, the reverse execution statement refers to a statement that implements the opposite function to the original execution statement; the reverse execution refers to an execution order opposite to that at the time of submission.
可选地,所述第一事务的分支事务的回滚请求中携带所述第一事务的事务标识,以及发起所述第一事务的分支事务的提交请求的时刻;Optionally, the rollback request of the branch transaction of the first transaction carries the transaction identifier of the first transaction, and the time when the submission request of the branch transaction of the first transaction is initiated;
所述筛选出所述第一事务的分支事务对应的事务日志包括:The transaction log corresponding to the branch transaction that filters out the first transaction includes:
通过解析出的所述回滚请求中发起所述第一事务的分支事务的提交请求的时刻,在保存每个事务日志分块的开始位置和事务日志分块中第一个事件发生的时刻的列表中选取事务日志分块,确定所选取的事务日志分块的开始位置;The time at which the commit request of the branch transaction of the first transaction is initiated in the parsed request, the start position of each transaction log block and the time when the first event occurs in the transaction log block Select the transaction log block in the list to determine the starting position of the selected transaction log block;
从所确定的事务日志分块的开始位置开始扫描,找到所述第一事务的事务标识对应的事务日志分块。Scanning is started from the determined start position of the transaction log block, and the transaction log block corresponding to the transaction identifier of the first transaction is found.
可选地,所述将生成的反向执行语句作为一个事务逆序执行后还包括:Optionally, after the executing the reverse execution statement as a transaction reverse order, the method further includes:
当所述反向执行语句全部执行成功时,向所述事务管理器反馈表示回滚成功的回滚结果;当所述反向执行语句没有全部执行成功时,向所述事务管理器反馈表示回滚失败的回滚结果,并携带执行失败的反向执行语句和所涉及的表。When the reverse execution statement is all executed successfully, feeding back to the transaction manager a rollback result indicating that the rollback is successful; when the reverse execution statement is not all executed successfully, feeding back to the transaction manager Rolls the failed rollback result and carries the reverse execution statement that failed the execution and the tables involved.
可选地,所述将生成的反向执行语句作为一个事务逆序执行包括:Optionally, the executing the reverse execution statement as a transaction in reverse order includes:
所述资源管理器连接对应的数据库节点,以事务为单位提交生成的反向执行语句;The resource manager connects to the corresponding database node, and submits the generated reverse execution statement in units of transactions;
所述资源管理器对所对应的数据库节点逆序执行所生成的反向执行语句,并从所述数据库节点接收所述反向执行语句的执行结果。The resource manager executes the generated reverse execution statement in reverse order on the corresponding database node, and receives an execution result of the reverse execution statement from the database node.
可选地,所述资源管理器收到事务管理器发送的第一事务的分支事务的回滚请求前还包括:Optionally, before the resource manager receives the rollback request of the branch transaction of the first transaction sent by the transaction manager, the method further includes:
所述资源管理器收到所述事务管理器发起的分支事务的提交请求后,向对应的数据库节点提交所述分支事务,根据执行所述分支事务的结果反馈分支事务执行结果响应给所述事务管理器。
After receiving the commit request of the branch transaction initiated by the transaction manager, the resource manager submits the branch transaction to the corresponding database node, and feedbacks the branch transaction execution result response to the transaction according to the result of executing the branch transaction. Manager.
一种分布式事务回滚装置,设置在事务管理器中,包括:A distributed transaction rollback device, which is set in a transaction manager, and includes:
提交发起模块,设置成向和第一事务相关的数据库节点的资源管理器发起第一事务的分支事务的提交请求;Submitting an initiating module, configured to initiate a commit request of a branch transaction of the first transaction to a resource manager of the database node associated with the first transaction;
回滚发起模块,设置成当收到任一所述资源管理器发来的提交所述第一事务的分支事务失败的响应时,向其它正在提交所述第一事务的分支事务、或者提交所述第一事务的分支事务成功的资源管理器发起所述第一事务的分支事务的回滚请求。Rollback initiation module, configured to, when receiving a response from any of the resource managers that fails to submit the first transaction, to another branch transaction or submitting the first transaction The resource manager of the first transaction of the first transaction initiates a rollback request for the branch transaction of the first transaction.
可选地,标识生成模块,设置成为所述第一事务生成全局唯一的事务标识;Optionally, the identifier generating module is configured to generate a globally unique transaction identifier for the first transaction;
所述提交发起模块还设置成在所述第一事务的分支事务的提交请求中携带所述第一事务的事务标识;The commit initiating module is further configured to carry a transaction identifier of the first transaction in a commit request of a branch transaction of the first transaction;
所述回滚发起模块还设置成在所述第一事务的分支事务的回滚请求中携带所述第一事务的事务标识,以及发起所述第一事务的分支事务的提交请求的时刻。The rollback initiation module is further configured to carry a transaction identifier of the first transaction and a time of initiating a submission request of a branch transaction of the first transaction in a rollback request of a branch transaction of the first transaction.
可选地,所述的装置还包括:Optionally, the device further includes:
回滚结果处理模块,设置成汇总所述资源管理器反馈的回滚结果;如果存在回滚失败的资源管理器,则连接回滚失败的资源管理器对应的数据库节点,锁定回滚失败所涉及的表。The rollback result processing module is configured to summarize the rollback result fed back by the resource manager; if there is a resource manager that fails to roll back, the database node corresponding to the resource manager that fails to roll back the connection, the lock rollback failure is involved Table.
一种分布式事务回滚装置,设置在资源管理器中,包括:A distributed transaction rollback device, which is set in the resource manager, and includes:
选择模块,设置成收到事务管理器发送的第一事务的分支事务的回滚请求后,如果所述第一事务的分支事务已经提交,则筛选出所述第一事务的分支事务对应的事务日志;Selecting a module, configured to receive a rollback request of a branch transaction of the first transaction sent by the transaction manager, and if the branch transaction of the first transaction has been committed, filter out a transaction corresponding to the branch transaction of the first transaction Log
回滚执行模块,设置成根据筛选出的事务日志中记录的数据和执行语句,生成反向执行语句,将生成的反向执行语句作为一个事务逆序执行。The execution module is rolled back, and is set to generate a reverse execution statement according to the data and the execution statement recorded in the filtered transaction log, and execute the generated reverse execution statement as a transaction in reverse order.
可选地,所述反向执行语句是指和原执行语句实现相反功能的语句;所述逆序执行是指和提交时的执行顺序相反。
Optionally, the reverse execution statement refers to a statement that implements the opposite function to the original execution statement; the reverse execution refers to an execution order opposite to that at the time of submission.
可选地,所述第一事务的分支事务的回滚请求中携带所述第一事务的事务标识,以及发起所述第一事务的分支事务的提交请求的时刻;Optionally, the rollback request of the branch transaction of the first transaction carries the transaction identifier of the first transaction, and the time when the submission request of the branch transaction of the first transaction is initiated;
所述选择模块筛选出所述第一事务的分支事务对应的事务日志包括:The selection module filters out the transaction log corresponding to the branch transaction of the first transaction, including:
所述选择模块通过解析出的所述回滚请求中发起所述第一事务的分支事务的提交请求的时刻,在保存每个事务日志分块的开始位置和事务日志分块中第一个事件发生的时刻的列表中选取事务日志分块,确定所选取的事务日志分块的开始位置;从所确定的事务日志分块的开始位置开始扫描,找到所述第一事务的事务标识对应的事务日志分块。The selecting module saves the first event in the start position of each transaction log block and the transaction log block by the time of initiating the submit request of the branch transaction of the first transaction in the parsed request Selecting a transaction log block in the list of occurrence moments, determining a start position of the selected transaction log block; starting from the determined start position of the transaction log block, finding a transaction corresponding to the transaction identifier of the first transaction The log is chunked.
可选地,所述的装置还包括:Optionally, the device further includes:
反馈模块,设置成当所述反向执行语句全部执行成功时,向所述事务管理器反馈表示回滚成功的回滚结果;当所述反向执行语句没有全部执行成功时,向所述事务管理器反馈表示回滚失败的回滚结果,并携带执行失败的反向执行语句和所涉及的表。a feedback module, configured to: when the reverse execution statement is all executed successfully, feed back to the transaction manager a rollback result indicating that the rollback is successful; and when the reverse execution statement is not all executed successfully, to the transaction The manager feedback indicates that the rollback result of the rollback failed, and carries the reverse execution statement that failed the execution and the table involved.
可选地,所述回滚执行模块将生成的反向执行语句作为一个事务逆序执行包括:Optionally, the rollback execution module executes the generated reverse execution statement as a transaction in reverse order, including:
所述回滚执行模块连接对应的数据库节点,以事务为单位提交生成的反向执行语句;对所对应的数据库节点逆序执行所生成的反向执行语句,并从所述数据库节点接收所述反向执行语句的执行结果。The rollback execution module connects the corresponding database node, submits the generated reverse execution statement in units of transactions, executes the generated reverse execution statement in reverse order on the corresponding database node, and receives the reverse statement from the database node. The execution result to the execution statement.
可选地,所述的装置还包括:Optionally, the device further includes:
提交执行模块,设置成收到所述事务管理器发起的分支事务提交请求后,向对应的数据库节点提交所述分支事务,根据执行所述分支事务的结果反馈分支事务执行结果响应给所述事务管理器。And submitting an execution module, configured to submit the branch transaction to the corresponding database node after receiving the branch transaction commit request initiated by the transaction manager, and feedback the branch transaction execution result response to the transaction according to the result of executing the branch transaction Manager.
一种计算机可读存储介质,存储有计算机可执行指令,所述计算机可执行指令用于执行上述方法。A computer readable storage medium storing computer executable instructions for performing the above method.
本发明实施例相较于相关技术中的分布式事务提交和回滚方法,有益效果主要体现三个方面:Compared with the distributed transaction commit and rollback method in the related art, the beneficial effects of the embodiment of the present invention mainly reflect three aspects:
(1)正常事务的提交性能的提升。本发明实施例采用直接提交的方式,
摒弃了分布式事务原来两阶段提交的方式,从而减少了冗余的消息交互开销,从根本上提高了提交性能。(1) Increase in the submission performance of normal transactions. The embodiment of the invention adopts a direct submission method,
The original two-phase commit method of distributed transactions is abandoned, which reduces the redundant message interaction overhead and fundamentally improves the submission performance.
(2)保证分布式事务的一致性和可靠性。由于采用直接提交事务的方式和分支事务提交失败时回滚其它分支事务的做法,因此规避了在XA二阶段提交协议中第二阶段发起真实提交时可能发生的风险,从而进一步保证了整个分布式事务的一致性,提高了分布式事务的可靠性。(2) Guarantee the consistency and reliability of distributed transactions. The use of direct commit transactions and the rollback of other branch transactions when branch transaction commit fails, thus avoiding the risks that may occur when the second commit of the XA two-phase commit protocol is initiated, thus further ensuring the entire distributed The consistency of transactions improves the reliability of distributed transactions.
(3)无需数据库节点支持XA协议也能实现。(3) It can be implemented without the need for a database node to support the XA protocol.
在阅读并理解了附图和详细描述后,可以明白其它方面。Other aspects will be apparent upon reading and understanding the drawings and detailed description.
附图概述BRIEF abstract
图1为实施例一的分布式事务回滚方法的流程示意图;1 is a schematic flowchart of a distributed transaction rollback method according to Embodiment 1;
图2为实施例二的分布式事务回滚方法的流程示意图;2 is a schematic flowchart of a distributed transaction rollback method in Embodiment 2;
图3为实施例三的分布式事务提交和回滚方法的流程示意图;3 is a schematic flowchart of a distributed transaction commit and rollback method in Embodiment 3;
图4为实施例四的分布式事务回滚装置的示意图;4 is a schematic diagram of a distributed transaction rollback apparatus of Embodiment 4;
图5为实施例五的分布式事务回滚装置的示意图;5 is a schematic diagram of a distributed transaction rollback device of Embodiment 5;
图6为实施例六的分布式事务回滚系统的示意图。6 is a schematic diagram of a distributed transaction rollback system of Embodiment 6.
需要说明的是,如果不冲突,本发明实施例以及实施例中的各个特征可以相互结合。另外,虽然在流程图中示出了逻辑顺序,但是在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤。It should be noted that the embodiments of the present invention and the various features in the embodiments may be combined with each other if they do not conflict. Additionally, although logical sequences are shown in the flowcharts, in some cases the steps shown or described may be performed in a different order than the ones described herein.
实施例一、一种分布式事务回滚方法,如图1所示,包括:Embodiment 1 A distributed transaction rollback method, as shown in FIG. 1, includes:
S110、事务管理器向和第一事务相关的数据库节点的资源管理器发起第一事务的分支事务的提交请求;可见,本实施例摒弃了两阶段提交的做法,使用直接提交的方式;S110, the transaction manager initiates a commit request of the branch transaction of the first transaction to the resource manager of the database node associated with the first transaction; it can be seen that the embodiment discards the two-phase commit method and uses the direct commit method;
S120、所述事务管理器当收到任一所述资源管理器发来的提交所述第一事务的分支事务失败的响应时,向其它正在提交所述第一事务的分支事务、
或者提交所述第一事务的分支事务成功的资源管理器发起所述第一事务的分支事务的回滚请求。S120. When the transaction manager receives a response from any of the resource managers that fails to submit the branch transaction of the first transaction, to the other branch transaction that is submitting the first transaction,
Or the resource manager that successfully submits the branch transaction of the first transaction initiates a rollback request of the branch transaction of the first transaction.
本实施例中,如果事务管理器收到所有资源管理器提交第一事务的分支事务交成功的响应,则判定整个第一事务提交成功。In this embodiment, if the transaction manager receives a response from all resource managers submitting the branch transaction of the first transaction successfully, it determines that the entire first transaction is successfully submitted.
可选地,所述事务管理器向和第一事务相关的数据库节点的资源管理器发起第一事务的分支事务的提交请求前还包括:所述事务管理器为所述第一事务生成全局唯一的事务ID(标识);Optionally, before the transaction manager of the database node associated with the first transaction initiates the commit request of the branch transaction of the first transaction, the transaction manager further includes: the transaction manager generating a global unique for the first transaction Transaction ID (identification);
所述方法还包括:所述事务管理器在所述第一事务的分支事务的提交请求中携带所述第一事务的事务ID;在所述第一事务的分支事务的回滚请求中携带所述第一事务的事务标识,以及发起所述第一事务的分支事务的提交请求的时刻。The method further includes: the transaction manager carrying a transaction ID of the first transaction in a commit request of a branch transaction of the first transaction; carrying a location in a rollback request of a branch transaction of the first transaction The transaction identifier of the first transaction, and the time of submitting the request for the branch transaction of the first transaction.
可选地,所述步骤S120后还包括:事务管理器汇总所述资源管理器反馈的回滚结果,汇总后反馈给客户端。Optionally, after the step S120, the transaction manager further summarizes the rollback result fed back by the resource manager, and summarizes the result and feeds back to the client.
事务管理器汇总所述资源管理器反馈的回滚结果(只有收到过所述回滚请求的资源管理器反馈回滚结果),如果全部回滚成功,就向客户端返回表示回滚成功的结果,结束流程;可选地,如果存在回滚失败的资源管理器,则事务管理器连接回滚失败的资源管理器对应的数据库节点,锁定回滚失败所涉及的表,等待人工干预,以便保证事务一致性。The transaction manager summarizes the rollback result of the resource manager feedback (only the resource manager feedback rollback result of receiving the rollback request), and if all the rollback is successful, returning to the client, indicating that the rollback is successful As a result, the process ends; optionally, if there is a resource manager that fails to roll back, the transaction manager connection rolls back the database node corresponding to the failed resource manager, locks the table involved in the rollback failure, and waits for manual intervention, so that Ensure transactional consistency.
实施例二、一种分布式事务回滚方法,如图2所示,包括:Embodiment 2 A distributed transaction rollback method, as shown in FIG. 2, includes:
S210、资源管理器收到事务管理器发送的第一事务的分支事务的回滚请求后,如果所述第一事务的分支事务已经提交,则筛选出所述第一事务的分支事务对应的事务日志;S210. After receiving the rollback request of the branch transaction of the first transaction sent by the transaction manager, if the branch transaction of the first transaction has been submitted, filtering the transaction corresponding to the branch transaction of the first transaction. Log
S220、根据筛选出的事务日志中记录的数据和执行语句,生成反向执行语句,将生成的反向执行语句作为一个事务逆序执行,从而完成局部资源的回滚。S220: Generate a reverse execution statement according to the data and the execution statement recorded in the selected transaction log, and execute the reverse execution statement as a transaction in reverse order, thereby completing rollback of the local resource.
所述执行语句可以但不限于为SQL(Structured Query Language,结构化查询语言)语句。
The execution statement may be, but not limited to, a SQL (Structured Query Language) statement.
其中,所述反向执行语句可以是指和原执行语句实现相反功能的语句;比如原执行语句是加5,则对应的反向执行语句为减5;再比如原执行语句是保存,则对应的反向执行语句为读取。Wherein, the reverse execution statement may refer to a statement that implements the opposite function from the original execution statement; for example, if the original execution statement is plus 5, the corresponding reverse execution statement is subtracted by 5; and if the original execution statement is saved, the corresponding The reverse execution statement is read.
所述逆序执行可以是指和提交时的执行顺序相反,比如提交时依次执行SQL语句:X、Y、Z;针对X生成的反向SQL语句为X’,针对Y生成的反向SQL语句为Y’,针对Z生成的反向SQL语句为Z’,则逆序执行是指依次执行:Z’、Y’、X’。The reverse execution may be performed in the reverse order of execution, such as executing SQL statements in sequence: X, Y, Z; the reverse SQL statement generated for X is X', and the reverse SQL statement generated for Y is Y', the reverse SQL statement generated for Z is Z', and the reverse execution means sequential execution: Z', Y', X'.
所述资源管理器在空闲时会对事务日志进行扫描,并对事务日志根据分块大小生成索引文件,记录每个事务日志分块的开始位置和事务日志分块中第一个事件发生的时刻,从而形成内存中一个按时间顺序保存这些记录的列表。The resource manager scans the transaction log when idle, and generates an index file according to the block size of the transaction log, records the start position of each transaction log block and the time when the first event in the transaction log block occurs. , thus forming a list in memory that saves these records in chronological order.
可选地,所述第一事务的分支事务的回滚请求中携带所述第一事务的事务标识,以及发起所述第一事务的分支事务的提交请求的时刻;Optionally, the rollback request of the branch transaction of the first transaction carries the transaction identifier of the first transaction, and the time when the submission request of the branch transaction of the first transaction is initiated;
所述筛选出所述第一事务的分支事务对应的事务日志包括:The transaction log corresponding to the branch transaction that filters out the first transaction includes:
通过解析出的所述回滚请求中发起所述第一事务的分支事务的提交请求的时刻,在上述列表中选取事务日志分块,确定所选取的事务日志分块的开始位置;可以但不限于从后往前扫描所述列表;Determining, by the parsed, the request for submitting the branch transaction of the first transaction in the rollback request, selecting a transaction log block in the list to determine a starting position of the selected transaction log block; Limited to scanning the list from back to front;
从所确定的事务日志分块的开始位置开始扫描,找到所述第一事务的事务ID对应的事务日志分块。Scanning is started from the start position of the determined transaction log block, and the transaction log block corresponding to the transaction ID of the first transaction is found.
可选地,步骤S220后还可以包括:Optionally, after step S220, the method may further include:
如果所生成的反向执行语句全部执行成功,则表示回滚操作执行成功,向所述事务管理器发送表示回滚成功的回滚结果;如果生成的反向执行语句没有全部执行成功,则表示回滚操作执行失败,向所述事务管理器发送表示回滚失败的回滚结果,并携带执行失败的反向执行语句和所涉及的表。If all the generated reverse execution statements are successfully executed, it indicates that the rollback operation is successful, and the rollback result indicating that the rollback is successful is sent to the transaction manager; if the generated reverse execution statement is not all executed successfully, it indicates The rollback operation fails to execute, sending a rollback result indicating that the rollback failed to the transaction manager, and carrying the reverse execution statement that failed the execution and the table involved.
可选地,所述将生成的反向执行语句作为一个事务逆序执行包括:Optionally, the executing the reverse execution statement as a transaction in reverse order includes:
所述资源管理器连接对应的数据库节点,以事务为单位提交生成的反向执行语句;The resource manager connects to the corresponding database node, and submits the generated reverse execution statement in units of transactions;
所述资源管理器对所对应的数据库节点逆序执行所生成的反向执行语
句,并从所述数据库节点接收所述反向执行语句的执行结果。The resource manager performs the generated reverse verbs in reverse order on the corresponding database node
a sentence, and receiving an execution result of the reverse execution statement from the database node.
可选地,所述资源管理器收到事务管理器发送的第一事务的分支事务的回滚请求前还包括:Optionally, before the resource manager receives the rollback request of the branch transaction of the first transaction sent by the transaction manager, the method further includes:
所述资源管理器收到所述事务管理器发起的分支事务的提交请求后,向对应的数据库节点提交所述分支事务,根据执行所述分支事务的结果反馈分支事务执行结果响应(即:提交分支事务成功的响应或提交分支事务失败的响应)给所述事务管理器。After receiving the commit request of the branch transaction initiated by the transaction manager, the resource manager submits the branch transaction to the corresponding database node, and feedbacks the branch transaction execution result response according to the result of executing the branch transaction (ie, submitting The branch transaction successfully responds or submits a response to the branch transaction failure) to the transaction manager.
实施例三、本实施例以MariaDB分布式系统为例,分布式事务提交和回滚的过程如下所示,如图3所示,包括步骤301~306:Embodiment 3 This embodiment takes the MariaDB distributed system as an example. The process of distributed transaction submission and rollback is as follows, as shown in FIG. 3, including steps 301-306:
301、事务管理器收到执行事务的请求后,首先为该操作生成全局唯一的事务ID,然后根据分发策略得到节点信息列表以及每个数据库节点的分支事务,向相关数据库节点的资源管理器直接请求提交各自的分支事务。本实施例中,假设存在两个分支事务,分别对应数据库节点1和数据库节点2;事务管理器分别向数据库节点1的资源管理器1和数据库节点2的资源管理器2发起分支事务的提交请求。资源管理器1向数据库节点1提交分支事务,资源管理器2向数据库节点2提交分支事务。301. After receiving the request for executing the transaction, the transaction manager first generates a globally unique transaction ID for the operation, and then obtains the node information list and the branch transaction of each database node according to the distribution policy, and directly to the resource manager of the related database node. Request to submit their own branch transaction. In this embodiment, it is assumed that there are two branch transactions corresponding to the database node 1 and the database node 2 respectively; the transaction manager initiates a branch transaction commit request to the resource manager 1 of the database node 1 and the resource manager 2 of the database node 2, respectively. . The resource manager 1 submits a branch transaction to the database node 1, and the resource manager 2 submits a branch transaction to the database node 2.
302、资源管理器1根据数据库节点1执行分支事务的结果反馈分支事务执行结果(假设为提交分支事务成功)的响应给事务管理器,资源管理器2根据数据库节点2执行分支事务的结果反馈分支事务执行结果(假设为提交分支事务失败)的响应给事务管理器。302. The resource manager 1 feeds back a response of the branch transaction execution result (assuming that the commit branch transaction succeeds) to the transaction manager according to the result of executing the branch transaction by the database node 1, and the resource manager 2 performs the branch feedback result of the branch transaction according to the database node 2. The transaction execution result (assuming the commit branch transaction failed) is sent to the transaction manager.
303、在某个数据库节点的分支事务提交失败的情况下,事务管理器将对其他已经提交成功及正在提交(未收到分支事务执行结果响应)的数据库节点的资源管理器发起分布式事务回滚请求,本实施例中是向资源管理器1发起回滚请求;所述回滚请求中主要携带要回滚的事务ID和提交请求的发起时刻(利用该时刻确定事务日志范围)。303. In the case that the branch transaction of a database node fails to be submitted, the transaction manager will initiate a distributed transaction back to the resource manager of the database node that has successfully submitted and is submitting (the branch transaction execution result response is not received). In the embodiment, the rollback request is initiated to the resource manager 1; the rollback request mainly carries the transaction ID to be rolled back and the initiation time of the submission request (using the time to determine the transaction log range).
304、资源管理器1连接数据库节点1,以事务为单位提交生成的反向SQL语句。
304. The resource manager 1 connects to the database node 1, and submits the generated reverse SQL statement in units of transactions.
资源管理器在日常监控中会定期扫描MariaDB的当前的事务日志,即binlog,对事务日志根据大小进行逻辑分割,记录每个分块的开始位置和第一个事件的时间,从而形成内存中一个按时间顺序保存这些记录的列表。In the daily monitoring, the resource manager periodically scans MariaDB's current transaction log, binlog, logically splits the transaction log according to the size, records the starting position of each partition and the time of the first event, thus forming a memory. Save a list of these records in chronological order.
资源管理器1生成反向SQL语句的过程如下:The process of resource manager 1 generating reverse SQL statements is as follows:
当资源管理器1收到针对它所监听的数据库节点1的回滚请求时,首先根据回滚请求中的发起时刻,初步从上述列表中确定需要扫描分析的事务日志分块(可以用列表形式保存)和所确定的每个事务日志分块的开始位置。When the resource manager 1 receives the rollback request for the database node 1 it is listening to, firstly, according to the initiation time in the rollback request, the transaction log block that needs to be scanned and analyzed is initially determined from the above list (can be in the form of a list) Save) and the starting position of each transaction log partition determined.
根据初步确定的事务日志分块的开始位置扫描binlog日志,通过回滚请求中的事务ID,在初步确定的事务日志分块中过滤得到相应的事务日志。The binlog log is scanned according to the initially determined start position of the transaction log block, and the corresponding transaction log is filtered in the initially determined transaction log block by rolling back the transaction ID in the request.
根据事务日志中记录的数据和执行语句,生成反向SQL语句,按照事务为单位写入内存或者文件中。According to the data and execution statements recorded in the transaction log, a reverse SQL statement is generated and written into the memory or file in units of transactions.
305、对数据库节点1逆序执行所述反向SQL语句,数据库节点1将反向SQL语句的执行结果反馈给资源管理器1。305. Perform the reverse SQL statement in reverse order on the database node 1, and the database node 1 feeds back the execution result of the reverse SQL statement to the resource manager 1.
306、资源管理器1向事务管理器反馈回滚结果:如果所有反向SQL语句执行成功,资源管理器1回复给事务管理器回滚成功命令。如果反向SQL语句执行失败,将向事务管理器回复执行失败的反向SQL语句和相关表。306. The resource manager 1 feeds back the rollback result to the transaction manager: if all the reverse SQL statements are executed successfully, the resource manager 1 replies to the transaction manager to roll back the success command. If the reverse SQL statement fails to execute, the transaction manager will be replied to the reverse SQL statement and related table that failed to execute.
事务管理器收集所有发起回滚请求的资源管理器反馈的回滚结果,如果有回滚失败的消息,则锁定相关表,以保证事务一致性。The transaction manager collects the rollback results of all resource manager feedback that initiates the rollback request. If there is a rollback failure message, the related table is locked to ensure transaction consistency.
下面用四个实施示例进一步说明上述实施例。The above embodiment will be further explained below with four embodiment examples.
实施示例1、基于MySQL分布式集群数据库的在线支付系统。Implementation example 1. An online payment system based on the MySQL distributed cluster database.
在该系统中,当A账户向B账户发起一个支付操作时,由于要保证A账户金额减少的同时,B账户增加相同的金额,两个操作必须要全做,失败要全部回滚。因此要作为一个事务执行,若A、B账户数据分布在不同的数据库节点上,则涉及分布式事务。In this system, when the A account initiates a payment operation to the B account, since the A account amount is reduced and the B account is increased by the same amount, both operations must be completed, and all failures must be rolled back. Therefore, it should be executed as a transaction. If the A and B account data are distributed on different database nodes, it involves distributed transactions.
在本实施示例的实现细节中,该操作事务将分为A账户的扣减和B账户的增加两个分支事务,事务管理器首先为该操作事务生成全局唯一的事务ID,然后同时向A、B账户各自所在的数据库节点的资源管理器直接发起对应分
支事务的提交请求,提交请求中携带事务ID。In the implementation details of this embodiment example, the operational transaction will be divided into two branch transactions of the deduction of the A account and the addition of the B account, and the transaction manager first generates a globally unique transaction ID for the operational transaction, and then simultaneously to A, The resource manager of the database node where the B account is located directly initiates the corresponding score
A commit request for a transaction, which carries the transaction ID.
如果有一个数据库节点执行分支事务失败,比如B账户执行增加金额时执行失败,则事务管理器将向已经提交成功的A账户所在数据库节点的资源管理器发起回滚请求,回滚请求中携带这次分支事务的事务ID和发起提交请求的时间点t1。If there is a database node that fails to execute the branch transaction, such as the execution failure when the B account executes the increased amount, the transaction manager will initiate a rollback request to the resource manager of the database node where the A account that has successfully submitted the A account, and the rollback request carries this The transaction ID of the secondary branch transaction and the time point t1 at which the commit request is initiated.
资源管理器收到回滚请求后,根据t1筛选得到需要扫描的事务日志分块和所确定的每个事务日志分块的开始位置,再通过事务ID在筛选出的事务日志分块中过滤得到相应的事务日志;顺序分析事务日志,并根据事务日志中记录的数据和执行语句生成反向SQL语句,存储在内存或文件(视所述反向SQL语句的大小而定)中,最后按事务为单位逆向执行这些SQL语句,从而完成A账户的回滚操作,完成后回复事务管理器回滚成功。After receiving the rollback request, the resource manager obtains the transaction log partition to be scanned according to t1 and the determined start position of each transaction log block, and then filters the filtered transaction log block by the transaction ID. Corresponding transaction log; analyze the transaction log sequentially, and generate reverse SQL statements based on the data and execution statements recorded in the transaction log, stored in memory or file (depending on the size of the reverse SQL statement), and finally by transaction These SQL statements are reversed for the unit to complete the rollback operation of the A account, and the transaction manager returns successfully after completion.
实施示例2、基于MariaDB分布式集群数据库的车票在线购票系统。Implementation example 2. Ticket online ticketing system based on MariaDB distributed cluster database.
在该系统中,当某一账户发起购票业务操作时,要保证相关车次剩余票数和账户关联的票同时更新。In this system, when an account initiates a ticket purchase operation, it is necessary to ensure that the number of remaining tickets of the relevant train and the ticket associated with the account are simultaneously updated.
在本实施示例的实现细节中,如果车次剩余票数信息和账户与车票的关联信息分布在不同的数据库节点上,该操作事务将分为对相关车次剩余票数的更新和该账户购买车票信息的更新两个分支事务,事务管理器首先为该操作事务生成全局唯一的事务ID,然后同时向两个数据库节点的资源管理器发起对应分支事务的提交请求,提交请求中携带事务ID。In the implementation details of the present embodiment, if the number of remaining ticket information and the association information of the account and the ticket are distributed on different database nodes, the operation transaction will be divided into an update of the number of remaining tickets of the relevant train and an update of the ticket information of the account purchase. Two branch transactions, the transaction manager first generates a globally unique transaction ID for the operation transaction, and then simultaneously initiates a commit request for the corresponding branch transaction to the resource managers of the two database nodes, and the commit request carries the transaction ID.
如果有一个数据库节点执行分支事务失败,比如对该账户购买车票信息的更新执行失败,事务管理器将向已经提交成功的相关车次剩余票数信息所在数据库节点的资源管理器发起回滚请求,回滚请求中携带这次分支事务的事务ID和发起提交请求的时间点t1。If a database node fails to perform a branch transaction, such as the failure to perform the update of the purchase ticket information for the account, the transaction manager will initiate a rollback request to the resource manager of the database node where the remaining number of votes of the relevant train has been successfully submitted, and roll back The request carries the transaction ID of the branch transaction and the time point t1 at which the commit request is initiated.
资源管理器收到回滚请求后,根据t1筛选得到需要扫描的事务日志分块和所确定的每个事务日志分块的开始位置,再通过事务ID,在筛选出的事务日志分块中过滤得到相应的事务日志;顺序分析事务日志,并根据事务日志中记录的数据和执行语句生成反向SQL语句,即对相应车次剩余车票数的增
加的语句,并保存在内存或文件中,最后将该反向SQL语句作为一个事务执行(因为它之前属于分支事务),从而完成对相关车次剩余票数信息的回滚操作,完成后回复事务管理器回滚成功。After receiving the rollback request, the resource manager obtains the transaction log partition to be scanned according to t1 and the determined start position of each transaction log block, and then filters the filtered transaction log block by the transaction ID. Obtain the corresponding transaction log; analyze the transaction log sequentially, and generate reverse SQL statements based on the data and execution statements recorded in the transaction log, that is, increase the number of remaining tickets for the corresponding train
The added statement is saved in the memory or file, and finally the reverse SQL statement is executed as a transaction (because it belongs to the branch transaction), thereby completing the rollback operation of the remaining ticket information of the relevant train, and replying to the transaction management after completion The rollback was successful.
实施示例3、基于Oracle的分布式集群数据库的在线购物系统。Implementation Example 3, an online shopping system based on Oracle's distributed cluster database.
在该系统中,当一个选购商品操作发生时,要保证用户订购商品和剩余商品数量的同时更新。In this system, when an optional merchandise operation occurs, it is necessary to ensure that the user orders the merchandise and the remaining merchandise while updating.
在本实施示例的实现细节中,如果用户订购关系和剩余商品数量分布在不同的数据库节点上,该操作事务将分为剩余商品数量的更新和该用户与商品的一次订购关系的保存两个分支事务,事务管理器首先为该操作事务生成全局唯一的事务ID,然后同时向用户订购关系和剩余商品数量各自所在的数据库节点的资源管理器直接发起相应分支事务的提交请求,提交请求中携带事务ID。In the implementation details of the present embodiment, if the user subscription relationship and the remaining item quantity are distributed on different database nodes, the operation transaction will be divided into an update of the remaining item quantity and a save of the user and the item's one order relationship. Transaction, the transaction manager first generates a globally unique transaction ID for the operation transaction, and then simultaneously requests the resource manager of the database node where the relationship and the remaining commodity quantity are respectively in the user to initiate the submission request of the corresponding branch transaction, and the transaction is carried in the submission request. ID.
如果有一个数据库节点执行分支事务失败,比如对该用户与商品的一次订购关系的保存执行失败,事务管理器将向已经提交成功的剩余商品数量信息所在数据库节点的资源管理器发起回滚请求,回滚请求中携带这次分支事务的事务ID和发起提交请求的时间点t1。If a database node fails to perform a branch transaction, such as the failure to save the subscription relationship between the user and the commodity, the transaction manager will initiate a rollback request to the resource manager of the database node where the remaining commodity quantity information has been successfully submitted. The rollback request carries the transaction ID of the branch transaction and the time point t1 at which the commit request is initiated.
资源管理器收到回滚请求后,根据t1筛选得到需要扫描的事务日志分块和所确定的每个事务日志分块的开始位置,再通过事务ID在筛选出的事务日志分块中过滤得到相应的事务日志;顺序分析事务日志,并根据事务日志中记录的数据和执行语句生成反向SQL语句,即删除这次用户与商品的订购关系的SQL语句,并将该反向SQL语句保存在内存或文件中,最后按事务为单位逆向执行这些反向SQL语句,从而完成对剩余商品数量信息的回滚操作,完成后回复全局事务管理器回滚成功。After receiving the rollback request, the resource manager obtains the transaction log partition to be scanned according to t1 and the determined start position of each transaction log block, and then filters the filtered transaction log block by the transaction ID. Corresponding transaction log; analyze the transaction log sequentially, and generate reverse SQL statements according to the data and execution statements recorded in the transaction log, that is, delete the SQL statement of the subscription relationship between the user and the commodity, and save the reverse SQL statement in In the memory or file, the reverse SQL statement is executed in reverse by the transaction unit, thereby completing the rollback operation on the remaining item quantity information, and the global transaction manager returns successfully after completion.
实施示例4、基于PosgreSQL分布式集群数据库的在线股票交易系统。Implementation example 4, an online stock trading system based on PosgreSQL distributed cluster database.
在该系统中,当一个账户发起一个购买股票操作时,至少要保证该账户持有股票的增加和账户剩余资金的减少同时更新。
In this system, when an account initiates a stock purchase operation, at least the increase in the stock held by the account and the decrease in the remaining funds of the account are simultaneously updated.
在本实施示例的实现细节中,如果账户持有股票和账户剩余资金分布在不同的数据库节点上,该操作事务将分为该账户持有股票的增加和账户剩余资金的减少两个分支事务,事务管理器首先为该操作事务生成全局唯一的事务ID,然后同时向账户持有股票和账户剩余资金各自所在的数据库节点的资源管理器直接发起相应分支事务的提交请求,提交请求中携带事务ID。In the implementation details of the present embodiment, if the account holding stock and the remaining funds of the account are distributed on different database nodes, the operational transaction will be divided into two branch transactions in which the account holds the stock and the remaining funds of the account are reduced. The transaction manager first generates a globally unique transaction ID for the operational transaction, and then directly initiates a commit request for the corresponding branch transaction to the resource manager of the database node where the account holding stock and the remaining funds of the account are located, and the commit request carries the transaction ID. .
如果有一个数据库节点执行分支事务失败,比如账户剩余资金的减少执行失败,事务管理器将向已经提交成功的该账户持有股票数量信息所在数据库节点的资源管理器发起回滚请求,回滚请求中携带这次分支事务的事务ID和发起提交请求的时间点t1。If there is a database node performing a branch transaction failure, such as the failure of the account's remaining funds to fail to execute, the transaction manager will initiate a rollback request to the resource manager of the database node where the account has the stock quantity information that has been successfully submitted, and roll back the request. The transaction ID of the branch transaction and the time point t1 at which the commit request is initiated.
资源管理器收到回滚请求后,根据t1筛选得到需要扫描的事务日志分块和所确定的每个事务日志分块的开始位置,再通过事务ID在筛选出的事务日志分块中过滤得到相应的事务日志;顺序分析事务日志,并根据事务日志中记录的数据和执行语句生成反向SQL语句,即从用户账户里清除用户这次购买的股票数量的SQL语句,并将该反向SQL语句保存在内存或者文件中,最后按事务为单位逆向执行这些反向SQL语句,从而完成对该账户持有股票数量信息的回滚操作,完成后回复全局事务管理器回滚成功。After receiving the rollback request, the resource manager obtains the transaction log partition to be scanned according to t1 and the determined start position of each transaction log block, and then filters the filtered transaction log block by the transaction ID. Corresponding transaction log; analyze the transaction log sequentially, and generate reverse SQL statements according to the data and execution statements recorded in the transaction log, that is, clear the SQL statement of the number of shares purchased by the user from the user account, and the reverse SQL The statement is stored in the memory or file, and finally these reverse SQL statements are reversely executed in units of transactions, thereby completing the rollback operation of the stock quantity information held by the account, and the global transaction manager returns successfully after completion.
实施例四、一种分布式事务回滚装置,设置于事务管理器中,如图4所示,包括:Embodiment 4 is a distributed transaction rollback device, which is disposed in a transaction manager, as shown in FIG. 4, and includes:
提交发起模块41,设置成向和第一事务相关的数据库节点的资源管理器发起第一事务的分支事务的提交请求;The commit initiating module 41 is configured to initiate a commit request of the branch transaction of the first transaction to the resource manager of the database node associated with the first transaction;
回滚发起模块42,设置成当收到任一所述资源管理器发来的提交所述第一事务的分支事务失败的响应时,向其它正在提交所述第一事务的分支事务、或者提交所述第一事务的分支事务成功的资源管理器发起所述第一事务的分支事务的回滚请求。The rollback initiation module 42 is configured to, when receiving a response from any of the resource managers that fails to submit the branch transaction of the first transaction, to another branch transaction that is submitting the first transaction, or submit The resource manager of the branch transaction of the first transaction initiates a rollback request for the branch transaction of the first transaction.
可选地,所述的装置还包括:Optionally, the device further includes:
标识生成模块,设置成为所述第一事务生成全局唯一的事务标识;An identifier generation module configured to generate a globally unique transaction identifier for the first transaction;
所述提交发起模块41还设置成在所述第一事务的分支事务的提交请求
中携带所述第一事务的事务标识;The commit initiation module 41 is further configured to submit a request for a branch transaction of the first transaction
Carrying the transaction identifier of the first transaction;
所述回滚发起模块42还设置成在所述第一事务的分支事务的回滚请求中携带所述第一事务的事务标识,以及发起所述第一事务的分支事务的提交请求的时刻。The rollback initiation module 42 is further configured to carry a transaction identifier of the first transaction and a time of initiating a submission request of the branch transaction of the first transaction in a rollback request of a branch transaction of the first transaction.
可选地,所述的装置还包括:Optionally, the device further includes:
回滚结果处理模块,设置成汇总所述资源管理器反馈的回滚结果;如果存在回滚失败的资源管理器,则连接回滚失败的资源管理器对应的数据库节点,锁定回滚失败所涉及的表。The rollback result processing module is configured to summarize the rollback result fed back by the resource manager; if there is a resource manager that fails to roll back, the database node corresponding to the resource manager that fails to roll back the connection, the lock rollback failure is involved Table.
实施例五、一种分布式事务回滚装置,设置于资源管理器中,如图5所示,包括:The fifth embodiment is a distributed transaction rollback device, which is disposed in the resource manager, as shown in FIG. 5, and includes:
选择模块51,设置成收到事务管理器发送的第一事务的分支事务的回滚请求后,如果所述第一事务的分支事务已经提交,则筛选出所述第一事务的分支事务对应的事务日志;The selecting module 51 is configured to: after receiving the rollback request of the branch transaction of the first transaction sent by the transaction manager, if the branch transaction of the first transaction has been submitted, filtering out the branch transaction corresponding to the first transaction Transaction log
回滚执行模块52,设置成根据筛选出的事务日志中记录的数据和执行语句,生成反向执行语句,将生成的反向执行语句作为一个事务逆序执行。The rollback execution module 52 is configured to generate a reverse execution statement according to the data and the execution statement recorded in the filtered transaction log, and execute the generated reverse execution statement as a transaction reverse order.
可选地,所述反向执行语句是指和原执行语句实现相反功能的语句;所述逆序执行是指和提交时的执行顺序相反。Optionally, the reverse execution statement refers to a statement that implements the opposite function to the original execution statement; the reverse execution refers to an execution order opposite to that at the time of submission.
可选地,所述第一事务的分支事务的回滚请求中携带所述第一事务的事务标识,以及发起所述第一事务的分支事务的提交请求的时刻;Optionally, the rollback request of the branch transaction of the first transaction carries the transaction identifier of the first transaction, and the time when the submission request of the branch transaction of the first transaction is initiated;
所述选择模块51筛选出所述第一事务的分支事务对应的事务日志包括:The selection module 51 filters out the transaction log corresponding to the branch transaction of the first transaction, including:
所述选择模块51通过解析出的所述回滚请求中发起所述第一事务的分支事务的提交请求的时刻,在保存每个事务日志分块的开始位置和事务日志分块中第一个事件发生的时刻的列表中选取事务日志分块,确定所选取的事务日志分块的开始位置;从所确定的事务日志分块的开始位置开始扫描,找到所述第一事务的事务标识对应的事务日志分块。The selection module 51, by parsing the time of submitting the commit request of the branch transaction of the first transaction in the rollback request, saves the first position in the start position of each transaction log block and the first in the transaction log block Selecting a transaction log block in the list of times when the event occurs, determining a start position of the selected transaction log block; starting from the determined start position of the transaction log block, finding a transaction identifier corresponding to the first transaction The transaction log is chunked.
可选地,所述装置还包括:
Optionally, the device further includes:
反馈模块,设置成当所述反向执行语句全部执行成功时,向所述事务管理器反馈表示回滚成功的回滚结果;当所述反向执行语句没有全部执行成功时,向所述事务管理器反馈表示回滚失败的回滚结果,并携带执行失败的反向执行语句和所涉及的表。a feedback module, configured to: when the reverse execution statement is all executed successfully, feed back to the transaction manager a rollback result indicating that the rollback is successful; and when the reverse execution statement is not all executed successfully, to the transaction The manager feedback indicates that the rollback result of the rollback failed, and carries the reverse execution statement that failed the execution and the table involved.
可选地,所述回滚执行模块52将生成的反向执行语句作为一个事务逆序执行包括:Optionally, the rollback execution module 52 executes the generated reverse execution statement as a transaction in reverse order, including:
所述回滚执行模块52连接对应的数据库节点,以事务为单位提交生成的反向执行语句;对所对应的数据库节点逆序执行所生成的反向执行语句,并从数据库节点接收所述反向执行语句的执行结果。The rollback execution module 52 connects the corresponding database node, submits the generated reverse execution statement in units of transactions, executes the generated reverse execution statement in reverse order on the corresponding database node, and receives the reverse from the database node. Execute the execution result of the statement.
可选地,所述装置还包括:Optionally, the device further includes:
提交执行模块,设置成收到所述事务管理器发起的分支事务提交请求后,向对应的数据库节点提交所述分支事务,根据执行所述分支事务的结果反馈分支事务执行结果响应给所述事务管理器。And submitting an execution module, configured to submit the branch transaction to the corresponding database node after receiving the branch transaction commit request initiated by the transaction manager, and feedback the branch transaction execution result response to the transaction according to the result of executing the branch transaction Manager.
实施例六、一种分布式事务回滚系统,如图6所示,包括:Embodiment 6 A distributed transaction rollback system, as shown in FIG. 6, includes:
事务管理器61:设置成接收上层业务的事务请求,对全局事务进行管理,管理事务分支状态,协调资源管理器62的处理,通知资源管理器62操作属于哪些全局事务以及事务分支等等。事务管理器61也是整个事务调度模型的核心部分。在本实施例中事务管理器61还包括实施例四中的分布式事务回滚装置。The transaction manager 61 is configured to receive a transaction request of the upper layer service, manage the global transaction, manage the transaction branch state, coordinate the processing of the resource manager 62, notify the resource manager 62 of which global transactions and transaction branches belong to, and the like. Transaction manager 61 is also a core part of the overall transaction scheduling model. The transaction manager 61 also includes the distributed transaction rollback device of the fourth embodiment in this embodiment.
多个资源管理器62:通常是数据库节点的上层代理,是响应上层请求对相应的数据库节点63进行复杂操作的本地数据库监控程序。在本实施例中资源管理器62还包括实施例五中的分布式事务回滚装置。A plurality of resource managers 62: usually upper layer agents of database nodes, are local database monitoring programs that perform complex operations on the corresponding database nodes 63 in response to upper layer requests. In this embodiment, the resource manager 62 further includes the distributed transaction rollback device in the fifth embodiment.
本实施例中,事务管理器61收到事务请求后,向分支事务所在数据库节点63的资源管理器62发起分支事务的提交请求,并接收分支事务执行结果;当存在提交失败的分支事务时,向提交成功及正在提交的资源管理器62发起回滚请求;收到回滚请求的资源管理器62对相应的数据库节点63执行回滚操作,并向事务管理器61反馈回滚结果。
In this embodiment, after receiving the transaction request, the transaction manager 61 initiates a branch transaction commit request to the branch manager at the resource manager 62 of the database node 63, and receives the branch transaction execution result; when there is a branch transaction that fails to commit A resource rollback request is initiated to the resource manager 62 that submitted the success and is being submitted; the resource manager 62 that received the rollback request performs a rollback operation on the corresponding database node 63 and feeds back the rollback result to the transaction manager 61.
实施例七、一种计算机可读存储介质,存储有计算机可执行指令,所述计算机可执行指令用于执行上述实施例一和/或实施例二的方法。Embodiment 7 A computer readable storage medium storing computer executable instructions for performing the methods of Embodiment 1 and/or Embodiment 2 above.
本领域普通技术人员可以理解上述方法中的全部或部分步骤可通过程序来指令相关硬件完成,所述程序可以存储于计算机可读存储介质中,如只读存储器、磁盘或光盘等。可选地,上述实施例的全部或部分步骤也可以使用一个或多个集成电路来实现。相应地,上述实施例中的各模块/单元可以采用硬件的形式实现,也可以采用软件功能模块的形式实现。本发明不限制于任何特定形式的硬件和软件的结合。One of ordinary skill in the art will appreciate that all or a portion of the steps described above can be accomplished by a program that instructs the associated hardware, such as a read-only memory, a magnetic or optical disk, and the like. Alternatively, all or part of the steps of the above embodiments may also be implemented using one or more integrated circuits. Correspondingly, each module/unit in the foregoing embodiment may be implemented in the form of hardware or in the form of a software function module. The invention is not limited to any specific form of combination of hardware and software.
本发明实施例采用直接提交的方式,摒弃了分布式事务原来两阶段提交的方式,从而减少了冗余的消息交互开销,从根本上提高了提交性能;由于采用直接提交事务的方式和分支事务提交失败时回滚其它分支事务的做法,因此规避了在XA二阶段提交协议中第二阶段发起真实提交时可能发生的风险,从而进一步保证了整个分布式事务的一致性,提高了分布式事务的可靠性;另外无需数据库节点支持XA协议也能实现。
The embodiment of the invention adopts the direct submission method, and discards the original two-phase commit mode of the distributed transaction, thereby reducing redundant message interaction overhead, and fundamentally improving the submission performance; and adopting the direct commit transaction method and the branch transaction The practice of rolling back other branch transactions when the submission fails, thus avoiding the risks that may occur when the second phase of the XA two-phase commit protocol initiates the real commit, thereby further ensuring the consistency of the entire distributed transaction and improving the distributed transaction. Reliability; in addition, it can be implemented without the need for a database node to support the XA protocol.
Claims (18)
- 一种分布式事务回滚方法,包括:A distributed transaction rollback method, comprising:事务管理器向和第一事务相关的数据库节点的资源管理器发起第一事务的分支事务的提交请求;The transaction manager initiates a commit request for the branch transaction of the first transaction to the resource manager of the database node associated with the first transaction;所述事务管理器当收到任一所述资源管理器发来的提交所述第一事务的分支事务失败的响应时,向其它正在提交所述第一事务的分支事务、或者提交所述第一事务的分支事务成功的资源管理器发起所述第一事务的分支事务的回滚请求。The transaction manager, when receiving a response from any of the resource managers that fails to submit the branch transaction of the first transaction, commits to the other branch transaction that is submitting the first transaction, or submits the A branch transaction of a transaction A successful resource manager initiates a rollback request for a branch transaction of the first transaction.
- 如权利要求1所述的方法,其中,所述事务管理器向和第一事务相关的数据库节点的资源管理器发起第一事务的分支事务的提交请求前还包括:The method of claim 1, wherein the transaction manager further includes: before the resource manager of the database node associated with the first transaction initiates the submit request of the branch transaction of the first transaction:所述事务管理器为所述第一事务生成全局唯一的事务标识;The transaction manager generates a globally unique transaction identifier for the first transaction;所述方法还包括:所述事务管理器在所述第一事务的分支事务的提交请求中携带所述第一事务的事务标识;在所述第一事务的分支事务的回滚请求中携带所述第一事务的事务标识,以及发起所述第一事务的分支事务的提交请求的时刻。The method further includes: the transaction manager carrying a transaction identifier of the first transaction in a commit request of a branch transaction of the first transaction; carrying a location in a rollback request of a branch transaction of the first transaction The transaction identifier of the first transaction, and the time of submitting the request for the branch transaction of the first transaction.
- 如权利要求1所述的方法,其中,所述向其它正在提交第一事务的分支事务、或者提交第一事务的分支事务成功的资源管理器发起第一事务的分支事务的回滚请求后还包括:The method of claim 1, wherein the resource manager that successfully submits the branch transaction of the first transaction or the branch transaction that successfully submits the first transaction initiates a rollback request of the branch transaction of the first transaction include:所述事务管理器汇总所述资源管理器反馈的回滚结果;如果存在回滚失败的资源管理器,则连接回滚失败的资源管理器对应的数据库节点,锁定回滚失败所涉及的表。The transaction manager summarizes the rollback result fed back by the resource manager; if there is a resource manager that fails to roll back, the connection corresponds to the database node corresponding to the failed resource manager, and locks the table involved in the rollback failure.
- 一种分布式事务回滚方法,包括:A distributed transaction rollback method, comprising:资源管理器收到事务管理器发送的第一事务的分支事务的回滚请求后,如果所述第一事务的分支事务已经提交,则筛选出所述第一事务的分支事务对应的事务日志;After the resource manager receives the rollback request of the branch transaction of the first transaction sent by the transaction manager, if the branch transaction of the first transaction has been committed, the transaction log corresponding to the branch transaction of the first transaction is filtered out;根据筛选出的事务日志中记录的数据和执行语句,生成反向执行语句, 将生成的反向执行语句作为一个事务逆序执行。Generate a reverse execution statement based on the data and execution statements recorded in the filtered transaction log. The generated reverse execution statement is executed in reverse order as a transaction.
- 如权利要求4所述的方法,其中:The method of claim 4 wherein:所述反向执行语句是指和原执行语句实现相反功能的语句;所述逆序执行是指和提交时的执行顺序相反。The reverse execution statement refers to a statement that implements the opposite function to the original execution statement; the reverse execution refers to the reverse of the execution order at the time of submission.
- 如权利要求4所述的方法,其中:The method of claim 4 wherein:所述第一事务的分支事务的回滚请求中携带所述第一事务的事务标识,以及发起所述第一事务的分支事务的提交请求的时刻;The rollback request of the branch transaction of the first transaction carries the transaction identifier of the first transaction, and the time when the commit request of the branch transaction of the first transaction is initiated;所述筛选出所述第一事务的分支事务对应的事务日志包括:The transaction log corresponding to the branch transaction that filters out the first transaction includes:通过解析出的所述回滚请求中发起所述第一事务的分支事务的提交请求的时刻,在保存每个事务日志分块的开始位置和事务日志分块中第一个事件发生的时刻的列表中选取事务日志分块,确定所选取的事务日志分块的开始位置;The time at which the commit request of the branch transaction of the first transaction is initiated in the parsed request, the start position of each transaction log block and the time when the first event occurs in the transaction log block Select the transaction log block in the list to determine the starting position of the selected transaction log block;从所确定的事务日志分块的开始位置开始扫描,找到所述第一事务的事务标识对应的事务日志分块。Scanning is started from the determined start position of the transaction log block, and the transaction log block corresponding to the transaction identifier of the first transaction is found.
- 如权利要求4所述的方法,其中,所述将生成的反向执行语句作为一个事务逆序执行后还包括:The method of claim 4, wherein the executing the reverse execution statement as a transaction in reverse order further comprises:当所述反向执行语句全部执行成功时,向所述事务管理器反馈表示回滚成功的回滚结果;当所述反向执行语句没有全部执行成功时,向所述事务管理器反馈表示回滚失败的回滚结果,并携带执行失败的反向执行语句和所涉及的表。When the reverse execution statement is all executed successfully, feeding back to the transaction manager a rollback result indicating that the rollback is successful; when the reverse execution statement is not all executed successfully, feeding back to the transaction manager Rolls the failed rollback result and carries the reverse execution statement that failed the execution and the tables involved.
- 如权利要求4所述的方法,其中,所述将生成的反向执行语句作为一个事务逆序执行包括:The method of claim 4 wherein said executing the reverse execution statement as a transaction in reverse order comprises:所述资源管理器连接对应的数据库节点,以事务为单位提交生成的反向执行语句;The resource manager connects to the corresponding database node, and submits the generated reverse execution statement in units of transactions;所述资源管理器对所对应的数据库节点逆序执行所生成的反向执行语句,并从所述数据库节点接收所述反向执行语句的执行结果。 The resource manager executes the generated reverse execution statement in reverse order on the corresponding database node, and receives an execution result of the reverse execution statement from the database node.
- 如权利要求4所述的方法,其中,所述资源管理器收到事务管理器发送的第一事务的分支事务的回滚请求前还包括:The method of claim 4, wherein the resource manager further comprises: before receiving the rollback request of the branch transaction of the first transaction sent by the transaction manager:所述资源管理器收到所述事务管理器发起的分支事务的提交请求后,向对应的数据库节点提交所述分支事务,根据执行所述分支事务的结果反馈分支事务执行结果响应给所述事务管理器。After receiving the commit request of the branch transaction initiated by the transaction manager, the resource manager submits the branch transaction to the corresponding database node, and feedbacks the branch transaction execution result response to the transaction according to the result of executing the branch transaction. Manager.
- 一种分布式事务回滚装置,设置在事务管理器中,包括:A distributed transaction rollback device, which is set in a transaction manager, and includes:提交发起模块,设置成向和第一事务相关的数据库节点的资源管理器发起第一事务的分支事务的提交请求;Submitting an initiating module, configured to initiate a commit request of a branch transaction of the first transaction to a resource manager of the database node associated with the first transaction;回滚发起模块,设置成当收到任一所述资源管理器发来的提交所述第一事务的分支事务失败的响应时,向其它正在提交所述第一事务的分支事务、或者提交所述第一事务的分支事务成功的资源管理器发起所述第一事务的分支事务的回滚请求。Rollback initiation module, configured to, when receiving a response from any of the resource managers that fails to submit the first transaction, to another branch transaction or submitting the first transaction The resource manager of the first transaction of the first transaction initiates a rollback request for the branch transaction of the first transaction.
- 如权利要求10所述的装置,还包括:The apparatus of claim 10 further comprising:标识生成模块,设置成为所述第一事务生成全局唯一的事务标识;An identifier generation module configured to generate a globally unique transaction identifier for the first transaction;所述提交发起模块还设置成在所述第一事务的分支事务的提交请求中携带所述第一事务的事务标识;The commit initiating module is further configured to carry a transaction identifier of the first transaction in a commit request of a branch transaction of the first transaction;所述回滚发起模块还设置成在所述第一事务的分支事务的回滚请求中携带所述第一事务的事务标识,以及发起所述第一事务的分支事务的提交请求的时刻。The rollback initiation module is further configured to carry a transaction identifier of the first transaction and a time of initiating a submission request of a branch transaction of the first transaction in a rollback request of a branch transaction of the first transaction.
- 如权利要求10所述的装置,还包括:The apparatus of claim 10 further comprising:回滚结果处理模块,设置成汇总所述资源管理器反馈的回滚结果;如果存在回滚失败的资源管理器,则连接回滚失败的资源管理器对应的数据库节点,锁定回滚失败所涉及的表。The rollback result processing module is configured to summarize the rollback result fed back by the resource manager; if there is a resource manager that fails to roll back, the database node corresponding to the resource manager that fails to roll back the connection, the lock rollback failure is involved Table.
- 一种分布式事务回滚装置,设置在资源管理器中,包括:A distributed transaction rollback device, which is set in the resource manager, and includes:选择模块,设置成收到事务管理器发送的第一事务的分支事务的回滚请求后,如果所述第一事务的分支事务已经提交,则筛选出所述第一事务的分 支事务对应的事务日志;Selecting a module, configured to receive a rollback request of a branch transaction of the first transaction sent by the transaction manager, and if the branch transaction of the first transaction has been committed, filter out the score of the first transaction The transaction log corresponding to the branch transaction;回滚执行模块,设置成根据筛选出的事务日志中记录的数据和执行语句,生成反向执行语句,将生成的反向执行语句作为一个事务逆序执行。The execution module is rolled back, and is set to generate a reverse execution statement according to the data and the execution statement recorded in the filtered transaction log, and execute the generated reverse execution statement as a transaction in reverse order.
- 如权利要求13所述的装置,其中:The apparatus of claim 13 wherein:所述反向执行语句是指和原执行语句实现相反功能的语句;所述逆序执行是指和提交时的执行顺序相反。The reverse execution statement refers to a statement that implements the opposite function to the original execution statement; the reverse execution refers to the reverse of the execution order at the time of submission.
- 如权利要求13所述的装置,其中:The apparatus of claim 13 wherein:所述第一事务的分支事务的回滚请求中携带所述第一事务的事务标识,以及发起所述第一事务的分支事务的提交请求的时刻;The rollback request of the branch transaction of the first transaction carries the transaction identifier of the first transaction, and the time when the commit request of the branch transaction of the first transaction is initiated;所述选择模块筛选出所述第一事务的分支事务对应的事务日志包括:The selection module filters out the transaction log corresponding to the branch transaction of the first transaction, including:所述选择模块通过解析出的所述回滚请求中发起所述第一事务的分支事务的提交请求的时刻,在保存每个事务日志分块的开始位置和事务日志分块中第一个事件发生的时刻的列表中选取事务日志分块,确定所选取的事务日志分块的开始位置;从所确定的事务日志分块的开始位置开始扫描,找到所述第一事务的事务标识对应的事务日志分块。The selecting module saves the first event in the start position of each transaction log block and the transaction log block by the time of initiating the submit request of the branch transaction of the first transaction in the parsed request Selecting a transaction log block in the list of occurrence moments, determining a start position of the selected transaction log block; starting from the determined start position of the transaction log block, finding a transaction corresponding to the transaction identifier of the first transaction The log is chunked.
- 如权利要求13所述的装置,还包括:The apparatus of claim 13 further comprising:反馈模块,设置成当所述反向执行语句全部执行成功时,向所述事务管理器反馈表示回滚成功的回滚结果;当所述反向执行语句没有全部执行成功时,向所述事务管理器反馈表示回滚失败的回滚结果,并携带执行失败的反向执行语句和所涉及的表。a feedback module, configured to: when the reverse execution statement is all executed successfully, feed back to the transaction manager a rollback result indicating that the rollback is successful; and when the reverse execution statement is not all executed successfully, to the transaction The manager feedback indicates that the rollback result of the rollback failed, and carries the reverse execution statement that failed the execution and the table involved.
- 如权利要求13所述的装置,其中,所述回滚执行模块将生成的反向执行语句作为一个事务逆序执行包括:The apparatus of claim 13 wherein said rollback execution module executing the generated reverse execution statement as a transaction in reverse order comprises:所述回滚执行模块连接对应的数据库节点,以事务为单位提交生成的反向执行语句;对所对应的数据库节点逆序执行所生成的反向执行语句,并从所述数据库节点接收所述反向执行语句的执行结果。The rollback execution module connects the corresponding database node, submits the generated reverse execution statement in units of transactions, executes the generated reverse execution statement in reverse order on the corresponding database node, and receives the reverse statement from the database node. The execution result to the execution statement.
- 如权利要求13所述的装置,还包括: The apparatus of claim 13 further comprising:提交执行模块,设置成收到所述事务管理器发起的分支事务提交请求后,向对应的数据库节点提交所述分支事务,根据执行所述分支事务的结果反馈分支事务执行结果响应给所述事务管理器。 And submitting an execution module, configured to submit the branch transaction to the corresponding database node after receiving the branch transaction commit request initiated by the transaction manager, and feedback the branch transaction execution result response to the transaction according to the result of executing the branch transaction Manager.
Applications Claiming Priority (2)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201510632660.6 | 2015-09-29 | ||
CN201510632660.6A CN106557514A (en) | 2015-09-29 | 2015-09-29 | A kind of distributed transaction rollback method and device |
Publications (1)
Publication Number | Publication Date |
---|---|
WO2016180164A1 true WO2016180164A1 (en) | 2016-11-17 |
Family
ID=57248515
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
PCT/CN2016/079487 WO2016180164A1 (en) | 2015-09-29 | 2016-04-15 | Method and apparatus for rolling back distributed transaction |
Country Status (2)
Country | Link |
---|---|
CN (1) | CN106557514A (en) |
WO (1) | WO2016180164A1 (en) |
Cited By (14)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN109785041A (en) * | 2018-12-13 | 2019-05-21 | 深圳平安财富宝投资咨询有限公司 | Based on distributed order fulfillment method, device, equipment and readable storage medium storing program for executing |
CN109800083A (en) * | 2018-12-18 | 2019-05-24 | 平安科技(深圳)有限公司 | A kind of method, apparatus, system and storage medium that micro services collaboration is called |
CN111125240A (en) * | 2018-10-31 | 2020-05-08 | 北京金山云网络技术有限公司 | Distributed transaction implementation method and device, electronic equipment and storage medium |
CN111209142A (en) * | 2020-01-02 | 2020-05-29 | 中国平安财产保险股份有限公司 | Cross-database transaction management method, device, equipment and storage medium |
CN111367694A (en) * | 2020-03-18 | 2020-07-03 | 北京奇艺世纪科技有限公司 | Event processing method, server and computer storage medium |
CN111444199A (en) * | 2019-01-17 | 2020-07-24 | 阿里巴巴集团控股有限公司 | Data processing method and device, storage medium and processor |
CN111476670A (en) * | 2020-04-08 | 2020-07-31 | 杭州复杂美科技有限公司 | Block chain rollback insurance method, equipment and storage medium |
CN111522631A (en) * | 2020-03-23 | 2020-08-11 | 支付宝(杭州)信息技术有限公司 | Distributed transaction processing method, device, server and medium |
CN112598520A (en) * | 2020-12-28 | 2021-04-02 | 中国农业银行股份有限公司 | Transaction management method, device, electronic equipment and storage medium |
CN112732414A (en) * | 2020-12-29 | 2021-04-30 | 北京浪潮数据技术有限公司 | Distributed transaction processing method, system and related components in OLTP mode |
CN112817704A (en) * | 2019-11-15 | 2021-05-18 | 北京沃东天骏信息技术有限公司 | Distributed flexible transaction processing method and device, storage medium and electronic equipment |
CN113296897A (en) * | 2020-07-21 | 2021-08-24 | 阿里巴巴集团控股有限公司 | Distributed transaction processing method, device, equipment and machine readable medium |
CN113872781A (en) * | 2020-06-30 | 2021-12-31 | 阿里巴巴集团控股有限公司 | Transaction processing method, device, equipment and storage medium |
CN116126481A (en) * | 2023-02-06 | 2023-05-16 | 安芯网盾(北京)科技有限公司 | Distributed long transaction processing method and device |
Families Citing this family (24)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110019050A (en) * | 2017-10-19 | 2019-07-16 | 中兴通讯股份有限公司 | A kind of data rewind method, system, equipment and computer readable storage medium |
CN110019469B (en) * | 2017-12-07 | 2022-06-21 | 金篆信科有限责任公司 | Distributed database data processing method and device, storage medium and electronic device |
CN108415757B (en) * | 2018-02-02 | 2020-10-30 | 创新先进技术有限公司 | Distributed transaction processing method and device |
CN108764879A (en) * | 2018-05-31 | 2018-11-06 | 广州唯品会信息科技有限公司 | The real-time account checking method of distribution, system and computer storage media based on affairs |
CN109002462B (en) * | 2018-06-04 | 2020-11-27 | 北京明朝万达科技股份有限公司 | Method and system for realizing distributed transaction |
CN108829876A (en) * | 2018-06-26 | 2018-11-16 | 山东汇贸电子口岸有限公司 | The solution and device that the pl/sql client request time-out of Oracle does not respond |
CN108845866B (en) * | 2018-06-28 | 2021-06-29 | 创新先进技术有限公司 | Method and apparatus for processing distributed transactions |
CN111221869B (en) * | 2018-11-27 | 2024-08-16 | 北京京东振世信息技术有限公司 | Method and device for tracking database transaction time and analyzing database lock |
CN110532068A (en) * | 2019-07-18 | 2019-12-03 | 政采云有限公司 | A kind of management method of distributed transaction |
CN112256656B (en) * | 2019-07-22 | 2023-04-18 | 金篆信科有限责任公司 | Transaction rollback method and device, database, system and computer storage medium |
CN110674151A (en) * | 2019-09-23 | 2020-01-10 | 四川长虹电器股份有限公司 | Method for supporting MySQL to quickly rollback data |
CN110716793B (en) * | 2019-10-10 | 2023-09-15 | 腾讯科技(深圳)有限公司 | Method, device, equipment and storage medium for executing distributed transaction |
CN110888718A (en) * | 2019-11-27 | 2020-03-17 | 武汉虹旭信息技术有限责任公司 | Method and device for realizing distributed transaction |
US20210240516A1 (en) * | 2020-02-05 | 2021-08-05 | International Business Machines Corporation | Distributed transaction management |
CN113296896B (en) * | 2020-06-09 | 2022-05-06 | 阿里巴巴集团控股有限公司 | Distributed transaction processing method, device and equipment |
CN111858641A (en) * | 2020-07-30 | 2020-10-30 | 中国工商银行股份有限公司 | Transaction processing method and device, electronic equipment and readable storage medium |
CN112286648A (en) * | 2020-11-02 | 2021-01-29 | 用友网络科技股份有限公司 | Transaction processing method, device, electronic device and readable storage medium |
CN112100001B (en) * | 2020-11-16 | 2021-02-05 | 甬矽电子(宁波)股份有限公司 | Data rollback method, device, server and readable storage medium |
CN112650562B (en) * | 2020-12-18 | 2024-03-08 | 平安科技(深圳)有限公司 | Data processing method, device, equipment and readable storage medium |
CN113254425B (en) * | 2021-06-24 | 2022-01-11 | 阿里云计算有限公司 | Method, apparatus, system, program and storage medium for database transaction retention |
CN113268471B (en) * | 2021-06-24 | 2023-09-22 | 京东科技控股股份有限公司 | Method, proxy connection pool, system, device and medium for processing distributed transaction |
CN114461601A (en) * | 2021-12-13 | 2022-05-10 | 上海虎瑾信息技术有限公司 | Distributed transaction rollback method, device, terminal and storage medium based on sub-base and sub-table |
CN114327799B (en) * | 2021-12-23 | 2022-08-05 | 杭州博盾习言科技有限公司 | Distributed transaction processing method and device, electronic equipment and storage medium |
CN115292092B (en) * | 2022-08-04 | 2023-04-25 | 深圳计算科学研究院 | Data rollback method, device, equipment and storage medium thereof |
Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101853288A (en) * | 2010-05-19 | 2010-10-06 | 马晓普 | Configurable full-text retrieval service system based on document real-time monitoring |
CN102073540A (en) * | 2010-12-15 | 2011-05-25 | 北京新媒传信科技有限公司 | Distributed affair submitting method and device thereof |
CN104636401A (en) * | 2013-11-15 | 2015-05-20 | 中国石油天然气股份有限公司 | Method and device for data rollback of SCADA (supervisory control and data acquisition) system |
CN104750755A (en) * | 2013-12-31 | 2015-07-01 | 阿里巴巴集团控股有限公司 | Method and system for recovering data after switching between main database and standby database |
-
2015
- 2015-09-29 CN CN201510632660.6A patent/CN106557514A/en not_active Withdrawn
-
2016
- 2016-04-15 WO PCT/CN2016/079487 patent/WO2016180164A1/en active Application Filing
Patent Citations (4)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101853288A (en) * | 2010-05-19 | 2010-10-06 | 马晓普 | Configurable full-text retrieval service system based on document real-time monitoring |
CN102073540A (en) * | 2010-12-15 | 2011-05-25 | 北京新媒传信科技有限公司 | Distributed affair submitting method and device thereof |
CN104636401A (en) * | 2013-11-15 | 2015-05-20 | 中国石油天然气股份有限公司 | Method and device for data rollback of SCADA (supervisory control and data acquisition) system |
CN104750755A (en) * | 2013-12-31 | 2015-07-01 | 阿里巴巴集团控股有限公司 | Method and system for recovering data after switching between main database and standby database |
Cited By (24)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN111125240A (en) * | 2018-10-31 | 2020-05-08 | 北京金山云网络技术有限公司 | Distributed transaction implementation method and device, electronic equipment and storage medium |
CN111125240B (en) * | 2018-10-31 | 2023-09-01 | 北京金山云网络技术有限公司 | Distributed transaction realization method and device, electronic equipment and storage medium |
CN109785041A (en) * | 2018-12-13 | 2019-05-21 | 深圳平安财富宝投资咨询有限公司 | Based on distributed order fulfillment method, device, equipment and readable storage medium storing program for executing |
CN109800083A (en) * | 2018-12-18 | 2019-05-24 | 平安科技(深圳)有限公司 | A kind of method, apparatus, system and storage medium that micro services collaboration is called |
CN109800083B (en) * | 2018-12-18 | 2024-05-07 | 平安科技(深圳)有限公司 | Method, device, system and storage medium for micro-service collaborative call |
CN111444199A (en) * | 2019-01-17 | 2020-07-24 | 阿里巴巴集团控股有限公司 | Data processing method and device, storage medium and processor |
CN111444199B (en) * | 2019-01-17 | 2023-11-14 | 阿里巴巴集团控股有限公司 | Data processing method and device, storage medium and processor |
CN112817704A (en) * | 2019-11-15 | 2021-05-18 | 北京沃东天骏信息技术有限公司 | Distributed flexible transaction processing method and device, storage medium and electronic equipment |
CN111209142A (en) * | 2020-01-02 | 2020-05-29 | 中国平安财产保险股份有限公司 | Cross-database transaction management method, device, equipment and storage medium |
CN111367694B (en) * | 2020-03-18 | 2024-01-26 | 北京奇艺世纪科技有限公司 | Event processing method, server and computer storage medium |
CN111367694A (en) * | 2020-03-18 | 2020-07-03 | 北京奇艺世纪科技有限公司 | Event processing method, server and computer storage medium |
CN111522631B (en) * | 2020-03-23 | 2024-02-06 | 支付宝(杭州)信息技术有限公司 | Distributed transaction processing method, device, server and medium |
CN111522631A (en) * | 2020-03-23 | 2020-08-11 | 支付宝(杭州)信息技术有限公司 | Distributed transaction processing method, device, server and medium |
CN111476670A (en) * | 2020-04-08 | 2020-07-31 | 杭州复杂美科技有限公司 | Block chain rollback insurance method, equipment and storage medium |
CN111476670B (en) * | 2020-04-08 | 2023-05-30 | 杭州复杂美科技有限公司 | Block chain rollback insurance method, apparatus and storage medium |
CN113872781A (en) * | 2020-06-30 | 2021-12-31 | 阿里巴巴集团控股有限公司 | Transaction processing method, device, equipment and storage medium |
CN113296897B (en) * | 2020-07-21 | 2023-12-26 | 阿里巴巴集团控股有限公司 | Distributed transaction processing method, device, equipment and machine-readable medium |
CN113296897A (en) * | 2020-07-21 | 2021-08-24 | 阿里巴巴集团控股有限公司 | Distributed transaction processing method, device, equipment and machine readable medium |
CN112598520A (en) * | 2020-12-28 | 2021-04-02 | 中国农业银行股份有限公司 | Transaction management method, device, electronic equipment and storage medium |
CN112598520B (en) * | 2020-12-28 | 2024-06-11 | 中国农业银行股份有限公司 | Transaction management method, device, electronic equipment and storage medium |
CN112732414B (en) * | 2020-12-29 | 2023-12-08 | 北京浪潮数据技术有限公司 | Distributed transaction processing method and system in OLTP mode and related components |
CN112732414A (en) * | 2020-12-29 | 2021-04-30 | 北京浪潮数据技术有限公司 | Distributed transaction processing method, system and related components in OLTP mode |
CN116126481B (en) * | 2023-02-06 | 2023-08-25 | 安芯网盾(北京)科技有限公司 | Distributed long transaction processing method and device |
CN116126481A (en) * | 2023-02-06 | 2023-05-16 | 安芯网盾(北京)科技有限公司 | Distributed long transaction processing method and device |
Also Published As
Publication number | Publication date |
---|---|
CN106557514A (en) | 2017-04-05 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
WO2016180164A1 (en) | Method and apparatus for rolling back distributed transaction | |
US10942823B2 (en) | Transaction processing system, recovery subsystem and method for operating a recovery subsystem | |
US10747745B2 (en) | Transaction execution commitment without updating of data row transaction status | |
CN107077382B (en) | System and method for transaction recovery in a multi-tenant application server environment | |
CN102073540B (en) | Distributed affair submitting method and device thereof | |
CN104793988B (en) | The implementation method and device of integration across database distributed transaction | |
CN105608086B (en) | Transaction processing method and device for distributed database system | |
JP6220851B2 (en) | System and method for supporting transaction recovery based on strict ordering of two-phase commit calls | |
US8352421B2 (en) | Recording distributed transactions using probabalistic data structures | |
US20080276239A1 (en) | Recovery and restart of a batch application | |
KR20170132873A (en) | Method for processing database transactions in a distributed computing system | |
US7992148B2 (en) | Issuing syncpoints during execution of a batch application to minimize or eliminate periods of record unavailability due to batch related record locking | |
EP1241592A2 (en) | Collision avoidance in Bidirectional database replication | |
KR20140147812A (en) | Systems and methods for supporting inline delegation of middle-tier transaction logs to database | |
CN110888718A (en) | Method and device for realizing distributed transaction | |
CN110413687B (en) | Distributed transaction fault processing method and related equipment based on node interaction verification | |
Padhye et al. | Scalable transaction management with snapshot isolation for NoSQL data storage systems | |
CN107533474A (en) | A kind of transaction methods and device | |
US9218386B2 (en) | Dual locking mechanism for a domain | |
CN117234670A (en) | Distributed transaction processing method, system, computer equipment and storage medium | |
CN112765126B (en) | Database transaction management method, device, computer equipment and storage medium | |
CN113918654B (en) | Block data submitting method and device | |
CN114579260A (en) | Transaction processing method and system | |
KR101549655B1 (en) | Method of duplicating database using pararell-processing and computer readable storage media storing the same) | |
Padhye | Transaction and data consistency models for cloud applications |
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: 16792014 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: 16792014 Country of ref document: EP Kind code of ref document: A1 |