Business processing method and device and storage medium

By intercepting log flag annotations in the Spring framework and switching connection identifiers, the performance consumption problem caused by frequent log operations is solved, efficient business processing in multiple connection scenarios is achieved, and system performance is improved.

CN118939625APending Publication Date: 2024-11-12CCB FINTECH CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

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

AI Technical Summary

Technical Problem

Under the Spring framework, frequent logging operations lead to excessive performance consumption, and the prior art is difficult to control multiple connections at the same time, such as network connections or database connections in one thread, resulting in system performance degradation.

Method used

By intercepting log flag annotations during application execution, the connection identifier of the transaction operation is changed as a log connection, and a log type operation for the log database is initiated; after the operation log record is completed, it is changed to a business connection, and a business type for the business database is initiated. Operation, thereby switching between business connections and log connections, avoiding frequent connection opening and closing operations, and reducing performance overhead.

Benefits of technology

It effectively reduces the performance consumption caused by log operations, especially in frequent log operations scenarios, which significantly improves system performance.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118939625A_ABST
    Figure CN118939625A_ABST
Patent Text Reader

Abstract

The invention provides a business processing method and device and a storage medium, and relates to the technical field of big data. The method is applied to a server deployed with Spring AOP, and comprises the following steps: in an application execution process, if a log mark annotation is intercepted, changing a connection identifier of a transaction operation into a log connection, and initiating a log type operation for a log database; and after the operation log is recorded, changing a connection identifier of the transaction operation into a service connection, and initiating a service type operation aiming at the service database. By means of the method and device, performance consumption caused by frequent log operation can be reduced.
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 business processing method, device and storage medium. Background Art

[0002] In the Spring framework, using annotations to mark and control transactions has become the most important transaction management method in the field of JAVA development. Spring provides a simple @Transactional tag to record the current transaction. However, since all its transaction control is based on thread-private cache (ThreadLocal) to achieve cross-method transaction synchronization, it is difficult to control multiple connections in one thread at the same time, such as network connections or database connections. Controlling multiple connections in one thread at the same time is a common requirement. For example, in the process of business development, business operations must be recorded while operating logs. The results of business operations will eventually be submitted or rolled back along with the various conditions of the execution process, and operation logs must be submitted.

[0003] In the above scenario, since the Spring transaction manager does not provide a method to enable two connections at the same time, you can currently set the propagation type of Spring's transaction to REQUIRES_NEW, open the connection when there is a log operation, and close the connection after the log operation is completed to ensure that the request of a single method is isolated from the entire transaction. However, in actual implementation, frequent log operations will cause a lot of performance consumption. Summary of the invention

[0004] The present application provides a business processing method, device and storage medium to solve the problem of frequent log operations leading to large performance consumption in the prior art.

[0005] In a first aspect, the present application provides a business processing method, which is applied to a server deployed with Spring AOP, and the business processing method includes: during the application execution process, if a log mark annotation is intercepted, the connection identifier of the transaction operation is changed to a log connection (logConnection), and a log type operation is initiated for the log database;

[0006] After the operation log record is completed, the connection identifier of the transaction operation is changed to the business connection (targetConnection), and a business type operation is initiated for the business database.

[0007] In a possible design, the connection identifier for the change transaction operation is a log connection, including:

[0008] A static enterLog operation is performed in the log database key holder (DbLogKeyHolder), the log database key holder adds an integer key flag in the thread private cache attribute, and the static enterLog operation is used to perform an increment operation on the integer key flag;

[0009] Correspondingly, a log type operation is initiated for the log database, including: calling the log database interface (DbLogConnection) to perform log type operations on the log database, the log database interface is used to detect the value of the integer key flag in the log database key holder, if the value indicates that the log database key holder is in a log activation state, the log connection is used to initiate a log type operation for the log database.

[0010] In a possible design, the connection identifier of the change transaction operation is a business connection, including:

[0011] Execute the decrement operation on the integer key flag in the log database key holder;

[0012] Correspondingly, a business type operation is initiated for the business database, including: calling the log database interface to perform business type operations on the business database. The log database interface is also used to detect the value of the integer key flag in the log database key holder. If the value indicates that the log database key holder is not in a log activation state, a business type operation is initiated for the business database using a business connection.

[0013] In a possible design, it also includes: after all business type operations corresponding to the current business call request are executed, calling the log database interface to perform submission operations on the business connection and the log connection respectively;

[0014] Alternatively, when an exception occurs, the log database interface is called to perform a rollback operation on the business connection and a commit operation on the log connection.

[0015] In a possible design, it also includes: after the commit operation and / or rollback operation is completed, the closing method and the property configuration restoration method of the log database interface are called, the closing method is used to close the business connection and the log connection, and the property configuration restoration method is used to restore the business connection configuration and the log connection configuration to recycle system resources.

[0016] In a possible design, it also includes: responding to a business call request for an application, starting a transaction manager, the transaction manager obtaining a log database interface through a log database data source (DbLogDataSource), and initializing and configuring the log database interface.

[0017] In one possible design, the log database interface is constructed in the following way:

