Flexible Distributed Transaction Center System Based on Java Probe Technology

Through the flexible distributed transaction center system based on Java probe technology, it solves the problems of code intrusion and difficulty in processing high-concurrency scenarios in the existing technology, realizes low-intrusion distributed transaction processing and rollback operations, and supports old version of Java projects. transformation, and balance consistency and performance in high concurrency scenarios.

CN114281838BActive Publication Date: 2024-10-11ZHEJIANG EXPRESSWAY INFO ENG TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202111323387.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-08
Publication Date
2024-10-11
Estimated Expiration
2041-11-08

AI Technical Summary

Technical Problem

The existing distributed transaction framework has code intrusion problems when supporting the transformation of low-version Java projects and RPC frameworks, and it is difficult to handle distributed transaction processing and rollback in high-concurrency scenarios.

Method used

Using a flexible distributed transaction center system based on Java probe technology, the Java probe monitoring module records the interface call chain and database snapshots, the SQL analysis module intercepts and parses SQL statements, and the logging module saves snapshots for rollback operations, distributed The transaction server manages global transactions and rollback requests, reducing intrusion into user code and databases.

Benefits of technology

It achieves low-invasive code transformation, reduces the amount of user code writing, supports the transformation of old versions of Java projects, balances consistency and performance in high-concurrency scenarios, and improves system flexibility.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114281838B_ABST
    Figure CN114281838B_ABST
Patent Text Reader

Abstract

The present invention discloses a flexible distributed transaction center system based on Java probe technology, comprising: a distributed transaction client and a distributed transaction server; the distributed transaction client comprises a Java probe monitoring module, an SQL analysis module, a log recording module and a local transaction rollback module; the distributed transaction server comprises a transaction registration module, a global transaction rollback module and a branch transaction driver module. The service interface is monitored by the Java probe monitoring module, the call chain and call status of the interface between the services are recorded, the database snapshots before and after the execution of each interface are saved, and a probe log is generated for rollback operations. The flexible distributed transaction center system based on Java probe technology provided by the present invention realizes low code intrusion by replacing interceptors or aspects with probes, and the characteristics of accessing the system can be achieved by modifying bytecodes without modifying user code.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention relates to a flexible distributed transaction center system based on Java probe technology. Background Art

[0002] In the microservice scenario, there are interrelated businesses between multiple services, and they need to operate their own databases separately. Simple local transactions can only guarantee the transaction consistency of a single service, but cannot guarantee the transaction consistency between multiple services. Therefore, distributed transactions are needed to solve the problem of transaction consistency of multiple services in the microservice scenario. The existing solution is to ensure transaction consistency through distributed transaction solutions such as AT and TCC. Existing distributed transaction frameworks, such as Seata and Hmily, obtain the original SQL statement through interceptors or proxy SQL, and then analyze the SQL statement type by parsing the SQL language, and save the database snapshot according to the type for subsequent lost property rollback operations. However, this implementation method is difficult to support the transformation of low-version Java projects, and is bound to the Java RPC framework. In addition, transformation through this type of distributed transaction framework will have code intrusion problems, and the code needs to be partially transformed.

[0003] The main drawback of the existing technology is that the projects transformed through the distributed transaction framework need to transform the original code and even the database, which is a large amount of work. Since the user's existing projects are bound to a certain extent to the RPC framework already in use, the existing distributed transaction framework is difficult to support the transformation of old projects, and the supported framework version is not compatible with the old version. Some distributed transaction frameworks add locks in the process and are difficult to support distributed transaction processing and rollback in high-concurrency scenarios. Summary of the invention

[0004] The present invention provides a flexible distributed transaction center system based on Java probe technology, which adopts the following technical solutions:

[0005] A flexible distributed transaction center system based on Java probe technology, comprising:

[0006] Distributed transaction client and distributed transaction server;

[0007] The distributed transaction client connects to the distributed transaction server;

[0008] The distributed transaction client includes:

[0009] Java probe monitoring module, which is used to monitor the service interface, record the call chain and call status of the interface between services, save the database snapshot before and after the execution of each interface, and generate probe logs;

