Detailed Description
In order to make the objects, technical solutions and advantages of the present application more apparent, the technical solutions of the present application will be described in detail and completely with reference to the following specific embodiments of the present application and the accompanying drawings. It should be apparent that the described embodiments are only some of the embodiments of the present application, 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 application.
The technical solutions provided by the embodiments of the present application are described in detail below with reference to the accompanying drawings.
Fig. 1 is a schematic diagram of an application scenario of a transaction processing method provided in an embodiment of the present specification. As shown in fig. 1, the present transaction processing method can be applied to a distributed system.
The system includes a server 10 as a coordinator, a server 21 as a participant, a server 22, and a server 23. The coordinator and participants are connected via a network. There may be a plurality of participants. When a transaction needs to be split into multiple sub-transactions, which are executed by multiple different servers, the transaction may be referred to as a master transaction. The corresponding individual sub-transactions may be referred to as branch transactions. The server responsible for the generation of the main transaction, as well as the processing of the branch transaction, may be referred to as the coordinator. The server responsible for the processing of the branch transaction may be referred to as a participant.
In order to ensure data consistency in a distributed system, a general procedure is that a coordinator sends a branch transaction preparation instruction to each participant in a first stage, and each participant performs a corresponding branch transaction preparation operation after receiving the instruction. After the coordinator determines that all participants are ready, in the second phase, a branch transaction commit instruction is sent to each participant. If the transaction commit fails, then retry is performed until all commits are successful. If the coordinator determines that all participants can not be completely prepared in the first stage, a rollback instruction is sent to each participant in the second stage; and after receiving the rollback instruction, the participant executes the rollback operation and releases the corresponding resource. If the rollback fails, retry is carried out until all rollback succeeds. The above-described manner of processing a distributed transaction using two phases is also referred to as two-phase commit of the distributed transaction. In the embodiments of the present specification, a transaction that a participant needs to process in the first phase, which is referred to as a one-phase transaction, is simply referred to as a two-phase transaction.
However, the inventors have studied and found that the one-stage command and the two-stage command sent by the coordinator to the participants may arrive out of order at the participants due to network delay or network jitter. If the participant receives a two-phase instruction before the one-phase transaction is completed, the two-phase transaction will begin to be processed before the one-phase transaction is completed. This results in that after the one-phase transaction is completed, the subsequent two-phase instruction cannot be received, and thus the one-phase transaction is in a suspended state.
Specifically, for example: user a transfers 100 dollars to user B's account at Y bank through X bank's account. The server corresponding to the account of bank X may be considered participant a and the server corresponding to the account of bank Y may be considered participant B. Normally, the server as the coordinator sends two different one-phase instructions to participant a and participant B, respectively. A phase instruction is sent to participant a instructing participant a to perform a freeze operation on 100 elements in user a's account. A phase instruction sent to participant B instructing participant B to add 100 elements to user B's account whose status is unavailable. After receiving the first-stage instruction, the participant a freezes 100 yuan in the account of the user a according to the first-stage instruction, and after receiving the first-stage instruction, the participant B performs an operation of adding 100 yuan to the account of the user B according to the instruction, wherein the added 100 yuan is in an unavailable state. After the participant a and the participant B respectively complete the operations that need to be executed, a message that the one-phase transaction is ready is sent to the coordinator. After receiving the message, the coordinator sends two-stage instructions to the participant A and the participant B. A two-phase instruction is sent to participant a instructing participant a to delete the 100 elements frozen in user a's account completely. A two-phase instruction sent to participant B instructing participant B to change the 100-tuple in user B's account for which the status is unavailable to an available status. And after receiving the corresponding two-stage instructions, the participant A and the participant B execute corresponding operations, and finally finish the operation of transferring 100 yuan to the user B by the user A.
If for some reason, neither participant a or participant B sends a message to the coordinator within a preset time indicating that a phase of the transaction is ready, the coordinator sends a two-phase instruction to participant a and participant B, respectively, indicating that participant a and participant B are rolling back. Normally, participant a would unfreeze the frozen 100-dollar account of a according to the two-phase instruction. Participant B may delete the 100-tuple whose status was previously added as unavailable according to the two-phase instruction. However, due to network latency or network jitter, the two-phase instruction may arrive before the one-phase transaction is completed. Taking participant a as an example, in the case that participant a has not finished freezing 100 bins, the rollback operation (which may be a null rollback here) corresponding to the two-phase instruction has already been performed. After the two-phase instruction is executed, if the participant a continues to execute the one-phase instruction, 100 yuan will be frozen, and since the two phases will not be executed any more, the frozen 100 yuan will be in the frozen state all the time, so that the amount of 100 yuan in the account of the user a cannot be used. This case, also referred to as a one-phase transaction, is suspended.
Fig. 2 is a flowchart of a transaction processing method according to an embodiment of the present disclosure. From a procedural perspective, the execution subject of a flow may be a program deployed on a server as a participant in a distributed system.
As shown in fig. 2, the process may include the following steps:
s201, acquiring an instruction which is sent by a server and used for instructing one-stage transaction processing; the first-phase transaction is a transaction needing to be processed in the first phase by a main transaction needing to be submitted in two phases; the instruction comprises a main transaction identifier of the main transaction.
In a transaction that requires a two-phase commit, the master transaction may include two phases, a first phase, which is a prepare phase, and a second phase, which is a commit phase or a rollback phase. In the embodiment of the present specification, after the first phase preparation is completed, the second phase is mainly rolled back.
In the embodiment of the present specification, the master transaction id is unique in the whole master transaction and is used to identify the master transaction, and the master transaction ids may be represented in different forms, for example, each master transaction id is represented by a different arabic number, capital letter or small letter.
S202, determining that two-phase transactions of the main transaction are not executed; the two-phase transaction is a transaction which needs to be processed in the second phase by a main transaction needing two-phase submission.
In this embodiment of the present specification, after the one-phase preparation is completed, in order to avoid confusion of the execution order of the one-phase transaction and the two-phase transaction due to network delay or network jitter, it is necessary to determine that the two-phase transaction of the main transaction has not been executed yet.
S203, processing the one-phase transaction.
In this specification embodiment, upon determining that a two-phase transaction of the master transaction has not been executed, the participant may proceed with the processing of the one-phase transaction according to an indication sent by the coordinator.
In the prior art, when a participant executes a transaction submitted in two phases, the participant does not know whether the transaction in the second phase is executed or not when the participant executes the transaction in the first phase; the participants themselves are unaware of whether the first phase transaction has already been executed while executing the second phase transaction. Therefore, the following may occur: the participator adopts different threads to process the affairs of the two phases at the same time, or the participator processes the affairs of the second phase firstly and then processes the affairs of the first phase, which leads to that the affairs of the first phase are suspended after being processed.
Optionally, the determining that the two-phase transaction of the main transaction is not executed may specifically include:
and inquiring the master transaction record containing the master transaction identifier to obtain a first inquiry result.
Locking the master transaction record when the first query result indicates that the master transaction record is queried.
Optionally, the method may further include:
and when the first query result indicates that the query does not reach the main transaction record containing the main transaction identifier, inserting the main transaction record containing the main transaction identifier.
And inquiring whether a rollback record containing the main transaction identifier exists or not to obtain a second inquiry result.
The processing the one-phase transaction may specifically include:
and when the second query result indicates that the query does not reach the rollback record containing the primary transaction identifier, processing the one-phase transaction.
Optionally, after querying whether there is a rollback record containing the primary transaction identifier, the method may further include:
and when the second query result shows that the rollback record containing the main transaction identifier exists, ending the process of processing the one-phase transaction.
Optionally, after querying the master transaction record containing the master transaction identifier, the method may further include:
and when the first query result shows that the query does not reach the main transaction record containing the main transaction identifier, querying a rollback record containing the main transaction identifier to obtain a third query result.
And when the third query result indicates that the query does not reach the rollback record containing the main transaction identifier, performing locking operation on the storage area of the rollback record containing the main transaction identifier.
Inserting a master transaction record containing the master transaction identification.
Optionally, after the querying the rollback record containing the primary transaction identifier, the method may further include:
and when the third query result shows that the rollback record containing the main transaction identifier is queried, ending the process of processing the one-phase transaction.
In this embodiment of the present specification, it is determined that the two-phase transaction of the main transaction has not been executed, and it is ensured that after the one-phase transaction is executed, the corresponding two-phase transaction can be executed, so that a hang phenomenon is avoided after the one-phase transaction is executed.
After the scheme is adopted, the participator can determine that the two-phase transaction is not executed after the instruction which is sent by the server and indicates the one-phase transaction processing is obtained, then the one-phase transaction is processed, the processing process of the one-phase transaction and the two-phase transaction is correctly coordinated, and an error transaction processing result can not be generated even if the one-phase instruction and the two-phase instruction arrive out of order.
Fig. 3 is a schematic flow chart of a first-phase transaction process provided in an embodiment of the present specification. From a procedural perspective, the execution subject of a flow may be a program deployed on a server as a participant in a distributed system.
As shown in FIG. 3, upon receiving an instruction sent by the coordinator instructing a one-phase transaction to proceed, the participants may perform the following steps:
s301, inquiring the master transaction record containing the master transaction identifier to obtain a first inquiry result. When the first query result indicates that a primary transaction record containing the primary transaction identifier is queried, executing step S302; when the first query result indicates that the query does not reach the primary transaction record containing the primary transaction identifier, step S303 is executed.
S302, when the first query result shows that the main transaction record is queried, locking the main transaction record.
In the embodiment corresponding to fig. 3, the isolation level of the database is R-C (Read committed), and the exclusive lock method is adopted for processing. The first-stage transaction queries a main transaction record containing a main transaction identifier to obtain a first query result, when the first query result indicates that the main transaction record is queried, the first query result indicates that the main transaction record is not locked by the second-stage transaction, namely the second-stage transaction does not start to be executed, the first-stage transaction locks the main transaction record, in the execution process of the first-stage transaction, if the second-stage transaction receives an execution instruction in advance and wants to start to execute, the main transaction record is queried and locked first, at the moment, the first-stage transaction locks the main transaction record, and the second-stage transaction can start to execute only when the first-stage execution is finished and the main transaction record is released.
S303, when the first query result shows that the query does not reach the master transaction record containing the master transaction identifier, inserting the master transaction record containing the master transaction identifier.
In this embodiment, when the primary transaction record containing the primary transaction identifier is not queried, the primary transaction record containing the primary transaction identifier may be inserted first, which represents that the transaction has not been executed in one stage.
S306, inquiring whether a rollback record containing the main transaction identifier exists or not to obtain a second inquiry result. When the second query result indicates that a rollback record containing the primary transaction identifier is queried, executing step S307; when the first query result indicates that the query does not reach the rollback record containing the primary transaction identifier, step S304 is performed.
In this embodiment of the present specification, after the master transaction record containing the master transaction identifier is inserted without querying the master transaction record, it is required to query whether a rollback record containing the master transaction identifier exists.
S307, when the second query result shows that the rollback record containing the main transaction identifier exists, ending the process of processing the one-phase transaction.
In this embodiment of the present specification, after querying that a rollback record including a main transaction identifier exists, it indicates that a rollback operation has been performed in the second transaction stage, that is, the second transaction stage performs a null rollback when the first transaction stage is not ready, and cannot perform a commit operation on the first transaction stage any more, and it is necessary to abnormally end a process for processing a one-stage transaction.
S304, when the second query result shows that the rollback record containing the main transaction identifier cannot be queried, processing the one-phase transaction.
In this embodiment, when the second query result indicates that the query does not reach the rollback record containing the primary transaction identifier, it indicates that the second transaction stage has not been executed yet. Branch transactions may be processed and branch transaction records inserted after branch transaction processing is complete. In addition, there may be multiple branch transactions, and after one branch transaction is processed and recorded, the next branch transaction is rolled back and recorded in sequence until all branch transactions are processed.
S305, normally ending the process of processing the one-phase transaction.
After the scheme is adopted, the serial execution of the first-stage transaction and the second-stage transaction is ensured by using the competition between the exclusive locks of the database, the normal execution of the first-stage transaction is ensured under the condition that the second-stage transaction is not executed, and the problem of hanging the first-stage transaction is avoided.
Fig. 4 is a flowchart of a first phase transaction process according to another embodiment of the present disclosure. From a procedural perspective, the execution subject of a flow may be a program deployed on a server as a participant in a distributed system.
As shown in fig. 4, the process may include the following steps:
s401, inquiring the main transaction record containing the main transaction identification to obtain a first inquiry result.
S402, when the first query result shows that the master transaction record is queried, locking the master transaction record.
After the primary transaction record is locked, step S404 may be performed.
In the embodiment corresponding to FIG. 4, the isolation level of the database is R-R (Repeatable Read).
The first-stage transaction queries a master transaction record containing a master transaction identifier to obtain a first query result. When the first query result indicates that the master transaction record is queried, the master transaction record is not locked on behalf of the two-phase transaction, i.e., the two-phase transaction has not yet begun execution. After the primary transaction record is locked by the first-stage transaction, in the execution process of the first-stage transaction, if the participant receives a processing instruction of the second-stage transaction sent by the coordinator in advance, the rollback record containing the primary transaction identifier may be firstly queried in the record table storing the rollback record. And if the rollback record containing the main transaction identifier is not inquired, inserting the rollback record of the main transaction identifier. And then inquiring the main transaction record, and if the main transaction record is inquired at the moment, executing the operation of locking the main transaction record. If the main transaction record is already locked in the process of executing the first-stage transaction, in the process of executing the second-stage transaction, the participant can lock the main transaction record only after the main transaction record is released after the first-stage transaction is executed, so that the condition that the second-stage transaction cannot be executed in the process of executing the first-stage transaction is ensured.
S403, when the first query result shows that the query does not reach the master transaction record containing the master transaction identifier, querying a rollback record containing the master transaction identifier to obtain a third query result. When the third query result indicates that the query finds that the rollback record containing the master transaction identifier is queried, executing step S408; when the third query result indicates that the query does not reach the rollback record containing the master transaction identifier, step S406 is executed.
S406, when the third query result shows that the rollback record containing the main transaction identifier cannot be queried, performing locking operation on the storage area containing the rollback record containing the main transaction identifier.
In this embodiment, when the rollback record containing the primary transaction identifier is not queried, the storage area of the rollback record containing the primary transaction identifier may be locked, representing that the two-phase transaction has not been executed. The two-phase transaction cannot operate on the storage area of the rollback record during the period, and the two-phase transaction cannot be executed in the execution process of the one-phase transaction.
S407, inserting the master transaction record containing the master transaction identifier.
S404, processing the one-phase transaction.
S405, normally ending the process of processing the one-phase transaction.
In embodiments of the present description, processing a branch transaction may begin after a master transaction record containing a master transaction identification is inserted or after the master transaction record is queried and locked. And inserting branch transaction records after the branch transaction processing is completed. In addition, there may be multiple branch transactions, and after one branch transaction is processed and recorded, the next branch transaction is executed and recorded in sequence until all branch transactions are completed.
S408, when the third query result shows that the rollback record containing the main transaction identifier is queried, ending the process of processing the one-phase transaction.
In this embodiment of the present specification, when a rollback record containing the identification of the main transaction is queried, it represents that the second-stage transaction has completed rollback, that is, the second-stage transaction has been executed before the first-stage transaction is executed, and at this time, the process of processing the first-stage transaction may be aborted.
After the scheme is adopted, the locking method of the database is used for processing, serial execution of the first-stage transaction and the second-stage transaction is guaranteed, the condition that the first-stage transaction can be normally executed under the condition that the second-stage transaction is not executed is guaranteed, and the problem of hanging of the first-stage transaction is avoided.
Fig. 5 is a flowchart illustrating a transaction processing method according to another embodiment of the present disclosure. From a procedural perspective, the execution subject of a flow may be a program deployed on a server as a participant in a distributed system.
As shown in fig. 5, the process may include the following steps:
s501, a rollback instruction which is sent by a server and used for indicating to perform two-stage transaction processing is obtained; the two-stage transaction is a transaction needing to be processed in the second stage by a main transaction needing to be submitted in two stages; the rollback instruction comprises a main transaction identifier of the main transaction.
In this embodiment of the present specification, the transaction that needs to be processed in the second phase is a rollback.
S502, determining that a phase transaction of the main transaction is executed; the one-phase transaction is a transaction which needs to be processed in the first phase by a main transaction needing two-phase submission.
In this embodiment of the present specification, in order to avoid confusion of the execution order of the first-phase transaction and the second-phase transaction due to network delay or network jitter, it is necessary to determine that the first-phase transaction is completely executed when the second-phase transaction of the main transaction is executed.
S503, executing a rollback operation on the executed one-phase transaction.
In this illustrative embodiment, upon determining that the one-phase transaction of the master transaction has completed execution, the participant may perform a rollback of the one-phase transaction based on the indication sent by the coordinator.
Optionally, the determining that the one-stage transaction of the main transaction is executed may specifically include:
and inquiring the master transaction record containing the master transaction identifier to obtain a first inquiry result.
And locking the master transaction record when the first query result indicates that the master transaction record containing the master transaction identifier is queried.
Optionally, after performing the rollback operation on the executed one-phase transaction, the method may further include:
inserting a rollback record containing the master transaction identification.
Optionally, after querying the master transaction record containing the master transaction identifier, the method may further include:
and when the first query result indicates that the query does not reach the main transaction record containing the main transaction identifier, inserting the main transaction record containing the main transaction identifier.
Deleting the master transaction record.
And inquiring the rollback record containing the main transaction identifier to obtain a second inquiry result.
And when the second query result indicates that the query does not reach the rollback record containing the main transaction identifier, inserting the rollback record containing the main transaction identifier.
Optionally, after the querying the rollback record containing the primary transaction identifier, the method may further include:
and when the second query result shows that the rollback record containing the main transaction identifier is queried, ending the process of processing the two-phase transaction.
Optionally, before the querying the master transaction record containing the master transaction identifier, the method may further include:
and inquiring the rollback record containing the main transaction identifier to obtain a third inquiry result.
And when the third query result shows that the query does not reach the rollback record containing the main transaction identifier, inserting the rollback record containing the main transaction identifier.
Optionally, after the querying the rollback record containing the primary transaction identifier, the method may further include:
and when the third query result shows that the rollback record containing the main transaction identifier is queried, ending the process of processing the two-phase transaction.
Optionally, after inserting the rollback record containing the master transaction identifier, the method may further include:
and when the first query result shows that the query does not reach the main transaction record containing the main transaction identifier, ending the process of processing the two-phase transaction.
After the scheme is adopted, the participator can determine that the two-phase transaction is not executed after the instruction which is sent by the server and indicates the one-phase transaction processing is obtained, then the one-phase transaction is processed, the processing process of the one-phase transaction and the two-phase transaction is correctly coordinated, and an error transaction processing result can not be generated even if the one-phase instruction and the two-phase instruction arrive out of order.
Fig. 6 is a flowchart of a second phase transaction process provided in an embodiment of the present specification. From a procedural perspective, the execution subject of a flow may be a program deployed on a server as a participant in a distributed system.
As shown in fig. 6, after receiving the instruction sent by the coordinator to instruct the two-phase transaction processing, the participants may perform the following steps:
s601, inquiring the main transaction record containing the main transaction identifier to obtain a first inquiry result. When the first query result indicates that a primary transaction record containing the primary transaction identifier is queried, executing step S602; when the first query result indicates that the query does not reach the master transaction record containing the master transaction identifier, step S603 is executed.
S602, when the first query result shows that the master transaction record containing the master transaction identifier is queried, locking the master transaction record.
S604, inquiring the branch transaction record and rolling back the branch transaction.
S605, inserting a rollback record containing the main transaction identifier.
In this embodiment of the present specification, when a master transaction record containing a master transaction identifier is queried, the master transaction record is first locked, so as to prevent a one-phase transaction from locking the master transaction record in the process of a two-phase transaction. Then, the branch transaction record is inquired, after the branch transaction record is inquired, the branch transaction is rolled back, and the roll-back record containing the main transaction identifier is inserted. In addition, there may be multiple branch transactions, and after one branch transaction is rolled back and recorded, the next branch transaction is rolled back and recorded in turn until all branch transactions are completed.
S603, when the first query result shows that the query does not reach the master transaction record containing the master transaction identifier, inserting the master transaction record containing the master transaction identifier.
S607, deleting the main transaction record.
S608, the rollback record containing the main transaction identifier is inquired, and a second inquiry result is obtained. When the second query result indicates that the query does not reach the rollback record containing the primary transaction identifier, executing step S605; when the second query result indicates that a rollback record containing the primary transaction identifier is queried, step S606 is executed.
S605, when the second query result shows that the query does not reach the rollback record containing the main transaction identifier, inserting the rollback record containing the main transaction identifier.
In this illustrative embodiment, when the primary transaction record identified by the primary transaction is not queried, representing that the one-phase transaction has not been executed, a rollback instruction for the two-phase transaction may indicate that the participant is reached prior to or during the time that the one-phase transaction has not been executed. In order to avoid the suspension of the one-phase transaction, a primary transaction record containing a primary transaction identifier can be inserted firstly, a certain storage space is occupied, and then the primary transaction record is deleted. In this embodiment, a database of R-C isolation levels is employed. In the database of the R-C isolation level, because a gap lock cannot be used, in order to occupy the storage space of the main transaction record, in the process of executing the two-phase transaction, if the one-phase transaction is executed, the one-phase transaction cannot be inserted because the storage space corresponding to the main transaction record is occupied when the step of inserting the main transaction record is executed. When the two-phase transaction is completed, the one-phase transaction can be executed continuously. When the one-phase transaction is continuously executed, the participant can inquire the rollback record generated by the executed two-phase transaction, and then can abnormally end the one-phase transaction, so that the problem of hanging the one-phase transaction is avoided.
S606, when the second query result shows that the rollback record containing the main transaction identifier is queried, ending the process of processing the two-stage transaction.
In this embodiment, when a rollback record containing the primary transaction identifier is queried, it indicates that the rollback record can be queried by the second-phase transaction during execution, and the second-phase transaction can be normally ended.
Fig. 7 is a flowchart of a second phase transaction process according to another embodiment of the present disclosure. From a procedural perspective, the execution subject of a flow may be a program deployed on a server as a participant in a distributed system.
As shown in fig. 7, after receiving the instruction sent by the coordinator to instruct the two-phase transaction processing, the participants may perform the following steps:
s701, a rollback record containing the main transaction identifier is inquired, and a third inquiry result is obtained. When the third query result indicates that the query does not reach the rollback record containing the master transaction identifier, executing step S702; when the third query result indicates that a rollback record containing the master transaction identifier is queried, executing step S704;
s702, when the third query result shows that the rollback record containing the main transaction identifier cannot be queried, locking a storage area of the rollback record containing the main transaction identifier.
S703, inserting a rollback record containing the main transaction identifier.
In this embodiment of the present specification, in the process of the second-stage transaction processing, a participant may first query whether a rollback record including the main transaction identifier is included, and when the rollback record including the main transaction identifier is not queried, it represents that the second-stage transaction has not performed a rollback operation yet, and may first lock a storage area of the rollback record including the main transaction identifier, and then insert the rollback record including the main transaction identifier. It is guaranteed that a one-phase transaction cannot be executed during execution of the two-phase transaction. After the two-phase transaction is executed, the participant can inquire the rollback record in the one-phase transaction, and then abnormally ends the one-phase transaction, so that the condition that the one-phase transaction is suspended is avoided.
S704, when the third query result shows that the rollback record containing the main transaction identifier is queried, ending the process of processing the two-stage transaction.
In this embodiment of the present specification, when a rollback record containing a main transaction identifier is queried, it represents that the rollback of the two-phase transaction has been completed, and the process of processing the two-phase transaction may be normally ended.
After inserting the rollback record containing the primary transaction identifier, the method may further include:
s705, inquiring the master transaction record containing the master transaction identifier to obtain a first inquiry result. When the first query result indicates that a primary transaction record containing the primary transaction identifier is queried, executing step S706; when the first query result indicates that the query does not reach the primary transaction record containing the primary transaction identifier, step S704 is executed.
S704, when the first query result shows that the query does not reach the main transaction record containing the main transaction identifier, ending the process of processing the two-stage transaction.
In this embodiment of the present specification, the main transaction record containing the main transaction identifier is not queried, which means that the one-phase transaction has not been executed yet, and the process of processing the two-phase transaction can be normally ended.
S706, when the first query result shows that the master transaction record containing the master transaction identifier is queried, locking the master transaction record.
S707, inquiring the branch transaction record and rolling back the branch transaction.
In this embodiment, when the master transaction record containing the master transaction identifier is queried, the master transaction record can be locked, which represents that the transaction has been executed in one stage. The branch transaction record may be queried and the branch transaction rolled back and then re-recorded. In addition, there may be multiple branch transactions, and after one branch transaction is rolled back and recorded, the next branch transaction is rolled back and recorded in turn until all branch transactions are completed.
Based on the same idea, the embodiment of the present specification further provides a device corresponding to the above method. Fig. 8 is a schematic structural diagram of a transaction processing device corresponding to fig. 2 according to an embodiment of the present disclosure. As shown in fig. 8, the apparatus may include:
an instruction obtaining module 801, configured to obtain an instruction that instructs to perform one-stage transaction processing and is sent by a server; the first-phase transaction is a transaction needing to be processed in the first phase by a main transaction needing to be submitted in two phases; the instruction comprises a main transaction identifier of the main transaction.
A determining module 802 for determining that a two-phase transaction of the master transaction has not been executed; the two-phase transaction is a transaction which needs to be processed in the second phase by a main transaction needing two-phase submission.
A one-phase transaction processing module 803, configured to process the one-phase transaction.
Optionally, the determining module may specifically include:
the first result determining unit is used for inquiring the main transaction record containing the main transaction identifier to obtain a first inquiry result;
and the master transaction record locking unit is used for locking the master transaction record when the first query result shows that the master transaction record is queried.
Optionally, the determining module may further include:
and the first master transaction record inserting unit is used for inserting the master transaction record containing the master transaction identifier when the first query result shows that the master transaction record containing the master transaction identifier cannot be queried.
And the second result determining unit is used for inquiring whether the rollback record containing the main transaction identifier exists or not to obtain a second inquiry result.
The one-phase transaction processing module may specifically include:
and the one-phase transaction processing unit is used for processing the one-phase transaction when the second query result shows that the rollback record containing the main transaction identifier is not queried.
Optionally, the apparatus may further include:
and a first end unit, configured to end the process of processing the one-phase transaction when the second query result indicates that a rollback record including the master transaction identifier exists.
Optionally, the apparatus may further include:
and the third result determining unit is used for inquiring the rollback record containing the main transaction identifier to obtain a third inquiry result when the first inquiry result shows that the main transaction record containing the main transaction identifier cannot be inquired.
And the locking unit is used for executing locking operation on the storage area of the rollback record containing the main transaction identifier when the third query result shows that the rollback record containing the main transaction identifier cannot be queried.
And the second master transaction record inserting unit is used for inserting the master transaction record containing the master transaction identifier.
Optionally, the apparatus may further include:
and the second ending unit is used for ending the process of processing the one-phase transaction when the third query result shows that the rollback record containing the main transaction identifier is queried.
Based on the same idea, the embodiment of the present specification further provides a device corresponding to the above method. Fig. 9 is a schematic structural diagram of a transaction processing apparatus corresponding to fig. 5 provided in an embodiment of this specification. As shown in fig. 9, the apparatus may include:
a rollback instruction obtaining module 901, configured to obtain a rollback instruction that instructs to perform two-stage transaction processing and is sent by a server; the two-stage transaction is a transaction needing to be processed in the second stage by a main transaction needing to be submitted in two stages; the rollback instruction comprises a main transaction identifier of the main transaction.
A determining module 902, configured to determine that a phase transaction of the master transaction has been executed; the one-phase transaction is a transaction which needs to be processed in the first phase by a main transaction needing two-phase submission.
And a rollback execution module 903, configured to execute a rollback operation on the one-phase transaction that has been executed.
Optionally, the determining module may specifically include:
and the first result determining unit is used for inquiring the master transaction record containing the master transaction identifier to obtain a first inquiry result.
And the master transaction record locking unit is used for locking the master transaction record when the first query result shows that the master transaction record containing the master transaction identifier is queried.
Optionally, the apparatus may further include:
the first inserting module is used for executing the rollback record operation containing the main transaction identifier after the one-phase transaction rollback operation executing module executes the rollback operation on the executed one-phase transaction.
Optionally, the determining module may further include:
and the master transaction record inserting unit inserts the master transaction record containing the master transaction identifier when the first query result shows that the master transaction record containing the master transaction identifier cannot be queried.
And the master transaction record deleting unit is used for deleting the master transaction record.
And the second result determining unit is used for inquiring the rollback record containing the main transaction identifier to obtain a second inquiry result.
And the second inserting unit is used for inserting the rollback record containing the main transaction identifier when the second query result shows that the rollback record containing the main transaction identifier cannot be queried.
Optionally, the apparatus may further include:
and the first end unit is used for ending the process of processing the two-stage transaction when the second query result indicates that the rollback record containing the main transaction identifier is queried.
Optionally, the apparatus may further include:
and the third result determining unit is used for executing the operation of inquiring the rollback record containing the main transaction identifier to obtain a third inquiry result before the first inquiry result determining unit inquires the main transaction record containing the main transaction identifier.
And the third inserting unit is used for inserting the rollback record containing the main transaction identifier when the third query result shows that the rollback record containing the main transaction identifier cannot be queried.
Optionally, the apparatus may further include:
and the second ending unit is used for ending the process of processing the two-stage transaction when the third query result shows that the rollback record containing the main transaction identifier is queried.
Optionally, the apparatus may further include:
and the third ending unit is used for ending the process of processing the two-phase transaction when the first query result shows that the query does not reach the main transaction record containing the main transaction identifier.
Based on the same idea, the embodiment of the present specification further provides a device corresponding to the above method.
Fig. 10 is a schematic structural diagram of a transaction processing device corresponding to fig. 2 and 5 according to an embodiment of the present disclosure. As shown in fig. 10, the apparatus 1000 may include:
at least one processor 1010; and the number of the first and second groups,
a memory 1030 communicatively coupled to the at least one processor; wherein,
the memory 1030 stores instructions 1020 that are executable by the at least one processor 1010, the instructions being executed by the at least one processor 1010.
Corresponding to fig. 2, the instructions may enable the at least one processor 1010 to: acquiring an instruction which is sent by a server and used for indicating one-stage transaction processing; the first-phase transaction is a transaction needing to be processed in the first phase by a main transaction needing to be submitted in two phases; the instruction comprises a main transaction identifier of the main transaction.
Determining that a two-phase transaction of the master transaction has not been executed; the two-phase transaction is a transaction which needs to be processed in the second phase by a main transaction needing two-phase submission.
The one-phase transaction is processed.
Corresponding to fig. 5, the instructions may enable the at least one processor 1010 to: acquiring a rollback instruction which is sent by a server and used for indicating to perform two-stage transaction processing; the two-stage transaction is a transaction needing to be processed in the second stage by a main transaction needing to be submitted in two stages; the rollback instruction comprises a main transaction identifier of the main transaction.
Determining that a phase transaction of the master transaction has been executed; the one-phase transaction is a transaction which needs to be processed in the first phase by a main transaction needing two-phase submission.
And executing a rollback operation on the executed one-phase transaction.
In the 90 s of the 20 th century, improvements in a technology could clearly distinguish between improvements in hardware (e.g., improvements in circuit structures such as diodes, transistors, switches, etc.) and improvements in software (improvements in process flow). However, as technology advances, many of today's process flow improvements have been seen as direct improvements in hardware circuit architecture. Designers almost always obtain the corresponding hardware circuit structure by programming an improved method flow into the hardware circuit. Thus, it cannot be said that an improvement in the process flow cannot be realized by hardware physical modules. For example, a Programmable Logic Device (PLD), such as a Field Programmable Gate Array (FPGA), is an integrated circuit whose Logic functions are determined by programming the Device by a user. A digital system is "integrated" on a PLD by the designer's own programming without requiring the chip manufacturer to design and fabricate application-specific integrated circuit chips. Furthermore, nowadays, instead of manually making an integrated Circuit chip, such Programming is often implemented by "logic compiler" software, which is similar to a software compiler used in program development and writing, but the original code before compiling is also written by a specific Programming Language, which is called Hardware Description Language (HDL), and HDL is not only one but many, such as abel (advanced Boolean Expression Language), ahdl (alternate Language Description Language), traffic, pl (core unified Programming Language), HDCal, JHDL (Java Hardware Description Language), langue, Lola, HDL, laspam, hardsradware (Hardware Description Language), vhjhd (Hardware Description Language), and vhigh-Language, which are currently used in most common. It will also be apparent to those skilled in the art that hardware circuitry that implements the logical method flows can be readily obtained by merely slightly programming the method flows into an integrated circuit using the hardware description languages described above.
The controller may be implemented in any suitable manner, for example, the controller may take the form of, for example, a microprocessor or processor and a computer-readable medium storing computer-readable program code (e.g., software or firmware) executable by the (micro) processor, logic gates, switches, an Application Specific Integrated Circuit (ASIC), a programmable logic controller, and an embedded microcontroller, examples of which include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320, the memory controller may also be implemented as part of the control logic for the memory. Those skilled in the art will also appreciate that, in addition to implementing the controller as pure computer readable program code, the same functionality can be implemented by logically programming method steps such that the controller is in the form of logic gates, switches, application specific integrated circuits, programmable logic controllers, embedded microcontrollers and the like. Such a controller may thus be considered a hardware component, and the means included therein for performing the various functions may also be considered as a structure within the hardware component. Or even means for performing the functions may be regarded as being both a software module for performing the method and a structure within a hardware component.
The systems, devices, modules or units illustrated in the above embodiments may be implemented by a computer chip or an entity, or by a product with certain functions. One typical implementation device is a computer. In particular, the computer may be, for example, a personal computer, a laptop computer, a cellular telephone, a camera phone, a smartphone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
For convenience of description, the above devices are described as being divided into various units by function, and are described separately. Of course, the functionality of the units may be implemented in one or more software and/or hardware when implementing the present application.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In a typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include forms of volatile memory in a computer readable medium, Random Access Memory (RAM) and/or non-volatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of a computer-readable medium.
Computer-readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), Static Random Access Memory (SRAM), Dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), Read Only Memory (ROM), Electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), Digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium that can be used to store information that can be accessed by a computing device. As defined herein, a computer readable medium does not include a transitory computer readable medium such as a modulated data signal and a carrier wave.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other like elements in a process, method, article, or apparatus that comprises the element.
The application may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. The application may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
The above description is only an example of the present application and is not intended to limit the present application. Various modifications and changes may occur to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application should be included in the scope of the claims of the present application.