[0018] Obtain two database connections through the basic data source. One of the two database connections is used for business operations, and the other is used for log operations.

[0019] Set the initial connection identifier of the transaction operation to the business connection.

[0020] In a second aspect, the present application provides a service processing device, including:

[0021] The log type operation module is used to change the connection identifier of the transaction operation to a log connection and initiate a log type operation for the log database if a log mark annotation is intercepted during the application execution process;

[0022] The business type operation module is used to change the connection identifier of the transaction operation to a business connection after the operation log record is completed, and initiate a business type operation for the business database.

[0023] In some embodiments, the log type operation module is specifically used to: perform a static injection log operation in a log database key holder, the log database key holder adds an integer key flag in a thread private cache attribute, and the static injection log operation is used to perform an increment operation on the integer key flag;

[0024] Correspondingly, a log type operation is initiated for the log database, including: calling the log database interface to perform the log type operation on the log database, the log database interface is used to detect the value of the integer key flag in the log database key holder, if the value indicates that the log database key holder is in a log activation state, a log connection is used to initiate a log type operation for the log database.

[0025] In some embodiments, the business type operation module is specifically used to: perform a subtraction operation on an integer key flag in a log database key holder;

[0026] Correspondingly, a business type operation is initiated for the business database, including: calling the log database interface to perform business type operations on the business database. The log database interface is also used to detect the value of the integer key flag in the log database key holder. If the value indicates that the log database key holder is not in a log activation state, a business type operation is initiated for the business database using a business connection.

[0027] In some embodiments, the business processing method device further includes a commit rollback module (not shown), which is specifically used to: after all business type operations corresponding to the current business call request are completed, call the log database interface to perform commit operations on the business connection and the log connection respectively;

[0028] Alternatively, when an exception occurs, the log database interface is called to perform a rollback operation on the business connection and a commit operation on the log connection.

[0029] In some embodiments, the business processing method device also includes a shutdown and restoration module, which is specifically used to: after the commit operation and / or rollback operation is completed, call the closing method and attribute configuration restoration method of the log database interface, the closing method is used to close the business connection and the log connection, and the attribute configuration restoration method is used to restore the business connection configuration and the log connection configuration to recycle system resources.

[0030] In some embodiments, the business processing method device also includes a startup module, which is specifically used to: respond to a business call request for an application, start a transaction manager, the transaction manager obtains a log database interface through a log database data source, and initializes the log database interface.

[0031] In some embodiments, the log database interface is constructed in the following manner:

[0032] Obtain two database connections through the basic data source. One of the two database connections is used for business operations, and the other is used for log operations.

[0033] Set the initial connection identifier of the transaction operation to the business connection.

[0034] In a third aspect, an embodiment of the present application provides a server, which is deployed with Spring AOP. The server includes: at least one processor and a memory; the memory stores computer-executable instructions; at least one processor executes the computer-executable instructions stored in the memory, so that at least one processor executes the method of the first aspect and various possible designs of the first aspect.

[0035] In a fourth aspect, an embodiment of the present application provides a computer-readable storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, the method of the first aspect and various possible designs of the first aspect are implemented.

[0036] In a fifth aspect, an embodiment of the present application provides a computer program product, including a computer program. When the computer program is executed by a processor, it implements the method of the first aspect and various possible designs of the first aspect.

[0037] The business processing method, device and storage medium provided by the present application are applied to a server deployed with Spring AOP. During the application execution process, if a log mark annotation is intercepted, the connection identifier of the transaction operation is changed to a log connection, and a log type operation for the log database is initiated. Since business processing is mainly performed under the business connection during the application execution process, when the log mark annotation is intercepted, the business connection is switched to the log connection; after the operation log record is completed, the connection identifier of the transaction operation is changed to a business connection, and a business type operation for the business database is initiated, that is, after the operation log record is completed, the log connection is switched to the business connection. By switching between the business connection and the log connection, the opening and closing operations of the log connection can be avoided when there is a log operation, and the performance overhead caused thereby is reduced, especially in the scenario where there are frequent log operations, the system performance is more significantly improved. BRIEF DESCRIPTION OF THE DRAWINGS

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

[0039] Figure 1 A process diagram of a business processing method provided in an embodiment of the present application Figure 1 ;

[0040] Figure 2 An overall flow chart of the business processing method provided in the embodiment of the present application;

[0041] Figure 3 A schematic diagram of the principle of the log mark annotation method provided in the embodiment of the present application;

[0042] Figure 4 A schematic diagram of the principle of the matching section determination type method provided in an embodiment of the present application;

[0043] Figure 5 A schematic diagram of the principle of the log interceptor provided in the embodiment of the present application;

[0044] Figure 6 A schematic diagram of the principle of the log entry point notifier provided in the embodiment of the present application;

[0045] Figure 7 A schematic diagram of the structure of a service processing device provided in one embodiment of the present application;

[0046] Figure 8 A schematic diagram of the structure of a server provided in one embodiment of the present application.

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

[0048] 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, unless otherwise indicated, the same numbers in different drawings represent the same or similar elements. 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.

