Abnormality processing system and method, electronic device, storage medium, and program product

Through the transaction rollback interceptor and manager in the exception handling system, the transaction status and exception information in the Spring transaction management component are monitored and recorded, and the rollback report is generated, which solves the problem of unexpected rollback exception positioning in the Spring transaction management component. Improve development efficiency and system stability.

CN118916232APending Publication Date: 2024-11-08CCB FINTECH CO LTD
View PDF 0 Cites 2 Cited by

Patent Information

Application Number
CN202410973528.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-07-19
Publication Date
2024-11-08

AI Technical Summary

Technical Problem

In multi-level nested transaction method calls, existing Spring transaction management components cannot efficiently locate and resolve unexpected rollback exceptions, making it difficult for developers and maintenance personnel to quickly locate the causes of exceptions, affecting efficiency and system stability.

Method used

Provide an exception handling system, including a transaction rollback interceptor and a transaction rollback manager, which generates exception rollback reports by monitoring and recording transaction status and exception information, works together to monitor and record transaction status and exceptions in real time, and locates back The specific location and root cause of the roll exception.

Benefits of technology

It significantly improves the efficiency of development and maintenance, enhances the stability and reliability of the system, reduces the time and energy to locate the causes of abnormalities, and quickly solves the problem through exception rollback reports.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118916232A_ABST
    Figure CN118916232A_ABST
Patent Text Reader

Abstract

The invention provides an exception handling system and method, electronic equipment, a storage medium and a program product, and relates to the technical field of big data, a transaction rollback interceptor is used for checking a current transaction state when an exception thrown out by a transaction management component is captured in the operation process of a response business logic method, recording a transaction execution state and a transaction rollback state, and reporting related information to a transaction rollback manager; the transaction rollback manager is used for recording abnormal related information and a transaction state; and when the transaction state is a non-execution state and the exception is an unexpected rollback exception, generating an exception rollback report for operating the business logic method based on the recorded transaction state and exception related information. According to the method and the device, the transaction state and the exception are monitored and recorded, and when the captured exception is an accidental rollback exception, the exception rollback report is generated according to the recorded related information, so that related personnel can quickly position the position and the reason of the exception rollback, and the development and maintenance efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of big data technology, and in particular to an exception handling system, method, electronic device, storage medium and program product. Background Art

[0002] The Spring framework is an open source framework widely used in Java server-side programming. Its transaction management component has become the de facto standard in the field of transaction management. The Spring transaction management component is powerful, configurable based on annotations, easy to use, and can automatically complete transaction control, including transaction opening, committing, and rollback operations based on exception capture, which allows developers to write business logic without explicitly managing transaction opening and rollback. Although the Spring transaction management component provides a powerful automatic rollback mechanism, in some scenarios, the automatic rollback mechanism is not perfect, especially in multi-level nested transaction method calls.

[0003] In the related art, when the inner logic triggers an exception for some reason, the Spring transaction management component will mark the current transaction as a global rollback state. However, if the exception is abnormally captured by the outer logic and no exception that triggers the transaction rollback is thrown in the outer logic, the Spring transaction management component will perform a rollback operation when the transaction is committed because the transaction is marked as a global rollback state, and throw an unexpected rollback exception, namely, an UnexpectedRollbackException. For developers or maintenance personnel, it takes a lot of time and effort to locate the cause of the exception. Therefore, it is urgent to provide an efficient solution for locating exceptions in the Spring transaction management component. Summary of the invention

[0004] The present application provides an exception handling system, method, electronic device, storage medium and program product to solve the problem in the related art that exceptions in Spring transaction management components cannot be efficiently located.

[0005] In a first aspect, the present application provides an exception handling system, including: a transaction rollback interceptor and a transaction rollback manager, wherein:

[0006] The transaction rollback interceptor is used to respond to the exception thrown by the transaction management component during the operation of the business logic method, check the current transaction status, record the transaction execution status and transaction rollback status, and report the transaction status and exception related information to the transaction rollback manager. The business logic method is annotated with management transactions;

[0007] The transaction rollback manager is used to record exception-related information and transaction status when the transaction status is in the execution state; and when the transaction status is in the non-execution state and the exception is an unexpected rollback exception, generate an exception rollback report for running the business logic method based on the recorded transaction status and exception-related information.

[0008] In a possible implementation, the transaction rollback interceptor is also used to: record whether the thread is in a transaction execution state, and initiate a call to a transaction management component; correspondingly, the transaction management component is also used to: detect whether the thread has opened a transaction, and when the thread has not opened a transaction, open the transaction and initiate a call to a business logic method; when the thread has opened a transaction, mark the transaction execution state and initiate a call to a business logic method.

[0009] In a possible implementation, the transaction rollback manager is further used to output the exception rollback report in at least one of the following forms: recording the exception rollback report to a local log file; writing the exception rollback report to a set storage medium; sending the exception rollback report to a remote target receiving device.

