Low-intrusion compensation method and device for distributed transactions

By intercepting and parsing business SQL statements in distributed transactions, generating data snapshots and automatically generating rollback SQL statements, the existing distributed transaction model is solved, and the existing distributed transaction model is compensated with low intrusion, reducing development costs and workload.

CN113138840BActive Publication Date: 2025-03-14INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202110448380.5
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-04-25
Publication Date
2025-03-14
Estimated Expiration
2041-04-25

AI Technical Summary

Technical Problem

The existing Saga model and TCC model have high invasiveness and high transformation costs in distributed transactions, increasing system complexity and developer workload.

Method used

Low-invasion distributed transaction compensation is achieved by intercepting the business SQL statement of each sub-transaction upon receiving the main transaction request, parsing its type and conditions, generating pre- and post-data snapshots, and generating rollback SQL statements when rolling back the request.

Benefits of technology

Reduces business intrusion and developer workload, reduces development costs, and saves unnecessary workload by automatically generating back-pull logic.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113138840B_ABST
    Figure CN113138840B_ABST
Patent Text Reader

Abstract

The present invention discloses a low-intrusion compensation method and device for distributed transactions, and relates to the technical field of automatic programming, wherein the method comprises: when receiving a main transaction request, intercepting the business SQL statement of each sub-transaction; parsing the business SQL statement of each sub-transaction, obtaining the SQL statement type and condition of each sub-transaction as the parsing result; generating a pre-data snapshot before the execution of the business SQL statement of each sub-transaction and a post-data snapshot after the execution of the business SQL statement according to the parsing result of each sub-transaction; when receiving a rollback request for each sub-transaction, generating a rollback SQL statement of each sub-transaction according to the pre-data snapshot and post-data snapshot corresponding to each sub-transaction; the rollback SQL statement is used to complete the backwash operation. The present invention can reduce the intrusiveness of the business and the development amount of the staff, and reduce the development cost.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of automatic programming, and in particular to a low-intrusion compensation method and device for distributed transactions. Background Art

[0002] This section is intended to provide a background or context to the embodiments of the invention recited in the claims. No admission is made that the description herein is prior art by inclusion in this section.

[0003] Although the existing Saga model and TCC model each have their own focus, both distributed transaction models are somewhat invasive to the business. The Saga model requires that each business method has its corresponding business compensation method, while the TCC model requires the disassembly of the existing business design and that a business method needs to be replaced by a set of three methods: try, confirm, and cancel. Therefore, the two existing distributed transaction models will increase system complexity and the workload of developers, resulting in an increase in development costs. Therefore, the two existing distributed transaction models have the problems of high invasiveness and high transformation costs. Summary of the invention

[0004] An embodiment of the present invention provides a low-intrusion compensation method for distributed transactions, which is used to reduce the intrusion of services and the development workload of staff. The method includes:

[0005] When receiving the main transaction request, intercept the business SQL statement of each sub-transaction;

[0006] Parse the business SQL statement of each sub-transaction, and obtain the SQL statement type and condition of each sub-transaction as the parsing result;

[0007] Generate a pre-data snapshot before the execution of the business SQL statement of each sub-transaction and a post-data snapshot after the execution of the business SQL statement according to the parsing result of each sub-transaction;

[0008] When a rollback request for each subtransaction is received, a rollback SQL statement for each subtransaction is generated according to a preceding data snapshot and a succeeding data snapshot of each subtransaction; the rollback SQL statement is used to complete the flush back operation.

[0009] The embodiment of the present invention further provides a low-intrusion compensation device for distributed transactions, which is used to reduce the intrusion of services and the development workload of staff. The device includes:

[0010] The interception unit is used to intercept the business SQL statement of each sub-transaction when receiving the main transaction request;

[0011] A parsing unit, used to parse the business SQL statement of each sub-transaction, and obtain the SQL statement type and condition of each sub-transaction as a parsing result;

[0012] A data snapshot generating unit, used to generate a pre-data snapshot before the execution of the business SQL statement of each sub-transaction and a post-data snapshot after the execution of the business SQL statement according to the parsing result of each sub-transaction;

[0013] The compensation unit is used to generate a rollback SQL statement for each subtransaction according to the preceding data snapshot and the following data snapshot of each subtransaction when receiving the rollback request of each subtransaction; the rollback SQL statement is used to complete the backwash operation.

[0014] An embodiment of the present invention further provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned low-intrusion compensation method for distributed transactions when executing the computer program.

