Transaction nesting detection method and device, equipment, storage medium and program product

By obtaining and analyzing the database connection log and link call log of the application service, combined with AOP section technology, dynamically detecting the database transaction nesting relationship, solving the problem that static code analysis cannot accurately detect transaction nesting, and improving detection accuracy.

CN119226374AActive Publication Date: 2024-12-31CHINA MERCHANTS BANK
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411279550.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-09-12
Publication Date
2024-12-31
Estimated Expiration
2044-09-12

AI Technical Summary

Technical Problem

Existing static code analysis methods cannot accurately detect database transaction nesting, especially when there are single application and multiple service calls under the same calling link, the transaction nesting relationship between multiple services cannot be detected dynamically.

Method used

By obtaining the database connection log and link call log of each application service, based on the connection establishment time, release time and call method, we can determine whether there is a nested relationship between application services under the same link, and use AOP sections to capture the connection time and generate logs , realize dynamic detection.

Benefits of technology

Improves the accuracy of database transaction nested detection, and can identify transaction dependencies in dynamic service calls in real time to avoid deadlocks and misjudgments.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119226374A_ABST
    Figure CN119226374A_ABST
Patent Text Reader

Abstract

The invention discloses a transaction nesting detection method and device, equipment, a storage medium and a program product, and relates to the technical field of data processing. The connection establishment time and the connection release time of the database can reflect the starting time and the ending time of the database transactions started by the first application service under the same link for the same database, and the upstream and downstream relationship of the first application service under the same link can be reflected by calling the link depth. The calling mode can reflect the dependency relationship between the database transactions started by the first application service, and whether the database transactions started by the first application service under the same link have the nested relationship or not can be accurately judged based on the starting time, the ending time, the upstream and downstream relationship and the dependency relationship; compared with the prior art that only source codes of the application framework can be analyzed in a static code analysis mode, the method can improve the detection accuracy of database transaction nesting.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of data processing technology, and in particular to a transaction nesting detection method, apparatus, device, storage medium and program product. Background Art

[0002] Currently, static code analysis is usually used to detect database transaction nesting. Specifically, the service layer and data access object (DAO) layer in the business code of the application framework are scanned to determine whether there is database transaction nesting.

[0003] Since the static code analysis method can only analyze the source code of the application framework, it cannot analyze the service calls during dynamic operation. If there are multiple service calls in a single application under the same call link, and multiple services under the single application start database transactions at the same time, there will be nested transactions between the multiple services under the single application, but the static code analysis method cannot accurately detect this database transaction nesting. Summary of the invention

[0004] The main purpose of the present application is to provide a transaction nesting detection method, device, equipment, storage medium and program product, aiming to solve the technical problem of low detection accuracy of database transaction nesting.

[0005] To achieve the above object, the present application proposes a transaction nesting detection method, which is applied to a transaction nesting detection device, and the method comprises:

[0006] Obtain the database connection log and link call log recorded by each application service, wherein the database connection log includes the link identifier of the application service that initiates the service call request, the call link depth, the database name, the database connection establishment time and the connection release time, and the link call log includes the call method corresponding to the service call request;

[0007] Based on the connection establishment time, connection release time, and calling method of the database, determine whether there is a nested relationship between database transactions initiated by the first application service under the same link, wherein the first application service under the same link is an application service that initiates database transactions for a database with the same database name under a link with the same link identifier.

[0008] In one embodiment, the step of determining whether there is a nested relationship between database transactions initiated by the first application service under the same link based on the connection establishment time, the connection release time, and the calling mode of the database includes:

[0009] Determining whether the call link depths of the first application services are the same;

[0010] If they are not the same, judging whether the duration periods of the database transaction started by the first application service are in an inclusive relationship based on the connection establishment time and the connection release time of the database;

[0011] If it is an inclusion relationship, based on the calling method of the upstream application service of the second application service, it is determined whether there is a nested relationship between the database transactions initiated by the first application service under the same link, wherein the second application service is the application service with the latest connection establishment time among the first application services.

[0012] In one embodiment, the step of determining whether there is a nested relationship between database transactions initiated by the first application service under the same link based on the calling mode of the upstream application service of the second application service includes:

[0013] Starting from the upper layer application service of the second application service, traverse the calling mode of the upstream application service of the second application service to see whether it is an asynchronous call;

[0014] If the calling mode of the upstream application service does not include asynchronous calling, it is determined that there is a nested relationship between the database transactions started by the first application service under the same link.

[0015] To achieve the above purpose, the present application also proposes a transaction nesting detection method, which is applied to one of the application services, and the method includes:

[0016] In response to a local service call request from a target application service, obtaining a link identifier of the target application service, a call link depth, and a call mode corresponding to the service call request from the service call request;

[0017] Execute business processing logic to obtain the database name, connection establishment time and connection release time of the database, and generate a database connection log based on the link identifier, call link depth, database name, database connection establishment time and connection release time. The business processing logic includes establishing a database connection and releasing a database connection, so that the transaction nesting detection device can perform transaction nesting detection based on the database connection log and the link call log, and the link call log includes the call link depth.

[0018] In one embodiment, the step of executing the business processing logic to obtain the database name, connection establishment time and connection release time of the database, and generating a database connection log based on the link identifier, call link depth, database name, database connection establishment time and connection release time includes:

[0019] Execute business processing logic;

[0020] In the process of establishing and releasing a database connection, the database name of the database is obtained, and the database connection establishment time and connection release time are captured through a pre-defined AOP aspect. Based on the link identifier, call link depth, database name, database connection establishment time and connection release time, a database connection log is generated. The AOP aspect focuses on the method required to call to establish the database connection and the method required to call to release the database connection.

[0021] In one embodiment, in the process of establishing a database connection, the database name of the database is obtained, and when it is detected that the openSession method of the SqlSessionFactory is called, the AOP aspect is triggered to execute the first aspect logic: based on the database name, link identifier and the call link depth, a log object is created, the database connection establishment time is stored in the log object, and the log object is injected into the SqlSession instance as an InvocationHandler, and the connection establishment time is the time when the openSession method is called;

[0022] In the process of releasing the database connection, if the SqlSession instance calls the close method, the AOP aspect is triggered and the second aspect logic is executed: the connection release time is stored in the log object to obtain the database connection log, and the connection release time is the time when the close method is called.

[0023] In addition, to achieve the above-mentioned purpose, the present application also proposes a transaction nesting detection device, the transaction nesting detection device comprising:

[0024] An acquisition module is used to acquire the database connection log and link call log recorded by each application service, wherein the database connection log includes the link identifier of the application service that initiated the service call request, the call link depth, the database name, the database connection establishment time and the connection release time, and the link call log includes the call method corresponding to the service call request;

[0025] A judgment module is used to judge whether there is a nested relationship between database transactions initiated by the first application service under the same link based on the connection establishment time, connection release time, and calling method of the database, wherein the first application service under the same link is an application service that starts a database transaction for a database with the same database name under a link with the same link identifier.

[0026] In addition, to achieve the above-mentioned purpose, the present application also proposes a transaction nesting detection device, which includes: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the transaction nesting detection method described above.

[0027] In addition, to achieve the above-mentioned purpose, the present application also proposes a storage medium, which is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the transaction nesting detection method described above are implemented.

[0028] In addition, to achieve the above-mentioned purpose, the present application also provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, the steps of the transaction nesting detection method described above are implemented.

[0029] One or more technical solutions proposed in this application have at least the following technical effects:

[0030] The transaction nesting detection device of the present application obtains the database connection log including the link identification, call link depth, database name, database connection establishment time and connection release time of the application service that initiates the service call request, and the link call log including the call method corresponding to the service call request, that is, the transaction nesting detection device can obtain the link identification, call link depth, database name, database connection establishment time and connection release time of the application service that initiates the service call request related to the database transaction in real time, and the call method corresponding to the service call request related to the link call; based on the obtained link identification and link call depth of the application service that initiates the service call request, the first application service under the same link can be determined. It can be understood that the application service that starts the database transaction for the database with the same database name under the link with the same link identification is the first application service under the same link.

[0031] Since there is a situation where a single application calls multiple services under the same call link, and multiple services under the single application start database transactions at the same time, there is transaction nesting between the multiple services under the single application. The transaction nesting detection device of the present application needs to determine whether there is a nested relationship between the database transactions started by the first application service under the same link. Specifically, the judgment can be made based on the database connection establishment time, connection release time and the calling method. It can be understood that the database connection establishment time and connection release time can reflect the start time and end time of the database transactions started by the first application service under the same link for the same database, respectively, the call link depth can reflect the upstream and downstream relationship of the first application service under the same link, and the calling method can reflect the dependency relationship between the database transactions started by the first application service. Based on the start time, end time, upstream and downstream relationship and dependency relationship, it can be accurately determined whether there is a nested relationship between the database transactions started by the first application service under the same link. Compared with the static code analysis method in the related art that can only analyze the source code of the application framework and cannot analyze the service call situation during dynamic operation, the present application adopts the above method to improve the detection accuracy of database transaction nesting. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0033] In order to more clearly illustrate the embodiments of the present application or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, for ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative labor.