[0010] In a possible implementation, the exception handling system also includes a type judgment component and a transaction rollback monitoring entry point component, and the type judgment component and the transaction rollback interceptor are internal components of the transaction rollback monitoring entry point component; wherein the type judgment component is used to provide filtering rules, and the filtering rules are used to determine whether to call the transaction rollback interceptor before calling the business logic method; the transaction rollback monitoring entry point component is used to provide a transaction rollback interceptor to enhance the business logic method that meets the requirements according to the filtering rules provided by the type judgment component.

[0011] In one possible implementation, the exception handling system is constructed in the following manner: in response to the startup instruction of the application, the bootstrap class for the application startup is loaded; based on the default configuration rule of the application, the preset rollback monitor configuration file is parsed to obtain the definition of the singleton object of the rollback monitor configuration component, the transaction rollback monitoring entry point component and the transaction rollback manager; according to the standard package scanning and configuration class loading rule results, the instances of the rollback monitor configuration component and the transaction rollback monitoring entry point component are loaded, wherein the type judgment component and the transaction rollback interceptor are instantiated during the instantiation process of the transaction rollback monitoring entry point component; the transaction rollback manager is instantiated during the instantiation process of the type judgment component; and, when loading the instance of the transaction rollback monitoring entry point component, the parsing annotation-style transaction attribute component and the transaction aspect support component are introduced, the parsing annotation-style transaction attribute component is used to parse the transaction annotation into transaction attributes, and the transaction aspect support component is used for transaction management.

[0012] In a possible implementation, the transaction management component is specifically used to: when an exception generated during the operation of a business logic method is captured, determine whether the current state is in the method layer corresponding to the open transaction; when the state is not in the method layer corresponding to the open transaction and the transaction is in the transaction execution state, mark the transaction as a rollback state, throw the generated exception to the upper-layer method and record the transaction rollback state; when the state is in the layer corresponding to the open transaction, initiate a transaction commit operation, detect the transaction state during the transaction commit process, and if it is in the rollback state, execute a rollback operation, throw the generated exception to the upper-layer method and record the transaction rollback state.

[0013] In one possible implementation, the transaction rollback interceptor is also used to insert additional processing logic before the business logic method is called; correspondingly, the transaction management component is also used to: before calling the business logic method, sequentially call the reflection mechanism method of the transaction rollback interceptor and the reflection mechanism method of the transaction management component to enhance the business logic method.

[0014] In a second aspect, the present application provides an exception handling method, which is applied to the exception handling system described in any one of the first aspects, and the exception handling method includes:

[0015] Monitor the running process of business logic methods with management transaction annotations;

[0016] Record the transaction status of the transaction management component during the operation of the business logic method;

[0017] If an exception thrown by the transaction management component is caught during the operation of the business logic method, the exception-related information is recorded, and the exception-related information includes the location where the exception occurred;

[0018] If the transaction status is an execution status, record the transaction status and exception related information; and if the transaction status is a non-execution status and the exception is an unexpected rollback exception, generate an exception rollback report for running the business logic method based on the recorded transaction status and exception related information.

[0019] In a third aspect, the present application provides an electronic device, comprising: a processor, and a memory communicatively connected to the processor;

[0020] Memory for storing computer-executable instructions;

[0021] A processor is used to execute computer-executable instructions stored in the memory to implement the method described in any one of the first aspects.

[0022] In a fourth aspect, the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed, they are used to implement any method described in the first aspect.

[0023] In a fifth aspect, the present application provides a computer program product, including a computer program, which implements the method described in any one of the first aspects when executed.

[0024] The exception handling system, method, electronic device, storage medium and program product provided by the present application, wherein a transaction rollback interceptor is used to check the current transaction status, record the transaction execution status and transaction rollback status, and report the transaction status and exception-related information to the transaction rollback manager in response to an exception thrown by a transaction management component captured during the operation of a business logic method, wherein the business logic method carries annotations for managing transactions; the transaction rollback manager is used to record exception-related information and the transaction status when the transaction status is an execution status; and when the transaction status is a non-execution status and the exception is an unexpected rollback exception, based on the recorded transaction status and exception-related information, generate an exception rollback report for the operation of the business logic method. Through the collaborative work of the transaction rollback interceptor and the transaction rollback manager, real-time monitoring and recording of transaction status and exceptions during the operation of business logic methods with management transaction annotations can be achieved, and exceptions during the operation can be captured. When the exception is an unexpected rollback exception, an exception rollback report is generated based on the recorded transaction status and exception-related information, so that developers or maintenance personnel do not need to spend a lot of time and energy to locate the cause of the exception. Based on the exception rollback report, the specific location and root cause of the transaction exception rollback can be quickly located, thereby significantly improving the efficiency of development and maintenance, and further enhancing the stability and reliability of the system. BRIEF DESCRIPTION OF THE DRAWINGS

[0025] 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.

[0026] Figure 1 A schematic diagram of a common Spring transaction management exception handling process in the related art provided for an exemplary embodiment of the present application;

[0027] Figure 2 An application scenario diagram of an exception handling system is provided for an exemplary embodiment of the present application;

[0028] Figure 3 A schematic diagram of the structure of an exception handling system provided for an exemplary embodiment of the present application;

[0029] Figure 4 A schematic diagram of the actual calling sequence of calling a business logic method provided by an exemplary embodiment of the present application;

