A transaction link logging method and system based on Druid

The transaction link logging method on Druid addresses the lack of comprehensive transaction logging in hospital information systems by intercepting requests and configuring event listeners to record and track transaction logs, enhancing system performance and reliability.

CN118672991BActive Publication Date: 2024-12-27ZOE SOFT CORP LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411161689.6
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-08-23
Publication Date
2024-12-27
Estimated Expiration
2044-08-23

AI Technical Summary

Technical Problem

Existing hospital information systems fail to record transaction-related link logs, including transaction start logs, end logs, execution time logs, database details, and rollback logs, leading to inefficiencies and instability due to long transactions, undetected unclosed transactions, and inability to trace error information, affecting system performance and reliability.

Method used

Implementing a transaction link logging method based on Druid by intercepting client requests, extending event listeners, and configuring a YAML file to monitor and record transaction logs, including unique identifiers and database statements, ensuring comprehensive transaction logging and tracking.

Benefits of technology

Enables unified information display of transaction logs, detects long-running transactions, and enhances database performance and fault protection by bundling transaction and link log records, improving system stability and reliability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118672991B_ABST
    Figure CN118672991B_ABST
Patent Text Reader

Abstract

The present invention proposes a transaction link log recording method and system based on druid, including: implementing a HandlerInterceptor interface in a druid database connection pool, the HandlerInterceptor interface intercepts requests sent by a client, and sends the request to a business module interface of the druid database connection pool; extending a basic event listener class FilterEventAdapter in the druid database connection pool and listening to events in the druid database connection pool, and monitoring transactions; rewriting methods in the druid database connection pool in the extended basic event listener class FilterEventAdapter; setting parameters of a yml configuration file and loading a configuration function for opening and closing a transaction link log in a configuration class, and controlling and recording the transaction link log through the yml configuration file. The problem that the prior art cannot record transaction start time, end time log, transaction execution time-consuming log, database details and quantity link log, transaction commit or rollback status link log, cannot display long-time transactions by interface ID, and cannot detect transactions that have not been closed for a long time is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a transaction link log recording method and system based on Druid. Background Art

[0002] In the hospital information system, the codes of each business module usually involve business logic operations performed by the API interface, which require simultaneous operations on multiple tables in the database to complete. Simultaneous operations on multiple tables in the database involve transaction issues. In the existing practice of handling transaction issues, only the link logs of different business module interfaces calling each other are recorded, and the transaction-related link logs cannot be recorded, including transaction start logs, transaction end logs, transaction interface logs, transaction execution time logs, database details and quantity link logs, transaction commit logs and transaction rollback logs. Transactions with long processing times cannot be optimized, transactions with long processing times cannot be displayed by interface ID, and transactions that have not been closed for a long time cannot be detected. When an error occurs in a transaction, it is also impossible to check transaction-related error information based on the transaction link log, including increased database resource usage, data inconsistency, transaction locks, system performance degradation caused by unclosed transactions, and errors in transaction rollbacks, which seriously affects the stability and reliability of the hospital information system. Summary of the invention

[0003] The present invention proposes the following technical solutions to address one or more technical deficiencies in the above-mentioned prior art.

[0004] Based on the first aspect of the present invention, a transaction link logging method based on druid is proposed.

[0005] include:

[0006] S1: Implement the HandlerInterceptor interface in the druid database connection pool, the HandlerInterceptor interface intercepts the request sent by the client, and sends the request to the business module interface of the druid database connection pool;

[0007] S2: Extend the basic event listener class FilterEventAdapter in the druid database connection pool and listen to the events in the druid database connection pool, and monitor the transactions;

[0008] S3: Rewrite the method in the druid database connection pool in the extended basic event listener class FilterEventAdapter;

[0009] S4: Set the parameters of the yml configuration file and load the configuration function of turning on and off the transaction link log in the configuration class, and control and record the transaction link log through the yml configuration file.

[0010] Furthermore, before processing the client request, the business module interface in S1 calls the preHandle() method of the HandlerInterceptor interface to obtain the unique identifier traceId and interface URL of the link tracking and set them to the cache, and obtains the span node of the current link tracking and sets the related tag tag1;

