Distributed transaction implementation method and device, equipment and storage medium

Through Seata and Nacos, a distributed microservice application framework is built to realize global transaction mode and SQL interception, which solves the problem of transaction inconsistency among microservices and improves the reliability and data integrity of business processing.

CN119127410APending Publication Date: 2024-12-13HANGZHOU DBAPPSECURITY CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411327766.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-23
Publication Date
2024-12-13

AI Technical Summary

Technical Problem

When microservices communicate through network protocols, it is difficult to ensure the ACID of global services, resulting in transaction inconsistency problems. Especially when service A calls service B, the inconsistency caused by exceptions of service B is difficult to roll back.

Method used

Adopt distributed transaction implementation method, build the target distributed microservice application framework through Seata and Nacos, open the global transaction mode, use relational database to intercept, parse, image generation and row lock management, and the transaction coordinator analyzes the execution results to complete Commit or rollback of distributed transactions.

Benefits of technology

It improves the reliability of service processing and the ACID of global services, guarantees the integrity of service data, and ensures that data integrity is not corrupted in the event of failure or network interruption.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119127410A_ABST
    Figure CN119127410A_ABST
Patent Text Reader

Abstract

The invention discloses a distributed transaction implementation method and device, equipment and a storage medium, relates to the technical field of business processing, is applied to a server, and comprises the following steps: performing Sate configuration and Nacos registration based on a preset micro-service application framework creation rule to obtain a target distributed micro-service application framework; when distributed micro-service deployment is carried out, starting a global transaction based on an automatic transaction mode of a target distributed micro-service application framework for to-be-processed services related to multiple micro-services, and intercepting SQL statements corresponding to the to-be-processed services by utilizing a preset relational database; determining a global transaction execution result based on the automatic transaction mode and the SQL statement; and the transaction coordinator based on the target distributed micro-service application framework analyzes the global transaction execution result, and submits or rolls back the global transaction execution result by using the obtained analysis result, so that operation is realized by the distributed transaction. And the integrity of the business data is ensured.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of business processing technology, and in particular to a distributed transaction implementation method, device, equipment and storage medium. Background Art

[0002] When microservices communicate with each other through network protocols, each microservice can only rely on its own local transactions, and it is difficult to ensure the ACID (Atomicity Consistency Isolation Durability) of the global business. Figure 1 As shown in the figure, there is a business that involves service A and service B. In this business, services A and B can only rely on their own local transactions. Assuming that all operations of service A are normal, and the function of service B is successfully called, and the local transaction is committed, but an exception occurs during the operation of service B, it will eventually cause inconsistency between services A and B in the same business. On the contrary, it is possible that after service A calls service B, all subsequent operations of service B are completed, but service A has an exception in the subsequent operations, and the local transaction rolls back all operations, but cannot roll back the operation of service B, which will also cause transaction inconsistency. Summary of the invention

[0003] In view of this, the purpose of the present invention is to provide a distributed transaction implementation method, device, equipment and storage medium, which can effectively implement distributed transactions, improve the reliability of business processing and the ACID of global business, thereby ensuring the integrity of business data. The specific scheme is as follows:

[0004] In a first aspect, the present application provides a distributed transaction implementation method, which is applied to a server, including:

[0005] Based on the preset microservice application framework creation rules, Seate configuration and Nacos registration are performed to obtain the corresponding target distributed microservice application framework;

[0006] When performing distributed microservice deployment, for pending businesses related to multiple microservices, a global transaction is started based on the automatic transaction mode of the target distributed microservice application framework, and the SQL statements corresponding to the pending businesses are intercepted using a preset relational database;

[0007] Based on the automatic transaction mode and the SQL statement, statement parsing, mirror generation, and row lock generation are performed to obtain corresponding global transaction execution results;

[0008] The transaction coordinator based on the target distributed microservice application framework analyzes the global transaction execution result, and uses the obtained analysis result to commit or roll back the global transaction execution result to complete the distributed transaction implementation operation corresponding to the business to be processed.

