Exception handling method and device for multi-level transaction, equipment, medium and program product

By creating an exception rollback list and exception rollback tracking object, recording and tracking rollback logs for multi-level transactions, the problem of difficult to troubleshoot the reasons for rollback of nested transactions is solved, and rapid identification and efficient troubleshooting are achieved.

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

Patent Information

Application Number
CN202410973533.1
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 the prior art, the reasons for rollback of nested transactions are difficult to be quickly investigated by exception handling systems or developers, resulting in difficulty in troubleshooting errors.

Method used

By creating an exception rollback manifest, record the rollback log of multi-level transactions, and trigger the rollback operation when the exception is caught during the underlying transaction processing, generate a rollback log and write it to the manifest, and use exception rollback tracking object to bind the manifest to the directory Determine, when a rollback flag is detected, an exception is thrown to the exception handling system to realize recording and tracking of the cause of the exception.

Benefits of technology

It realizes that exception handling system or developers can quickly identify the cause of exceptions and perform efficient troubleshooting, solving the problem of error troubleshooting caused by the loss of transactions in nested transactions.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118916121A_ABST
    Figure CN118916121A_ABST
Patent Text Reader

Abstract

The invention provides an exception handling method and device for multi-level transactions, equipment, a medium and a program product, and relates to the technical field of big data, the method comprises the following steps: creating an exception rollback list; executing each level of transaction processing process, if an exception is captured in any underlying transaction processing process, triggering an exception rollback operation for underlying transactions, generating a first rollback log, and writing the first rollback log into an exception rollback list; binding a pre-created abnormal rollback tracking object with the abnormal rollback list to obtain binding information about the abnormal rollback tracking object; and when all levels of transactions are processed, if it is detected that any level of transaction is provided with a rollback mark, and the rollback mark is generated when any level of transaction triggers an abnormal rollback operation, throwing an exception to the exception processing system based on the binding information. By means of the method, the problem that errors are difficult to check due to the fact that the nested transaction is lost and the transaction rollback is caused can be effectively solved.
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 a method, device, equipment, medium and program product for handling exceptions of multi-level transactions. Background Art

[0002] A transaction is considered as a single concurrency control unit and is a user-defined sequence of operations. The operations in these sequences are either completed in full or not completed in full. Its main purpose is to ensure data consistency and integrity.

[0003] Currently, we mainly rely on the Spring framework to implement transaction management. In order to be consistent with the design concept of Spring, the platform transaction manager (PlatformTransactionManager) can throw a transaction exception (TransactionException), which is a runtime exception (i.e., inherited from the runtime exception class of the Java language), which means that if a transaction exception is caught, the transaction will be rolled back. Developers (application code) sometimes catch these exceptions inside the transaction and handle them.

[0004] However, developers do not always write programs according to the convention. Therefore, when developers inappropriately capture and handle exceptions thrown by underlying transactions in business logic, the top-level transaction interceptor may not be aware of the exception, thereby executing the transaction commit logic and triggering an unexpected rollback exception (UnexpectedRollbackException) due to detection of the rollback flag of the underlying transaction during commit. The root cause of the transaction rollback is lost, making it difficult for the exception handling system or developers to quickly troubleshoot errors. Summary of the invention

[0005] The present application provides a multi-level transaction exception handling method, device, equipment, medium and program product, which are used to solve the problem of difficulty in error troubleshooting caused by nested transaction loss and transaction rollback reasons.

[0006] In a first aspect, the present application provides a method for handling exceptions in a multi-level transaction, wherein the multi-level transaction includes a top-level transaction and at least one bottom-level transaction, and the method includes:

[0007] Creating an exception rollback list, where the exception rollback list is used to record the rollback log corresponding to the multi-level transaction;

[0008] Execute the transaction processing process at each level. If an exception is caught during the processing of any underlying transaction, trigger an exception rollback operation for the underlying transaction and generate a first rollback log, and write the first rollback log into the exception rollback list; wherein, the exception rollback operation of any underlying transaction triggers the exception rollback operation of the top-level transaction;

[0009] Binding the pre-created exception rollback tracking object and the exception rollback list to obtain binding information about the exception rollback tracking object;

[0010] When the transaction processing at each level is completed, if it is detected that any level of transaction sets a rollback flag, which is generated when any level of transaction triggers an abnormal rollback operation, an exception is thrown to the exception handling system based on the binding information.

[0011] In one embodiment, the method further comprises:

[0012] If an exception is caught during the top-level transaction processing, a global exception rollback operation for the multi-level transaction processing process is triggered and a second rollback log is generated;

[0013] The second rollback log is written into the abnormal rollback list.

[0014] In one embodiment, the method further comprises:

[0015] Create a database connection management object and a thread private cache; wherein the database management object is used to manage the database connection information corresponding to the multi-level transaction and the rollback flag of each underlying transaction;

[0016] The database connection management object is cached in the thread private cache.

[0017] In one implementation, caching the database connection management object into the thread private cache includes:

[0018] Based on the transaction synchronization management tool, the database connection management object is cached in the thread private cache, so that the thread private cache stores the corresponding database connection information and the rollback flag of the transaction in the transaction processing process at each level.

[0019] In one embodiment, after creating the exception rollback list, the method further includes:

[0020] Based on a transaction synchronization management tool, the exception rollback list is cached in the thread private cache to implement binding between the exception rollback list and the database connection management object.

[0021] In one embodiment, it further includes:

[0022] For the multi-level transaction processing process, before starting to process any level of transaction, the transaction definition of the transaction is read based on the interception aspect and an interception point identifier for the transaction is generated to obtain the transaction definition and interception point identifier of each level of transaction;

[0023] According to the transaction definitions of transactions at various levels and the interception point identifiers, transaction information objects of transactions at various levels are created. The transaction information objects are used to record transaction information during transaction processing, and the transaction information is cached in a thread private cache.

[0024] In one embodiment, the method further comprises:

[0025] In response to each bottom-level transaction setting a transaction status completion flag, and the top-level transaction not setting a transaction completion flag, generating a third rollback log according to a rollback flag set by any bottom-level transaction;

[0026] The third rollback log is written into the abnormal rollback list.

[0027] In one embodiment, the method further comprises:

[0028] In response to setting transaction status completion flags of transactions at various levels, transaction information of transactions at various levels in the thread private cache is cleared in sequence.

[0029] In one embodiment, the method further comprises:

[0030] The cache information other than the transaction information in the thread private cache and related to the multi-level transaction is cleared, wherein the cache information includes the exception rollback list.