[0011] The tag tag1 includes request parameters, request header and request client IP.

[0012] The request interception and processing mechanism provided by HandlerInterceptor can control the processing of requests more finely.

[0013] Furthermore, after processing the client request, the business module interface calls the afterCompletion() method of the HandlerInterceptor interface to obtain the span node of the current link tracking, and sets the relevant tag tag2 to record the link log;

[0014] The tag tag2 includes the interface response content length and the interface response status code.

[0015] Furthermore, S2 also includes defining member attributes in the extended basic event listener class FilterEventAdapter class, wherein the member attributes include a transaction identifier TRAN_ID, a transaction status, a transaction start time TX_BEGIN_TIME, and a database statement TX_SQL_LIST executed during the transaction.

[0016] Furthermore, the method in the druid database connection pool includes a setAutoCommit method, specifically, obtaining the transaction identifier TRAN_ID of the current transaction, if the transaction identifier TRAN_ID can be obtained, the current transaction has a sub-transaction, creating a span node of the sub-transaction and setting the transaction start time and transaction related information of the span node;

[0017] If the transaction identifier TRAN_ID cannot be obtained, the current transaction is the main transaction, and monitoring of the current transaction begins.

[0018] Furthermore, the monitoring of the current transaction specifically includes:

[0019] S401: Obtain the current system time as the transaction start time of the main transaction, and store it in the transaction start time TX_BEGIN_TIME array;

[0020] S402: Create an array variable object LinkedList that records database statement SQL <string>And store it in the database statement TX_SQL_LIST array;

[0021] S403: Create a link log for the start of the transaction, obtain the database ID of the current connection as the link identifier tranId of the link log and save it in the transaction identifier TRAN_ID array, generate the span node of the main transaction and set the transaction start time and transaction related information of the span node.

[0022] Furthermore, the methods in the druid database connection pool also include statementExecuteBefore method, statementExecuteUpdateBefore method and statementExecuteQueryBefore method, which monitor database statements, database update statements and database query statements respectively. If there are values ​​in the transaction start time TX_BEGIN_TIME array corresponding to the statementExecuteBefore method, statementExecuteUpdateBefore method and statementExecuteQueryBefore method respectively, the relevant database statements are recorded and stored in the relevant database statement TX_SQL_LIST array.

[0023] Furthermore, the method in the druid database connection pool also includes overriding the connection_commit method, specifically,

[0024] Get the URL interface from the cache, and get the transaction identifier TRAN_ID of the current transaction. If the transaction identifier TRAN_ID of the current transaction can be obtained, the current transaction is a subtransaction. Generate and record the span node where the subtransaction ends. Use the current system time as the transaction end time and end the statementExecuteQueryBefore method.

[0025] If the transaction identifier TRAN_ID of the current transaction cannot be obtained and there is a value in the transaction start time TX_BEGIN_TIME array, the transaction execution time is calculated based on the transaction start time and the current time;

[0026] Create a link log for the end of the transaction, obtain the link identifier tranId from the transaction identifier TRAN_ID array, generate the span node of the main transaction and set the relevant tag tag3, including the transaction execution time, transaction start time, transaction end time, business module interface, SQL statements and the number of SQL statements in the database statement TX_SQL_LIST array, and transaction status;

[0027] Clear the transaction identifier TRAN_ID array, transaction start time TX_BEGIN_TIME array, database statement TX_SQL_LIST array and the URL interface in the cache.

[0028] Furthermore, the method in the druid database connection pool also includes rewriting the connection_rollback method, which is specifically rewritten according to rewriting the connection_commit method and recording the rollback link log.

[0029] Based on the second aspect of the present invention, a transaction link logging system based on druid is also proposed, including:

[0030] Interface module: implements the HandlerInterceptor interface in the druid database connection pool, the HandlerInterceptor interface intercepts the request sent by the client, and sends the request to the business module interface of the druid database connection pool;

[0031] Extension class module: extends the basic event listener class FilterEventAdapter in the druid database connection pool and listens to events in the druid database connection pool, as well as monitors transactions;

[0032] Rewrite module: rewrite the method in the druid database connection pool in the extended basic event listener class FilterEventAdapter;