[0049] 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 shall comply with the provisions of relevant laws and regulations and shall not violate public order and good morals.

[0050] It should be noted that in the embodiments of the present application, certain software, components, models and other existing solutions in the industry may be mentioned, and they should be regarded as exemplary. Their purpose is only to illustrate the feasibility of implementing the technical solution of the present application, but it does not mean that the applicant has or will necessarily use the solution.

[0051] 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 further 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.

[0052] In order to reduce the problem of frequent log operations in related technologies causing a large amount of performance consumption, this application designs a business processing method, namely a database log recording method based on annotation configuration. When executing this method, the idea of ​​a log-specific shadow connection is adopted to execute the operations marked as logs in the call stack, thereby solving the problem of overlapping commit and rollback of business status and commit and rollback of business operation log records in the business process. At the same time, this method avoids the need to perform a connection initialization operation and a closing operation after each log operation, thereby improving the system's operating performance.

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

[0054] Figure 1 A process diagram of a business processing method provided in an embodiment of the present application Figure 1 The business processing method provided in the embodiment of the present application is applied to a server deployed with Spring AOP and can be executed by a computing device such as a server or a server cluster. Figure 1 As shown, the method includes:

[0055] S101. During the application execution process, if a log mark annotation is intercepted, the connection identifier of the transaction operation is changed to a log connection, and a log type operation for the log database is initiated.

[0056] A log flag annotation is a metadata tag that indicates that a specific location in the code needs to be logged. This annotation can be recognized by the logging framework at runtime and perform logging operations accordingly. In an example, the log flag annotation can be specifically @Dblog.

[0057] Furthermore, log type operations refer to the management and recording of transaction execution processes in a database system by recording operation logs of various types of databases. These operation logs are used to ensure that the database can be restored to a consistent state in the event of a failure and that transactions can be processed correctly.

[0058] The connection identifier of the change transaction operation is a log connection, that is, a connection is established with a log database, and after the connection is established, a log type operation for the log database is initiated, such as injecting logs into the log database, and so on.

[0059] S102: After the operation log record is completed, the connection identifier of the transaction operation is changed to a business connection, and a business type operation for the business database is initiated.

[0060] In this step, it can be understood that after the operation log record is completed, the connection identifier of the transaction operation needs to be changed to a business connection, and a business type operation for the business database of the business connection is initiated. Among them, the business type operation refers to the operation performed on various types of business databases in the database system. Such operations include but are not limited to the following aspects:

[0061] Data creation: Add new business information to the business database through insert operations, such as adding product information of new products to the business database;

[0062] Data reading: quickly retrieve business information from the business database by executing query operations to respond to user requests;

[0063] Data update: modify the business information in the business database to ensure the timeliness and accuracy of the business information;

[0064] Data Deletion: Remove outdated or no longer needed business information by performing a deletion operation.

[0065] Furthermore, the specific implementation of the business type operation can be set according to user needs, for example, the business type operation on the business database can be implemented through the Structured Query Language (SQL for short).

[0066] The embodiment of the present application switches between business connections and log connections to avoid opening and closing log connections when log operations are present, thereby reducing the performance overhead incurred thereby, and the system performance is more significantly improved in scenarios where frequent log operations are present.

[0067] In one example, when the system detects the intercept log flag annotation, the system will automatically switch the connection mode of the transaction operation. For example, if the current transaction operation uses the connection of database A, the system can switch to the connection of database B. After the switch is completed, the system will initiate corresponding operations based on the new connection mode, such as executing queries or update operations. After the log record is completed, the system will switch the connection mode of the transaction operation again, restore to the original connection mode or switch to another predefined connection mode. Then, the system will initiate corresponding operations based on the restored connection mode or switch to another predefined connection mode to ensure the continuity and consistency of the transaction operation. In this way, the system can flexibly switch between different connection modes and reduce the performance overhead caused by this, especially in scenarios with frequent log operations, the system performance improvement is more obvious.

[0068] On the basis of the above embodiment, the connection identifier of the change transaction operation described in S101 is a log connection, including: performing a static injection log operation in the log database key holder, the log database key holder adds an integer key flag in the thread private cache attribute, and the static injection log operation is used to perform a plus 1 operation on the integer key flag; correspondingly, initiating a log type operation for the log database, including: calling a log database interface to perform a log type operation on the log database, the log database interface is used to detect the value of the integer key flag in the log database key holder, if the value indicates that the log database key holder is in a log activation state, using the log connection to initiate a log type operation for the log database.

[0069] In this embodiment, it can be understood that changing the connection identifier of the transaction operation to a log connection requires the log database key holder to add an integer key flag in the thread private cache attribute and perform an increment operation on the integer key flag. The log database interface is called to detect the value of the integer key flag in the log database key holder. If the value of the integer key flag indicates that the log database key holder is in a log activation state, a log type operation for the log database is initiated using a log connection.

