Global Transaction Processing Methods and Systems
By using global transaction processing methods and rollback log management, combined with optimistic locking and the 2PC algorithm, the problems of data consistency and processing efficiency in distributed systems are solved, achieving efficient and stable global transaction processing.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-13
- Publication Date
- 2026-03-10
AI Technical Summary
In distributed systems, improving the efficiency of global transaction processing while ensuring data consistency is a challenge that current technologies face problems such as complex development, high costs, and low processing efficiency.
By using a global transaction processing method, a global transaction is determined based on multiple sub-transactions. Rollback logs are used to manage the status of sub-transactions. Combined with optimistic locking and the 2PC algorithm, rollback logs are deleted only when all sub-transactions are completed, thus avoiding locking local resources and achieving lock-free processing.
It improves the efficiency of global transaction processing, enhances the stability and robustness of the system, reduces development costs, supports long transactions, and does not affect the normal processing of other transactions.
Smart Images

Figure CN113849278B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of data processing, and in particular to a global transaction processing method and system. BACKGROUND
[0002] With the development of information technology, software systems have changed from monolithic applications to distributed applications. Distributed systems split an application system into multiple services that can be independently deployed. Therefore, services need to remotely collaborate with each other to complete transaction operations. In a distributed system environment, transactions are completed by different services remotely collaborating through a network, which is referred to as a distributed transaction. A distributed transaction may involve multiple different application systems and data sources, and needs to ensure data consistency between multiple application systems during application.
[0003] Therefore, how to provide a global transaction processing method and system to improve the processing efficiency of global transactions while ensuring data consistency has become a problem to be solved. SUMMARY
[0004] The global transaction processing method and system provided by the present application are used to improve the processing efficiency of global transactions while ensuring data consistency.
[0005] The global transaction processing method provided by the present application comprises the following steps:
[0006] Based on multiple sub-transactions, a global transaction corresponding to the multiple sub-transactions is determined. At least two sub-transactions in the multiple sub-transactions are triggered by different service systems.
[0007] Based on the operation information of the received multiple sub-transactions, a rollback log corresponding to the global transaction is determined.
[0008] According to the rollback log corresponding to the global transaction, global transaction control is performed.
[0009] According to the global transaction processing method provided by the present application, before the step of determining a global transaction corresponding to multiple sub-transactions based on the multiple sub-transactions, the following steps are further included:
[0010] Sub-transaction annotations of multiple sub-transactions are received respectively. The sub-transaction annotation of each sub-transaction includes the identification and operation annotation of the sub-transaction. The operation annotation is a forward operation annotation or a reverse operation annotation.
[0011] The step of determining a global transaction corresponding to multiple sub-transactions based on the multiple sub-transactions comprises the following steps:
[0012] According to the sub-transaction annotations of the multiple sub-transactions, a global transaction corresponding to the multiple sub-transactions is determined. The global transaction has a global transaction unique identifier.
[0013] According to the global transaction processing method provided by the application, the rollback log corresponding to the global transaction is determined based on the received operation information of the plurality of sub-transactions, and specifically includes:
[0014] The operation information of each sub-transaction is received, and the operation information includes operation success or operation exception; wherein the operation information of each sub-transaction is determined according to the operation annotation of the sub-transaction;
[0015] In response to the operation success or operation exception of each sub-transaction, the rollback log corresponding to the global transaction is determined according to the optimistic lock mechanism.
[0016] According to the global transaction processing method provided by the application, the global transaction control is executed according to the rollback log corresponding to the global transaction, and specifically includes:
[0017] When it is determined according to the rollback log that the plurality of sub-transactions are operated successfully, the rollback log is deleted; or
[0018] When it is determined according to the rollback log that there is a sub-transaction with operation exception in the plurality of sub-transactions, an exception control instruction is sent, and the exception control instruction is used to instruct to execute a control operation on the plurality of sub-transactions.
[0019] According to the global transaction processing method provided by the application, when it is determined according to the rollback log that there is a sub-transaction with operation exception in the plurality of sub-transactions, the exception control instruction is sent, and the exception control instruction is used to instruct to execute a control operation on the plurality of sub-transactions, including:
[0020] When the rollback log is parsed and it is determined that there is a first sub-transaction with operation exception in the plurality of sub-transactions, the reverse operation interface corresponding to the plurality of sub-transactions is obtained, wherein the operation exception includes sub-transaction running exception;
[0021] Based on the reverse operation interface corresponding to the plurality of sub-transactions, the exception control instruction is sent, and the exception control instruction is used to instruct to execute a rollback operation on the plurality of sub-transactions;
[0022] In response to the completion of the rollback of the plurality of sub-transactions, the rollback log is deleted.
[0023] According to the global transaction processing method provided by the application, the operation annotation includes timeout time and runtime exception; and the rollback log includes sub-transaction start time;
[0024] The rollback log is parsed to determine the first sub-transaction with operation exception, and specifically includes:
[0025] parsing the rollback log to obtain the sub-transaction annotation of each sub-transaction, and determining the timeout time, the sub-transaction start time and operation annotation of each sub-transaction based on the sub-transaction annotation;
[0026] determining a sub-transaction running with a runtime exception and having a timeout as the first sub-transaction from the plurality of sub-transactions according to the operation annotation, the timeout time and the sub-transaction start time of each sub-transaction.
[0027] According to the global transaction processing method provided by the application, the operation annotation further comprises an exception rollback.
[0028] When it is determined that there is an operation exception in the plurality of sub-transactions according to the rollback log, an exception control instruction is sent, and the exception control instruction is used to instruct to perform a control operation on the plurality of sub-transactions, and specifically comprises:
[0029] parsing the rollback log to obtain the sub-transaction annotation of each sub-transaction;
[0030] When it is determined that there is an operation annotation of a second sub-transaction of an exception rollback in the plurality of sub-transactions based on the sub-transaction annotation, an exception control instruction is sent and the rollback log is deleted, and the exception control instruction is used to instruct not to perform a rollback operation on the plurality of sub-transactions.
[0031] The application further provides a global transaction processing method, comprising:
[0032] According to the information of the plurality of sub-transactions received, annotations are added to the plurality of sub-transactions respectively;
[0033] Based on the annotations of the plurality of sub-transactions, a registration request is sent to a server, and the registration request is used to request to determine a global transaction corresponding to the plurality of sub-transactions;
[0034] Operation information of each sub-transaction in the plurality of sub-transactions is determined and submitted to the server respectively, so as to determine a rollback log corresponding to the global transaction, and the rollback log is generated according to the operation information of each sub-transaction.
[0035] According to the global transaction processing method provided by the application, the plurality of sub-transactions are added with annotations respectively according to the information of the plurality of sub-transactions received, and specifically comprises:
[0036] According to the information of the plurality of sub-transactions received, a forward operation interface and a reverse operation interface corresponding to each sub-transaction in the plurality of sub-transactions are determined;
[0037] A forward operation annotation is added to the forward operation interface, and a reverse operation annotation is added to the reverse operation interface; wherein the annotation comprises a unique sub-transaction identifier.
[0038] wherein the method further comprises:
[0039] receiving the exception control instruction corresponding to the global transaction sent by the server;
[0040] According to the exception control instruction, the reverse operation interface of each sub-transaction is called to perform the rollback operation.
[0041] The application also provides a global transaction processing system, comprising a client and a server, wherein:
[0042] The client is configured to add annotations to the plurality of sub-transactions according to the received information of the plurality of sub-transactions, wherein at least two sub-transactions in the plurality of sub-transactions are triggered by different service systems; send a registration request to the server based on the annotations of the plurality of sub-transactions; determine and submit operation information of each sub-transaction in the plurality of sub-transactions to the server respectively;
[0043] The server is configured to receive the registration request, determine a global transaction corresponding to the plurality of sub-transactions, determine a rollback log corresponding to the global transaction based on the received operation information of the plurality of sub-transactions, and perform global transaction control according to the rollback log corresponding to the global transaction.
[0044] The application also provides an electronic device comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the global transaction processing method according to any one of the above embodiments when executing the program.
[0045] The application also provides a non-transitory computer readable storage medium having a computer program stored thereon, wherein the computer program is executable on a processor to implement the steps of the global transaction processing method according to any one of the above embodiments.
[0046] The global transaction processing method and system provided by the application manage and monitor the state of the sub-transactions by taking the global transaction and the corresponding sub-transactions as a complete unit and combining the rollback log, delete the corresponding rollback log only when it is determined that all the sub-transactions are completed, ensure the data consistency of the sub-transactions, and monitor the state of the sub-transactions only by the rollback transaction table without locking the local resources and affecting the normal processing of other transactions, thereby effectively improving the processing efficiency of the global transaction. BRIEF DESCRIPTION OF DRAWINGS
[0047] In order to make the technical solutions in the present application or prior art clearer, the drawings needed to be used in the embodiments or prior art description will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative effort on the basis of these drawings.
[0048] Figure 1 is one of the global transaction processing method flowcharts provided by the present application;
[0049] Figure 2 is a global transaction processing framework schematic diagram provided by the present application;
[0050] Figure 3 is a global transaction processing method timing flow schematic diagram provided by the present application;
[0051] Figure 4 is a global transaction exception rollback timing flow schematic diagram provided by the present application;
[0052] Figure 5 is another global transaction processing method flowchart provided by the present application;
[0053] Figure 6 is a global transaction processing system structure schematic diagram provided by the present application;
[0054] Figure 7 is an electronic device entity structure schematic diagram provided by the present application. DETAILED DESCRIPTION
[0055] In order to make the technical solutions in the present application or prior art clearer, the drawings needed to be used in the embodiments or prior art description will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present application, and other drawings can be obtained by those skilled in the art without creative effort on the basis of these drawings.
[0056] The application system consistency of single application and single data source in the prior art usually uses the transaction implementation provided by the database itself.
[0057] The transaction data consistency between multiple micro services in the internal distributed system of single application and multiple data sources can be realized by the Seata framework.
[0058] In a multi-application, multi-data source distributed transaction process across application systems, data consistency between multiple application systems needs to be ensured, for example: cross-bank transfer, involving the systems of two banks, ensuring the data consistency of the two banks. For example, a common e-commerce website involves two core systems of "bank deduction" and "logistics delivery", and the order system needs to ensure the data consistency of the two operations of user payment and logistics delivery. The data consistency cannot be paid and not delivered or not paid and delivered. At least two application systems of bank and logistics are involved, and the order system is used to implement and ensure the data consistency across the application systems.
[0059] Currently, there is no simple and easy solution for consistency of multiple application systems in the prior art. Generally, programmers use databases or transaction-enabled MQs with various locks to achieve 2PC or TCC algorithms, so as to achieve the purpose of distributed transactions.
[0060] For example, databases, transaction-enabled message queues (MQ), two-phase commit (2PC), three-phase commit (3PC), or distributed transaction TCC (Try-Confirm-Cancel) mode can also be used to ensure the data consistency between the application systems involved in the distributed transactions. However, the above methods have the problems of complex development process, high development cost, locking of local resources when applied, low efficiency of distributed transaction processing, and high error rate in processing, low stability and low robustness.
[0061] Before the detailed description of the present application, the related concepts involved in the present application are first described.
[0062] The present application is based on the Base theory. BASE is the abbreviation of Basically Available (basic availability), Softstate (soft state) and Eventually consistent (eventually consistent).
[0063] The BASE theory is an extension of AP in CAP. By sacrificing strong consistency, availability is obtained. When a fault occurs, partial unavailability is allowed, but the core function is ensured to be available. Data is allowed to be inconsistent for a period of time, but eventually reaches a consistent state. The transaction that meets the BASE theory is called "flexible transaction".
[0064] Basically available: the distributed system allows partial loss of available functions when a fault occurs, and ensures the availability of the core function. For example, if the payment of the e-commerce website transaction fails, the goods can still be normally browsed.
[0065] Soft state: BASE allows the system to have intermediate states (also called soft states) because it does not require strong consistency, which does not affect the availability of the system, such as the states of "payment in progress", "data synchronization in progress" and the like, and the state is changed to "success" state after the data is eventually consistent.
[0066] Eventually consistent: Eventually consistent means that after a period of time, all node data will be consistent. For example, the "payment in progress" state of an order will eventually become "payment success" or "payment failure", so that the order state is consistent with the actual transaction result, but there is a time delay and waiting.
[0067] Figure 2 The distributed transaction processing framework provided by the application is shown in the figure, and the application is implemented based on a C / S architecture, which includes a TM Client and a TM Server. Figure 2
[0068] TM Client (Transaction Management Client, transaction manager client): embedded in a certain micro-service system in the form of a jar package, providing basic annotations and data communication capabilities.
[0069] TM Server (Transaction Management Server, transaction manager server): that is, a global transaction manager, which uses a 2PC algorithm to implement distributed transaction control and management.
[0070] As shown in the figure, the entire distributed transaction processing can be divided into two steps, wherein step (1) is to register and submit a transaction, and after data modification, the global transaction is registered and submitted. Step (2) is to roll back the transaction, and if a system transaction fails to be executed, all global system transactions are rolled back, and the global transaction manager of the server schedules and notifies each system to roll back the transaction. Figure 2
[0071] 2PC (two-phase commit protocol) is a two-phase commit protocol, which divides the entire transaction process into two phases, P is the preparation phase (Prepare phase), and C is the commit phase (commit phase).
[0072] The entire transaction process is implemented by the global transaction manager TM Server and the participants TM Client.
[0073] Preparation phase (Prepare phase): TM Client registers a transaction, each TM Client provides two operation interfaces of forward and reverse, and then executes the operation locally, and the local transaction can also be executed locally without affecting the global transaction.
[0074] commit phase: if the transaction manager receives an execution failure or timeout message of a participant, directly sends a rollback message to each participant; otherwise, sends a commit message; the participant executes the commit or rollback operation according to the instruction of the transaction manager, and releases the lock resource used in the transaction process.
[0075] Figure 1 is one of the global transaction processing method flowcharts provided by the present application, as shown in Figure 1 A global transaction processing method provided by the present application, and a corresponding execution subject is a server, i.e., a TM Server, which comprises the following steps:
[0076] Step 101, based on a plurality of sub-transactions, determining a global transaction corresponding to the plurality of sub-transactions; wherein at least two sub-transactions in the plurality of sub-transactions are triggered by different service systems;
[0077] Step 102, based on the operation information of the plurality of sub-transactions received, determining a rollback log corresponding to the global transaction;
[0078] Step 103, according to the rollback log corresponding to the global transaction, executing global transaction control.
[0079] It should be noted that the execution subject of the above method can be an electronic device, a component in an electronic device, an integrated circuit or a chip. The electronic device can be a mobile electronic device or a non-mobile electronic device. Exemplarily, the mobile electronic device can be a mobile phone, a tablet computer, a notebook computer, a palm computer, a vehicle-mounted electronic device, a wearable device, an ultra-mobile personal computer (UMPC), a netbook or a personal digital assistant (PDA), etc., and the non-mobile electronic device can be a server, a network attached storage (NAS), a personal computer (PC), a television (TV), a teller machine or a self-service machine, etc., and the present application is not limited in this regard.
[0080] Specifically, since the application is suitable for maintaining data consistency of a distributed system, several prerequisites need to be met for applying the application: (1) at least two application systems need to be involved; (2) each application provides two interfaces of forward and reverse operations (for example, a transfer scenario needs to provide two interfaces of transfer and refund); (3) the forward operation and the reverse operation are independent of each other (allowing short-term data inconsistency, existing short-term data delay, but the data will eventually be consistent, meeting the Base theory).
[0081] It should be noted that, in the actual application of the application, the number of application systems that need to be synchronized (i.e., the number of sub-transactions in a global transaction) can be set according to actual conditions, and the application does not limit this.
[0082] The application is described by taking two application systems as an example. It is assumed that there are two systems A and B, the A system has an a operation, the B system has a b operation, the scene requires the a operation and the b operation to maintain data consistency, the a operation succeeds, and the b operation must also succeed, and if any one of the a operation and the b operation fails, a rollback operation is performed.
[0083] When a global transaction that needs to be processed is determined, in step 101, a global transaction corresponding to a plurality of sub-transactions is determined based on the plurality of sub-transactions; wherein at least two sub-transactions in the plurality of sub-transactions are triggered by different service systems.
[0084] It should be noted that the sub-transactions are not necessarily unique in the multi-operation system. For example, in a transfer scenario, the transfer business is a distributed application, and multiple users can perform transfer operations within the same time period. The number of sub-transactions that need to be processed is the same as the number of users. For the above plurality of sub-transactions, the TM Server provides a global transaction that manages the plurality of sub-transactions.
[0085] Here, the different service systems include a plurality of application systems in practice, and at least include two different application systems. In step 102, based on the operation information of the plurality of sub-transactions received, a rollback log corresponding to the global transaction is determined.
[0086] It can be understood that the plurality of sub-transactions triggered by different service systems perform corresponding operations to generate corresponding operation information, which is received by the TM Server to generate a rollback log of the global transaction. The rollback log records information and states related to the sub-transactions, and the sub-transactions can be quickly determined according to the analysis of the rollback log.
[0087] It should be noted that the storage format of the rollback log (e.g., in the form of a data form or an array) and the data type stored (e.g., unique identifier, start time, completion time, transaction type, and transaction status) can be adjusted according to the actual situation, and this invention does not limit this.
[0088] In step 103, global transaction control is performed based on the rollback log corresponding to the global transaction.
[0089] Understandably, the TM Server parses the rollback logs and determines the corresponding execution strategy based on the operation status of multiple sub-transactions. If the sub-transaction operation is successful, the rollback log is deleted directly. If the sub-transaction operation fails, an exception control command is sent to the TM Client, instructing the sub-transaction to perform a rollback operation.
[0090] The corresponding actions for sub-transaction operation exceptions can be set according to the actual situation, and the corresponding actions for different sub-transactions may be different and can be adjusted according to the actual situation. This invention does not limit this.
[0091] It should be noted that, in addition to the completion of all sub-transactions and the existence of sub-transaction operation exceptions, there is also a situation where not all sub-transactions are completed but there are no exceptions. In this case, based on the Base theory, short-term data inconsistency is allowed, and there is a brief data delay, but the data will eventually be consistent.
[0092] The global transaction processing method provided by this invention treats the global transaction and its corresponding sub-transactions as a complete unit, and combines rollback logs to manage and monitor the status of sub-transactions. The corresponding rollback logs are only deleted when it is determined that all sub-transactions have been completed, ensuring data consistency of sub-transactions. Furthermore, the status of sub-transactions is monitored only through the rollback transaction table, without locking local resources or affecting the normal processing of other transactions, thus effectively improving the processing efficiency of global transactions.
[0093] Optionally, according to the global transaction processing method provided by the present invention, before the step of determining the global transaction corresponding to the multiple sub-transactions based on multiple sub-transactions, the method further includes:
[0094] The system receives sub-transaction annotations from multiple sub-transactions. Each sub-transaction annotation includes the identifier of the sub-transaction and an operation annotation, wherein the operation annotation is either a forward operation annotation or a reverse operation annotation.
[0095] The step of determining the global transaction corresponding to the multiple sub-transactions includes:
[0096] Based on the sub-transaction annotations of the multiple sub-transactions, a global transaction corresponding to the multiple sub-transactions is determined, and the global transaction has a unique global transaction identifier. Specifically,Figure 3 This is a schematic diagram of the timing flow of the global transaction processing method provided by the present invention, as follows: Figure 3 As shown, system A and system B provide cross-application operation data scenarios. The method provided by this invention is a microservice application, in which the TM Client transaction manager client is embedded in the microservice application in the form of a jar package; the TMServer transaction manager server provides operations such as transaction registration and rollback, and is responsible for the management and control of global transactions.
[0097] Systems A and B provide two operations: forward and reverse. System A corresponds to... Figure 3 In steps (1) and (3), B corresponds to Figure 3 In steps (5) and (7), system A and system B provide at least four methods, corresponding to the four forward and reverse operations A1, A2, B1, and B2, respectively, corresponding to steps (2), (4), (6), and (8) in the figure.
[0098] Before determining whether the method provided by this invention is needed to manage data consistency between system A and system B, annotations need to be added to the multiple sub-transactions corresponding to the global transaction.
[0099] Based on the multiple sub-transactions corresponding to the global transaction, determine the forward operation interface corresponding to the sub-transaction. Figure 3 (A1, B1) and reverse operation interface ( Figure 3 (A2, B2); where the forward operation interface is used to execute sub-transaction commit operations (e.g., payment); the reverse operation interface is used to execute sub-transaction rollback operations (e.g., refund).
[0100] Add the positive operation annotation @Do to the positive operation interface. Figure 3 In steps (2) and (6), add the reverse operation annotation @UnDo to the reverse operation interface. The annotation includes a unique identifier for the sub-transaction.
[0101] It is understandable that the specific language used to implement this method can be set according to actual needs, and the specific method for adding annotations can be adjusted according to actual circumstances. Furthermore, the unique identifier of a sub-transaction is used to distinguish different sub-transactions, and the generation rule for the unique identifier of a sub-transaction can be adjusted according to actual circumstances. This invention does not impose any limitations on this.
[0102] Based on global transactions, determine the unique identifier of the global transaction ( Figure 3 Steps (9), (10), and (11) specifically include:
[0103] When the TM Client starts, it determines the annotations of the multiple sub-transactions corresponding to the global transaction.
[0104] The annotations of the sub-transactions are scanned, the forward and reverse annotations corresponding to the multiple sub-transactions are read, a global transaction JSON is generated, and submitted to the TM Server.
[0105] It is understood that the storage format and form of data can be adjusted according to the actual situation, and this invention does not limit this.
[0106] TM Server determines the unique identifier (TID) of a global transaction based on the global transaction JSON.
[0107] It is understood that the operations corresponding to sub-transactions include forward operations and reverse operations. To distinguish sub-transactions, both forward operation annotations and reverse operation annotations include a unique identifier (id) for the sub-transaction. The specific rules for generating the unique identifier and the form of the annotation can be adjusted according to the actual situation, and this invention does not limit this.
[0108] The global transaction processing method provided by this invention is simple to use and widely applicable through the addition of annotations. It is compatible with the microservice ecosystem, with all operations based on the microservice development model. It provides friendly support for the Spring ecosystem and Spring Boot framework. Transaction registration, commit, and rollback can all be implemented through HTTP REST interface calls. Unlike traditional transaction protocols, any microservice system can easily integrate and use the global transaction manager using only an HTTP (HyperText Transfer Protocol) client tool, achieving seamless compatibility with the microservice ecosystem. Global transaction management can be achieved by adding annotations without rewriting the program, effectively reducing development costs.
[0109] In addition, by treating the global transaction and its corresponding sub-transactions as a complete unit, and by reading the forward and reverse operation annotations corresponding to the multiple sub-transactions, a unique identifier for the global transaction is determined, ensuring high availability. It is understood that, preferably using a C / S architecture, TM Server supports single-node and multi-node cluster deployments, providing high-availability services, supporting database-based cluster modes, and exhibiting strong horizontal scalability.
[0110] In addition, the global transaction processing method provided by this invention can also be implemented directly on a server. The specific implementation method can be adjusted according to actual needs, and this invention does not limit it.
[0111] Optionally, according to the global transaction processing method provided by the present invention, determining the rollback log corresponding to the global transaction based on the received operation information of the plurality of sub-transactions specifically includes:
[0112] Receive operation information for each sub-transaction, including whether the operation was successful or not; wherein, the operation information for each sub-transaction is determined based on the operation annotation of that sub-transaction;
[0113] In response to the success or failure of each sub-transaction operation, the rollback log corresponding to the global transaction is determined according to the optimistic locking mechanism.
[0114] Specifically, the TM Server receives operation information about each sub-transaction from the TM Client. This operation information includes whether the sub-transaction operation was successful or failed, which is determined by the operation annotation of each sub-transaction. After responding, the TM Server marks and locks the sub-transaction operation according to the optimistic locking mechanism and records the data volume in the undo log.
[0115] It is understandable that optimistic locking assumes no concurrent data conflicts and only checks for data integrity violations during data updates (commit operations). It does not intentionally use the database's own locking mechanisms but relies on the data itself to ensure data correctness. The specific implementation method of the optimistic locking mechanism can be set according to the actual situation, and this invention does not limit it.
[0116] The global transaction processing method provided by this invention implements the 2PC algorithm "lock-free" through an optimistic locking mechanism, ensuring that local resources are not locked and local transactions can be committed freely, effectively improving the efficiency of global transaction processing. Furthermore, it enhances the stability and robustness of system transaction processing, improves availability, supports long transactions, and its timeout mechanism can support long transactions spanning days, months, and even years, without affecting the performance of individual microservices while transactions are locked.
[0117] Optionally, according to the global transaction processing method provided by the present invention, the step of performing global transaction control based on the rollback log corresponding to the global transaction specifically includes:
[0118] When the rollback log determines that the multiple sub-transaction operations were successful, the rollback log is deleted; or
[0119] When it is determined from the rollback log that there is an operation error among the multiple sub-transactions, an error control instruction is sent. The error control instruction is used to instruct the execution of control operations on the multiple sub-transactions.
[0120] Wherein, when it is determined from the rollback log that there is a sub-transaction with operational anomalies among the plurality of sub-transactions, the anomaly control instruction is sent. The anomaly control instruction is used to instruct the execution of control operations on the plurality of sub-transactions, including:
[0121] When the rollback log is parsed and the first sub-transaction with an operational anomaly is determined among the multiple sub-transactions, the reverse operation interface corresponding to the multiple sub-transactions is obtained, wherein the operational anomaly includes sub-transaction execution anomaly;
[0122] Based on the reverse operation interface corresponding to the multiple sub-transactions, the exception control instruction is sent, which is used to instruct the multiple sub-transactions to perform a rollback operation.
[0123] In response to the completion of the rollback of the multiple sub-transactions, the rollback log is deleted.
[0124] Specifically, Figure 3 In the process, steps (12)-(15) are a sub-transaction operation. After the A1 operation is successful, the transaction is automatically committed. The TM Client marks the sub-transaction as successful and records the effective time. Steps (16)-(19) are another sub-transaction operation. After the B1 operation is successful, the transaction is automatically committed. The TM Client marks the sub-transaction as successful and records the effective time.
[0125] The TM Client submits the data to the TM Server. If it is confirmed that all global transactions have been executed successfully (step (20)), the TM Server automatically confirms the completion of the global transactions and then deletes the corresponding rollback log (undo log).
[0126] At the same time, when processing global transactions, issues such as sub-transaction operations failing or exceptions may occur. Figure 3 The present invention will be explained using the example of an abnormal operation in the B1 module. Figure 4 This invention provides a schematic diagram of the global transaction exception rollback sequence, as shown below. Figure 4 As shown.
[0127] After the TM Client determines that the B1 operation is abnormal (step (16)), it automatically submits the abnormal information of the B1 operation to the TM Server (step (17)). The TM Server will parse the undo log, parse out the interface address of the A2 rollback operation (step (18)), and then call the reverse interface a2 corresponding to the sub-transaction (step (19)) to roll back the global transaction. After confirming that the global transaction rollback is complete, the undo log is deleted (step (20)).
[0128] It should be noted that, in this invention, the method for determining sub-transaction operation anomalies, and the settings for what constitutes an anomaly in a sub-transaction, can be adjusted according to actual circumstances, and this invention does not limit them.
[0129] The global transaction processing method provided by this invention treats a global transaction and its corresponding sub-transactions as a complete unit, and combines rollback logs to manage and monitor the status of sub-transactions. When it is determined that there is an operation anomaly in a sub-transaction, the reverse operation corresponding to the sub-transaction is determined and rolled back, and the rollback log is deleted to ensure data consistency when an operation anomaly occurs.
[0130] Optionally, according to the global transaction processing method provided by the present invention, the operation annotation includes timeout time and runtime exception; the rollback log includes sub-transaction start time;
[0131] The process of parsing the rollback log to determine the first sub-transaction that experienced an operational anomaly specifically includes:
[0132] The rollback log is parsed to obtain the sub-transaction annotation for each sub-transaction, and the timeout, start time, and operation annotation for each sub-transaction are determined based on the sub-transaction annotation.
[0133] Based on the operation annotation, timeout time, and start time of each sub-transaction, the sub-transaction that has run abnormally and timed out among the plurality of sub-transactions is identified as the first sub-transaction.
[0134] Specifically, when dealing with distributed applications, there may be situations where tasks are not processed but no exceptions occur. In this case, to avoid data accumulation and problems caused by timeout tasks, the time of sub-transactions can be managed by setting a timeout period.
[0135] When adding annotations, set the timeout in both forward and reverse operation annotations. Specifically, the `@Do` and `@UnDo` annotations include the following attributes: 1) `value` (or `name`): the sub-transaction name, uniquely identifying a sub-transaction operation; 2) `timeout`: the timeout period (the specific value can be set as needed, or an unlimited timeout can be set). Correspondingly, the rollback log records the sub-transaction start time.
[0136] The process of parsing the rollback log to determine the first sub-transaction that experienced an operational anomaly specifically includes:
[0137] The rollback log is parsed to obtain the sub-transaction annotation for each sub-transaction, and the timeout, start time, and operation annotation for each sub-transaction are determined based on the sub-transaction annotation.
[0138] Based on the operation annotation, timeout time, and start time of each sub-transaction, the sub-transaction that has run abnormally and timed out among the plurality of sub-transactions is identified as the first sub-transaction.
[0139] It is understood that in this invention, the timeout period can be the time point of timeout, or the longest duration for which a sub-transaction can continue. The specific setting method and the corresponding duration can be set according to the actual situation, and this invention does not limit them.
[0140] Furthermore, it is understandable that, in addition to setting timeouts to control the duration of sub-transactions, other methods can also be used such as... Figure 3 As shown, step (21) configures the TM Server to periodically scan the undo log table, clean up successfully completed transactions, and roll back timed-out transactions. Specific implementation methods include cleaning at fixed time intervals or setting fixed times for cleaning, etc. The specific implementation can be adjusted according to the actual situation, and this invention does not limit this.
[0141] The global transaction processing method provided by this invention treats the global transaction and its corresponding sub-transactions as a complete unit. It combines rollback logs to manage and monitor the state of sub-transactions and control their timing. When a sub-transaction times out, it determines that the sub-transaction operation is abnormal and rolls back the global transaction. This effectively avoids the excessive storage time and large data volume that can occur in lock-free 2PC distributed applications, thus reducing storage and processing burdens and saving computing resources.
[0142] Optionally, according to the global transaction processing method provided by the present invention, the operation annotation further includes a non-rollback exception;
[0143] When it is determined from the rollback log that there is an operational anomaly among the multiple sub-transactions, an anomaly control instruction is sent. The anomaly control instruction is used to instruct the execution of control operations on the multiple sub-transactions, specifically including:
[0144] Parse the rollback log to obtain the sub-transaction annotation for each sub-transaction;
[0145] When it is determined, based on the sub-transaction annotation, that there is a second sub-transaction among the multiple sub-transactions with an operation annotation of "no rollback exception", an exception control instruction is sent and the rollback log is deleted. The exception control instruction is used to indicate that no rollback operation is performed on the multiple sub-transactions.
[0146] Specifically, both forward and reverse operation annotations include the option to not roll back exceptions. For certain sub-transactions, you can specify the option to not roll back exceptions in the annotation. That is, set `noRollbackFor: noRollbackExceptions` to specify which exceptions will not roll back (this can be set as an array, defaulting to empty). It should be noted that the specific operations and number of no-rollback exceptions can be set according to the actual situation.
[0147] The system checks the completion status of sub-transactions. If the multiple sub-transactions are determined to have executed successfully, the rollback log is deleted. If an abnormal sub-transaction operation is determined to have occurred, the multiple sub-transactions are rolled back and the rollback log is deleted. Specifically, this includes:
[0148] Check the completion status of the sub-transaction to determine if there is an abnormal operation in the second sub-transaction.
[0149] Parse the rollback log and, based on the unique identifier of the second sub-transaction, read the corresponding non-rollback exception from the annotations of the second sub-transaction operations.
[0150] The abnormal operation of the current second sub-transaction is compared with the non-rollback exception of the read. If it is determined that the abnormal operation of the second sub-transaction is a non-rollback exception, then the global transaction is not rolled back. If it is determined that the abnormal operation of the second sub-transaction is not a non-rollback exception, then the global transaction is rolled back.
[0151] Understandably, when annotating, you can also annotate `rollbackFor: rollback exception` to specify which exceptions to roll back (this can be set as an array, for example, the default is `RuntimeException`).
[0152] You can choose to set either rollback exceptions or non-rollback exceptions, or you can set the same operation type for rollback exceptions for all sub-transactions in the global transaction, and set non-rollback exceptions for individual sub-transactions, leaving some operations unrestricted. The specific setting method can be adjusted according to actual needs, and this invention does not limit it.
[0153] The global transaction processing method provided by this invention treats a global transaction and its corresponding sub-transactions as a complete unit, and combines rollback logs to manage and monitor the status of sub-transactions. When it is determined that there is an operation exception in a sub-transaction, some abnormal operations are exempted according to the set non-rollback exception. This can address different abnormal operations for different sub-transactions, thereby improving the flexibility of global transaction processing.
[0154] Figure 5 This is the second flowchart of the global transaction processing method provided by the present invention, as follows: Figure 5 As shown, the present invention provides a global transaction processing method, the corresponding execution subject of which is the client, i.e., TM Client, including:
[0155] Step 201: Based on the received information of multiple sub-transactions, add annotations to each of the multiple sub-transactions;
[0156] Step 202: Based on the annotations of the multiple sub-transactions, send a registration request to the server. The registration request is used to request the determination of the global transaction corresponding to the multiple sub-transactions.
[0157] Step 203: Determine and submit the operation information of each of the multiple sub-transactions to the server to determine the rollback log corresponding to the global transaction, wherein the rollback log is generated based on the operation information of each sub-transaction.
[0158] It should be noted that the subject executing the above method can be an electronic device, a component within an electronic device, an integrated circuit, or a chip. The electronic device can be a mobile electronic device or a non-mobile electronic device. For example, a mobile electronic device can be a mobile phone, tablet computer, laptop computer, PDA, in-vehicle electronic device, wearable device, ultra-mobile personal computer (UMPC), netbook, or personal digital assistant (PDA), etc., while a non-mobile electronic device can be a server, network attached storage (NAS), personal computer (PC), television set (TV), ATM, or self-service machine, etc. This invention does not impose specific limitations.
[0159] Specifically, in step 201, annotations are added to the multiple sub-transactions based on the received information.
[0160] like Figure 3 As shown, system A and system B provide cross-application operation data scenarios. The method provided by this invention is a microservice application, in which the TM Client transaction manager client is embedded in the microservice application in the form of a jar package; the TMServer transaction manager server provides operations such as transaction registration and rollback, and is responsible for the management and control of global transactions.
[0161] Before determining whether the method provided by this invention is needed to manage data consistency between system A and system B, annotations need to be added to the multiple sub-transactions corresponding to the global transaction.
[0162] In step 202, based on the annotations of the multiple sub-transactions, a registration request is sent to the server. The registration request is used to request the determination of the global transaction corresponding to the multiple sub-transactions.
[0163] It should be noted that after the TM Client adds annotations to multiple sub-transactions, it sends a registration request to the TM Server. This allows the TM Server to determine the global transaction corresponding to the multiple sub-transactions. At least two of these sub-transactions are triggered by different service systems. In practice, these different service systems include multiple application systems, with at least two different application systems.
[0164] Since transactions are not necessarily unique across multiple operating systems, for example, in a money transfer scenario, the money transfer business is a distributed application, and multiple users can perform money transfer operations at the same time. The number of sub-transactions that need to be processed is the same as the number of users.
[0165] In step 203, the operation information of each of the multiple sub-transactions is determined and submitted to the server to determine the rollback log corresponding to the global transaction, wherein the rollback log is generated based on the operation information of each sub-transaction.
[0166] It is understandable that using rollback logs based on sub-transactions can be understood as marking different sub-transactions. The rollback log records information and status related to the sub-transactions, and the sub-transactions can be quickly identified by parsing the rollback logs.
[0167] It should be noted that the storage format of the rollback log (e.g., in the form of a data form or an array) and the data type stored (e.g., unique identifier, start time, completion time, transaction type, and transaction status) can be adjusted according to the actual situation, and this invention does not limit this.
[0168] The global transaction processing method provided by this invention treats the global transaction and its corresponding sub-transactions as a complete unit, and combines rollback logs to manage and monitor the status of sub-transactions. The corresponding rollback logs are only deleted when it is determined that all sub-transactions have been completed, ensuring data consistency of sub-transactions. Furthermore, the status of sub-transactions is monitored only through the rollback transaction table, without locking local resources or affecting the normal processing of other transactions, thus effectively improving the processing efficiency of global transactions.
[0169] Optionally, according to the global transaction processing method provided by the present invention, adding annotations to the multiple sub-transactions based on the received information of the multiple sub-transactions specifically includes:
[0170] Based on the information received from multiple sub-transactions, determine the forward operation interface and reverse operation interface corresponding to each sub-transaction in the multiple sub-transactions;
[0171] Add a forward operation annotation to the forward operation interface and a reverse operation annotation to the reverse operation interface; wherein the annotation includes a unique identifier for the sub-transaction.
[0172] The method further includes:
[0173] Receive the exception control command corresponding to the global transaction sent by the server;
[0174] According to the exception control instructions, the reverse operation interface of each sub-transaction is invoked to perform a rollback operation.
[0175] Specifically, such as Figure 3 As shown, systems A and B provide two operations: forward and reverse. System A corresponds to... Figure 3 In steps (1) and (3), B corresponds to Figure 3 In steps (5) and (7), system A and system B provide at least four methods, corresponding to the four forward and reverse operations A1, A2, B1, and B2, respectively, corresponding to steps (2), (4), (6), and (8) in the figure.
[0176] Before determining whether the method provided by this invention is needed to manage data consistency between system A and system B, annotations need to be added to the multiple sub-transactions corresponding to the global transaction.
[0177] Based on the multiple sub-transactions corresponding to the global transaction, determine the forward operation interface corresponding to the sub-transaction. Figure 3 (A1, B1) and reverse operation interface ( Figure 3 (A2, B2); where the forward operation interface is used to execute sub-transaction commit operations (e.g., payment); the reverse operation interface is used to execute sub-transaction rollback operations (e.g., refund).
[0178] Add the positive operation annotation @Do to the positive operation interface. Figure 3 In steps (2) and (6), add the reverse operation annotation @UnDo to the reverse operation interface. The annotation includes a unique identifier for the sub-transaction.
[0179] It is understandable that the specific language used to implement this method can be set according to actual needs, and the specific method for adding annotations can be adjusted according to actual circumstances. Furthermore, the unique identifier of a sub-transaction is used to distinguish different sub-transactions, and the generation rule for the unique identifier of a sub-transaction can be adjusted according to actual circumstances. This invention does not impose any limitations on this.
[0180] Based on global transactions, determine the unique identifier of the global transaction ( Figure 3 Steps (9), (10), and (11) specifically include:
[0181] When the TM Client starts, it determines the annotations of the multiple sub-transactions corresponding to the global transaction.
[0182] The annotations of the sub-transactions are scanned, the forward and reverse annotations corresponding to the multiple sub-transactions are read, a global transaction JSON is generated, and submitted to the TM Server.
[0183] It is understood that the storage format and form of data can be adjusted according to the actual situation, and this invention does not limit this.
[0184] TM Server determines the unique identifier (TID) of a global transaction based on the global transaction JSON.
[0185] It is understood that the operations corresponding to sub-transactions include forward operations and reverse operations. To distinguish sub-transactions, both forward operation annotations and reverse operation annotations include a unique identifier (id) for the sub-transaction. The specific rules for generating the unique identifier and the form of the annotation can be adjusted according to the actual situation, and this invention does not limit this.
[0186] like Figure 3 As shown, steps (12)-(15) are a sub-transaction operation. After the A1 operation is successful, the transaction is automatically committed. The TMClient marks the sub-transaction as successful and records the effective time. Steps (16)-(19) are another sub-transaction operation. After the B1 operation is successful, the transaction is automatically committed. The TM Client marks the sub-transaction as successful and records the effective time.
[0187] The TM Client submits the data to the TM Server. If it is confirmed that all global transactions have been executed successfully (step (20)), the TM Server automatically confirms the completion of the global transactions and then deletes the corresponding rollback log (undo log).
[0188] At the same time, when processing global transactions, issues such as sub-transaction operations failing or exceptions may occur. Figure 3 The present invention will be explained using the example of an abnormal operation in the B1 module. Figure 4 This invention provides a schematic diagram of the global transaction exception rollback sequence, as shown below. Figure 4 As shown:
[0189] After the TM Client determines that the B1 operation is abnormal (step (16)), it automatically submits the abnormal information of the B1 operation to the TM Server (step (17)). The TM Server will parse the undo log, parse out the interface address of the A2 rollback operation (step (18)), and then call the reverse interface a2 corresponding to the sub-transaction (step (19)) to roll back the global transaction. After confirming that the global transaction rollback is complete, the undo log is deleted (step (20)).
[0190] It should be noted that, in this invention, the method for determining sub-transaction operation anomalies, and the settings for what constitutes an anomaly in a sub-transaction, can be adjusted according to actual circumstances, and this invention does not limit them.
[0191] The global transaction processing method provided by this invention is simple to use and widely applicable through the addition of annotations. It is compatible with the microservice ecosystem, with all operations based on the microservice development model. It provides friendly support for the Spring ecosystem and Spring Boot framework. Transaction registration, commit, and rollback can all be implemented through HTTP REST interface calls. Unlike traditional transaction protocols, any microservice system can easily integrate and use the global transaction manager using only an HTTP (HyperText Transfer Protocol) client tool, achieving seamless compatibility with the microservice ecosystem. Global transaction management can be achieved by adding annotations, eliminating the need to rewrite programs and effectively reducing development costs. By treating the global transaction and its corresponding sub-transactions as a complete unit, and combining this with rollback logs, the status of sub-transactions is managed and monitored. When an operational anomaly is detected in a sub-transaction, the corresponding reverse operation is determined and rolled back, and the rollback log is deleted, ensuring data consistency in the event of an operational anomaly. Figure 6 This is a schematic diagram of the structure of the global transaction processing system provided by the present invention, as shown below. Figure 6 As shown, the present invention also provides a global transaction processing system, comprising: a client 61 and a server 62, wherein:
[0192] The client 61 is configured to add annotations to the multiple sub-transactions based on the received information of the multiple sub-transactions, wherein at least two of the multiple sub-transactions are triggered by different service systems; send a registration request to the server based on the annotations of the multiple sub-transactions; and determine and submit the operation information of each of the multiple sub-transactions to the server.
[0193] The server 62 is configured to receive the registration request, determine the global transaction corresponding to the plurality of sub-transactions, determine the rollback log corresponding to the global transaction based on the received operation information of the plurality of sub-transactions, and execute global transaction control according to the rollback log corresponding to the global transaction.
[0194] The global transaction processing system provided by this invention treats a global transaction and its corresponding sub-transactions as a complete unit, and combines rollback logs to manage and monitor the status of sub-transactions. The corresponding rollback logs are only deleted when it is determined that all sub-transactions have been completed, ensuring data consistency of sub-transactions. Furthermore, the status of sub-transactions is monitored only through the rollback transaction table, without locking local resources or affecting the normal processing of other transactions, thus effectively improving the processing efficiency of global transactions.
[0195] Optionally, according to the global transaction processing system provided by the present invention, the client 61 includes a first processing module 611, a second processing module 612, and a third processing module 613, wherein:
[0196] The first processing module 611 is used to add annotations to the multiple sub-transactions according to the information of the multiple sub-transactions received; the second processing module 612 is used to send a registration request to the server based on the annotations of the multiple sub-transactions, the registration request being used to request the determination of the global transaction corresponding to the multiple sub-transactions; the third processing module 613 is used to determine and submit the operation information of each of the multiple sub-transactions to the server respectively, so as to determine the rollback log corresponding to the global transaction, wherein the rollback log is generated based on the operation information of each sub-transaction.
[0197] The global transaction processing system provided by this invention treats a global transaction and its corresponding sub-transactions as a complete unit, and combines rollback logs to manage and monitor the status of sub-transactions. The corresponding rollback logs are only deleted when it is determined that all sub-transactions have been completed, ensuring data consistency of sub-transactions. Furthermore, the status of sub-transactions is monitored only through the rollback transaction table, without locking local resources or affecting the normal processing of other transactions, thus effectively improving the processing efficiency of global transactions.
[0198] Optionally, according to the global transaction processing system provided by the present invention, the first processing module 611 is specifically configured to determine the forward operation interface and the reverse operation interface corresponding to each of the multiple sub-transactions based on the information of the received multiple sub-transactions; add a forward operation annotation to the forward operation interface and add a reverse operation annotation to the reverse operation interface; wherein, the annotation includes a unique identifier of the sub-transaction.
[0199] The global transaction processing system provided by this invention is simple to use and widely applicable through the addition of annotations. It is compatible with the microservice ecosystem, with all operations based on the microservice development model. It provides friendly support for the Spring ecosystem and Spring Boot framework. Transaction registration, commit, and rollback can all be implemented through HTTP REST interface calls. Unlike traditional transaction protocols, any microservice system can easily integrate and use the global transaction manager using only an HTTP (HyperText Transfer Protocol) client tool, achieving seamless compatibility with the microservice ecosystem. Global transaction management can be achieved by adding annotations without rewriting the program, effectively reducing development costs.
[0200] Optionally, according to the global transaction processing system provided by the present invention, the second processing module 612 is specifically used to receive the exception control instruction corresponding to the global transaction sent by the server; and to call the reverse operation interface of each sub-transaction to perform a rollback operation according to the exception control instruction.
[0201] The global transaction processing system provided by this invention manages and monitors the status of sub-transactions by treating global transactions and their corresponding sub-transactions as a complete unit and combining them with rollback logs. When it is determined that there is an operation anomaly in a sub-transaction, the system determines the reverse operation corresponding to the sub-transaction, rolls it back, and deletes the rollback log, thus ensuring data consistency when an operation anomaly occurs.
[0202] Optionally, according to the global transaction processing system provided by the present invention, the server 62 includes a fourth processing module 621, a fifth processing module 622, and a sixth processing module 623, wherein:
[0203] The fourth processing module 621 is used to determine a global transaction corresponding to the multiple sub-transactions based on the multiple sub-transactions; wherein at least two of the multiple sub-transactions are triggered by different service systems; the fifth processing module 622 is used to determine the rollback log corresponding to the global transaction based on the received operation information of the multiple sub-transactions; the sixth processing module 623 performs global transaction control according to the rollback log corresponding to the global transaction.
[0204] The global transaction processing system provided by this invention treats a global transaction and its corresponding sub-transactions as a complete unit, and combines rollback logs to manage and monitor the status of sub-transactions. The corresponding rollback logs are only deleted when it is determined that all sub-transactions have been completed, ensuring data consistency of sub-transactions. Furthermore, the status of sub-transactions is monitored only through the rollback transaction table, without locking local resources or affecting the normal processing of other transactions, thus effectively improving the processing efficiency of global transactions.
[0205] Optionally, according to the global transaction processing system provided by the present invention, the server 62 further includes a seventh processing module 624, which is used to receive sub-transaction annotations of multiple sub-transactions respectively. Each sub-transaction annotation includes the identifier of the sub-transaction and an operation annotation, wherein the operation annotation is a forward operation annotation or a reverse operation annotation. The step of determining the global transaction corresponding to the multiple sub-transactions includes: determining the global transaction corresponding to the multiple sub-transactions according to the sub-transaction annotations of the multiple sub-transactions, wherein the global transaction has a unique global transaction identifier. According to the global transaction processing method provided by the present invention, the step of determining the rollback log corresponding to the global transaction based on the received operation information of the multiple sub-transactions specifically includes: receiving operation information of each sub-transaction, wherein the operation information includes operation success or operation exception; wherein the operation information of each sub-transaction is determined according to the operation annotation of the sub-transaction; and in response to each sub-transaction operation success or operation exception, determining the rollback log corresponding to the global transaction according to an optimistic locking mechanism.
[0206] The global transaction processing system provided by this invention is simple to use and widely applicable through the addition of annotations. It is compatible with the microservice ecosystem, with all operations based on the microservice development model. It provides friendly support for the Spring ecosystem and Spring Boot framework. Transaction registration, commit, and rollback can all be implemented through HTTP REST interface calls. Unlike traditional transaction protocols, any microservice system can easily integrate and use the global transaction manager using only an HTTP (HyperText Transfer Protocol) client tool, achieving seamless compatibility with the microservice ecosystem. Global transaction management can be achieved by adding annotations without rewriting the program, effectively reducing development costs.
[0207] Optionally, in the global transaction processing system provided by the present invention, the fifth processing module 622 is specifically used to receive operation information of each sub-transaction, the operation information including operation success or operation exception; wherein, the operation information of each sub-transaction is determined according to the operation annotation of the sub-transaction; in response to the operation success or operation exception of each sub-transaction, the rollback log corresponding to the global transaction is determined according to the optimistic locking mechanism.
[0208] The global transaction processing system provided by this invention implements the 2PC algorithm "lock-free" through an optimistic locking mechanism, ensuring that local resources are not locked and local transactions can be committed freely, effectively improving the efficiency of global transaction processing. Furthermore, it enhances the stability and robustness of system transaction processing, improves availability, supports long transactions, and its timeout mechanism can support long transactions spanning days, months, and even years, without affecting the performance of individual microservices while transactions are locked.
[0209] Optionally, according to the global transaction processing system provided by the present invention, the sixth processing module 623 is specifically used to delete the rollback log when it is determined from the rollback log that the multiple sub-transactions have successfully completed their operations; or to send an exception control instruction when it is determined from the rollback log that there is an operationally abnormal sub-transaction among the multiple sub-transactions, the exception control instruction being used to instruct the execution of control operations on the multiple sub-transactions. Specifically, sending the exception control instruction when it is determined from the rollback log that there is an operationally abnormal sub-transaction among the multiple sub-transactions, the exception control instruction being used to instruct the execution of control operations on the multiple sub-transactions, includes: parsing the rollback log; when it is determined that there is a first operationally abnormal sub-transaction among the multiple sub-transactions, obtaining the reverse operation interface corresponding to the multiple sub-transactions, wherein the operational abnormality includes sub-transaction execution abnormality; sending the exception control instruction based on the reverse operation interface corresponding to the multiple sub-transactions, the exception control instruction being used to instruct the execution of rollback operations on the multiple sub-transactions; and deleting the rollback log in response to the completion of the rollback of the multiple sub-transactions.
[0210] The global transaction processing system provided by this invention manages and monitors the status of sub-transactions by treating global transactions and their corresponding sub-transactions as a complete unit and combining them with rollback logs. When it is determined that there is an operation anomaly in a sub-transaction, the system determines the reverse operation corresponding to the sub-transaction, rolls it back, and deletes the rollback log, thus ensuring data consistency when an operation anomaly occurs.
[0211] Optionally, in the global transaction processing system provided by the present invention, the operation annotation includes timeout time and runtime exception; the rollback log includes sub-transaction start time; the sixth processing module 623 is further specifically used to parse the rollback log, obtain the sub-transaction annotation of each sub-transaction, and determine the timeout time, sub-transaction start time and operation annotation of each sub-transaction based on the sub-transaction annotation; according to the operation annotation, timeout time and sub-transaction start time of each sub-transaction, the sub-transaction that has runtime exception and timeout among the plurality of sub-transactions is determined as the first sub-transaction.
[0212] The global transaction processing system provided by this invention treats a global transaction and its corresponding sub-transactions as a complete unit. Combined with rollback logs, it manages and monitors the status of sub-transactions and controls their timing. When a sub-transaction times out, it determines that the sub-transaction operation is abnormal and rolls back the global transaction. This effectively avoids the excessive storage time and large data volume that can occur in lock-free 2PC distributed applications, thus reducing storage and processing burdens and saving computing resources.
[0213] Optionally, according to the global transaction processing system provided by the present invention, the operation annotation further includes a non-rollback exception, and the sixth processing module 623 is further specifically used to parse the rollback log, obtain the sub-transaction annotation of each sub-transaction; when it is determined based on the sub-transaction annotation that there is a second sub-transaction among the multiple sub-transactions with an operation annotation of non-rollback exception, an exception control instruction is sent and the rollback log is deleted, the exception control instruction is used to indicate that no rollback operation is performed on the multiple sub-transactions.
[0214] The global transaction processing system provided by this invention treats a global transaction and its corresponding sub-transactions as a complete unit, and combines rollback logs to manage and monitor the status of sub-transactions. When it is determined that there is an operational anomaly in a sub-transaction, some abnormal operations are exempted according to the set non-rollback exception. This can address different abnormal operations for different sub-transactions, thereby improving the flexibility of global transaction processing.
[0215] Figure 7 This is a schematic diagram of the physical structure of an electronic device provided by the present invention, such as... Figure 7 As shown, the electronic device may include a processor 710, a communication interface 711, a memory 712, and a bus 713, wherein the processor 710, the communication interface 711, and the memory 712 communicate with each other via the bus 713. The processor 710 can invoke logical instructions in the memory 712 to execute the following methods: determining a global transaction corresponding to multiple sub-transactions; wherein at least two of the multiple sub-transactions are triggered by different service systems; determining the rollback log corresponding to the global transaction based on the received operation information of the multiple sub-transactions; and performing global transaction control according to the rollback log corresponding to the global transaction.
[0216] Furthermore, the logical instructions in the aforementioned memory can be implemented as software functional units and sold or used as independent products, and can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer power supply (which may be a personal computer, server, or network power supply, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0217] Furthermore, this invention discloses a computer program product, which includes a computer program stored on a non-transitory computer-readable storage medium. The computer program includes program instructions, and when the program instructions are executed by a computer, the computer can execute the global transaction processing method provided in the above-described method embodiments, for example including: determining a global transaction corresponding to multiple sub-transactions based on multiple sub-transactions; wherein at least two of the multiple sub-transactions are triggered by different service systems; determining a rollback log corresponding to the global transaction based on the received operation information of the multiple sub-transactions; and performing global transaction control according to the rollback log corresponding to the global transaction.
[0218] On the other hand, the present invention also provides a non-transitory computer-readable storage medium storing a computer program thereon. When executed by a processor, the computer program implements the global transaction processing method provided in the above embodiments, including, for example,: determining a global transaction corresponding to multiple sub-transactions based on multiple sub-transactions; wherein at least two of the multiple sub-transactions are triggered by different service systems; determining a rollback log corresponding to the global transaction based on the received operation information of the multiple sub-transactions; and performing global transaction control according to the rollback log corresponding to the global transaction.
[0219] The system embodiments described above are merely illustrative. The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the modules can be selected to achieve the purpose of this embodiment according to actual needs. Those skilled in the art can understand and implement this without any creative effort.
[0220] Through the above description of the embodiments, those skilled in the art can clearly understand that each embodiment can be implemented by means of software plus necessary general-purpose hardware platforms, and of course, it can also be implemented by hardware. Based on this understanding, the above technical solutions, in essence or the part that contributes to the prior art, can be embodied in the form of a software product. This computer software product can be stored in a computer-readable storage medium, such as ROM / RAM, magnetic disk, optical disk, etc., including several instructions to cause a computer power supply (which may be a personal computer, server, or network power supply, etc.) to execute the methods described in various embodiments or some parts of the embodiments.
[0221] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention, and not to limit them; although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features; and these modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention.
Claims
1. A method of global transaction processing, the method comprising: The method comprises the following steps: determining a global transaction corresponding to a plurality of sub-transactions based on the plurality of sub-transactions, wherein at least two sub-transactions in the plurality of sub-transactions are triggered by different service systems; determining a rollback log corresponding to the global transaction based on received operation information of the plurality of sub-transactions; performing global transaction control according to the rollback log corresponding to the global transaction; Before the step of determining the global transaction corresponding to the plurality of sub-transactions, the method further comprises the following steps: receiving sub-transaction annotations of the plurality of sub-transactions respectively, wherein each sub-transaction annotation of each sub-transaction comprises an identifier of the sub-transaction and an operation annotation, and the operation annotation is a forward operation annotation or a reverse operation annotation; wherein the step of determining the global transaction corresponding to the plurality of sub-transactions based on the plurality of sub-transactions comprises the following steps: determining the global transaction corresponding to the plurality of sub-transactions according to the sub-transaction annotations of the plurality of sub-transactions, wherein the global transaction has a global transaction unique identifier; the step of determining the rollback log corresponding to the global transaction based on the received operation information of the plurality of sub-transactions comprises the following steps: receiving operation information of each sub-transaction, wherein the operation information comprises operation success or operation exception, and the operation information of each sub-transaction is determined according to the operation annotation of the sub-transaction; determining the rollback log corresponding to the global transaction according to an optimistic locking mechanism in response to operation success or operation exception of each sub-transaction; the step of performing global transaction control according to the rollback log corresponding to the global transaction comprises the following steps: deleting the rollback log when it is determined that the plurality of sub-transactions are successful according to the rollback log, or sending an exception control instruction for indicating performing control operation on the plurality of sub-transactions when it is determined that there is a sub-transaction with operation exception in the plurality of sub-transactions according to the rollback log; when it is determined that there is a sub-transaction with operation exception in the plurality of sub-transactions according to the rollback log, sending the exception control instruction for indicating performing control operation on the plurality of sub-transactions, comprising the following steps: when it is determined that there is a first sub-transaction with operation exception in the plurality of sub-transactions by analyzing the rollback log, acquiring reverse operation interfaces corresponding to the plurality of sub-transactions, wherein the operation exception comprises sub-transaction running exception; sending the exception control instruction for indicating performing rollback operation on the plurality of sub-transactions based on the reverse operation interfaces corresponding to the plurality of sub-transactions; deleting the rollback log in response to completion of rollback of the plurality of sub-transactions; the operation annotation comprises a timeout time and a running time exception, and the rollback log comprises a sub-transaction start time; the step of analyzing the rollback log to determine the first sub-transaction with operation exception comprises the following steps: analyzing the rollback log to acquire the sub-transaction annotation of each sub-transaction, and determining the timeout time, the sub-transaction start time and the operation annotation of each sub-transaction based on the sub-transaction annotation; determining a sub-transaction with running time exception and timeout in the plurality of sub-transactions as the first sub-transaction according to the operation annotation, the timeout time and the sub-transaction start time of each sub-transaction.
2. The method of claim 1, wherein, the operation annotation further comprises a non-rollback exception. The method comprises the following steps: parsing the rollback log, obtaining the sub-transaction annotation of each sub-transaction; when it is determined that there is a second sub-transaction with an operation annotation that is not rollback exception in the plurality of sub-transactions based on the sub-transaction annotation, sending an exception control instruction and deleting the rollback log, wherein the exception control instruction is used to instruct not to perform a rollback operation on the plurality of sub-transactions.
3. A method of global transaction processing, the method comprising: The method comprises the following steps: adding an annotation to each of the plurality of sub-transactions according to the received information of the plurality of sub-transactions; sending a registration request to the server based on the annotations of the plurality of sub-transactions, wherein the registration request is used to request to determine a global transaction corresponding to the plurality of sub-transactions; determining and submitting operation information of each of the plurality of sub-transactions to the server respectively to determine a rollback log corresponding to the global transaction, wherein the rollback log is generated according to the operation information of each sub-transaction; The method comprises the following steps: determining a forward operation interface and a reverse operation interface corresponding to each of the plurality of sub-transactions according to the received information of the plurality of sub-transactions; adding a forward operation annotation to the forward operation interface and a reverse operation annotation to the reverse operation interface; wherein the annotation comprises a unique sub-transaction identifier; The method further comprises the following steps: receiving an exception control instruction corresponding to a global transaction sent by the server; calling a reverse operation interface of each sub-transaction to perform a rollback operation according to the exception control instruction; when it is determined that there is a sub-transaction with an operation exception in the plurality of sub-transactions according to the rollback log, sending the exception control instruction, wherein the exception control instruction is used to instruct to perform a control operation on the plurality of sub-transactions, comprising: parsing the rollback log, and when it is determined that there is a first sub-transaction with an operation exception in the plurality of sub-transactions, obtaining a reverse operation interface corresponding to the plurality of sub-transactions, wherein the operation exception comprises a sub-transaction running exception; sending the exception control instruction based on the reverse operation interface corresponding to the plurality of sub-transactions, wherein the exception control instruction is used to instruct to perform a rollback operation on the plurality of sub-transactions; deleting the rollback log in response to the completion of the rollback of the plurality of sub-transactions; The operation annotation comprises a timeout time and a runtime exception; the rollback log comprises a sub-transaction start time; The method comprises the following steps: parsing the rollback log, obtaining the sub-transaction annotation of each sub-transaction, and determining the timeout time, the sub-transaction start time and the operation annotation of each sub-transaction based on the sub-transaction annotation; determining a sub-transaction with a runtime exception and a timeout as the first sub-transaction according to the operation annotation, the timeout time and the sub-transaction start time of each sub-transaction.
4. A global transaction processing system, characterized by The method comprises the following steps: a client and a server, wherein: The client is used for adding annotations to the multiple sub-transactions respectively according to the received information of the multiple sub-transactions; determining the forward operation interface and the reverse operation interface corresponding to each sub-transaction in the multiple sub-transactions according to the received information of the multiple sub-transactions; adding forward operation annotations to the forward operation interface and adding reverse operation annotations to the reverse operation interface; wherein the annotations include a sub-transaction unique identifier; wherein at least two sub-transactions in the multiple sub-transactions are triggered by different service systems; sending a registration request to a server based on the annotations of the multiple sub-transactions; determining and submitting operation information of each sub-transaction in the multiple sub-transactions to the server respectively; receiving an exception control instruction corresponding to a global transaction sent by the server; and calling the reverse operation interface of each sub-transaction to perform a rollback operation according to the exception control instruction; The server is used for receiving the registration request, determining a global transaction corresponding to the multiple sub-transactions; determining a rollback log corresponding to the global transaction based on the received operation information of the multiple sub-transactions; and performing global transaction control according to the rollback log corresponding to the global transaction; before the step of determining the global transaction corresponding to the multiple sub-transactions, the server further includes: receiving sub-transaction annotations of the multiple sub-transactions respectively, wherein the sub-transaction annotations of each sub-transaction include an identifier and operation annotations of the sub-transaction, and the operation annotations are forward operation annotations or reverse operation annotations; The server is used for receiving the registration request, determining a global transaction corresponding to the multiple sub-transactions; determining a rollback log corresponding to the global transaction based on the received operation information of the multiple sub-transactions; and performing global transaction control according to the rollback log corresponding to the global transaction; before the step of determining the global transaction corresponding to the multiple sub-transactions, the server further includes: receiving sub-transaction annotations of the multiple sub-transactions respectively, wherein the sub-transaction annotations of each sub-transaction include an identifier and operation annotations of the sub-transaction, and the operation annotations are forward operation annotations or reverse operation annotations; The server is used for receiving the registration request, determining a global transaction corresponding to the multiple sub-transactions; determining a rollback log corresponding to the global transaction based on the received operation information of the multiple sub-transactions; and performing global transaction control according to the rollback log corresponding to the global transaction; before the step of determining the global transaction corresponding to the multiple sub-transactions, the server further includes: receiving sub-transaction annotations of the multiple sub-transactions respectively, wherein the sub-transaction annotations of each sub-transaction include an identifier and operation annotations of the sub-transaction, and the operation annotations are forward operation annotations or reverse operation annotations; The server is used for receiving the registration request, determining a global transaction corresponding to the multiple sub-transactions; determining a rollback log corresponding to the global transaction based on the received operation information of the multiple sub-transactions; and performing global transaction control according to the rollback log corresponding to the global transaction; before the step of determining the global transaction corresponding to the multiple sub-transactions, the server further includes: receiving sub-transaction annotations of the multiple sub-transactions respectively, wherein the sub-transaction annotations of each sub-transaction include an identifier and operation annotations of the sub-transaction, and the operation annotations are forward operation annotations or reverse operation annotations; The server is used for receiving the registration request, determining a global transaction corresponding to the multiple sub-transactions; determining a rollback log corresponding to the global transaction based on the received operation information of the multiple sub-transactions; and performing global transaction control according to the rollback log corresponding to the global transaction; before the step of determining the global transaction corresponding to the multiple sub-transactions, the server further includes: receiving sub-transaction annotations of the multiple sub-transactions respectively, wherein the sub-transaction annotations of each sub-transaction include an identifier and operation annotations of the sub-transaction, and the operation annotations are forward operation annotations or reverse operation annotations; The server is used for receiving the registration request, determining a global transaction corresponding to the multiple sub-transactions; determining a rollback log corresponding to the global transaction based on the received operation information of the multiple sub-transactions; and performing global transaction control according to the rollback log corresponding to the global transaction; before the step of determining the global transaction corresponding to the multiple sub-transactions, the server further includes: receiving sub-transaction annotations of the multiple sub-transactions respectively, wherein the sub-transaction annotations of each sub-transaction include an identifier and operation annotations of the sub-transaction, and the operation annotations are forward operation annotations or reverse operation annotations; The abnormal control instruction is sent based on the reverse operation interfaces corresponding to the plurality of sub-transactions, and the abnormal control instruction is used to instruct to perform a rollback operation on the plurality of sub-transactions; In response to the completion of the rollback of the plurality of sub-transactions, the rollback log is deleted; The operation annotation includes a timeout time and a runtime exception; and the rollback log includes a sub-transaction start time; The operation annotation includes a timeout time and a runtime exception; and the rollback log includes a sub-transaction start time; The rollback log is parsed to determine a first sub-transaction with an operation exception, and specifically includes: The rollback log is parsed to obtain the sub-transaction annotation of each sub-transaction, and the timeout time, the sub-transaction start time and the operation annotation of each sub-transaction are determined based on the sub-transaction annotation; According to the operation annotation, the timeout time and the sub-transaction start time of each sub-transaction, a sub-transaction with a runtime exception and having timed out in the plurality of sub-transactions is determined as the first sub-transaction.
Citation Information
Patent Citations
Transaction control method, system and device for data consistency and storage medium
CN112559140A