[0034] Figure 1 A flowchart of the first embodiment of the transaction nesting detection method of the present application is provided;

[0035] Figure 2 A schematic diagram of a first scenario provided for the first embodiment of the transaction nesting detection method of the present application;

[0036] Figure 3 A schematic diagram of a second scenario provided in Example 1 of the transaction nesting detection method of the present application;

[0037] Figure 4 A schematic diagram of a third scenario provided in Example 1 of the transaction nesting detection method of the present application;

[0038] Figure 5 A schematic diagram of a fourth scenario provided in Example 1 of the transaction nesting detection method of the present application;

[0039] Figure 6A flowchart of the second embodiment of the transaction nesting detection method of the present application is provided;

[0040] Figure 7 A schematic diagram of the fifth scenario provided in Example 2 of the transaction nesting detection method of the present application;

[0041] Figure 8 This is a schematic diagram of the module structure of a transaction nesting detection device according to an embodiment of the present application;

[0042] Fig. 9 Schematic diagram of the device structure of the hardware operating environment involved in the transaction nesting detection method in the embodiment of the present application.

[0043] The purpose, features and advantages of this application will be further described in conjunction with the embodiments and with reference to the accompanying drawings. DETAILED DESCRIPTION

[0044] It should be understood that the specific embodiments described herein are only used to explain the technical solutions of the present application and are not used to limit the present application.

[0045] In order to better understand the technical solution of the present application, a detailed description will be given below in conjunction with the accompanying drawings and specific implementation methods.

[0046] Based on this, the embodiment of the present application provides a transaction nesting detection method, referring to Figure 1 , Figure 1 This is a flow chart of the first embodiment of the transaction nesting detection method of the present application.

[0047] In this embodiment, the transaction nesting detection method includes steps S10 to S20:

[0048] Step S10, obtaining the database connection log and link call log recorded by each application service, wherein the database connection log includes the link identifier of the application service that initiates the service call request, the call link depth, the database name, the database connection establishment time and the connection release time, and the link call log includes the call method corresponding to the service call request;

[0049] It should be noted that the executor of this embodiment is a transaction nesting detection device, specifically, it can be a computing service device with data processing, network communication and program running functions, such as a tablet computer, personal computer, mobile phone, etc., or an electronic device that can realize the above functions.

[0050] Since the static code analysis method in the related art can only analyze the source code of the application framework, it cannot analyze the service calls in the dynamic operation process. If there are multiple service calls in a single application under the same call link, and multiple services under the single application start database transactions at the same time, there will be nested transactions between the multiple services under the single application, such as Figure 2 As shown, Application A Service A1 and Application A Service A2 are two services under a single application. The database transaction started by Application A Service A1 needs to wait for the downstream request to be completed before it can end, and the database transaction started by the downstream Application B Service B1 also needs to wait for the downstream request to be completed before it can end. The downstream application service of Application B Service B1 is Application A Service A2. Therefore, there is a nesting between the database transaction started by Application A Service A1 and the database transaction started by Application A Service A2, resulting in the database connection occupied by Application A Service A1 not being released, eventually causing a deadlock; however, the static code analysis method cannot accurately detect this kind of database transaction nesting.

[0051] In order to solve the above problem, this embodiment aims to accurately detect the above database transaction nesting situation through a transaction nesting detection device.

[0052] First, obtain the database connection log and link call log recorded by each application service. Specifically, you can use Apache Flink (an open source framework for stream processing and batch processing) to obtain the database connection log in real time from Kafka Topic (a topic or category for message storage). You can access the log management module of each application service to obtain the corresponding link call log based on the link identifier and call link depth.

[0053] Among them, the database connection log includes the link identifier of the application service that initiates the service call request, the call link depth, the database name, the database connection establishment time and the connection release time. Specifically, the database connection log can be recorded in real time during the execution of business processing logic by each application service after responding to the service call request; the link call log includes the call method corresponding to the service call request, and the link call log can be determined and recorded by each application service when initiating a response to the service call request.

[0054] It should be noted that, refer to Figure 3The link identifier can be TraceId (tracing ID), the call link depth can be determined based on SpanId (span ID), the link identifier is generated when the service call request is initiated, and the link identifiers in the same call link are consistent. SpanId is used to identify each hop call request under the same link. The database name can be database D, database E, etc.; the calling methods corresponding to the service call request include synchronous calling and asynchronous calling, etc. The asynchronous calling method enables the application service to release the database connection immediately after completing the service call request, without waiting for the return result of the downstream application service, and will not cause deadlock; the connection release time is the connection establishment time plus the total connection time.