[0070] Furthermore, the connection identifier of the transaction change operation described in S102 is a business connection, including: performing a subtraction operation on the integer key flag in the log database key holder; correspondingly, initiating a business type operation for the business database, including: calling the log database interface to perform the business type operation on the business database, the log database interface is also used to detect the value of the integer key flag in the log database key holder, if the value indicates that the log database key holder is not in a log activation state, the business connection is used to initiate a business type operation for the business database.

[0071] In this embodiment, it can be understood that to change the connection identifier of the transaction operation to a business connection, it is necessary to perform a subtraction operation on the integer key flag in the log database key holder. The log database interface is called to detect the value of the integer key flag in the log database key holder. If the value of the integer key flag indicates that the log database key holder is not in the log activation state, the business type operation for the business database is initiated using the business connection.

[0072] The embodiment of the present application determines the state of the log database key holder by detecting the value of the integer key flag in the log database key holder, and determines the database operation type according to the log database key holder state, thereby achieving the purpose of improving the accuracy of the business processing method.

[0073] In order to ensure the atomicity, consistency, isolation and persistence of transactions, as well as the persistence of log records and the recovery capability of the database, the above-mentioned business processing method also includes: after all business type operations corresponding to the current business call request are completed, calling the log database interface to perform commit operations on the business connection and the log connection respectively; or, when there is an exception, calling the log database interface to perform a rollback operation on the business connection.

[0074] In this step, it can be understood that after all log type operations and business type operations corresponding to the current business call request are completed, the log database interface is called to perform submission operations on the log connection and the business connection respectively. In this way, all business type operations can be treated as a whole and all log type operations can be treated as another whole, thereby ensuring the consistency and integrity of the database data.

[0075] Furthermore, when there is an exception in the business type operation corresponding to the current business call request, it is necessary to call the log database interface to perform a rollback operation on the business connection to restore the database to the state before the business type operation, that is, to cancel all business type operations.

[0076] In addition, due to the atomicity of log operations, when a database or other exception occurs in the corresponding log type operation of the current business call request, the abnormal behavior will be captured and intercepted by the log interceptor, and the occurrence of the abnormal behavior will be recorded in the form of file logs, etc., but the log connection will not be rolled back.

[0077] The embodiment of the present application can ensure the consistency and integrity of database data by performing commit and / or rollback operations on business connections and performing commit operations on log connections after all business type operations corresponding to the current business call request are completed.

[0078] Furthermore, the Spring-based business processing method also includes: after the commit operation and / or rollback operation is completed, calling the closing method and property configuration restoration method of the log database interface, the closing method is used to close the business connection and the log connection, and the property configuration restoration method is used to restore the business connection configuration and the log connection configuration to recycle system resources.

[0079] In one implementation, when there is an exception in the corresponding business type operation of the current business call request, the log database interface is called to perform a rollback operation on the business connection; then, the closing method and attribute configuration restoration method of the log database interface are called to close the business connection and the log connection, and to restore the business connection configuration and the log connection configuration to recycle system resources.

[0080] In another implementation, when there is an exception in the corresponding business type operation of the current business call request, the log database interface is called to perform a rollback operation on the business connection. When there is no exception in the corresponding business type operation, the closing method and attribute configuration restoration method of the log database interface are called to close the business connection and log connection, and restore the business connection configuration and log connection configuration to recycle system resources.

[0081] In another implementation, when there is no exception in the corresponding business type operation of the current business call request, the log database interface is called to perform a commit operation on the business connection and the log connection; thereafter, the closing method and the property configuration restoration method of the log database interface are called to close the business connection and the log connection, and to restore the business connection configuration and the log connection configuration to recycle system resources.

[0082] In this embodiment, it can be understood that after the business connection is submitted and / or rolled back, and the log connection is submitted, the closing method and the attribute configuration restoration method of the log database interface are called, wherein the closing method is used to close the business connection and the log connection, and the attribute configuration restoration method is used to restore the business connection configuration and the log connection configuration. Further, calling the closing method and the attribute configuration restoration method of the log database interface is to recycle system resources, thereby releasing system memory.

[0083] After the commit operation of the log database interface, the closing method of the log database interface is called. Optionally, the closing method of the log database interface can be called in the following manner: the closing methods of the log connection and the business connection are called respectively.

[0084] The embodiment of the present application can realize the recovery of system resources by calling the closing method and the attribute configuration restoration method of the log database interface after the commit operation and / or the rollback operation are completed, so as to efficiently utilize the system resources and reduce the consumption of system resources.

[0085] Based on the above embodiment, the service processing method further includes: responding to a service call request for an application, starting a transaction manager, the transaction manager obtaining a log database interface through a log database data source, and initializing configuration of the log database interface.

[0086] The specific implementation method of starting the transaction manager can be set according to specific needs.

[0087] Optionally, after receiving a business call request for an application, the server enters the transaction interceptor through a method modified with the @Transactional annotation in the business call logic, and uses the transaction interceptor to start the transaction manager.

[0088] After the transaction manager is started, it is necessary to obtain the log database interface through the log database data source and initialize the log database interface.

[0089] The contents of the initial configuration include but are not limited to the following aspects:

[0090] Intercept aspect framework: used to switch the database connection mode based on Spring transaction management. The intercept aspect framework contains log flag annotations. The log flag annotation is the flag to enable database log operations. The log flag annotation must be defined for database operations of all log-type transactions.

[0091] Matching aspect judgment type method (DblogPointCut): expressed through pointcut expressions, used to define methods that require transaction enhancement in declarative transaction managers;

[0092] Log interceptor (DblogInterceptor): used to perform the operation of changing the connection identifier of the transaction operation when the log flag annotation is enabled;

[0093] Log entry point notifier (DblogPointcutAdvisor): used to use the Spring AOP mechanism to determine the method that meets the entry interception requirements at runtime, and add a log interceptor for injection interception;

[0094] Log database data source: inherited from the proxy data source, it is a decorated data source, and the internal attribute target data source (targetDataSource) needs to reference the real data source object. The log database data source is used as the default data source, and common Druid data sources (DruidDataSource) and other data sources are injected as the actual internal data source objects.

[0095] The getConnection method of the log database data source returns a custom connection object log database interface. The log database interface is a decorated connection object that implements the connection interface and contains two internal underlying connections: the target connection (targetConnection), that is, the business connection, and the log connection (logConnection).

[0096] In the process of implementing the log database interface, you must first define a constructor, which, when constructing itself, builds two instances of the business connection and the log connection from the data source at the same time.

[0097] Log database key holder object: Based on thread-private cache, control the integer key flag in different aspects.

[0098] In addition, the initialization configuration also includes encoding configuration and basic configuration. Encoding configuration refers to defining log mark annotations on database operations of all log-type transactions. Basic configuration refers to interception configuration in Spring AOP: defining a singleton bean in the configuration, which is used to introduce a log entry point notifier in the Bean Factory (SpringBeanFactory) in the Spring framework, and the introduced log entry point notifier is used to enhance each valid method.

[0099] By starting the transaction manager, the embodiment of the present application can ensure that all operations in the transaction are either completed or not completed. This all-or-nothing feature can improve the reliability of the system.

[0100] Based on the above embodiment, the log database interface is constructed in the following manner: two database connections are obtained through the basic data source, one of the two database connections is used for business type operations, and the other database connection is used for log type operations; the initial connection identifier of the transaction operation is set to the business connection.

[0101] In this embodiment, it can be understood that when building a log database interface, it is necessary to obtain two database connections through a basic data source, such as obtaining two database connections through a druid data source. Among them, one database connection is used for business type operations, and the other database connection is used for log type operations. Since the interception aspect is not passed at this time, that is, the log connection identifier is not stored by default, the initial connection identifier of the transaction operation is set to the business connection. Through the embodiment of the present application, a database connection can be established in advance, so that log type operations and business type operations can be performed through the pre-established database connection during the execution of subsequent applications.

[0102] Next, taking database logging based on Spring transaction components as an example, it is explained how to use the business processing method provided in the embodiment of the present application. Figure 2 This is an overall flow chart of the business processing method provided in the embodiment of the present application.

[0103] The aggregation layer encapsulates complex business logic and multiple service calls, and provides simplified interfaces, such as log database interfaces. The service layer is used to process user-related business logic and data operations, such as obtaining log connections, executing log-type operations, obtaining business connections, executing business-type operations, and returning execution results.

[0104] like Figure 2 As shown, the overall process is as follows:

[0105] 1. Configuration phase:

[0106] 1) Define an interception aspect framework to switch the database connection mode based on Spring transaction management. The interception aspect framework contains a log flag annotation, which is a flag for enabling database log operations and is used to mark the database access method that performs log operations. Define the log flag annotation on the database operations of all log-type transactions.

[0107] Optionally, the principle of the log mark annotation method can be referred to Figure 3 , Figure 3 A schematic diagram of the principles of the log mark annotation method provided in an embodiment of the present application.

[0108] Define the matching aspect determination type method. The matching aspect determination type method is expressed through a pointcut expression and is used to define methods that require transaction enhancement in the declarative transaction manager.

[0109] Optionally, the principle of matching aspect determination type method can refer to Figure 4 , Figure 4 A schematic diagram of the principle of the matching section determination type method provided in an embodiment of the present application.

[0110] Defines a log interceptor to change the connection identifier of a transaction operation when the log flag annotation is enabled.

[0111] Optionally, the principle of log interceptor can refer to Figure 5 , Figure 5 A schematic diagram of the principles of the log interceptor provided in an embodiment of the present application.

[0112] Define a log entry point notifier to use the Spring AOP mechanism to determine the methods that meet the entry interception requirements at runtime, and add a log interceptor for injection interception.

[0113] In one example, the principle of the log entry point notifier can be referred to Figure 6 , Figure 6 A schematic diagram of the principles of a log entry point notifier provided in an embodiment of the present application.

[0114] 2) Define the data source framework, which is used to provide a data source with switchable connections, i.e., the operation object:

[0115] Define the log database data source, which inherits from the proxy data source and is itself a decorative data source. The internal attribute business connection needs to reference the real data source object.