[0009] Optionally, the performing statement parsing, mirror generation, and row lock generation based on the automatic transaction mode and the SQL statement to obtain a corresponding global transaction execution result includes:

[0010] For any of the microservices, in any transaction of the preset relational database, semantically parse the SQL statement based on the automatic transaction mode, and determine the business data to be updated corresponding to the business to be processed based on the obtained semantic parsing result;

[0011] Based on a preset application program interface, the business data to be updated is saved in the preset relational database in a previous mirroring manner;

[0012] The business data to be updated is updated by executing the SQL statement to obtain corresponding updated data, and row lock data corresponding to the updated data is generated to obtain a branch transaction execution result corresponding to the microservice;

[0013] The corresponding global transaction execution result is determined based on the execution results of each branch transaction.

[0014] Optionally, also include:

[0015] The updated data is saved in the preset relational database in a post-mirroring manner based on the preset application program interface, and the row lock data is saved in a preset table in the preset relational database.

[0016] Optionally, the transaction coordinator based on the target distributed microservice application framework analyzes the execution result of the global transaction, including:

[0017] Based on Dubbo as a transaction coordinator in the target distributed microservice application framework, the global transaction execution result is analyzed to obtain a corresponding analysis result.

[0018] Optionally, submitting the global transaction execution result by using the obtained analysis result includes:

[0019] When it is determined to commit the execution result of the global transaction based on the obtained analysis result, the transaction manager in the target distributed microservice application framework deletes each of the front images, each of the back images and the corresponding row lock data saved in the preset relational database to complete the corresponding transaction submission operation.

[0020] Optionally, rolling back the global transaction execution result using the obtained analysis result includes:

[0021] When it is determined to submit the execution result of the global transaction based on the obtained analysis result, the current business data corresponding to the to-be-processed business and each of the back images saved in the preset relational database are compared based on the transaction manager to obtain a corresponding comparison result;

[0022] When the comparison result shows that the current business data is consistent with each of the rear images, the business data is restored based on each of the front images that have been saved in the preset relational database.

[0023] Optionally, the creating rules based on the preset microservice application framework to perform Seate configuration and Nacos registration includes:

[0024] During the Seate configuration process, configure Nacos as the configuration center and registration center of Seate-server, and configure the preset relational database used to support local ACID transactions as the storage center of Seate-server to obtain the corresponding target Seate-server;

[0025] After starting the target Seate-server, register the target Seate-server in the service list of Nacos.

[0026] In a second aspect, the present application provides a distributed transaction implementation device, which is applied to a server, including:

[0027] The framework building module is used to perform Seate configuration and Nacos registration based on the preset microservice application framework creation rules to obtain the corresponding target distributed microservice application framework;

[0028] A statement interception module is used to start a global transaction based on the automatic transaction mode of the target distributed microservice application framework for pending businesses related to multiple microservices when deploying distributed microservices, and intercept SQL statements corresponding to the pending businesses using a preset relational database;

[0029] A result acquisition module, used to perform statement parsing, image generation, and row lock generation based on the automatic transaction mode and the SQL statement to obtain a corresponding global transaction execution result;

[0030] A result processing module is used to analyze the global transaction execution result based on the transaction coordinator of the target distributed microservice application framework, and use the obtained analysis result to commit or roll back the global transaction execution result to complete the distributed transaction implementation operation corresponding to the business to be processed.

[0031] In a third aspect, the present application provides an electronic device, including:

[0032] Memory, used to store computer programs;

[0033] The processor is used to execute the computer program to implement the steps of the aforementioned distributed transaction implementation method.

[0034] In a fourth aspect, the present application provides a computer-readable storage medium for storing a computer program, which implements the steps of the aforementioned distributed transaction implementation method when executed by a processor.