[0010] SQL analysis module, used to intercept the SQL statements executed by the interface calling the database and analyze the SQL statements;

[0011] The logging module is used to query the data in the database according to the analysis results of the SQL analysis module, and save the snapshot of the data to the call log entry of the interface for subsequent rollback operations;

[0012] The local transaction rollback module is used to query the local recorded database snapshot according to the traceid transmitted by the distributed transaction server after the distributed transaction server notifies the rollback and gives the rollback range, and rolls back the local transaction according to the database snapshot;

[0013] The distributed transaction server includes:

[0014] The transaction registration module is used to create a new global transaction and generate a traceid based on the registration information sent by the distributed transaction client when the microservice calls the interface and return it to the distributed transaction client;

[0015] The global transaction rollback module is used to receive the traceid sent by the distributed transaction client after detecting an abnormal or failed database operation, query the corresponding global transaction according to the traceid, change the status of the corresponding global transaction to rollback, and send a rollback request;

[0016] The branch transaction driver module is used to query the call chain according to the traceid after receiving the rollback request and notify each service on the call chain to perform the rollback operation.

[0017] Furthermore, the SQL analysis module formats and preprocesses the intercepted SQL statements, and then parses the formatted SQL statements through the integrated SQL parser GSP, stores the parsed SQL type in a single record of the probe log, converts the other parsed information into SELECT statements and executes them in the database, and at the same time obtains the value of the single record modified this time and stores it in the probe log as a snapshot.

[0018] Furthermore, the log recording module queries the data in the database through different strategies according to the SQL type analyzed by the SQL analysis module.

[0019] Furthermore, the transaction registration module generates a globally unique traceid through the snowflake algorithm to mark the call chain.

[0020] Furthermore, the flexible distributed transaction center system based on Java probe technology also includes a system access configuration module;

[0021] The system access configuration module is connected to the distributed transaction client for users to configure parameters of microservices accessing the system.

[0022] Furthermore, the system access configuration module is used for users to configure the database type, database address, and username and password of the microservice that needs to be accessed.

[0023] Furthermore, the system access configuration module is used for the user to configure the SQL statement variable name or connection method, and the SQL analysis module intercepts the variable according to the configured SQL statement variable name to obtain the SQL statement for parsing or directly obtains the SQL statement according to the configured connection method.

[0024] Furthermore, the system access configuration module is used for users to configure whitelist information of microservices that need to be accessed, and the whitelist information includes interface information that does not need to be monitored in the microservices that need to be accessed.

[0025] Furthermore, the system access configuration module is used for users to configure their own network transmission mode.

[0026] Furthermore, after the branch transaction driver module notifies each distributed transaction client on the call chain to perform a rollback operation, it also receives the rollback operation results fed back by each distributed transaction client, and sends the collected rollback operation results to the global transaction rollback module.

[0027] The benefit of the present invention lies in the flexible distributed transaction center system based on Java probe technology, which achieves low code intrusion by replacing interceptors or aspects with probes. The characteristics of accessing the system can be achieved by modifying the bytecode without modifying the user code, which greatly reduces the business transformation that users need to perform in the business code program.

[0028] The present invention is also beneficial in that it provides a flexible distributed transaction center system based on Java probe technology, which replaces database access with probe logs, eliminates intrusion into user databases, and automatically performs database rollback operations through logs. This method greatly reduces the code that users need to write and further reduces intrusion into user codes. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] Figure 1 It is a schematic diagram of the flexible distributed transaction center system based on Java probe technology of the present invention. DETAILED DESCRIPTION

[0030] The present invention is described in detail below with reference to the accompanying drawings and specific embodiments.

[0031] like Figure 1The flexible distributed transaction center system based on Java probe technology of the present application is shown, which includes: a distributed transaction client and a distributed transaction server, and the distributed transaction client is connected to the distributed transaction server.

[0032] The distributed transaction client includes a Java probe monitoring module, a SQL analysis module, a logging module, and a local transaction rollback module.

[0033] Among them, the Java probe monitoring module is used to monitor the service interface, record the call chain and call status of the interface between each service, save the database snapshot before and after the execution of each interface, and generate a probe log.