[0031] In one embodiment, the method is applied to a client, and before creating an exception rollback list, further includes:

[0032] In response to a service request initiated by a user at a client, the service request is a request for a multi-level service, and based on an interception aspect, a service method for the service request is encapsulated as the multi-level transaction.

[0033] In one embodiment, the method further comprises:

[0034] When an exception is thrown to the exception handling system based on the binding information, error information of business processing failure is fed back to the user.

[0035] In a second aspect, the present application provides a multi-level transaction exception handling device, the device comprising:

[0036] A list creation module, which is configured to create an exception rollback list, wherein the exception rollback list is used to record the rollback log corresponding to the multi-level transaction;

[0037] A log generation module, which is configured to execute the transaction processing process at each level, and if an exception is caught during any bottom-level transaction processing, trigger an exception rollback operation for the bottom-level transaction and generate a first rollback log, and write the first rollback log into the exception rollback list; wherein the exception rollback operation of any bottom-level transaction triggers the exception rollback operation of the top-level transaction;

[0038] A binding module, which is configured to bind a pre-created exception rollback tracking object and the exception rollback list to obtain binding information about the exception rollback tracking object;

[0039] The exception throwing module is configured to throw an exception to the exception handling system based on the binding information when the transaction processing at each level is completed and if it is detected that any level transaction sets a rollback flag, the rollback flag is generated when any level transaction triggers an abnormal rollback operation.

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

[0041] The memory stores computer-executable instructions;

[0042] The processor executes the computer-executable instructions stored in the memory to implement the multi-level transaction exception handling method provided in the first aspect above.

[0043] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores computer execution instructions, and when the computer execution instructions are executed by a processor, the computer execution instructions are used to implement the multi-level transaction exception handling method provided in the first aspect above.

[0044] In a fifth aspect, the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the multi-level transaction exception handling method provided in the first aspect above.

[0045] The exception handling method, apparatus, device, medium and program product for multi-level transactions provided by the present application create an exception rollback list to record the rollback logs when transactions at all levels are abnormally rolled back, generate a rollback log for the abnormal rollback operation during the underlying transaction processing and add it to the exception rollback list, bind the exception rollback tracking object to the exception rollback list, detect the rollback flag when the transaction processing is completed, throw an exception according to the binding information, realize the recording and tracking of the cause of the exception, solve the problem of difficult error troubleshooting caused by the loss of the cause of the transaction rollback when the nested transaction is completed, and enable the exception handling system or developers to quickly identify the cause of the exception and perform efficient troubleshooting. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0047] Figure 1 A flowchart of a method for handling exceptions in a multi-level transaction provided in an embodiment of the present application;

[0048] Figure 2 A flowchart of another method for handling exceptions in a multi-level transaction provided in an embodiment of the present application;

[0049] Figure 3 A flowchart of another method for handling exceptions in a multi-level transaction provided in an embodiment of the present application;

[0050] Figure 4 An application scenario diagram provided for an exemplary embodiment of the present application;

[0051] Figure 5 This is one of the spring transaction exception handling flow charts in the related technology;

[0052] Figure 6 This is the second flow chart of spring transaction exception handling in related technologies;

[0053] Figure 7 This is the third flow chart of spring transaction exception handling in related technologies;

[0054] Figure 8 A flowchart of a method for handling exceptions in a multi-level transaction provided by an exemplary embodiment of the present application;

[0055] Fig. 9 A schematic diagram of the structure of a multi-level transaction exception handling device provided in an embodiment of the present application;

[0056] Fig.10 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.

[0057] 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

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

[0059] In the technical solution of this application, the collection, storage, use, processing, transmission, provision and disclosure of financial data or user data and other information involved are in compliance with the provisions of relevant laws and regulations and do not violate public order and good morals. It should be noted that in the embodiments of this application, some existing solutions in the industry such as certain software, components, models, etc. may be mentioned, and they should be considered as exemplary. 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.

[0060] Transactions are a concurrency control unit, a user-defined sequence of operations, which are either all completed or not completed, and are an indivisible unit of work. Transactions have four ACID characteristics, namely: Atomicity: All operations in a transaction are either all completed or not completed, and will not end at a certain link in the middle; Consistency: The integrity of the database is not destroyed before and after the transaction starts; Transaction isolation: Multiple transactions are independent and do not affect each other; Durability: After the transaction processing is completed, the modification of the data is permanent and will not be lost even if the system fails. Spring transactions are the implementation of transactions in the Spring framework, which supports declarative transactions (annotation mode) and programmatic transactions (code mode). In declarative transactions, Spring uses AOP aspect technology to start transactions in the appropriate place, and then commit or roll back transactions in the appropriate place, thereby realizing transaction operations at the business programming level.

[0061] In keeping with Spring's philosophy, the TransactionException that can be thrown by any of the PlatformTransactionManager interface's methods is a runtime exception (that is, it extends the java.lang.RuntimeException class). Transaction infrastructure failures are almost always fatal. In rare cases where application code can actually recover from a transaction failure, application developers can still choose to catch and handle TransactionException.

[0062] At present, the Spring transaction management framework adopts a transaction control method based on annotations and interceptors, and transfers transaction status and transaction objects between multi-level businesses through a thread-private (ThreadLocal)-based transmission mechanism. In the inner transaction interceptor, if an exception that triggers a transaction rollback is captured, the transaction is marked as rollback and then the exception object is thrown. Under normal circumstances, according to programming conventions, the outer transaction interceptor should also capture the exception that triggers a transaction rollback and actively roll back the transaction. It can be understood that the inner transaction is the bottom-level transaction, and the outer transaction is the top-level transaction.

[0063] However, developers do not always write programs according to the convention. Therefore, when an exception thrown in the inner layer is caught in the business logic, the external transaction interceptor may not be aware of the exception, and thus execute the transaction commit logic. When committing, the UnexpectedRollbackException is triggered due to the detection of the transaction rollback flag in the inner layer, and the root cause of the transaction rollback is lost.

[0064] In view of this, the embodiments of the present application provide a method, apparatus, device, medium and program product for handling exceptions of multi-level transactions. By creating an exception rollback list, and when an exception is captured during the processing of any underlying transaction, an exception rollback operation for the underlying transaction is triggered and a first rollback log is generated and written into the exception rollback list. At the same time, the pre-created exception rollback tracking object and the exception rollback list are bound to obtain binding information about the exception rollback tracking object. When the processing of transactions at all levels is completed, if it is detected that a rollback flag is set for any level of transaction, the rollback flag is generated when any level of transaction triggers an exception rollback operation, and an exception is thrown to the exception handling system based on the binding information. In this process, even if the developer or application code captures the inner transaction exception, resulting in the normal submission of the inner transaction and triggering an unexpected exception rollback when the outer transaction is submitted, the exception handling system can quickly troubleshoot the cause of the exception based on the thrown exception.