[0035] It can be seen that in this application, the server-side creates rules based on the preset microservice application framework to perform Seat configuration and Nacos registration to obtain the corresponding target distributed microservice application framework; when deploying distributed microservices, for pending businesses related to multiple microservices, a global transaction is opened based on the automatic transaction mode of the target distributed microservice application framework, and the SQL statement corresponding to the pending business is intercepted using the preset relational database; statement parsing, mirror generation, and row lock generation are performed based on the automatic transaction mode and the SQL statement to obtain the corresponding global transaction execution result; the transaction coordinator based on the target distributed microservice application framework analyzes the global transaction execution result, and uses the obtained analysis result to commit or roll back the global transaction execution result to complete the distributed transaction implementation operation corresponding to the pending business. That is to say, after this application builds the corresponding target distributed microservice application framework based on Seata and Nacos, it selects the automatic transaction mode and uses the preset relational database to perform global transaction execution, execution result analysis, and execution result submission or rollback on the pending businesses related to multiple microservices to complete the corresponding distributed transaction implementation operation. In this way, distributed transactions are effectively implemented, the reliability of business processing and the ACID of global business are improved, thereby ensuring the integrity of business data. BRIEF DESCRIPTION OF THE DRAWINGS

[0036] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on the provided drawings without paying creative work.

[0037] Figure 1 A business processing diagram provided for this application;

[0038] Figure 2 A flow chart of a distributed transaction implementation method provided by this application;

[0039] Figure 3 A schematic diagram of role interaction in Seate provided for this application;

[0040] Figure 4 A schematic diagram of the transaction processing flow of the first stage of an automatic transaction mode provided by this application;

[0041] Figure 5 A schematic diagram of a transaction processing flow in the second phase of an automatic transaction mode provided by this application;

[0042] Figure 6 A schematic diagram of the rollback process of the second phase of an automatic transaction mode provided for this application;

[0043] Figure 7 A schematic diagram of a specific business case architecture provided for this application;

[0044] Figure 8 A code diagram of the Seata-server configuration for a specific business case provided for this application;

[0045] Fig. 9 A code diagram of the client Seata configuration for a specific business case provided by this application;

[0046] Fig.10 A code diagram of a global transaction implementation for a specific business case provided by this application;

[0047] Fig.11 A code schematic diagram of order creation for a specific business case provided by this application;

[0048] Fig.12 A code diagram of the inventory, order, and account interface definitions for a specific business case provided for this application;

[0049] Fig.13 A schematic diagram of the structure of a distributed transaction implementation device provided in this application;

[0050] Fig.14 A structural diagram of an electronic device provided for this application. DETAILED DESCRIPTION

[0051] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0052] like Figure 1 As shown, there is a certain business involving service A and service B. In this business, services A and B can only rely on their respective local transactions. Assuming that all operations of service A have no exceptions, and the function of calling service B is successful, and the local transaction is committed, but an exception occurs during the operation of service B, it will eventually cause inconsistency between services A and B for the same business. On the contrary, it is possible that after service A calls service B, all subsequent operations of service B are executed, but service A has an exception in subsequent operations, and the local transaction rolls back all operations, but cannot roll back the operation of service B, which will also cause transaction inconsistency. To this end, the present application provides a distributed transaction implementation scheme, which effectively implements distributed transactions, improves the reliability of business processing and the ACID of global business, thereby ensuring the integrity of business data.

[0053] See also Figure 2 As shown, an embodiment of the present invention discloses a distributed transaction implementation method, which is applied to a server, including:

[0054] Step S11: Perform Seate configuration and Nacos registration based on the preset microservice application framework creation rules to obtain the corresponding target distributed microservice application framework.

[0055] In this embodiment, it is necessary to build a corresponding framework first, that is, to create rules based on the preset microservice application framework to perform Seate configuration and Nacos registration, including: in the process of Seate configuration, configure Nacos as the configuration center and registration center of Seate-server, and configure the preset relational database used to support local ACID transactions as the storage center of Seate-server to obtain the corresponding target Seate-server; after starting the target Seate-server, register the target Seate-server in the service list of Nacos. It can be understood that when a business involves multiple services, each service can only support its own local transactions. When global transactions need to be supported, a manager can be introduced. Combined with Figure 3 As shown in the figure, in Seata's architecture, there are three important roles: TC (Transaction Coordinator) is used to maintain the status of global and branch transactions, and drive global transactions to commit or roll back; TM (Transaction Manager) is used to define the scope of global transactions, start global transactions, commit or roll back global transactions; RM (Resource Manager) is used to manage resources for branch transaction processing, talk to TC to register branch transactions and report the status of branch transactions, and drive branch transactions to commit or roll back. RM is the various workshops in the factory, and they are the executors of their respective branches; TM and TC are the managers of the factory, helping the various workshops to coordinate work when cross-workshop cooperation is required.