[0034] Before each interface runs, the Java probe monitoring module will register the interface with the distributed transaction server and generate a globally unique traceid through the distributed transaction server's snowflake algorithm to mark the call chain. The traceid generated here will be passed to the interface and all downstream and branch service interfaces called. The downstream service interface can register the transaction of this database operation under the same global transaction of the transaction center through the traceid.

[0035] The SQL analysis module is used to intercept the SQL statements executed by the interface calling the database and analyze the SQL statements. Specifically, the SQL analysis module pre-processes the intercepted SQL statements, including but not limited to converting multiple spaces into single spaces, replacing uppercase and lowercase letters, etc. Then, the formatted SQL statements are parsed through the integrated SQL parser GSP, and the information required after parsing is extracted and temporarily stored. The parser will split the SQL statement into SQL type, table name, table alias, modified column, modified row, modified value, modified condition, SQL statement Limit and Order By, etc., and save different values ​​according to the type of SQL statement. The parsed SQL type is stored in a single record of the probe log (SELECT, INSERT, UPDATE, DELETE, etc.), and other parsed information, such as table name, query conditions, sorting and other restrictions, is converted into SELECT statements, etc., and converted into SELECT statements to be executed in the database. At the same time, the value of the single record modified this time is obtained and stored as a snapshot in the probe log for subsequent rollback operations.

[0036] The logging module is used to query the data in the database according to the analysis results of the SQL analysis module, and save the snapshot of the data to the call log entry of the interface for subsequent rollback operations. It can be understood that the logging module queries the data in the database through different strategies according to the SQL type analyzed and saved by the SQL analysis module. The snapshot of the data is saved in the interface call log entry for subsequent rollback operations. Each interface will record a call log when it is called. These logs are used for the rollback of local transactions after the distributed transaction server issues a rollback request or when the server does not respond to a connection error.

[0037] The local transaction rollback module is used to query the local recorded database snapshot according to the traceid transmitted by the distributed transaction server after the distributed transaction server notifies the rollback and gives the rollback range, and rolls back the local transaction according to the database snapshot.

[0038] The distributed transaction server includes a transaction registration module, a global transaction rollback module and a branch transaction driver module.

[0039] The main function of the transaction registration module is that when the distributed transaction client calls the interface in the microservice, it sends registration information to the distributed transaction server. The registration information contains the interface information corresponding to the interface. The transaction registration module determines whether the traceid is carried. If not, a new global transaction is created according to the received registration information, a traceid is generated, and it is returned to the distributed transaction client.

[0040] The global transaction rollback module is used to receive the traceid sent by the distributed transaction client after detecting an abnormal or failed database operation, and then query the corresponding global transaction based on the traceid, change the status of the corresponding global transaction to rollback, and send a rollback request to the branch transaction driver module to rollback all branch transactions on the call chain. Then, according to the rollback result returned by the branch transaction driver module, the pre-configured strategy is executed to deal with it.

[0041] After receiving the rollback request, the branch transaction driver module queries the call chain according to the traceid and notifies each service on the call chain to perform the rollback operation. After the branch transaction driver module notifies each distributed transaction client on the call chain to perform the rollback operation, it also receives the rollback operation results fed back by each distributed transaction client, and sends the collected rollback operation results to the global transaction rollback module to notify the global transaction rollback module of the success or failure of the rollback.

[0042] The existing system improves reliability but also brings performance loss because the server needs to control and coordinate transactions. The flexible distributed transaction center system based on Java probe technology in this application balances strong consistency and uses a flexible approach to reduce performance loss, thereby improving the flexibility of the system. Since the actual situation is that the probability of problems occurring in distributed transactions is extremely small, there is no need to limit other normal businesses to improve reliability because of this extremely small situation.

[0043] Preferably, the flexible distributed transaction center system based on Java probe technology further comprises a system access configuration module. The system access configuration module is connected to the distributed transaction client for users to configure parameters of microservices accessing the system.