[0116] The get connection method of the log database data source returns a custom connection object log database interface. The log database interface is a decorated connection object and also a proxy type that implements the connection interface. It is used to perform connection switching during operations.

[0117] In the process of implementing the log database interface, you must first define a constructor, which, when constructing itself, simultaneously builds two instances of business connection and log connection from the log database data source. That is, the log database interface contains two internal underlying connections, business connection and log connection.

[0118] Log database key holder object: Based on thread-private cache, control the integer key flag in different aspects.

[0119] 3)Encoding configuration:

[0120] Define the @Dblog annotation on all database operations that are log-type transactions.

[0121] 4) Basic configuration:

[0122] Intercept configuration in Spring AOP: Define a singleton bean in the configuration. The singleton bean is used to introduce a log entry point notifier into the bean factory in the Spring framework. The introduced log entry point notifier is used to enhance each valid method.

[0123] Define the log database data source as the default data source, and inject common Druid data sources and other data sources as the actual internal data source objects.

[0124] 2. Start-up phase:

[0125] Start the Springboot project through the startup method, and use the scanning mechanism in the Springboot project to scan and find the bean definition of the log entry point notifier, the log database data source definition, and the bean definition modified by the log mark annotation @Dblog;

[0126] Generates a singleton instance corresponding to the above type.

[0127] In addition, after the Springboot project is started, Springboot automatically loads business components, including service components, controllers, and configuration classes.

[0128] 3. Execution phase:

[0129] 1) The user initiates a service call operation on the user request layer, wherein the specific implementation method of the user initiating the service call operation can be set according to the requirements, for example, the user can initiate the service call operation by clicking a certain area of ​​the image on the human-computer interaction page;

[0130] 2) After the server receives the business call operation request initiated by the user, if it is confirmed that the business call operation request contains a request for database processing, it enters the transaction interceptor through the method modified by the @Transactional annotation in the business call logic, and uses the transaction interceptor to start the transaction manager in the interception aspect (Spring-Transaction-AOP, referred to as Spring-TX-AOP). The transaction interceptor and the log interceptor are different interceptors;

[0131] 3) After the transaction manager is started, the connection acquisition method is called to acquire the business connection and log connection instances in the log database interface based on the data source, where the business connection is used for regular transactions and the log connection is used for log records, and the business connection is used as the current connection;

[0132] 4) Initialize the configuration of the log database interface, business connection, and log connection, such as configuring the auto-commit (setautocommit) operation;

[0133] 5) After the initialization configuration is completed, the log database interface will check the integer key flag in the log database key holder, and determine the connection method for executing business type operations and log type operations based on the integer key flag. Since it has not passed the interception aspect, the default log connection is not in an activated state, that is, the log database key holder is in a state where the integer key flag does not exist or the integer key flag is 0, and it is determined to use the business connection to execute business type operations;

[0134] 6) The log interceptor initiates a log type operation for the log database, and uses the log interceptor to intercept the received request to read the annotation information. The log database key holder adds an integer key flag to the thread private cache attribute, and performs an increment operation on the integer key flag to activate the log connection, even if the integer key flag is greater than 0, and determines that the current connection mode is a log connection. Among them, the increment operation on the integer key flag is performed after the log interceptor intercepts the request;

[0135] 7) Use the log database interface to obtain the current log connection and perform log type operations;

[0136] 8) After the log type operation is executed, the execution result is returned to the transaction manager and the integer key flag in the log database key holder is decremented by 1, that is, the leave flag (leavelog) operation is executed to end the log type operation;

[0137] 9) The log interceptor initiates a business type operation against the business database, obtains the current business connection using the log database interface, and executes the business type operation. After the business type operation is completed, the execution result is returned to the transaction manager;

[0138] 10) The transaction manager calls the log database interface to perform a commit operation on the business connection and the log connection respectively according to the execution result; or, when an exception occurs, calls the log database interface to perform a rollback operation on the business connection;

[0139] 11) After the commit operation and / or rollback operation is completed, the log database interface is called to close the business connection and log connection and restore the attribute configuration to recycle system resources. In addition, the log database key holder needs to be cleaned up of the integer key mark.

[0140] Furthermore, when the system call enters the interception aspect multiple times in succession, the integer key flag of the log database key holder is increased by 1 each time. Similarly, when the system call leaves the log interceptor multiple times in succession, the integer key flag of the log database key holder is reduced by 1 each time.

[0141] In summary, the business processing method provided in the embodiment of the present application relies on a set of customized devices, and by combining the characteristics of Spring transaction management, it achieves the effect of recording exclusive shadow connections in database logs in a single business, reduces the complexity of database and log operations, and improves readability and execution performance.

[0142] The following are device embodiments of the present application, which can be used to execute the method embodiments of the present application. For details not disclosed in the device embodiments of the present application, please refer to the method embodiments of the present application.

[0143] The business processing method device is applied to a server deployed with Spring AOP. Figure 7 This is a schematic diagram of the structure of a service processing device provided in one embodiment of the present application. Figure 7 As shown, the service processing method and device 700 includes:

[0144] The log type operation module 701 is used to change the connection identifier of the transaction operation to a log connection and initiate a log type operation for the log database if a log mark annotation is intercepted during the application execution process;