[0065] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.

[0066] Figure 1 One of the flow diagrams of a multi-level transaction exception handling method provided in an embodiment of the present application is shown. In this method, the multi-level transaction includes a top-level transaction and at least one bottom-level transaction, such as Figure 1 As shown, the method may include the following steps S101-S104:

[0067] S101. Create an exception rollback list, where the exception rollback list is used to record the rollback log corresponding to the multi-level transaction.

[0068] It can be understood that the top-level transaction, also known as the outer-level transaction, refers to the transaction defined on the outermost method of the call chain, which is usually a higher-level business logic method that calls other methods to complete a complete business operation; the bottom-level transaction, also known as the inner-level transaction, refers to the transaction defined on the methods called by the top-level transaction method in the call chain, which is usually a lower-level operation. For example, in a banking system, users can perform transfer operations. The transfer operation involves two accounts: one is the transfer-out account and the other is the transfer-in account. This operation needs to ensure that the funds are transferred correctly between the two accounts and can be rolled back to the initial state in any error situation. The top-level transaction refers to the transaction of the entire transfer operation. It includes two steps: deducting money from the transfer-out account and depositing money into the transfer-in account. For example, user A transfers 100 yuan to user B, which refers to a sub-transaction inside the top-level transaction. Each sub-transaction can be committed or rolled back independently.

[0069] For example, the platform transaction manager (PlatformTransactionManager) can be used to create an exception rollback list, that is, a rollback log list (RollbackLog), which can be used to record the rollback reasons of multiple interception aspects. Among them, RollbackLog records a list, and each record in the list can contain interception aspect identification, interception point identification (joinpointIdentification), transaction definition, captured exception, rollback status, whether global exception rollback and other element information.

[0070] In one possible application scenario, the method is applied to the client, such as Figure 2 As shown, except Figure 1 In addition to steps S101-S104, before creating the abnormal rollback list in step S101, the following steps may also be included:

[0071] Step S201: In response to a service request initiated by a user at a client, where the service request is a request for a multi-level service, a service method for the service request is encapsulated as a multi-level transaction based on an interception aspect.

[0072] For example, the interception aspect is AOP, specifically, the transaction aspect support (TransactionAspectSupport) in AOP. When a user initiates a request in the user controller (UserController) (for example, a user details query request), TransactionAspectSupport encapsulates the various parameters in the method for processing the business request, and packages the business method into a multi-level transaction for processing, thereby ensuring the integrity and consistency of the overall task. More specifically, custom logic can be added before and after the execution of the business method, so that the transaction is started before the method is executed, the transaction is committed after the method is executed, or the transaction is rolled back when the method is executed abnormally.

[0073] It can be understood that the interception aspect technology is like setting an interception point on the request path, and all requests will pass through this interception point. At this interception point, the user's request can be decomposed into multiple small business operations, and then these operations are packaged into a "multi-level transaction". This "multi-level transaction" is like a task with multiple steps, and each step needs to be executed in sequence to ensure the integrity and consistency of the entire task.

[0074] S102, executing transaction processing processes at all levels. If an exception is captured during any underlying transaction processing, an abnormal rollback operation for the underlying transaction is triggered and a first rollback log is generated, and the first rollback log is written into the abnormal rollback list; wherein, an abnormal rollback operation of any underlying transaction triggers an abnormal rollback operation of the top-level transaction.

[0075] It is understandable that a multi-level business, that is, one business, includes multiple business processes. For example, in a transfer business, the balance of account A needs to be transferred to the balance of account B, including multiple sub-businesses such as deducting the balance of account A and increasing the balance of account B. Each sub-business can correspond to a transaction.

[0076] Compared with the prior art, this embodiment adds the generation of rollback logs in the transaction processing at all levels, wherein the generation of rollback logs can be divided into two situations: in the transaction manager, abnormal rollback is divided into two scenarios: abnormal rollback of the first aspect (new transaction, i.e., top-level transaction) and abnormal rollback of the second aspect (non-new transaction, i.e., bottom-level transaction). In the first aspect rollback process, the transaction manager can read the database connection management (ConnectionHolder) object, obtain the underlying Connection object, and call its method to perform the actual rollback operation; in the second aspect rollback process, the transaction manager reads the ConnectionHolder object and sets its rollbackOnly attribute to true (rollbackOnly is a Boolean attribute used to indicate whether the current transaction can only be rolled back. When rollbackOnly is set to true, it means that the transaction cannot be committed and can only be rolled back).

[0077] Similarly, in the transaction manager, there are two conditions for triggering rollback. The first is that the exception triggered by the business process is captured, and the exception meets the rollback condition in the transaction definition, triggering an exception rollback. The second is that when the rollback aspect performs a commit action, it detects that the ConnectionHolder has set the rollbackOnly property to true, triggering an exception rollback. This type of rollback triggering condition is generally inconsistent between the inner and outer aspect transaction rollback definitions, the inner layer triggering rollback condition cannot trigger the outer layer rollback condition, or the exception that triggers the inner layer aspect rollback is improperly captured by the business code, resulting in the loss of the trigger factor.

[0078] Therefore, this embodiment performs rollback recording by generating a rollback log at the above-mentioned rollback node, including the first rollback log for the underlying transaction: transaction rollback-second interception aspect exception capture rollback, second aspect rollback, and the generated rollback log record content can be as follows: interception point identifier (joinpointIdentification), transaction definition, captured exception, rollback status setRollbackonly, global exception rollback is no, etc.

[0079] In some embodiments, in addition to recording the reason for the rollback of the bottom-level transaction, the abnormal rollback list may also record the rollback log of the top-level transaction. Specifically, the method may further include the following steps:

[0080] If an exception is caught during the top-level transaction processing, a global exception rollback operation for the multi-level transaction processing process is triggered and a second rollback log is generated;

[0081] The second rollback log is written into the abnormal rollback list.

[0082] Exemplarily, for the second rollback log of the top-level transaction: Transaction Rollback - The first interception aspect exception captures the node that generates the rollback log, and creates a log record with the following content: interception point identifier (joinpointIdentification), transaction definition, triggering exception is null, rollback status, rollback, global exception rollback is yes, etc.