[0030] Figure 5 A system architecture diagram of an exception handling system provided for an exemplary embodiment of the present application;

[0031] Figure 6 A flowchart of an exception handling method provided for an exemplary embodiment of the present application;

[0032] Figure 7 Another flowchart of an exception handling method provided by an exemplary embodiment of the present application;

[0033] Figure 8 A schematic diagram of the structure of an electronic device provided for an exemplary embodiment of the present application.

[0034] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION

[0035] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.

[0036] The terms "first", "second", etc. in the specification and claims of the present application are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchangeable in appropriate circumstances, so that the embodiments of the present application described herein can be implemented in a sequence other than those illustrated or described herein, for example. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, the process, system, product or equipment comprising a series of steps or units need not be limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, products or equipment.

[0037] It should be noted that in the technical solution of this application, the collection, storage, use, processing, transmission, provision and disclosure of information such as financial data or user data involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals. In the embodiments of this application, some existing solutions in the industry such as certain software, components, models, etc. may be mentioned, which should be considered as exemplary, and their purpose is only to illustrate the feasibility of the implementation of the technical solution of this application, but it does not mean that the applicant has or will necessarily use the solution. The user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data need to comply with relevant laws, regulations and standards, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0038] It should be noted that, in this article, the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of more restrictions, an element defined by the sentence "comprises a ..." does not exclude the existence of other identical elements in the process, method, article or device including the element.

[0039] For example, Figure 1 The following is a schematic diagram of a common Spring transaction management exception handling process in the related art provided by the exemplary embodiment of this application. Figure 1 As shown, the user throws an exception in the inner method (i.e., the second method), which triggers a change in the transaction rollback status in the transaction management component of the interceptor aspect (Spring-TX-AOP). However, the exception is captured and intercepted by the business code of the aggregation layer (UsersFacade), and reaches the transaction management component again in the form of normal return data. The transaction management component receives the normal request and commits the transaction as normal. However, when checking the transaction exception, it finds the transaction rollback status marked in the previous step. Therefore, the rollback operation is performed and an unexpected rollback exception (UnexpectedRollbackException) is thrown.

[0040] Because in the related art, there is no direct correlation between the unexpected rollback exception and the exception that causes the business error, and the description information for the unexpected rollback exception is vague, does not mark the specific location of the transaction error, and does not explain the root cause of the exception. For developers or maintainers who are not familiar with the Spring transaction framework, it is difficult to find the root cause of the exception based on the unexpected rollback exception, which is not conducive to developers or maintainers tracking the problem; at the same time, the exception occurs outside the inner method code, and the conventional exception capture mechanism cannot effectively capture the exception.

[0041] In order to solve the above problems, an embodiment of the present application provides an exception handling solution, which monitors the running process of the business logic method with management transaction annotations, records the transaction status during the running process of the business logic method, captures the thrown exceptions and records the exception-related information. When an unexpected rollback exception occurs, the specific location and root cause of the abnormal transaction rollback are located based on the recorded transaction status and exception-related information.

[0042] Figure 2 The application scenario diagram of the exception handling system is provided for the exemplary embodiment of the present application. Figure 2 As shown, the application scenario includes a first client 21, a server 22, and a second client 23, wherein the number of the first client 21 and the second client 23 can be at least one. The exception handling system is an application software deployed on the server 22; or, the exception handling system is the server 22. In actual applications, for example, a user submits an operation request to call a business logic method with a management transaction annotation to the server 22 through the first client 21. After receiving the operation request, the exception handling system deployed on the server 22 monitors the running process of the business logic method with the management transaction annotation, and when an unexpected rollback exception is captured, generates an exception rollback report for running the business logic method, and sends the exception rollback report to the second client 23, so that developers or maintenance personnel can track problems based on the exception rollback report.

[0043] It should be noted that the server 22 can be replaced by a server cluster or other computing devices with certain computing power, and the terminal devices 21 and 23 can be mobile phones, computers, notebooks and personal digital assistants (PDA), etc., which are not limited here.

[0044] Combine the following Figure 2 For application scenarios, refer to Figure 3 To describe the exception handling based on Spring AOP mechanism according to the exemplary implementation of this application. It should be noted that the above application scenario is only shown to facilitate understanding of the spirit and principle of this application, and the implementation of this application is not subject to Figure 2 Limitations of the application scenario shown.

[0045] Figure 3 The schematic diagram of the structure of the exception handling system provided by the exemplary embodiment of the present application is as follows. Figure 3 As shown, the exception handling system 30 includes a transaction rollback interceptor 31 and a transaction rollback manager 32, wherein:

[0046] The transaction rollback interceptor 31 is used to respond to the exception thrown by the transaction management component during the operation of the business logic method, check the current transaction status, record the transaction execution status and transaction rollback status, and report the transaction status and exception-related information to the transaction rollback manager. The business logic method has annotations for managing transactions.

[0047] The transaction rollback interceptor (TxRollbackMonitorInterceptor) 31 is a transaction rollback interceptor type defined according to the transaction rollback interceptor (MethodInterceptor) interface specification of SpringAOP.