[0145] The business type operation module 702 is used to change the connection identifier of the transaction operation to a business connection after the operation log record is completed, and initiate a business type operation for the business database.

[0146] In some embodiments, the log type operation module 701 is specifically used to: perform a static injection log operation in a log database key holder, the log database key holder adds an integer key flag in a thread private cache attribute, and the static injection log operation is used to perform an increment operation on the integer key flag;

[0147] Correspondingly, a log type operation is initiated for the log database, including: calling the log database interface to perform the log type operation on the log database, the log database interface is used to detect the value of the integer key flag in the log database key holder, if the value indicates that the log database key holder is in a log activation state, a log connection is used to initiate a log type operation for the log database.

[0148] In some embodiments, the business type operation module 702 is specifically used to: perform a subtraction operation on an integer key flag in a log database key holder;

[0149] Correspondingly, a business type operation is initiated for the business database, including: calling the log database interface to perform business type operations on the business database. The log database interface is also used to detect the value of the integer key flag in the log database key holder. If the value indicates that the log database key holder is not in a log activation state, a business type operation is initiated for the business database using a business connection.

[0150] In some embodiments, the business processing method device 700 further includes a commit rollback module (not shown), which is specifically used to: after all business type operations corresponding to the current business call request are executed, call the log database interface to perform commit operations on the business connection and the log connection respectively;

[0151] Alternatively, when an exception occurs, the log database interface is called to perform a rollback operation on the business connection and a commit operation on the log connection.

[0152] In some embodiments, the business processing method device 700 also includes a closing and restoring module, which is specifically used to: after the commit operation and / or rollback operation is completed, call the closing method and the attribute configuration restoration method of the log database interface, the closing method is used to close the business connection and the log connection, and the attribute configuration restoration method is used to restore the business connection configuration and the log connection configuration to recycle system resources.

[0153] In some embodiments, the business processing method device 700 also includes a startup module, which is specifically used to: respond to a business call request for an application, start a transaction manager, and the transaction manager obtains a log database interface through a log database data source and initializes the log database interface.

[0154] In some embodiments, the log database interface is constructed in the following manner:

[0155] Obtain two database connections through the basic data source. One of the two database connections is used for business operations, and the other is used for log operations.

[0156] Set the initial connection identifier of the transaction operation to the business connection.

[0157] The business processing device provided in the embodiment of the present application can be used to execute the technical solution of the business processing method in the above embodiment. Its implementation principle and technical effect are similar and will not be repeated here.

[0158] 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, they can be fully or partially 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 processing module 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 implementation of other modules is similar. In addition, these modules can be fully or partially 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.

[0159] For example, the above modules can be one or more integrated circuits configured to implement the above methods, such as: one or more specific integrated circuits (Application Specific Integrated Circuit, referred to as ASIC), or, one or more microprocessors (Digital Signal Processor, referred to as DSP), or, one or more field programmable gate arrays (Field Programmable Gate Array, referred to as FPGA), etc. For another example, when a certain module above is implemented in the form of a processing element to allocate program code, the processing element can be a general-purpose processor, such as a central processing unit (Central Processing Unit, referred to as CPU) or other processors that can call program code. For another example, these modules can be integrated together and implemented in the form of a system-on-a-chip (System-On-a-Chip, referred to as SOC). The server provided in the embodiment of the present application can be the terminal device of the above embodiment.

[0160] Figure 8 This is a schematic diagram of the structure of a server provided in an embodiment of the present application. This embodiment of the present application provides a server, which is deployed with Spring AOP. Figure 8 As shown, the server 800 provided in the embodiment of the present application includes: a processor 801, and a memory 802 connected to the processor in communication, wherein:

[0161] Memory stores computer-executable instructions;

[0162] The processor executes the computer-executable instructions stored in the memory to implement the method described in the foregoing method embodiment.

[0163] It should be understood that the processor 801 can be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSP), application-specific integrated circuits (ASIC), etc. The general-purpose processor can be a microprocessor or the processor can be any conventional processor, etc. The steps of the method disclosed in the application can be directly embodied as being executed by a hardware processor, or executed by a combination of hardware and software modules in the processor. The memory 802 may include a high-speed random access memory (RAM), and may also include non-volatile storage NVM (non-volatile memory), such as at least one disk storage, and can also be a USB flash drive, a mobile hard disk, a read-only memory, a disk or an optical disk, etc.

[0164] Optionally, the server 800 may further include a communication interface 803. In a specific implementation, if the communication interface 803, the memory 802, and the processor 801 are implemented independently, the communication interface 803, the memory 802, and the processor 801 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.

[0165] Optionally, in a specific implementation, if the communication interface 803, the memory 802 and the processor 801 are integrated on a chip, the communication interface 803, the memory 802 and the processor 801 can communicate through an internal interface.

[0166] An 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, they are used to implement the method described in any of the aforementioned embodiments.

[0167] It is understood that the 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 computer.