[0015] An embodiment of the present invention further provides a computer-readable storage medium storing a computer program for executing the above-mentioned low-intrusion compensation method for distributed transactions.

[0016] In the embodiment of the present invention, the low-intrusion compensation scheme of distributed transactions, compared with the technical scheme in the prior art that increases the complexity of the system and the workload of developers in the distributed transaction model, includes: intercepting the business SQL statement of each sub-transaction when receiving a main transaction request; parsing the business SQL statement of each sub-transaction, obtaining the SQL statement type and condition of each sub-transaction as the parsing result; generating a pre-data snapshot before the execution of the business SQL statement of each sub-transaction and a post-data snapshot after the execution of the business SQL statement according to the parsing result of each sub-transaction; generating a rollback SQL statement of each sub-transaction according to the pre-data snapshot and the post-data snapshot of each sub-transaction when receiving a rollback request for each sub-transaction; the rollback SQL statement is used to complete the backwash operation, which can reduce the intrusiveness of the business and the development workload of the staff, thereby reducing the development cost. BRIEF DESCRIPTION OF THE DRAWINGS

[0017] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the following briefly introduces the drawings required for use in the embodiments or the prior art descriptions. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. In the drawings:

[0018] Figure 1It is a flowchart of a low-intrusive compensation method for distributed transactions in an embodiment of the present invention;

[0019] Figure 2 A schematic diagram of a flow chart of a method for executing a distributed transaction on a client side in an embodiment of the present invention;

[0020] Figure 3 A schematic diagram of a process flow of a method for executing a distributed transaction on a server side according to an embodiment of the present invention;

[0021] Figure 4 It is a flowchart of a low-intrusive compensation method for distributed transactions in another embodiment of the present invention;

[0022] Figure 5 It is a schematic diagram of the structure of a low-intrusive compensation device for distributed transactions in an embodiment of the present invention. DETAILED DESCRIPTION

[0023] To make the purpose, technical solution and advantages of the embodiments of the present invention more clear, the embodiments of the present invention are further described in detail below in conjunction with the accompanying drawings. Here, the exemplary embodiments of the present invention and their descriptions are used to explain the present invention, but are not intended to limit the present invention.

[0024] Before introducing the embodiments of the present invention, the terms involved in the embodiments of the present invention are first introduced.

[0025] 1. The Saga transaction model is a mainstream distributed transaction model in the industry. Through the analysis of business logic, the Saga transaction model decomposes the business logic method into two methods, one is the positive method and the other is the negative method:

[0026] Correct method: Define business logic operations, and the data will be immediately available after execution.

[0027] Negative method: defines the business logic operation of rolling back the corresponding positive method.

[0028] 2. The TCC (Try-Confirm-Cancel) transaction model is a two-stage distributed transaction model that is the mainstream in the industry. By decomposing the business logic, the TCC model decomposes the business logic into two stages: the first stage is the Try stage, and the second stage is the Confirm or Cancel stage:

[0029] Try: Complete all business checks and reserve necessary business resources. It is necessary to ensure that Confirm will succeed after Try is completed.

[0030] Confirm: The actual business logic is executed without any business check, and only the business resources reserved in the try phase are used.

[0031] Cancel: Releases the business resources reserved in the try phase.

[0032] The three words try, confirm, and cancel are the three-letter English references to the TCC transaction model. Try is the first-stage resource reservation. In the first stage, it checks whether the database resources can meet the current business operation. If they can, the resources are locked. Confirm is the second-stage resource submission. If the resources of each link in the first stage of the entire distributed transaction are successfully reserved, the second stage initiates resource submission and processes these reserved resources. Cancel is the second-stage resource cancellation. If the resource reservation of a link in the first stage of the entire distributed transaction fails, the second stage initiates resource cancellation and cancels the resources that have been successfully reserved.

[0033] 3. JDBC represents a component for operating the database at the Java layer. Generally, projects will introduce this component to operate the database.

[0034] 4. SQL statements represent a language that can be recognized and executed by the database. In essence, all business operations are performed on the data in the database through SQL statements.

[0035] 5. Connection (commit, rollback) and Statement. These two are two classes in the JDBC component. Each time an application operates the database, it needs to obtain a database connection, i.e., Connection. Then, the specific SQL statement needs to be executed using Statement. Then, the commit method or rollback method of the database connection is called to persist the operation in the database or roll back the operation.

[0036] 6. ConnectionProxy and StatementProxy, these two are also the English names of the classes, which are the proxy class of the Connection class and the proxy class of the Statement respectively.

