Transaction-based Data Resource Management Method, Device, Medium, and Electronic Device
Through dynamic proxy technology, a multi-level proxy chain and transaction object management is generated, which solves the application's data resource management automation problem for non-database systems, realizes the consistency and reliability of cross-system data resource operations, and reduces operation and maintenance costs.
Patent Information
- Application Number
- CN202510578827.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-07
- Publication Date
- 2025-07-29
- Estimated Expiration
- 2045-05-07
AI Technical Summary
In the prior art, applications lack an automated mechanism for data resource management of systems other than databases such as file systems and cache systems, which requires manual intervention when abnormalities are caused, which can easily lead to junk data accumulation and resource waste.
Dynamic proxy technology is used to generate multi-level proxy chains, intercept interface method calls through transaction proxy objects, create root transaction objects and sub-transaction objects, determine transaction execution process, and manage data resources through change revocation operations in case of exceptions.
It improves the degree of automation of data resource management, ensures consistency of cross-system data resource operations, reduces manual intervention, reduces operation and maintenance costs, and avoids spam data accumulation and resource waste.
Smart Images

Figure CN120085970B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of data resource management, and in particular, to a transaction-based data resource management method, apparatus, medium, and electronic device. Background Art
[0002] In application development, in addition to performing data resource operations on a database, an application may also perform data resource operations on other systems such as a file system and a cache system.
[0003] The database has a transaction mechanism. When an error occurs in the application, the database supports transaction rollback to manage data resources. Other systems need to manually manage data resources by themselves. Once mismanaged, a large amount of application garbage will appear. Summary of the Invention
[0004] The present application provides a transaction-based data resource management method, apparatus, medium, and electronic device, which can achieve the purpose of improving the automation degree of data resource management.
[0005] According to a first aspect of the present application, there is provided a transaction-based data resource management method, the method comprising:
[0006] In response to detecting that the application has started up successfully, generating a multi-level proxy chain for a data source instance object associated with the application through dynamic proxy; wherein, the multi-level proxy chain includes at least a transaction proxy object; the data source instance object includes at least one of a file system and a data resource in memory in addition to the database;
[0007] If it is detected that a service class marked with a transaction annotation in the application is called, intercepting a data change operation in the service class through the transaction proxy object and obtaining transaction data of the application in the current thread;
[0008] If it is determined based on the transaction data that no transaction has been started in the current thread of the application, creating a root transaction object for the current thread, and determining a transaction execution process of the current thread based on the root transaction object and a sub-transaction object associated with the current thread; wherein, at least two data change operations and change cancellation operations opposite to the data change operations are associated with the transaction object in the transaction execution process;
[0009] If it is detected that an exception occurs during the transaction execution, managing the data resources based on the transaction execution process and the change cancellation operation associated with the transaction object.
[0010] According to a second aspect of the present application, there is provided a transaction-based data resource management apparatus, the apparatus comprising:
[0011] A multi-level proxy chain generation module, which is used to dynamically generate a multi-level proxy chain for the data source instance object associated with the application in response to detecting that the application startup is completed; wherein, the multi-level proxy chain at least includes a transaction proxy object; the data source instance object includes at least one of a file system and in-memory data resources in addition to the database;
[0012] A transaction data acquisition module, which is used to intercept the data change operations in the service class through the transaction proxy object and acquire the transaction data of the application in the current thread if it is detected that a service class marked with a transaction annotation in the application is called;
[0013] A transaction execution process determination module, which is used to create a root transaction object for the current thread and determine the transaction execution process of the current thread based on the root transaction object and the sub-transaction objects associated with the current thread if it is determined based on the transaction data that no transaction has been opened in the current thread of the application; wherein, at least two data change operations and change cancellation operations opposite to the data change operations are associated with the transaction objects in the transaction execution process;
[0014] A data resource management module, which is used to manage the data resources based on the transaction execution process and the change cancellation operations associated with the transaction objects if an exception occurs during the transaction execution.
[0015] According to the third aspect of the present invention, an embodiment of the present application provides a computer-readable storage medium, on which a computer program is stored, and when the program is executed by a processor, it implements the transaction-based data resource management method as described in the embodiment of the present application.
[0016] According to the fourth aspect of the present invention, an embodiment of the present application provides an electronic device, which includes a memory, a processor, and a computer program stored on the memory and executable on the processor. When the processor executes the computer program, it implements the transaction-based data resource management method as described in the embodiment of the present application.
[0017] According to the fifth aspect of the present application, an embodiment of the present application provides a computer program product, which includes a computer program, and when the computer program is executed by a processor, it implements the transaction-based data resource management method as described in the embodiment of the present application.
[0018] In the technical solution of the embodiment of the present application, the dynamic proxy technology is used to dynamically proxy the data source instance object associated with the application program to generate a multi-level proxy chain. The transaction proxy object in the multi-level proxy chain intercepts the invocation of the interface method, adds additional logic before and after the interface method invocation. When the service class marked with the transaction annotation in the application program is called and the application program has not started a transaction in the current thread, the transaction execution process of the current thread is determined. The transaction object in the transaction execution process is associated with at least two data change operations and change cancellation operations corresponding to the data change operations. When an exception occurs during the transaction execution, the data resources are managed based on the transaction execution process and the change cancellation operations associated with the transaction object. In this way, the limitation that the transaction annotation is only applicable to data resource management of the database can be broken, and the transaction annotation can be extended to data resource management of other systems such as the file system and the memory system. By doing so, when an exception occurs during the transaction execution, the changes made to the data resources of other systems except the database can be restored, without manual data resource management of other systems except the database, effectively improving the automation degree of data resource management, effectively managing the consistency of cross-system data resource operations, significantly enhancing the overall reliability of the system, and avoiding the accumulation of garbage data and resource waste caused by abnormal transaction execution. It can reduce manual intervention, lower operation and maintenance costs, and improve the utilization rate of storage and computing resources at the same time.
[0019] It should be understood that the content described in this part is not intended to identify the key or important features of the embodiments of the present application, nor is it used to limit the scope of the present application. Other features of the present application will become easily understood through the following description. Brief Description of the Drawings
[0020] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the following will briefly introduce the drawings required for the description of the embodiments. Obviously, the following drawings are only some embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained based on these drawings without creative efforts.
[0021] Figure 1 is a flowchart of a transaction-based data resource management method provided according to Embodiment 1;
[0022] Figure 2 is a flowchart of a transaction-based data resource management method provided according to Embodiment 2;
[0023] Figure 3 is a flowchart of a transaction-based data resource management method provided according to the embodiment of the present application;
[0024] Figure 4It is a schematic structural diagram of a transaction-based data resource management device provided in Embodiment 3 of the present application;
[0025] Figure 5 It is a schematic structural diagram of an electronic device provided in Embodiment 4 of the present application. Detailed implementation manners
[0026] To enable those skilled in the art to better understand the solution of the present application, the technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts shall fall within the protection scope of the present application.
[0027] It should be noted that the terms "first", "second", "target", and "candidate" in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily need to be used to describe a specific order or sequence. It should be understood that the data used in this way can be interchanged under appropriate circumstances so that the embodiments of the present application described here can be implemented in an order different from those illustrated or described here. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product, or device that includes a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products, or devices.
[0028] Embodiment 1
[0029] Figure 1 It is a flowchart of a transaction-based data resource management method provided according to Embodiment 1. This embodiment is applicable to the situation where an application program operates on data resources stored in other systems in addition to a database when developing an application program using a program development framework such as the Spring architecture. This method can be executed by a transaction-based data resource management device, which is implemented in the form of hardware and / or software and can be integrated into an electronic device running this system.
[0030] As Figure 1 shown, the method includes:
[0031] S110. In response to detecting that the application program has started successfully, generate a multi-level proxy chain for the data source instance object associated with the application program; wherein, the multi-level proxy chain includes at least a transaction proxy object; the data source instance object includes at least one of a file system and memory in addition to the database.
[0032] S120. If it is detected that a service class marked with a transaction annotation in the application program is called, intercept the data change operations in the service class through the transaction proxy object and obtain the transaction data of the application program in the current thread.
[0033] S130. If it is determined based on the transaction data that no transaction has been started in the current thread of the application program, create a root transaction object for the current thread, and determine the transaction execution process of the current thread based on the root transaction object and the sub-transaction objects associated with the current thread; wherein, at least two data change operations and change cancellation operations corresponding to the data change operations are associated with the transaction objects in the transaction execution process.
[0034] S140. If an exception occurs during the transaction execution, manage the data resources based on the transaction execution process and the change cancellation operations associated with the transaction objects.
[0035] The data source instance object (DataSource) is created by a dependency management container such as a Spring container according to the configuration file of the application program when the application program starts. Optionally, the data source instance object is stored in the instance singleton pool of the dependency management container. Among them, the instance singleton pool is a design pattern used to ensure that there is only one instance of the pooled resource throughout the application program. Among them, the application program not only operates on the data resources of the database but also operates on the data resources of other systems such as the file system and the memory system.
[0036] The data source instance object is a standardized connection hub between the application program and various data storage systems (such as databases, file systems, and memory storage, etc.), and realizes secure and efficient resource management and data access through a unified interface. The data source instance object is used to provide a connection for the application program to operate on the data resources.
[0037] Since transaction annotations such as @Transactional are mainly used for managing data resources in relational databases and cannot manage the data resources stored in other systems such as memory systems and file systems, etc. Therefore, dynamic proxy technology is used to dynamically proxy the data source instance object. When a service class marked with a transaction annotation in the application program is called, the dependency management container will automatically intercept the data change operations in the service class and call the data source instance object in the dependency management container to obtain a connection for operating on the data resources. Since the data source instance object is dynamically proxied, that is, the interface methods associated with the data source instance object are proxied, when the Spring framework obtains a connection for operating on the data resources, a multi-level proxy chain needs to be constructed.
[0038] When the interface method is called, the request will sequentially pass through each layer of the multi-level proxy chain. Each layer of the proxy can add additional logic before and after the interface method is called. Optionally, in addition to the transaction proxy object, the multi-level proxy chain also includes a connection proxy object, an SQL executor proxy object, and a result proxy object. That is to say, any layer of the proxy among the transaction proxy object, the connection proxy object, the SQL executor proxy object, and the result proxy object can add additional logic before and after the interface method is called.
[0039] If it is detected that a service class marked with a transaction annotation in the application is called, the dependency management container calls the transaction proxy object to intercept the data change operations in the service class and obtain the transaction data of the current thread. Among them, the application corresponds to at least two threads. Optionally, transaction data management is performed on a per-thread basis. The transaction data is used to determine whether a transaction has been started for the current thread. If the transaction data is empty, it can be determined that no transaction has been started for the current thread.
[0040] In the case where no transaction has been started for the current thread, a root transaction object is created for the current thread, and the transaction execution process for the current thread is determined based on the root transaction object and the sub-transaction objects associated with the current thread.
[0041] Among them, the transaction execution process is used to describe the transaction hierarchy relationship between the root transaction object, the sub-transaction objects, and the sub-transaction objects. The transaction execution process includes at least two transaction objects. Each transaction object represents a transaction interaction process, and during the interaction process, there will be multiple interception actions to intercept the data change operations. Based on the intercepted data change operations, the change cancellation operations corresponding to the data change operations are determined. Optionally, the data change operations and the change cancellation operations are associated with the transaction objects according to the operation execution order. Optionally, the data change operations include any one of data addition, data deletion, and data modification. The change cancellation operation is opposite to the data change operation and is used to cancel the changes made to the data resources by the data change operation. Exemplarily, if the data change operation is to modify data A to data B, then the change cancellation operation is to cancel the changes made to data A by the data change operation and restore data B to data A.
[0042] Associate the data change operations and the change cancellation operations opposite to the data change operations with the transaction objects in the transaction execution process.
[0043] If it is detected that an exception occurs during the transaction execution, manage the data resources based on the transaction hierarchy relationship described by the transaction execution process and the operation execution order of the data change operations in the transaction objects.
[0044] Among them, the change cancellation operation is used to cancel the changes made to the data resources by the data change operation and restore the data resources of other systems except the database.
[0045] In the technical solution of the embodiment of the present application, the dynamic proxy technology is used to dynamically proxy the data source instance object associated with the application program to generate a multi-level proxy chain. The transaction proxy object in the multi-level proxy chain intercepts the invocation of the interface method, adds additional logic before and after the interface method is invoked. When the service class marked with the transaction annotation in the application program is called, and the application program has not started a transaction in the current thread, the transaction execution process of the current thread is determined. The transaction object in the transaction execution process is associated with at least two data change operations and change cancellation operations corresponding to the data change operations. When it is detected that an exception occurs during the transaction execution process, the data resources are managed based on the transaction execution process and the change cancellation operations associated with the transaction object. In this way, the limitation that the transaction annotation is only applicable to data resource management of the database can be broken, and the transaction annotation can be extended to data resource management of other systems such as the file system and the memory system. By doing so, when it is detected that an exception occurs during the transaction execution process, the changes made to the data resources of other systems except the database can be restored, without the need for manual data resource management of other systems except the database, effectively improving the automation degree of data resource management, effectively managing the consistency of cross-system data resource operations, significantly enhancing the overall reliability of the system, and avoiding the accumulation of garbage data and resource waste caused by abnormal transaction execution. It can reduce manual intervention, reduce operation and maintenance costs, and at the same time improve the utilization rate of storage and computing resources.
[0046] In an optional embodiment, in response to detecting that the application program has started up successfully, dynamically proxying the data source instance object associated with the application program to generate a multi-level proxy chain includes: in response to detecting that the application program has started up successfully, constructing a data source proxy object; if the data source instance object exists in the dependency management container, inserting the data source proxy object on the access path of the dependency management container to dynamically proxy the data source instance object; intercepting the target interface method associated with the data source instance object through the data source proxy object, and constructing a multi-level proxy chain including at least the transaction proxy object.
[0047] Among them, the data source proxy object is virtual, the data source proxy object is created after the application program has started up successfully, the data source proxy object is used to proxy the data source instance object, the data source instance object is real, and the data source instance object is created when the application program starts up. That is to say, the data source proxy object is created after the data source instance object.
[0048] The data source instance object is generated by the dependency management container based on the application's configuration file and stored in the singleton instance pool of the dependency management container. The existence of the data source instance object in the dependency management container indicates that the application needs to process data resources. A data source proxy object is inserted on the access path of the dependency management container, and the reference representing the data source instance object is replaced with a reference to the data source proxy object. At the same time, a reference to the data source instance object is retained in the proxy logic of the data source proxy object so that when the proxy method is called, the request can be forwarded to the data source instance object to achieve dynamic proxy of the data source instance object.
[0049] Using the data source proxy object to perform dynamic proxy on the data source instance object is to proxy the target interface methods associated with the data source instance object. Among them, the target interface methods can be all interface methods associated with the data element instance object. When the Spring framework obtains a connection for operating on data resources, a multi-level proxy chain needs to be constructed.
[0050] The above technical solution uses dynamic proxy technology to perform dynamic proxy on the data source instance object and generates a multi-level proxy chain. To intercept the invocation of interface methods through the transaction proxy object in the multi-level proxy chain and add additional logic before and after the interface method invocation, it provides technical support for breaking the limitation that transaction annotations are only applicable to data resource management of databases and extending transaction annotations to data resource management of other systems such as file systems and memory systems.
[0051] In an optional embodiment, before intercepting the invocation of the data change operation in the service class through the transaction proxy object, the method includes: obtaining the object metadata of the application from the metadata container; wherein, the object metadata is used to describe the component objects in the application; based on the component name of the object metadata, determining the component type to which the component object belongs; if the component type is a database template, then performing data tracing on the component object to intercept the data processing operation of the database; if the component type is a data access object, then determining the data resource framework called by the component object; in the case where the data resource framework is associated with a data change operation, performing data tracing on the component object to intercept the data change operation of the data resource framework.
[0052] Among them, object metadata is used to describe component objects in an application. A component object is a part of the application and is an object managed by a dependency management container, which is called a Bean in software development frameworks such as Spring. The dependency management container is used to manage the creation, configuration, lifecycle, and dependencies of component objects in the application. When the initialization of the dependency management container is completed, the object metadata of the application is obtained from the metadata container of the dependency management container. Optionally, the object metadata includes component name, scope, lifecycle callbacks, and dependencies, etc. The type keyword included in the component name can be used to determine the component type to which the component object belongs. Optionally, the component type includes database templates and data access objects (DAOs, Data Access Objects).
[0053] Among them, the database template is used to provide predefined database table structures, fields, and constraint rules, has a standardized data structure, and belongs to the database design layer. The data access object is the implementation layer of the data access logic, encapsulates the operations of adding, deleting, modifying, and querying the database, and belongs to the code implementation layer.
[0054] In the case where the component type is a database template, the component object is instrumented, and method call interception is added to the component object. Optionally, the interception is performed before the method execution, after the method execution, and after the process ends.
[0055] In the case where the component type is a data access object, the data resource framework called by the component object is determined. Exemplarily, the data resource framework can be jpa and mybatis. Whether the data resource framework is associated with data change operations needs to identify the program code content corresponding to the component object to identify whether the code contains resource connection actions and resource closing actions, and whether there are calls to data change operations on the data resource.
[0056] In the case where the data resource framework is associated with data change operations, the component object is instrumented, and the data change operations of the data resource framework are intercepted. If the data resource framework is only associated with data query operations, the component object is not instrumented.
[0057] The above technical solution provides a technical solution that can be used to identify data change operations on data resources, can intercept data change operations on data resources, and provides technical support and data support for determining the transaction execution process based on the intercepted data change operations in the future.
[0058] In an optional embodiment, the method further includes: if the component name includes a first keyword, adding the object metadata of the component object to the database template container; if the component name includes a second keyword, adding the object metadata of the component object to the data access object container; if the data processing operation called by the component object includes a data change operation, determining that the component object is a valid component, and deleting the object metadata of other component objects except the valid component in the data access object container; respectively performing data point embedding on the component objects in the database template container and the data access object container.
[0059] Wherein, both the first keyword and the second keyword are type keywords in the component name. The type keyword can be used to determine the component type to which the component object belongs. Optionally, the component types include: database template and data access object. Optionally, the first keyword is "Template" and the second keyword is "DAO". The database template container can be referred to as the DBBDR container, which is used to store the object metadata of the database template, and the data access object container can be referred to as the DAO container, which is used to store the object metadata of the data access object.
[0060] The component name including the first keyword indicates that the component object is a database template, and the object metadata of the component object is added to the database template container. The component name including the second keyword indicates that the component object is a data access object, and the object metadata of the component object is added to the data access object container.
[0061] Not all component objects in the data access object container are associated with data change operations, and there are also component objects that are only associated with data change operations. If the data processing operation called by the component object includes a data change operation, it is determined that the component object is a valid component. Among them, the object metadata of the valid component needs to be saved in the data access object container. Delete the object metadata of other component objects except the valid component in the data access object container, where the other component objects can be component objects that are only associated with data query operations. This can ensure that only the object metadata of the valid components is included in the data access object container. In the data access object container, it can be stored according to the dimension of the data resource framework, and the data resource framework is stored together with its associated data change operations. Perform data point embedding on the component objects in the database template container and the data access object container.
[0062] Through the above technical solution, by constructing a data access object container and a database template container, the component objects are managed according to the component type and the data operation type, realizing the identification of data change operations on data resources.
[0063] Embodiment 2
[0064] Figure 2 It is a flowchart of a transaction-based data resource management method provided according to Embodiment 2. This embodiment is further optimized based on the above embodiments.
[0065] As Figure 2 shown, the method includes:
[0066] S210. In response to detecting that the application startup is completed, dynamically generate a multi-level proxy chain for the data source instance object associated with the application; wherein, the multi-level proxy chain at least includes a transaction proxy object; the data source instance object includes at least one of a file system and in-memory data resources in addition to the database.
[0067] S220. If it is detected that a service class marked with a transaction annotation in the application is called, intercept the data change operation in the service class through the transaction proxy object and obtain the transaction data of the application in the current thread.
[0068] S230. If it is determined based on the transaction data that no transaction has been started in the current thread of the application, create a root transaction object for the current thread.
[0069] S240. Create a transaction chain starting from the root transaction object.
[0070] Among them, the transaction chain is determined based on the transaction hierarchy relationship and is used to determine the transaction execution process of the current process. Optionally, the transaction chain includes at least two transaction objects. The root transaction object is the starting point of the transaction chain.
[0071] S250. Obtain the sub-transaction object associated with the current thread and determine the data change operation intercepted in the sub-transaction object.
[0072] The sub-transaction object associated with the current process belongs to the transaction objects in the transaction chain. Each transaction object represents a transaction interaction process, and during the interaction process, there will be multiple interception actions to intercept the data change operation.
[0073] S260. Based on the method name and related parameters corresponding to the data change operation, determine the change cancellation operation corresponding to the data change operation.
[0074] Among them, the change cancellation operation is opposite to the data change operation and is used to cancel the changes made to the data resources by the data change operation. The method name is used to determine the correspondence between the data change operation and the change cancellation operation.
[0075] The related parameters are used for the change cancellation operation to cancel the changes made to the data resources by the data change operation.
[0076] S270. Associate the data change operation and the change cancellation operation with the sub-transaction object according to the operation execution order.
[0077] Among them, the operation execution order is the execution order of the data change operation. Optionally, generate a forward operation sequence for the data change operation according to the execution order. The execution order of the change cancellation operation is determined based on the execution order of the data change operation. Optionally, generate a reverse operation sequence for the change cancellation operation according to the execution order.
[0078] Optionally, add the forward operation sequence and the reverse operation sequence to a transaction operation container, and associate the transaction operation container with the sub-transaction object, so as to associate the data change operation and the change cancellation operation with the sub-transaction object according to the operation execution order.
[0079] S280. Insert the sub-transaction object into the end of the transaction chain in turn based on the transaction hierarchy relationship.
[0080] Among them, the transaction hierarchy relationship is used to constrain the transaction execution order, and the sub-transaction object is inserted into the end of the transaction chain in turn according to the transaction execution order.
[0081] S290. Determine the transaction execution process of the current thread based on the transaction chain.
[0082] The transaction objects are added to the transaction chain in turn according to the transaction hierarchy relationship. Based on the transaction chain, the transaction execution order of the current thread can be determined. The transaction execution process is used to describe the transaction execution order of the current thread.
[0083] S295. If an exception occurs during the transaction execution, manage the data resources based on the transaction execution process and the change cancellation operation associated with the transaction object.
[0084] When an exception occurs during the transaction execution, open the transaction objects in turn according to the transaction execution order described by the transaction execution process, and manage the data resources using the change cancellation operation associated with the transaction object. Optionally, restore the changes made to the data resources by the data change operation using the change cancellation operation.
[0085] The technical solution of the embodiment of the present application creates a transaction chain starting from the root transaction object, obtains the sub-transaction object associated with the current thread, and determines the data change operations intercepted in the sub-transaction object. Based on the method name and related parameters corresponding to the data change operations, the change cancellation operations opposite to the data change operations are determined. The data change operations and the change cancellation operations are associated with the sub-transaction object according to the operation execution order. Based on the transaction hierarchy relationship, the sub-transaction objects are sequentially inserted at the end of the transaction chain. Based on the transaction chain, the transaction execution process of the current thread is determined. A practical transaction execution process determination solution is provided, which provides technical support and data support for managing data resources based on the transaction execution process and the change cancellation operations associated with the transaction objects in the case of detecting an exception during the transaction execution process, effectively improving the automation degree of data resource management, effectively managing the consistency of cross-system data resource operations, and avoiding the accumulation of garbage data and resource waste caused by abnormal transaction execution.
[0086] In an alternative embodiment, after determining the transaction execution process of the current thread, the method further includes: in response to detecting a transaction closing operation for the transaction object in the transaction chain, deleting the transaction chain of the current thread.
[0087] Among them, the transaction closing operation refers to the final step of completing the transaction life cycle and ensuring data consistency. Detecting a transaction closing operation for the transaction object in the transaction chain indicates that the transaction object of the current thread has completed the transaction life cycle, and the transaction chain of the current thread is deleted.
[0088] The above technical solution provides a practical transaction chain management solution, ensuring the accuracy and effectiveness of the transaction execution process, and providing data support for managing data resources based on the transaction execution process in the subsequent case of an exception during the transaction execution process.
[0089] In an alternative embodiment, if an exception is detected during the transaction execution process, managing the data resources based on the transaction execution process and the change cancellation operations associated with the transaction object includes: if an exception is detected during the transaction execution process, determining the target transaction object to be rolled back in the transaction execution process based on the transaction hierarchy relationship; obtaining the change cancellation operations associated with the target transaction object, and calling the change cancellation operations to manage the data resources according to the operation execution order.
[0090] Among them, the target transaction object refers to the transaction object that needs to be rolled back in the transaction chain. The target transaction object represents a transaction interaction process. During the interaction process, there will be multiple interception actions to intercept data change operations. The target transaction object is associated with at least two data change operations and change cancellation operations corresponding to the data change operations. The operation execution order refers to the execution order of the data change operations. Based on the operation execution order, the execution order of the change cancellation operations can be determined, and the change cancellation operations are called based on the execution order of the change cancellation operations to manage the data resources.
[0091] In the above technical solution, in the case of detecting an exception during the transaction execution process, the data resources are managed based on the transaction execution process and the change cancellation operations associated with the transaction object, effectively improving the automation degree of data resource management, effectively managing the consistency of cross-system data resource operations, and avoiding the accumulation of garbage data and resource waste caused by abnormal transaction execution.
[0092] In a specific embodiment, Figure 3 is a flowchart of the data resource management method based on transactions provided by an embodiment of the present application. Figure 3 shows the process of the data resource management method based on transactions in the case of software development using the Spring framework.
[0093] See Figure 3 , the data resource management method based on transactions includes main steps such as dynamically proxying the data source instance object, identifying the data change operations of the data resources, and creating a transaction chain.
[0094] See Figure 3 , dynamically proxying the data source instance object includes: obtaining the data source instance object through the @transactional interceptor, and proxying the data source instance object using the created data source proxy object. The data source instance object is real, and the data source proxy object is virtual. The data source instance object and the data source proxy object respectively correspond to Figure 3 a layer of datasource and a second layer of datasource in. By dynamically proxying the data source instance object, a multi-level proxy chain can be obtained. Figure 3 The connections and transactions in include two parts: real and virtual, where the virtual part respectively represents the connection proxy object and the transaction proxy object in the multi-level proxy chain.
[0095] In the embodiments of the present application, the call of the interface method can be intercepted by the transaction proxy object in the multi-level proxy chain, and additional logic can be added before and after the call of the interface method. Intercept the data change operation in the service class and obtain the transaction data of the application in the current thread. If it is determined based on the transaction data that the application has not started a transaction in the current thread, a root transaction object is created for the current thread. A transaction chain starting from the root transaction object is created. As Figure 3 shown, a transaction chain including 4 transaction objects is created. The encoding of the transaction object is determined based on the transaction hierarchy relationship between the transaction objects. Transaction 1 is the root transaction object, and Transaction 2, Transaction 3, and Transaction 4 are child transaction objects associated with the current thread. Among them, the numbers 1, 2, 3, and 4 are transaction numbers, which are used to determine the transaction hierarchy relationship between the transaction objects and are related to the interception order.
[0096] Each transaction object represents a transaction interaction process. During the interaction process, there will be multiple interception actions to intercept the data change operation. Based on the intercepted data change operation, determine the change cancellation operation corresponding to the data change operation. Generate a forward operation sequence according to the execution order of the data change operation. The execution order of the change cancellation operation is determined based on the execution order of the data change operation. Optionally, generate a reverse operation sequence according to the execution order of the change cancellation operation. Figure 3 Here, "forward" and "reverse" respectively represent the forward operation sequence and the change operation sequence formed by the data change operation. The forward operation sequence and the reverse operation sequence are stored in the transaction operation container of the transaction object. The transaction chain is used to determine the transaction processing flow of the current thread.
[0097] Optionally, the transaction execution flow of the current thread is determined based on the transaction chain placed in the transaction management object, and the transaction life cycle is managed. Detect the transaction action through the transaction management object. If a transaction start operation is detected, create a transaction chain. If a transaction close operation is detected, it means that the transaction object of the current thread has completed the transaction life cycle, and the transaction management object is cleared to delete the transaction chain of the current thread. If an exception occurs during the transaction execution, then based on the transaction chain, determine the transaction execution flow and perform a reverse rollback of the change cancellation operation associated with the transaction object to implement the management of the data resource.
[0098] The forward operation sequence and the reverse operation sequence associated with the transaction object are related to the data change operation intercepted by the RT interceptor. By instrumenting the component objects of the application in the DBBDR container and the DAO container, the data change operation can be intercepted by the RT interceptor. The RT interceptor is used to intercept the calls before and after the method execution. The DBBDR container is used to store the metadata of the database template. The DAO container is used to store the metadata of the data access object, such as the data resource framework and the data change operation associated with the data resource framework. Among them, in Figure 3Among them, the metadata of the bean in the DBBDR container refers to the metadata of the database template. The framework in the DAO container refers to the data resource framework, and the set of operation methods called refers to the data change operations associated with the data resource framework. Whether it is a database template or a data access object can be determined by the type keyword in the component name. The type keyword corresponding to the database template is Template, and the type keyword corresponding to the data access object is DAO.
[0099] Embodiment 3
[0100] Figure 4 It is a schematic structural diagram of a transaction-based data resource management device provided in Embodiment 3 of the present application. This embodiment is applicable to the situation where an application operates on data resources stored in other systems besides the database during application development using a program development framework such as the Spring architecture. The device can be implemented by software and / or hardware and can be integrated into electronic devices such as intelligent terminals.
[0101] As Figure 4 shown, the device may include:
[0102] A multi-level proxy chain generation module 310, configured to, in response to detecting that the application startup is completed, perform dynamic proxy on the data source instance object associated with the application to generate a multi-level proxy chain; wherein, the multi-level proxy chain at least includes a transaction proxy object; the data source instance object includes at least one of a file system and memory in addition to the database;
[0103] A transaction data acquisition module 320, configured to, if it is detected that a service class marked with a transaction annotation in the application is called, intercept the data change operation in the service class through the transaction proxy object and acquire the transaction data of the application in the current thread;
[0104] A transaction execution process determination module 330, configured to, if it is determined based on the transaction data that no transaction has been started in the current thread of the application, create a root transaction object for the current thread, and determine the transaction execution process of the current thread based on the root transaction object and the sub-transaction objects associated with the current thread; wherein, at least two data change operations and change cancellation operations opposite to the data change operations are associated with the transaction objects in the transaction execution process;
[0105] A data resource management module 340, configured to, if an exception occurs during the transaction execution, manage the data resources based on the transaction execution process and the change cancellation operations associated with the transaction objects.
[0106] The technical solution of the embodiment of the present application uses dynamic proxy technology to dynamically proxy the data source instance object associated with the application program to generate a multi-level proxy chain. The transaction proxy object in the multi-level proxy chain intercepts the invocation of the interface method, adds additional logic before and after the interface method invocation. When the service class marked with the transaction annotation in the application program is called, and the application program has not started a transaction in the current thread, the transaction execution process of the current thread is determined. The transaction object in the transaction execution process is associated with at least two data change operations and change cancellation operations corresponding to the data change operations. When an exception occurs during the transaction execution process is detected, the data resources are managed based on the transaction execution process and the change cancellation operations associated with the transaction object. This can break the limitation that the transaction annotation is only applicable to data resource management of the database, and extend the transaction annotation to data resource management of other systems such as the file system and the memory system. By doing so, when an exception occurs during the transaction execution process is detected, the changes made to the data resources of other systems except the database can be restored, without manual data resource management of other systems except the database, effectively improving the automation degree of data resource management, effectively managing the consistency of cross-system data resource operations, significantly enhancing the overall reliability of the system, and avoiding the accumulation of garbage data and resource waste caused by abnormal transaction execution. It can reduce manual intervention, reduce operation and maintenance costs, and improve the utilization rate of storage and computing resources at the same time.
[0107] Optionally, the transaction execution process determination module 330 includes: a transaction chain creation sub-module for creating a transaction chain starting from the root transaction object; a data change operation determination sub-module for obtaining the sub-transaction object associated with the current thread and determining the data change operation intercepted in the sub-transaction object; a change cancellation operation determination sub-module for determining the change cancellation operation corresponding to the data change operation based on the method name and related parameters of the data change operation; an operation association sub-module for associating the data change operation and the change cancellation operation in the operation execution order to the sub-transaction object; a sub-transaction object insertion sub-module for sequentially inserting the sub-transaction object into the end of the transaction chain based on the transaction hierarchy relationship; a transaction execution process determination sub-module for determining the transaction execution process of the current thread based on the transaction chain.
[0108] Optionally, the device is further configured to: after determining the transaction execution process of the current thread, in response to detecting a transaction closing operation for the transaction object in the transaction chain, delete the transaction chain of the current thread.
[0109] Optionally, the data resource management module 340 includes: a target transaction object determination sub-module, configured to, if an exception occurs during transaction execution, determine a target transaction object to be rolled back in the transaction execution process based on the transaction hierarchy relationship; and a data resource management sub-module, configured to obtain a change cancellation operation associated with the target transaction object, and manage the data resources by invoking the change cancellation operation based on the operation execution order.
[0110] Optionally, the multi-level proxy chain generation module 310 includes: a data source proxy object construction sub-module, configured to construct a data source proxy object in response to detecting that the application startup is completed; a dynamic proxy sub-module, configured to, if the data source instance object exists in the dependency management container, insert the data source proxy object on the access path of the dependency management container to perform dynamic proxy on the data source instance object; and a proxy chain construction sub-module, configured to intercept a target interface method associated with the data source instance object through the data source proxy object, and construct a multi-level proxy chain including at least the transaction proxy object.
[0111] Optionally, the apparatus further includes: an object metadata acquisition module, configured to obtain the object metadata of the application from the metadata container before intercepting the call of the data change operation in the service class through the transaction proxy object; wherein the object metadata is used to describe the component objects in the application; a component type determination module, configured to determine the component type to which the component object belongs based on the component name of the object metadata; a processing operation interception module, configured to, if the component type is a database template, perform instrumentation on the component object to intercept the data processing operation of the database; a resource framework determination module, configured to, if the component type is a data access object, determine the data resource framework called by the component object; and a change operation interception module, configured to, if a data change operation is associated with the data resource framework, perform instrumentation on the component object to intercept the data change operation of the data resource framework.
[0112] Optionally, the apparatus further includes: a database template writing module, configured to, if the component name includes a first keyword, add the object metadata of the component object to the database template container; a data access object writing module, configured to, if the component name includes a second keyword, add the object metadata of the component object to the data access object container; a valid component determination module, configured to, if the data processing operation called by the component object includes a data change operation, determine that the component object is a valid component, and delete the object metadata of other component objects except the valid component in the data access object container; and a component object instrumentation module, configured to perform instrumentation on the component objects in the database template container and the data access object container respectively.
[0113] The data resource management device based on transactions provided by the invention embodiment can execute the data resource management method based on transactions provided by any embodiment of the present application, and has the corresponding performance modules and beneficial effects for executing the data resource management method based on transactions.
[0114] Embodiment 4
[0115] According to the embodiments of the present application, the present application also provides an electronic device, a readable storage medium, and a computer program product.
[0116] Figure 5 FIG. shows a schematic structural diagram of an electronic device 410 that can be used to implement the embodiments. The electronic device 410 includes at least one processor 411, and a memory communicatively connected to at least one processor 411, such as a read-only memory (ROM) 412, a random access memory (RAM) 413, etc. Among them, the memory stores a computer program executable by at least one processor. The processor 411 can execute various appropriate actions and processes according to the computer program stored in the read-only memory (ROM) 412 or the computer program loaded from the storage unit 418 into the random access memory (RAM) 413. In the RAM 413, various programs and data required for the operation of the electronic device 410 can also be stored. The processor 411, the ROM 412, and the RAM 413 are connected to each other through a bus 414. The input / output (I / O) interface 415 is also connected to the bus 414.
[0117] Multiple components in the electronic device 410 are connected to the I / O interface 415, including: an input unit 416, such as a keyboard, a mouse, etc.; an output unit 417, such as various types of displays, speakers, etc.; a storage unit 418, such as a disk, an optical disc, etc.; and a communication unit 419, such as a network card, a modem, a wireless communication transceiver, etc. The communication unit 419 allows the electronic device 410 to exchange information / data with other devices through a computer network such as the Internet and / or various telecommunication networks.
[0118] The processor 411 can be various general-purpose and / or dedicated processing components with processing and computing capabilities. Some examples of the processor 411 include, but are not limited to, a central processing unit (CPU), a graphics processing unit (GPU), various dedicated artificial intelligence (AI) computing chips, various processors running machine learning model algorithms, a digital signal processor (DSP), and any appropriate processor, controller, microcontroller, etc. The processor 411 executes the various methods and processes described above, such as the data resource management method based on transactions.
[0119] In some embodiments, the transaction-based data resource management method may be implemented as a computer program tangibly embodied in a computer-readable storage medium, such as storage unit 418. In some embodiments, part or all of the computer program may be loaded and / or installed onto the electronic device 410 via the ROM 412 and / or the communication unit 419. When the computer program is loaded into the RAM 413 and executed by the processor 411, one or more steps of the transaction-based data resource management method described above may be performed. Alternatively, in other embodiments, the processor 411 may be configured to execute the transaction-based data resource management method by any other suitable means (e.g., by means of firmware).
[0120] The various embodiments of the systems and techniques described above in this document may be implemented in digital electronic circuitry, integrated circuit systems, field programmable gate arrays (FPGA), application specific integrated circuits (ASIC), application specific standard products (ASSP), systems on a chip (SOC), complex programmable logic devices (CPLD), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include: being implemented in one or more computer programs executable and / or interpretable on a programmable system including at least one programmable processor, which may be a dedicated or general-purpose programmable processor that receives data and instructions from a storage system, at least one input device, and at least one output device, and transmits the data and instructions to the storage system, the at least one input device, and the at least one output device.
[0121] The computer programs for implementing the methods of the present application may be written in any combination of one or more programming languages. These computer programs may be provided to a processor of a general-purpose computer, a special-purpose computer, or other programmable transaction-based data resource management device, such that when the computer programs are executed by the processor, the functions / operations specified in the flowchart and / or block diagram are implemented. The computer programs may be executed entirely on the machine, partially on the machine, as a stand-alone software package partially on the machine and partially on a remote machine, or entirely on a remote machine or server.
[0122] In the context of this application, a computer-readable storage medium can be a tangible medium that can contain or store a computer program for use by or in connection with an instruction execution system, apparatus, or device. The computer-readable storage medium can include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. Alternatively, the computer-readable storage medium can be a machine-readable signal medium. More specific examples of the machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or Flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0123] To provide for interaction with a user, the systems and techniques described herein can be implemented on an electronic device having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and a pointing device (e.g., a mouse or a trackball) by which the user can provide input to the electronic device. Other kinds of devices can also be used to provide for interaction with the user; for example, feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic, speech, or tactile input).
[0124] The systems and techniques described herein can be implemented in a computing system that includes backend components (e.g., as a transaction-based data resource management server), or a computing system that includes middleware components (e.g., an application server), or a computing system that includes frontend components (e.g., a user computer having a graphical user interface or a web browser through which the user can interact with an implementation of the systems and techniques described herein), or a computing system that includes any combination of such backend components, middleware components, or frontend components. The components of the system can be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), a blockchain network, and the Internet.
[0125] A computing system may include a client and a server. The client and the server are generally far from each other and usually interact via a communication network. The relationship between the client and the server is created by computer programs running on respective computers and having a client-server relationship with each other. The server may be a cloud server, also known as a cloud computing server or a cloud host, which is a host product in the cloud computing service system, solving the defects of difficult management and weak business scalability existing in traditional physical hosts and VPS services.
[0126] The embodiments of the present application also disclose a computer program product, which includes a computer program that, when executed by a processor, implements the method for managing data resources based on transactions provided in any embodiment of the present application. This program product and the method for managing data resources based on transactions disclosed in the embodiments of the present application belong to the same inventive concept, and thus will not be elaborated herein.
[0127] It should be understood that various forms of the processes shown above can be used, with steps reordered, added, or deleted. For example, the steps described in the present application can be executed in parallel, sequentially, or in a different order, as long as the desired results of the technical solution of the present application can be achieved, and no limitations are imposed herein.
[0128] The above specific embodiments do not constitute a limitation to the protection scope of the present application. Those skilled in the art should understand that various modifications, combinations, sub-combinations, and substitutions can be made according to design requirements and other factors. Any modifications, equivalent substitutions, and improvements made within the spirit and principles of the present application shall be included within the protection scope of the present application.
Claims
1. A data resource management method based on transactions, characterized in that, The method includes: In response to detecting that the application startup is completed, generating a multi-level proxy chain through dynamic proxy for the data source instance object associated with the application; wherein, the multi-level proxy chain includes at least a transaction proxy object; the data source instance object includes at least one of a file system and in-memory data resources in addition to the database; If it is detected that a service class marked with a transaction annotation in the application is called, intercept the data change operations in the service class through the transaction proxy object and obtain the transaction data of the application in the current thread; If it is determined based on the transaction data that no transaction has been started in the current thread of the application, create a root transaction object for the current thread, and determine the transaction execution process of the current thread based on the root transaction object and the sub-transaction object associated with the current thread; wherein, at least two data change operations and change cancellation operations opposite to the data change operations are associated with the transaction objects in the transaction execution process; If it is detected that an exception occurs during the transaction execution, manage the data resources based on the transaction execution process and the change cancellation operations associated with the transaction objects; Among them, the generating a multi-level proxy chain through dynamic proxy for the data source instance object associated with the application in response to detecting that the application startup is completed includes: in response to detecting that the application startup is completed, constructing a data source proxy object; if the data source instance object exists in the dependency management container, insert the data source proxy object on the access path of the dependency management container to perform dynamic proxy on the data source instance object; intercept the target interface method associated with the data source instance object through the data source proxy object, and construct a multi-level proxy chain including at least the transaction proxy object.
2. The data resource management method based on transactions according to claim 1, characterized in that The determining the transaction execution process of the current thread based on the root transaction object and the sub-transaction object associated with the current thread includes: Creating a transaction chain starting from the root transaction object; Obtaining the sub-transaction object associated with the current thread, and determining the data change operations intercepted in the sub-transaction object; Based on the method name and related parameters corresponding to the data change operations, determining the change cancellation operations opposite to the data change operations; Associating the data change operations and the change cancellation operations to the sub-transaction object in the order of operation execution; Inserting the sub-transaction object into the end of the transaction chain in sequence based on the transaction hierarchy relationship; Determining the transaction execution process of the current thread based on the transaction chain.
3. The method for transaction-based data resource management according to claim 2, wherein, After determining the transaction execution process of the current thread, the method further includes: In response to detecting a transaction closing operation for the transaction object in the transaction chain, deleting the transaction chain of the current thread.
4. The method for transaction-based data resource management according to claim 1, wherein If it is detected that an exception occurs during the transaction execution, managing the data resources based on the transaction execution process and the change cancellation operations associated with the transaction objects includes: If it is detected that an exception occurs during the transaction execution, determining the target transaction object that needs to be rolled back in the transaction execution process based on the transaction hierarchy relationship; Obtain the change cancellation operation associated with the target transaction object, and call the change cancellation operation to manage the data resource based on the operation execution order.
5. The method for transaction-based data resource management according to claim 1, wherein Before intercepting the data change operation in the service class through the transaction proxy object, the method includes: Obtain the object metadata of the application from the metadata container; wherein, the object metadata is used to describe the component objects in the application. Based on the component name of the object metadata, determine the component type to which the component object belongs. If the component type is a database template, perform instrumentation on the component object to intercept the data processing operation of the database. If the component type is a data access object, determine the data resource framework called by the component object. In the case where the data resource framework is associated with a data change operation, perform instrumentation on the component object to intercept the data change operation of the data resource framework.
6. The data resource management method based on transactions according to claim 5, characterized in that The method further includes: If the component name includes a first keyword, add the object metadata of the component object to the database template container. If the component name includes a second keyword, add the object metadata of the component object to the data access object container. If the data processing operation called by the component object includes a data change operation, determine that the component object is a valid component, and delete the object metadata of other component objects in the data access object container except the valid component. Perform instrumentation on the component objects in the database template container and the data access object container respectively.
7. A transaction-based data resource management device, characterized in that, The apparatus includes: A multi-level proxy chain generation module, configured to, in response to detecting that the application startup is completed, perform dynamic proxy on the data source instance object associated with the application to generate a multi-level proxy chain; wherein, the multi-level proxy chain includes at least a transaction proxy object; the data source instance object includes at least one of a file system and memory in addition to the database. A transaction data acquisition module, configured to, if it is detected that the service class marked with a transaction annotation in the application is called, intercept the data change operation in the service class through the transaction proxy object and acquire the transaction data of the application in the current thread. A transaction execution process determination module, configured to, if it is determined based on the transaction data that no transaction has been started in the current thread of the application, create a root transaction object for the current thread, and determine the transaction execution process of the current thread based on the root transaction object and the sub-transaction objects associated with the current thread; wherein, the transaction objects in the transaction execution process are associated with at least two data change operations and change cancellation operations opposite to the data change operations. A data resource management module, configured to, if it is detected that an exception occurs during the transaction execution, manage the data resource based on the transaction execution process and the change cancellation operation associated with the transaction object. Among them, the multi-level proxy chain generation module includes: a data source proxy object construction sub-module, configured to construct a data source proxy object in response to detecting that the application startup is completed; a dynamic proxy sub-module, configured to insert the data source proxy object on the access path of the dependency management container to perform dynamic proxy on the data source instance object if the data source instance object exists in the dependency management container; and a proxy chain construction sub-module, configured to intercept the target interface method associated with the data source instance object through the data source proxy object and construct a multi-level proxy chain including at least the transaction proxy object.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the program is executed by a processor, it implements the transaction-based data resource management method according to any one of claims 1-6.
9. An electronic device, comprising a memory, a processor, and a computer program stored on the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the transaction-based data resource management method according to any one of claims 1-6.
Citation Information
Patent Citations
Multi-data-source transaction management method, system and device and medium
CN116244043A
Multi-database transaction aspect management method and device, equipment and storage medium
CN119179687A