[0033] Configuration module: Set the parameters of the yml configuration file and load the configuration function of turning on and off the transaction link log in the configuration class, and control and record the transaction link log through the yml configuration file.

[0034] The technical effect of the present invention is that: based on the interceptor and event monitoring mechanism of the druid database, the present invention customizes the recording logic, opens up the link tracking node, and performs unified information display, which solves the problem that the prior art only records the link logs of mutual calls between different business module interfaces, but cannot record transaction-related link logs. The transaction log record and link log tracking are bundled, and the transaction start time, end time log, transaction execution time log, database details and quantity link log, transaction submission or rollback status link log can be recorded, and the time-consuming transaction can be displayed by interface ID, and the transaction that has not been closed for a long time can be detected, so that the database has better performance and data replication function, as well as stronger fault protection function. BRIEF DESCRIPTION OF THE DRAWINGS

[0035] Other features, objects and advantages of the present application will become more apparent from the detailed description of non-limiting embodiments made with reference to the following drawings.

[0036] Figure 1 The figure is an overall flow chart of a transaction link logging method based on Druid provided according to an embodiment of the present invention.

[0037] Figure 2 It is a specific flow chart for monitoring current affairs provided according to an embodiment of the present invention.

[0038] Figure 3 It is an overall module diagram of a Druid-based transaction link logging system provided according to an embodiment of the present invention.

[0039] Figure 4 The figure is a general technical architecture diagram of a Druid-based transaction link logging system provided according to an embodiment of the present invention.

[0040] Figure 5 The figure is a rendering of a Druid-based transaction link logging system provided according to an embodiment of the present invention.

[0041] Figure 6 The present invention provides a Druid-based transaction link logging system according to an embodiment of the present invention.

[0042] Figure 7 It is a detailed technical architecture diagram of a Druid-based transaction link logging system provided according to an embodiment of the present invention.

[0043] Figure 8 A schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application is shown. DETAILED DESCRIPTION

[0044] The present application will be further described in detail below in conjunction with the accompanying drawings and embodiments. It is to be understood that the specific embodiments described herein are only used to explain the relevant invention, rather than to limit the invention. It should also be noted that, for ease of description, only the parts related to the relevant invention are shown in the accompanying drawings.

[0045] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0046] Figure 1 A transaction link log recording method based on druid of the present invention is shown, comprising:

[0047] S1: Implement the HandlerInterceptor interface in the druid database connection pool, the HandlerInterceptor interface intercepts the request sent by the client, and sends the request to the business module interface of the druid database connection pool;

[0048] S2: Extend the basic event listener class FilterEventAdapter in the druid database connection pool and listen to the events in the druid database connection pool, and monitor the transactions;

[0049] S3: Rewrite the method in the druid database connection pool in the extended basic event listener class FilterEventAdapter;

[0050] S4: Set the parameters of the yml configuration file and load the configuration function of turning on and off the transaction link log in the configuration class, and control and record the transaction link log through the yml configuration file.

[0051] It should be noted that the transaction link logging method of the present application stores records of changes made to the database, integrates transaction log records and link tracking, defines recording logic based on the interceptor and event monitoring mechanism of the druid database, and can ensure the consistency and integrity of the database, so that the database has better performance and data replication capabilities, and stronger fault protection capabilities.

[0052] It should be noted that link tracking is a technology used to track the flow of requests in a distributed system. By tracking the link and recording the transaction link log, you can clearly understand which services a request has passed through, the processing time of each service, and other information, which facilitates the location and troubleshooting of problems.

[0053] It should be noted that when a user executes a transaction, the database system records the transaction operations in the transaction log. During the transaction execution, the database writes the transaction operations into the memory buffer. When the transaction is committed, the database writes the transaction operations in the buffer into the transaction log file and applies the related operations to the database data file. When a failure occurs, the database can restore the consistency of the database by reading the transaction log and restore the database to the state before the failure according to the records in the transaction log.

[0054] It should be noted that the present invention configures the relevant environment of sleuth, zipkin, and ElactisSearch before step S1, and deploys the relevant third-party services of zipkin, ElactisSearch, and kibana in the business system operating environment.