[0083] It can be understood that the first interception aspect and the second interception aspect mentioned above are used to distinguish the interception aspect through which each transaction is executed.

[0084] In some embodiments, since the rollback of any bottom-level transaction will trigger the rollback of the top-level transaction, when an exception is thrown, in order to track the transaction node that generates the exception, the method provided in this embodiment may further include the following steps:

[0085] In response to each bottom-level transaction setting a transaction status completion flag, and the top-level transaction not setting a transaction completion flag, generating a third rollback log according to a rollback flag set by any bottom-level transaction;

[0086] The third rollback log is written into the abnormal rollback list.

[0087] In this embodiment, it is considered that in a normal multi-level transaction processing process, when the bottom transaction triggers an abnormal rollback operation, the transaction will not be committed but an exception will be thrown. When the developer improperly captures the exception of the bottom transaction and handles it, the transaction will be committed normally and enter the processing of the top transaction, resulting in an unexpected rollback exception.

[0088] It should be noted that the third rollback log is different from the second rollback log in that the abnormal rollback of the top-level transaction is triggered by the abnormal rollback of the bottom-level transaction, while the second rollback log is when the bottom-level transaction succeeds (no abnormal rollback) and the top-level transaction is abnormally rolled back due to other reasons (such as business verification failure).

[0089] S103: Bind the pre-created exception rollback tracking object and the exception rollback list to obtain binding information about the exception rollback tracking object.

[0090] In this embodiment, the platform transaction manager can be used to create an exception rollback tracking object, which defines a traced unexpected exception rollback (TracedUnexpectedRollbackException) exception type, which can inherit from the UnexpectedRollbackException exception. Unlike the UnexpectedRollbackException exception, this embodiment binds the exception rollback tracking object to the exception rollback list, so that the transaction rollback record list attribute is added to the binding information, which can be used to record the rollback reasons of multiple interception aspects (transactions).

[0091] S104. When the transaction processing at each level is completed, if it is detected that a rollback flag is set for any level of transaction, and the rollback flag is generated when any level of transaction triggers an abnormal rollback operation, an exception is thrown to the exception handling system based on the binding information.

[0092] Exemplarily, in the node where the transaction manager throws UnexpectedRollbackException in the first interception aspect of transaction unexpected rollback, it is changed to create a newly defined TracedUnexpectedRollbackException exception, and the rollback log list is assigned to the exception as an attribute to replace the original exception thrown.

[0093] Continue to combine Figure 2 As shown, the method provided in this embodiment may also include the following steps:

[0094] Step S202: When an exception is thrown to the exception handling system based on the binding information, error information of business processing failure is fed back to the user.

[0095] It can be understood that throwing an exception is to throw an exception to the exception handling system or developer, so that the exception handling system or developer can generate the reason for the exception rollback according to the thrown exception (the binding information carried). The error message of business processing failure is the information fed back to the user, which can be fed back to the user in the form of a pop-up window through UserController.

[0096] Through the above technical solution, an exception rollback list is created to record the rollback logs when transactions at all levels are rolled back abnormally. In the underlying transaction processing process, a rollback log is generated for the exception rollback operation and added to the exception rollback list. The exception rollback tracking object is used to bind to the exception rollback list. When the transaction processing is completed, the rollback flag is detected and an exception is thrown according to the binding information, thereby realizing the recording and tracking of the cause of the exception, so that the exception handling system or developers can quickly identify the cause of the exception and perform troubleshooting.

[0097] Figure 3 This is a flowchart of another method for handling exceptions in a multi-level transaction provided by an embodiment of the present application. Based on the above embodiment, this embodiment creates a database connection management object, a thread private cache, and binds related data to achieve synchronization of transaction information in a multi-level transaction processing process and isolation from other transactions. Specifically, in addition to the above steps S101-S104, the method provided by this embodiment may also include the following steps:

[0098] Step S301, creating a database connection management object and a thread private cache; wherein the database management object is used to manage the database connection information corresponding to the multi-level transaction and the rollback flag of each underlying transaction.

[0099] In this embodiment, a database connection management object and a thread-private cache are created, mainly for managing transaction synchronization and isolation. For example, a transaction synchronization manager (TransactionSynchronizationManager) can be used to manage transaction synchronization information, which is thread-private. When each thread executes a transaction, it will have its own transaction synchronization information, including the current transaction status and connection information.

[0100] It can be understood that TransactionSynchronizationManager is the key tool for the transaction manager to perform transaction state synchronization across interception aspects, and in the transaction processing of multiple interception aspects, ConnectionHolder is the only cross-aspect object.

[0101] Step S302: Cache the database connection management object into the thread private cache.

[0102] In this embodiment, TransactionSynchronizationManager is used to cache the database connection management object in the thread private cache, so that the relevant database connection information and rollback flag are synchronously stored in the thread private cache to achieve data sharing between transactions and isolation from external transactions.

[0103] Exemplarily, the rollback marker set by any level of transaction can be detected from the rollback marker information in the ConnectionHolder in the thread private cache.

[0104] Optionally, step S302 of caching the database connection management object into the thread private cache may include the following steps:

[0105] Based on the transaction synchronization management tool, the database connection management object is cached in the thread private cache, so that the thread private cache stores the corresponding database connection information and the rollback flag of the transaction in the transaction processing process at each level.

[0106] The TransactionSynchronizationManager is a key component in the Spring framework. It manages transaction synchronization status and resources, manages resource binding and unbinding during the life cycle of a transaction, and ensures that the corresponding callback operations are executed when the transaction is completed. The TransactionSynchronizationManager can use the Java mechanism (ThreadLocal) to implement thread-private caching. Others allow each thread to have its own independent copy of variables, thus avoiding concurrency issues in a multi-threaded environment.

[0107] Furthermore, after creating the abnormal rollback list, the following steps may also be included:

[0108] Based on a transaction synchronization management tool, the exception rollback list is cached in the thread private cache to implement binding between the exception rollback list and the database connection management object.

[0109] For example, in the entire transaction management process provided by this embodiment, the transaction management can bind and synchronize thread-private resources through the resource binding (bindResource) method of the TransactionSynchronizationManager tool. The above-mentioned RollbackLog list is created, and the above-mentioned bindResource method can be used to bind the above-mentioned ConnectionHolder to the empty RollbackLog at the thread level.

[0110] The above-mentioned bound node operation can be performed in the transaction start phase - the first interception aspect phase (i.e., the interception aspect phase for processing top-level transactions), and TransactionSynchronizationManager binds the current thread, ConnectionHolder, and RollbackLog list through the bindResource method.