[0048] For example, the business logic method with the Transactional annotation is a multi-level nested transaction method, for example, the business logic method with the Transactional annotation includes a first method and a second method, wherein the business logic of the first method depends on the second method; correspondingly, the transaction management component (TransactionInterceptor) monitors the running process of the first method and the second method, and records the transaction status during the running process of the first method and the second method; if an exception is captured during the running process of the first method and the second method, the exception-related information is recorded, and the exception-related information includes the exception status, method execution status, thread status, etc.

[0049] Correspondingly, if an exception that causes transaction rollback is thrown during the execution of the second method, the transaction management component captures the exception when receiving the return value of the second method. Since it is detected that the current transaction is in an ongoing transaction, the current transaction state is marked as a rollback state, and the exception is thrown to the upper layer. Correspondingly, when the transaction rollback interceptor 31 captures the exception thrown by the transaction management component, it checks the current transaction state. If it is a transaction execution state and the transaction is marked as a rollback state, it reports the transaction state and exception-related information to the transaction rollback manager (TxRollbackManager) 32.

[0050] It should be noted that the above-mentioned business logic methods with Transactional annotations include the first method and the second method, which are only examples of business logic methods. Business logic methods may also include multi-level nested transaction methods such as the third method and the fourth method. The business logic methods are not limited here.

[0051] The transaction rollback manager 32 is used to record exception-related information and transaction status when the transaction status is an execution status; and when the transaction status is a non-execution status and the exception is an unexpected rollback exception, generate an exception rollback report for running the business logic method based on the recorded transaction status and exception-related information.

[0052] For example, the transaction rollback manager 32 records the exception-related information and the transaction status; if the exception is an unexpected rollback exception, based on the recorded transaction status and exception-related information, the abnormal call chain of the thread is detected, for example, there is an exception thrown in the second method, and after it is thrown, the corresponding transaction management component marks the transaction status as a rollback state; further, the transaction rollback manager 32 generates a report on the transaction exception rollback, and the report on the exception rollback records the direct location of the unexpected rollback exception in the first method, and the root cause of the unexpected rollback exception is due to the exception thrown by the second method. Further, the transaction rollback manager cleans up the transaction-related records in this thread and throws the unexpected rollback exception to the outer logic.

[0053] The exception handling system provided in the embodiment of the present application realizes real-time monitoring and recording of transaction status and exceptions during the operation of business logic methods with management transaction annotations through the collaborative work of a transaction rollback interceptor and a transaction rollback manager, captures exceptions during the operation, and when the exception is an unexpected rollback exception, generates an exception rollback report based on the recorded transaction status and exception-related information, so that developers or maintenance personnel do not need to spend a lot of time and energy to locate the cause of the exception. Based on the exception rollback report, the specific location and root cause of the transaction exception rollback can be quickly located, thereby significantly improving the efficiency of development and maintenance, and further enhancing the stability and reliability of the system.

[0054] Based on the above embodiments, in some embodiments, the transaction rollback manager is also used to output the exception rollback report in at least one of the following forms: recording the exception rollback report to a local log file; writing the exception rollback report to a set storage medium; sending the exception rollback report to a remote target receiving device.

[0055] For example, in one implementation, the exception rollback report is recorded in a local log file, which can be convenient for developers or maintenance personnel to review and analyze later; in another implementation, the exception rollback report is written to a set storage medium, such as a database and file system, so that the exception rollback report can be persistently stored and managed; in yet another implementation, the exception rollback report is sent to a remote target receiving device, such as sending it to a monitoring system, an alarm system or an operation and maintenance platform via a network, so that developers or maintenance personnel can monitor and handle exceptions in the operation of business logic methods in real time; through the above-mentioned various forms of exception rollback report output, developers or maintenance personnel can quickly locate and solve problems, thereby improving the efficiency of development and maintenance, and further enhancing the stability and reliability of the system.

[0056] In some embodiments, the transaction management component is specifically used to: when an exception generated during the execution of a business logic method is captured, determine whether the current state is in the method layer corresponding to the open transaction; when the state is not in the method layer corresponding to the open transaction and the transaction is in the transaction execution state, mark the transaction as a rollback state, throw the generated exception to the upper-layer method and record the transaction rollback state; when the state is in the layer corresponding to the open transaction, initiate a transaction commit operation, detect the transaction state during the transaction commit process, and if it is in the rollback state, execute a rollback operation, throw the generated exception to the upper-layer method and record the transaction rollback state.

[0057] For example, when an exception generated during the execution of the second method is captured, it is determined whether the current layer is in the method layer corresponding to the open transaction; if it is not in the method layer corresponding to the open transaction, and the transaction is in the transaction execution state, the current transaction is marked as a rollback state, and the generated exception is thrown to the upper-layer method and the transaction rollback state is recorded; correspondingly, the exception is thrown to the first method layer, the first method captures the runtime exception, performs custom processing (for example, hijacks the runtime exception) and no longer throws it upward, and selects normal return data and sends the data to the transaction management component; correspondingly, after receiving the return data of the first method, the transaction management component detects that the current level is in the layer corresponding to the transaction opening, and therefore initiates a transaction commit operation; and detects the transaction state during the transaction commit process. If it is in the rollback state, a rollback operation is performed, and the generated exception is thrown to the upper-layer method and the transaction rollback state is recorded.