[0055] It should be noted that the HandlerInterceptor interface is based on the interceptor mechanism of Spring MVC. When the client sends a request to the business module interface, the preHandle() method of the HandlerInterceptor interface will be called before the business module interface executes the request; after the business module interface is executed, the afterCompletion() method of the HandlerInterceptor interface will be called. Writing a custom algorithm in the preHandle() and afterCompletion() methods of the HandlerInterceptor interface can automatically call the preHandle() method to record the link log before the business interface processes the request, and automatically call the afterCompletion() method to record the link log after the business interface is executed.

[0056] It should be noted that the interceptor is a pluggable mechanism that improves the reusability and maintainability of the code and can effectively implement the functions of cross-cutting concerns.

[0057] It should be noted that the HandlerInterceptor interface provides a powerful mechanism to intervene in the request processing process. The preHandle() method is used to preprocess and decide whether to continue processing the request, and the afterCompletion() method performs cleanup after the request is completed.

[0058] It should be noted that before processing the client request, the business module interface in S1 calls the preHandle() method of the HandlerInterceptor interface to obtain the unique identifier traceId and interface URL of the link tracking and set them to the cache, and obtains the span node of the current link tracking and sets the relevant tag tag1;

[0059] The tag tag1 includes request parameters, request header and request client IP.

[0060] It should be noted that the span node represents a tracking unit of an operation or event.

[0061] It should be noted that after processing the client request, the business module interface calls the afterCompletion() method of the HandlerInterceptor interface to obtain the span node of the current link tracking, and sets the relevant tag tag2 to record the link log;

[0062] The tag tag2 includes the interface response content length and the interface response status code.

[0063] It should be noted that S2 also includes defining member attributes in the extended basic event listener class FilterEventAdapter class, and the member attributes include a transaction identifier TRAN_ID, a transaction status, a transaction start time TX_BEGIN_TIME, and a database statement TX_SQL_LIST executed during the transaction.

[0064] In a specific embodiment, the code for defining member properties in the extended basic event listener class FilterEventAdapter class is as follows:

[0065] private static final ThreadLocal <long>TRAN_ID = new ThreadLocal<>();

[0066] private static final ThreadLocal <long>TX_BEGIN_TIME = newThreadLocal<>();

[0067] private static final ThreadLocal<List <string>> TX_SQL_LIST = newThreadLocal<>();

[0068] It should be noted that the method in the druid database connection pool includes the setAutoCommit method, specifically, obtaining the transaction identifier TRAN_ID of the current transaction. If the transaction identifier TRAN_ID can be obtained, the current transaction has a sub-transaction, creating a span node of the sub-transaction and setting the transaction start time and transaction related information of the span node;

[0069] If the transaction identifier TRAN_ID cannot be obtained, the current transaction is the main transaction, and monitoring of the current transaction begins.

[0070] It should be noted that the span node represents the internal view of different services in the entire link. All span nodes constitute the entire link view of the request in the distributed system. TRAN_ID is a unique identifier used to identify a request. During the entire life cycle of a request, through TRAN_ID, all services that a request passes through in the distributed system can be connected in series to form a complete link.

[0071] It should be noted that the monitoring of the current transaction is specifically as follows: Figure 2 As shown, including:

[0072] S401: Obtain the current system time as the transaction start time of the main transaction, and store it in the transaction start time TX_BEGIN_TIME array;

[0073] S402: Create an array variable object LinkedList that records database statement SQL <string>And store it in the database statement TX_SQL_LIST array;

[0074] S403: Create a link log for the start of the transaction, obtain the database ID of the current connection as the link identifier tranId of the link log and save it in the transaction identifier TRAN_ID array, generate the span node of the main transaction and set the transaction start time and transaction related information of the span node.

[0075] It should be noted that the methods in the druid database connection pool also include statementExecuteBefore method, statementExecuteUpdateBefore method and statementExecuteQueryBefore method, which monitor database statements, database update statements and database query statements respectively. If there are values ​​in the transaction start time TX_BEGIN_TIME array corresponding to the statementExecuteBefore method, statementExecuteUpdateBefore method and statementExecuteQueryBefore method, respectively, the relevant database statements are recorded and stored in the relevant database statement TX_SQL_LIST array.