[0111] In some embodiments, to ensure that resources do not have cross-business impacts, in the unexpected transaction rollback-first interception aspect stage, the binding relationship between the current thread, ConnectionHolder, and RollbackLog lists is removed through the resource unbinding (unbindResource) method to ensure the reasonable recycling and destruction of resources.

[0112] In this embodiment, by caching the exception rollback list in the thread private cache, the exception rollback list and the database connection management object are bound, which can achieve efficient management of exception rollback and reliable binding of database connection, thereby improving the reliability, isolation and performance of the system.

[0113] In some embodiments, the following steps may also be included:

[0114] For the multi-level transaction processing process, before starting to process any level of transaction, the transaction definition of the transaction is read based on the interception aspect and an interception point identifier for the transaction is generated to obtain the transaction definition and interception point identifier of each level of transaction;

[0115] According to the transaction definitions of transactions at various levels and the interception point identifiers, transaction information objects of transactions at various levels are created. The transaction information objects are used to record transaction information during transaction processing, and the transaction information is cached in a thread private cache.

[0116] In this embodiment, before starting to process any level of transaction, Spring's transaction manager can read the transaction definition in the method annotation or configuration file of the transaction through the interception aspect and generate a unique interception point identifier. The transaction definition (TransactionDefinition) can contain the configuration properties of the transaction, such as propagation behavior (Propagation), isolation level (Isolation), timeout (Timeout), etc. The interception point identifier is used to uniquely identify the call of a transaction method. This identifier can be generated based on the signature, class name and other context information of the method. And according to the read transaction definition and the generated interception point identifier, a transaction information object (TransactionInfo) can be created through spring. This object can contain the following information: transaction definition, transaction status (TransactionStatus): contains the current status of the transaction, such as whether it has started, whether it has been committed or rolled back, etc.; interception point identifier: uniquely identifies the transaction method call and other contents, and records the transaction information when the transaction is started and synchronized to the thread private cache.

[0117] Through the above technical solution, more fine-grained transaction control can be achieved and synchronized in the thread private cache, so as to achieve efficient multi-level transaction management in the transaction management process and ensure the consistency and integrity of the transaction.

[0118] In some embodiments, the following steps may also be included:

[0119] In response to transactions at various levels setting transaction status completion flags, transaction information of transactions at various levels in the thread private cache is cleared in sequence.

[0120] Exemplarily, when a multi-level transaction includes two bottom-level transactions and one top-level transaction, the transaction processing order is bottom-level transaction 1 → bottom-level transaction 2 → top-level transaction. Each time a transaction is completed (including commit and rollback), the transaction information of the transaction at that level in the thread private cache is cleared.

[0121] Furthermore, cache information other than the transaction information about the multi-level transaction in the thread-private cache may also be cleared, and the cache information includes the exception rollback list.

[0122] Exemplarily, when the top-level transaction processing is completed, the information such as the exception rollback list in the thread private cache can be cleared to release thread resources.

[0123] Through the above solution, each transaction will clean up its related thread local variables after completion, which can effectively ensure the isolation and independence of transactions.

[0124] To facilitate the understanding of the embodiments of the present application, the embodiments of the present application are further described below in combination with application scenarios. Figure 4 As shown, the client includes a user controller (UserController), a transaction interceptor (TransactionInterceptor / TransactionAspectSupport), a platform transaction manager (PlatformTransactionManager), a transaction synchronization manager (TransactionSynchronizationManager), a user facade (UserFacade) and a user service (UserService).

[0125] In this application scenario, relying on the implementation of Spring transaction management components, its basic principles are combined with Figure 5 As shown in the figure, developers can use the @Transactional annotation to decorate each transaction initiation method in each business logic. In a multi-level business logic, a business call may pass through multiple methods decorated with the above annotations.

[0126] Spring transaction management component intercepts the above methods through AOP technology, and checks the transaction startup status before entering each method, and starts the transaction according to the needs and preset configuration. Specifically, the transaction interceptor (TransactionInterceptor) plays the role of method request interception. It adopts the around mode (around), and executes the internal logic of TransactionInterceptor before any method containing @Transactional annotation is called, before and after the business method is executed. The internal logic is implemented by its parent class, the invokeWithinTransaction method of TransactionAspectSupport. Its core logic structure is shown in the attachment Figure 6 : There are two core process control objects in the transaction management technology component: TransactionAspectSupport and its specific implementation TransactionInterceptor and AbstractPlatformTransactionManager and its specific implementation. TransactionAspectSupport is used for overall transaction process control during the AOP interception process. It is actually a global framework in the entire transaction control. AbstractPlatformTransactionManager is responsible for specific operations on transaction-related objects. The independent key business processes of TransactionAspectSupport are shown in the attachment. Figure 7 As shown, it can include the following functions:

[0127] Function 1: Define the transaction information object (TransactionInfo) to record the status of this transaction. The TransactionInfo object contains the following resources: transaction manager (TransactionManager), transaction status (TransactionStatus), transaction definition (TransactionAttribute), and transaction section point (joinpointIdentification). At the same time, TransactionInfo also connects multiple instances across sections through the old transaction information attributes and the transactionInfoHolder thread-private attributes of TransactionAspectSupport. It is used to identify whether the current transaction information is the outermost transaction information (the latest transaction information). The above transaction manager (TransactionManager) is the process operation object of this transaction execution process, which is used to complete various logics of the transaction operation process. The above TransactionStatus is the transaction status object of this transaction execution, which is used to record the current status of this transaction execution. It contains the key attribute data source transaction object (DataSourceTransactionObject), which contains the database connection management (ConnectionHolder) object and other configuration states. ConnectionHolder contains the underlying specific database connection Connection object, which is used to complete direct operations on the database. It contains the key tag attribute rollbackOnly, which is used to mark the transaction rollback status in non-top-level transaction sections. Spring's transaction manager is implemented through the TransactionSynchronizationManager static object, and the cross-aspect synchronization operation of the ConnectionHolder object.

[0128] Function 2: Initiate a call to a business operation and receive a return value or catch an exception.

[0129] Function 3: After catching an exception, call TransactionManager to make a decision based on the transaction definition. If the rollback decision is met, the rollback is performed and an exception is finally thrown.

[0130] Function 4: After the business call is completed, clean up transaction information TransactionInfo and other related resources.

[0131] Function 5: After the business call returns normally, call TransactionManager to perform the transaction commit operation.

