CN114356888A - Transaction processing method and device, storage medium and electronic equipment - Google Patents

Transaction processing method and device, storage medium and electronic equipment Download PDF

Info

Publication number
CN114356888A
CN114356888A CN202111660999.9A CN202111660999A CN114356888A CN 114356888 A CN114356888 A CN 114356888A CN 202111660999 A CN202111660999 A CN 202111660999A CN 114356888 A CN114356888 A CN 114356888A
Authority
CN
China
Prior art keywords
transaction
sub
group
execution
participant
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111660999.9A
Other languages
Chinese (zh)
Inventor
陈伟
刘佳
蒋廷波
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
China Travelsky Technology Co Ltd
Original Assignee
China Travelsky Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by China Travelsky Technology Co Ltd filed Critical China Travelsky Technology Co Ltd
Priority to CN202111660999.9A priority Critical patent/CN114356888A/en
Publication of CN114356888A publication Critical patent/CN114356888A/en
Pending legal-status Critical Current

Links

Images

Abstract

The invention provides a transaction processing method and device, a storage medium and electronic equipment, wherein the method comprises the following steps: when a transaction execution instruction is received, determining a transaction group corresponding to the transaction execution instruction; judging whether a distributed lock is set for the transaction group; if not, setting a distributed lock for the transaction group, and setting the transaction state of each sub-transaction of the transaction group as a state to be executed, so that the transaction participant of each sub-transaction in the transaction group executes the transaction operation corresponding to the sub-transaction; acquiring the execution state and the execution duration of each sub-transaction; and if the execution state of at least one sub-transaction represents that the transaction operation fails to be executed, or the execution duration is greater than a preset duration threshold, sending rollback information to the transaction participant of each sub-transaction to indicate the transaction participant of each sub-transaction to execute the rollback operation on the sub-transaction based on the local database. The transaction processing method provided by the invention can ensure the accuracy of the data required by transaction rollback.

Description

