CN109901914B - Transaction processing method, device and equipment - Google Patents

Transaction processing method, device and equipment Download PDF

Info

Publication number
CN109901914B
CN109901914B CN201811624568.5A CN201811624568A CN109901914B CN 109901914 B CN109901914 B CN 109901914B CN 201811624568 A CN201811624568 A CN 201811624568A CN 109901914 B CN109901914 B CN 109901914B
Authority
CN
China
Prior art keywords
transaction
main
stage
record
rollback
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.)
Active
Application number
CN201811624568.5A
Other languages
Chinese (zh)
Other versions
CN109901914A (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.)
Advanced New Technologies Co Ltd
Advantageous New Technologies Co Ltd
Original Assignee
Advanced New Technologies 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 Advanced New Technologies Co Ltd filed Critical Advanced New Technologies Co Ltd
Priority to CN201811624568.5A priority Critical patent/CN109901914B/en
Publication of CN109901914A publication Critical patent/CN109901914A/en
Application granted granted Critical
Publication of CN109901914B publication Critical patent/CN109901914B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Landscapes

  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The embodiment of the specification discloses a transaction processing method, a transaction processing device and transaction processing equipment. The scheme comprises the following steps: acquiring an instruction sent by a server for indicating to perform one-stage transaction processing; the one-stage transaction is a transaction which needs to be processed in the first stage of a main transaction submitted by two stages; 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-stage transaction is a transaction which needs to be processed in the second stage by a main transaction which needs to be submitted in two stages; the one-phase transaction is processed.

Description