[0132] It is understandable that the operation of TransactionAspectSupport is the basic framework of the entire component. In addition, AbstractPlatformTransactionManager and its inherited class DataSourceTransactionManager in transaction management are the specific executors of transaction management operations. The execution process can be referred to Figure 6 The complete process includes the submission process, rollback process, and unexpected rollback process.

[0133] In the unexpected rollback process, the entire cross-aspect state only maintains the rollbackOnly attribute, which results in insufficient information for developers to understand the specific cause of the problem when reporting the transaction rollback exception, thus causing confusion in program modification. Therefore, the embodiment of the present application makes the following improvements to achieve the goal of providing more accurate transaction rollback reasons to the outside world.

[0134] It should be noted that the above Figure 5-Figure 7 The description of the related art is used to facilitate the understanding of the embodiments of the present application and should not be regarded as prior art.

[0135] Combine the following Figure 8 As shown, taking user details query (i.e. business request) as an example, it can be understood that Figure 8 The first and second are used to distinguish transactions at all levels, where the first corresponds to the top-level transaction information (such as the first transaction definition refers to the top-level transaction definition), and the second corresponds to the bottom-level transaction information (taking the number of bottom-level transactions as one as an example, in some embodiments, more bottom-level transactions may be included, and the processing logic is similar). Compared with the current transaction management, at least the following improvements are included:

[0136] 1) Define the exception type of the TracedUnexpectedRollbackException object, which is inherited from the UnexpectedRollbackException exception. Add a transaction rollback record list attribute, rollbackLog, to record the rollback reasons of multiple interception aspects. RollbackLog records a list, each record of which contains the interception aspect identifier, joinpointIdentification, transaction definition, captured exception, rollback status, whether the global exception rollback occurs, and other elements.

[0137] 2) In Spring transaction management, TransactionSynchronizationManager is the key tool for the transaction manager to perform transaction state synchronization across interception aspects. In transaction processing of multiple interception aspects, ConnectionHolder is the only cross-aspect object. In the entire transaction management process, the transaction manager binds and synchronizes thread-private resources through the bindResource method of the TransactionSynchronizationManager tool.

[0138] By creating a RollbackLog list, use the bindResource method above to bind the ConnectionHolder to the empty RollbackLog at the thread level. Figure 6 In the transaction phase - the first interception aspect phase, TransactionSynchronizationManager binds the current thread, ConnectionHolder, and RollbackLog list through the bindResource method.

[0139] In addition, to ensure that resources do not have cross-business impacts, the binding relationship between the current thread, ConnectionHolder, and RollbackLog list is removed through the unbindResource method during the unexpected transaction rollback - first interception aspect stage to ensure the reasonable recycling and destruction of resources.

[0140] 3) Added rollback logs, including at least the following two situations: In the spring transaction manager, exception rollback is divided into two scenarios: first aspect (new transaction) exception rollback and second aspect (non-new transaction) exception rollback. In the first aspect rollback process, the transaction manager reads the ConnectionHolder object, obtains the underlying Connection object, and calls its method to perform the actual rollback operation. In the second aspect rollback process, the transaction manager reads the ConnectionHolder object and sets its rollbackOnly property to true.

[0141] Similarly, in transaction management, there are two conditions for triggering rollback. The first is that the exception triggered by the business process is captured, and the exception meets the rollback condition in the transaction definition, triggering rollback. The second is that when the rollback aspect performs a commit action, it detects that the ConnectionHolder has set the rollbackOnly property to true, triggering an exception rollback. This type of rollback triggering condition is generally inconsistent with the inner and outer aspect transaction rollback definitions, the inner layer triggering rollback condition cannot trigger the outer layer rollback condition, or the exception that triggers the inner layer rollback is improperly captured by the business code, resulting in the loss of the trigger factor.

[0142] Therefore, the embodiments of the present application respectively execute records at corresponding rollback nodes, and the specific process nodes executed are as follows: Figure 8 As shown, the records of the rollback log refer to S801-S809.

[0143] Among them, the first rollback log: transaction rollback-second interception aspect, steps S803-S805 correspond to the node for generating the rollback log, in which the exception is captured and rolled back in the interception aspect, the second aspect is rolled back, and the rollback log record is created as follows: joinpointIdentification, transaction definition, captured exception, rollback status, setRollbackonly, global exception rollback is no, etc.

[0144] The second rollback log: unexpected transaction rollback - the node that generates the rollback log in steps S806-S809 in the first interception aspect, and its creation log record content is as follows: joinpointIdentification, transaction definition, trigger exception is null, rollback status, rollback, global exception rollback is yes, etc.

[0145] 4) In the transaction unexpected rollback - the node where the transaction manager throws an unexpected exception rollback in the first interception aspect, change it to create a newly defined (unexpected) exception rollback tracking object exception, and assign the rollback log list as an attribute to the exception (through signal binding), replacing the original exception thrown.

[0146] In summary, the embodiment of the present application improves the Spring transaction manager of the client, adds a rollback reason tracking mechanism, and provides an effective problem tracking mechanism for unexpected abnormal rollbacks caused by unreasonable code writing or transaction definition. This provides a more convenient basis for locating errors for developers and system maintenance personnel who do not understand the Spring framework code, greatly improving the troubleshooting efficiency of this type of error.

[0147] Fig. 9 A schematic diagram of the structure of a multi-level transaction exception handling device provided in an embodiment of the present application is shown. Fig. 9 As shown, the device 900 includes a list creation module 901, a log generation module 902, a binding module 903 and an exception throwing module 904, wherein:

[0148] A list creation module 901, which is configured to create an exception rollback list, wherein the exception rollback list is used to record the rollback log corresponding to the multi-level transaction;

[0149] The log generation module 902 is configured to execute the transaction processing process at each level. If an exception is caught during the processing of any underlying transaction, an abnormal rollback operation for the underlying transaction is triggered and a first rollback log is generated, and the first rollback log is written into the abnormal rollback list; wherein the abnormal rollback operation of any underlying transaction triggers the abnormal rollback operation of the top-level transaction;

[0150] A binding module 903, which is configured to bind the pre-created exception rollback tracking object and the exception rollback list to obtain binding information about the exception rollback tracking object;

[0151] The exception throwing module 904 is configured to throw an exception to the exception handling system based on the binding information when the transaction processing at each level is completed and if it is detected that any level transaction sets a rollback flag, the rollback flag is generated when any level transaction triggers an abnormal rollback operation.