[0168] An exemplary computer-readable storage medium is coupled to a processor so that the processor can read information from the computer-readable storage medium and write information to the computer-readable storage medium. Of course, the computer-readable storage medium can also be an integral part of the processor. The processor and the computer-readable storage medium can be located in an ASIC. Of course, the processor and the computer-readable storage medium can also exist in a server as discrete components.

[0169] 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 computer-readable storage medium, including a number of instructions for enabling a server (which can be a personal computer, server, or network device, etc.) or a processor to perform some steps of the method described in each embodiment of the present application.

[0170] An embodiment of the present application also provides a computer program product, including a computer program, which implements the method described in any of the above embodiments when executed.

[0171] It should be noted that, for the aforementioned method embodiments, for the sake of simplicity, they are all expressed as a series of action combinations, but those skilled in the art should be aware that the present application is not limited by the described order of actions, because according to the present application, certain steps can be performed in other orders or simultaneously. Secondly, those skilled in the art should also be aware that the embodiments described in the specification are all optional embodiments, and the actions and modules involved are not necessarily required by the present application.

[0172] It should be further noted that, although the various steps in the flowchart are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless there is a clear description in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowchart may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a portion of the sub-steps or stages of other steps.

[0173] In the above embodiments, the description of each embodiment has its own emphasis. For parts not described in detail in a certain embodiment, please refer to the relevant description of other embodiments. The technical features of the above embodiments can be combined arbitrarily. In order to make the description concise, all possible combinations of the technical features in the above embodiments are not described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.

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

[0175] 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. A business processing method, characterized in that: Applied to a server deployed with Spring AOP, the business processing method includes: During the application execution process, if the log mark annotation is intercepted, the connection identifier of the transaction operation is changed to a log connection, and a log type operation for the log database is initiated; After the operation log record is completed, the connection identifier of the transaction operation is changed to a business connection, and a business type operation for the business database is initiated.

2. The service processing method according to claim 1, characterized in that: The connection identifier of the change transaction operation is a log connection, including: Performing a static injection log operation in a log database key holder, the log database key holder adding an integer key flag in a thread private cache attribute, the static injection log operation being used to perform an increment operation on the integer key flag; Correspondingly, the initiating log type operation for the log database includes: calling the log database interface to perform the log type operation for the log database, the log database interface is used to detect the value of the integer key flag in the log database key holder, if the value indicates that the log database key holder is in a log activation state, using the log connection to initiate the log type operation for the log database.

3. The service processing method according to claim 2, characterized in that: The connection identifier of the change transaction operation is a business connection, including: Execute a subtraction operation on the integer key flag in the log database key holder; Correspondingly, the initiating business type operation for the business database includes: calling the log database interface to perform the business type operation for the business database, the log database interface is also used to detect the value of the integer key flag in the log database key holder, if the value indicates that the log database key holder is not in a log activation state, using the business connection to initiate the business type operation for the business database.

4. The service processing method according to claim 3, characterized in that: Also includes: After all business type operations corresponding to the current business call request are completed, the log database interface is called to perform submission operations on the business connection and log connection respectively; Alternatively, when an exception occurs, the log database interface is called to perform a rollback operation on the business connection.

5. The service processing method according to claim 4, characterized in that: Also includes: After the commit operation and / or rollback operation is completed, the closing method and attribute configuration restoration method of the log database interface are called. The closing method is used to close the business connection and the log connection, and the attribute configuration restoration method is used to restore the business connection configuration and the log connection configuration to recycle system resources.

6. The service processing method according to any one of claims 2 to 5, characterized in that: Also includes: In response to a service call request for the application, a transaction manager is started, the transaction manager obtains the log database interface through a log database data source and performs initialization configuration on the log database interface.

7. The service processing method according to any one of claims 2 to 5, characterized in that: The log database interface is constructed in the following way: Obtain two database connections through a basic data source, wherein one database connection is used for business type operations, and the other database connection is used for log type operations; Set the initial connection identifier of the transaction operation to the business connection.

8. A service processing device, characterized in that: Applied to a server deployed with Spring AOP, the business processing device includes: A log type operation module, used to change the connection identifier of the transaction operation to a log connection if a log mark annotation is intercepted during the application execution process, and initiate a log type operation for the log database; The business type operation module is used to change the connection identifier of the transaction operation to a business connection after the operation log record is completed, and initiate a business type operation for the business database.

9. A server, characterized in that: The server is deployed with Spring AOP, and the server includes: a processor, and a memory connected to the processor in communication; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory to implement the method according to any one of claims 1 to 7.

10. 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 7 when executed.

11. A computer program product, characterized in that The invention comprises a computer program, which implements the method according to any one of claims 1 to 7 when being executed.

Citation Information

Patent Citations

  • Multi-source data processing method and terminal equipment

    CN110262854A

  • Database connection switching method and device, equipment and medium

    CN112000738A

  • Service call chain implementation method based on self-research framework

    CN112559212A

  • Business log collection and management method and system for realizing reuse and decoupling in cross-platform multi-service architecture mode

    CN114968720A

  • Database log recording method and device, computer equipment and computer readable storage medium

    CN116561146A