Transaction processing method, device and equipment
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a transaction processing method, apparatus, and device.
Background
A transaction, in computer terminology, refers to a program execution unit (unit) that accesses and possibly updates various data items in a database.
When a transaction needs to be split into multiple sub-transactions that 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 master transaction, as well as the processing of the branch transaction, may be referred to as a coordinator. The server responsible for the processing of the branch transaction may be referred to as a participant.
In the prior art, in order to ensure the consistency of data, a common flow is that a coordinator sends a branch transaction preparation instruction to each participant at one 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 two stages, a branch transaction commit instruction is sent to each participant. If the coordinator determines that all participants in one stage cannot be completely prepared, a rollback instruction is sent to each participant in two stages; and after receiving the rollback instruction, the participant executes rollback operation to release the corresponding resources.
However, in the prior art, due to network delay or other reasons, the participants themselves may not receive the instructions of the first stage and the second stage in the correct order, and the participants start to execute as soon as they receive the instructions of the coordinator, so that the execution order of the first stage and the second stage is disordered, and an erroneous transaction result is generated.
Disclosure of Invention
In view of this, the embodiments of the present application provide a transaction processing method, apparatus, and device, which are used to solve the problem that due to network delay or other reasons, a participant may not receive one-stage and two-stage instructions in a correct order, and the participant may start to execute as long as receiving the instruction of the coordinator, so that the execution order of the one-stage and the two-stage is disordered, and an erroneous transaction processing result is generated.
In order to solve the above technical problems, the embodiments of the present specification are implemented as follows:
the transaction processing method provided in the embodiment of the present specification includes:
acquiring an instruction sent by a server for indicating to perform one-stage transaction processing; the one-stage transaction is a transaction which needs to be processed in the first stage of a main transaction submitted by two stages; 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-stage transaction is a transaction which needs to be processed in the second stage by a main transaction which needs to be submitted in two stages;
the one-phase transaction is processed.
Another transaction processing method provided in an embodiment of the present disclosure includes:
acquiring a rollback instruction sent by a server and indicating to perform two-stage transaction processing; the two-stage transaction is a transaction which needs to be processed in the second stage by a main transaction which needs to be submitted in two stages; the rollback instruction comprises a main transaction identifier of the main transaction;
determining that a one-stage transaction of the master transaction has been executed; the one-stage transaction is a transaction which needs to be processed in the first stage of a main transaction submitted by two stages;
and executing rollback operation on the executed one-stage transaction.
The transaction processing device provided in the embodiment of the present specification includes:
the instruction acquisition module is used for acquiring an instruction which is sent by the server and indicates to perform one-stage transaction processing; the one-stage transaction is a transaction which needs to be processed in the first stage of a main transaction submitted by two stages; the instruction comprises a main transaction identifier of the main transaction;
a determining module, configured to determine that a two-stage transaction of the main transaction has not yet been executed; the two-stage transaction is a transaction which needs to be processed in the second stage by a main transaction which needs to be submitted in two stages;
and the one-stage transaction processing module is used for processing the one-stage transaction.
Another transaction processing apparatus provided in an embodiment of the present disclosure includes:
the rollback instruction acquisition module is used for acquiring rollback instructions which are sent by the server and indicate to perform two-stage transaction processing; the two-stage transaction is a transaction which needs to be processed in the second stage by a main transaction which needs to be submitted in two stages; the rollback instruction comprises a main transaction identifier of the main transaction;
a determining module, configured to determine that a one-stage transaction of the master transaction has been executed; the one-stage transaction is a transaction which needs to be processed in the first stage of a main transaction submitted by two stages;
And the rollback execution module is used for executing rollback operation on the executed one-stage transaction.
The embodiment of the present specification provides a transaction processing device, including:
at least one processor; the method comprises the steps of,
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to:
acquiring an instruction sent by a server for indicating to perform one-stage transaction processing; the one-stage transaction is a transaction which needs to be processed in the first stage of a main transaction submitted by two stages; 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-stage transaction is a transaction which needs to be processed in the second stage by a main transaction which needs to be submitted in two stages;
the one-phase transaction is processed.
Another transaction processing device provided in an embodiment of the present disclosure includes:
at least one processor; the method comprises the steps of,
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to:
Acquiring a rollback instruction sent by a server and indicating to perform two-stage transaction processing; the two-stage transaction is a transaction which needs to be processed in the second stage by a main transaction which needs to be submitted in two stages; the rollback instruction comprises a main transaction identifier of the main transaction;
determining that a one-stage transaction of the master transaction has been executed; the one-stage transaction is a transaction which needs to be processed in the first stage of a main transaction submitted by two stages;
and executing rollback operation on the executed one-stage transaction.
The above-mentioned at least one technical scheme that this description embodiment adopted can reach following beneficial effect:
after the scheme is adopted, after the participant obtains the instruction which is sent by the server and indicates the one-stage transaction processing, the participant can determine that the two-stage transaction is not executed, then process the one-stage transaction, correctly coordinate the processing processes of the one-stage transaction and the two-stage transaction, and even if the one-stage instruction and the two-stage instruction arrive out of order, the incorrect transaction processing result can not be generated.
Drawings
The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiments of the application and together with the description serve to explain the application and do not constitute an undue limitation to the application. In the drawings:
Fig. 1 is a schematic diagram of an application scenario of a transaction processing method according to an embodiment of the present disclosure;
FIG. 2 is a schematic flow chart of a transaction processing method according to an embodiment of the present disclosure;
FIG. 3 is a schematic flow chart of a first stage transaction according to an embodiment of the present disclosure;
FIG. 4 is a flow chart of a first stage transaction according to another embodiment of the present disclosure;
FIG. 5 is a flow chart of a transaction processing method according to another embodiment of the present disclosure;
FIG. 6 is a flow chart of a second stage transaction provided in an embodiment of the present disclosure;
FIG. 7 is a flow chart of a second stage transaction according to another embodiment of the present disclosure;
fig. 8 is a schematic structural diagram of a transaction processing device according to an embodiment of the present disclosure;
FIG. 9 is a schematic diagram of a transaction processing device according to another embodiment of the present disclosure;
fig. 10 is a block diagram of a transaction processing system according to an embodiment of the present disclosure.
Detailed Description
For the purposes, technical solutions and advantages of the present application, the technical solutions of the present application will be clearly and completely described below with reference to specific embodiments of the present application and corresponding drawings. It will be apparent that the described embodiments are only some, but not all, of the embodiments of the present application. All other embodiments, which can be made by one of ordinary skill in the art without undue burden from the present disclosure, are within the scope of the present disclosure.
The following describes in detail the technical solutions provided by the embodiments of the present application with reference to the accompanying drawings.
Fig. 1 is a schematic diagram of an application scenario of a transaction processing method according to an embodiment of the present disclosure. As shown in fig. 1, the present transaction processing method may 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 the participants are connected through a network. There may be multiple participants. When a transaction needs to be split into multiple sub-transactions that 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 master transaction, as well as the processing of the branch transaction, may be referred to as a coordinator. The server responsible for the processing of the branch transaction may be referred to as a participant.
In a distributed system, in order to ensure data consistency, a common flow is that, in a first stage, a coordinator sends a branch transaction preparation instruction to each participant, and after each participant receives the instruction, the coordinator performs a corresponding branch transaction preparation operation. After the coordinator determines that all participants are ready, in the second stage, a branch transaction commit instruction is sent to each participant. Retry if the transaction commit fails until all commit is successful. If the coordinator determines that all participants in the first stage cannot be completely prepared, a rollback instruction is sent to each participant in the second stage; and after receiving the rollback instruction, the participant executes rollback operation to release the corresponding resources. Retry if rollback fails until all rollbacks are successful. The above-described manner of processing distributed transactions in two phases is also referred to as two-phase commit of the distributed transaction. Unless otherwise specified, in the embodiment of the present disclosure, a transaction that a participant needs to process in the first stage is referred to as a one-stage transaction, and a transaction that a participant needs to process in the second stage is referred to as a two-stage transaction.
However, the inventors have studied and found that the one-phase instruction and the two-phase instruction sent by the coordinator to the participants may arrive out of order at the participants due to network delay or network jitter, etc. If the participant receives a two-stage instruction before a stage has been completed, the two-stage transaction will begin to be processed before a stage transaction has been completed. This will result in the failure to receive subsequent two-phase instructions after the one-phase transaction is completed, resulting in the one-phase transaction being in a suspended state.
Specifically, for example: user a transfers 100 elements through the account of X bank to the account of user B of Y bank. The server corresponding to the account of the X bank may be considered as participant a and the server corresponding to the account of the Y bank may be considered as participant B. Normally, the server acting as coordinator sends two different one-phase instructions to participant a and participant B, respectively. A phase instruction 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 of status as unavailable to user B's account. After receiving the one-stage instruction, participant a freezes 100 elements in the account of user a according to the one-stage instruction, and after receiving the one-stage instruction, participant B performs an operation of adding 100 elements to the account of user B according to the instruction, and the added 100 elements are in an unavailable state. When each of the participant a and the participant B completes the operation to be executed, a message of one-stage transaction preparation is sent to the coordinator. After receiving the message, the coordinator sends a two-stage instruction to the participant A and the participant B. A two-phase instruction sent to participant a instructing participant a to delete the frozen 100 elements from user a's account. A two-phase instruction sent to participant B instructing participant B to change 100-element from the unavailable state in user B's account to the available state. After receiving the respective corresponding two-stage instructions, the participant A and the participant B execute corresponding operations, and finally complete the operation of transferring 100 yuan from the user A to the user B.
If for some reason either participant a or participant B does not send a message to the coordinator that the one-phase transaction is ready within a preset time, the coordinator will send a two-phase instruction to participant a and participant B, respectively, indicating that participant a and participant B are rolling back. Normally, participant a will defrost the 100-element frozen a account according to the two-phase instruction. Participant B may delete 100 elements of the previously added state as unavailable according to the two-phase instruction. However, due to network delay or network jitter, the two-phase instruction may arrive before the one-phase transaction is completed. Taking participant a as an example, in the event that participant a has not completed freezing 100 elements, a rollback operation (which may be a null rollback here) corresponding to the two-phase instruction has already been performed. After executing the two-stage instruction, if the participant a continues to execute the one-stage instruction, 100 elements are frozen, and the frozen 100 elements are always in a frozen state because the two stages are not executed any more, so that the amount of 100 elements in the account of the user a cannot be used. This case, also called one-phase transaction, is suspended.
Fig. 2 is a flow chart of a transaction processing method according to an embodiment of the present disclosure. From a program perspective, the execution subject of the flow may be a program deployed on a server that is a participant in a distributed system.
As shown in fig. 2, the process may include the steps of:
s201, acquiring an instruction sent by a server for indicating to perform one-stage transaction processing; the one-stage transaction is a transaction which needs to be processed in the first stage of a main transaction submitted by two stages; the instruction comprises a main transaction identifier of the main transaction.
In a transaction requiring a two-phase commit, a master transaction may include two phases, a first phase, a preparation phase, and a second phase, either a commit phase or a rollback phase. In the present embodiment, the second stage is directed to rolling back mainly after the first stage is ready to be completed.
In the present embodiment, the master transaction identifier is unique throughout the master transaction to identify the master transaction, and the master transaction identifier may be represented in different forms, e.g., each master transaction identifier may be represented in a different arabic, uppercase or lowercase letter.
S202, determining that two-stage transactions of the main transaction are not executed yet; the two-stage transaction is a transaction which needs to be processed in the second stage by a main transaction which needs to be submitted in two stages.
In the embodiment of the present disclosure, after the one-stage preparation is completed, in order to avoid the confusion of the execution order of the one-stage transaction and the two-stage transaction due to network delay or other reasons such as network jitter, it is required to determine that the two-stage transaction of the main transaction has not yet been executed.
S203, processing the one-stage transaction.
In this embodiment, in the case where it is determined that the two-stage transaction of the master transaction has not yet been executed, the participant may perform the processing of the one-stage transaction according to the instruction sent by the coordinator.
Because in the prior art, when the participant performs the transaction submitted by two phases, the participant does not know whether the transaction of the second phase has been performed or not when the participant performs the transaction of the first phase; the participant itself does not know whether the first stage transaction has been executed while executing the second stage transaction. Thus, the following may occur: the participants adopt different threads to process the transactions of two stages simultaneously, or the participants process the transactions of the second stage first and then process the transactions of the first stage, so that the transactions of the first stage are suspended after the transactions of the first stage are processed.
Optionally, the determining that the two-stage transaction of the main transaction has not been executed may specifically include:
and inquiring a 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 is queried.
Optionally, the method may further include:
and inserting the main transaction record containing the main transaction identifier when the first query result indicates that the main transaction record containing the main transaction identifier cannot be queried.
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 processing the one-stage transaction when the second query result indicates that no rollback record containing the primary transaction identification is queried.
Optionally, after the querying whether the rollback record containing the primary transaction identifier exists, the method may further include:
and ending the process of processing the one-stage transaction when the second query result indicates that the rollback record containing the main transaction identifier exists.
Optionally, after the querying the master transaction record including the master transaction identifier, the method may further include:
And when the first query result indicates that the primary transaction record containing the primary transaction identifier cannot be queried, querying a rollback record containing the primary transaction identifier, and obtaining a third query result.
And when the third query result indicates that the rollback record containing the main transaction identifier is not queried, executing locking operation on the storage area containing the rollback record of the main transaction identifier.
And inserting a master transaction record containing the master transaction identifier.
Optionally, after the querying the rollback record including the primary transaction identifier, the method may further include:
and ending the process of processing the one-stage transaction when the third query result indicates that the rollback record containing the main transaction identifier is queried.
In the embodiment of the present disclosure, by determining that the two-stage transaction of the main transaction has not yet been executed, it may be ensured that after the execution of the one-stage transaction is completed, the corresponding two-stage transaction may be executed, so as to avoid a suspension phenomenon after the execution of the one-stage transaction is completed.
After the scheme is adopted, after the participant obtains the instruction which is sent by the server and indicates the one-stage transaction processing, the participant can determine that the two-stage transaction is not executed, then process the one-stage transaction, correctly coordinate the processing processes of the one-stage transaction and the two-stage transaction, and even if the one-stage instruction and the two-stage instruction arrive out of order, the incorrect transaction processing result can not be generated.
Fig. 3 is a schematic flow chart of a first-stage transaction according to an embodiment of the present disclosure. From a program perspective, the execution subject of the flow may be a program deployed on a server that is a participant in a distributed system.
As shown in fig. 3, after receiving an instruction sent by the coordinator to instruct to perform a one-stage transaction, the participant may perform the following steps:
s301, inquiring a master transaction record containing the master transaction identifier to obtain a first inquiry result. When the first query result indicates that the primary transaction record containing the primary transaction identifier is queried, executing step S302; when the first query result indicates that the primary transaction record containing the primary transaction identifier is not queried, step S303 is performed.
S302, locking the master transaction record when the first query result indicates that the master transaction record is queried.
In the corresponding embodiment of FIG. 3, the database has an isolation level of R-C (Read committed), and is handled by an exclusive lock approach. The first inquiry result is obtained when the first inquiry result indicates that the main transaction record is inquired, the main transaction record is not locked by the two-stage transaction, namely, the two-stage transaction is not started to be executed yet, the main transaction record is locked by the one-stage transaction, and in the execution process of the one-stage transaction, if the two-stage transaction receives an execution instruction in advance and wants to start to be executed, the main transaction record is inquired and locked first, at this time, the main transaction record is already locked by the one-stage transaction, and the two-stage transaction can be started to be executed only after the execution of the one-stage transaction is completed and the main transaction record is released.
S303, inserting the main transaction record containing the main transaction identifier when the first query result indicates that the main transaction record containing the main transaction identifier is not queried.
In the embodiment of the present disclosure, when the master transaction record including the master transaction identifier is not queried, the master transaction record including the master transaction identifier may be inserted first, which represents that the first-stage transaction has not yet been executed.
S306, inquiring whether a rollback record containing the main transaction identifier exists or not, and obtaining a second inquiry result. When the second query result indicates that the rollback record containing the main transaction identifier is queried, executing step S307; when the first query result indicates that the rollback record containing the primary transaction identifier is not queried, step S304 is performed.
In the embodiment of the present disclosure, after the master transaction record is not queried and the master transaction record containing the master transaction identifier is inserted, it is required to query whether there is a rollback record containing the master transaction identifier.
S307, when the second query result indicates that the rollback record containing the main transaction identifier exists, ending the process of processing the one-stage transaction.
In the embodiment of the present disclosure, after the existence of the rollback record including the main transaction identifier is queried, it indicates that the second transaction stage has performed a rollback operation, that is, the second transaction stage performs an empty rollback if the first transaction stage is not ready, and cannot commit the first transaction stage any more, and it needs to abnormally end the process of processing the one-stage transaction.
S304, when the second query result indicates that the rollback record containing the main transaction identifier is not queried, the one-stage transaction is processed.
In this embodiment of the present disclosure, the second query result indicates that the second transaction stage has not been executed when the rollback record including the main transaction identifier is not queried. The branch transaction can be processed, and the branch transaction record is inserted after the branch transaction is processed. 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 turn until all branch transactions are completed.
S305, normally ending the process of processing the one-stage transaction.
After the scheme is adopted, the serial execution of the one-stage transaction and the two-stage transaction is ensured by utilizing the competition among the exclusive locks of the database, the normal execution of the one-stage transaction under the condition that the two-stage transaction is not executed is ensured, and the problem of one-stage transaction suspension is avoided.
Fig. 4 is a schematic flow chart of a first-stage transaction according to another embodiment of the present disclosure. From a program perspective, the execution subject of the flow may be a program deployed on a server that is a participant in a distributed system.
As shown in fig. 4, the process may include the steps of:
s401, inquiring a master transaction record containing the master transaction identifier to obtain a first inquiry result.
S402, locking the master transaction record when the first query result indicates that the master transaction record is queried.
After the master transaction record is locked, step S404 may be performed.
In the corresponding embodiment of FIG. 4, the isolation level of the database is R-R (Repeatable Read).
The first-stage transaction inquiry comprises a main transaction record of a main transaction identifier, and a first inquiry result is obtained. 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-stage transaction, i.e. the two-stage transaction has not yet started executing. After the primary transaction record is locked by the one-stage transaction, if the participant receives the processing instruction of the second-stage transaction sent by the coordinator in advance in the execution process of the one-stage transaction, the rollback record containing the primary transaction identifier can be queried in the record table of the rollback record. If the rollback record containing the main transaction identifier is not queried, inserting the rollback record of the main transaction identifier. And then, inquiring the master transaction record, and if the master transaction record is inquired at the moment, executing the operation of locking the master transaction record. If the main transaction record is locked in the process of executing the first-stage transaction at this time, the participant can lock the main transaction record only after the main transaction record is released after the completion of the execution of the first-stage transaction in the process of executing the second-stage transaction, so that the two-stage transaction cannot be executed in the process of executing the first-stage transaction.
S403, when the first query result indicates that the primary transaction record containing the primary transaction identifier cannot be queried, querying a rollback record containing the primary transaction identifier, and obtaining a third query result. When the third query result indicates that the rollback record containing the main transaction identifier is queried, executing step S408; when the third query result indicates that the rollback record containing the primary transaction identifier is not queried, step S406 is performed.
S406, when the third query result indicates that the rollback record containing the main transaction identifier is not queried, locking the storage area of the rollback record containing the main transaction identifier.
In the embodiment of the present description, when the rollback record containing the main transaction identifier is not queried, representing that the two-stage transaction has not been executed, the storage area of the rollback record containing the main transaction identifier may be locked. The two-stage transaction cannot operate on the storage area of the rollback record during the period, so that the two-stage transaction cannot be executed in the execution process of the one-stage transaction.
S407, inserting a master transaction record containing the master transaction identifier.
S404, processing the one-stage transaction.
S405, normally ending the process of processing the one-stage transaction.
In the embodiment of the present specification, after the insertion of the main transaction record containing the main transaction identifier or after the inquiry of the main transaction record and locking of the main transaction record, the processing of the branch transaction may be started. And after the branch transaction processing is completed, the branch transaction record is inserted. In addition, there may be multiple branch transactions, and after one branch transaction is processed and recorded, the next branch transaction is executed in turn and recorded until all branch transactions are completed.
S408, when the third query result indicates that the rollback record containing the main transaction identifier is queried, ending the process of processing the one-stage transaction.
In the embodiment of the present disclosure, when the rollback record including the main transaction identifier is queried, it represents that the rollback has been completed for the second-stage transaction, 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 abnormally ended.
After the scheme is adopted, the locking method of the database is utilized for processing, so that the serial execution of the one-stage transaction and the two-stage transaction is ensured, the normal execution of the one-stage transaction under the condition that the two-stage transaction is not executed is ensured, and the problem of one-stage transaction suspension is avoided.
Fig. 5 is a flowchart of a transaction processing method according to another embodiment of the present disclosure. From a program perspective, the execution subject of the flow may be a program deployed on a server that is a participant in a distributed system.
As shown in fig. 5, the process may include the steps of:
s501, acquiring a rollback instruction sent by a server and indicating to perform two-stage transaction processing; the two-stage transaction is a transaction which needs to be processed in the second stage by a main transaction which needs to be submitted in two stages; the rollback instruction comprises a main transaction identifier of the main transaction.
In the embodiment of the present specification, the transaction that needs to be processed in the second stage is rollback.
S502, determining that one-stage 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 which needs to be submitted in two phases.
In the embodiment of the present disclosure, in order to avoid the confusion of the execution order of the first-stage transaction and the second-stage transaction due to network delay or other reasons such as network jitter, when the second-stage transaction of the main transaction is executed, it is required to determine that the first-stage transaction has been executed.
S503, executing rollback operation on the executed one-stage transaction.
In this embodiment of the present disclosure, in the case where it is determined that the one-phase transaction of the master transaction has been executed, the participant may perform rollback of the one-phase transaction according to the instruction sent by the coordinator.
Optionally, the determining that the one-stage transaction of the master transaction has been executed may specifically include:
and inquiring a master transaction record containing the master transaction identifier to obtain a first inquiry result.
And locking the main transaction record when the first query result indicates that the main transaction record containing the main transaction identifier is queried.
Optionally, after the rollback operation is performed on the executed one-stage transaction, the method may further include:
a rollback record containing the primary transaction identification is inserted.
Optionally, after the querying the master transaction record including the master transaction identifier, the method may further include:
and inserting the main transaction record containing the main transaction identifier when the first query result indicates that the main transaction record containing the main transaction identifier cannot be queried.
And deleting the master transaction record.
And inquiring the rollback record containing the main transaction identifier to obtain a second inquiry result.
And inserting the rollback record containing the main transaction identifier when the second query result indicates that the rollback record containing the main transaction identifier is not queried.
Optionally, after the querying the rollback record including the primary transaction identifier, the method may further include:
and 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, before the querying the master transaction record including 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 inserting the rollback record containing the main transaction identifier when the third query result indicates that the rollback record containing the main transaction identifier is not queried.
Optionally, after the querying the rollback record including the primary transaction identifier, the method may further include:
and ending the process of processing the two-stage transaction when the third query result indicates that the rollback record containing the main transaction identifier is queried.
Optionally, after the inserting the rollback record including the primary transaction identifier, the method may further include:
and ending the process of processing the two-stage transaction when the first query result indicates that the primary transaction record containing the primary transaction identifier is not queried.
After the scheme is adopted, after the participant obtains the instruction which is sent by the server and indicates the one-stage transaction processing, the participant can determine that the two-stage transaction is not executed, then process the one-stage transaction, correctly coordinate the processing processes of the one-stage transaction and the two-stage transaction, and even if the one-stage instruction and the two-stage instruction arrive out of order, the incorrect transaction processing result can not be generated.
Fig. 6 is a schematic flow chart of a second-stage transaction according to an embodiment of the present disclosure. From a program perspective, the execution subject of the flow may be a program deployed on a server that is a participant in a distributed system.
As shown in fig. 6, after receiving the instruction sent by the coordinator to instruct two-stage transaction, the participant may perform the following steps:
s601, inquiring a master transaction record containing the master transaction identifier to obtain a first inquiry result. When the first query result indicates that a master transaction record containing the master transaction identifier is queried, executing step S602; when the first query result indicates that the primary transaction record containing the primary transaction identifier is not queried, step S603 is performed.
S602, locking the main transaction record when the first query result indicates that the main transaction record containing the main transaction identifier is queried.
S604, inquiring the branch transaction record and rolling back the branch transaction.
S605, inserting a rollback record containing the main transaction identifier.
In the embodiment of the present disclosure, when a master transaction record including a master transaction identifier is queried, the master transaction record is locked first, so as to prevent a one-stage transaction from locking the master transaction record during a two-stage transaction. And then inquiring the branch transaction record, rolling back the branch transaction after inquiring the branch transaction record, and inserting the rollback record containing the main transaction identification. In addition, there may be multiple branch transactions, and after rolling back one branch transaction and recording, rolling back the next branch transaction and recording in turn until all branch transactions are completed.
And S603, inserting a main transaction record containing the main transaction identifier when the first query result indicates that the main transaction record containing the main transaction identifier is not queried.
S607, deleting the master transaction record.
And S608, inquiring the rollback record containing the main transaction identifier to obtain a second inquiry result. When the second query result indicates that the rollback record containing the primary transaction identifier is not queried, executing step S605; when the second query result indicates that a rollback record containing the primary transaction identity is queried, step S606 is performed.
S605, inserting the rollback record containing the main transaction identifier when the second query result indicates that the rollback record containing the main transaction identifier is not queried.
In this embodiment of the present disclosure, when a master transaction record identified by a master transaction is not queried, it represents that a one-phase transaction has not yet been executed, and a rollback instruction may indicate that a two-phase transaction has arrived at a participant prior to or during the time that the one-phase transaction has not yet been executed. To avoid one-stage transaction suspension, a master transaction record containing a master transaction identifier may be inserted first, occupying a certain memory space, and then deleted. In this embodiment, a database of R-C isolation levels is employed. In the database with the R-C isolation level, since the gap lock cannot be used, in order to occupy the storage space of the master transaction record, if a one-stage transaction is executed during the execution process, the step of inserting the master transaction record is executed, and therefore the storage space corresponding to the master transaction record is occupied and cannot be inserted. After the two-stage transaction is completed, the one-stage transaction can be continuously executed. When the one-stage transaction continues to be executed, the participant can inquire the rollback record generated by the two-stage transaction which has already been executed, and then the one-stage transaction can be abnormally ended, so that the problem of suspension of the one-stage transaction is avoided.
S606, when the second query result indicates that the rollback record containing the main transaction identifier is queried, ending the process of processing the two-stage transaction.
In the embodiment of the specification, when the rollback record containing the main transaction identifier is queried, the rollback record can be queried when the second-stage transaction is executed, and the second-stage transaction can be normally ended.
Fig. 7 is a schematic flow chart of a second-stage transaction according to another embodiment of the present disclosure. From a program perspective, the execution subject of the flow may be a program deployed on a server that is a participant in a distributed system.
As shown in fig. 7, after receiving the instruction sent by the coordinator to instruct two-stage transaction, the participant may perform the following steps:
s701, inquiring a rollback record containing the main transaction identifier to obtain a third inquiry result. When the third query result indicates that the rollback record containing the main transaction identifier is not queried, executing step S702; when the third query result indicates that the rollback record containing the primary transaction identifier is queried, executing step S704;
s702, when the third query result indicates that the rollback record containing the main transaction identifier is not 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 disclosure, during the second stage transaction, the participant may first query whether the rollback record includes the main transaction identifier, and when the rollback record including the main transaction identifier is not queried, it represents that the second stage transaction has not performed the rollback operation, and may first lock the storage area of the rollback record including the main transaction identifier, and then insert the rollback record including the main transaction identifier. It is ensured that a one-phase transaction cannot be executed during execution of a two-phase transaction. After the participant waits until the two-stage transaction is executed, the rollback record can be queried in the one-stage transaction, and then the one-stage transaction is abnormally ended, so that the condition that the one-stage transaction is suspended is avoided.
And S704, ending the process of processing the two-stage transaction when the third query result indicates that the rollback record containing the main transaction identifier is queried.
In the embodiment of the present disclosure, when the rollback record including the main transaction identifier is queried, it represents that the two-stage transaction has completed rollback, and the process of processing the two-stage transaction may be normally ended.
The inserting the rollback record containing the primary transaction identifier may further include:
s705, inquiring a master transaction record containing the master transaction identifier to obtain a first inquiring result. When the first query result indicates that a master transaction record containing the master transaction identifier is queried, executing step S706; when the first query result indicates that the primary transaction record containing the primary transaction identifier is not queried, step S704 is performed.
And S704, ending the process of processing the two-stage transaction when the first query result indicates that the primary transaction record containing the primary transaction identifier is not queried.
In the embodiment of the present disclosure, the master transaction record containing the master transaction identifier is not queried, which represents that the one-stage transaction is not yet executed, and the process of processing the two-stage transaction can be normally ended.
S706, locking the master transaction record when the first query result indicates that the master transaction record containing the master transaction identifier is queried.
S707, querying the branch transaction record and rolling back the branch transaction.
In the embodiment of the present disclosure, when the master transaction record including the master transaction identifier is queried, the master transaction record can be locked, which represents that the one-stage transaction has been executed. The branch transaction record may be queried and rolled back and then recorded. In addition, there may be multiple branch transactions, and after rolling back one branch transaction and recording, rolling back the next branch transaction and recording in turn until all branch transactions are completed.
Based on the same thought, the embodiment of the specification also provides a device corresponding to the 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 sent by a server to instruct to perform a one-stage transaction; the one-stage transaction is a transaction which needs to be processed in the first stage of a main transaction submitted by two stages; the instruction comprises a main transaction identifier of the main transaction.
A determining module 802, configured to determine that a two-stage transaction of the main transaction has not yet been executed; the two-stage transaction is a transaction which needs to be processed in the second stage by a main transaction which needs to be submitted in two stages.
A one-phase transaction processing module 803 for processing the one-phase transaction.
Optionally, the determining module may specifically include:
the first result determining unit is used for querying a main transaction record containing the main transaction identifier to obtain a first query result;
and the main transaction record locking unit is used for locking the main transaction record when the first query result indicates that the main transaction record is queried.
Optionally, the determining module may further include:
And the first main transaction record inserting unit is used for inserting the main transaction record containing the main transaction identifier when the first query result indicates that the main transaction record containing the main 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-stage transaction module may specifically include:
and the one-stage transaction processing unit is used for processing the one-stage transaction when the second query result indicates that the rollback record containing the main transaction identifier is not queried.
Optionally, the apparatus may further include:
and the first ending unit is used for ending the process of processing the one-stage transaction when the second query result indicates that the rollback record containing the main transaction identifier exists.
Optionally, the apparatus may further include:
and the third result determining unit is used for querying the rollback record containing the main transaction identifier to obtain a third query result when the first query result indicates that the main transaction record containing the main transaction identifier cannot be queried.
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 indicates that the rollback record containing the main transaction identifier is not queried.
And the second main transaction record insertion unit is used for inserting the main transaction record containing the main transaction identifier.
Optionally, the apparatus may further include:
and the second ending unit is used for ending the process of processing the one-stage transaction when the third query result indicates that the rollback record containing the main transaction identifier is queried.
Based on the same thought, the embodiment of the specification also provides a device corresponding to the method. Fig. 9 is a schematic structural diagram of a transaction processing device corresponding to fig. 5 according to an embodiment of the present disclosure. As shown in fig. 9, the apparatus may include:
the rollback instruction acquisition module 901 is configured to acquire a rollback instruction sent by a server and indicating to perform two-stage transaction processing; the two-stage transaction is a transaction which needs to be processed in the second stage by a main transaction which needs 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 one-stage 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 which needs to be submitted in two phases.
The rollback execution module 903 is configured to execute a rollback operation on the executed one-phase transaction.
Optionally, the determining module may specifically include:
and the first result determining unit is used for querying the master transaction record containing the master transaction identifier to obtain a first query result.
And the main transaction record locking unit is used for locking the main transaction record when the first query result indicates that the main transaction record containing the main transaction identifier is queried.
Optionally, the apparatus may further include:
and the first inserting module is used for executing the rollback record operation which is inserted to contain the main transaction identifier after the rollback operation executing module executes the rollback operation on the executed one-stage transaction.
Optionally, the determining module may further include:
and the main transaction record inserting unit is used for inserting the main transaction record containing the main transaction identifier when the first query result indicates that the main transaction record containing the main transaction identifier cannot be queried.
And the main transaction record deleting unit is used for deleting the main transaction record.
And the second result determining unit is used for querying the rollback record containing the main transaction identifier to obtain a second query result.
And the second inserting unit is used for inserting the rollback record containing the main transaction identifier when the second query result indicates that the rollback record containing the main transaction identifier is not queried.
Optionally, the apparatus may further include:
and the first ending 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 rollback record comprising the main transaction identifier before the first query result determining unit queries the main transaction record comprising the main transaction identifier, so as to obtain a third query result operation.
And the third inserting unit is used for inserting the rollback record containing the main transaction identifier when the third query result indicates that the rollback record containing the main transaction identifier is not 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 indicates 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-stage transaction when the first query result indicates that the primary transaction record containing the primary transaction identifier is not queried.
Based on the same thought, the embodiment of the specification also provides equipment corresponding to the 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; the method comprises the steps of,
a memory 1030 communicatively coupled to the at least one processor; wherein,
the memory 1030 stores instructions 1020 executable by the at least one processor 1010 for execution 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 sent by a server for indicating to perform one-stage transaction processing; the one-stage transaction is a transaction which needs to be processed in the first stage of a main transaction submitted by two stages; 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-stage transaction is a transaction which needs to be processed in the second stage by a main transaction which needs to be submitted in two stages.
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 sent by a server and indicating to perform two-stage transaction processing; the two-stage transaction is a transaction which needs to be processed in the second stage by a main transaction which needs to be submitted in two stages; the rollback instruction comprises a main transaction identifier of the main transaction.
Determining that a one-stage 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 which needs to be submitted in two phases.
And executing rollback operation on the executed one-stage transaction.
In the 90 s of the 20 th century, improvements to one technology could clearly be distinguished as improvements in hardware (e.g., improvements to circuit structures such as diodes, transistors, switches, etc.) or software (improvements to the process flow). However, with the development of technology, many improvements of the current method flows can be regarded as direct improvements of hardware circuit structures. Designers almost always obtain corresponding hardware circuit structures by programming improved method flows into hardware circuits. Therefore, an improvement of a method flow cannot be said to be realized by a hardware entity module. For example, a programmable logic device (Programmable Logic Device, PLD) (e.g., field programmable gate array (Field Programmable Gate Array, FPGA)) is an integrated circuit whose logic function is determined by the programming of the device by a user. A designer programs to "integrate" a digital system onto a PLD without requiring the chip manufacturer to design and fabricate application-specific integrated circuit chips. Moreover, nowadays, instead of manually manufacturing integrated circuit chips, such programming is mostly implemented by using "logic compiler" software, which is similar to the software compiler used in program development and writing, and the original code before the compiling is also written in a specific programming language, which is called hardware description language (Hardware Description Language, HDL), but not just one of the hdds, but a plurality of kinds, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), lava, lola, myHDL, PALASM, RHDL (Ruby Hardware Description Language), etc., VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog are currently most commonly used. It will also be apparent to those skilled in the art that a hardware circuit implementing the logic method flow can be readily obtained by merely slightly programming the method flow into an integrated circuit using several of 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, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable logic controllers, and embedded microcontrollers, 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 of the memory. Those skilled in the art will also appreciate that, in addition to implementing the controller in a pure computer readable program code, it is well possible to implement the same functionality by logically programming the method steps such that the controller is in the form of logic gates, switches, application specific integrated circuits, programmable logic controllers, embedded microcontrollers, etc. Such a controller may thus be regarded as a kind of hardware component, and means for performing various functions included therein may also be regarded as structures within the hardware component. Or even means for achieving the various functions may be regarded as either software modules implementing the methods or structures within hardware components.
The system, apparatus, module or unit set forth in the above embodiments may be implemented in particular by a computer chip or entity, or by a product having a certain function. One typical implementation is a computer. In particular, the computer may be, for example, a personal computer, a laptop computer, a cellular telephone, a camera phone, a smart phone, 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 functionally divided into various units, respectively. Of course, the functions of each element may be implemented in one or more software and/or hardware elements when implemented in the present application.
It will be appreciated by those skilled in the art that 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 flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations 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 one typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include volatile memory in a computer-readable medium, random Access Memory (RAM) and/or nonvolatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of computer-readable media.
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 storage media for a computer 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, which can be used to store information that can be accessed by a computing device. Computer-readable media, as defined herein, does not include transitory computer-readable media (transmission media), such as modulated data signals and carrier waves.
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 one … …" 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.
In this specification, each embodiment is described in a progressive manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for system embodiments, since they are substantially similar to method embodiments, the description is relatively simple, as relevant to see a section of the description of method embodiments.
The foregoing is merely exemplary of the present application and is not intended to limit the present application. Various modifications and changes may be made to the present application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc. which are within the spirit and principles of the present application are intended to be included within the scope of the claims of the present application.