[0152] In one embodiment, the log generation module 902 is also configured to trigger a global exception rollback operation for the multi-level transaction processing process and generate a second rollback log if an exception is captured during the top-level transaction processing; and write the second rollback log into the exception rollback list.

[0153] In one embodiment, the device further comprises:

[0154] An object creation module, which is configured to create a database connection management object and a thread private cache; wherein the database management object is used to manage the database connection information corresponding to the multi-level transaction and the rollback flag of each underlying transaction;

[0155] A cache module is configured to cache the database connection management object into the thread private cache.

[0156] In one embodiment, the cache module is specifically configured to cache the database connection management object in the thread private cache based on a transaction synchronization management tool, so that the thread private cache stores the corresponding database connection information and transaction rollback flags during transaction processing at each level.

[0157] In one embodiment, the device further comprises:

[0158] The resource binding module is configured to cache the exception rollback list in the thread private cache based on a transaction synchronization management tool, so as to implement binding between the exception rollback list and the database connection management object.

[0159] In one embodiment, the device further comprises:

[0160] An interception module is configured to read the transaction definition of the transaction based on the interception aspect and generate an interception point identifier for the transaction before starting to process any level of transaction in the multi-level transaction processing process, thereby obtaining the transaction definition and interception point identifier for each level of transaction;

[0161] The object creation module also includes: creating transaction information objects for transactions at all levels according to transaction definitions at all levels and the interception point identifiers, wherein the transaction information objects are used to record transaction information during transaction processing, and cache the transaction information in a thread private cache.

[0162] In one embodiment,

[0163] The log generation module 902 is also configured to generate a third rollback log in response to each underlying transaction setting a transaction status completion flag and the top-level transaction not setting a transaction completion flag according to the rollback flag set by any of the underlying transactions, and write the third rollback log into the abnormal rollback list.

[0164] In one embodiment, the device further comprises:

[0165] The cleaning module is configured to set a transaction status completion flag in response to each level of transactions, and sequentially clean up the transaction information of each level of transactions in the thread private cache.

[0166] In one embodiment,

[0167] The cleaning module is further configured to clean up other cache information about the multi-level transaction in the thread private cache except the transaction information, and the cache information includes the abnormal rollback list.

[0168] In one embodiment, the device is applied to a client, and before creating an exception rollback list, further includes:

[0169] The business response module is configured to respond to a business request initiated by a user at a client, wherein the business request is a request for a multi-level business, and based on an interception aspect, the business method for the business request is encapsulated as the multi-level transaction.

[0170] In one embodiment, the device further comprises:

[0171] The error feedback module is configured to feed back error information of business processing failure to the user when an exception is thrown to the exception handling system based on the binding information.

[0172] The above-mentioned device provided in the embodiment of the present application can be used to execute the technical solution of the exception handling method of multi-level transactions in the above-mentioned embodiment. Its implementation principle and technical effect are similar and will not be repeated here.

[0173] It should be noted that it should be understood that the division of the various modules of the above device is only a division of logical functions. In actual implementation, all or part of them can be integrated into one physical entity, or they can be physically separated. And these modules can all be implemented in the form of software called by processing elements; they can also be all implemented in the form of hardware; some modules can also be implemented in the form of software called by processing elements, and some modules can be implemented in the form of hardware. For example, the log generation module 902 can be a separately established processing element, or it can be integrated in a chip of the above device. In addition, it can also be stored in the memory of the above device in the form of program code, and called and executed by a processing element of the above device. The function of the above log generation module 902. The implementation of other modules is similar. In addition, all or part of these modules can be integrated together, or they can be implemented independently. The processing element here can be an integrated circuit with signal processing capabilities. In the implementation process, each step of the above method or each module above can be completed by an integrated logic circuit of hardware in the processor element or instructions in the form of software.

[0174] Fig.10 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Fig.10 As shown, the electronic device may include: a transceiver 101 , a processor 102 , and a memory 103 .

[0175] The processor 102 executes the computer execution instructions stored in the memory, so that the processor 102 executes the scheme of the exception handling method of the multi-level transaction in the above embodiment. The processor 102 can be a general-purpose processor, including a central processing unit CPU, a network processor (NP), etc.; it can also be a digital signal processor DSP, an application-specific integrated circuit ASIC, a field programmable gate array FPGA or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components.

[0176] The memory 103 is connected to the processor 102 via a system bus and implements communication therebetween. The memory 103 is used to store computer program instructions.

[0177] The transceiver 101 may be used to perform data transmission with an external device.

[0178] The system bus can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The system bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus. The transceiver is used to realize the communication between the database access device and other computers (such as clients, read-write libraries, and read-only libraries). The memory may include random access memory (RAM) and may also include non-volatile memory.

[0179] The electronic device provided in the embodiments of the present application may be the client mentioned in the above embodiments.

[0180] It should be noted that the above-mentioned electronic device provided in the embodiment of the present application can be used to execute the technical solution of the exception handling method of multi-level transactions in the above-mentioned embodiment, and its implementation principle and technical effect are similar, which will not be repeated here.

[0181] The embodiment of the present application also provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the exception handling method for multi-level transactions provided in the above embodiment.

[0182] It should be noted that the above-mentioned medium provided in the embodiment of the present application can be used to execute the technical solution of the exception handling method of multi-level transactions in the above-mentioned embodiment, and its implementation principle and technical effect are similar, which will not be repeated here.

[0183] In a fifth aspect, the present application provides a computer program product, including a computer program, which, when executed by a processor, implements the multi-level transaction exception handling method provided in the above embodiment.

[0184] It should be noted that the above-mentioned program product provided in the embodiment of the present application can be used to execute the technical solution of the exception handling method of multi-level transactions in the above-mentioned embodiment. Its implementation principle and technical effect are similar and will not be repeated here.

[0185] The embodiment of the present application also provides a chip for executing instructions, which is used to execute the technical solution of the exception method of multi-level transactions in the above embodiment. Its implementation principle and technical effect are similar and will not be repeated here.

[0186] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic, for example, the division of modules is only a logical function division, and there may be other division methods in actual implementation, such as multiple modules can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or modules, which can be electrical, mechanical or other forms.

[0187] The modules described as separate components may or may not be physically separated, and the components shown as modules may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the modules may be selected according to actual needs to implement the solution of this embodiment.

[0188] In addition, each functional module in each embodiment of the present application can be integrated into one processing unit, or each module can exist physically separately, or two or more modules can be integrated into one unit. The above-mentioned module-composed unit can be implemented in the form of hardware or in the form of hardware plus software functional units.