[0037] 7. Intrusiveness refers to the cost of transforming an application to use a framework. For example, the cost of transforming a mature application to use the SpringBoot framework is very low. It can be connected to the SpringBoot framework without modifying the business code and database structure, just a few annotations are needed. If the use of a framework requires a significant modification of the existing business code or even the disassembly of the existing database table structure, then the intrusiveness of this framework is very high.

[0038] In view of the problems of high invasiveness and high transformation cost of the two existing distributed transaction models, the present invention overcomes the above two problems and provides a low-invasive compensation solution for distributed transactions, which is a low-invasive automatic compensation transformation solution for distributed transactions. Specifically, the present invention is based on the native database component of the proxy JDBC, intercepts the business SQL in the proxy method, and then parses the business SQL to obtain the SQL statement type and conditions, generates and stores the before and after data snapshots through the parsing results, and provides data basis for the subsequent generation of fault-tolerant methods. The low-invasive compensation solution for distributed transactions is introduced in detail below.

[0039] Figure 1 FIG. 1 is a flow chart of a low-intrusive compensation method for distributed transactions in an embodiment of the present invention. Figure 1 As shown, the method comprises the following steps:

[0040] Step 101: When receiving a main transaction request, intercept the business SQL statement of each sub-transaction;

[0041] Step 102: parse the business SQL statement of each sub-transaction, and obtain the SQL statement type and condition of each sub-transaction as the parsing result;

[0042] Step 103: Generate a pre-data snapshot before the execution of the business SQL statement of each sub-transaction and a post-data snapshot after the execution of the business SQL statement according to the parsing result of each sub-transaction;

[0043] Step 104: upon receiving a rollback request for each subtransaction, a rollback SQL statement for each subtransaction is generated according to the preceding data snapshot and the succeeding data snapshot of each subtransaction; the rollback SQL statement is used to complete the flush back operation.

[0044] The low-intrusive compensation method for distributed transactions in the embodiment of the present invention is based on the native database component of the proxy JDBC, intercepts the business SQL in the proxy method, and then parses the business SQL to obtain the SQL statement type and conditions, generates and stores the data snapshots before and after the parsing results, and provides data basis for the subsequent generation of fault-tolerant methods, which can reduce the intrusiveness of the business and the development workload of the staff, and reduce the development cost. The various steps involved in the method are introduced in detail below.

[0045] 1. First, the above step 101 is introduced.

[0046] When implementing it, Figure 2 As shown, when a main transaction request is received, the business SQL statement of each sub-transaction is intercepted.

[0047] 2. Next, for ease of understanding, the above steps 102 and 103 are introduced together.

[0048] In specific implementation, the above steps 102 and 103 are the logic of the Statement proxy object, such as Figure 2 As shown:

[0049] 1. Parse the business SQL statements and extract the SQL statement types and conditions. The types can include update, delete, and insert, and the conditions can be simple where conditions.

[0050] 2. Before executing the business SQL, perform a previous data snapshot query based on the parsing results to obtain a previous data snapshot before the business SQL statement is executed.

[0051] 3. Execute business SQL statements.

[0052] 4. After executing the business SQL, perform a post-data snapshot query based on the parsing results to obtain a post-data snapshot after the business SQL statement is executed.

[0053] 5. Return the combined preceding data snapshot and following data snapshot to the Connection proxy object.

[0054] From the above, it can be seen that in one embodiment, the native database component Statement proxy object of the proxy JDBC can be used to execute: parsing the business SQL statement of each subtransaction, obtaining the SQL statement type and conditions of each subtransaction as the parsing result, and generating a pre-data snapshot of the business SQL statement of each subtransaction before the execution of the business SQL statement and a post-data snapshot of the business SQL statement after the execution of the business SQL statement according to the parsing result of each subtransaction, that is, parsing the business SQL statement of each subtransaction, obtaining the SQL statement type and conditions of each subtransaction as the parsing result, and generating a pre-data snapshot of the business SQL statement of each subtransaction before the execution of the business SQL statement and a post-data snapshot of the business SQL statement after the execution of the business SQL statement according to the parsing result of each subtransaction, which may include: parsing the business SQL statement of each subtransaction using the native database component Statement proxy object of the proxy JDBC, obtaining the SQL statement type and conditions of each subtransaction as the parsing result, and generating a pre-data snapshot of the business SQL statement of each subtransaction before the execution of the business SQL statement and a post-data snapshot of the business SQL statement after the execution of the business SQL statement according to the parsing result of each subtransaction.