[0056] Furthermore, in the target distributed microservice framework, Nacos is used as the transaction coordinator middleware and the service configuration center and service discovery and registration center, which enhances the flexibility of development and service interaction. In addition, Dubbo is used as the transaction coordinator and the RPC (Remote Procedure Call) communication tool between services, which greatly increases the communication efficiency.

[0057] Step S12: When performing distributed microservice deployment, for pending businesses related to multiple microservices, a global transaction is started based on the automatic transaction mode of the target distributed microservice application framework, and a preset relational database is used to intercept SQL statements corresponding to the pending businesses.

[0058] Specifically, this embodiment uses the automatic transaction mode (AT) of the target distributed microservice application framework and a preset relational database that supports local ACID transactions to implement distributed transactions. In specific applications, the preset relational database can be accessed through JDBC (Java Database Connectivity).

[0059] Combination Figure 4 As shown, in one stage, the target distributed microservice application framework intercepts business SQL (Structured Query Language) statements involving multiple microservices.

[0060] Step S13: performing statement parsing, mirroring, and row lock generation based on the automatic transaction mode and the SQL statement to obtain a corresponding global transaction execution result.

[0061] Specifically, in this embodiment, combined with Figure 4 As shown, firstly, the SQL semantics are parsed, the business data to be updated by the business SQL is found, and before the business data is updated, it is saved as a before image, then the business SQL is executed, the business data is updated, and after the business data is updated, it is saved as an after image, and finally a row lock is generated. All the above operations are completed in one database transaction, which ensures the atomicity of one-stage operation. That is, the statement parsing, image generation, and row lock generation based on the automatic transaction mode and the SQL statement to obtain the corresponding global transaction execution result include: for any of the microservices, in any transaction of the preset relational database, the SQL statement is semantically parsed based on the automatic transaction mode, and the business data to be updated corresponding to the business to be processed is determined based on the obtained semantic parsing result; based on the preset application interface, the business data to be updated is saved in the preset relational database in the form of a before image; the business data to be updated is updated by executing the SQL statement to obtain the corresponding updated data, and the row lock data corresponding to the updated data is generated to obtain the branch transaction execution result corresponding to the microservice; the corresponding global transaction execution result is determined based on each of the branch transaction execution results. It is understandable that the front image and the back image can be saved in the form of logs to the Figure 4 In the log table, there is a corresponding database transaction. Figure 4 The business table in can store business information such as the business to be processed and the intercepted SQL statements.

[0062] In addition, in this embodiment, the updated data can also be saved in the preset relational database in a post-mirroring manner based on the preset application program interface, and the row lock data can be saved in a preset table in the preset relational database. Figure 4 The lock table in.

[0063] Step S14: The transaction coordinator based on the target distributed microservice application framework analyzes the global transaction execution result, and uses the obtained analysis result to commit or roll back the global transaction execution result to complete the distributed transaction implementation operation corresponding to the business to be processed.

[0064] In this embodiment, in the second stage, the transaction coordinator will commit or roll back the transaction by analyzing the execution status of the global transaction. That is, the transaction coordinator based on the target distributed microservice application framework analyzes the execution result of the global transaction, including: analyzing the execution result of the global transaction based on Dubbo as the transaction coordinator in the target distributed microservice application framework to obtain corresponding analysis results.