[0058] In some embodiments, the transaction rollback interceptor is also used to: record whether the thread is in a transaction execution state, and initiate a call to a transaction management component; correspondingly, the transaction management component is also used to: detect whether the thread has opened a transaction, and when the thread has not opened a transaction, open the transaction and initiate a call to a business logic method; when the thread has opened a transaction, mark the transaction execution state and initiate a call to a business logic method.

[0059] For example, in response to a user's operation request, the transaction rollback interceptor records whether the thread is in a transaction execution state, and initiates a call to a transaction management component; correspondingly, the transaction management component is also used to detect whether the thread has opened a transaction, and when the thread has not opened a transaction, opens the transaction and initiates a call to a first method in a business logic method; when it is detected that the thread has opened a transaction, the transaction execution state is marked and a call to a second method in the business logic method is initiated.

[0060] Furthermore, in some embodiments, the transaction rollback interceptor is also used to insert additional processing logic before the business logic method is called; correspondingly, the transaction management component is also used to: before calling the business logic method, sequentially call the reflection mechanism method of the transaction rollback interceptor and the reflection mechanism method of the transaction management component to enhance the business logic method.

[0061] For example, Figure 4 The actual calling sequence diagram of calling the business logic method provided by the exemplary embodiment of the present application is as follows. Figure 4 As shown, before calling the business logic method, the outer logic first calls the transaction rollback interceptor, and then calls the transaction management component; in the call chain of the object or method modified by the @Transactional annotation, the transaction management component is called at the lowest priority by default, and the transaction rollback interceptor is called by the outer logic before the transaction management component by default. Specifically, in the transaction execution phase, the outer logic first calls the reflection mechanism (invoke) method of the transaction rollback interceptor, and the transaction rollback interceptor records whether the thread is in the transaction execution state, and initiates a call to the reflection mechanism method of the transaction management component; after the reflection mechanism method of the transaction management component is called, the transaction management component detects whether the thread has opened a transaction. When the thread has not opened a transaction, since the business logic method to be called needs to open a transaction, the transaction is opened, and a call to the first method in the business logic method is initiated. Correspondingly, after the business logic method is completed, the operation results are returned to the outer logic through the transaction management component and the transaction rollback interceptor in sequence.

[0062] Based on the above embodiments, in some embodiments, the exception handling system also includes a type judgment component and a transaction rollback monitoring entry point component, and the type judgment component and the transaction rollback interceptor are internal components of the transaction rollback monitoring entry point component; wherein the type judgment component is used to provide filtering rules, and the filtering rules are used to determine whether to call the transaction rollback interceptor before calling the business logic method; the transaction rollback monitoring entry point component is used to provide a transaction rollback interceptor to enhance the business logic method that meets the requirements according to the filtering rules provided by the type judgment component.

[0063] Among them, the type judgment component (TxRollbackMonitorPointcut) is a type judgment object defined according to the pointcut interface specification of Spring AOP. It introduces the parsing annotation transaction attribute component (AnnotationTransactionAttributeSource) in the Spring transaction management component to determine whether to introduce the transaction rollback interceptor for code enhancement during the dynamic enhancement of the target type instance. It should be noted that this type has the same type and method filtering logic as the transaction attribute source point cut (TransactionAttributeSourcePointcut) and relies on the same object of the parsing annotation transaction attribute component; the transaction rollback monitoring pointcut component (TxRollbackMonitorPointcutAdvisor) is an infrastructure object defined according to the pointcut advisor interface specification of Spring AOP. Its function is to provide transaction rollback interceptors for enhancement to objects that meet the requirements according to the filtering rules provided by the type judgment component.

[0064] The above embodiment introduces the functions of each component in the exception handling system. Next, how to construct the exception handling system is described through a specific implementation method.

[0065] In some embodiments, the exception handling system is constructed in the following manner: in response to the startup instruction of the application, the bootstrap class for the application startup is loaded; based on the default configuration rules of the application, the preset rollback monitor configuration file is parsed to obtain the definition of the singleton objects of the rollback monitor configuration component, the transaction rollback monitoring entry point component and the transaction rollback manager; according to the standard package scanning and configuration class loading rule results, the instances of the rollback monitor configuration component and the transaction rollback monitoring entry point component are loaded, wherein the type judgment component and the transaction rollback interceptor are instantiated during the instantiation process of the transaction rollback monitoring entry point component; the transaction rollback manager is instantiated during the instantiation process of the type judgment component; and, when loading the instance of the transaction rollback monitoring entry point component, the parsing annotation-style transaction attribute component and the transaction aspect support component are introduced, the parsing annotation-style transaction attribute component is used to parse the transaction annotation into transaction attributes, and the transaction aspect support component is used for transaction management.