Transaction processing method and device, storage medium and electronic equipment
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a transaction processing method and apparatus, a storage medium, and an electronic device.
Background
With the rapid development of the internet, service architecture modes such as micro services and SOA are being used in large scale, and a distributed system generally comprises a plurality of independent subsystems at present, and the subsystems cooperate with each other through network communication to complete each function. Many services can be completed across multiple subsystems, and a typical ordering and payment process of an e-commerce website at least involves a transaction system and a payment system. Moreover, the concept of transaction, i.e. ensuring data consistency between the transaction system and the payment system, is involved in this process, and we refer to this kind of transaction across systems as distributed transaction.
In the prior art, in the execution process of a distributed transaction, if the execution of the transaction fails, process data is stored through a temporary table, and the transaction is rolled back through the process data.
Disclosure of Invention
The technical problem to be solved by the invention is to provide a transaction processing method which can ensure the accuracy of data required by transaction rollback.
The invention also provides a transaction processing device used for ensuring the realization and the application of the method in practice.
A transaction processing method, comprising:
when a transaction execution instruction is received, determining a transaction group corresponding to the transaction execution instruction; the transaction group comprises a plurality of sub-transactions;
judging whether a distributed lock is set for the transaction group;
if not, setting a distributed lock for the transaction group, and setting the transaction state of each sub-transaction of the transaction group as a state to be executed, so that a transaction participant of each sub-transaction in the transaction group executes the transaction operation corresponding to the sub-transaction;
acquiring the execution state and the execution duration of each sub-transaction, wherein the execution state of the sub-transaction is the transaction state updated by the transaction participant of the sub-transaction after the execution of the transaction operation is completed;
and if the execution state of at least one sub-transaction represents that the transaction operation fails to be executed, or the execution duration is greater than a preset duration threshold, sending rollback information to the transaction participant of each sub-transaction to indicate the transaction participant of each sub-transaction to execute the rollback operation on the sub-transaction based on the database of the transaction participant.
A transaction processing device, comprising:
the determining unit is used for determining a transaction group corresponding to the transaction execution instruction when the transaction execution instruction is received; the transaction group comprises a plurality of sub-transactions;
the judging unit is used for judging whether a distributed lock is set for the transaction group;
the setting unit is used for setting a distributed lock for the transaction group and setting the transaction state of each sub-transaction of the transaction group as a to-be-executed state under the condition that the distributed lock is not set for the transaction group, so that a transaction participant of each sub-transaction in the transaction group executes the transaction operation corresponding to the sub-transaction;
an obtaining unit, configured to obtain an execution state and an execution duration of each sub-transaction, where the execution state of the sub-transaction is a transaction state updated by a transaction participant of the sub-transaction after the transaction operation is completed;
and the rollback unit is used for sending rollback information to the transaction participant of each sub-transaction to indicate that the transaction participant of each sub-transaction executes the rollback operation on the sub-transaction based on the database of the transaction participant if the execution state of at least one sub-transaction represents that the transaction operation fails to execute, or the execution duration is greater than a preset duration threshold.
A storage medium comprising stored instructions, wherein the instructions, when executed, control a device on which the storage medium resides to perform a transaction processing method as described above.
An electronic device comprising a memory, and one or more instructions, wherein the one or more instructions are stored in the memory and configured to be executed by one or more processors to perform a transaction processing method as described above.
Compared with the prior art, the invention has the following advantages:
the invention provides a transaction processing method and device, a storage medium and electronic equipment, wherein the method comprises the following steps: when a transaction execution instruction is received, determining a transaction group corresponding to the transaction execution instruction; the transaction group comprises a plurality of sub-transactions; judging whether a distributed lock is set for the transaction group; if not, setting a distributed lock for the transaction group, and setting the transaction state of each sub-transaction of the transaction group as a state to be executed, so that a transaction participant of each sub-transaction in the transaction group executes the transaction operation corresponding to the sub-transaction; acquiring the execution state and the execution duration of each sub-transaction, wherein the execution state of the sub-transaction is the transaction state updated by the transaction participant of the sub-transaction after the execution of the transaction operation is completed; and if the execution state of at least one sub-transaction represents that the transaction operation fails to be executed, or the execution duration is greater than a preset duration threshold, sending rollback information to the transaction participant of each sub-transaction to indicate the transaction participant of each sub-transaction to execute the rollback operation on the sub-transaction based on the database of the transaction participant. By applying the transaction processing method provided by the invention, the transaction participant of each sub-transaction can execute the rollback operation on the sub-transaction based on the database of the transaction participant. The accuracy of the data rolled back by the transaction can be improved.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the provided drawings without creative efforts.
FIG. 1 is a flow chart of a method of transaction processing according to the present invention;
FIG. 2 is a flow chart of a method of another transaction processing method provided by the present invention;
FIG. 3 is a flow diagram of a lock handling process provided by the present invention;
FIG. 4 is a schematic structural diagram of a transaction processing apparatus according to the present invention;
fig. 5 is a schematic structural diagram of an electronic device provided in the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
In this application, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
An embodiment of the present invention provides a transaction processing method, where an execution subject of the method may be an electronic device, the electronic device includes a transaction coordinator of a distributed system, and a flowchart of the method is shown in fig. 1, and specifically includes:
s101: when a transaction execution instruction is received, determining a transaction group corresponding to the transaction execution instruction; the transaction group includes a plurality of sub-transactions.
In the embodiment of the present invention, after receiving the transaction execution instruction, the service operation in the transaction execution instruction may be obtained, and a transaction group is generated according to the service operation, where the transaction group includes a plurality of sub-transactions, and each sub-transaction may be regarded as a service implementation of each sub-transaction in the distributed application.
S102: determining whether a distributed lock has been set for the transaction group.
The method includes the steps of determining whether a preset configuration file contains a distributed lock identifier of a transaction group, if the configuration file contains the distributed lock identifier of the transaction group, determining that a distributed lock is already set for the transaction group, and if the configuration file does not contain the distributed lock identifier of the transaction group, determining that the distributed lock is not already set for the transaction group.
Wherein each sub-transaction of the transaction group may be a local transaction.
S103: if not, setting a distributed lock for the transaction group, and setting the transaction state of each sub-transaction of the transaction group as a to-be-executed state, so that the transaction participant of each sub-transaction in the transaction group executes the transaction operation corresponding to the sub-transaction.
Distributed locks are used to ensure that the transaction coordinator guarantees the atomicity of the transaction in operation, that is, the integrity of the transaction operation of each sub-transaction of the transaction group.
Specifically, the distributed lock is set so that each service in the distributed system can be controlled by the distributed lock, and the distributed lock may be a redis distributed lock.
In the embodiment of the invention, the distributed lock is released after the preset lock release time point is reached and each sub-transaction in the transaction group rolls back or commits.
After the distributed lock is successfully created, the distributed lock identification of the distributed lock of the transaction group is stored in a configuration file stored in the redis database for indicating that the distributed lock has been set for the transaction group.
Each sub-transaction in the transaction group has a corresponding transaction state, and the transaction state can be set to be a to-be-executed state, a rollback state and a commit state; the to-be-executed state of the sub-transaction is used for indicating the transaction participants of the sub-transaction to execute the transaction operation corresponding to the sub-transaction, the rollback state of the sub-transaction indicates that the transaction participants of the sub-transaction fail to execute the transaction operation of the sub-transaction, and the commit state of the sub-transaction is used for indicating that the transaction participants of the sub-transaction successfully execute the transaction operation of the sub-transaction.
S104: and acquiring the execution state and the execution duration of each sub-transaction, wherein the execution state of the sub-transaction is the transaction state updated by the transaction participant of the sub-transaction after the execution of the transaction operation is completed.
The execution state of the sub-transaction is a rollback state or a commit state, and after the transaction participant successfully executes the transaction operation of the sub-transaction, the transaction participant updates the transaction state of the sub-transaction to the commit state and takes the commit state as the execution state of the sub-transaction; and after the execution of the time operation of the transaction participant fails, updating the transaction state of the sub-transaction into a rollback state, and taking the rollback state as the execution state of the sub-transaction.
S105: and if the execution state of at least one sub-transaction represents that the transaction operation fails to be executed, or the execution duration is greater than a preset duration threshold, sending rollback information to the transaction participant of each sub-transaction to indicate the transaction participant of each sub-transaction to execute the rollback operation on the sub-transaction based on the database of the transaction participant.
Wherein the database may be a local redis database with transaction functionality.
S106: and if the execution state of each sub-transaction represents that the transaction is successfully executed and the execution duration of each sub-transaction is less than the preset execution duration, sending a commit message to the transaction participant of each sub-transaction to indicate the transaction participant of each sub-transaction to commit each sub-transaction.
By applying the transaction processing method provided by the invention, the transaction participant of each sub-transaction can execute the rollback operation on the sub-transaction based on the database of the transaction participant. The accuracy of the data rolled back by the transaction can be improved.
In the method provided in the embodiment of the present invention, based on the implementation process, specifically, after rolling back each sub-transaction in the transaction group or committing each sub-transaction in the transaction group, the method further includes:
releasing the distributed lock for the transaction group.
By applying the method provided by the embodiment of the invention, the distributed lock is released after each sub-transaction in the transaction group is submitted or rolled back, so that the lock resources can be prevented from being occupied.
In the method provided in the embodiment of the present invention, based on the implementation process, specifically, after the creating a distributed lock for the transaction group, the method further includes:
detecting whether a first time length between a current time point and a preset lock release time point is less than a preset effective time length or not;
if the first time length between the current time point and the preset lock release time point is less than the effective time length, under the condition that each sub-transaction of the transaction group is not completed, the lock release time point is adjusted, so that the second time length between the current time point and the adjusted lock release time point is greater than the first time length.
If the first time duration between the current time point and the lock release time point is less than the effective time duration, whether each sub-transaction of the transaction group is completed or not can be determined, and if the sub-transactions of the transaction group are completed, the distributed lock of the transaction group is released when the lock release time point is reached.
If the first duration between the current time point and the lock release time point is not less than the effective duration, returning to continue detecting whether the first duration between the current time point and the lock release time point is less than the effective duration.
By applying the method provided by the embodiment of the invention, the problem of deadlock caused by the fact that the lock cannot be released for a long time due to abnormal sending in the execution process can be avoided by setting the lock release time point.
In the practical application process, the embodiment of the invention can be applied to various fields, for example, the field of flight data processing of civil aviation, and particularly, the embodiment of the invention can be applied to the bill processing of flights and the like, so that the data consistency of each subsystem in a civil aviation system can be ensured.
In the process of specific implementation, two stages can be divided.
The first stage is a preparation stage, the transaction coordinator is served by redis, the transaction participants send participation applications to the transaction coordinator, the transaction coordinator does not need to wait for replies, and the transaction coordinator only needs to record the current states of the participants.
The transaction participants begin executing the local business, and the execution of the local business completely depends on the transaction management of the local database.
And after the transaction participant finishes the business operation, the transaction coordinator is informed that the operation is finished but does not submit the local transaction.
The second phase is an execution phase, and after completing the operation (success, failure), the transaction participants need to inform the transaction coordinator and continuously ask the transaction coordinator whether the commit operation can be performed.
Based on the foregoing solution, a method flowchart of another transaction processing method provided in the embodiment of the present invention, as shown in fig. 2, specifically includes:
the method comprises the following steps: the transaction coordinator for establishing the distributed system is mainly realized by using redis. The transaction coordinator generates a transaction group for our business operation, where the transaction group includes multiple sub-transactions, and each sub-transaction can be regarded as a business implementation of each sub-transaction in the distributed application.
Step two: in order to ensure that the transaction coordinator can ensure the atomicity of the transaction in operation, a distributed lock is opened for the current transaction group for locking the current atomicity operation. Through the redis, each service in the distributed system can be controlled by the distributed lock.
Referring to fig. 3, a flow chart of a lock processing procedure provided in the embodiment of the present invention is that, first, a locking method is called at a client (service execution entry method) that initiates a distributed transaction, and once the locking method is executed, a record with the current transaction as a unique id is added to redis to indicate that the current operation is locked, and a validity period is given to prevent deadlock, and meanwhile, a monitoring method is started to monitor whether the current lock needs to extend the validity period, and prevent the problem that the current transaction is still in normal execution but is automatically released from lock. Example codes are as follows:
Figure BDA0003446955370000071
step three: after the lock is added to the transaction coordinator, the transaction state of each application in the local machine needs to be written into the transaction group as "to be executed".
The transaction group relates to a plurality of sub-transactions, the state of each sub-transaction is stored in a map mode, and the key is the name (unique) of each sub-transaction.
Step four: and setting the overtime execution duration for the transaction group.
Step five: and starting to execute the transaction operation of the sub-transaction, and modifying the state of the corresponding sub-transaction to be 'to be submitted' or 'to be rolled back' after the transaction operation of the sub-transaction is executed.
Step six: before the transaction is submitted, each subsystem needs to continuously judge the states of all the sub-transactions in the transaction group and whether the execution duration exceeds the longest duration set by the transaction group. And if all the sub-transaction states are 'to be submitted' within the set timeout range, submitting the local transaction. If the "to-be-rolled-back" status occurs in the child transaction, the local transaction is immediately rolled back.
Step seven: and releasing the global transaction lock after the local transaction completes the commit operation or the rollback operation.
The method provided by the embodiment of the invention can effectively solve the problem of how to quickly and effectively solve the distributed transaction under the condition of low concurrency, and compared with other distributed transaction solutions, the method provided by the embodiment of the invention can be completed only by relying on redis, and more of the method utilizes the local support of the database for the transaction.
The method provided by the embodiment of the invention can also be used for projects with higher requirements on data accuracy, because the implementation mechanism is mainly dependent on a rollback mechanism of the local database, rollback failure caused by additional factors (rollback of other distributed transactions may depend on a temporary table to store process data, rollback operation depends on the process data, relatively higher cost is needed for managing the process data, and certain risk exists in a specific project environment) is eliminated, so that the accuracy of the data is influenced, but if the local database is directly used, good experience is provided on the accuracy of data rollback.
Corresponding to the method described in fig. 1, an embodiment of the present invention further provides a transaction processing apparatus, which is used for specifically implementing the method in fig. 1, where the transaction processing apparatus provided in the embodiment of the present invention may be applied to an electronic device, and a schematic structural diagram of the transaction processing apparatus is shown in fig. 4, and specifically includes:
a determining unit 401, configured to determine, when a transaction execution instruction is received, a transaction group corresponding to the transaction execution instruction; the transaction group comprises a plurality of sub-transactions;
a determining unit 402, configured to determine whether a distributed lock has been set for the transaction group;
a setting unit 403, configured to, in a case that a distribution lock is not set for a transaction group, set a distribution lock for the transaction group, and set a transaction state of each sub-transaction of the transaction group to a to-be-executed state, so that a transaction participant of each sub-transaction in the transaction group executes a transaction operation corresponding to the sub-transaction;
an obtaining unit 404, configured to obtain an execution state and an execution duration of each sub-transaction, where the execution state of the sub-transaction is a transaction state updated by a transaction participant of the sub-transaction after the execution of the transaction operation is completed;
a rollback unit 405, configured to send rollback information to a transaction participant of each sub-transaction to instruct the transaction participant of each sub-transaction to perform a rollback operation on the sub-transaction based on the database of the transaction participant if there is an execution state of at least one of the sub-transactions that indicates that the transaction operation fails to be executed, or an execution duration is greater than a preset duration threshold.
In an embodiment provided by the present invention, based on the above scheme, specifically, the transaction processing apparatus further includes:
and the submitting unit is used for sending a submitting message to the transaction participant of each sub-transaction to indicate that the transaction participant of each sub-transaction submits each sub-transaction if the execution state of each sub-transaction represents that the transaction is successfully executed and the execution duration of each sub-transaction is less than the preset execution duration.
In an embodiment provided by the present invention, based on the above scheme, specifically, the transaction processing apparatus further includes:
and the lock releasing unit is used for releasing the distributed lock of the transaction group.
In an embodiment provided by the present invention, based on the above scheme, specifically, the transaction processing apparatus further includes:
the detection unit is used for detecting whether a first time length between the current time point and a preset lock release time point is less than a preset effective time length or not;
an adjusting unit, configured to adjust the lock release time point if a first time length between the current time point and the preset lock release time point is less than the effective time length, so that a second time length between the current time point and the adjusted lock release time point is greater than the first time length when each sub-transaction of the transaction group is not completed.
The specific principle and the execution process of each unit and each module in the transaction processing device disclosed in the above embodiment of the present invention are the same as those of the transaction processing method disclosed in the above embodiment of the present invention, and reference may be made to corresponding parts in the transaction processing method provided in the above embodiment of the present invention, and details are not described here.
An embodiment of the present invention further provides a storage medium, where the storage medium includes a stored instruction, where when the instruction runs, a device where the storage medium is located is controlled to execute the transaction processing method, where the method specifically includes:
when a transaction execution instruction is received, determining a transaction group corresponding to the transaction execution instruction; the transaction group comprises a plurality of sub-transactions;
judging whether a distributed lock is set for the transaction group;
if not, setting a distributed lock for the transaction group, and setting the transaction state of each sub-transaction of the transaction group as a state to be executed, so that a transaction participant of each sub-transaction in the transaction group executes the transaction operation corresponding to the sub-transaction;
acquiring the execution state and the execution duration of each sub-transaction, wherein the execution state of the sub-transaction is the transaction state updated by the transaction participant of the sub-transaction after the execution of the transaction operation is completed;
and if the execution state of at least one sub-transaction represents that the transaction operation fails to be executed, or the execution duration is greater than a preset duration threshold, sending rollback information to the transaction participant of each sub-transaction to indicate the transaction participant of each sub-transaction to execute the rollback operation on the sub-transaction based on the database of the transaction participant.
The above method, optionally, further includes:
and if the execution state of each sub-transaction represents that the transaction is successfully executed and the execution duration of each sub-transaction is less than the preset execution duration, sending a commit message to the transaction participant of each sub-transaction to indicate the transaction participant of each sub-transaction to commit each sub-transaction.
Optionally, the method further includes, after rolling back each sub-transaction in the transaction group:
releasing the distributed lock for the transaction group.
Optionally, the method further includes, after creating the distributed lock for the transaction group, that:
detecting whether a first time length between a current time point and a preset lock release time point is less than a preset effective time length or not;
if the first time length between the current time point and the preset lock release time point is less than the effective time length, under the condition that each sub-transaction of the transaction group is not completed, the lock release time point is adjusted, so that the second time length between the current time point and the adjusted lock release time point is greater than the first time length.
An electronic device is provided in an embodiment of the present invention, and the structural diagram of the electronic device is shown in fig. 5, which specifically includes a memory 501 and one or more instructions 502, where the one or more instructions 502 are stored in the memory 501, and are configured to be executed by one or more processors 503 to perform the following operations according to the one or more instructions 502:
when a transaction execution instruction is received, determining a transaction group corresponding to the transaction execution instruction; the transaction group comprises a plurality of sub-transactions;
judging whether a distributed lock is set for the transaction group;
if not, setting a distributed lock for the transaction group, and setting the transaction state of each sub-transaction of the transaction group as a state to be executed, so that a transaction participant of each sub-transaction in the transaction group executes the transaction operation corresponding to the sub-transaction;
acquiring the execution state and the execution duration of each sub-transaction, wherein the execution state of the sub-transaction is the transaction state updated by the transaction participant of the sub-transaction after the execution of the transaction operation is completed;
and if the execution state of at least one sub-transaction represents that the transaction operation fails to be executed, or the execution duration is greater than a preset duration threshold, sending rollback information to the transaction participant of each sub-transaction to indicate the transaction participant of each sub-transaction to execute the rollback operation on the sub-transaction based on the database of the transaction participant.
In accordance with one or more embodiments of the present disclosure, the embodiment of fig. 1 provides a transaction processing method, including:
when a transaction execution instruction is received, determining a transaction group corresponding to the transaction execution instruction; the transaction group comprises a plurality of sub-transactions;
judging whether a distributed lock is set for the transaction group;
if not, setting a distributed lock for the transaction group, and setting the transaction state of each sub-transaction of the transaction group as a state to be executed, so that a transaction participant of each sub-transaction in the transaction group executes the transaction operation corresponding to the sub-transaction;
acquiring the execution state and the execution duration of each sub-transaction, wherein the execution state of the sub-transaction is the transaction state updated by the transaction participant of the sub-transaction after the execution of the transaction operation is completed;
and if the execution state of at least one sub-transaction represents that the transaction operation fails to be executed, or the execution duration is greater than a preset duration threshold, sending rollback information to the transaction participant of each sub-transaction to indicate the transaction participant of each sub-transaction to execute the rollback operation on the sub-transaction based on the database of the transaction participant.
The above method, optionally, further includes:
and if the execution state of each sub-transaction represents that the transaction is successfully executed and the execution duration of each sub-transaction is less than the preset execution duration, sending a commit message to the transaction participant of each sub-transaction to indicate the transaction participant of each sub-transaction to commit each sub-transaction.
Optionally, the method further includes, after rolling back each sub-transaction in the transaction group:
releasing the distributed lock for the transaction group.
Optionally, the method further includes, after creating the distributed lock for the transaction group, that:
detecting whether a first time length between a current time point and a preset lock release time point is less than a preset effective time length or not;
if the first time length between the current time point and the preset lock release time point is less than the effective time length, under the condition that each sub-transaction of the transaction group is not completed, the lock release time point is adjusted, so that the second time length between the current time point and the adjusted lock release time point is greater than the first time length.
In accordance with one or more embodiments of the present disclosure, the embodiment of fig. 4 provides a transaction processing apparatus, including:
the determining unit is used for determining a transaction group corresponding to the transaction execution instruction when the transaction execution instruction is received; the transaction group comprises a plurality of sub-transactions;
the judging unit is used for judging whether a distributed lock is set for the transaction group;
the setting unit is used for setting a distributed lock for the transaction group and setting the transaction state of each sub-transaction of the transaction group as a to-be-executed state under the condition that the distributed lock is not set for the transaction group, so that a transaction participant of each sub-transaction in the transaction group executes the transaction operation corresponding to the sub-transaction;
an obtaining unit, configured to obtain an execution state and an execution duration of each sub-transaction, where the execution state of the sub-transaction is a transaction state updated by a transaction participant of the sub-transaction after the transaction operation is completed;
and the rollback unit is used for sending rollback information to the transaction participant of each sub-transaction to indicate that the transaction participant of each sub-transaction executes the rollback operation on the sub-transaction based on the database of the transaction participant if the execution state of at least one sub-transaction represents that the transaction operation fails to execute, or the execution duration is greater than a preset duration threshold.
The above apparatus, optionally, further comprises:
and the submitting unit is used for sending a submitting message to the transaction participant of each sub-transaction to indicate that the transaction participant of each sub-transaction submits each sub-transaction if the execution state of each sub-transaction represents that the transaction is successfully executed and the execution duration of each sub-transaction is less than the preset execution duration.
The above apparatus, optionally, further comprises:
and the lock releasing unit is used for releasing the distributed lock of the transaction group.
The above apparatus, optionally, further comprises:
the detection unit is used for detecting whether a first time length between the current time point and a preset lock release time point is less than a preset effective time length or not;
an adjusting unit, configured to adjust the lock release time point if a first time length between the current time point and the preset lock release time point is less than the effective time length, so that a second time length between the current time point and the adjusted lock release time point is greater than the first time length when each sub-transaction of the transaction group is not completed.
It should be noted that, in the present specification, the embodiments are all described in a progressive manner, each embodiment focuses on differences from other embodiments, and the same and similar parts among the embodiments may be referred to each other. For the device-like embodiment, since it is basically similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment.
Finally, it should also be noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
For convenience of description, the above devices are described as being divided into various units by function, and are described separately. Of course, the functions of the units may be implemented in the same software and/or hardware or in a plurality of software and/or hardware when implementing the invention.
From the above description of the embodiments, it is clear to those skilled in the art that the present invention can be implemented by software plus necessary general hardware platform. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which may be stored in a storage medium, such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the method according to the embodiments or some parts of the embodiments.
The transaction processing method provided by the present invention is described in detail above, and the principle and the implementation of the present invention are explained in this document by applying specific examples, and the description of the above examples is only used to help understanding the method and the core idea of the present invention; meanwhile, for a person skilled in the art, according to the idea of the present invention, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present invention.