[0055] 3. Next, the preferred steps after the above step 103 are introduced.

[0056] In specific implementation, the logic of the Connection proxy object, such as Figure 2 As shown:

[0057] 1. Register sub-transaction information with the server.

[0058] 2. After successful registration, obtain the native Statement object and store the pre- and post-data snapshots in the local database of the application. That is, in one embodiment, the low-intrusive compensation method for distributed transactions may also include: after successfully registering the sub-transaction information with the server, store the pre- and post-data snapshots of each sub-transaction in the local database.

[0059] 3. Execute the commit method, and in order to achieve transaction consistency, commit the business SQL and the snapshot storage SQL as a transaction. That is, in one embodiment, the low-intrusion compensation method of the distributed transaction may also include: after successfully registering the sub-transaction information with the server, commit the business SQL statement and the snapshot storage SQL statement as a transaction.

[0060] In addition, it can be seen from the above that in one embodiment, the native database component Connection proxy object of the proxy JDBC can be used to execute the step of storing the pre-data snapshot and post-data snapshot of each sub-transaction in the local database after successfully registering the sub-transaction information with the server.

[0061] In addition, it can be seen from the above that in one embodiment, the native database component Connection proxy object of the proxy JDBC can be used to execute: after successfully registering the sub-transaction information with the server, the business SQL statement and the snapshot storage SQL statement are submitted as a transaction step.

[0062] 4. Next, the above step 104 is introduced.

[0063] In specific implementation, the above is the first-stage operation of the subtransaction, which is mainly transformed to obtain data snapshots before and after the business SQL is executed, and then the snapshot storage and business SQL execution are regarded as one transaction. The second-stage operation of the subtransaction is initiated by the server. When the main transaction reports a commit request (persistence operation request), such as Figure 3 As shown in the figure, the server queries all sub-transaction information under the main transaction and then initiates a commit request to all sub-transactions. After the sub-transaction commit request reaches the application side, the application side deletes the data snapshots before and after the sub-transaction. Figure 3As shown, the server queries all subtransaction information under the main transaction and then initiates a rollback request to all subtransactions. After the subtransaction rollback request reaches the application side, the application side (application side, client side) parses the pre- and post-data snapshots of the subtransaction into a rollback SQL statement for execution, and performs backwashing of one-stage operations. That is, when receiving each subtransaction rollback request, a rollback SQL statement for each subtransaction is generated according to the pre- and post-data snapshots of each subtransaction, and the rollback SQL statement is used to complete the backwash operation.

[0064] From the above, it can be seen that in one embodiment, Figure 4 As shown, the low-intrusion compensation method for distributed transactions may further include step 105: upon receiving a persistence operation request for each sub-transaction, deleting a preceding data snapshot and a succeeding data snapshot corresponding to each sub-transaction.

[0065] An example is given below to illustrate how to implement the present invention.

[0066] For example, a person named Zhangsan has 1,000 yuan in his bank card, and a person named Lisi has 1,000 yuan in his bank card. Because one is from the north and the other is from the south, their data is stored in the north center database and the other in the south center database.

[0067] The table name of the North Center data is north-account (as shown in Table 1 below). The table structure has only two fields: id and amount.

[0068] The table name of the South Center data is south-account (as shown in Table 2 below). The table structure has only two fields, id and amount.

[0069] Now a business is executed, which is to deduct 100 from the bank card of zhangsan, and add 100 to the bank card of lisi.

[0070] Table 1

[0071] id amout zhangsan 1000

[0072] Table 2

[0073] id amout lisi 1000

[0074] First, execute the first sub-transaction, zhangsan deducts money. Register the sub-transaction with the server, generate a pre-snapshot, execute the business SQL, generate a post-snapshot, and report the success status of the sub-transaction. Then the pre- and post-snapshots are stored in the local database.

[0075] Previous snapshot:

[0076] A map structure, the keys in the map are id, amod, tableName, SQLType

[0077]

[0078]

[0079] Post snapshot:

[0080] A map structure, the keys in the map are id, amod, tableName, SQLType

[0081]

[0082] Then execute the second sub-transaction, lisi increase the payment. Perform the same operation, but the database fails when executing the business SQL, the application code side (application side, client side) gets an exception and reports the failure of this sub-transaction to the server.

[0083] Next, after receiving the information that the sub-transaction failed, the server determines that the main transaction has failed and initiates a rollback request to all sub-transactions under the main transaction. The zhangsan account then generates a reverse SQL statement (rollback SQL statement) based on the generated before and after snapshots to execute and cancel the original successful business SQL operation.