[0066] For example, Figure 5 The system architecture diagram of the exception handling system provided by the exemplary embodiment of the present application. Figure 5As shown, the exception handling system includes a rollback monitor configuration component (TxRollbackMonitorConfig), a transaction rollback monitoring entry point component, a transaction rollback manager, a type judgment component, a transaction rollback interceptor, a parsing annotation-style transaction attribute component, and a transaction aspect support component (TransactionAspectSupport). Among them, the rollback monitor configuration component is the configuration entry of other components. Its function is to be automatically scanned and loaded when Springboot is started, and to register the transaction rollback monitoring entry point component with the application context (ApplicationContext) after loading. At the same time, it also introduces a transaction rollback manager to the system during the Springboot application startup phase; and when creating a transaction rollback monitoring entry point component, two additional external components (i.e., the parsing annotation-style transaction attribute component and the transaction aspect support component) are introduced. Both external components are provided by the Spring transaction management component and can be dynamically obtained from the application context.

[0067] For example, after the application is started, the bootstrap class (SpringbootApplication) for application startup is loaded. After the bootstrap class is loaded, according to the default configuration rules, the preset rollback monitor configuration file (such as the TxRollbackMonitorConfig type definition file) is scanned and parsed to obtain the definitions of three singleton objects of the rollback monitor configuration component, the transaction rollback monitoring entry point component and the transaction rollback manager; according to SpringBoot, during the instantiation of the object, the Advisor type object will be preloaded according to the type. Springboot loads the rollback monitor configuration component and the transaction rollback monitoring entry point component instances according to the standard package scanning and configuration class loading rule results; at the same time, its construction The factory type rollback monitor configuration component is a singleton object of the factory instance method, and is instantiated in advance as a factory object before the transaction rollback monitoring entry point component is instantiated; among them, the type judgment component and the transaction rollback interceptor are internal components of the transaction rollback monitoring entry point component, and are instantiated during the instantiation process of the transaction rollback monitoring entry point component; and the transaction rollback manager is instantiated as a dependent object during the instantiation process of the type judgment component; and when loading an instance of the transaction rollback monitoring entry point component, the parsing annotation-style transaction attribute component and the transaction aspect support component are introduced, the parsing annotation-style transaction attribute component is used to parse the transaction annotation into transaction attributes, and the transaction aspect support component is used for transaction management, wherein transaction management includes transaction start, transaction commit and transaction rollback operations.

[0068] Furthermore, after SpringBoot initializes and loads the transaction rollback monitoring entry point component, each object and method matched by the match method of the type judgment component will be enhanced using bytecode enhancement technology, so that before the corresponding business logic method is called, the reflection mechanism method of the transaction rollback interceptor and the reflection mechanism method of the transaction management component are called in sequence to enhance the business logic method.

[0069] Next, the application of the exception handling system is introduced through a specific embodiment. For example, Figure 6 A flowchart of an exception handling method provided by an exemplary embodiment of the present application. The exception handling method provided by the embodiment of the present application is applied to an exception handling system, and the exception handling method includes the following steps:

[0070] S601. Monitor the running process of the business logic method with management transaction annotation.

[0071] For example, the business logic method with the Transactional annotation is a multi-level nested transaction method. For example, the business logic method with the Transactional annotation includes a first method and a second method, and the business logic of the first method depends on the second method; correspondingly, the running process of the first method and the second method is monitored.

[0072] S602: Record the transaction status of the transaction management component during the operation of the business logic method.

[0073] That is, the transaction status of the transaction management component during the execution of the first method and the second method is recorded; wherein the transaction status includes the execution status, the rollback status and the exception throwing status.

[0074] S603: If an exception thrown by the transaction management component is captured during the execution of the business logic method, the exception-related information is recorded, and the exception-related information includes the location where the exception occurs.

[0075] Correspondingly, if an exception thrown by the transaction management component is captured during the execution of the first method and the second method, the exception-related information is recorded, wherein the exception-related information includes the exception state, method execution state, thread state, and the like.

[0076] S604. If the transaction status is an execution status, record the transaction status and exception-related information; and if the transaction status is a non-execution status and the exception is an unexpected rollback exception, generate an exception rollback report for running the business logic method based on the recorded transaction status and exception-related information.

[0077] For example, if the transaction state is in the execution state, the transaction state and exception-related information are recorded; if the transaction state is in the non-execution state, and the exception is an unexpected rollback exception, based on the recorded transaction state and exception-related information, the abnormal call chain of the thread is detected, for example, there is an exception thrown in the second method, and after it is thrown, the transaction state is marked as a rollback state; further, a report on the transaction exception rollback is generated, and the report on the exception rollback records the direct location of the unexpected rollback exception in the first method, and the root cause of the unexpected rollback exception is the exception thrown by the second method. Further, the transaction-related records in this thread are cleaned up, and the unexpected rollback exception is thrown to the outer logic.

[0078] Figure 7 Another flowchart of the exception handling method provided by the exemplary embodiment of the present application is shown in FIG. Figure 7 As shown, in Figure 1 On the basis of the framework shown, a rollback monitor (RollbackMonitor) is added, wherein the rollback monitor corresponds to the exception handling system in the above embodiment.

