Distributed transaction execution method and device, electronic equipment and storage medium
By generating and verifying transaction verification data to determine the execution strategy, the problem of disordered execution order of distributed transactions is solved, and the normal execution of distributed transactions and consistency of business data is achieved.
Patent Information
- Application Number
- CN202510226100.4
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-02-27
- Publication Date
- 2025-06-13
AI Technical Summary
The problem of disorganized execution order of distributed transactions leads to execution exceptions, rollback exceptions or data inconsistencies, making it difficult to ensure the consistency of business data between multiple distributed transaction services or systems.
By obtaining the current distributed transaction and executed transaction records, determining the target operation type based on the operation type, and generating transaction verification data based on the target operation type and executed transaction record, verifying the execution status of the current distributed transaction through the transaction verification data, obtaining the verification result, determining the execution strategy based on the operation type and verification result and executing the current distributed transaction.
Distributed transaction exceptions caused by disordered execution order are avoided, and normal execution of transactions and consistency of business data is ensured.
Smart Images

Figure CN120144238A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular, to a method, apparatus, electronic device, and storage medium for executing distributed transactions. Background Art
[0002] Distributed transactions originally referred to database transaction problems involving multiple resources. With the rapid development of the Internet, especially after the popularity of the microservices architecture, distributed transactions mostly refer to a business scenario that requires orchestrating many independently deployed services or external systems to complete the execution of transactions.
[0003] Currently, solutions for distributed transactions include: Two-Phase-Commit (2PC), Try-Confirm-Cancel (TCC) staged commit, reliable message queues, etc. Since TCC is completely independent of the underlying database and can achieve cross-database and cross-application resource management, it has high performance potential and is a high-performance distributed transaction solution. It is more widely applied to the microservices architecture to implement distributed transactions under various complex business scenarios.
[0004] However, problems such as disordered execution order of distributed transactions may exist in the services or systems of distributed transactions, resulting in execution exceptions, rollback exceptions, or data inconsistencies during the transaction execution process, making it difficult to ensure the consistency of business data among multiple distributed transaction services or systems. Summary of the Invention
[0005] In view of the above-mentioned disadvantages of the prior art, the present application provides a method, apparatus, electronic device, and storage medium for executing distributed transactions to solve the above technical problems.
[0006] According to one aspect of the embodiments of the present application, a method for executing a distributed transaction is provided, including: obtaining a current distributed transaction and an executed transaction record; the distributed transaction includes a transaction between multiple databases or multiple application programs in a distributed system; determining a target operation type based on the operation type of the current distributed transaction; generating transaction verification data according to the target operation type and the executed transaction record; verifying the execution status of the current distributed transaction through the transaction verification data to obtain a verification result; the verification result includes not executed and executed; determining an execution strategy for the current distributed transaction according to the operation type and the verification result, and executing the current distributed transaction according to the execution strategy.
[0007] In one embodiment of the present application, the process of determining the target operation type based on the operation type of the current distributed transaction includes: if the operation type is a resource reservation operation or a cancellation operation, then taking the resource reservation operation as the target operation type; if the operation type is a confirmation operation, then taking the confirmation operation as the target operation type; wherein, if the resource reservation operation is successfully executed, then continue to execute the confirmation operation; if the resource reservation operation fails to be executed, then continue to execute the cancellation operation; if the confirmation operation is successfully executed, then continue to execute the resource reservation operation; if the confirmation operation fails to be executed, then continue to execute the cancellation operation.
[0008] In one embodiment of the present application, the process of generating transaction verification data according to the target operation type and the executed transaction record includes: combining the executed transaction record and the target operation type to obtain combined data; the executed transaction record at least includes: a globally unique identifier and a business data identifier; converting the combined data into data in a preset format, and taking the data in the preset format as the transaction verification data.
[0009] In one embodiment of the present application, the process of determining the execution policy for the current distributed transaction according to the operation type and the verification result includes: if the operation type is a cancellation operation and the verification result is not executed, then taking executing the transaction verification data first and then executing the current distributed transaction, or taking a null rollback operation, as the execution policy; if the operation type is the cancellation operation and the verification result is executed, then taking executing the current distributed transaction, as the execution policy; if the operation type is a resource reservation operation or a confirmation operation, and the verification result is not executed, then taking executing the current distributed transaction, as the execution policy; if the operation type is the resource reservation operation or the confirmation operation, and the verification result is executed, then taking executing the next transaction request of the current distributed transaction, as the execution policy.
[0010] In one embodiment of the present application, if the operation type is the cancellation operation, and after executing the current distributed transaction, the method further includes: generating a business data cancellation request in response to the current distributed transaction; performing a cancellation operation on the business data according to the business data cancellation request to obtain an operation result; if the operation result is cancellation failure, then re-attempt the cancellation operation; if the operation result is cancellation failure within a preset number of operation attempts, then issue an exception warning in a preset warning manner; if the operation result is cancellation success, or, the operation result is cancellation success within the preset number of operation attempts, then synchronize the operation result to a first target system, the first target system including a system determined in advance or in real time.
[0011] In an embodiment of the present application, when the operation type is the cancellation operation and the function of the current distributed transaction is to delete the target transaction, the method further includes: executing the current distributed transaction and synchronizing the message of successful execution to a second target system, so that the second target system deletes the target transaction according to the message of successful execution until the deletion operation of the second business system is successful; the second target transaction includes a transaction request determined in advance or in real time.
[0012] In an embodiment of the present application, the current distributed transaction is locked according to a preset locking time; the locking method includes a distributed lock method; if the current distributed transaction is successfully executed within the preset locking time, the current distributed transaction is unlocked; if the current distributed transaction fails to be executed within the preset locking time, after an alarm message is sent, the current distributed transaction is unlocked.
[0013] According to one aspect of the embodiments of the present application, a distributed transaction execution device is provided, including: a data acquisition module, configured to obtain a current distributed transaction and an executed transaction record; the distributed transaction includes a transaction between multiple databases or multiple application programs in a distributed system; a data generation module, configured to determine a target operation type based on the operation type of the current distributed transaction; and generate transaction verification data according to the target operation type and the executed transaction record; a transaction verification module, configured to verify the execution situation of the current distributed transaction through the transaction verification data to obtain a verification result; the verification result includes not executed and executed; a transaction execution module, configured to determine an execution policy for the current distributed transaction according to the operation type and the verification result, and execute the current distributed transaction according to the execution policy.
[0014] According to one aspect of the embodiments of the present application, an electronic device is provided, the electronic device includes: one or more processors; a storage device, configured to store one or more programs, when the one or more programs are executed by the one or more processors, the electronic device is caused to implement the distributed transaction execution method as described above.
[0015] According to one aspect of the embodiments of the present application, a computer-readable storage medium is provided, on which a computer program is stored, when the computer program is executed by a processor of a computer, the computer is caused to execute the distributed transaction execution method as described above.
[0016] Advantages of the present invention: By obtaining the current distributed transaction and the executed transaction records, determining the target operation type based on the operation type of the current distributed transaction, generating transaction verification data according to the target operation type and the executed transaction records, verifying the execution status of the current distributed transaction through the transaction verification data to obtain a verification result, determining the execution strategy for the current distributed transaction according to the operation type and the verification result, and executing the current distributed transaction according to the execution strategy. In the above process, before executing the current distributed transaction, by verifying the execution status of the current distributed transaction with the transaction verification data and determining the execution strategy for the current distributed transaction according to the verification result, it is possible to avoid problems such as abnormal execution of the distributed transaction, transaction suspension, rollback exception, or data inconsistency caused by the disorder of the execution order of the current distributed transaction, thereby ensuring the normal execution of the distributed transaction and further ensuring the consistency of business data among multiple distributed transaction services or systems.
[0017] It should be understood that the above general description and the following detailed description are only exemplary and explanatory, and do not limit this application. BRIEF DESCRIPTION OF THE DRAWINGS
[0018] The accompanying drawings herein are incorporated into the specification and form a part of this specification, showing embodiments consistent with this application and used together with the specification to explain the principles of this application. Obviously, the accompanying drawings in the following description are only some embodiments of this application, and those of ordinary skill in the art can obtain other drawings based on these drawings without creative efforts. In the drawings:
[0019] Figure 1 is a schematic diagram of an exemplary system architecture shown in an exemplary embodiment of this application;
[0020] Figure 2 is a flowchart of a distributed transaction execution method shown in an exemplary embodiment of this application;
[0021] Figure 3 is a flowchart of distributed transaction execution between a data governance platform and a distributed scheduling system when creating a quality monitoring task shown in an exemplary embodiment of this application;
[0022] Figure 4 is a flowchart of distributed transaction execution between a data governance platform and a distributed scheduling system when deleting a quality monitoring task shown in an exemplary embodiment of this application;
[0023] Figure 5 is a flowchart of a retry mechanism shown in an exemplary embodiment of this application;
[0024] Figure 6It is a flowchart for locking the current distributed transaction shown in an exemplary embodiment of the present application;
[0025] Figure 7 It shows a block diagram of a distributed transaction execution device suitable for implementing the embodiments of the present application;
[0026] Figure 8 It shows a schematic structural diagram of a computer system of an electronic device suitable for implementing the embodiments of the present application. Detailed implementation manners
[0027] Here, the exemplary embodiments will be described in detail, and the examples are shown in the drawings. When the following description refers to the drawings, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. The implementation manners described in the following exemplary embodiments do not represent all implementation manners consistent with the present application. On the contrary, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.
[0028] The block diagrams shown in the drawings are only functional entities and do not necessarily correspond to physically independent entities. That is, these functional entities can be implemented in software form, or implemented in one or more hardware modules or integrated circuits, or implemented in different networks and / or processor devices and / or microcontroller devices.
[0029] The flowcharts shown in the drawings are only exemplary descriptions, and do not necessarily include all contents and operations / steps, nor do they necessarily need to be executed in the described order. For example, some operations / steps can be decomposed, and some operations / steps can be combined or partially combined. Therefore, the actual execution order may change according to the actual situation.
[0030] In the present application, "a plurality of" means two or more. "And / or" describes the association relationship of associated objects, indicating that there can be three relationships. For example, A and / or B can represent: A exists alone, A and B exist simultaneously, and B exists alone. The character " / " generally represents an "or" relationship between the associated objects before and after.
[0031] The technical solution of the embodiments of the present application relates to related technologies such as TCC, and is specifically described through the following embodiments:
[0032] TCC (Try-Confirm-Cancel) refers to the resource reservation (Try) operation, confirmation operation (Confirm), and cancellation operation (Cancel). Among them, the Try operation refers to the inspection and reservation of business resources; the Confirm operation refers to the submission of business processing. As long as the Try operation is successful, this step will definitely be successful; the Cancel operation refers to the cancellation of business processing, that is, the rollback operation, and this step will release the resources reserved by Try.
[0033] During the execution of TCC, due to factors such as network exceptions and disordered execution order, problems such as empty rollback, non-idempotency, and suspension may occur. Among them, empty rollback means that in a distributed transaction, without calling the Try operation of the participating party, the TM (Transaction Manager) drives the two-phase rollback to call the Cancel operation of the participating party; suspension means that the two-phase Cancel operation is executed prior to the one-phase Try operation. Due to the reason of allowing empty rollback, after the execution of the two-phase Cancel operation, it directly returns successfully with an empty rollback. At this time, the global transaction has ended. However, since the Try operation is executed subsequently, this will cause the resources reserved by the one-phase Try operation to never be submitted and released; the non-idempotency problem means that the TC (Transaction Coordinator) repeats the two-phase submission. Therefore, the Confirm / Cancel interface needs to support idempotent processing, that is, it will not cause duplicate resource submission or duplicate release.
[0034] Figure 1 It is a schematic diagram of an exemplary system architecture shown in an exemplary embodiment of the present application.
[0035] Refer to Figure 1As shown in the figure, the system architecture may include a storage device 101 and a computer device 102. Among them, the computer device 102 may be at least one of a desktop Graphics Processing Unit (GPU) computer, a GPU computing cluster, a neural network computer, etc. Relevant technicians can use the computer device 102 to obtain the current distributed transaction and the executed transaction record, determine the target operation type based on the operation type of the current distributed transaction, generate transaction verification data according to the target operation type and the executed transaction record, verify the execution situation of the current distributed transaction through the transaction verification data to obtain a verification result, determine the execution strategy for the current distributed transaction according to the operation type and the verification result, and execute the current distributed transaction according to the execution strategy. The storage device 101 is used to store the current distributed transaction and the executed transaction record. In this embodiment, the storage device 101 uses a Random Access Memory (RAM), etc. to store the current distributed transaction and the executed transaction record, and provides them to the computer device 102 for processing.
[0036] Schematically, after the computer device 102 obtains the current distributed transaction and the executed transaction record of the storage device 101, it determines the target operation type based on the operation type of the current distributed transaction, generates transaction verification data according to the target operation type and the executed transaction record, verifies the execution situation of the current distributed transaction through the transaction verification data to obtain a verification result, determines the execution strategy for the current distributed transaction according to the operation type and the verification result, and executes the current distributed transaction according to the execution strategy. The above process, before executing the current distributed transaction, verifies the execution situation of the current distributed transaction through the transaction verification data and determines the execution strategy for the current distributed transaction according to the verification result, avoiding problems such as abnormal execution of distributed transactions, transaction suspension, rollback exception, or data inconsistency caused by the disorder of the execution order of the current distributed transaction, thus ensuring the normal execution of distributed transactions and further ensuring the consistency of business data among multiple distributed transaction services or systems.
[0037] It should be noted that the distributed transaction execution method provided by the embodiments of the present application is generally executed by the computer device 102. Correspondingly, the distributed transaction execution device is generally set in the computer device 102.
[0038] The implementation details of the technical solution of the embodiments of the present application are elaborated in detail below:
[0039] Figure 2 is a flowchart of the distributed transaction execution method shown in an exemplary embodiment of the present application. The distributed transaction execution method can be executed by a computing processing device, and the computing processing device can beFigure 1 the computer device 102 shown in Figure 2 As shown, the distributed transaction execution method at least includes steps S210 to S240, which are introduced in detail as follows:
[0040] In step S210, obtain the current distributed transaction and the executed transaction records. In an embodiment of the present application, the distributed transaction includes transactions between multiple databases or multiple applications in a distributed system; the executed transaction records are stored in a sub-transaction barrier table or other tables, and the executed transaction records include a globally unique identifier and a business data identifier, etc., and the business data identifier includes a business branch identifier and a sub-transaction behavior type, etc.
[0041] In step S220, based on the operation type of the current distributed transaction, determine the target operation type; and generate transaction verification data according to the target operation type and the executed transaction records. In an embodiment of the present application, the operation type includes a resource reservation operation, a confirmation operation, and a cancellation operation, the target operation type includes a resource reservation operation, a confirmation operation, and a cancellation operation, and there is a preset correspondence between the operation type and the target operation type. The preset correspondence includes: if the operation type is a resource reservation operation, then the target operation type is a resource reservation operation; if the operation type is a confirmation operation, then the target operation type is a confirmation operation; if the operation type is a cancellation operation, then the target operation type is a resource reservation operation. That is, after the operation type is determined, the target operation type is also determined accordingly, so that the current distributed transactions of different operation types correspond to different transaction verification data, ensuring the accuracy of verifying the current distributed transaction.
[0042] In step S230, verify the execution status of the current distributed transaction through the transaction verification data to obtain a verification result. In an embodiment of the present application, the verification result includes not executed and executed. The process of verifying the execution status of the current distributed transaction through the transaction verification data includes: adding the transaction verification data before the current distributed transaction to obtain an addition feedback result; if the addition feedback result is a successful addition, then determine that the verification result is not executed; if the addition feedback result is an addition failure, then determine that the verification result is executed.
[0043] In step S240, according to the operation type and the verification result, determine the execution strategy for the current distributed transaction, and execute the current distributed transaction according to the execution strategy. In an embodiment of the present application, the execution strategy includes: first execute the transaction verification data and then execute the current distributed transaction, perform an empty rollback operation, execute the current distributed transaction, execute the next transaction request of the current distributed transaction. Before executing the current distributed transaction, verify the execution situation of the current distributed transaction with the transaction verification data, and determine the execution strategy for the current distributed transaction according to the verification result, so as to avoid problems such as abnormal execution of the distributed transaction, transaction suspension, rollback exception or data inconsistency caused by the disorder of the execution order of the current distributed transaction, thereby ensuring the normal execution of the distributed transaction, and further ensuring the consistency of business data among multiple distributed transaction services or systems.
[0044] In an embodiment of the present application, the process of determining the target operation type based on the operation type of the current distributed transaction includes:
[0045] If the operation type is a resource reservation operation, then use the resource reservation operation as the target operation type. In an embodiment of the present application, when the operation type is a resource reservation operation, in order to avoid repeated execution or disorder of the execution order of the current distributed transaction, it is necessary to verify whether the current distributed transaction has been executed. Therefore, use the resource reservation operation as the target operation type.
[0046] If the operation type is a confirmation operation, then use the confirmation operation as the target operation type. In an embodiment of the present application, when the operation type is a confirmation operation, in order to avoid repeated execution or disorder of the execution order of the current distributed transaction, it is necessary to verify whether the current distributed transaction has been executed. Therefore, use the confirmation operation as the target operation type.
[0047] If the operation type is a cancellation operation, then use the resource reservation operation as the target operation type. In an embodiment of the present application, when the operation type is a cancellation operation, in order to avoid repeated execution or disorder of the execution order of the current distributed transaction, it is necessary to verify whether the current distributed transaction has been executed. Therefore, use the cancellation operation as the target operation type.
[0048] In some embodiments of the present application, if the resource reservation operation is executed successfully, then continue to execute the confirmation operation; if the resource reservation operation fails, then continue to execute the cancellation operation; if the confirmation operation is executed successfully, then continue to execute the resource reservation operation; if the confirmation operation fails, then continue to execute the cancellation operation.
[0049] In an embodiment of the present application, the process of generating transaction verification data according to the target operation type and the executed transaction record includes:
[0050] Combine the executed transaction record and the target operation type to obtain combined data. In an embodiment of the present application, the executed transaction record at least includes: a globally unique identifier and a business data identifier; the business data identifier includes a business branch identifier, a sub-transaction behavior type, etc. The process of combining the executed transaction record and the target operation type includes: concatenating the executed transaction record and the target operation type; or, embedding the executed transaction record into the target operation type, or, embedding the target operation type into the executed transaction record.
[0051] Convert the combined data into preset format data, and use the preset format data as transaction verification data. In an embodiment of the present application, the preset format data can be preset storage format data, or preset encapsulation format data, or preset code format data, and no specific limitation is made here.
[0052] In an embodiment of the present application, the process of determining the execution strategy for the current distributed transaction according to the operation type and the verification result includes:
[0053] If the operation type is a cancellation operation and the verification result is not executed, then execute the transaction verification data first and then execute the current distributed transaction, or use an empty rollback operation as the execution strategy. In an embodiment of the present application, if the operation type is a cancellation operation and the verification result is not executed, it means that no resource reservation operation has been performed before the cancellation operation. At this time, only by executing the transaction verification data first and then executing the current distributed transaction, or performing an empty rollback operation, can the current distributed transaction be ensured to be executed in the correct order, avoiding out-of-order situations, and at the same time, being able to solve the problems of transaction suspension and data inconsistency. An empty rollback operation means not canceling any executed operations.
[0054] In some embodiments of the present application, in the case where the distributed transaction execution times out due to factors such as network anomalies and it is not clear whether the current distributed transaction is executed successfully, executing the transaction verification data first and then executing the current distributed transaction is beneficial to solving the suspension problem of the current distributed transaction, enabling the current distributed transaction to continue to execute instead of being in a stuck state or losing notification messages for a long time.
[0055] In some embodiments of the present application, executing the transaction verification data first and then executing the current distributed transaction is beneficial to clarifying which functional operations (such as submitting an order, paying the price, etc.) have been executed during the transaction execution process, avoiding rolling back all functional operations when the current distributed transaction fails (if all the functional operations included in the current distributed transaction are executed successfully, it is determined that the current distributed transaction is executed successfully), resulting in out-of-order situations.
[0056] In some embodiments of the present application, the process of determining whether the current distributed transaction is successfully executed includes: if all the functional operations included in the current distributed transaction are successfully executed, it is determined that the current distributed transaction is successfully executed; if one of the functional operations included in the current distributed transaction fails, it is determined that the current distributed transaction fails.
[0057] If the operation type is a cancellation operation and the verification result is executed, then executing the current distributed transaction is used as the execution strategy. In an embodiment of the present application, if the operation type is a cancellation operation and the verification result is executed, it indicates that a resource reservation operation has been performed before the cancellation operation. At this time, executing the current distributed transaction will not cause the execution order to be disordered, and at the same time, it can solve the problems of transaction suspension and data inconsistency.
[0058] If the operation type is a resource reservation operation or a confirmation operation, and the verification result is not executed, then executing the current distributed transaction is used as the execution strategy. In an embodiment of the present application, when the operation type is a resource reservation operation or a confirmation operation and the verification result is not executed, it indicates that the corresponding operation has not been performed before the resource reservation operation or the confirmation operation. Therefore, executing the current distributed transaction will not cause the execution order to be disordered, and at the same time, it can solve the problems of transaction suspension and data inconsistency.
[0059] If the operation type is a resource reservation operation or a confirmation operation, and the verification result is executed, then executing the next transaction request of the current distributed transaction is used as the execution strategy. In an embodiment of the present application, when the operation type is a resource reservation operation or a confirmation operation and the verification result is executed, it indicates that the corresponding operation has been performed before the resource reservation operation or the confirmation operation. Therefore, it is not necessary to repeatedly execute the current distributed transaction, and directly execute the next transaction request of the current distributed transaction, which not only ensures that the current distributed transaction is executed in the correct order and avoids the occurrence of disordered order, but also can solve the problems of transaction suspension and data inconsistency.
[0060] In an embodiment of the present application, if the operation type is a cancellation operation, and after executing the current distributed transaction, the distributed transaction execution method further includes:
[0061] Generating a business data cancellation request in response to the current distributed transaction. In an embodiment of the present application, the current distributed transaction includes one or more business operations. When the corresponding business operations are cancelled by executing the current distributed transaction, the business data corresponding to the business operations also needs to be cancelled. The generation method of the business data cancellation request can be implemented according to the process of generating a business data cancellation request in relevant technical documents, and is not specifically limited herein.
[0062] Cancel the business data according to the business data cancellation request, and perform a cancellation operation on the business data to obtain an operation result. In an embodiment of the present application, the operation result includes successful cancellation and failed cancellation. If the business data is successfully cancelled, stop the cancellation of the business data; if the business data cancellation fails, perform the cancellation operation on the business data again.
[0063] If the operation result is failed cancellation, retry the cancellation operation. In an embodiment of the present application, the number of times of retrying the cancellation operation (preset operation times) needs to be set according to the actual situation.
[0064] If the operation result obtained within the preset operation times is failed cancellation, issue an exception warning according to the preset warning method. In an embodiment of the present application, the preset warning method can be an audible and visual prompt method, or a text prompt method, etc.
[0065] If the operation result is successful cancellation, or, if the operation result obtained within the preset operation times is successful cancellation, synchronize the operation result to the first target system. In an embodiment of the present application, the first target system includes a system determined in advance or in real time. If the system that cancels the business data is used as the current business system, the first target system can be the upstream and downstream business systems of the current business system, and the current business system can be a sales system, a payment system, an inventory system, etc.
[0066] In some embodiments of the present application, when the operation type is a resource reservation operation or a confirmation operation, and after the current distributed transaction is executed, the distributed transaction execution method further includes:
[0067] Perform corresponding operations on the business data according to the function of the current distributed transaction. For example, if the function of the current distributed transaction is to confirm payment, perform a deduction operation in the payment system, that is, perform a deduction operation on the business data in the payment system; if the function of the current distributed transaction is an address change operation, perform an address change and save operation in the sales system, that is, perform a save operation on the business data in the payment system.
[0068] In an embodiment of the present application, when the operation type is a cancellation operation and the function of the current distributed transaction is to delete the target transaction, the distributed transaction execution method further includes:
[0069] Execute the current distributed transaction and synchronize the successful execution message to the second target system, so that the second target system deletes the target transaction according to the successful execution message until the deletion operation of the second business system is successful. In an embodiment of the present application, the second target transaction includes a transaction request determined in advance or in real time. If the current system is a data governance platform, the second target system may be a distributed scheduling system, etc. When the data governance platform deletes the target transaction, the second target system can only delete the target transaction and ensure the successful deletion of the target transaction to ensure the consistency of the data in the data governance platform and the data in the distributed scheduling system. The target transaction is determined according to the user's usage requirements.
[0070] In some embodiments of the present application, when the operation type is a resource reservation operation or a confirmation operation, and the function of the current distributed transaction is to create a target transaction, in the data governance platform, after successfully creating the target transaction, execute the creation of the target transaction in the distributed scheduling system.
[0071] In an embodiment of the present application, the distributed transaction execution method further includes:
[0072] Lock the current distributed transaction according to a preset locking time. In an embodiment of the present application, the preset locking time can be set according to the actual situation, and the locking method includes the distributed lock method. The distributed lock has the function of preventing multiple services or systems from operating the same data simultaneously, thus avoiding data inconsistency between different systems or services.
[0073] If the current distributed transaction is successfully executed within the preset locking time, unlock the current distributed transaction. In an embodiment of the present application, if the current distributed transaction is successfully executed, unlock the current distributed transaction to release resources, so that the released resources can be used by other services or systems.
[0074] If the current distributed transaction fails within the preset locking time, after sending an alarm message, unlock the current distributed transaction. In an embodiment of the present application, the alarm message is notified to developers or maintenance personnel, etc. through email, text message, etc., and the notification method for developers or maintenance personnel, etc. needs to be pre-configured.
[0075] Figure 3 It is a flowchart of the distributed transaction execution between the data governance platform and the distributed scheduling system when creating a quality monitoring task shown in an exemplary embodiment of the present application, as Figure 3As shown in the figure, the process of distributed transaction execution includes: (1) Attempt stage: First, the data governance platform starts a transaction, writes the business information related to the quality monitoring task into the business information table, and performs an idempotency check (i.e., uniqueness check) on the transaction of creating the quality monitoring task according to the business information; then, writes the business information into the TCC barrier (tcc_barrier) table, generates a transaction verification data according to the globally unique identifier, business data identifier and resource reservation operation type, and submits the transaction verification data. If the submission return result is 0, it means that a cancellation operation has been performed before, and this resource reservation operation will not be executed. If the submission return result is 1, the new transaction is started successfully, and the resource reservation operation is attempted. Query whether there is the same quality monitoring task in the data governance platform. If not, attempt to create the quality monitoring task and set the status of the quality monitoring task to not enabled. If the creation fails, directly return that the creation of the quality monitoring task fails; if the data governance platform successfully creates the quality monitoring task, first, generate a transaction verification data according to the globally unique identifier, business data identifier and confirmation operation type, and execute the transaction verification data. If the return result is 0, this confirmation operation will not be executed. If the return result is 1, attempt to execute the confirmation operation, that is, complete the creation of the quality monitoring task in the distributed scheduling system; (2) The data governance platform sends the message that the quality monitoring task is successfully created to the distributed scheduling system. The distributed scheduling system starts a transaction, writes the business information related to the quality monitoring task into the business information table, and performs an idempotency check (i.e., uniqueness check) on the transaction of creating the quality monitoring task according to the business information; then, writes the business information into the TCC barrier (tcc_barrier) table, generates a transaction verification data according to the globally unique identifier, business data identifier and resource reservation operation type, and submits the transaction verification data. If the submission return result is 0, it means that a cancellation operation has been performed before, and this resource reservation operation will not be executed. If the submission return result is 1, the new transaction is started successfully, and the resource reservation operation is attempted. Query whether there is the same quality monitoring task in the distributed scheduling system. If not, attempt to perform the confirmation operation.During the reconfirmation operation process, first, a transaction verification data is generated based on the globally unique identifier, business data identifier, and confirmation operation type, and the transaction verification data is executed. If the return result is 0, the current confirmation operation is not executed. If the return result is 1, an attempt is made to create the quality monitoring task, the status of the quality monitoring task is modified to enabled, and it is returned that the quality monitoring task is successfully created; (3) In the distributed scheduling system, if the attempt / confirmation phase fails, an attempt is made to perform a cancellation operation. Before performing the cancellation operation, first, a transaction verification data is generated based on the globally unique identifier, business data identifier, and resource reservation operation type, and the transaction verification data is executed. If the execution result returns 1, it proves that the resource reservation operation has not been executed before the cancellation operation, and only an empty rollback is required for this cancellation operation. If the execution result returns 0, the cancellation operation (for example, deleting the quality monitoring task) is executed, and the data governance platform is notified to perform the cancellation process; (4) In the data governance platform, if the attempt / confirmation phase fails, an attempt is made to perform a cancellation operation. Before performing the cancellation operation, first, a transaction verification data is generated based on the globally unique identifier, business data identifier, and resource reservation operation type, and the transaction verification data is executed. If the execution result returns 1, it proves that the resource reservation operation has not been executed before the cancellation operation, and only an empty rollback is required for this cancellation operation. If the execution result returns 0, the cancellation operation (for example, deleting the quality monitoring task) is executed, and the distributed scheduling system is notified to perform the cancellation process.
[0076] In some embodiments of the present application, before the resource reservation operation, confirmation operation, and cancellation operation are executed, it is necessary to generate transaction verification data based on the globally unique identifier, business data identifier, and target operation type; and according to the execution result of the transaction verification data, determine the execution strategy of the resource reservation operation, confirmation operation, or cancellation operation, so as to avoid problems such as abnormal execution of distributed transactions, transaction suspension, rollback exception, or data inconsistency caused by the disorder of the execution order of the current distributed transaction, thereby ensuring the normal execution of the distributed transaction, and further ensuring the consistency of business data among multiple distributed transaction services or systems.
[0077] Figure 4 It is a flowchart of the execution of the distributed transaction between the data governance platform and the distributed scheduling system when deleting the quality monitoring task shown in an exemplary embodiment of the present application, as Figure 4As shown in the figure, the distributed transaction execution process includes: (1) The data governance platform starts a transaction, writes the business information related to the quality monitoring task into the business information table, and performs an idempotency check (i.e., uniqueness check) on the transaction for creating the quality monitoring task, determines the quality monitoring tasks to be deleted (consistent with the tasks the user needs to delete), and commits the transaction; (2) Starts a new transaction and attempts to perform a resource reservation operation: attempts to delete the selected quality monitoring tasks. If the execution is successful, the transaction is committed and "delete successful" is returned. If the delete operation fails, "failed" is directly returned; (3) If the data governance platform successfully deletes the quality monitoring tasks, it attempts to perform a confirmation operation, sends the message of successful deletion to the message middleware. The downstream distributed scheduling system receives the message of successful deletion. If the downstream distributed scheduling system successfully deletes the quality monitoring tasks, it will feedback a success message (ack) to confirm the completion of deletion; if the downstream distributed scheduling system fails to delete, a deletion exception will be thrown; (4) In this case, the downstream distributed scheduling system will rely on the retry mechanism of the message queue (message middleware) and keep retrying until the delete operation is successful or the maximum number of retries is reached.
[0078] In some embodiments of the present application, due to the particularity of the deletion task, if the data quality platform deletes successfully, the distributed scheduling system must also delete successfully. In the distributed scheduling system, whether any exceptions are encountered during the attempt stage or the confirmation stage, continuous repeated attempts and confirmations are required until the repeated attempt is successful, or the relevant business interfaces reach the preset number of retries.
[0079] Figure 5 is a flowchart of the retry mechanism shown in an exemplary embodiment of the present application. In Figure 5 it, the implementation process of the retry mechanism includes the following two methods: (1) The data governance platform retries the records with the deletion status of "not successful" by regularly scanning the local message table; (2) The data governance platform writes the message of deleting the quality monitoring tasks into the message queue (message middleware) through the interface. After the downstream distributed scheduling system deletes successfully, it will feedback a success message (ack) to confirm the completion of deletion; if the downstream distributed scheduling system fails to delete, a deletion exception will be thrown.
[0080] Figure 6 is a flowchart of locking the current distributed transaction shown in an exemplary embodiment of the present application. As shown in Figure 6As shown in the figure, the process of locking the current distributed transaction includes: (1) The timing task starts; (2) Determine whether the Redis distributed lock is successfully acquired; (3) If the Redis distributed lock is successfully acquired, use the setnx method to set the locking time (for example, set the locking time to 1 hour); (4) Within the preset locking time, partition the time and scan the records within the time partition; (5) Pull the abnormal records within the time partition (records with an execution result of failure or records that have been in the execution process for a long time (exceeding the preset duration), etc.); (6) Determine whether the notification method is configured; (7) If the notification method is already configured, determine whether an email address or a mobile phone number is configured. If an email address or a mobile phone number is configured, send the notification message in the form of an email or a text message; (8) Determine whether the notification message is successfully sent; (9) If the notification message is successfully sent, modify the status of the abnormal record to notified, and unlock the Redis distributed lock, and the process ends; if the notification message fails to be sent, the process ends; (10) If the notification method is not configured, the process ends; (11) If the Redis distributed lock acquisition fails, the process ends.
[0081] In some embodiments of the present application, the distributed cluster architecture distributes the load of the business system to multiple services, thereby avoiding the unavailability of the business system caused by a single point of failure. At the same time, it also uses technical means such as redundant key components (databases, message queues, caches, etc.) and data backup to implement fault transfer and fault tolerance mechanisms. Finally, reliable servers and network environments are selected to minimize the impact of network environment factors on the business while ensuring service availability during failures.
[0082] The following introduces the device embodiments of the present application, which can be used to execute the distributed transaction execution method in the above embodiments of the present application. For details not disclosed in the device embodiments of the present application, please refer to the embodiments of the distributed transaction execution method above of the present application.
[0083] Figure 7 is a block diagram of a distributed transaction execution device shown in an exemplary embodiment of the present application. The device can be applied to Figure 1 the implementation environment shown in the figure and is specifically configured in the computer device 102. The device can also be applicable to other exemplary implementation environments and is specifically configured in other devices. The present embodiment does not limit the implementation environment applicable to the device.
[0084] As Figure 7 shown, the exemplary distributed transaction execution device includes:
[0085] The data acquisition module 701 is used to obtain the current distributed transaction and the executed transaction records.
[0086] The data generation module 702 is used to determine the target operation type based on the operation type of the current distributed transaction; and generate transaction verification data according to the target operation type and the executed transaction record.
[0087] The transaction verification module 703 is used to verify the execution situation of the current distributed transaction through the transaction verification data to obtain a verification result.
[0088] The transaction execution module 704 is used to determine the execution strategy for the current distributed transaction according to the operation type and the verification result, and execute the current distributed transaction according to the execution strategy.
[0089] In an embodiment of the present application, the executed transaction record is stored in a sub-transaction barrier table or other tables, and the distributed transaction includes transactions between multiple databases or multiple application programs in a distributed system; the executed transaction record includes a globally unique identifier and a business data identifier, etc., and the business data identifier includes a business branch identifier and a sub-transaction behavior type, etc.
[0090] In an embodiment of the present application, the operation type includes a resource reservation operation, a confirmation operation, and a cancellation operation, and the target operation type includes a resource reservation operation, a confirmation operation, and a cancellation operation. There is a preset correspondence between the operation type and the target operation type, and the preset correspondence includes: if the operation type is a resource reservation operation, the target operation type is a resource reservation operation; if the operation type is a confirmation operation, the target operation type is a confirmation operation; if the operation type is a cancellation operation, the target operation type is a resource reservation operation. That is, after the operation type is determined, the target operation type is also determined accordingly, so that the current distributed transactions of different operation types correspond to different transaction verification data, ensuring the accuracy of verifying the current distributed transaction.
[0091] In an embodiment of the present application, the verification result includes not executed and executed. The process of verifying the execution situation of the current distributed transaction through the transaction verification data includes: obtaining an addition feedback result before adding the transaction verification data to the current distributed transaction; if the addition feedback result is a successful addition, it is determined that the verification result is not executed; if the addition feedback result is an addition failure, it is determined that the verification result is executed.
[0092] In an embodiment of the present application, the execution policy includes: first performing transaction verification on data and then executing the current distributed transaction, performing an empty rollback operation, executing the current distributed transaction, and executing the next transaction request of the current distributed transaction. Before executing the current distributed transaction, the execution situation of the current distributed transaction is verified by using the transaction verification data, and the execution policy for the current distributed transaction is determined according to the verification result, so as to avoid problems such as abnormal execution of the distributed transaction, transaction suspension, rollback exception, or data inconsistency caused by the disorder of the execution order of the current distributed transaction, thereby ensuring the normal execution of the distributed transaction, and further ensuring the consistency of business data among multiple distributed transaction services or systems.
[0093] It should be noted that the distributed transaction execution device provided in the above embodiment and the distributed transaction execution method provided in the above embodiment belong to the same concept. The specific manners in which each module and unit perform operations have been described in detail in the method embodiment, and will not be elaborated here. In practical applications, the distributed transaction execution device provided in the above embodiment can, according to needs, allocate the above functions to different functional modules, that is, divide the internal structure of the device into different functional modules to complete all or part of the functions described above, and this is not limited here either.
[0094] An embodiment of the present application further provides an electronic device, including: one or more processors; a storage device for storing one or more programs, which, when executed by the one or more processors, cause the electronic device to implement the distributed transaction execution method provided in each of the above embodiments.
[0095] Figure 8 The structural schematic diagram of a computer system of an electronic device suitable for implementing the embodiment of the present application is shown. It should be noted that Figure 8 The computer system 800 of the electronic device shown is only an example and should not impose any limitations on the functions and usage scope of the embodiment of the present application.
[0096] Such as Figure 8As shown, the computer system 800 includes a Central Processing Unit (CPU) 801, which can perform various appropriate actions and processes according to the program stored in the Read-Only Memory (ROM) 802 or the program loaded from the storage section 808 into the Random Access Memory (RAM) 803, such as executing the methods in the above embodiments. In the RAM 803, various programs and data required for system operation are also stored. The CPU 801, ROM 802, and RAM 803 are connected to each other via a bus 804. An Input / Output (I / O) interface 805 is also connected to the bus 804.
[0097] The following components are connected to the I / O interface 805: an input section 806 including a keyboard, a mouse, etc.; an output section 807 including, for example, a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), etc. and a speaker, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN (Local Area Network) card, a modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to the I / O interface 805 as needed. A removable medium 811, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 810 as needed so that the computer program read from it can be installed into the storage section 808 as needed.
[0098] Specifically, according to the embodiments of the present application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, the embodiments of the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program contains a computer program for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network via the communication section 809, and / or installed from the removable medium 811. When the computer program is executed by the Central Processing Unit (CPU) 801, various functions defined in the system of the present application are executed.
[0099] It should be noted that the computer-readable medium shown in the embodiments of the present application may be a computer-readable signal medium, a computer-readable storage medium, or any combination of the two. A computer-readable storage medium may, for example, be a system, device, or apparatus of electricity, magnetism, light, electromagnetic, infrared, or semiconductor, or any combination of the above. More specific examples of the computer-readable storage medium may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM), a flash memory, an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable computer program. Such a propagated data signal may take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable medium other than a computer-readable storage medium, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, device, or apparatus. The computer program contained on the computer-readable medium may be transmitted by any appropriate medium, including but not limited to: wireless, wired, etc., or any suitable combination of the above.
[0100] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of the present application. Among them, each block in the flowchart or block diagram may represent a module, a program segment, or a part of code, and the above module, program segment, or part of code contains one or more executable instructions for implementing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the blocks may occur in a different order than marked in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, and they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram or flowchart, and the combination of blocks in the block diagram or flowchart, may be implemented by a dedicated hardware-based system for performing the specified functions or operations, or may be implemented by a combination of dedicated hardware and computer instructions.
[0101] The units involved in the embodiments described in this application can be implemented in software or in hardware, and the described units can also be provided in a processor. Among them, the names of these units do not, in some cases, constitute a limitation on the unit itself.
[0102] Another aspect of this application also provides a computer-readable storage medium, on which computer-readable instructions are stored. When the computer-readable instructions are executed by a processor of a computer, the computer is caused to execute the distributed transaction execution methods provided in the above various embodiments. The computer-readable storage medium can be included in the electronic device described in the above embodiments, or can exist alone without being assembled into the electronic device.
[0103] It should be noted that although several modules or units of a device for action execution are mentioned in the above detailed description, such a division is not mandatory. In fact, according to the embodiments of this application, the features and functions of the two or more modules or units described above can be embodied in one module or unit. Conversely, the features and functions of one module or unit described above can be further divided and embodied by multiple modules or units.
[0104] Through the description of the above embodiments, those skilled in the art can easily understand that the exemplary embodiments described here can be implemented in software or in a manner combining software with necessary hardware. Therefore, the technical solutions according to the embodiments of this application can be embodied in the form of a software product, which can be stored in a non-volatile storage medium (which can be a CD-ROM, a USB flash drive, a mobile hard disk, etc.) or on a network, including several instructions to enable a computing device (which can be a personal computer, a server, a touch terminal, or a network device, etc.) to execute the methods according to the embodiments of this application.
[0105] After considering the specification and practicing the embodiments disclosed herein, those skilled in the art will readily conceive of other embodiments of this application. This application is intended to cover any variations, uses, or adaptations of this application, which follow the general principles of this application and include common general knowledge or conventional technical means in the technical field not disclosed in this application.
[0106] It should be understood that the above content is only a preferred exemplary embodiment of this application and is not used to limit the implementation of this application. Those of ordinary skill in the art can easily make corresponding adaptations or modifications according to the main concept and spirit of this application. Therefore, the protection scope of this application should be subject to the protection scope required by the claims.
Claims
1. A distributed transaction execution method, characterized in that: include: Get the current distributed transaction and executed transaction records; distributed transactions include transactions between multiple databases or multiple applications in a distributed system; Determine a target operation type based on the operation type of the current distributed transaction; and generating transaction verification data according to the target operation type and the executed transaction record; Verifying the execution status of the current distributed transaction through the transaction verification data to obtain a verification result; The verification results include not executed and executed; An execution strategy for the current distributed transaction is determined according to the operation type and the verification result, and the current distributed transaction is executed according to the execution strategy.
2. The distributed transaction execution method according to claim 1, characterized in that: Based on the operation type of the current distributed transaction, the process of determining the target operation type includes: If the operation type is a resource reservation operation or a cancellation operation, taking the resource reservation operation as the target operation type; If the operation type is a confirmation operation, taking the confirmation operation as the target operation type; If the resource reservation operation is successfully executed, the confirmation operation is continued; if the resource reservation operation fails, the cancellation operation is continued; If the confirmation operation is successfully executed, the resource reservation operation is continued to be executed; if the confirmation operation fails to be executed, the cancellation operation is continued to be executed.
3. The distributed transaction execution method according to claim 1, characterized in that: The process of generating transaction verification data according to the target operation type and the executed transaction record includes: Combining the executed transaction record and the target operation type to obtain combined data; the executed transaction record includes at least: a globally unique identifier and a business data identifier; The combined data is converted into preset format data, and the preset format data is used as the transaction verification data.
4. The distributed transaction execution method according to claim 1, characterized in that: The process of determining the execution strategy for the current distributed transaction according to the operation type and the verification result includes: If the operation type is a cancel operation and the verification result is not executed, the transaction verification data is executed first and then the current distributed transaction is executed, or an empty rollback operation is used as the execution strategy; If the operation type is the cancel operation and the verification result is the executed operation, the current distributed transaction is executed as the execution strategy; If the operation type is a resource reservation operation or a confirmation operation, and the verification result is that it is not executed, executing the current distributed transaction as the execution strategy; If the operation type is the resource reservation operation or the confirmation operation, and the verification result is that it has been executed, then the next transaction request of the current distributed transaction is executed as the execution strategy.
5. The distributed transaction execution method according to claim 1, characterized in that: If the operation type is the cancel operation, and after executing the current distributed transaction, the method further includes: In response to the current distributed transaction, generating a business data cancellation request; According to the business data cancellation request, cancel the business data and obtain the operation result; If the operation result is a cancellation failure, retry the cancellation operation; If the operation result obtained within the preset operation times is a cancellation failure, an abnormal warning is issued according to the preset warning method; If the operation result is a successful cancellation, or the operation result obtained within the preset operation times is a successful cancellation, the operation result is synchronized to the first target system, and the first target system includes a system determined in advance or in real time.
6. The distributed transaction execution method according to claim 1, characterized in that: If the operation type is the cancel operation, and the function of the current distributed transaction is to delete the target transaction, the method further includes: Execute the current distributed transaction and synchronize a message of successful execution to a second target system, so that the second target system deletes the target transaction according to the message of successful execution until the second business system successfully executes the deletion operation; the second target transaction includes a transaction request determined in advance or in real time.
7. The distributed transaction execution method according to any one of claims 1 to 6, characterized in that: The method further comprises: According to a preset locking time, the current distributed transaction is locked; the locking method includes a distributed locking method; If the current distributed transaction is successfully executed within the preset locking time, the current distributed transaction is unlocked; If the current distributed transaction fails to execute within the preset locking time, the current distributed transaction is unlocked after an alarm message is issued.
8. A distributed transaction execution device, characterized in that: include: A data acquisition module is used to obtain current distributed transactions and executed transaction records; distributed transactions include transactions between multiple databases or multiple applications in a distributed system; A data generation module, used to determine a target operation type based on the operation type of the current distributed transaction; and generating transaction verification data according to the target operation type and the executed transaction record; A transaction verification module, used to verify the execution status of the current distributed transaction through the transaction verification data to obtain a verification result; The verification results include not executed and executed; The transaction execution module is used to determine the execution strategy for the current distributed transaction according to the operation type and the verification result, and execute the current distributed transaction according to the execution strategy.
9. An electronic device, characterized in that: include: one or more processors; A storage device for storing one or more programs, which, when executed by the one or more processors, enables the electronic device to implement the distributed transaction execution method as described in any one of claims 1 to 7.
10. A computer-readable storage medium, characterized in that: Computer-readable instructions are stored thereon, and when the computer-readable instructions are executed by a processor of a computer, the computer is caused to execute the distributed transaction execution method according to any one of claims 1 to 7.