[0084] In summary, the present invention intercepts the business SQL when it is executed by proxying the database component of the native JDBC, generates the data snapshots before and after, and stores them in the local database, thereby reducing the intrusiveness of the business and the development workload of the staff. The main points are as follows:

[0085] 1. Low business intrusion. A proxy layer is built at the database level to generate pre- and post-data snapshots (pre- and post-data snapshots), which basically makes the business invisible.

[0086] 2. The backwash logic of the two-stage method can be automatically generated (i.e., the rollback SQL statement is automatically generated), saving unnecessary work and reducing the workload of staff.

[0087] The present invention also provides a low-intrusive compensation device for distributed transactions, as described in the following embodiments. Since the principle of solving the problem by the device is similar to that of the low-intrusive compensation method for distributed transactions, the implementation of the device can refer to the implementation of the low-intrusive compensation method for distributed transactions, and the repeated parts will not be repeated.

[0088] Figure 5 FIG. 1 is a schematic diagram of the structure of a low-intrusive compensation device for distributed transactions in an embodiment of the present invention. Figure 5 As shown, the device comprises:

[0089] The interception unit 01 is used to intercept the business SQL statement of each sub-transaction when receiving the main transaction request;

[0090] Parsing unit 02, used to parse the business SQL statement of each sub-transaction, and obtain the SQL statement type and condition of each sub-transaction as the parsing result;

[0091] The data snapshot generating unit 03 is used to generate a pre-data snapshot before the execution of the business SQL statement of each sub-transaction and a post-data snapshot after the execution of the business SQL statement according to the parsing result of each sub-transaction;

[0092] The compensation unit 04 is used to generate a rollback SQL statement for each subtransaction according to the preceding data snapshot and the succeeding data snapshot of each subtransaction when receiving the rollback request of each subtransaction; the rollback SQL statement is used to complete the flushing operation.

[0093] In one embodiment, the low-intrusive compensation device for distributed transactions may further include: a deleting unit, configured to delete the preceding data snapshot and the succeeding data snapshot corresponding to each sub-transaction upon receiving a persistence operation request for each sub-transaction.

[0094] In one embodiment, the low-intrusive compensation device for distributed transactions may further include: a storage unit, configured to store a pre-data snapshot and a post-data snapshot of each sub-transaction in a local database after successfully registering the sub-transaction information with the server.

[0095] In one embodiment, after successfully registering the sub-transaction information with the server, the storage unit may use the native database component Connection proxy object of the proxy JDBC to store the pre-data snapshot and post-data snapshot of each sub-transaction in the local database.

[0096] In one embodiment, the low-intrusion compensation method for distributed transactions may further include: a commit unit, configured to commit the service SQL statement and the snapshot storage SQL statement as a transaction after successfully registering the sub-transaction information with the server.

[0097] In one embodiment, the submitting unit may submit the business SQL statement and the snapshot storage SQL statement as a transaction by using the native database component Connection proxy object of the proxy JDBC after successfully registering the sub-transaction information with the server.

[0098] In one embodiment, the parsing unit and the data snapshot generating unit can specifically utilize the native database component Statement proxy object of the proxy JDBC to parse the business SQL statement of each subtransaction, obtain the SQL statement type and condition of each subtransaction as the parsing result, and generate a pre-data snapshot before the execution of the business SQL statement of each subtransaction and a post-data snapshot after the execution of the business SQL statement based on the parsing result of each subtransaction.

[0099] An embodiment of the present invention further provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the above-mentioned low-intrusion compensation method for distributed transactions when executing the computer program.

[0100] An embodiment of the present invention further provides a computer-readable storage medium storing a computer program for executing the above-mentioned low-intrusion compensation method for distributed transactions.

[0101] In the embodiment of the present invention, the low-intrusion compensation scheme of distributed transactions, compared with the technical scheme in the prior art that increases the complexity of the system and the workload of developers in the distributed transaction model, includes: intercepting the business SQL statement of each sub-transaction when receiving a main transaction request; parsing the business SQL statement of each sub-transaction, obtaining the SQL statement type and condition of each sub-transaction as the parsing result; generating a pre-data snapshot before the execution of the business SQL statement of each sub-transaction and a post-data snapshot after the execution of the business SQL statement according to the parsing result of each sub-transaction; generating a rollback SQL statement of each sub-transaction according to the pre-data snapshot and the post-data snapshot of each sub-transaction when receiving a rollback request for each sub-transaction; the rollback SQL statement is used to complete the backwash operation, which can reduce the intrusiveness of the business and the development workload of the staff, thereby reducing the development cost.