[0079] For example, a user operation request is initiated through the user request access layer, the rollback monitor records the current transaction status, the interception method in the interceptor aspect requests to start a transaction and initiates a call to the first method, the rollback monitor records the current transaction status, the interception method requests to continue the transaction and initiates a call to the second method. If an exception is thrown in the second method, the runtime exception is captured in the interceptor aspect and the transaction rollback status is marked, and then the runtime exception is thrown; the rollback monitor captures the exception, records the transaction status, exception status, method and thread, etc., and throws a runtime exception; correspondingly, the exception is thrown to the first method layer, the first method captures the runtime exception, performs custom processing (such as hijacking the runtime exception) and no longer throws it upward, and selects the correct method. Often return data and send the data to the interceptor aspect; correspondingly, after receiving the return data, the interceptor aspect detects that the current level is in the layer corresponding to the transaction opening, so it initiates a transaction commit operation and performs a transaction exception check during the transaction commit process. If it is in a rollback state (that is, it is found that the previous setting is an abnormal rollback state), the rollback operation is executed, an unexpected rollback exception is thrown, and the transaction state and exception-related information when the exception occurs are sent to the rollback monitor; the rollback monitor captures the unexpected rollback exception, records the exception, detects the transaction rollback record, generates and outputs the abnormal rollback report, and further throws the exception to the user request access layer; correspondingly, the user request access layer captures the exception and performs error handling for the captured exception.

[0080] In summary, this application has at least the following advantages:

[0081] 1. By intercepting and monitoring, an exception handling system is provided to accurately locate and track the unexpected rollback exceptions that are difficult to troubleshoot in the Spring transaction management component. The exception handling system includes an extension component of the Spring transaction management component. Since the exceptions thrown by the basic Spring transaction management component originate from the Spring framework and do not carry relevant information such as the cause and location of the exception, it is extremely difficult for developers or maintenance personnel who are not familiar with the spring architecture to trace the cause of the problem. By utilizing the extension component in the exception handling system provided by the present application, the root cause and location of the exception can be intuitively and clearly located.

[0082] 2. Through the collaborative work of the transaction management component and the transaction rollback manager, real-time monitoring and recording of transaction status and exceptions during the operation of business logic methods with management transaction annotations are achieved, and exceptions during the operation are captured. When the exception is an unexpected rollback exception, an exception rollback report is generated based on the recorded transaction status and exception-related information, so that developers or maintenance personnel do not need to spend a lot of time and energy to locate the cause of the exception. Based on the exception rollback report, the specific location and root cause of the transaction exception rollback can be quickly located, thereby significantly improving the efficiency of development and maintenance, and further enhancing the stability and reliability of the system.

[0083] In some embodiments, the exception handling system may be a hardware server or a server cluster.

[0084] In some embodiments, the exception handling system may be application software deployed on a server, a server cluster, or other computing devices with a certain computing power.

[0085] Correspondingly, Figure 8 The schematic diagram of the structure of the electronic device provided by the exemplary embodiment of the present application. Figure 8 As shown, the electronic device 80 of this embodiment includes:

[0086] At least one processor 81; and a memory 82 communicatively connected to the at least one processor;

[0087] The memory 82 stores instructions that can be executed by the at least one processor 81, and the instructions are executed by the at least one processor 81 to enable the electronic device to execute the method described in the above embodiment.

[0088] Optionally, the memory 82 may be independent or integrated with the processor 81 .

[0089] The memory 82 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk memory.

[0090] The processor 81 may be a central processing unit (CPU), or an application specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of the present application. Specifically, when deploying the exception handling system described in the aforementioned system embodiment, the electronic device may be, for example, an electronic device with processing functions such as a server.

[0091] Optionally, the electronic device may further include a communication interface 83. In a specific implementation, if the communication interface 83, the memory 82 and the processor 81 are implemented independently, the communication interface 83, the memory 82 and the processor 81 may be interconnected through a bus and communicate with each other. The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc., but it does not mean that there is only one bus or one type of bus.

[0092] Optionally, in a specific implementation, if the communication interface 83, the memory 82 and the processor 81 are integrated on a chip, the communication interface 83, the memory 82 and the processor 81 can communicate through an internal interface.

[0093] The implementation principle and technical effects of the electronic device provided in this embodiment can be found in the aforementioned embodiments and will not be described in detail here.

[0094] Correspondingly, an embodiment of the present application provides a computer-readable storage medium, which stores computer execution instructions. When the computer execution instructions are executed, they are used to implement the method steps in the above method embodiment. The specific implementation method and technical effect are similar and will not be repeated here.

[0095] The above-mentioned computer readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read only memory (EEPROM), erasable programmable read only memory (EPROM), programmable read only memory (PROM), read only memory (ROM), magnetic storage, flash memory, magnetic disk or optical disk. The readable storage medium can be any available medium that can be accessed by a general or special-purpose computer.

[0096] An exemplary readable storage medium is coupled to a processor so that the processor can read information from the readable storage medium and write information to the readable storage medium. Of course, the readable storage medium can also be an integral part of the processor. The processor and the readable storage medium can be located in a dedicated integrated circuit.

[0097] Correspondingly, an embodiment of the present application provides a computer program product, including a computer program. When the computer program is executed, the method steps in the above method embodiment are implemented. The specific implementation method and technical effects are similar and will not be repeated here.