[0076] It should be noted that the method in the druid database connection pool also includes rewriting the connection_commit method. Specifically,

[0077] Get the URL interface from the cache, and get the transaction identifier TRAN_ID of the current transaction. If the transaction identifier TRAN_ID of the current transaction can be obtained, the current transaction is a subtransaction. Generate and record the span node where the subtransaction ends. Use the current system time as the transaction end time and end the statementExecuteQueryBefore method.

[0078] If the transaction identifier TRAN_ID of the current transaction cannot be obtained and there is a value in the transaction start time TX_BEGIN_TIME array, the transaction execution time is calculated based on the transaction start time and the current time;

[0079] Create a link log for the end of the transaction, obtain the link identifier tranId from the transaction identifier TRAN_ID array, generate the span node of the main transaction and set the relevant tag tag3, including the transaction execution time, transaction start time, transaction end time, business module interface, SQL statements and the number of SQL statements in the database statement TX_SQL_LIST array, and transaction status;

[0080] Clear the transaction identifier TRAN_ID array, transaction start time TX_BEGIN_TIME array, database statement TX_SQL_LIST array and the URL interface in the cache.

[0081] It should be noted that the method in the druid database connection pool also includes rewriting the connection_rollback method, which is specifically rewritten according to rewriting the connection_commit method and recording the rollback link log.

[0082] It should be noted that in general link logging, it is necessary to introduce dependencies and create aspects to generate and pass link IDs in requests, configure log output link IDs, and record business operation logs in business codes. In order to ensure reliability, high performance and scalability during log link tracking, this application rewrites the methods in the database connection pool.

[0083] In a specific embodiment, the parameters of the yml configuration file are set and the configuration function of opening and closing the transaction link log is loaded in the configuration class. The code for controlling and recording the transaction link log through the yml configuration file is as follows:

[0084] @Configuration(proxyBeanMethods = false)

[0085] @ConditionalOnClass(Interceptor.class)

[0086] @Slf4j

[0087] public class OnelinkTraceMybatisAutoConfiguration {

[0088] / / Whether to enable transaction monitoring

[0089] @Bean

[0090] @ConditionalOnProperty(prefix = "onelink.logging.sql", name = "tx-monitor-enabled")

[0091] public OnelinkdruidTxMonitorFilter druidTxMonitorFilter(OnelinkTraceLogProperties onelinkTraceLogProperties, Tracer tracer) {

[0092] return new OnelinkdruidTxMonitorFilter(onelinkTraceLogProperties.getSql(), tracer);

[0093] }

[0094] }

[0095] In a specific embodiment, the yml configuration is as follows:

[0096] onelink:

[0097] logging:

[0098] tx:

[0099] # Whether to enable transaction monitoring, disabled by default

[0100] tx-monitor-enabled: true

[0101] #Whether transaction monitoring counts the number of SQL lists and concise information, closed by default

[0102] tx-monitor-sql-enabled: true

[0103] # Do not record exclusions for transaction monitoring

[0104] tx-monitor-exclude: com.zoe.**.dao.*

[0105] # Long transaction warning duration (milliseconds)

[0106] tx-monitor-police-time: 10000

[0107] # Long transaction warning mode

[0108] tx-monitor-police-mode: WX

[0109] Reference below Figure 3 , Figure 3 A transaction link logging system based on druid is shown, including an interface module a, an extension class module b, a rewrite module c and a configuration module d.

[0110] In a specific embodiment, the interface module a is configured to: implement a HandlerInterceptor interface in the druid database connection pool, the HandlerInterceptor interface intercepts the request sent by the client, and sends the request to the business module interface of the druid database connection pool;

[0111] In a specific embodiment, the extension class module b is configured to: extend the basic event listener class FilterEventAdapter in the druid database connection pool and listen to events in the druid database connection pool, and monitor transactions;

[0112] In a specific embodiment, the rewriting module c is configured to: rewrite the method in the druid database connection pool in the extended basic event listener class FilterEventAdapter;

[0113] In a specific embodiment, the configuration module d is configured to: set the parameters of the yml configuration file and load the configuration function of turning on and off the transaction link log in the configuration class, and control and record the transaction link log through the yml configuration file.