[0065] Combination Figure 5 As shown, specifically, if the second stage is to be submitted, because the business SQL has been submitted to the database in the first stage, the target distributed microservice application framework only needs to delete the snapshot data and row locks saved in the first stage to complete the data cleanup. That is, the use of the obtained analysis results to submit the global transaction execution results includes: when it is determined to submit the global transaction execution results based on the obtained analysis results, the transaction manager in the target distributed microservice application framework deletes each of the front images, each of the back images, and the corresponding row lock data saved in the preset relational database to complete the corresponding transaction submission operation.

[0066] At the same time, in this embodiment, combined with Figure 6As shown, if the second stage is a rollback, the target distributed microservice application framework needs to roll back the business SQL that has been executed in the first stage to restore the business data. The rollback method is to restore the business data with the front image; but before restoring, it is necessary to first check the dirty write, compare the current business data of the database with the back image, if the two data are completely consistent, it means there is no dirty write, and the business data can be restored. If they are inconsistent, it means there is dirty write, and if dirty write occurs, it needs to be transferred to manual processing. That is, the global transaction execution result is rolled back using the obtained analysis result, including: when it is determined to commit the global transaction execution result based on the obtained analysis result, the current business data corresponding to the to-be-processed business and each of the back images saved in the preset relational database are compared based on the transaction manager to obtain the corresponding comparison result; when the comparison result shows that the current business data is consistent with each of the back images, the business data is restored based on each of the front images saved in the preset relational database.

[0067] In summary, this embodiment can ensure that the integrity of the data will not be destroyed when a failure or network interruption occurs, thereby improving reliability. For example, if a transaction involves multiple databases or services, when one of them fails, the distributed transaction can roll back or commit other transactions, thereby ensuring the integrity of the data. In addition, this embodiment can also add a new database or service without the need for secondary development, and can realize all the functions of the global transaction, thereby improving scalability. In addition, this embodiment builds the corresponding middleware, and when each service is used, it only needs to be configured, and the corresponding annotations can be used to realize the function without intrusion.

[0068] It can be seen that in this application, the server-side creates rules based on the preset microservice application framework to perform Seat configuration and Nacos registration to obtain the corresponding target distributed microservice application framework; when deploying distributed microservices, for pending businesses related to multiple microservices, a global transaction is opened based on the automatic transaction mode of the target distributed microservice application framework, and the SQL statement corresponding to the pending business is intercepted using the preset relational database; statement parsing, mirror generation, and row lock generation are performed based on the automatic transaction mode and the SQL statement to obtain the corresponding global transaction execution result; the transaction coordinator based on the target distributed microservice application framework analyzes the global transaction execution result, and uses the obtained analysis result to commit or roll back the global transaction execution result to complete the distributed transaction implementation operation corresponding to the pending business. That is to say, after this application builds the corresponding target distributed microservice application framework based on Seata and Nacos, it selects the automatic transaction mode and uses the preset relational database to perform global transaction execution, execution result analysis, and execution result submission or rollback on the pending businesses related to multiple microservices to complete the corresponding distributed transaction implementation operation. In this way, distributed transactions are effectively implemented, the reliability of business processing and the ACID of global business are improved, thereby ensuring the integrity of business data.

[0069] Combine the following Figure 7-12 The schematic diagram disclosed in the figure specifically illustrates the technical solution of the embodiment of the present application.

[0070] against Figure 7 The following is a specific practice case of business design. In this case, the main external dependencies are shown in Table 1.

[0071] Table 1

[0072]

[0073] like Figure 7 The business logic of users purchasing goods is shown in Table 1. The entire business logic is supported by three microservices: 1) Storage service: deduct the storage quantity for a given product. 2) Order service: create orders based on purchasing needs. 3) Account service: deduct the balance from the user account. Then, the framework is built based on the external dependencies shown in Table 1. First, in the process of configuring and starting Seata-server, Nacos is used as the configuration center and registration center of Seata-server, and MySQL (relational database management system) is used as the storage center of Seata-server. The specific Seata-server configuration code is as follows: Figure 8 shown.