[0098] Those skilled in the art will readily appreciate other embodiments of the present application after considering the specification and practicing the invention disclosed herein. The present application is intended to cover any modification, use or adaptation of the present application, which follows the general principles of the present application and includes common knowledge or customary techniques in the art that are not disclosed in the present application. The specification and examples are intended to be exemplary only, and the true scope and spirit of the present application are indicated by the following claims.

[0099] It should be understood that the present application is not limited to the precise structures that have been described above and shown in the drawings, and that various modifications and changes may be made without departing from the scope thereof. The scope of the present application is limited only by the appended claims.

Claims

1. An exception handling system, characterized in that: include: Transaction rollback interceptor and transaction rollback manager, where: The transaction rollback interceptor is used to check the current transaction status, record the transaction execution status and transaction rollback status, and report the transaction status and exception related information to the transaction rollback manager in response to the exception thrown by the transaction management component captured during the operation of the business logic method. The business logic method is annotated with management transactions; The transaction rollback manager is used to record exception-related information and transaction status when the transaction status is an execution status; and to generate an exception rollback report for running the business logic method based on the recorded transaction status and exception-related information when the transaction status is a non-execution status and the exception is an unexpected rollback exception.

2. The exception handling system according to claim 1, characterized in that: The transaction rollback interceptor is also used to: Record whether the thread is in a transaction execution state, and initiate a call to the transaction management component; Correspondingly, the transaction management component is used to: detect whether the thread has opened a transaction, and if the thread has not opened a transaction, open the transaction and initiate a call to the business logic method; if the thread has opened a transaction, mark the transaction execution status and initiate a call to the business logic method.

3. The exception handling system according to claim 1 or 2, characterized in that: The transaction rollback manager is further configured to output the abnormal rollback report in at least one of the following forms: Record the abnormal rollback report to a local log file; Writing the abnormal rollback report into a set storage medium; The abnormal rollback report is sent to a remote target receiving device.

4. The exception handling system according to claim 1 or 2, characterized in that: The exception handling system further comprises a type judgment component and a transaction rollback monitoring entry point component, wherein the type judgment component and the transaction rollback interceptor are internal components of the transaction rollback monitoring entry point component; Among them, the type judgment component is used to provide filtering rules, and the filtering rules are used to determine whether to call the transaction rollback interceptor before calling the business logic method; the transaction rollback monitoring entry point component is used to provide the transaction rollback interceptor for enhancement to the business logic method that meets the requirements according to the filtering rules provided by the type judgment component.

5. The exception handling system according to claim 4, characterized in that: The exception handling system is constructed in the following way: In response to a startup instruction of an application, loading a boot class started by the application; Based on the default configuration rules of the application, a preset rollback monitor configuration file is parsed to obtain definitions of a rollback monitor configuration component, the transaction rollback monitoring entry point component, and a singleton object of the transaction rollback manager; According to the standard package scanning and configuration class loading rule results, load the instances of the rollback monitor configuration component and the transaction rollback monitoring entry point component, wherein the type judgment component and the transaction rollback interceptor are instantiated during the instantiation process of the transaction rollback monitoring entry point component; The transaction rollback manager is instantiated during the instantiation process of the type judgment component; And, when loading the instance of the transaction rollback monitoring entry point component, a parsing annotation-style transaction attribute component and a transaction aspect support component are introduced, wherein the parsing annotation-style transaction attribute component is used to parse the transaction annotation into transaction attributes, and the transaction aspect support component is used for transaction management.

6. The exception handling system according to claim 1 or 2, characterized in that: The transaction management component is specifically used for: When an exception generated during the operation of the business logic method is captured, determining whether the method layer corresponding to the open transaction is currently in place; When the method layer corresponding to the open transaction is not in progress and the transaction is in the transaction execution state, the transaction is marked as being in the rollback state, and the generated exception is thrown to the upper layer method and the transaction rollback state is recorded; When in the layer corresponding to the open transaction, initiate the transaction commit operation, detect the transaction status during the transaction commit process, and if it is in the rollback state, execute the rollback operation, throw the generated exception to the upper layer method, and record the transaction rollback status.

7. An exception handling method, characterized in that: Applied to the exception handling system according to any one of claims 1 to 6, the exception handling method comprises: Monitor the running process of business logic methods with management transaction annotations; Recording the transaction status of the transaction management component during the operation of the business logic method; If an exception thrown by the transaction management component is captured during the operation of the business logic method, record the exception related information, which includes the location where the exception occurred; If the transaction status is an execution status, record the transaction status and the exception related information; and if the transaction status is a non-execution status and the exception is an unexpected rollback exception, generate an exception rollback report for running the business logic method based on the recorded transaction status and the exception related information.

8. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory is used to store computer-executable instructions; The processor is used to execute the computer-executable instruction to implement the exception handling method as claimed in claim 7.

9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the exception handling method according to claim 7 when executed.

10. A computer program product, comprising a computer program, characterized in that When the computer program is executed, the exception handling method according to claim 7 is implemented.

Citation Information

Cited By

  • Service orchestration method and device, computer equipment, readable storage medium and program product

    CN119440675A

  • Abnormal positioning method, device and equipment, readable storage medium and program product

    CN119961037A