Claims (10)

1. A transaction processing method, comprising:
when a transaction execution instruction is received, determining a transaction group corresponding to the transaction execution instruction; the transaction group comprises a plurality of sub-transactions;
judging whether a distributed lock is set for the transaction group;
if not, setting a distributed lock for the transaction group, and setting the transaction state of each sub-transaction of the transaction group as a state to be executed, so that a transaction participant of each sub-transaction in the transaction group executes the transaction operation corresponding to the sub-transaction;
acquiring the execution state and the execution duration of each sub-transaction, wherein the execution state of the sub-transaction is the transaction state updated by the transaction participant of the sub-transaction after the execution of the transaction operation is completed;
and if the execution state of at least one sub-transaction represents that the transaction operation fails to be executed, or the execution duration is greater than a preset duration threshold, sending rollback information to the transaction participant of each sub-transaction to indicate the transaction participant of each sub-transaction to execute the rollback operation on the sub-transaction based on the database of the transaction participant.
2. The method of claim 1, further comprising:
and if the execution state of each sub-transaction represents that the transaction is successfully executed and the execution duration of each sub-transaction is less than the preset execution duration, sending a commit message to the transaction participant of each sub-transaction to indicate the transaction participant of each sub-transaction to commit each sub-transaction.
3. The method of claim 1, wherein after rolling back each sub-transaction in the transaction group, further comprising:
releasing the distributed lock for the transaction group.
4. The method of claim 1, wherein after creating the distributed lock for the transaction group, further comprising:
detecting whether a first time length between a current time point and a preset lock release time point is less than a preset effective time length or not;
if the first time length between the current time point and the preset lock release time point is less than the effective time length, under the condition that each sub-transaction of the transaction group is not completed, the lock release time point is adjusted, so that the second time length between the current time point and the adjusted lock release time point is greater than the first time length.
5. A transaction processing apparatus, comprising:
the determining unit is used for determining a transaction group corresponding to the transaction execution instruction when the transaction execution instruction is received; the transaction group comprises a plurality of sub-transactions;
the judging unit is used for judging whether a distributed lock is set for the transaction group;
the setting unit is used for setting a distributed lock for the transaction group and setting the transaction state of each sub-transaction of the transaction group as a to-be-executed state under the condition that the distributed lock is not set for the transaction group, so that a transaction participant of each sub-transaction in the transaction group executes the transaction operation corresponding to the sub-transaction;
an obtaining unit, configured to obtain an execution state and an execution duration of each sub-transaction, where the execution state of the sub-transaction is a transaction state updated by a transaction participant of the sub-transaction after the transaction operation is completed;
and the rollback unit is used for sending rollback information to the transaction participant of each sub-transaction to indicate that the transaction participant of each sub-transaction executes the rollback operation on the sub-transaction based on the database of the transaction participant if the execution state of at least one sub-transaction represents that the transaction operation fails to execute, or the execution duration is greater than a preset duration threshold.
6. The apparatus of claim 5, further comprising:
and the submitting unit is used for sending a submitting message to the transaction participant of each sub-transaction to indicate that the transaction participant of each sub-transaction submits each sub-transaction if the execution state of each sub-transaction represents that the transaction is successfully executed and the execution duration of each sub-transaction is less than the preset execution duration.
7. The apparatus of claim 5, further comprising:
and the lock releasing unit is used for releasing the distributed lock of the transaction group.
8. The apparatus of claim 5, further comprising:
the detection unit is used for detecting whether a first time length between the current time point and a preset lock release time point is less than a preset effective time length or not;
an adjusting unit, configured to adjust the lock release time point if a first time length between the current time point and the preset lock release time point is less than the effective time length, so that a second time length between the current time point and the adjusted lock release time point is greater than the first time length when each sub-transaction of the transaction group is not completed.
9. A storage medium, comprising storage instructions, wherein the instructions, when executed, control a device on which the storage medium is located to execute the transaction processing method according to any one of claims 1 to 4.
10. An electronic device comprising a memory and one or more instructions, wherein the one or more instructions are stored in the memory and configured to be executed by the one or more processors to perform the transaction processing method of any one of claims 1-4.
CN202111660999.9A 2021-12-30 2021-12-30 Transaction processing method and device, storage medium and electronic equipment Pending CN114356888A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111660999.9A CN114356888A (en) 2021-12-30 2021-12-30 Transaction processing method and device, storage medium and electronic equipment

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111660999.9A CN114356888A (en) 2021-12-30 2021-12-30 Transaction processing method and device, storage medium and electronic equipment