[0102] Those skilled in the art will appreciate that embodiments of the present invention may be provided as methods, systems, or computer program products. Therefore, the present invention may take the form of a complete hardware embodiment, a complete software embodiment, or an embodiment combining software and hardware. Moreover, the present invention may take the form of a computer program product implemented on one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) containing computer-usable program code.

[0103] The present invention is described with reference to flowcharts and / or block diagrams of methods, devices (systems), and computer program products according to embodiments of the present invention. It should be understood that each process and / or block in the flowchart and / or block diagram, as well as the combination of processes and / or blocks in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0104] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0105] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0106] The specific embodiments described above further illustrate the objectives, technical solutions and beneficial effects of the present invention in detail. It should be understood that the above description is only a specific embodiment of the present invention and is not intended to limit the scope of protection of the present invention. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present invention should be included in the scope of protection of the present invention.

Claims

1. A low-intrusive compensation method for distributed transactions, characterized in that: The method is applied to a banking business scenario, and the method includes: When receiving the main transaction request, intercept the business SQL statement of each sub-transaction; The native database component Statement proxy object of the proxy JDBC is used to perform the following steps: parsing the business SQL statement of each sub-transaction, and obtaining the SQL statement type and condition of each sub-transaction as the parsing result; The native database component Statement proxy object of the proxy JDBC is used to perform the following steps: before executing the business SQL, perform a pre-data snapshot query based on the parsing result of each sub-transaction to generate a pre-data snapshot before the business SQL statement of each sub-transaction is executed; execute the business SQL statement, perform a post-data snapshot query based on the parsing result of each sub-transaction to generate a post-data snapshot after the business SQL statement of each sub-transaction is executed; The native database component Connection proxy object of the proxy JDBC is used to perform the following steps: after successfully registering the sub-transaction information with the server, storing the pre-data snapshot and post-data snapshot of each sub-transaction in the local database; When receiving a rollback request for each subtransaction, a rollback SQL statement for each subtransaction is generated according to the preceding data snapshot and the succeeding data snapshot of each subtransaction; the rollback SQL statement is used to complete the flush operation; The native database component Connection proxy object of the proxy JDBC is used to execute: after successfully registering the sub-transaction information with the server, the business SQL statement and the snapshot storage SQL statement are submitted as a transaction.

2. The low-intrusion compensation method for distributed transactions according to claim 1, characterized in that: Also includes: When receiving a persistence operation request for each sub-transaction, the preceding data snapshot and the succeeding data snapshot corresponding to each sub-transaction are deleted.

3. A low-intrusion compensation device for distributed transactions, characterized in that: The device is applied to banking business scenarios and includes: The interception unit is used to intercept the business SQL statement of each sub-transaction when receiving the main transaction request; The parsing unit is used to use the native database component Statement proxy object of the proxy JDBC to perform: parsing the business SQL statement of each sub-transaction, and obtaining the SQL statement type and condition of each sub-transaction as the parsing result; The data snapshot generation unit is used to use the native database component Statement proxy object of the proxy JDBC to perform the following steps: before executing the business SQL, perform a pre-data snapshot query according to the parsing result of each sub-transaction to generate a pre-data snapshot before the execution of the business SQL statement of each sub-transaction; execute the business SQL statement, perform a post-data snapshot query according to the parsing result of each sub-transaction, and generate a post-data snapshot after the execution of the business SQL statement of each sub-transaction; The storage unit is used to use the native database component Connection proxy object of the proxy JDBC to perform the following steps: after successfully registering the sub-transaction information with the server, storing the pre-data snapshot and post-data snapshot of each sub-transaction in the local database; A compensation unit, configured to generate a rollback SQL statement for each subtransaction according to a preceding data snapshot and a succeeding data snapshot of each subtransaction upon receiving a rollback request for each subtransaction; the rollback SQL statement is used to complete a backwash operation; The commit unit is used to use the native database component Connection proxy object of the proxy JDBC to execute: after successfully registering the sub-transaction information with the server, the business SQL statement and the snapshot storage SQL statement are submitted as a transaction.

4. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the method according to any one of claims 1 to 2 is implemented.

5. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program for executing the method according to any one of claims 1 to 2.

Citation Information

Patent Citations

  • Method and system for processing distributed transaction

    CN106033439A