Claims (26)

1. A transaction processing method, comprising:
acquiring an instruction sent by a server for indicating to perform one-stage transaction processing; the one-stage transaction is a transaction which needs to be processed in the first stage of a main transaction submitted by two stages; the instruction comprises a main transaction identifier of the main transaction;
determining that the two-stage transaction of the main transaction is not executed, specifically comprising:
inquiring a main transaction record containing the main transaction identifier to obtain a first inquiry result;
When the first query result indicates that the master transaction record is queried, locking the master transaction record; the two-stage transaction is a transaction which needs to be processed in the second stage by a main transaction which needs to be submitted in two stages;
when the first query result indicates that the main transaction record cannot be queried, inserting the main transaction record containing the main transaction identifier, wherein the one-stage transaction occupies a storage space, so that the one-stage transaction cannot be inserted because the storage space corresponding to the main transaction record is occupied when the one-stage transaction is executed in the execution process of the two-stage transaction;
deleting the master transaction record;
the one-phase transaction is processed.
2. The method of claim 1, wherein after querying a master transaction record containing the master transaction identification, further comprising:
inserting a main transaction record containing the main transaction identifier when the first query result indicates that the main transaction record containing the main transaction identifier cannot be queried;
inquiring whether a rollback record containing the main transaction identifier exists or not to obtain a second inquiry result;
the processing the one-stage transaction specifically includes:
and processing the one-stage transaction when the second query result indicates that no rollback record containing the primary transaction identification is queried.
3. The method of claim 2, wherein after the querying whether there is a rollback record containing the primary transaction identification, further comprising:
and ending the process of processing the one-stage transaction when the second query result indicates that the rollback record containing the main transaction identifier exists.
4. The method of claim 1, wherein after querying a master transaction record containing the master transaction identification, further comprising:
when the first query result indicates that the primary transaction record containing the primary transaction identifier cannot be queried, querying a rollback record containing the primary transaction identifier to obtain a third query result;
when the third query result indicates that the rollback record containing the main transaction identifier is not queried, executing locking operation on a storage area of the rollback record containing the main transaction identifier;
and inserting a master transaction record containing the master transaction identifier.
5. The method of claim 4, wherein after querying the rollback record containing the primary transaction identification, further comprising:
and ending the process of processing the one-stage transaction when the third query result indicates that the rollback record containing the main transaction identifier is queried.
6. A transaction processing method, comprising:
acquiring a rollback instruction sent by a server and indicating to perform two-stage transaction processing; the two-stage transaction is a transaction which needs to be processed in the second stage by a main transaction which needs to be submitted in two stages; the rollback instruction comprises a main transaction identifier of the main transaction;
determining that the one-stage transaction of the main transaction is executed, specifically includes:
inquiring a main transaction record containing the main transaction identifier to obtain a first inquiry result;
when the first query result indicates that the main transaction record containing the main transaction identifier is queried, locking the main transaction record; the one-stage transaction is a transaction which needs to be processed in the first stage of a main transaction submitted by two stages;
when the first query result indicates that the main transaction record cannot be queried, inserting the main transaction record containing the main transaction identifier, wherein the one-stage transaction occupies a storage space, so that the one-stage transaction cannot be inserted because the storage space corresponding to the main transaction record is occupied when the one-stage transaction is executed in the execution process of the two-stage transaction; deleting the master transaction record;
and executing rollback operation on the executed one-stage transaction.
7. The method of claim 6, wherein after performing a rollback operation on the executed one-phase transaction, further comprising:
a rollback record containing the primary transaction identification is inserted.
8. The method of claim 6, wherein after querying the master transaction record containing the master transaction identification, further comprising:
inserting a main transaction record containing the main transaction identifier when the first query result indicates that the main transaction record containing the main transaction identifier cannot be queried;
deleting the master transaction record;
inquiring a rollback record containing the main transaction identifier to obtain a second inquiry result;
and inserting the rollback record containing the main transaction identifier when the second query result indicates that the rollback record containing the main transaction identifier is not queried.
9. The method of claim 8, wherein after querying the rollback record containing the primary transaction identification, further comprising:
and 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.
10. The method of claim 6, wherein prior to querying a master transaction record containing the master transaction identification, further comprising:
Inquiring a rollback record containing the main transaction identifier to obtain a third inquiry result;
and inserting the rollback record containing the main transaction identifier when the third query result indicates that the rollback record containing the main transaction identifier is not queried.
11. The method of claim 10, wherein after querying the rollback record containing the primary transaction identification, further comprising:
and ending the process of processing the two-stage transaction when the third query result indicates that the rollback record containing the main transaction identifier is queried.
12. The method of claim 11, wherein the inserting the rollback record containing the primary transaction identification is followed by:
and ending the process of processing the two-stage transaction when the first query result indicates that the primary transaction record containing the primary transaction identifier is not queried.
13. A transaction processing apparatus, comprising:
the instruction acquisition module is used for acquiring an instruction which is sent by the server and indicates to perform one-stage transaction processing; the one-stage transaction is a transaction which needs to be processed in the first stage of a main transaction submitted by two stages; the instruction comprises a main transaction identifier of the main transaction;
A determining module, configured to determine that a two-stage transaction of the main transaction has not yet been executed; the two-stage transaction is a transaction which needs to be processed in the second stage by a main transaction which needs to be submitted in two stages; the determining module specifically includes: the first result determining unit is used for querying a main transaction record containing the main transaction identifier to obtain a first query result; a main transaction record locking unit, configured to lock the main transaction record when the first query result indicates that the main transaction record is queried; the second determining unit is configured to insert a master transaction record containing the master transaction identifier when the first query result indicates that the master transaction record is not queried, where the one-stage transaction occupies a storage space, so that when the one-stage transaction is executed in the execution process of the two-stage transaction, the storage space corresponding to the master transaction record is occupied and cannot be inserted; a deleting unit, configured to delete the master transaction record;
and the one-stage transaction processing module is used for processing the one-stage transaction.
14. The apparatus of claim 13, the determination module further comprising:
a first main transaction record insertion unit, configured to insert a main transaction record including the main transaction identifier when the first query result indicates that the main transaction record including the main transaction identifier is not queried;
The second result determining unit is used for inquiring whether a rollback record containing the main transaction identifier exists or not to obtain a second inquiry result;
the one-stage transaction processing module specifically comprises:
and the one-stage transaction processing unit is used for processing the one-stage transaction when the second query result indicates that the rollback record containing the main transaction identifier is not queried.
15. The apparatus of claim 14, further comprising:
and the first ending unit is used for ending the process of processing the one-stage transaction when the second query result indicates that the rollback record containing the main transaction identifier exists.
16. The apparatus of claim 13, further comprising:
a third result determining unit, configured to query a rollback record including the main transaction identifier when the first query result indicates that the main transaction record including the main transaction identifier is not queried, to obtain a third query result;
a locking unit, configured to perform a locking operation on a storage area of the rollback record including the primary transaction identifier when the third query result indicates that the rollback record including the primary transaction identifier is not queried;
and the second main transaction record insertion unit is used for inserting the main transaction record containing the main transaction identifier.
17. The apparatus of claim 16, further comprising:
and the second ending unit is used for ending the process of processing the one-stage transaction when the third query result indicates that the rollback record containing the main transaction identifier is queried.
18. A transaction processing apparatus, comprising:
the rollback instruction acquisition module is used for acquiring rollback instructions which are sent by the server and indicate to perform two-stage transaction processing; the two-stage transaction is a transaction which needs to be processed in the second stage by a main transaction which needs to be submitted in two stages; the rollback instruction comprises a main transaction identifier of the main transaction;
a determining module, configured to determine that a one-stage transaction of the master transaction has been executed; the one-stage transaction is a transaction which needs to be processed in the first stage of a main transaction submitted by two stages; the determining module specifically includes: the first result determining unit is used for querying a main transaction record containing the main transaction identifier to obtain a first query result; a main transaction record locking unit, configured to lock a main transaction record when the first query result indicates that the main transaction record including the main transaction identifier is queried; the primary transaction record locking unit is further configured to insert a primary transaction record including the primary transaction identifier when the first query result indicates that the primary transaction record is not queried, where the one-stage transaction occupies a storage space, so that the one-stage transaction cannot be inserted if the one-stage transaction is executed because the storage space corresponding to the primary transaction record is occupied; deleting the master transaction record;
And the rollback execution module is used for executing rollback operation on the executed one-stage transaction.
19. The apparatus of claim 18, further comprising:
and the first inserting module is used for executing the rollback record operation which is inserted to contain the main transaction identifier after the rollback operation executing module executes the rollback operation on the executed one-stage transaction.
20. The apparatus of claim 18, the determining module further comprising:
a main transaction record inserting unit for inserting a main transaction record containing the main transaction identifier when the first query result indicates that the main transaction record containing the main transaction identifier is not queried;
a main transaction record deleting unit for deleting the main transaction record;
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 indicates that the rollback record containing the main transaction identifier is not queried.
21. The apparatus of claim 20, further comprising:
and the first ending 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.
22. The apparatus of claim 18, further comprising:
the third result determining unit is used for executing the rollback record comprising the main transaction identifier before the first query result determining unit queries the main transaction record comprising the main transaction identifier, so as to obtain a third query result operation;
and the third inserting unit is used for inserting the rollback record containing the main transaction identifier when the third query result indicates that the rollback record containing the main transaction identifier is not queried.
23. The apparatus of claim 22, further comprising:
and the second ending unit is used for ending the process of processing the two-stage transaction when the third query result indicates that the rollback record containing the main transaction identifier is queried.
24. The apparatus of claim 20, further comprising:
and the third ending unit is used for ending the process of processing the two-stage transaction when the first query result indicates that the primary transaction record containing the primary transaction identifier is not queried.
25. A transaction processing device, comprising:
at least one processor; the method comprises the steps of,
a memory communicatively coupled to the at least one processor; wherein,
The memory stores instructions executable by the at least one processor to enable the at least one processor to:
acquiring an instruction sent by a server for indicating to perform one-stage transaction processing; the one-stage transaction is a transaction which needs to be processed in the first stage of a main transaction submitted by two stages; the instruction comprises a main transaction identifier of the main transaction;
determining that the two-stage transaction of the main transaction is not executed, specifically comprising:
inquiring a main transaction record containing the main transaction identifier to obtain a first inquiry result;
when the first query result indicates that the main transaction record containing the main transaction identifier is queried, locking the main transaction record; the two-stage transaction is a transaction which needs to be processed in the second stage by a main transaction which needs to be submitted in two stages;
when the first query result indicates that the main transaction record cannot be queried, inserting the main transaction record containing the main transaction identifier, wherein the one-stage transaction occupies a storage space, so that the one-stage transaction cannot be inserted because the storage space corresponding to the main transaction record is occupied when the one-stage transaction is executed in the execution process of the two-stage transaction; deleting the master transaction record;
The one-phase transaction is processed.
26. A transaction processing device, comprising:
at least one processor; the method comprises the steps of,
a memory communicatively coupled to the at least one processor; wherein,
the memory stores instructions executable by the at least one processor to enable the at least one processor to:
acquiring a rollback instruction sent by a server and indicating to perform two-stage transaction processing; the two-stage transaction is a transaction which needs to be processed in the second stage by a main transaction which needs to be submitted in two stages; the rollback instruction comprises a main transaction identifier of the main transaction;
determining that the one-stage transaction of the main transaction is executed, specifically includes:
inquiring a main transaction record containing the main transaction identifier to obtain a first inquiry result;
when the first query result indicates that the main transaction record containing the main transaction identifier is queried, locking the main transaction record; the one-stage transaction is a transaction which needs to be processed in the first stage of a main transaction submitted by two stages; when the first query result indicates that the main transaction record cannot be queried, inserting the main transaction record containing the main transaction identifier, wherein the one-stage transaction occupies a storage space, so that the one-stage transaction cannot be inserted because the storage space corresponding to the main transaction record is occupied when the one-stage transaction is executed in the execution process of the two-stage transaction; deleting the master transaction record;
And executing rollback operation on the executed one-stage transaction.
CN201811624568.5A 2018-12-28 2018-12-28 Transaction processing method, device and equipment Active CN109901914B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201811624568.5A CN109901914B (en) 2018-12-28 2018-12-28 Transaction processing method, device and equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201811624568.5A CN109901914B (en) 2018-12-28 2018-12-28 Transaction processing method, device and equipment