[0055] Step S20, based on the connection establishment time, connection release time, and calling method of the database, determine whether there is a nested relationship between database transactions initiated by the first application service under the same link, wherein the first application service under the same link is an application service that initiates database transactions for a database with the same database name under a link with the same link identifier.

[0056] It should be noted that the database connection establishment time and connection release time can reflect the start time and end time of the database transactions initiated by the first application service under the same link for the same database, the call link depth can reflect the upstream and downstream relationships of the first application service under the same link, and the calling method can reflect the dependency relationship between the database transactions initiated by the first application service. Based on the start time, end time, upstream and downstream relationships, and dependency relationships, it is possible to accurately determine whether there is a nested relationship between the database transactions initiated by the first application service under the same link.

[0057] Specifically, the first application service under the same link may be screened based on the link identifier and the database name summarized in the database connection log.

[0058] Further, the implementation method of judging whether there is a nested relationship between database transactions initiated by the first application service under the same link based on the connection establishment time, the connection release time, and the calling mode of the database may be:

[0059] Determine whether the call link depths of the first application services are the same; if not, determine whether the duration periods of the database transactions initiated by the first application service are in an inclusion relationship based on the connection establishment time and the connection release time of the database; if they are an inclusion relationship, determine whether there is a nested relationship between the database transactions initiated by the first application service under the same link based on the calling method of the upstream application service of the second application service, wherein the second application service is the application service with the latest connection establishment time among the first application services.

[0060] Even if the first application service under the same link starts a database transaction for the same database, transaction nesting will not occur. Therefore, this embodiment only performs transaction nesting detection on the first application services with different call link depths. The method for judging whether the call link depths of the first application services are the same can be: judging whether the call link depths are the same based on SpanId. If the sizes of SpanId are the same, the call link depths are the same; if the sizes of SpanId are the same, there is an upstream and downstream relationship between the first application services. For example, if the SpanIds corresponding to the first application services are 10, 14, and 15 respectively, the upstream and downstream relationships between the application services corresponding to 10, 14, and 15 are: upstream, midstream, and downstream.

[0061] Further, in order to facilitate judging whether the duration periods of the database transaction started by the first application service are inclusive of each other based on the connection establishment time and connection release time of the database; when a database connection log is added to the session window, the database connection log can be grouped based on the link identifier using the Session Window, and each group of database connection logs can be sorted from small to large based on the connection establishment time and connection release time of the database, with reference to Figure 4 .

[0062] Specifically, the connection release time can be used as the session window waterline. When no new connection log is generated within a preset time period (for example, within 15 minutes, or within 20 minutes, etc.), it is determined that the session window has ended; it is determined whether there are deeply inconsistent database connection logs in the session window. If not, new database connection logs continue to be obtained; if there are deeply inconsistent database connection logs, it is determined whether the duration periods of the database transaction initiated by the first application service are in an inclusion relationship.

[0063] For example, the database transactions initiated by the first application service for the same database are TR1 and TR2 respectively. If the start time of the database transaction TR1 is less than or equal to the start time of the database transaction TR2, and the end time of the database transaction TR1 is greater than or equal to the end time of the database transaction TR2, it is determined that the database transaction TR2 is nested in the database transaction TR1, that is, there is an inclusion relationship between TR1 and TR2.

[0064] Furthermore, due to the asynchronous invocation mode, the application service will release the database connection immediately after completing the service invocation request, without waiting for the return result of the downstream application service, and will not cause a deadlock; therefore, if there is an inclusion relationship between the duration periods of the database transactions initiated by the first application service, it is necessary to be based on the application services between the first application services (for example, the application A service A1 and the application A service A2 corresponding to the link 100 are both first application services, and the application services between the first application services include the application C service C1 and the application B service B1 corresponding to the link 100, refer to Figure 5 ) to determine whether there is a nested relationship between database transactions initiated by the first application service under the same link.

[0065] Specifically, it may be based on the calling mode of the upstream application service of the application service (the second application service, for example, the application A service A2 corresponding to the link 100) with the latest connection establishment time among the first application services, to determine whether there is a nested relationship between the database transactions initiated by the first application service under the same link; or it may be based on the calling mode of the downstream application service of the downstream application service (for example, the application A service A1 corresponding to the link 100) with the earliest connection establishment time among the first application services, to determine whether there is a nested relationship between the database transactions initiated by the first application service under the same link.

[0066] Specifically, the implementation method of judging whether there is a nested relationship between database transactions initiated by the first application service under the same link based on the calling mode of the upstream application service of the second application service may be:

[0067] Starting from the upper layer application service of the second application service, traverse whether the calling method of the upstream application service of the second application service is asynchronous calling; if the calling method of the upstream application service does not include asynchronous calling, determine whether there is a nested relationship between the database transactions started by the first application service under the same link.

[0068] It is understandable that it is possible to start from the upper layer application service of the second application service (for example, application B service B1 corresponding to link 100) and traverse whether the calling mode of the upstream application service of the second application service is asynchronous calling; Figure 5 If it is not an asynchronous call, then continue to traverse the upstream application service of the second application service (for example, the application C service C1 corresponding to link 100) to see if the calling mode is an asynchronous call; refer to Figure 5 If it is not an asynchronous call, it is determined that there is a nested relationship between the database transactions initiated by the first application service under the same link (between the database transactions respectively initiated by the application A service A1 and the application A service A2 corresponding to the link 100).

[0069] Based on the above method, the dependency relationship between each database transaction started during the dynamic link call process can be analyzed in real time, and based on the duration of each database transaction, it can be determined whether there is a nested relationship between the database transactions; compared with static code analysis tools, it can only analyze the dependency relationship between each service from the code level, and then determine whether transaction nesting logic will appear; this embodiment can improve the detection accuracy of database transaction nesting.

[0070] Based on this, the embodiment of the present application provides a microservice fuse processing method, referring to Figure 6 , Figure 6 This is a flow chart of the second embodiment of the microservice fuse processing method of the present application.

[0071] In this embodiment, the transaction nesting detection method includes steps S01 to S03:

[0072] Step S01, in response to a service call request from a target application service to a local service, obtaining a link identifier of the target application service, a call link depth, and a call mode corresponding to the service call request from the service call request;

[0073] It should be noted that the execution subject of this embodiment is one of the multiple application services.

[0074] Since static code scanning relies on code scanning rules and the adaptability of code scanning tools to the development framework, it is difficult for static code scanning to identify database transaction operations in business codes that use custom methods to operate the database and use dynamic proxies for aspect code programming, resulting in misjudgment and omission of transaction nested scenarios.

[0075] In order to solve the above problems, this embodiment aims to identify dynamic database transaction operations and improve the detection accuracy of database transaction nesting.

[0076] Specifically, one of the application services responds to a local service call request Servlet from a target application service other than the one of the application services among multiple application services, and obtains the link identifier, call link depth, and call method corresponding to the service call request of the target application service from the service call request.

[0077] It can be understood that the request header Http Header of the service call request will carry the link identifier of the target application service, the call link depth, and the call method corresponding to the service call request; refer to Figure 7, one of the application services can obtain the link information by parsing the request header of the service call request: the link identifier of the target application service, the call link depth, and the call method corresponding to the service call request; and store the link information in ThreadLocal (thread local variable).

[0078] Step S02, execute the business processing logic to obtain the database name, connection establishment time and connection release time of the database, and generate a database connection log based on the link identifier, call link depth, database name, database connection establishment time and connection release time. The business processing logic includes establishing a database connection and releasing a database connection, so that the transaction nesting detection device can perform transaction nesting detection based on the database connection log and the link call log, and the link call log includes the call link depth.

[0079] Furthermore, one of the application services executes the business processing logic: obtains the database connection, the DAO (Data Access Object) layer handles the operations of interacting with the database, thereby establishing a database connection, accessing the database, releasing the database connection, and ending the service call. Figure 7 ; That is, the business processing logic includes establishing a database connection and releasing a database connection.

[0080] It can be understood that in the process of executing the above-mentioned business processing logic, the database name, connection establishment time and connection release time of the database can be obtained, and based on the link identifier, call link depth, database name, database connection establishment time and connection release time, a database connection log is generated.

[0081] Specifically, the execution of the business processing logic to obtain the database name, connection establishment time and connection release time of the database, and based on the link identifier, call link depth, database name, database connection establishment time and connection release time, the implementation method of generating a database connection log may be:

[0082] Execute business processing logic; wherein, in the process of establishing and releasing a database connection, obtain the database name of the database, and capture the database connection establishment time and connection release time through a predefined AOP (Aspect Oriented Pr ogramming) aspect, and generate a database connection log based on the link identifier, call link depth, database name, database connection establishment time and connection release time. The AOP aspect focuses on the method required to call to establish the database connection and the method required to call to release the database connection.

[0083] It should be noted that in the process of establishing and releasing database connections, the database connection details can be obtained through the DataSource object to obtain the database name of the database; the database connection establishment time and connection release time can be captured through the pre-defined AOP aspect.