[0074] Then, after Seata-server is started and registered in the service list of Nacos, you need to register the service name (Seata-server), group name (such as SEATA_GROUP), number of clusters, number of instances, number of healthy instances, and trigger protection threshold (select 'false' or 'true'). Then the client also needs to configure Seata information. The configuration center and registration center need to be consistent with Seata-server, and select AT mode (other modes can also be selected in combination with specific scenarios). The specific code is as follows Fig. 9 shown.

[0075] After configuring Seata and completing the framework construction, when the server uses global transactions, you only need to add the @GlobalTransactional annotation, which is almost non-invasive to the code. The specific transaction implementation is as follows Fig.10 , 11 , as shown in 12.

[0076] See also Fig.13 As shown, the embodiment of the present application also discloses a distributed transaction implementation device, which is applied to the server, including:

[0077] The framework construction module 11 is used to perform Seate configuration and Nacos registration based on the preset microservice application framework creation rules to obtain the corresponding target distributed microservice application framework;

[0078] The statement interception module 12 is used to start a global transaction based on the automatic transaction mode of the target distributed microservice application framework for pending businesses related to multiple microservices when deploying distributed microservices, and intercept SQL statements corresponding to the pending businesses using a preset relational database;

[0079] A result acquisition module 13 is used to perform statement parsing, image generation, and row lock generation based on the automatic transaction mode and the SQL statement to obtain a corresponding global transaction execution result;

[0080] The result processing module 14 is used to analyze the global transaction execution result based on the transaction coordinator of the target distributed microservice application framework, and use the obtained analysis result to commit or roll back the global transaction execution result to complete the distributed transaction implementation operation corresponding to the business to be processed.

[0081] Among them, for more specific working processes of the above-mentioned modules, please refer to the corresponding contents disclosed in the aforementioned embodiments, which will not be repeated here.

[0082] It can be seen that after building the corresponding target distributed microservice application framework based on Seata and Nacos in this application, the automatic transaction mode is selected and the preset relational database is used to perform global transaction execution, execution result analysis, and execution result submission or rollback on pending businesses related to multiple microservices to complete the corresponding distributed transaction implementation operations. In this way, distributed transactions are effectively implemented, the reliability of business processing and the ACID of global business are improved, thereby ensuring the integrity of business data.

[0083] In some specific embodiments, the result acquisition module 13 can be specifically used to: for any of the microservices, in any transaction of the preset relational database, perform semantic analysis on the SQL statement based on the automatic transaction mode, and determine the to-be-updated business data corresponding to the to-be-processed business based on the obtained semantic analysis result; save the to-be-updated business data in the preset relational database in a previous mirror image manner based on a preset application program interface; update the to-be-updated business data by executing the SQL statement to obtain corresponding updated data, and generate row lock data corresponding to the updated data to obtain a branch transaction execution result corresponding to the microservice; determine the corresponding global transaction execution result based on each of the branch transaction execution results.

[0084] In some specific embodiments, the distributed transaction implementation device can also be used to: save the updated data in the preset relational database in a post-mirroring manner based on the preset application interface, and save the row lock data to a preset table in the preset relational database.

[0085] In some specific embodiments, the result processing module 14 can be specifically used to: analyze the global transaction execution result based on Dubbo as the transaction coordinator in the target distributed microservice application framework to obtain a corresponding analysis result.

[0086] In some specific embodiments, the result processing module 14 can be specifically used for: when it is determined to commit the execution result of the global transaction based on the obtained analysis result, the transaction manager in the target distributed microservice application framework will delete each of the front images, each of the back images and the corresponding row lock data saved in the preset relational database to complete the corresponding transaction submission operation.

[0087] In some specific embodiments, the result processing module 14 can be specifically used for: when it is determined to commit the execution result of the global transaction based on the obtained analysis result, comparing the current business data corresponding to the business to be processed and the respective back images saved in the preset relational database based on the transaction manager to obtain a corresponding comparison result; when the comparison result shows that the current business data is consistent with the respective back images, restoring the business data based on the respective front images saved in the preset relational database.