Publications (1)

Publication Number Publication Date
CN114356888A true CN114356888A (en) 2022-04-15

Family

ID=81105776

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111660999.9A Pending CN114356888A (en) 2021-12-30 2021-12-30 Transaction processing method and device, storage medium and electronic equipment

Country Status (1)

Country Link
CN (1) CN114356888A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115577031A (en) * 2022-10-24 2023-01-06 北京力控元通科技有限公司 Database transaction processing method and device, electronic equipment and storage medium

Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20020174108A1 (en) * 2001-05-15 2002-11-21 International Business Machines Corporation Method for managing distributed savepoints across multiple DBMS's within a distributed transaction
US20170097847A1 (en) * 2015-10-05 2017-04-06 International Business Machines Corporation Client controlled transaction processing involving a plurality of participants
CN107908518A (en) * 2017-06-29 2018-04-13 平安科技(深圳)有限公司 Database performance monitoring method, device, storage medium and computer equipment
CN108491252A (en) * 2018-03-13 2018-09-04 万惠投资管理有限公司 distributed transaction processing method and distributed system
CN111209142A (en) * 2020-01-02 2020-05-29 中国平安财产保险股份有限公司 Cross-database transaction management method, device, equipment and storage medium
US20200394052A1 (en) * 2019-06-14 2020-12-17 Oracle International Corporation Transaction state logger and retriever
US20210081429A1 (en) * 2017-06-12 2021-03-18 China Unionpay Co., Ltd. Transaction savepoint management apparatus and method for distributed database
WO2021169243A1 (en) * 2020-02-29 2021-09-02 华为技术有限公司 Method, apparatus and system for processing distributed transaction