[0084] For example, define an AOP aspect that executes predefined code before and after the method call of interest. For example, the database connection establishment time can be obtained after the method required to establish the database connection is called, and the database connection release time can be obtained after the method required to release the database connection is called.

[0085] Specifically, in the process of establishing a database connection, the database name of the database is obtained, and when it is detected that the openSession method of the SqlSessionFactory is called, the AOP aspect is triggered to execute the first aspect logic: based on the database name, link identifier and the call link depth, a log object is created, the database connection establishment time is stored in the log object, and the log object is injected into the SqlSession instance as an InvocationHandler. The connection establishment time is the time when the openSession method is called.

[0086] It should be noted that when one of the application services detects that the openSession method of SqlSessionFactory is called, the AOP aspect is triggered and the first aspect logic is executed (a predefined code for the case where the method required to be called to establish the database connection is concerned). Specifically, based on the database name, link identifier and the call link depth, a log object is created, the time when the openSession method is called is used as the database connection establishment time, and the database connection establishment time is stored in the log object.

[0087] Furthermore, in order to record all transaction operations of the database in real time, the log object can be injected into the SqlSession instance as an InvocationHandler, so that in the subsequent business processing logic execution process, when the SqlSession instance is called, information can be recorded in the log object in real time.

[0088] Therefore, in the process of releasing the database connection, if the SqlSession instance calls the close method, the AOP aspect is triggered and the second aspect logic is executed: the connection release time is stored in the log object to obtain the database connection log, and the connection release time is the time when the close method is called.

[0089] Specifically, when the SqlSession instance calls the close method, it means that the database connection has ended. At this time, the AOP aspect is triggered and the second aspect logic is executed (a predefined code for the case where the method required to release the database connection is called). For example, the time when the close method is called is used as the connection release time, and the connection release time is stored in the log object to obtain the database connection log, and the database connection log is sent to the preset Kafka Topic.

[0090] The transaction nesting detection device can obtain the database connection log from the Kafka Topic in real time and perform dynamic database transaction nesting detection.

[0091] In this embodiment, the AOP aspect is defined to dynamically intercept database transaction operations and record the database connection establishment time and connection release time. Compared with static code analysis tools, this embodiment does not rely on the code scanning rules and the degree of adaptation of the development framework. It can dynamically record the statements and execution time executed by the database, and realize dynamic detection of the nested relationship of database transactions, thereby improving the detection accuracy of nested database transactions.

[0092] It should be noted that the above examples are only used to understand the present application and do not constitute a limitation on the transaction nesting detection method of the present application. More simple transformations based on this technical concept are all within the protection scope of the present application.

[0093] This application also provides a transaction nesting detection device, please refer to Figure 8 , the transaction nesting detection device comprises:

[0094] The acquisition module 10 is used to obtain the database connection log and link call log recorded by each application service, wherein the database connection log includes the link identifier of the application service that initiated the service call request, the call link depth, the database name, the database connection establishment time and the connection release time, and the link call log includes the call method corresponding to the service call request;

[0095] The judgment module 20 is used to judge whether there is a nested relationship between database transactions initiated by the first application service under the same link based on the connection establishment time, the connection release time, and the calling method of the database, wherein the first application service under the same link is an application service that starts a database transaction for a database with the same database name under a link with the same link identifier.

[0096] The transaction nesting detection device provided by the present application adopts the transaction nesting detection method in the above embodiment, which can solve the technical problem of low detection accuracy of database transaction nesting. Compared with the prior art, the beneficial effects of the transaction nesting detection device provided by the present application are the same as the beneficial effects of the transaction nesting detection method provided by the above embodiment, and other technical features in the transaction nesting detection device are the same as the features disclosed in the above embodiment method, which will not be repeated here.

[0097] The present application provides a transaction nesting detection device, which includes: at least one processor; and a memory communicatively connected to the at least one processor; wherein the memory stores instructions executable by the at least one processor, and the instructions are executed by the at least one processor so that the at least one processor can execute the transaction nesting detection method in the above-mentioned embodiment 1.