[0189] The above-mentioned integrated module implemented in the form of a software function module can be stored in a computer-readable storage medium. The above-mentioned software function module is stored in a storage medium, including a number of instructions for enabling a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to perform some steps of the methods of various embodiments of the present application.

[0190] It should be understood that the processor may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. A general-purpose processor may be a microprocessor or any conventional processor. The steps of the method disclosed in the invention may be directly implemented as being executed by a hardware processor, or may be implemented by a combination of hardware and software modules in the processor.

[0191] The memory may include a high-speed RAM memory, and may also include a non-volatile storage NVM, such as at least one disk memory, and may also be a USB flash drive, a mobile hard disk, a read-only memory, a magnetic disk or an optical disk, etc.

[0192] The bus may be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (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. For ease of representation, the bus in the drawings of the present application is not limited to only one bus or one type of bus.

[0193] The above 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 memory, flash memory, magnetic disk or optical disk. The storage medium can be any available medium that can be accessed by a general or special purpose computer.

[0194] An exemplary storage medium is coupled to a processor so that the processor can read information from the storage medium and write information to the storage medium. Of course, the storage medium can also be a component of the processor. The processor and the storage medium can be located in an application specific integrated circuit (ASIC). Of course, the processor and the storage medium can also exist as discrete components in an electronic control unit or a main control device.

[0195] Those skilled in the art can understand that all or part of the steps of implementing the above-mentioned method embodiments can be completed by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When the program is executed, the steps of the above-mentioned method embodiments are executed; and the aforementioned storage medium includes: ROM, RAM, disk or optical disk and other media that can store program codes.

[0196] Finally, it should be noted that the above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit it. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or replace some or all of the technical features therein with equivalents. However, these modifications or replacements do not cause the essence of the corresponding technical solutions to deviate from the scope of the technical solutions of the embodiments of the present application.

Claims

1. A method for handling exceptions in a multi-level transaction, characterized in that: The multi-level transaction includes a top-level transaction and at least one bottom-level transaction, and the method includes: Creating an exception rollback list, where the exception rollback list is used to record the rollback log corresponding to the multi-level transaction; Execute the transaction processing process at each level. If an exception is caught during the processing of any underlying transaction, trigger an exception rollback operation for the underlying transaction and generate a first rollback log, and write the first rollback log into the exception rollback list; wherein, the exception rollback operation of any underlying transaction triggers the exception rollback operation of the top-level transaction; Binding the pre-created exception rollback tracking object and the exception rollback list to obtain binding information about the exception rollback tracking object; When the transaction processing at each level is completed, if it is detected that any level of transaction sets a rollback flag, which is generated when any level of transaction triggers an abnormal rollback operation, an exception is thrown to the exception handling system based on the binding information.

2. The method according to claim 1, characterized in that Also includes: If an exception is caught during the top-level transaction processing, a global exception rollback operation for the multi-level transaction processing process is triggered and a second rollback log is generated; The second rollback log is written into the abnormal rollback list.

3. The method according to claim 1 or 2, characterized in that: Also includes: Create a database connection management object and a thread private cache; wherein the database management object is used to manage the database connection information corresponding to the multi-level transaction and the rollback flag of each underlying transaction; The database connection management object is cached in the thread private cache.

4. The method according to claim 3, characterized in that The step of caching the database connection management object into the thread private cache includes: Based on the transaction synchronization management tool, the database connection management object is cached in the thread private cache, so that the thread private cache stores the corresponding database connection information and the rollback flag of the transaction in the transaction processing process at each level.

5. The method according to claim 3, characterized in that: After creating the exception rollback list, it also includes: Based on a transaction synchronization management tool, the exception rollback list is cached in the thread private cache to implement binding between the exception rollback list and the database connection management object.

6. The method according to any one of claims 1 to 5, characterized in that: Also includes: For the multi-level transaction processing process, before starting to process any level of transaction, the transaction definition of the transaction is read based on the interception aspect and an interception point identifier for the transaction is generated to obtain the transaction definition and interception point identifier of each level of transaction; According to the transaction definitions of transactions at various levels and the interception point identifiers, transaction information objects of transactions at various levels are created. The transaction information objects are used to record transaction information during transaction processing, and the transaction information is cached in a thread private cache.

7. The method according to claim 6, characterized in that Also includes: In response to each bottom-level transaction setting a transaction status completion flag, and the top-level transaction not setting a transaction completion flag, generating a third rollback log according to a rollback flag set by any bottom-level transaction; The third rollback log is written into the abnormal rollback list.

8. The method according to claim 6, characterized in that Also includes: In response to setting transaction status completion flags of transactions at various levels, transaction information of transactions at various levels in the thread private cache is cleared in sequence.

9. The method according to claim 6 or 7, characterized in that: Also includes: The cache information other than the transaction information in the thread private cache and related to the multi-level transaction is cleared, wherein the cache information includes the exception rollback list.

10. The method according to any one of claims 1 to 5, characterized in that: The method is applied to a client, and before creating an exception rollback list, further includes: In response to a service request initiated by a user at a client, the service request is a request for a multi-level service, and based on an interception aspect, a service method for the service request is encapsulated as the multi-level transaction.

11. The method according to claim 9, characterized in that Also includes: When an exception is thrown to the exception handling system based on the binding information, error information of business processing failure is fed back to the user.

12. An exception handling device for multi-level transactions, characterized in that: The device comprises: A list creation module, which is configured to create an exception rollback list, wherein the exception rollback list is used to record the rollback log corresponding to the multi-level transaction; A log generation module, which is configured to execute the transaction processing process at each level, and if an exception is caught during any bottom-level transaction processing, trigger an exception rollback operation for the bottom-level transaction and generate a first rollback log, and write the first rollback log into the exception rollback list; wherein the exception rollback operation of any bottom-level transaction triggers the exception rollback operation of the top-level transaction; A binding module, which is configured to bind a pre-created exception rollback tracking object and the exception rollback list to obtain binding information about the exception rollback tracking object; The exception throwing module is configured to throw an exception to the exception handling system based on the binding information when the transaction processing at each level is completed and if it is detected that any level transaction sets a rollback flag, the rollback flag is generated when any level transaction triggers an abnormal rollback operation.

13. An electronic device, characterized in that: include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the multi-level transaction exception handling method according to any one of claims 1-11.

14. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, which are used to implement the method according to any one of claims 1 to 11 when executed by a processor.

15. A computer program product, characterized in that The invention comprises a computer program, which, when executed by a processor, implements the method for handling exceptions of multi-level transactions according to any one of claims 1 to 11.