CN111984665A - Distributed transaction processing method, device and system - Google Patents

Distributed transaction processing method, device and system Download PDF

Info

Publication number
CN111984665A
CN111984665A CN202010947573.0A CN202010947573A CN111984665A CN 111984665 A CN111984665 A CN 111984665A CN 202010947573 A CN202010947573 A CN 202010947573A CN 111984665 A CN111984665 A CN 111984665A
Authority
CN
China
Prior art keywords
transaction
sub
version number
distributed
database
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Granted
Application number
CN202010947573.0A
Other languages
Chinese (zh)
Other versions
CN111984665B (en
Inventor
李兵
胡东旭
申大伟
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Duxiaoman Payment Technology Co.,Ltd.
Du Xiaoman Technology Beijing Co Ltd
Original Assignee
Shanghai Youyang New Media Information Technology Co ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shanghai Youyang New Media Information Technology Co ltd filed Critical Shanghai Youyang New Media Information Technology Co ltd
Priority to CN202010947573.0A priority Critical patent/CN111984665B/en
Publication of CN111984665A publication Critical patent/CN111984665A/en
Application granted granted Critical
Publication of CN111984665B publication Critical patent/CN111984665B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2358Change logging, detection, and notification
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2458Special types of queries, e.g. statistical queries, fuzzy queries or distributed queries
    • G06F16/2471Distributed queries
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/248Presentation of query results
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • YGENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
    • Y02TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
    • Y02DCLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
    • Y02D10/00Energy efficient computing, e.g. low power processors, power management or thermal management

Landscapes

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

Abstract

The invention discloses a distributed transaction processing method, a device and a system, wherein a TM transaction manager controls the version number of a distributed transaction which can be inquired by a client in a Mysql fragment database, receives the version number of a sub-transaction of the distributed transaction sent by the Mysql fragment database, and sends the version number of each sub-transaction of the completed distributed transaction to a preset cache database under the condition of receiving a preset trigger instruction so as to update the version number of the cache database. When receiving a query instruction sent by a client, the TM transaction manager sends the query instruction and a target version number pointed by the query instruction in the cache database to the Mysql fragment database, so that the execution result of the sub-transaction of the distributed transaction fed back by the Mysql fragment database does not exceed the range pointed by the target version number, and the isolation of the distributed transaction is guaranteed.

Description

Distributed transaction processing method, device and system
Technical Field
The present invention relates to the field of data processing, and in particular, to a distributed transaction processing method, apparatus, and system.
Background
A distributed transaction refers to a transaction participant, a supporter's server, a resource server, and a transaction manager being located on different nodes of different distributed systems, respectively, or it can be understood that a large operation consists of different small operations, which are distributed on different servers and belong to different applications.
In the process of executing the distributed transaction, the isolation of the distributed transaction processing needs to be ensured, and the isolation represents that: the execution of the transaction is not interfered by other transactions, the intermediate result of the execution of the transaction is transparent to other transactions, and the popular understanding is that the sub-transactions included in the transaction cannot be seen by a user before the execution of the transaction is not completed. Currently, ensuring the isolation of distributed transaction execution is always a difficult problem for distributed transaction processing.
Disclosure of Invention
In view of this, the embodiment of the present invention discloses a method, an apparatus, and a system for processing a distributed transaction, which ensure the requirement of isolation of the distributed transaction in the processing process.
In a first aspect, an embodiment of the present invention discloses a method for processing a distributed transaction, where the method is applied to a TM transaction manager in a distributed system, and includes:
the TM transaction manager receives the version number of the sub-transaction of the distributed transaction sent by the Mysql fragment database;
under the condition that a preset trigger instruction is received, sending the version number of each sub-transaction of the completed distributed transaction to a preset cache database, wherein the version number is the basis for updating the preset cache database; the completed distributed transaction is a distributed transaction in which the version numbers of all the sub-transactions are received;
when a query instruction of a client is received, acquiring a target version number of a target Mysql fragment database from the preset cache database; the target Mysql fragmentation database is the Mysql fragmentation database pointed by the query instruction; the preset cache database stores the version number of each Mysql fragment database;
sending the query instruction and the target version number to the target Mysql fragment database; the target version number is a basis for the target Mysql fragmentation database to feed back the execution result of the sub-transaction of the distributed transaction corresponding to the query instruction, and the fed back version number of the sub-transaction of the distributed transaction of the execution result does not exceed the indication range of the target version number;
and receiving the execution result of the distributed sub-transaction fed back by the Mysql fragment database, and sending the execution result of the distributed sub-transaction to the client.
Optionally, the method further includes:
acquiring a version number corresponding to each Mysql fragment database in the preset cache database as a version number to be saved;
sending a version number clearing instruction and a corresponding version number to be saved to each Mysql fragment database; the clear instruction and the version number to be saved are used for instructing the Mysql fragmentation database to clear other version numbers within the version number to be saved.
Optionally, the method further includes:
in the process of executing the distributed transaction, if the TM transaction manager is disconnected with the Mysql fragmentation database, determining to mark the sub-transaction in the to-be-recovered mode; the sub-transaction in the to-be-recovered mode is a sub-transaction in an XA PREPARE stage when the TM transaction manager is disconnected with the Mysql fragmentation database;
acquiring the states of other sub-transactions which belong to the same distributed transaction with the sub-transaction in the mode to be recovered;
determining an operation instruction of the sub-transaction in the to-be-recovered mode based on the states of the other sub-transactions; the operation instruction comprises a commit or a rollback;
and under the condition that the TM transaction manager establishes connection with the Mysql fragment database again, sending an operation instruction of the sub-transaction of the to-be-recovered mode to the Mysql fragment database.
Optionally, the determining, based on the state of execution of the other sub-transactions, an operation instruction of the sub-transaction in the to-be-recovered mode includes:
if the states of other sub-transactions belonging to the same distributed transaction with the sub-transaction in the to-be-recovered mode are both submitted, the operation instruction of the sub-transaction in the to-be-recovered mode is submitted;
if the state of other sub-transactions belonging to the same distributed transaction with the sub-transaction in the to-be-recovered mode comprises a rollback state, the operation instruction of the sub-transaction in the to-be-recovered mode is rollback;
and if the state of other sub-transactions which belong to the same distributed transaction with the sub-transaction in the to-be-recovered mode does not have a rollback or a commit state, determining the operation instruction of the sub-transaction in the to-be-recovered mode according to a preset operation rule.
In a second aspect, an embodiment of the present invention further discloses a method for processing a distributed transaction, where the method is applied to a Mysql fragmentation database of the distributed transaction, and includes:
under the condition that the sub-transaction of the distributed transaction executes the commit operation in the Mysql fragmentation database, generating the version number of the sub-transaction, and sending the version number of the sub-transaction to a TM transaction manager;
under the condition of receiving a query instruction and a target version number sent by a TM transaction manager, acquiring an execution result of a sub-transaction of a distributed transaction, the version number of which is within an indication range of the target version number and corresponds to the query instruction; the target version number is acquired from a preset cache database; the cache database stores version numbers of each Mysql fragmentation database, the version numbers in the preset cache database are updated through the version numbers of each sub-transaction of the completed distributed transaction sent by the TM transaction manager, and the completed distributed transaction is the distributed transaction in which the version numbers of all the sub-transactions of the distributed transaction in the TM transaction manager are received;
and sending the execution result of the sub-transaction of the distributed transaction, which is within the indicated range of the target version number and corresponds to the query instruction, to the TM transaction manager.
Optionally, the obtaining, when receiving the query instruction and the target version number sent by the TM transaction manager, the execution result of the sub-transaction of the distributed transaction whose version number is within the indicated range of the target version number and corresponding to the query instruction includes:
under the condition of receiving a query instruction and a target version number sent by the TM transaction manager, acquiring an execution result of a sub-transaction of a distributed transaction corresponding to the query instruction;
and screening out the execution results of the sub-transactions of the distributed transactions corresponding to the query instruction, wherein the version number of the execution results of the sub-transactions of the distributed transactions is within the range of the target version number.
Optionally, the method further includes:
in the process of executing the distributed transaction, if the TM transaction manager is disconnected with the Mysql fragmentation database, marking the sub-transaction in the XA PREPARE stage as a to-be-recovered mode;
when the TM transaction manager establishes connection with the Mysql fragmentation database again, receiving an operation instruction of the sub-transaction of the to-be-recovered mode sent by the TM transaction manager; the operation instruction of the sub-transaction in the mode to be recovered is determined based on the states of other sub-transactions which belong to the same distributed transaction as the sub-transaction in the mode to be recovered;
and executing the operation of committing or rolling back on the sub-transaction of the mode to be recovered according to the operation instruction.
Optionally, the method further includes:
screening out a connection session without active transaction under the condition that the TM transaction manager establishes connection with the Mysql fragmentation database again;
and executing the operation instruction of the sub-transaction of the mode to be recovered through the connection session without the active transaction.
Optionally, in a case that the connection session includes a plurality of connection sessions where no active transaction exists, an operation instruction for screening one connection session to execute the sub-transaction of the to-be-recovered mode is screened.
Optionally, the method further includes:
in the process of replaying records in binlog of the Mysql fragment database, if the XA START stage of a sub-transaction of a distributed transaction is replayed, a new data table for recording the data change of the distributed transaction is created on the SQL thread, and after the replay is completed, the data table and the SQL thread are unbound; each phase in the process of executing the transaction is recorded in the binlog of the Mysql fragment database;
if the replay is performed to the XA _ PREPARE stage of the sub-transaction of the distributed transaction and the distributed transaction corresponding to the sub-transaction is incomplete, binding a data table created in the previous XA START stage by the sub-transaction of the distributed transaction to the SQL thread, and after the replay is completed, unbinding the data table and the SQL thread;
and if the data table recording the replay result of the XA _ PREPARE phase of the sub-transaction of the distributed transaction is bound to the SQL thread under the condition of replaying to the XA COMMIT or ROLLBACK phase of the sub-transaction of the distributed transaction, and after the replay is finished, the data table and the SQL thread are unbound.
Optionally, the method further includes:
and executing a commit operation on the sub-transaction of the distributed transaction in the XA _ PREPARE phase of the sub-transaction which is played back to the distributed transaction and the state of the distributed transaction to which the sub-transaction belongs is completed.
In a third aspect: the embodiment of the invention also discloses a device for processing the distributed transaction, which is applied to the TM transaction manager in the distributed system, and the device comprises:
a receiving unit, configured to receive, by the TM transaction manager, a version number of a sub-transaction of a distributed transaction sent by a Mysql fragmentation database;
the first sending unit is used for sending the version number of each sub-transaction of the completed distributed transaction to a preset cache database under the condition that a preset trigger instruction is received, wherein the version number is the basis for updating the preset cache database; the completed distributed transaction is a distributed transaction in which the version numbers of all the sub-transactions are received;
a target version number obtaining unit, configured to obtain a target version number of a target Mysql fragment database in the preset cache database when a query instruction of a client is received; the target Mysql fragmentation database is the Mysql fragmentation database pointed by the query instruction; the preset cache database stores the version number of each Mysql fragment database;
a query instruction and target version number sending unit, configured to send the query instruction and the target version number to the target Mysql fragment database; the target version number is a basis for the target Mysql fragmentation database to feed back the execution result of the sub-transaction of the distributed transaction corresponding to the query instruction, and the fed back version number of the sub-transaction of the distributed transaction of the execution result does not exceed the indication range of the target version number;
and the execution result receiving unit is used for receiving the execution result of the distributed sub-transaction fed back by the Mysql fragment database and sending the execution result of the distributed sub-transaction to the client.
In a third aspect: the embodiment of the invention also discloses a device for processing the distributed transaction, which is applied to the Mysql fragmentation database of the distributed transaction, and comprises the following components:
a second sending unit, configured to generate a version number of a sub-transaction of the distributed transaction when the sub-transaction executes a commit operation in the Mysql fragmented database, and send the version number of the sub-transaction to the TM transaction manager;
an execution result obtaining unit, configured to, when receiving an inquiry instruction and a target version number sent by a TM transaction manager, obtain an execution result of a sub-transaction of a distributed transaction whose version number is within an indication range of the target version number and to which the inquiry instruction corresponds; the target version number is acquired from a preset cache database; the cache database stores version numbers of each Mysql fragmentation database, the version numbers in the preset cache database are updated through the version numbers of each sub-transaction of the completed distributed transaction sent by the TM transaction manager, and the completed distributed transaction is the distributed transaction in which the version numbers of all the sub-transactions of the distributed transaction in the TM transaction manager are received;
and the execution result sending unit is used for sending the execution result of the sub-transaction of the distributed transaction, which has the version number within the indication range of the target version number and corresponds to the query instruction, to the TM transaction manager.
In a fifth aspect, an embodiment of the present invention further discloses a distributed system, including:
the system comprises a TM transaction manager cluster, a Mysql database cluster and a preset cache database;
the TM transaction manager cluster comprises at least one TM transaction manager, and the Mysql database cluster comprises at least one Mysql fragmentation database;
the TM transaction manager is configured to perform any one of the processing methods of the distributed transaction according to the first aspect;
the Mysql fragmentation database is used for executing any one of the processing methods of the distributed transaction described in the second aspect;
the preset cache database is used for receiving the version number of each sub-transaction of the distributed transaction sent by the TM transaction manager and updating the stored version number according to the received version number of each sub-transaction of the completed distributed transaction.
Optionally, the method further includes:
and the automatic recovery robot is used for sensing system faults, analyzing fault types and determining a fault solving strategy based on the fault types.
The embodiment of the invention discloses a distributed transaction processing method, a device and a system, wherein a TM transaction manager controls a client in a Mysql fragment database to query the version number of a distributed transaction, receives the version number of a sub-transaction of the distributed transaction sent by the Mysql fragment database, and sends the version number of each sub-transaction of the completed distributed transaction to a preset cache database under the condition of receiving a preset trigger instruction so as to update the version number of the cache database. That is, the range indicated by the version number in the cache database is all the executed distributed transactions. Based on the above conditions, when receiving the query instruction sent by the client, the TM transaction manager sends the query instruction and the target version number pointed by the query instruction in the cache database to the Mysql fragment database, so that the execution result of the sub-transaction of the distributed transaction fed back by the Mysql fragment database does not exceed the range indicated by the target version number. Therefore, even if the Mysql fragment database stores the version number of a sub-transaction of a certain incomplete distributed transaction, the execution state of the sub-transaction of the incomplete distributed transaction is not fed back to the client by the limitation of the target version number sent by the TM transaction manager, so that the isolation of the distributed transaction is guaranteed.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
Fig. 1 is a flowchart illustrating a method for processing a distributed transaction according to an embodiment of the present invention;
FIG. 2 is a flow chart illustrating a method for clearing a history version number according to an embodiment of the present invention;
fig. 3 is a schematic flow chart of a distributed transaction processing method according to an embodiment of the present invention;
fig. 4 is a schematic flow chart of a distributed transaction processing method according to an embodiment of the present invention;
FIG. 5 is a flowchart illustrating a method for processing a distributed transaction according to an embodiment of the present invention;
FIG. 6 is a flow chart illustrating a method for distributed transaction playback according to an embodiment of the present invention;
fig. 7 is another flow chart of a distributed transaction processing method according to an embodiment of the present invention;
fig. 8 is a schematic structural diagram illustrating a distributed transaction processing apparatus according to an embodiment of the present invention;
fig. 9 is a schematic structural diagram of a distributed transaction processing apparatus according to an embodiment of the present invention;
fig. 10 is a schematic structural diagram of a distributed system according to an embodiment of the present invention;
fig. 11 shows a further schematic diagram of a distributed system.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Referring to fig. 1, a flow chart of a distributed transaction processing method provided by an embodiment of the present invention is shown, the method is applied to a TM transaction manager in a distributed system; wherein, this distributed system includes:
the system comprises a TM transaction manager cluster, a Mysql database cluster and a preset cache database;
the system comprises a TM transaction manager cluster, a Mysql database cluster and a Mysql fragment database, wherein the TM transaction manager cluster comprises at least one TM transaction manager, and the Mysql database cluster comprises at least one Mysql fragment database;
in this embodiment, the preset cache database may be any database capable of storing data, and may be, for example, a Redis database cluster.
In this embodiment, the method includes:
s101: the TM transaction manager receives the version number of the sub-transaction of the distributed transaction sent by the Mysql fragment database;
in this embodiment, the distributed transaction includes multiple sub-transactions, each sub-transaction is executed in a different Mysql fragmentation database, and when a commit operation is executed in the Mysql fragmentation database, the sub-transaction generates a version number of the sub-transaction, the Mysql fragmentation database sends the generated version number to the TM transaction manager, and the TM transaction manager receives the version number of the sub-transaction.
S102: under the condition that a preset trigger instruction is received, sending the version number of each sub-transaction of the completed distributed transaction to a preset cache database, wherein the version number is the basis for updating the preset cache database; the completed distributed transaction is the distributed transaction of which the version numbers of all the sub-transactions are received;
it should be noted that a distributed transaction includes multiple sub-transactions, each of which performs a commit operation before indicating that the distributed transaction is completed, and when any of the sub-transactions is in an uncommitted state, indicating that the distributed transaction is not completed.
In this embodiment, the sub-transactions of the distributed transaction are executed in the Mysql fragmentation database, and after the commit operation is performed, the version numbers of the generated sub-transactions of the distributed transaction are sent to the TM transaction manager, so that the TM transaction manager may consider the distributed transaction as a completed distributed transaction only when the version numbers of all the sub-transactions of the distributed transaction are received.
In this embodiment, the TM transaction manager, when receiving a preset trigger instruction, detects whether there is a completed distributed transaction, and if there is a completed distributed transaction, sends a version number of the completed distributed transaction to a preset cache database.
In this embodiment, the preset trigger instruction may include the following two cases, including:
in case one, the preset trigger instruction is: in the case of receiving a version number of a child transaction of a new distributed transaction;
wherein the new distributed transaction is a distributed transaction that has not been received by the TM transaction manager.
In this embodiment, when the TM transaction manager receives the version number of the sub-transaction of the new distributed transaction, if it is detected that there is a completed distributed transaction, the TM transaction manager sends the version number of the completed distributed transaction to the preset cache database.
In case two, the preset trigger instruction is: and receiving an instruction of feeding back the version number to a preset cache database.
In this embodiment, the instruction for feeding back the version number to the preset cache data may be sent at a fixed time, or may be sent based on a user requirement, which is not limited in this embodiment.
In this embodiment, the version number of the completed distributed transaction is sent to a preset cache database, and the cache database updates the currently stored version number according to the received version number.
For example, the following steps are carried out: when the TM transaction manager receives a preset trigger instruction, the TM transaction manager detects that a completed distributed transaction is included, the distributed transaction comprises 3 sub-transactions, the three sub-transactions are executed in the Mysql fragment database 1, the Mysql fragment database 2 and the Mysql fragment database 3 respectively, and the version numbers of the three sub-transactions are 80,90 and 100 respectively after the execution is completed. If the TM transaction manager sends each sub-transaction of the completed distributed transaction to a preset cache database. And the cache database updates the stored version number, namely, the version number corresponding to the Mysql fragment database 1 is updated to 80, the version number of the Mysql fragment database 2 is updated to 90, and the version number corresponding to the Mysql fragment database 3 is updated to 100.
Therefore, the version number of each Mysql fragment database stored in the cache database is updated through the TM transaction manager, so that the version numbers stored in the Mysql fragment databases are the version numbers of the completed sub-transactions of the distributed transaction; on the other hand, the version number stored in the cache database is guaranteed to be the maximum version number which can be used for querying in the Mysql fragmentation database.
S103: when a query instruction of a client is received, acquiring a target version number of a target Mysql fragment database from the preset cache database; the target Mysql fragmentation database is the Mysql fragmentation database pointed by the query instruction; the preset cache database stores the version number of each Mysql fragment database;
in this embodiment, the Mysql fragment database to which the query instruction of the client points may include one or more, the cache database stores the version number in each Mysql fragment database, and the version number of each Mysql fragment database stored in the cache database indicates that the version numbers in the version number range are the version numbers of the sub-transactions of the executed distributed transaction.
For example, the following steps are carried out: if the version number of the Mysql fragment database 1 stored in the preset cache database is 80, it indicates that the version numbers in the range of 1-80 in the Mysql fragment database 1 are the version numbers of the executed sub-transactions of the distributed transaction. In this embodiment, the Mysql fragmentation database to which the query instruction of the client points may be represented as a target Mysql fragmentation database, and the TM transaction manager obtains a target version number of the target Mysql fragmentation database from a preset cache database.
S104: sending the query instruction and the target version number to the target Mysql fragment database; the target version number is a basis for the target Mysql fragmentation database to feed back the execution result of the sub-transaction of the distributed transaction corresponding to the query instruction, and the fed back version number of the sub-transaction of the distributed transaction of the execution result does not exceed the indication range of the target version number;
in this embodiment, when the target Mysql fragment database receives the query instruction and the target version number sent by the TM transaction manager, the Mysql fragment database feeds back the execution result of the sub-transaction of the distributed transaction corresponding to the query instruction according to the target version number, and the fed back version number of the sub-transaction of the distributed transaction of the execution result does not exceed the indication range of the target version number.
How to feed back the specific process of the execution result of the sub-transaction of the distributed transaction corresponding to the query instruction according to the target version number is described in detail below, which is not described in detail in this embodiment.
For example, the following steps are carried out: assuming that the version number of the target Mysql fragmented database pointed by the query instruction in the preset cache database is 90, the version number of the sub-transaction of the distributed transaction of the execution result fed back by the target Mysql fragmented database does not exceed 90.
In this embodiment, if the target Mysql fragment database contains a sub-transaction that exceeds the target version number, the distributed transaction of the sub-transaction is considered to be not executed and completed, and in this case, in order to ensure the isolation of the distributed transaction, the execution result of the sub-transaction cannot be fed back to the client, that is, the intermediate process of the distributed transaction that is not executed and completed cannot be exposed to the client.
It can be understood that the query result (the execution result of the sub-transaction of the distributed transaction) of the query instruction fed back by the Mysql fragmented database is screened, and if the version number of the sub-transaction corresponding to the query result is within the range of the target version number, the query result is fed back to the TM transaction manager, and if the version number of the sub-transaction corresponding to the query result exceeds the range of the target version number, the query result is not fed back to the TM transaction manager. The range indicated by the target version number is the version number of the completed sub-transaction of the distributed transaction, so that the execution result of the sub-transaction of the unexecuted and completed distributed transaction is prevented from being fed back to the TM transaction manager, and the isolation of the distributed transaction is guaranteed.
S105: and receiving the execution result of the distributed sub-transaction fed back by the Mysql fragment database, and sending the execution result of the distributed sub-transaction to the client.
By the above description, the version number of the sub-transaction of the execution result fed back by the Mysql fragment database does not exceed the range indicated by the target version number, that is, the sub-transactions of the execution result fed back by the Mysql fragment database are all the sub-transactions of the executed distributed transaction.
In this embodiment, the TM transaction manager controls a client in the Mysql fragment database to be able to query the version number of the distributed transaction, and the TM transaction manager receives the version numbers of the sub-transactions of the distributed transaction sent by the Mysql fragment database, and sends the version number of each sub-transaction of the completed distributed transaction to the preset cache database when receiving the preset trigger instruction, so that the cache database updates the version number. That is, the range indicated by the version number in the cache database is all the executed distributed transactions. Based on the above conditions, when receiving the query instruction sent by the client, the TM transaction manager sends the query instruction and the target version number pointed by the query instruction in the cache database to the Mysql fragment database, so that the execution result of the sub-transaction of the distributed transaction fed back by the Mysql fragment database does not exceed the range indicated by the target version number. Therefore, even if the Mysql fragment database stores the version number of a sub-transaction of a certain incomplete distributed transaction, the execution state of the sub-transaction of the incomplete distributed transaction is not fed back to the client by the limitation of the target version number sent by the TM transaction manager, so that the isolation of the distributed transaction is guaranteed.
In this embodiment, sub-transactions of different distributed transactions are continuously executed in the Mysql fragment database, version numbers are continuously generated, the version numbers of the executed sub-transactions are stored in the Mysql fragment database, a large amount of storage space of the Mysql fragment database is occupied along with the continuous increase of the data volume, the processing efficiency of the Mysql fragment database is affected, and in order to reduce the storage pressure of the Mysql fragment database and improve the processing efficiency of the Mysql fragment database, historical version numbers can be removed. But since there may be version numbers of unexecuted completed distributed transactions in the Mysql sharded database, such version numbers cannot be cleared. In order to ensure that the version number of a distributed transaction that is not completed by execution is not cleared on the basis of clearing a history version number, referring to fig. 2, a flowchart of a method for clearing a history version number according to an embodiment of the present invention is shown, where in this embodiment, the method includes:
s201: acquiring a version number corresponding to each Mysql fragment database in the preset cache database as a version number to be saved;
s202: sending a version number clearing instruction and a corresponding version number to be saved to each Mysql fragment database; the clear instruction and the version number to be saved are used for instructing the Mysql fragmentation database to clear other version numbers within the version number to be saved.
In this embodiment, the range indicated by the version number of each Mysql fragmentation database stored in the preset cache database is the version number of a sub-transaction of a completed distributed transaction, and for convenience of description, in this embodiment, the version number of each Mysql fragmentation database in the preset cache database is represented as the version number to be retained. In this embodiment, for any Mysql fragmentation database, version numbers exceeding the range of version numbers to be saved of the Mysql fragmentation database are most likely to be version numbers of sub-transactions of incomplete distribution transactions. Based on this, in order to ensure that the version numbers of the sub-transactions of the incomplete distributed transaction are not cleared, in this embodiment, the version number to be retained is taken as a reference, and other version numbers within the range of the version number to be retained are cleared, that is, the version number to be retained and other version numbers beyond the range of the version number to be retained are retained.
In this embodiment, the range indicated by the version number stored in the preset cache database is the version number of the completed sub-transaction of the distributed transaction, and only the version number within the range of the version number is removed with the version number as a reference, so that the purposes of reducing the storage pressure of the Mysql fragment database, improving the processing efficiency of the Mysql fragment database, and ensuring that the version number of the unexecuted and completed distributed transaction is not removed are achieved.
In this embodiment, during the execution of the distributed transaction, some faults may occur to affect the execution of the distributed transaction, for example, a TM transaction manager may be disconnected from the Mysql fragmentation database, in this case, it is very likely that a sub-transaction of the distributed transaction does not perform commit or rollback, but other sub-transactions of the distributed transaction may have performed commit or rollback operations, and in this case, the consistency of the distributed transaction cannot be guaranteed.
To avoid the foregoing situation, referring to fig. 3, a schematic flowchart of a distributed transaction processing method according to an embodiment of the present invention is shown, where the method applies a TM transaction manager, and in this embodiment, the method includes:
s301: in the process of executing the distributed transaction, if the TM transaction manager is disconnected with the Mysql fragmentation database, determining to mark the sub-transaction in the to-be-recovered mode; the sub-transaction in the to-be-recovered mode is a sub-transaction in an XA PREPARE stage when the TM transaction manager is disconnected with the Mysql fragmentation database;
in this embodiment, in the process of executing the distributed transaction, if the TM transaction manager is disconnected from the Mysql fragmentation database, and if there is a sub-transaction in the XAPREPARE stage in the Mysql fragmentation database, the sub-transaction in the XAPREPARE stage is marked as a mode to be recovered.
S302: acquiring the states of other sub-transactions which belong to the same distributed transaction with the sub-transaction in the mode to be recovered;
s303: determining an operation instruction of the sub-transaction in the to-be-recovered mode based on the states of the other sub-transactions; the operation instruction comprises a commit or a rollback;
in order to ensure consistency of distributed transactions, the sub-transactions of a distributed transaction are either all committed or all rolled back. Based on the above principle, the operation of committing or rolling back performed in the next step by the sub-transaction marked as the mode to be recovered needs to be based on the state of other sub-transactions belonging to the same distributed transaction as the sub-transaction.
Specifically, S303 includes:
if the states of other sub-transactions belonging to the same distributed transaction with the sub-transaction in the to-be-recovered mode are both submitted, the operation instruction of the sub-transaction in the to-be-recovered mode is submitted;
if the state of other sub-transactions belonging to the same distributed transaction with the sub-transaction in the to-be-recovered mode comprises a rollback state, the operation instruction of the sub-transaction in the to-be-recovered mode is rollback;
and if the state of other sub-transactions which belong to the same distributed transaction with the sub-transaction in the to-be-recovered mode does not have a rollback or a commit state, determining the operation instruction of the sub-transaction in the to-be-recovered mode according to a preset operation rule.
S304: and under the condition that the TM transaction manager establishes connection with the Mysql fragment database again, sending an operation instruction of the sub-transaction of the to-be-recovered mode to the Mysql fragment database.
In this embodiment, if the TM transaction manager establishes connection with the Mysql fragment database again, the TM transaction manager sends an operation instruction of the sub-transaction in the to-be-recovered mode to the Mysql fragment database, and the Mysql fragment database performs commit or rollback operation on the sub-transaction based on the operation instruction.
In the embodiment, in the process of executing the distributed transaction, for the problem that the TM transaction manager is disconnected from the Mysql fragmentation database, the consistency of the distributed transaction is ensured by marking the sub-transaction in the XAPREPARE stage as the sub-transaction in the to-be-recovered mode, and determining whether the sub-transaction performs the next commit or rollback operation based on the state of other sub-transactions belonging to the same distributed transaction as the sub-transaction.
Referring to fig. 4, a schematic flowchart of another method for processing a distributed transaction according to an embodiment of the present invention is shown, where the method is applied to a Mysql fragmentation database of distributed transactions, and the method includes:
s401: under the condition that the sub-transaction of the distributed transaction executes the commit operation in the Mysql fragmentation database, generating the version number of the sub-transaction, and sending the version number of the sub-transaction to a TM transaction manager;
in this implementation, a distributed transaction includes multiple sub-transactions, each sub-transaction is executed in a different Mysql fragment database, and after the sub-transaction executes a commit operation, a version number of the sub-transaction is generated in the Mysql fragment database and sent to the TM transaction manager.
And for a distributed transaction, the distributed transaction is indicated to be executed and completed only when all the sub-transactions included in the distributed transaction are executed and completed, and if any sub-transaction included in the distributed transaction is not executed and completed, the distributed transaction is indicated to be not completed.
In this embodiment, the sub-transactions of the distributed transaction are executed in the Mysql fragmentation database, and after the commit operation is performed, the version numbers of the generated sub-transactions of the distributed transaction are sent to the TM transaction manager, so that the TM transaction manager may consider the distributed transaction as a completed distributed transaction only when the version numbers of all the sub-transactions of the distributed transaction are received. And the TM transaction manager detects whether the completed distributed transaction exists under the condition of receiving a preset trigger instruction, and sends the version number of the completed distributed transaction to a preset cache database if the completed distributed transaction exists.
In this embodiment, the version number of the completed distributed transaction is sent to a preset cache database, and the cache database updates the currently stored version number according to the received version number.
And the cache database stores the version number in each Mysql fragment database, and the version number of each Mysql fragment database stored in the cache database indicates that the version numbers in the version number range are the version numbers of the executed sub-transactions of the distributed transaction.
S402: under the condition of receiving a query instruction and a target version number sent by a TM transaction manager, acquiring an execution result of a sub-transaction of a distributed transaction, the version number of which is within an indication range of the target version number and corresponds to the query instruction;
the target version number is obtained from a preset cache database, the cache database stores version numbers of each Mysql fragmentation database, the version numbers in the preset cache database are updated through the version numbers of each sub-transaction of completed distributed transactions sent by the TM transaction manager, and the completed distributed transactions are distributed transactions in which the version numbers of all sub-transactions of the distributed transactions in the TM transaction manager are received.
As can be seen from the above description, the target version number indicates that the version numbers within the version number range are all version numbers of sub-transactions of the executed completed distributed transaction. And under the condition that the Mysql fragmentation database receives the query instruction and the target version number sent by the TM transaction manager, screening the final feedback result based on the target version number, wherein the obtained feedback result is as follows: and the version number is in the indicated range of the target version number and the execution result of the sub-transaction of the distributed transaction corresponding to the query instruction is obtained.
Wherein the determination of the feedback result comprises two conditions:
condition 1: inquiring an instruction;
condition 2: a target version number.
The process of determining the query result based on the two conditions may include the following two ways:
in a first mode, under the condition of receiving a query instruction and a target version number sent by the TM transaction manager, acquiring an execution result of a sub-transaction of a distributed transaction corresponding to the query instruction;
and screening out the execution results of the sub-transactions of the distributed transactions corresponding to the query instruction, wherein the version number of the execution results of the sub-transactions of the distributed transactions is within the range of the target version number.
Determining the range of the version number of the query result according to the target version number under the condition of receiving the query instruction and the target version number sent by the TM transaction manager;
and determining the execution result of the distributed transaction corresponding to the query instruction in the range of the version number of the query result.
S403: and sending the execution result of the sub-transaction of the distributed transaction, which is within the indicated range of the target version number and corresponds to the query instruction, to the TM transaction manager.
In this embodiment, when feeding back the query result pointed by the query instruction, the Mysql fragment database needs to send a target version number according to the TM transaction manager, and since the target version number indicates that the version numbers in the version number range are all version numbers of sub-transactions of the executed and completed distributed transaction, based on the limitation of the target version number, the version numbers of the query result corresponding to the query instruction fed back by the Mysql fragment database are all in the range of the target version number, in this case, even if the Mysql fragment database stores the version number of a sub-transaction of a certain unexecuted and completed distributed transaction, the execution state of the sub-transaction of the distributed transaction is not fed back to the client, so that the isolation of the distributed transaction is ensured to be incomplete.
During the execution of the distributed transaction, some faults may occur to affect the execution of the distributed transaction, for example, a situation that a TM transaction manager is disconnected from a Mysql fragmentation database may occur, in which case, it is very likely that a sub-transaction of the distributed transaction does not perform commit or rollback, but other sub-transactions of the distributed transaction may have performed commit or rollback operations, and in this case, the consistency of the distributed transaction cannot be guaranteed.
To avoid the foregoing situation, referring to fig. 5, there is shown another schematic flow chart illustrating a method for processing a distributed transaction according to an embodiment of the present invention, where in this embodiment, the method includes:
s501: in the process of executing the distributed transaction, if the TM transaction manager is disconnected with the Mysql fragmentation database, marking the sub-transaction in the XA PREPARE stage as a to-be-recovered mode;
s502: when the TM transaction manager establishes connection with the Mysql fragmentation database again, receiving an operation instruction of the sub-transaction of the to-be-recovered mode sent by the TM transaction manager; the operation instruction of the sub-transaction in the mode to be recovered is determined based on the states of other sub-transactions which belong to the same distributed transaction as the sub-transaction in the mode to be recovered;
in this embodiment, when the TM transaction manager is disconnected from the Mysql fragmentation database, the sub-transaction in the XA PREPARE stage is marked as the to-be-recovered mode, and the next operation of the sub-transaction marked as the to-be-recovered mode is determined according to the states of other sub-transactions belonging to the same distributed transaction as the sub-transaction.
The method for determining the operation instruction comprises the following steps:
if the states of other sub-transactions belonging to the same distributed transaction with the sub-transaction in the to-be-recovered mode are both submitted, the operation instruction of the sub-transaction in the to-be-recovered mode is submitted;
if the state of other sub-transactions belonging to the same distributed transaction with the sub-transaction in the to-be-recovered mode comprises a rollback state, the operation instruction of the sub-transaction in the to-be-recovered mode is rollback;
and if the state of other sub-transactions which belong to the same distributed transaction with the sub-transaction in the to-be-recovered mode does not have a rollback or a commit state, determining the operation instruction of the sub-transaction in the to-be-recovered mode according to a preset operation rule.
S503: and executing the operation of committing or rolling back on the sub-transaction of the mode to be recovered according to the operation instruction.
In this embodiment, if the TM transaction manager establishes connection with the Mysql fragment database again, the TM transaction manager sends an operation instruction of the sub-transaction in the to-be-recovered mode to the Mysql fragment database, and the Mysql fragment database performs commit or rollback operation on the sub-transaction based on the operation instruction.
And, in the case that the TM transaction manager establishes a connection with the Mysql fragmentation database again, multiple connection sessions may be included, but for an active session that is performing other operations, the sub-transaction marked with the to-be-recovered mode cannot be executed any more, and based on this, the method further includes:
screening out a connection session without active transaction under the condition that the TM transaction manager establishes connection with the Mysql fragmentation database again;
and executing the operation instruction of the sub-transaction of the mode to be recovered through the connection session without the active transaction.
And screening one connection session to execute the operation instruction of the sub-transaction of the to-be-recovered mode under the condition of containing a plurality of connection sessions without active transactions.
In this embodiment, in the process of executing the distributed transaction, for the problem that the TM transaction manager is disconnected from the Mysql fragmentation database, the consistency of the distributed transaction is ensured by marking the sub-transaction in the XA PREPARE stage as the sub-transaction in the to-be-recovered mode, and determining whether the sub-transaction performs the next commit or rollback operation based on the state of the other sub-transactions belonging to the same distributed transaction as the sub-transaction.
In this embodiment, in order to improve the fault tolerance of the Mysql fragment database, each Mysql fragment database includes at least one slave database, and in order to ensure the consistency of the data of the master database and the slave database, records in the binlog of the Mysql fragment database need to be played back in the slave database.
Referring to fig. 6, a flowchart of a method for distributed transaction playback provided in an embodiment of the present invention is shown, where the method includes:
s601: in the process of replaying records in binlog of the Mysql fragment database, if the XA START stage of a sub-transaction of a distributed transaction is replayed, a new data table for recording the data change of the distributed transaction is created on the SQL thread, and after the replay is completed, the data table and the SQL thread are unbound; each phase in the process of executing the transaction is recorded in the binlog of the Mysql fragment database;
in this embodiment, during execution of a distributed transaction, the execution state of a sub-transaction of the distributed transaction is recorded in binlog, in the prior art, an XA COMMIT or a ROLLBACK phase is generally recorded in binlog, and in order to improve consistency of the distributed transaction, an XA START phase and an XA PREPARE phase of the sub-transaction of the distributed transaction are also recorded in binlog.
In this embodiment, when the record in binlog is played back, if the playback reaches the XA START phase of the sub-transaction of the distributed transaction, a new data table needs to be created on the SQL thread, where the data table is used to record the data change of the distributed transaction.
It should be noted that, in general, a data table for recording data changes of the transaction, such as the inbb trx, is bound to the SQL thread. However, for distributed transactions, since the sub-transactions of a distributed transaction include multiple phases, including, for example: XA START phase, XA _ PREPARE phase, and XA COMMIT or ROLLBACK phase, but these phases may not be performed continuously, for example, after the XA START phase of a sub-transaction is performed, other transactions are played back, and the playback of the sub-transaction is not continuous. Therefore, in order to ensure the continuity of the playback of the sub-transactions of a distributed transaction, in the embodiment, in the case of executing the XASTART phase of the sub-transactions of a distributed transaction, the previously bound data table in the SQL database may be unbound, and a new data table may be created for recording the execution process of the sub-transactions of the distributed transaction.
And in order to ensure that the data table only records the execution process of the sub-transaction of the distributed transaction, the newly created data table is unbound after the playback of the XA START phase is executed.
Furthermore, it should be noted that, during the playback process, when the XA START phase of a sub-transaction of a distributed transaction is played back each time, a new data table for recording the execution process of the distributed transaction is created.
For example, the following steps are carried out: when the XA START phase of the sub-transaction of the distributed transaction 1 is played back, a new data table for recording the execution process of the distributed transaction is created on the SQL thread, and after the XA START phase of the sub-transaction of the distributed transaction 1 is played back, the data table is unbound from the SQL thread. When the XASTART phase of the sub-transaction of the distributed transaction 2 is played back, a new data table for recording the execution process of the distributed transaction is created on the SQL thread.
S602: if the replay is performed to the XA _ PREPARE stage of the sub-transaction of the distributed transaction and the distributed transaction corresponding to the sub-transaction is incomplete, binding a data table created in the previous XA START stage by the sub-transaction of the distributed transaction to the SQL thread, and after the replay is completed, unbinding the data table and the SQL thread;
in this embodiment, in order to ensure continuity of the sub-transactions of the distributed transaction during the playback process, when the playback is performed to the XA _ PREPARE phase of the sub-transactions of the distributed transaction and the sub-transactions are in the condition, the data table created in the preceding XA START phase with the sub-transactions of the distributed transaction is bound to the SQL thread, and after the playback is completed, the data table is unbound from the SQL thread.
In this embodiment, when a sub-transaction is executed to the XA _ PREPARE stage, there are two cases as follows:
in case one, when a sub-transaction is executed to the XA _ PREPARE phase, if the distributed transaction corresponding to the sub-transaction further includes other sub-transactions that are not executed, that is, the state of the distributed transaction to which the sub-transaction belongs is not completed, after the XA _ PREPARE phase is executed, the distributed transaction needs to wait for the execution result of the other sub-transactions, that is, wait for a commit or rollback instruction, and further execute a commit or rollback again.
In case two, if the distributed transaction corresponding to the sub-transaction does not include other sub-transactions, or other sub-transactions are all executed, that is, the state of the distributed transaction to which the sub-transaction belongs is complete, then after the distributed transaction executes the XA _ PREPARE phase, in order to improve processing efficiency, the commit operation may be directly executed without waiting for other sub-transactions.
In this embodiment, to distinguish between the case one and the case two, during the execution of the sub-transaction of the distributed transaction, the sub-transaction may be marked, and the marking may distinguish whether the state of the distributed transaction to which the sub-transaction belongs is completed.
S603: and if the data table recording the replay result of the XA _ PREPARE phase of the sub-transaction of the distributed transaction is bound to the SQL thread under the condition of replaying to the XA COMMIT or ROLLBACK phase of the sub-transaction of the distributed transaction, and after the replay is finished, the data table and the SQL thread are unbound.
In the embodiment, in the process of playback, for any sub-transaction of a distributed transaction, a data table of the sub-transaction belonging to the distributed transaction is created, and all execution processes of the sub-transaction of the distributed transaction are recorded through the data table, so that the continuity of the execution processes of the sub-transaction of one distributed transaction in the process of playback is guaranteed.
Referring to fig. 7, an interaction diagram of a processing method for a distributed transaction provided by an embodiment of the present invention is shown, where the method is applied to a distributed system, and the method includes:
s701, generating the version number of the sub-transaction under the condition that the sub-transaction of the distributed transaction executes the commit operation in the Mysql fragment database, and sending the version number of the sub-transaction to a TM transaction manager;
s702, the TM affair manager sends the version number of each sub-affair of the completed distributed affair to a preset cache database under the condition of receiving a preset trigger instruction;
s703, updating the stored version number by the preset cache database according to the received version number of each sub-transaction of the completed distributed transaction;
s704: the client sends a query instruction to the TM transaction manager;
s705, the TM transaction manager acquires a target version number of the target Mysql fragment database from the preset cache database; the target Mysql fragmentation database is the Mysql fragmentation database pointed by the query instruction;
s706: the TM transaction manager sends the query instruction and the target version number to the target Mysql fragmentation database;
s707: the method comprises the steps that under the condition that a target Mysql fragmentation database receives a query instruction and a target version number sent by a TM transaction manager, the execution result of a sub-transaction of a distributed transaction with the version number within the indication range of the target version number and corresponding to the query instruction is obtained;
s708: and the target Mysql fragmentation database sends the execution result of the sub-transaction of the distributed transaction, which has the version number within the indication range of the target version number and corresponds to the query instruction, to the TM transaction manager.
In this embodiment, the TM transaction manager controls a client in the Mysql fragment database to be able to query the version number of the distributed transaction, and the TM transaction manager receives the version numbers of the sub-transactions of the distributed transaction sent by the Mysql fragment database, and sends the version number of each sub-transaction of the completed distributed transaction to the preset cache database when receiving the preset trigger instruction, so that the cache database updates the version number. That is, the range indicated by the version number in the cache database is all the executed distributed transactions. Based on the above conditions, when receiving the query instruction sent by the client, the TM transaction manager sends the query instruction and the target version number pointed by the query instruction in the cache database to the Mysql fragment database, so that the execution result of the sub-transaction of the distributed transaction fed back by the Mysql fragment database does not exceed the range indicated by the target version number. Therefore, even if the Mysql fragment database stores the version number of a sub-transaction of a certain incomplete distributed transaction, the execution state of the sub-transaction of the incomplete distributed transaction is not fed back to the client by the limitation of the target version number sent by the TM transaction manager, so that the isolation of the distributed transaction is guaranteed.
Referring to fig. 8, a schematic structural diagram of a distributed transaction processing apparatus according to an embodiment of the present invention is shown, and in this embodiment, the apparatus includes:
a receiving unit 801, configured to receive, by the TM transaction manager, a version number of a sub-transaction of a distributed transaction sent by a Mysql shard database;
a first sending unit 802, configured to send, when a preset trigger instruction is received, a version number of each sub-transaction of a completed distributed transaction to a preset cache database, where the version number is a basis for updating the preset cache database; the completed distributed transaction is a distributed transaction in which the version numbers of all the sub-transactions are received;
a target version number obtaining unit 803, configured to obtain a target version number of the target Mysql fragment database in the preset cache database when receiving a query instruction from the client; the target Mysql fragmentation database is the Mysql fragmentation database pointed by the query instruction; the preset cache database stores the version number of each Mysql fragment database;
a query instruction and target version number sending unit 804, configured to send the query instruction and the target version number to the target Mysql fragment database; the target version number is a basis for the target Mysql fragmentation database to feed back the execution result of the sub-transaction of the distributed transaction corresponding to the query instruction, and the fed back version number of the sub-transaction of the distributed transaction of the execution result does not exceed the indication range of the target version number;
the execution result receiving unit 805 is configured to receive an execution result of the distributed sub-transaction fed back by the Mysql fragment database, and send the execution result of the distributed sub-transaction to the client.
Optionally, the method further includes:
a version number to be saved obtaining unit, configured to obtain a version number corresponding to each Mysql fragment database in the preset cache database, where the version number is used as a version number to be saved;
the historical version number clearing unit is used for sending a version number clearing instruction and a corresponding version number to be saved to each Mysql fragment database; the clear instruction and the version number to be saved are used for instructing the Mysql fragmentation database to clear other version numbers within the version number to be saved.
Optionally, the method further includes:
the sub-transaction determining unit of the to-be-recovered mode is used for determining and marking the sub-transaction of the to-be-recovered mode if the TM transaction manager is disconnected with the Mysql fragmentation database in the distributed transaction execution process; the sub-transaction in the to-be-recovered mode is a sub-transaction in an XA PREPARE stage when the TM transaction manager is disconnected with the Mysql fragmentation database;
the sub-transaction state determining unit is used for acquiring the states of other sub-transactions which belong to the same distributed transaction with the sub-transaction in the to-be-recovered mode;
an operation instruction determining unit, configured to determine, based on the states of the other sub-transactions, an operation instruction of the sub-transaction in the to-be-recovered mode; the operation instruction comprises a commit or a rollback;
and the operation instruction sending unit is used for sending the operation instruction of the sub-transaction in the to-be-recovered mode to the Mysql fragment database under the condition that the TM transaction manager establishes connection with the Mysql fragment database again.
Optionally, the operation instruction determining unit is specifically configured to:
if the states of other sub-transactions belonging to the same distributed transaction with the sub-transaction in the to-be-recovered mode are both submitted, the operation instruction of the sub-transaction in the to-be-recovered mode is submitted;
if the state of other sub-transactions belonging to the same distributed transaction with the sub-transaction in the to-be-recovered mode comprises a rollback state, the operation instruction of the sub-transaction in the to-be-recovered mode is rollback;
and if the state of other sub-transactions which belong to the same distributed transaction with the sub-transaction in the to-be-recovered mode does not have a rollback or a commit state, determining the operation instruction of the sub-transaction in the to-be-recovered mode according to a preset operation rule.
By the device of the embodiment, the isolation of the distributed transaction is guaranteed.
Referring to fig. 9, a schematic diagram of another structure of a distributed transaction processing apparatus according to an embodiment of the present invention is shown, in this embodiment, the apparatus includes:
a second sending unit 901, configured to generate a version number of a sub-transaction of a distributed transaction when the sub-transaction executes a commit operation in the Mysql fragmented database, and send the version number of the sub-transaction to the TM transaction manager;
an execution result obtaining unit 902, configured to, when receiving an inquiry instruction and a target version number sent by a TM transaction manager, obtain an execution result of a sub-transaction of a distributed transaction whose version number is within an indication range of the target version number and corresponding to the inquiry instruction; the target version number is acquired from a preset cache database; the cache database stores version numbers of each Mysql fragmentation database, the version numbers in the preset cache database are updated through the version numbers of each sub-transaction of the completed distributed transaction sent by the TM transaction manager, and the completed distributed transaction is the distributed transaction in which the version numbers of all the sub-transactions of the distributed transaction in the TM transaction manager are received;
an execution result sending unit 903, configured to send the execution result of the sub-transaction of the distributed transaction, where the version number is within the indicated range of the target version number and the sub-transaction corresponds to the query instruction, to the TM transaction manager.
Optionally, the execution result obtaining unit includes:
an execution result obtaining subunit, configured to obtain, when receiving the query instruction and the target version number sent by the TM transaction manager, an execution result of a sub-transaction of the distributed transaction corresponding to the query instruction;
and the execution result screening subunit is used for screening out the execution results of the sub-transactions of the distributed transactions corresponding to the query instruction, wherein the version number of the execution results of the sub-transactions of the distributed transactions is within the range of the target version number.
Optionally, the method further includes:
the recovery mode marking unit is used for marking the sub-transaction in the XA PREPARE stage as a recovery mode if the TM transaction manager is disconnected with the Mysql fragmentation database in the process of executing the distributed transaction;
an operation instruction receiving unit, configured to receive, when the TM transaction manager establishes a connection with the Mysql fragmentation database again, an operation instruction of the sub-transaction in the to-be-recovered mode sent by the TM transaction manager; the operation instruction of the sub-transaction in the mode to be recovered is determined based on the states of other sub-transactions which belong to the same distributed transaction as the sub-transaction in the mode to be recovered;
and the first operation instruction execution unit is used for executing the operation of committing or rolling back on the sub-transaction of the mode to be recovered according to the operation instruction.
Optionally, the method further includes:
the first connection session screening unit is used for screening out connection sessions without active transactions under the condition that the TM transaction manager establishes connection with the Mysql fragmentation database again;
and the second operation instruction execution unit is used for executing the operation instruction of the sub-transaction of the to-be-recovered mode through the connection session without the active transaction.
Optionally, the method further includes:
and the second connection session screening unit is used for screening an operation instruction of executing the sub-transaction of the to-be-recovered mode by one connection session under the condition that a plurality of connection sessions without active transactions exist.
Optionally, the method further includes:
the first playback unit is used for creating a new data table for recording the data change of the distributed transaction on the SQL thread and unbinding the data table and the SQL thread after the playback is finished if the XA START stage of a sub-transaction of the distributed transaction is played back in the process of playing back the record in the binlog of the Mysql fragment database; each phase in the process of executing the transaction is recorded in the binlog of the Mysql fragment database;
the second playback unit is used for binding the data table created in the previous XA START phase with the sub-transaction of the distributed transaction to the SQL thread if the playback is performed to the XA _ PREPARE phase of the sub-transaction of the distributed transaction and the distributed transaction corresponding to the sub-transaction is not completed, and unbinding the data table and the SQL thread after the playback is completed;
and the third playback unit is used for binding the data table recording the playback result of the XA _ PREPARE phase of the sub-transaction of the distributed transaction to the SQL thread if the playback is performed to the XA COMMIT or ROLLBACK phase of the sub-transaction of the distributed transaction, and unbinding the data table and the SQL thread after the playback is completed.
Optionally, the method further includes:
and the fourth playback unit is used for executing a commit operation on the sub-transaction of the distributed transaction when the playback reaches the XA _ PREPARE stage of the sub-transaction of the distributed transaction and the state of the distributed transaction to which the sub-transaction belongs is completed.
By the device in this embodiment, when the Mysql fragment database feeds back the query result pointed by the query instruction, the target version number sent by the TM transaction manager is needed, and since the target version number indicates that the version numbers in the version number range are all the version numbers of the sub-transactions of the executed and completed distributed transaction, based on the limitation of the target version number, the version numbers of the query results corresponding to the query instruction fed back by the Mysql fragment database are all in the range of the target version number, in this case, even if the Mysql fragment database stores the version number of a sub-transaction of a certain unexecuted and completed distributed transaction, the execution state of the incomplete sub-transaction is not fed back to the client, so that the isolation of the distributed transaction is ensured.
Referring to fig. 10, a schematic structural diagram of a distributed system provided in an embodiment of the present invention is shown, where the system includes:
a TM transaction manager cluster 1001, a Mysql database cluster 1002, and a preset cache database 1003;
the TM transaction manager cluster comprises at least one TM transaction manager, and the Mysql database cluster comprises at least one Mysql fragmentation database;
the TM transaction manager is used for executing the following processing methods of distributed transactions:
the TM transaction manager receives the version number of the sub-transaction of the distributed transaction sent by the Mysql fragment database;
under the condition that a preset trigger instruction is received, sending the version number of each sub-transaction of the completed distributed transaction to a preset cache database, wherein the version number is the basis for updating the preset cache database; the completed distributed transaction is a distributed transaction in which the version numbers of all the sub-transactions are received;
when a query instruction of a client is received, acquiring a target version number of a target Mysql fragment database from the preset cache database; the target Mysql fragmentation database is the Mysql fragmentation database pointed by the query instruction; the preset cache database stores the version number of each Mysql fragment database;
sending the query instruction and the target version number to the target Mysql fragment database; the target version number is a basis for the target Mysql fragmentation database to feed back the execution result of the sub-transaction of the distributed transaction corresponding to the query instruction, and the fed back version number of the sub-transaction of the distributed transaction of the execution result does not exceed the indication range of the target version number;
and receiving the execution result of the distributed sub-transaction fed back by the Mysql fragment database, and sending the execution result of the distributed sub-transaction to the client.
Optionally, the method further includes:
acquiring a version number corresponding to each Mysql fragment database in the preset cache database as a version number to be saved;
sending a version number clearing instruction and a corresponding version number to be saved to each Mysql fragment database; the clear instruction and the version number to be saved are used for instructing the Mysql fragmentation database to clear other version numbers within the version number to be saved.
Optionally, the method further includes:
in the process of executing the distributed transaction, if the TM transaction manager is disconnected with the Mysql fragmentation database, determining to mark the sub-transaction in the to-be-recovered mode; the sub-transaction in the to-be-recovered mode is a sub-transaction in an XA PREPARE stage when the TM transaction manager is disconnected with the Mysql fragmentation database;
acquiring the states of other sub-transactions which belong to the same distributed transaction with the sub-transaction in the mode to be recovered;
determining an operation instruction of the sub-transaction in the to-be-recovered mode based on the states of the other sub-transactions; the operation instruction comprises a commit or a rollback;
and under the condition that the TM transaction manager establishes connection with the Mysql fragment database again, sending an operation instruction of the sub-transaction of the to-be-recovered mode to the Mysql fragment database.
Optionally, the determining, based on the state of execution of the other sub-transactions, an operation instruction of the sub-transaction in the to-be-recovered mode includes:
if the states of other sub-transactions belonging to the same distributed transaction with the sub-transaction in the to-be-recovered mode are both submitted, the operation instruction of the sub-transaction in the to-be-recovered mode is submitted;
if the state of other sub-transactions belonging to the same distributed transaction with the sub-transaction in the to-be-recovered mode comprises a rollback state, the operation instruction of the sub-transaction in the to-be-recovered mode is rollback;
and if the state of other sub-transactions which belong to the same distributed transaction with the sub-transaction in the to-be-recovered mode does not have a rollback or a commit state, determining the operation instruction of the sub-transaction in the to-be-recovered mode according to a preset operation rule.
The Mysql fragmentation database is used for executing the following processing method of distributed transactions:
under the condition that the sub-transaction of the distributed transaction executes the commit operation in the Mysql fragmentation database, generating the version number of the sub-transaction, and sending the version number of the sub-transaction to a TM transaction manager;
under the condition of receiving a query instruction and a target version number sent by a TM transaction manager, acquiring an execution result of a sub-transaction of a distributed transaction, the version number of which is within an indication range of the target version number and corresponds to the query instruction; the target version number is acquired from a preset cache database; the cache database stores version numbers of each Mysql fragmentation database, the version numbers in the preset cache database are updated through the version numbers of each sub-transaction of the completed distributed transaction sent by the TM transaction manager, and the completed distributed transaction is the distributed transaction in which the version numbers of all the sub-transactions of the distributed transaction in the TM transaction manager are received;
and sending the execution result of the sub-transaction of the distributed transaction, which is within the indicated range of the target version number and corresponds to the query instruction, to the TM transaction manager.
Optionally, the obtaining, when receiving the query instruction and the target version number sent by the TM transaction manager, the execution result of the sub-transaction of the distributed transaction whose version number is within the indicated range of the target version number and corresponding to the query instruction includes:
under the condition of receiving a query instruction and a target version number sent by the TM transaction manager, acquiring an execution result of a sub-transaction of a distributed transaction corresponding to the query instruction;
and screening out the execution results of the sub-transactions of the distributed transactions corresponding to the query instruction, wherein the version number of the execution results of the sub-transactions of the distributed transactions is within the range of the target version number.
Optionally, the method further includes:
in the process of executing the distributed transaction, if the TM transaction manager is disconnected with the Mysql fragmentation database, marking the sub-transaction in the XA PREPARE stage as a to-be-recovered mode;
when the TM transaction manager establishes connection with the Mysql fragmentation database again, receiving an operation instruction of the sub-transaction of the to-be-recovered mode sent by the TM transaction manager; the operation instruction of the sub-transaction in the mode to be recovered is determined based on the states of other sub-transactions which belong to the same distributed transaction as the sub-transaction in the mode to be recovered;
and executing the operation of committing or rolling back on the sub-transaction of the mode to be recovered according to the operation instruction.
Optionally, the method further includes:
screening out a connection session without active transaction under the condition that the TM transaction manager establishes connection with the Mysql fragmentation database again;
and executing the operation instruction of the sub-transaction of the mode to be recovered through the connection session without the active transaction.
Optionally, in a case that the connection session includes a plurality of connection sessions where no active transaction exists, an operation instruction for screening one connection session to execute the sub-transaction of the to-be-recovered mode is screened.
Optionally, the method further includes:
in the process of replaying records in binlog of the Mysql fragment database, if the XA START stage of a sub-transaction of a distributed transaction is replayed, a new data table for recording the data change of the distributed transaction is created on the SQL thread, and after the replay is completed, the data table and the SQL thread are unbound; each phase in the process of executing the transaction is recorded in the binlog of the Mysql fragment database;
if the replay is performed to the XA _ PREPARE stage of the sub-transaction of the distributed transaction and the distributed transaction corresponding to the sub-transaction is incomplete, binding a data table created in the previous XA START stage by the sub-transaction of the distributed transaction to the SQL thread, and after the replay is completed, unbinding the data table and the SQL thread;
and if the data table recording the replay result of the XA _ PREPARE phase of the sub-transaction of the distributed transaction is bound to the SQL thread under the condition of replaying to the XA COMMIT or ROLLBACK phase of the sub-transaction of the distributed transaction, and after the replay is finished, the data table and the SQL thread are unbound.
Optionally, the method further includes:
and executing a commit operation on the sub-transaction of the distributed transaction in the XA _ PREPARE phase of the sub-transaction which is played back to the distributed transaction and the state of the distributed transaction to which the sub-transaction belongs is completed.
The preset cache database is used for receiving the version number of each sub-transaction of the distributed transaction sent by the TM transaction manager and updating the stored version number according to the received version number of each sub-transaction of the completed distributed transaction;
optionally, the preset cache database is a Redis database cluster;
optionally, referring to fig. 11, the distributed system further includes:
and the automatic recovery robot 1004 is used for sensing system faults, analyzing fault types and determining a fault solving strategy based on the fault types.
It should be noted that, in the present specification, the embodiments are all described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments may be referred to each other.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.

Claims (15)

1. A method for processing distributed transaction, the method is applied to a TM transaction manager in a distributed system, and comprises the following steps:
the TM transaction manager receives the version number of the sub-transaction of the distributed transaction sent by the Mysql fragment database;
under the condition that a preset trigger instruction is received, sending the version number of each sub-transaction of the completed distributed transaction to a preset cache database, wherein the version number is the basis for updating the preset cache database; the completed distributed transaction is a distributed transaction in which the version numbers of all the sub-transactions are received;
when a query instruction of a client is received, acquiring a target version number of a target Mysql fragment database from the preset cache database; the target Mysql fragmentation database is the Mysql fragmentation database pointed by the query instruction; the preset cache database stores the version number of each Mysql fragment database;
sending the query instruction and the target version number to the target Mysql fragment database; the target version number is a basis for the target Mysql fragmentation database to feed back the execution result of the sub-transaction of the distributed transaction corresponding to the query instruction, and the fed back version number of the sub-transaction of the distributed transaction of the execution result does not exceed the indication range of the target version number;
and receiving the execution result of the distributed sub-transaction fed back by the Mysql fragment database, and sending the execution result of the distributed sub-transaction to the client.
2. The method of claim 1, further comprising:
acquiring a version number corresponding to each Mysql fragment database in the preset cache database as a version number to be saved;
sending a version number clearing instruction and a corresponding version number to be saved to each Mysql fragment database; the clear instruction and the version number to be saved are used for instructing the Mysql fragmentation database to clear other version numbers within the version number to be saved.
3. The method of claim 1, further comprising:
in the process of executing the distributed transaction, if the TM transaction manager is disconnected with the Mysql fragmentation database, determining to mark the sub-transaction in the to-be-recovered mode; the sub-transaction in the to-be-recovered mode is a sub-transaction in an XA PREPARE stage when the TM transaction manager is disconnected with the Mysql fragmentation database;
acquiring the states of other sub-transactions which belong to the same distributed transaction with the sub-transaction in the mode to be recovered;
determining an operation instruction of the sub-transaction in the to-be-recovered mode based on the states of the other sub-transactions; the operation instruction comprises a commit or a rollback;
and under the condition that the TM transaction manager establishes connection with the Mysql fragment database again, sending an operation instruction of the sub-transaction of the to-be-recovered mode to the Mysql fragment database.
4. The method according to claim 3, wherein the determining the operation instruction of the sub-transaction in the to-be-recovered mode based on the execution state of the other sub-transactions comprises:
if the states of other sub-transactions belonging to the same distributed transaction with the sub-transaction in the to-be-recovered mode are both submitted, the operation instruction of the sub-transaction in the to-be-recovered mode is submitted;
if the state of other sub-transactions belonging to the same distributed transaction with the sub-transaction in the to-be-recovered mode comprises a rollback state, the operation instruction of the sub-transaction in the to-be-recovered mode is rollback;
and if the state of other sub-transactions which belong to the same distributed transaction with the sub-transaction in the to-be-recovered mode does not have a rollback or a commit state, determining the operation instruction of the sub-transaction in the to-be-recovered mode according to a preset operation rule.
5. A processing method of distributed transaction is characterized in that the method is applied to a Mysql fragmentation database of distributed transaction, and comprises the following steps:
under the condition that the sub-transaction of the distributed transaction executes the commit operation in the Mysql fragmentation database, generating the version number of the sub-transaction, and sending the version number of the sub-transaction to a TM transaction manager;
under the condition of receiving a query instruction and a target version number sent by a TM transaction manager, acquiring an execution result of a sub-transaction of a distributed transaction, the version number of which is within an indication range of the target version number and corresponds to the query instruction; the target version number is acquired from a preset cache database; the cache database stores version numbers of each Mysql fragmentation database, the version numbers in the preset cache database are updated through the version numbers of each sub-transaction of the completed distributed transaction sent by the TM transaction manager, and the completed distributed transaction is the distributed transaction in which the version numbers of all the sub-transactions of the distributed transaction in the TM transaction manager are received;
and sending the execution result of the sub-transaction of the distributed transaction, which is within the indicated range of the target version number and corresponds to the query instruction, to the TM transaction manager.
6. The method according to claim 5, wherein, in a case that the query instruction and the target version number sent by the TM transaction manager are received, acquiring an execution result of a sub-transaction of a distributed transaction whose version number is within an indicated range of the target version number and to which the query instruction corresponds, includes:
under the condition of receiving a query instruction and a target version number sent by the TM transaction manager, acquiring an execution result of a sub-transaction of a distributed transaction corresponding to the query instruction;
and screening out the execution results of the sub-transactions of the distributed transactions corresponding to the query instruction, wherein the version number of the execution results of the sub-transactions of the distributed transactions is within the range of the target version number.
7. The method of claim 5, further comprising:
in the process of executing the distributed transaction, if the TM transaction manager is disconnected with the Mysql fragmentation database, marking the sub-transaction in the XA PREPARE stage as a to-be-recovered mode;
when the TM transaction manager establishes connection with the Mysql fragmentation database again, receiving an operation instruction of the sub-transaction of the to-be-recovered mode sent by the TM transaction manager; the operation instruction of the sub-transaction in the mode to be recovered is determined based on the states of other sub-transactions which belong to the same distributed transaction as the sub-transaction in the mode to be recovered;
and executing the operation of committing or rolling back on the sub-transaction of the mode to be recovered according to the operation instruction.
8. The method of claim 7, further comprising:
screening out a connection session without active transaction under the condition that the TM transaction manager establishes connection with the Mysql fragmentation database again;
and executing the operation instruction of the sub-transaction of the mode to be recovered through the connection session without the active transaction.
9. The method according to claim 8, wherein in the case of a plurality of connection sessions without active transaction, the operation instruction for executing the sub-transaction of the to-be-recovered mode by one connection session is screened.
10. The method of claim 5, further comprising:
in the process of replaying records in binlog of the Mysql fragment database, if the XA START stage of a sub-transaction of a distributed transaction is replayed, a new data table for recording the data change of the distributed transaction is created on the SQL thread, and after the replay is completed, the data table and the SQL thread are unbound; each phase in the process of executing the transaction is recorded in the binlog of the Mysql fragment database;
if the replay is performed to the XA _ PREPARE stage of the sub-transaction of the distributed transaction and the distributed transaction corresponding to the sub-transaction is incomplete, binding a data table created in the previous XASTART stage with the sub-transaction of the distributed transaction to the SQL thread, and after the replay is completed, unbinding the data table and the SQL thread;
and if the data table recording the replay result of the XA _ PREPARE phase of the sub-transaction of the distributed transaction is bound to the SQL thread under the condition of replaying to the XACOMMIT or ROLLBACK phase of the sub-transaction of the distributed transaction, and after the replay is finished, the data table and the SQL thread are unbound.
11. The method of claim 10, further comprising:
and executing a commit operation on the sub-transaction of the distributed transaction in the XA _ PREPARE phase of the sub-transaction which is played back to the distributed transaction and the state of the distributed transaction to which the sub-transaction belongs is completed.
12. An apparatus for processing distributed transaction, the apparatus being applied to a TM transaction manager in a distributed system, the apparatus comprising:
a receiving unit, configured to receive, by the TM transaction manager, a version number of a sub-transaction of a distributed transaction sent by a Mysql fragmentation database;
the first sending unit is used for sending the version number of each sub-transaction of the completed distributed transaction to a preset cache database under the condition that a preset trigger instruction is received, wherein the version number is the basis for updating the preset cache database; the completed distributed transaction is a distributed transaction in which the version numbers of all the sub-transactions are received;
a target version number obtaining unit, configured to obtain a target version number of a target Mysql fragment database in the preset cache database when a query instruction of a client is received; the target Mysql fragmentation database is the Mysql fragmentation database pointed by the query instruction; the preset cache database stores the version number of each Mysql fragment database;
a query instruction and target version number sending unit, configured to send the query instruction and the target version number to the target Mysql fragment database; the target version number is a basis for the target Mysql fragmentation database to feed back the execution result of the sub-transaction of the distributed transaction corresponding to the query instruction, and the fed back version number of the sub-transaction of the distributed transaction of the execution result does not exceed the indication range of the target version number;
and the execution result receiving unit is used for receiving the execution result of the distributed sub-transaction fed back by the Mysql fragment database and sending the execution result of the distributed sub-transaction to the client.
13. An apparatus for processing a distributed transaction, the apparatus being applied to a Mysql sharded database of the distributed transaction, the apparatus comprising:
a second sending unit, configured to generate a version number of a sub-transaction of the distributed transaction when the sub-transaction executes a commit operation in the Mysql fragmented database, and send the version number of the sub-transaction to the TM transaction manager;
an execution result obtaining unit, configured to, when receiving an inquiry instruction and a target version number sent by a TM transaction manager, obtain an execution result of a sub-transaction of a distributed transaction whose version number is within an indication range of the target version number and to which the inquiry instruction corresponds; the target version number is acquired from a preset cache database; the cache database stores version numbers of each Mysql fragmentation database, the version numbers in the preset cache database are updated through the version numbers of each sub-transaction of the completed distributed transaction sent by the TM transaction manager, and the completed distributed transaction is the distributed transaction in which the version numbers of all the sub-transactions of the distributed transaction in the TM transaction manager are received;
and the execution result sending unit is used for sending the execution result of the sub-transaction of the distributed transaction, which has the version number within the indication range of the target version number and corresponds to the query instruction, to the TM transaction manager.
14. A distributed system, comprising:
the system comprises a TM transaction manager cluster, a Mysql database cluster and a preset cache database;
the TM transaction manager cluster comprises at least one TM transaction manager, and the Mysql database cluster comprises at least one Mysql fragmentation database;
the TM transaction manager is configured to execute the processing method of the distributed transaction according to any one of the preceding claims 1 to 4;
the Mysql fragmentation database is used for executing the processing method of the distributed transaction according to any one of the preceding claims 5 to 11;
the preset cache database is used for receiving the version number of each sub-transaction of the distributed transaction sent by the TM transaction manager and updating the stored version number according to the received version number of each sub-transaction of the completed distributed transaction.
15. The system of claim 14, further comprising:
and the automatic recovery robot is used for sensing system faults, analyzing fault types and determining a fault solving strategy based on the fault types.
CN202010947573.0A 2020-09-10 2020-09-10 Distributed transaction processing method, device and system Active CN111984665B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010947573.0A CN111984665B (en) 2020-09-10 2020-09-10 Distributed transaction processing method, device and system

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010947573.0A CN111984665B (en) 2020-09-10 2020-09-10 Distributed transaction processing method, device and system

Publications (2)

Publication Number Publication Date
CN111984665A true CN111984665A (en) 2020-11-24
CN111984665B CN111984665B (en) 2023-07-25

Family

ID=73449678

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010947573.0A Active CN111984665B (en) 2020-09-10 2020-09-10 Distributed transaction processing method, device and system

Country Status (1)

Country Link
CN (1) CN111984665B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114138888A (en) * 2021-12-03 2022-03-04 北京宇信科技集团股份有限公司 Processing method, system, medium and equipment for distributed data routing

Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080243865A1 (en) * 2007-03-28 2008-10-02 Oracle International Corporation Maintaining global state of distributed transaction managed by an external transaction manager for clustered database systems
CN106033437A (en) * 2015-03-13 2016-10-19 阿里巴巴集团控股有限公司 Method and system for processing distributed transaction
CN106156119A (en) * 2015-04-07 2016-11-23 阿里巴巴集团控股有限公司 A kind of distributed transaction communication means, system and device
CN106503132A (en) * 2016-10-19 2017-03-15 广州快塑电子商务有限公司 A kind of distributed transaction management method and system
US20180137166A1 (en) * 2016-11-17 2018-05-17 Sap Se Database Systems Architecture Incorporating Distributed Log
CN110019530A (en) * 2017-12-29 2019-07-16 百度在线网络技术(北京)有限公司 Transaction methods and device based on distributed data base

Patent Citations (6)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20080243865A1 (en) * 2007-03-28 2008-10-02 Oracle International Corporation Maintaining global state of distributed transaction managed by an external transaction manager for clustered database systems
CN106033437A (en) * 2015-03-13 2016-10-19 阿里巴巴集团控股有限公司 Method and system for processing distributed transaction
CN106156119A (en) * 2015-04-07 2016-11-23 阿里巴巴集团控股有限公司 A kind of distributed transaction communication means, system and device
CN106503132A (en) * 2016-10-19 2017-03-15 广州快塑电子商务有限公司 A kind of distributed transaction management method and system
US20180137166A1 (en) * 2016-11-17 2018-05-17 Sap Se Database Systems Architecture Incorporating Distributed Log
CN110019530A (en) * 2017-12-29 2019-07-16 百度在线网络技术(北京)有限公司 Transaction methods and device based on distributed data base

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
CARSTEN BINNING 等: "Distributed snapshot isolation:global transactions pay globally,local transactions pay locally", 《THE VLDB JOURNAL》, vol. 23, no. 3, pages 987 - 1011 *
张剑,刘梦赤: "面向信息网模型的高可扩展性分布式事务处理机制", 《计算机工程》, vol. 43, no. 11, pages 16 - 21 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114138888A (en) * 2021-12-03 2022-03-04 北京宇信科技集团股份有限公司 Processing method, system, medium and equipment for distributed data routing

Also Published As

Publication number Publication date
CN111984665B (en) 2023-07-25

Similar Documents

Publication Publication Date Title
CN109324757B (en) Block chain data capacity reduction method and device and storage medium
CN103077222B (en) Cluster file system distributed meta data consistance ensuring method and system
US7558883B1 (en) Fast transaction commit
CN106610876A (en) Method and device for recovering data snapshot
CN103294479A (en) Distribution type transaction processing method and system
KR20140147812A (en) Systems and methods for supporting inline delegation of middle-tier transaction logs to database
CN102203779B (en) Method for updating data and control apparatus thereof
EP3026574B1 (en) Affair processing method and device
CN106575251B (en) Speculative data processing of streaming data
CN102413166B (en) Distributed transaction method and system thereof
CN109063005B (en) Data migration method and system, storage medium and electronic device
CN112650812A (en) Data fragment storage method and device, computer equipment and storage medium
JP6079876B2 (en) Distributed processing system
CN111984665A (en) Distributed transaction processing method, device and system
US20130006920A1 (en) Record operation mode setting
CN110196788B (en) Data reading method, device and system and storage medium
CN114185991A (en) Method and related device for realizing data synchronization based on distributed database
CN117234670A (en) Distributed transaction processing method, system, computer equipment and storage medium
CN112148436A (en) Decentralized TCC (transmission control protocol) transaction management method, device, equipment and system
CN114661690A (en) Multi-version concurrency control and log clearing method, node, equipment and medium
CN112463786A (en) Data synchronization method, system, server and storage medium
Triantafillou et al. Efficiently maintaining availability in the presence of partitionings in distributed systems
JP2004295272A (en) Transaction control method
CN117573656B (en) Database upgrading method, electronic equipment and readable storage medium
CN112597176B (en) Processing method and system for transaction preservation points of distributed database

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
CB02 Change of applicant information

Address after: 401121 b7-7-2, Yuxing Plaza, No.5 Huangyang Road, Yubei District, Chongqing

Applicant after: Chongqing duxiaoman Youyang Technology Co.,Ltd.

Address before: 201800 room 307, 3 / F, building 8, 55 Huiyuan Road, Jiading District, Shanghai

Applicant before: SHANGHAI YOUYANG NEW MEDIA INFORMATION TECHNOLOGY Co.,Ltd.

CB02 Change of applicant information
TA01 Transfer of patent application right

Effective date of registration: 20211215

Address after: 100193 Room 606, 6 / F, building 4, West District, courtyard 10, northwest Wangdong Road, Haidian District, Beijing

Applicant after: Du Xiaoman Technology (Beijing) Co.,Ltd.

Address before: 401121 b7-7-2, Yuxing Plaza, No.5 Huangyang Road, Yubei District, Chongqing

Applicant before: Chongqing duxiaoman Youyang Technology Co.,Ltd.

TA01 Transfer of patent application right
GR01 Patent grant
GR01 Patent grant
TR01 Transfer of patent right

Effective date of registration: 20231229

Address after: Room 301, 3rd Floor, Building 4, West District, No.10 Northwest Wangdong Road, Haidian District, Beijing, 100085

Patentee after: Beijing Duxiaoman Payment Technology Co.,Ltd.

Patentee after: Du Xiaoman Technology (Beijing) Co.,Ltd.

Address before: 100193 Room 606, 6 / F, building 4, West District, courtyard 10, northwest Wangdong Road, Haidian District, Beijing

Patentee before: Du Xiaoman Technology (Beijing) Co.,Ltd.

TR01 Transfer of patent right