[0044] Specifically, when users connect microservices to the system, they need to configure their projects. The system access configuration module is used for users to configure the data source of the microservices that need to be connected. The data source includes at least the database type, database address, and user name and password, which are related to the database connection and subsequent SQL statement parsing.

[0045] The system access configuration module is also used for users to configure SQL statement variable names or connection methods. The SQL analysis module intercepts the variable according to the configured SQL statement variable name to obtain SQL statements for analysis or directly obtains SQL statements according to the configured connection method. The connection method refers to the SQL or JDBC connection method used.

[0046] Furthermore, the system access configuration module is also used for users to configure whitelist information of microservices that need to be accessed, and the whitelist information includes interface information that does not need to be monitored in the microservices that need to be accessed.

[0047] It is understandable that for some microservice interfaces that do not require probes to host transactions, the system access configuration module provides a whitelist configuration option. Through this configuration option, users can configure the interfaces for which they do or do not want to host global transactions and select the configuration method. When the probe is executed, the configuration file will be automatically read and the object of the global transaction will be selected according to the list in the configuration file.

[0048] The system access configuration module is also used for users to configure their own network transmission methods. For example, in existing RPC frameworks, such as Dubbo and Spring Cloud, the system will obtain network transmission requests based on these configurations to add or intercept information required for transaction operation such as traceid in the request. The system access configuration module also provides user-defined implementation methods, providing instance configuration or user-implemented operations such as sending traceid. Even the request framework implemented by yourself can adapt to the probes in the system.

[0049] Through the above-mentioned flexible distributed transaction center system based on Java probe technology, when the microservice interface is called, the Java probe monitoring module detects that the interface is called and does not detect that the request carries a traceid, and determines that the interface is the first to be called in the transaction. The distributed transaction client initiates a request to the distributed transaction server to register a global transaction. The distributed transaction server does not detect the traceid sent by the distributed transaction client and automatically creates a new global transaction. The distributed transaction server first generates a globally unique traceid and a unique spanid in the current transaction based on the snowflake algorithm, and then creates a global transaction based on the service name, interface name, call time, traceid, creation time, etc., and adds the spanid and the spanid of the previously called interface in the call chain table, and finally transmits the traceid back to the distributed transaction client. After receiving the returned traceid, the distributed transaction client starts parsing the SQL statement and obtains the method, table name, query condition, restriction condition, etc. in the SQL statement. If the SQL method obtained is SELECT, it will not be included in the probe log and no transaction control will be performed on it. If the SQL method obtained is INSERT or DELETE, the data snapshot after addition or before deletion will be saved. If it is UPDATE, the data snapshot before and after execution will be saved. The way to obtain the snapshot is to query the table name and query condition extracted above through the SELECT statement. After the distributed transaction client obtains the snapshot through database query, it combines the traceid sent by the server to generate a local probe log. The attributes of the probe log here include traceid, data snapshot, rollback status, creation time, modification time, etc. The current interface calls other service interfaces, and the probe automatically adds the traceid passed to the branch interface in the request. Another service receives the request from the service, and the probe detects that it initiates a request to register a global transaction with the traceid to the distributed transaction server. The distributed transaction server receives the registration request with service interface information and traceid, searches the database for the global transaction through traceid and interface information, and generates spanid to add a call chain for the transaction. The above process is repeated until all branch interface calls are completed.

[0050] After the microservice interface fails to execute or times out, the system performs a rollback operation. Specifically, when the interface execution throws an exception, the Java probe monitoring module detects that the program throws an exception and prepares to roll back. First, the distributed transaction server regards the transaction as an event and marks the event as needing to be rolled back. After the system captures the event, it initiates a reverse positive operation and reversely rolls back and updates the previous subtransaction. Specifically, the traceid is transmitted to the distributed transaction server, and the distributed transaction server changes the global transaction to rollback, and then queries the call chain of the connected transaction according to the traceid, and sequentially notifies each service on the call chain to perform a rollback operation with the traceid. Each service receives the rollback request, queries the local probe log according to the transmitted traceid, generates a hedged SQL statement according to the SQL type and the data snapshot saved in the probe log, and executes it. After the rollback SQL statement is executed, the distributed transaction server is notified of the rollback result. If the distributed transaction server receives the rollback success information, it modifies the entry in the call chain to have been rolled back. If it receives the rollback failure message, it notifies the retry rollback again. If multiple rollbacks fail, the transaction is set to rollback failure.