[0114] It should be noted that the overall technical architecture of the present invention is as follows Figure 4 As shown, the client requests the business module interface through http, manages transactions declaratively through business code or directly annotates @Transactional in the business module interface, and performs programmatic transaction management and starts transaction logic through Transaction Template or Platform TransactionManager;

[0115] Implement the HandlerInterceptor interface, write custom algorithms for preHandle() and afterCompletion() to process http requests; at the same time, extend the basic event listener class FilterEventAdapter in the druid database connection pool to implement transaction monitoring algorithms, record link logs, and store transaction link logs through data storage middleware (such as Elasticsearch);

[0116] Then use Zipkin's built-in visualization page to fully display the transaction-related link logs (such as Figure 5 ), and display the transaction link logs and other link log details that take a long time by grouping by interface ID using the Elasticsearch data visualization plug-in (as shown in Figure 6 as shown).

[0117] It should be noted that the technical architecture details of the present invention are as follows Figure 7 As shown, including:

[0118] After the druid database connection pool starts the transaction logic through the business code, the custom interceptor intercepts when the transaction is started, and then uses Sleuth distributed link tracking to start the transaction link tracking. The MyBatis persistence layer's add, delete, modify and query operations are executed through the business code. The custom interceptor intercepts the SQL database execution statement, and then uses thread variables to calculate and store transaction syntax. The business code executes transaction commit or rollback operations. The custom interceptor intercepts at the end of the transaction, and Sleuth distributed link tracking ends the transaction link tracking. The data of Sleuth distributed link tracking is written to the Zipkin distributed link system and the Elasticsearch search data analysis engine, which display the link log and link log details respectively.

[0119] Reference below Figure 8 , which shows a schematic diagram of the structure of a computer system suitable for implementing an electronic device of an embodiment of the present application. Figure 8 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0120] like Figure 8 As shown, the computer system includes a central processing unit (CPU) 801, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 802 or a program loaded from a storage part 808 to a random access memory (RAM) 803. In the RAM 803, various programs and data required for system operation are also stored. The CPU 801, the ROM 802, and the RAM 803 are connected to each other via a bus 804. An input / output (I / O) interface 805 is also connected to the bus 804.

[0121] The following components are connected to the I / O interface 805: an input section 806 including a keyboard, a mouse, etc.; an output section 807 including a liquid crystal display (LCD), etc. and a speaker, etc.; a storage section 808 including a hard disk, etc.; and a communication section 809 including a network interface card such as a LAN card, a modem, etc. The communication section 809 performs communication processing via a network such as the Internet. A drive 810 is also connected to the I / O interface 805 as needed. A removable medium 811, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 810 as needed, so that a computer program read therefrom is installed into the storage section 808 as needed.

[0122] In particular, according to an embodiment of the present disclosure, the process described above with reference to the flowchart can be implemented as a computer software program. For example, an embodiment of the present disclosure includes a computer program product, which includes a computer program carried on a computer-readable storage medium, and the computer program contains a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 809, and / or installed from the removable medium 811. When the computer program is executed by the central processing unit (CPU) 801, the above functions defined in the method of the present application are executed. It should be noted that the computer-readable storage medium of the present application can be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to, an electrical connection with one or more conductors, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present application, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, an apparatus, or a device. In the present application, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, in which a computer-readable program code is carried. Such propagated data signals may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium may also be any computer-readable storage medium other than a computer-readable storage medium, which may send, propagate, or transmit a program for use by or in combination with an instruction execution system, an apparatus, or a device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wireless, wireline, optical cable, RF, etc., or any suitable combination of the foregoing.

[0123] Computer program code for performing the operations of the present application may be written in one or more programming languages ​​or a combination thereof, including object-oriented programming languages, such as Java, Smalltalk, C++, and conventional procedural programming languages, such as "C" or similar programming languages. The program code may be executed entirely on the user's computer, partially on the user's computer, as a separate software package, partially on the user's computer and partially on a remote computer, or entirely on a remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or may be connected to an external computer (e.g., via the Internet using an Internet service provider).