[0088] In some specific embodiments, the framework construction module 11 can be specifically used to: during the process of Seate configuration, configure Nacos as the configuration center and registration center of Seate-server, and configure a preset relational database for supporting local ACID transactions as the storage center of Seate-server to obtain the corresponding target Seate-server; after starting the target Seate-server, register the target Seate-server in the service list of Nacos.

[0089] Furthermore, the present application also discloses an electronic device. Fig.14 This is a structural diagram of an electronic device 20 according to an exemplary embodiment. The content in the diagram cannot be regarded as any limitation on the scope of use of the present application.

[0090] Fig.14 A schematic diagram of the structure of an electronic device 20 provided in an embodiment of the present application. The electronic device 20 may specifically include: at least one processor 21, at least one memory 22, a power supply 23, a communication interface 24, an input / output interface 25, and a communication bus 26. The memory 22 is used to store a computer program, which is loaded and executed by the processor 21 to implement the relevant steps in the distributed transaction implementation method disclosed in any of the aforementioned embodiments. In addition, the electronic device 20 in this embodiment may specifically be an electronic computer.

[0091] In this embodiment, the power supply 23 is used to provide working voltage for each hardware device on the electronic device 20; the communication interface 24 can create a data transmission channel between the electronic device 20 and the external device, and the communication protocol it follows is any communication protocol that can be applied to the technical solution of the present application, and is not specifically limited here; the input and output interface 25 is used to obtain external input data or output data to the outside world, and its specific interface type can be selected according to specific application needs and is not specifically limited here.

[0092] In addition, the memory 22, as a carrier for storing resources, can be a read-only memory, a random access memory, a disk or an optical disk, etc. The resources stored thereon can include an operating system 221, a computer program 222, etc., and the storage method can be temporary storage or permanent storage.

[0093] The operating system 221 is used to manage and control the hardware devices on the electronic device 20 and the computer program 222, which can be Windows Server, Netware, Unix, Linux, etc. In addition to including a computer program that can be used to complete the distributed transaction implementation method performed by the electronic device 20 disclosed in any of the aforementioned embodiments, the computer program 222 can further include a computer program that can be used to complete other specific tasks.

[0094] Furthermore, the present application also discloses a computer-readable storage medium for storing a computer program; wherein, when the computer program is executed by a processor, the distributed transaction implementation method disclosed above is implemented. For the specific steps of the method, reference may be made to the corresponding contents disclosed in the above embodiments, and no further description will be given here.

[0095] In this specification, each embodiment is described in a progressive manner, and each embodiment focuses on the differences from other embodiments. The same or similar parts between the embodiments can be referred to each other. For the device disclosed in the embodiment, since it corresponds to the method disclosed in the embodiment, the description is relatively simple, and the relevant parts can be referred to the method part.

[0096] Professionals may further appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of the two. In order to clearly illustrate the interchangeability of hardware and software, the composition and steps of each example have been generally described in the above description according to function. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professionals and technicians may use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0097] The steps of the method or algorithm described in conjunction with the embodiments disclosed herein may be implemented directly using hardware, a software module executed by a processor, or a combination of the two. The software module may be placed in a random access memory (RAM), a memory, a read-only memory (ROM), an electrically programmable ROM, an electrically erasable programmable ROM, a register, a hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.

[0098] Finally, it should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.

[0099] The technical solution provided by the present application is introduced in detail above. Specific examples are used in this article to illustrate the principles and implementation methods of the present application. The description of the above embodiments is only used to help understand the method of the present application and its core idea. At the same time, for general technical personnel in this field, according to the idea of ​​the present application, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present application.

Claims

1. A distributed transaction implementation method, characterized in that: Applied to the server, including: Based on the preset microservice application framework creation rules, Seate configuration and Nacos registration are performed to obtain the corresponding target distributed microservice application framework; When performing distributed microservice deployment, for pending businesses related to multiple microservices, a global transaction is started based on the automatic transaction mode of the target distributed microservice application framework, and the SQL statements corresponding to the pending businesses are intercepted using a preset relational database; Based on the automatic transaction mode and the SQL statement, statement parsing, mirror generation, and row lock generation are performed to obtain corresponding global transaction execution results; The transaction coordinator based on the target distributed microservice application framework analyzes the global transaction execution result, and uses the obtained analysis result to commit or roll back the global transaction execution result to complete the distributed transaction implementation operation corresponding to the business to be processed.