[0051] The above shows and describes the basic principles, main features and advantages of the present invention. Those skilled in the art should understand that the above embodiments do not limit the present invention in any form, and any technical solution obtained by equivalent replacement or equivalent transformation falls within the protection scope of the present invention.

Claims

1. A flexible distributed transaction center system based on Java probe technology, characterized in that: Include: Distributed transaction client and distributed transaction server; The distributed transaction client is connected to the distributed transaction server; The distributed transaction client comprises: Java probe monitoring module, which is used to monitor the service interface, record the call chain and call status of the interface between services, save the database snapshot before and after the execution of each interface, and generate probe logs; SQL analysis module, used to intercept the SQL statements executed by the interface calling the database and analyze the SQL statements; A log recording module, used to query the data in the database according to the analysis results of the SQL analysis module, and save a snapshot of the data in the call log entry of the interface for subsequent rollback operations; A local transaction rollback module is used to query the local recorded database snapshot according to the traceid transmitted by the distributed transaction server after the distributed transaction server notifies the rollback and gives the rollback range, and to roll back the local transaction according to the database snapshot; The distributed transaction server includes: A transaction registration module is used to create a new global transaction and generate a traceid based on the registration information sent by the distributed transaction client when the microservice calls the interface, and return it to the distributed transaction client; A global transaction rollback module is used to receive the traceid sent by the distributed transaction client after detecting an abnormality or failure in the database operation, query the corresponding global transaction according to the traceid, modify the state of the corresponding global transaction to rollback, and send a rollback request; The branch transaction driver module is used to query the call chain according to the traceid after receiving the rollback request and notify each service on the call chain to perform the rollback operation; The SQL analysis module formats and preprocesses the intercepted SQL statements, then parses the formatted SQL statements through the integrated SQL parser GSP, stores the parsed SQL type in a single record of the probe log, converts the other parsed information into SELECT statements and executes them in the database, and simultaneously obtains the value of the single record modified this time and stores it in the probe log as a snapshot.

2. The flexible distributed transaction center system based on Java probe technology according to claim 1 is characterized in that: The log recording module queries the data in the database through different strategies according to the SQL type analyzed by the SQL analysis module.

3. The flexible distributed transaction center system based on Java probe technology according to claim 1 is characterized in that: The transaction registration module generates a globally unique traceid through a snowflake algorithm for marking the call chain.

4. The flexible distributed transaction center system based on Java probe technology according to claim 1 is characterized in that: The flexible distributed transaction center system based on Java probe technology also includes a system access configuration module; The system access configuration module is connected to the distributed transaction client for allowing the user to configure parameters of the microservices accessing the system.

5. The flexible distributed transaction center system based on Java probe technology according to claim 4 is characterized in that: The system access configuration module is used for users to configure the database type, database address and username and password of the microservice that needs to be accessed.

6. The flexible distributed transaction center system based on Java probe technology according to claim 5 is characterized in that: The system access configuration module is used for the user to configure the SQL statement variable name or connection method, and the SQL analysis module intercepts the variable according to the configured SQL statement variable name to obtain the SQL statement for analysis or directly obtains the SQL statement according to the configured connection method.

7. The flexible distributed transaction center system based on Java probe technology according to claim 6 is characterized in that: The system access configuration module is used for users to configure whitelist information of microservices that need to be accessed, and the whitelist information includes interface information that does not need to be monitored in the microservices that need to be accessed.

8. The flexible distributed transaction center system based on Java probe technology according to claim 7 is characterized in that: The system access configuration module is used for users to configure their own network transmission mode.

9. The flexible distributed transaction center system based on Java probe technology according to claim 1 is characterized in that: After the branch transaction driver module notifies each of the distributed transaction clients on the call chain to perform a rollback operation, it also receives the rollback operation results fed back by each of the distributed transaction clients, and sends the collected rollback operation results to the global transaction rollback module.