[0124] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present application. In this regard, each square box in the flow chart or block diagram can represent a module, a program segment or a part of a code, and the module, the program segment or a part of the code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the square box can also occur in a sequence different from that marked in the accompanying drawings. For example, two square boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each square box in the block diagram and / or flow chart, and the combination of the square boxes in the block diagram and / or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0125] The modules involved in the embodiments of the present application may be implemented by software or by hardware.

[0126] As another aspect, the present application also provides a computer-readable storage medium, which may be included in the electronic device described in the above embodiment; or it may exist independently without being assembled into the electronic device. The above computer-readable storage medium carries one or more programs. When the above one or more programs are executed by the electronic device, the electronic device: implements the HandlerInterceptor interface in the druid database connection pool, the HandlerInterceptor interface intercepts the request sent by the client, and sends the request to the business module interface of the druid database connection pool; extends the basic event listener class FilterEventAdapter in the druid database connection pool and listens to the events in the druid database connection pool, and monitors the transaction; rewrites the method in the druid database connection pool in the extended basic event listener class FilterEventAdapter; sets the parameters of the yml configuration file and loads the configuration function of opening and closing the transaction link log in the configuration class, and controls and records the transaction link log through the yml configuration file.

[0127] The above description is only a preferred embodiment of the present application and an explanation of the technical principles used. Those skilled in the art should understand that the scope of the invention involved in the present application is not limited to the technical solution formed by a specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above invention concept. For example, the above features are replaced with the technical features with similar functions disclosed in this application (but not limited to) by each other to form a technical solution.

[0128] Finally, it should be noted that the above embodiments are only intended to illustrate rather than limit the technical solutions of the present invention. Although the present invention has been described in detail with reference to the above embodiments, those skilled in the art should understand that the present invention can still be modified or replaced by equivalents. Any modification or partial replacement that does not depart from the spirit and scope of the present invention should be included in the scope of the claims of the present invention.< / string> < / string> < / long> < / long> < / string>

Claims

1. A transaction link log recording method based on Druid, characterized in that: include: S1: Implementing the HandlerInterceptor interface in the Druid database connection pool, the HandlerInterceptor interface intercepts the request sent by the client and sends the request to the business module interface of the Druid database connection pool; S2: Extend the basic event listener class FilterEventAdapter in the Druid database connection pool and listen to the events in the Druid database connection pool, and monitor the transactions; S2 also includes defining member attributes in the extended basic event listener class FilterEventAdapter class, wherein the member attributes include a transaction identifier TRAN_ID, a transaction status, a transaction start time TX_BEGIN_TIME, and a database statement TX_SQL_LIST executed during the transaction; The method in the Druid database connection pool includes a setAutoCommit method, specifically, obtaining the transaction identifier TRAN_ID of the current transaction. If the transaction identifier TRAN_ID can be obtained, the current transaction has a sub-transaction, creating a span node of the sub-transaction and setting the transaction start time and transaction related information of the span node; If the transaction identifier TRAN_ID cannot be obtained, the current transaction is the main transaction, and monitoring of the current transaction begins; The monitoring of the current transaction specifically includes: S401: Obtain the current system time as the transaction start time of the main transaction, and store it in the transaction start time TX_BEGIN_TIME array; S402: Create an array variable object LinkedList that records database statement SQL <string> And store it in the database statement TX_SQL_LIST array;< / string> S403: Create a link log for the start of a transaction, obtain the database ID of the current connection as the link identifier tranId of the link log and save it in the transaction identifier TRAN_ID array, generate a span node for the main transaction and set the transaction start time and transaction related information of the span node; S3: Rewrite the method in the Druid database connection pool in the extended basic event listener class FilterEventAdapter; S4: Set the parameters of the yml configuration file and load the configuration function of turning on and off the transaction link log in the configuration class, and control and record the transaction link log through the yml configuration file.

2. The method according to claim 1, characterized in that: Before processing the client request, the business module interface in S1 calls the preHandle() method of the HandlerInterceptor interface to obtain the unique identifier traceId and interface URL of the link tracking and set them to the cache, and obtains the span node of the current link tracking and sets the related tag tag1; The tag tag1 includes request parameters, request header and request client IP.