2. The distributed transaction implementation method according to claim 1, characterized in that: The statement parsing, mirror generation, and row lock generation based on the automatic transaction mode and the SQL statement to obtain the corresponding global transaction execution result includes: For any of the microservices, in any transaction of the preset relational database, semantically parse the SQL statement based on the automatic transaction mode, and determine the business data to be updated corresponding to the business to be processed based on the obtained semantic parsing result; Based on a preset application program interface, the business data to be updated is saved in the preset relational database in a previous mirroring manner; The business data to be updated is updated by executing the SQL statement to obtain corresponding updated data, and row lock data corresponding to the updated data is generated to obtain a branch transaction execution result corresponding to the microservice; The corresponding global transaction execution result is determined based on the execution results of each branch transaction.

3. The distributed transaction implementation method according to claim 2, characterized in that: Also includes: The updated data is saved in the preset relational database in a post-mirroring manner based on the preset application program interface, and the row lock data is saved in a preset table in the preset relational database.

4. The distributed transaction implementation method according to claim 1, characterized in that: The transaction coordinator based on the target distributed microservice application framework analyzes the execution result of the global transaction, including: Based on Dubbo as a transaction coordinator in the target distributed microservice application framework, the global transaction execution result is analyzed to obtain a corresponding analysis result.

5. The distributed transaction implementation method according to claim 3, characterized in that: The step of submitting the global transaction execution result by using the obtained analysis result includes: When it is determined to commit the execution result of the global transaction based on the obtained analysis result, the transaction manager in the target distributed microservice application framework deletes each of the front images, each of the back images and the corresponding row lock data saved in the preset relational database to complete the corresponding transaction submission operation.

6. The distributed transaction implementation method according to claim 5, characterized in that: Rolling back the global transaction execution result using the obtained analysis result includes: When it is determined to submit the execution result of the global transaction based on the obtained analysis result, the current business data corresponding to the to-be-processed business and each of the back images saved in the preset relational database are compared based on the transaction manager to obtain a corresponding comparison result; When the comparison result shows that the current business data is consistent with each of the rear images, the business data is restored based on each of the front images that have been saved in the preset relational database.

7. The distributed transaction implementation method according to any one of claims 1 to 6, characterized in that: The Seate configuration and Nacos registration based on the preset microservice application framework creation rules include: During the Seate configuration process, configure Nacos as the configuration center and registration center of Seate-server, and configure the preset relational database used to support local ACID transactions as the storage center of Seate-server to obtain the corresponding target Seate-server; After starting the target Seate-server, register the target Seate-server in the service list of Nacos.

8. A distributed transaction implementation device, characterized in that: Applied to the server, including: The framework building module is used to perform Seate configuration and Nacos registration based on the preset microservice application framework creation rules to obtain the corresponding target distributed microservice application framework; A statement interception module is used to start a global transaction based on the automatic transaction mode of the target distributed microservice application framework for pending businesses related to multiple microservices when deploying distributed microservices, and intercept SQL statements corresponding to the pending businesses using a preset relational database; A result acquisition module, used to perform statement parsing, image generation, and row lock generation based on the automatic transaction mode and the SQL statement to obtain a corresponding global transaction execution result; A result processing module is used to analyze the global transaction execution result based on the transaction coordinator of the target distributed microservice application framework, and use the obtained analysis result to commit or roll back the global transaction execution result to complete the distributed transaction implementation operation corresponding to the business to be processed.

9. An electronic device, characterized in that: include: Memory, used to store computer programs; A processor, configured to execute the computer program to implement the distributed transaction implementation method as claimed in any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: Used to store a computer program, which, when executed by a processor, implements the distributed transaction implementation method as described in any one of claims 1 to 7.