Patent Citations (8)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20020174108A1 (en) * 2001-05-15 2002-11-21 International Business Machines Corporation Method for managing distributed savepoints across multiple DBMS's within a distributed transaction
US20170097847A1 (en) * 2015-10-05 2017-04-06 International Business Machines Corporation Client controlled transaction processing involving a plurality of participants
US20210081429A1 (en) * 2017-06-12 2021-03-18 China Unionpay Co., Ltd. Transaction savepoint management apparatus and method for distributed database
CN107908518A (en) * 2017-06-29 2018-04-13 平安科技(深圳)有限公司 Database performance monitoring method, device, storage medium and computer equipment
CN108491252A (en) * 2018-03-13 2018-09-04 万惠投资管理有限公司 distributed transaction processing method and distributed system
US20200394052A1 (en) * 2019-06-14 2020-12-17 Oracle International Corporation Transaction state logger and retriever
CN111209142A (en) * 2020-01-02 2020-05-29 中国平安财产保险股份有限公司 Cross-database transaction management method, device, equipment and storage medium
WO2021169243A1 (en) * 2020-02-29 2021-09-02 华为技术有限公司 Method, apparatus and system for processing distributed transaction

Non-Patent Citations (1)

* Cited by examiner, † Cited by third party
Title
陈学明: "《Spring+Spring MVC+MyBatis整合开发实战》", 30 June 2020, 机械工业出版社, pages: 380 *

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN115577031A (en) * 2022-10-24 2023-01-06 北京力控元通科技有限公司 Database transaction processing method and device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
US9417906B2 (en) Transaction participant registration with caveats
US6665814B2 (en) Method and apparatus for providing serialization support for a computer system
US7389350B2 (en) Method, apparatus and computer program product for integrating heterogeneous systems
US5923833A (en) Restart and recovery of OMG-compliant transaction systems
US6526416B1 (en) Compensating resource managers
US20080134219A1 (en) Apparatus for maintaining resource integrity without a unified transaction manager in a software environment
CN108491252B (en) Distributed transaction processing method and distributed system
US6061708A (en) System and method for supporting mixed-phase transactions in an object-oriented environment
CN111209142A (en) Cross-database transaction management method, device, equipment and storage medium
CN110888718A (en) Method and device for realizing distributed transaction
CN110413687B (en) Distributed transaction fault processing method and related equipment based on node interaction verification
CN113268471B (en) Method, proxy connection pool, system, device and medium for processing distributed transaction
US20090182787A1 (en) Recovery Administration of Global Transaction Participants
CN114253673A (en) Transaction processing method and transaction processing device of distributed system
CN112148436B (en) Decentralised TCC transaction management method, device, equipment and system
JPH09204341A (en) Numbering mechanism, data compatibility confirming mechanism, transaction rerun mechanism and distributed transaction processing system
US20060149791A1 (en) Database-driven distributed recovery
US7284018B1 (en) Logless transaction coordination
CN114356888A (en) Transaction processing method and device, storage medium and electronic equipment
CN115544044A (en) Data consistency keeping method, device, equipment and storage medium
WO2001050264A1 (en) Preserving consistency of passively-replicated non-deterministic objects
CN107465725B (en) Heterogeneous long transaction processing system and method based on client information control system
CN111143040A (en) Transaction processing method, device, system and storage medium
US5964828A (en) Method and system for maintaining the integrity of objects
CN114579260A (en) Transaction processing method and system

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