3. The method according to claim 1, characterized in that After processing the client request, the business module interface calls the afterCompletion() method of the HandlerInterceptor interface to obtain the span node of the current link tracking, sets the relevant tag tag2, and records the link log; The tag tag2 includes the interface response content length and the interface response status code.

4. The method according to claim 1, characterized in that The methods in the Druid database connection pool also include statementExecuteBefore method, statementExecuteUpdateBefore method and statementExecuteQueryBefore method, which monitor database statements, database update statements and database query statements respectively. If there are values ​​in the transaction start time TX_BEGIN_TIME array corresponding to the statementExecuteBefore method, statementExecuteUpdateBefore method and statementExecuteQueryBefore method respectively, the relevant database statements are recorded and stored in the relevant database statement TX_SQL_LIST array.

5. The method according to claim 1, characterized in that: The method in the Druid database connection pool also includes rewriting the connection_commit method, specifically, Get the URL interface from the cache, and get the transaction identifier TRAN_ID of the current transaction. If the transaction identifier TRAN_ID of the current transaction can be obtained, the current transaction is a subtransaction. Generate and record the span node where the subtransaction ends. Use the current system time as the transaction end time and end the statementExecuteQueryBefore method. If the transaction identifier TRAN_ID of the current transaction cannot be obtained and there is a value in the transaction start time TX_BEGIN_TIME array, the transaction execution time is calculated based on the transaction start time and the current time; Create a link log for the end of the transaction, obtain the link identifier tranId from the transaction identifier TRAN_ID array, generate the span node of the main transaction and set the relevant tag tag3, including the transaction execution time, transaction start time, transaction end time, business module interface, SQL statements and the number of SQL statements in the database statement TX_SQL_LIST array, and transaction status; Clear the transaction identifier TRAN_ID array, transaction start time TX_BEGIN_TIME array, database statement TX_SQL_LIST array and the URL interface in the cache.

6. The method according to claim 5, characterized in that The method in the Druid database connection pool also includes rewriting the connection_rollback method, which is specifically rewritten according to rewriting the connection_commit method and recording the rollback link log.

7. A transaction link logging system based on Druid, characterized in that: include: Interface module: implements the HandlerInterceptor interface in the Druid database connection pool, the HandlerInterceptor interface intercepts the request sent by the client, and sends the request to the business module interface of the Druid database connection pool; Extension class module: extends the basic event listener class FilterEventAdapter in the Druid database connection pool and listens to events in the Druid database connection pool, as well as monitors transactions; S2 also includes defining member attributes in the extended basic event listener class FilterEventAdapter class, wherein the member attributes include a transaction identifier TRAN_ID, a transaction status, a transaction start time TX_BEGIN_TIME, and a database statement TX_SQL_LIST executed during the transaction; The method in the Druid database connection pool includes a setAutoCommit method, specifically, obtaining the transaction identifier TRAN_ID of the current transaction. If the transaction identifier TRAN_ID can be obtained, the current transaction has a sub-transaction, creating a span node of the sub-transaction and setting the transaction start time and transaction related information of the span node; If the transaction identifier TRAN_ID cannot be obtained, the current transaction is the main transaction, and monitoring of the current transaction begins; The monitoring of the current transaction specifically includes: S401: Obtain the current system time as the transaction start time of the main transaction, and store it in the transaction start time TX_BEGIN_TIME array; S402: Create an array variable object LinkedList that records database statement SQL <string> And store it in the database statement TX_SQL_LIST array;< / string> S403: Create a link log for the start of a transaction, obtain the database ID of the current connection as the link identifier tranId of the link log and save it in the transaction identifier TRAN_ID array, generate a span node for the main transaction and set the transaction start time and transaction related information of the span node; Rewrite module: rewrite the method in the Druid database connection pool in the extended basic event listener class FilterEventAdapter; Configuration module: Set the parameters of the yml configuration file and load the configuration function of turning on and off the transaction link log in the configuration class, and control and record the transaction link log through the yml configuration file.

Citation Information

Patent Citations

  • MongoDB-based distributed transaction processing system and method

    CN113032421A

  • Link monitoring and warning method and device, computer equipment and storage medium

    CN114978940A