[0098] Reference below Fig. 9 , which shows a schematic diagram of the structure of a transaction nesting detection device suitable for implementing the embodiment of the present application. The transaction nesting detection device in the embodiment of the present application may include but is not limited to mobile terminals such as mobile phones, tablet computers, laptop computers, digital broadcast receivers, PDAs (Personal Digital Assistants), PMPs (Portable Media Players), vehicle terminals (such as vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Fig. 9 The transaction nesting detection device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0099] like Fig. 9As shown, the transaction nesting detection device may include a processing device 1001 (e.g., a central processing unit, a graphics processing unit, etc.), which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM: Read Only Memory) 1002 or a program loaded from a storage device 1003 to a random access memory (RAM: Random Access Memory) 1004. In the RAM 1004, various programs and data required for the operation of the transaction nesting detection device are also stored. The processing device 1001, the ROM 1002, and the RAM 1004 are connected to each other through a bus 1005. An input / output (I / O) interface 1006 is also connected to the bus. Generally, the following systems can be connected to the I / O interface 1006: an input device 1007 including, for example, a touch screen, a touch pad, a keyboard, a mouse, an image sensor, a microphone, an accelerometer, a gyroscope, etc.; an output device 1008 including, for example, a liquid crystal display (LCD: Liquid Crystal Display), a speaker, a vibrator, etc.; a storage device 1003 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 1009. The communication device 1009 may allow the transaction nesting detection device to communicate with other devices wirelessly or by wire to exchange data. Although the transaction nesting detection device with various systems is shown in the figure, it should be understood that it is not required to implement or have all the systems shown. More or fewer systems may be implemented or have alternatively.

[0100] In particular, according to the embodiments disclosed in the present application, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present application include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from a network through a communication device, or installed from a storage device 1003, or installed from a ROM 1002. When the computer program is executed by the processing device 1001, the above-mentioned functions defined in the method of the embodiment disclosed in the present application are executed.

[0101] The transaction nesting detection device provided by the present application adopts the transaction nesting detection method in the above embodiment, which can solve the technical problem of low detection accuracy of database transaction nesting. Compared with the prior art, the beneficial effects of the transaction nesting detection device provided by the present application are the same as the beneficial effects of the transaction nesting detection method provided by the above embodiment, and other technical features in the transaction nesting detection device are the same as the features disclosed in the method of the previous embodiment, which will not be repeated here.

[0102] It should be understood that the various parts disclosed in this application can be implemented by hardware, software, firmware or a combination thereof. In the description of the above embodiments, specific features, structures, materials or characteristics can be combined in any one or more embodiments or examples in a suitable manner.

[0103] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto. Any person skilled in the art who is familiar with the present technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

[0104] The present application provides a computer-readable storage medium having computer-readable program instructions (ie, computer programs) stored thereon, and the computer-readable program instructions are used to execute the transaction nesting detection method in the above-mentioned embodiment.

[0105] The computer-readable storage medium provided in the present application may be, for example, a USB flash drive, but is not limited to electrical, magnetic, optical, electromagnetic, infrared, or semiconductor systems, systems or devices, 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 wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM 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 this embodiment, the 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, system or device. The program code contained on the computer-readable storage medium may be transmitted using any appropriate medium, including but not limited to: wires, optical cables, RF (Radio Frequency), etc., or any suitable combination of the above.

[0106] The computer-readable storage medium may be included in the transaction nesting detection device; or may exist independently without being assembled into the transaction nesting detection device.

[0107] The computer-readable storage medium carries one or more programs. When the one or more programs are executed by the transaction nesting detection device, the transaction nesting detection device executes the transaction nesting detection method.

[0108] 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).

[0109] 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 each embodiment 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 implementations as replacements, 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.

[0110] The modules involved in the embodiments described in this application may be implemented by software or hardware, wherein the name of the module does not constitute a limitation on the unit itself in some cases.

[0111] The readable storage medium provided by the present application is a computer-readable storage medium, which stores computer-readable program instructions (i.e., computer programs) for executing the above-mentioned transaction nesting detection method, and can solve the technical problem of low detection accuracy of database transaction nesting. Compared with the prior art, the beneficial effects of the computer-readable storage medium provided by the present application are the same as the beneficial effects of the transaction nesting detection method provided by the above-mentioned embodiment, and will not be repeated here.

[0112] The present application also provides a computer program product, including a computer program, which implements the steps of the transaction nesting detection method as described above when executed by a processor.

[0113] The computer program product provided by the present application can solve the technical problem of low accuracy in detecting nested database transactions. Compared with the prior art, the beneficial effects of the computer program product provided by the present application are the same as those of the transaction nesting detection method provided by the above embodiment, which will not be elaborated here.

[0114] The above descriptions are only some embodiments of the present application, and are not intended to limit the patent scope of the present application. All equivalent structural changes made using the contents of the present application specification and drawings under the technical concept of the present application, or direct / indirect applications in other related technical fields are included in the patent protection scope of the present application.

Claims