Publications (2)

Publication Number Publication Date
CN109901914A CN109901914A (en) 2019-06-18
CN109901914B true CN109901914B (en) 2024-01-26

Family

ID=66943505

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201811624568.5A Active CN109901914B (en) 2018-12-28 2018-12-28 Transaction processing method, device and equipment

Country Status (1)

Country Link
CN (1) CN109901914B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114730314A (en) * 2019-11-30 2022-07-08 华为云计算技术有限公司 Transaction submitting system and method and related equipment
CN115454656A (en) * 2022-08-09 2022-12-09 阿里云计算有限公司 Transaction processing method, device and storage medium

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US8352421B2 (en) * 2008-05-28 2013-01-08 Red Hat, Inc. Recording distributed transactions using probabalistic data structures
CN106033437B (en) * 2015-03-13 2020-01-10 阿里巴巴集团控股有限公司 Distributed transaction processing method and system
CN106844014B (en) * 2015-12-07 2020-04-28 阿里巴巴集团控股有限公司 Method and device for realizing suspension prevention of distributed transactions

Also Published As

Publication number Publication date
CN109901914A (en) 2019-06-18

Similar Documents

Publication Publication Date Title
EP3547129A1 (en) Block chain consensus method and device
US10545913B1 (en) Data storage system with on-demand recovery of file import metadata during file system migration
CN106844014B (en) Method and device for realizing suspension prevention of distributed transactions
CN108628688B (en) Message processing method, device and equipment
CN107590207B (en) Data synchronization method and device and electronic equipment
CN109033127B (en) Synchronous data verification method, device and equipment
CN113743942B (en) Transaction execution method, blockchain, master node and master storage device
CN113743941A (en) Method for executing transaction in block chain, block chain and main node
CN109901914B (en) Transaction processing method, device and equipment
CN110807013B (en) Data migration method and device for distributed data storage cluster
CN110633096B (en) Node control method and device, version control method and device and distributed system
CN108304455B (en) Method, device and equipment for processing service request
CN116048800A (en) Data processing method and device, storage medium and electronic equipment
US10901971B2 (en) Random walking and cluster-based random walking method, apparatus and device
CN113806143B (en) Remote disaster recovery method, system and electronic equipment
CN116166614A (en) Log archiving method and device, storage medium and electronic equipment
Pankowski Consistency and availability of Data in replicated NoSQL databases
CN107506378B (en) Method and device for realizing database access
CN115587099A (en) Distributed meter lock application method and device, storage medium and electronic equipment
CN111339117B (en) Data processing method, device and equipment
CN108153799B (en) Database access control method and device and database system
CN115774754A (en) Metadata management method, device, equipment and medium based on distributed transaction
CN115098483A (en) Pre-execution cache data cleaning method and block link point
CN115033350A (en) Execution method and device of distributed transaction
CN116541407B (en) Data processing method and device, storage medium and electronic equipment

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
TA01 Transfer of patent application right

Effective date of registration: 20201014

Address after: Cayman Enterprise Centre, 27 Hospital Road, George Town, Grand Cayman Islands

Applicant after: Innovative advanced technology Co.,Ltd.

Address before: Cayman Enterprise Centre, 27 Hospital Road, George Town, Grand Cayman Islands

Applicant before: Advanced innovation technology Co.,Ltd.

Effective date of registration: 20201014

Address after: Cayman Enterprise Centre, 27 Hospital Road, George Town, Grand Cayman Islands

Applicant after: Advanced innovation technology Co.,Ltd.

Address before: A four-storey 847 mailbox in Grand Cayman Capital Building, British Cayman Islands

Applicant before: Alibaba Group Holding Ltd.

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