1. A transaction nesting detection method, characterized in that: Applied to a transaction nesting detection device, the method includes: Obtain the database connection log and link call log recorded by each application service, wherein the database connection log includes the link identifier of the application service that initiates the service call request, the call link depth, the database name, the database connection establishment time and the connection release time, and the link call log includes the call method corresponding to the service call request; Based on the connection establishment time, connection release time, and calling method of the database, determine whether there is a nested relationship between database transactions initiated by the first application service under the same link, wherein the first application service under the same link is an application service that initiates database transactions for a database with the same database name under a link with the same link identifier.

2. The method according to claim 1, characterized in that The step of judging whether there is a nested relationship between database transactions started by the first application service under the same link based on the connection establishment time, the connection release time, and the calling mode of the database includes: Determining whether the call link depths of the first application services are the same; If they are not the same, judging whether the duration periods of the database transaction started by the first application service are in an inclusive relationship based on the connection establishment time and the connection release time of the database; If it is an inclusion relationship, based on the calling method of the upstream application service of the second application service, it is determined whether there is a nested relationship between the database transactions initiated by the first application service under the same link, wherein the second application service is the application service with the latest connection establishment time among the first application services.

3. The method according to claim 2, characterized in that The step of judging whether there is a nested relationship between database transactions initiated by the first application service under the same link based on the calling mode of the upstream application service of the second application service includes: Starting from the upper layer application service of the second application service, traverse the calling mode of the upstream application service of the second application service to see whether it is an asynchronous call; If the calling mode of the upstream application service does not include asynchronous calling, it is determined that there is a nested relationship between the database transactions started by the first application service under the same link.

4. A transaction nesting detection method, characterized in that: Applied to one of the application services, the method comprises: In response to a local service call request from a target application service, obtaining a link identifier of the target application service, a call link depth, and a call mode corresponding to the service call request from the service call request; Execute business processing logic to obtain the database name, connection establishment time and connection release time of the database, and generate a database connection log based on the link identifier, call link depth, database name, database connection establishment time and connection release time. The business processing logic includes establishing a database connection and releasing a database connection, so that the transaction nesting detection device can perform transaction nesting detection based on the database connection log and the link call log, and the link call log includes the call link depth.

5. The method according to claim 4, characterized in that The step of executing the business processing logic to obtain the database name, connection establishment time and connection release time of the database, and generating a database connection log based on the link identifier, call link depth, database name, database connection establishment time and connection release time includes: Execute business processing logic; In the process of establishing and releasing a database connection, the database name of the database is obtained, and the database connection establishment time and connection release time are captured through a pre-defined AOP aspect. Based on the link identifier, call link depth, database name, database connection establishment time and connection release time, a database connection log is generated. The AOP aspect focuses on the method required to call to establish the database connection and the method required to call to release the database connection.

6. The method according to claim 5, characterized in that In the process of establishing a database connection, the database name of the database is obtained, and when it is detected that the openSession method of the SqlSessionFactory is called, the AOP aspect is triggered to execute the first aspect logic: based on the database name, link identifier and the call link depth, a log object is created, the database connection establishment time is stored in the log object, and the log object is injected into the SqlSessio n instance as an InvocationHandler. The connection establishment time is the time when the openSession method is called; In the process of releasing the database connection, if the SqlSession instance calls the close method, the AOP aspect is triggered and the second aspect logic is executed: the connection release time is stored in the log object to obtain the database connection log, and the connection release time is the time when the close method is called.

7. A transaction nesting detection device, characterized in that: The device comprises: An acquisition module is used to acquire the database connection log and link call log recorded by each application service, wherein the database connection log includes the link identifier of the application service that initiated the service call request, the call link depth, the database name, the database connection establishment time and the connection release time, and the link call log includes the call method corresponding to the service call request; A judgment module is used to judge whether there is a nested relationship between database transactions initiated by the first application service under the same link based on the connection establishment time, connection release time, and calling method of the database, wherein the first application service under the same link is an application service that starts a database transaction for a database with the same database name under a link with the same link identifier.

8. A transaction nesting detection device, characterized in that: The device comprises: a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the computer program is configured to implement the steps of the transaction nesting detection method according to any one of claims 1 to 6.

9. A storage medium, characterized in that: The storage medium is a computer-readable storage medium, and a computer program is stored on the storage medium. When the computer program is executed by a processor, the steps of the transaction nesting detection method according to any one of claims 1 to 6 are implemented.

10. A computer program product, characterized in that The computer program product comprises a computer program, and when the computer program is executed by a processor, the steps of the transaction nesting detection method according to any one of claims 1 to 6 are implemented.

Citation Information

Patent Citations

  • Real-time database failure recovery method under nested transaction model

    CN101794247A

  • Dynamic predictor for coalescing memory transactions

    US20150169361A1