CN110008224B - Database transaction processing method and device - Google Patents

Database transaction processing method and device Download PDF

Info

Publication number
CN110008224B
CN110008224B CN201910176345.5A CN201910176345A CN110008224B CN 110008224 B CN110008224 B CN 110008224B CN 201910176345 A CN201910176345 A CN 201910176345A CN 110008224 B CN110008224 B CN 110008224B
Authority
CN
China
Prior art keywords
cache
database transaction
target database
target
cache data
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Active
Application number
CN201910176345.5A
Other languages
Chinese (zh)
Other versions
CN110008224A (en
Inventor
雷毅
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Advanced New Technologies Co Ltd
Advantageous New Technologies Co Ltd
Original Assignee
Advanced New Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Advanced New Technologies Co Ltd filed Critical Advanced New Technologies Co Ltd
Priority to CN201910176345.5A priority Critical patent/CN110008224B/en
Publication of CN110008224A publication Critical patent/CN110008224A/en
Application granted granted Critical
Publication of CN110008224B publication Critical patent/CN110008224B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2358Change logging, detection, and notification
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2365Ensuring data consistency and integrity
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/24Querying
    • G06F16/245Query processing
    • G06F16/2455Query execution
    • G06F16/24552Database cache management

Abstract

One or more embodiments of the present disclosure provide a database transaction processing method and apparatus, where the method includes: when the business code of the target database transaction runs, acquiring and storing a cache data identifier related to the target database transaction; and if the target database transaction execution is completed, deleting the cache data corresponding to the stored cache data identifier. In the execution process of the database transaction, the identification information of the cache data related to the database transaction is recorded, so that after the database transaction is submitted or rolled back, the cache data corresponding to the identification information of the cache data recorded by the database transaction are automatically deleted, and when the cache data corresponding to the identification information needs to be queried, the corresponding target data is automatically acquired from the database and stored in the local cache, thus ensuring that the data in the database and the local cache are kept consistent, and avoiding the problem of error in subsequent data operation caused by inconsistent data in the database and the local cache.

Description

Database transaction processing method and device
Technical Field
One or more of the present disclosure relates to the field of computer technology, and in particular, to a method and apparatus for processing database transactions.
Background
At present, in order to quickly acquire common and stable service data and reduce the access times to a database, a cache technology is generally adopted to store the common and stable service data into a local cache, so that when the service data needs to be used, the service data can be directly acquired from the local cache without repeatedly requesting the database to acquire the service data.
Since transactions can ensure that data-oriented resources are not permanently updated unless all operations within a transactional unit are completed successfully. By combining a set of related operations into one unit that is either totally successful or totally failed, error recovery can be simplified and the application can be made more reliable. Therefore, the transaction processing mode is adopted to carry out the operations of adding, deleting and checking on the data in the database so as to ensure the stability and predictability of the data in the database. That is, the database transaction (Database Transaction) is a series of operations performed as a single logical unit of work in the database, either performed entirely or not performed entirely.
However, when executing a database transaction, not only is the corresponding operation performed on the data in the database needed, if the database data operated by the transaction processing process is cached, that is, when performing the transaction operation on the business data in the database with the cache, the update operation is performed on the data in the cache based on the data change in the database, and for the case of high concurrency or the case of data rollback, the data in the database and the data in the cache are inconsistent, so that the subsequent data operation is abnormal, for example, for the data query operation, the data queried from the cache and the data in the database are inconsistent, and the data finally displayed to the user is erroneous data.
It is therefore desirable to provide a data processing method that improves the consistency of the data in the database and the cache.
Disclosure of Invention
In one or more embodiments of the present disclosure, in a process of executing a database transaction, identification information of cache data related to the database transaction is recorded, so that after the database transaction is submitted or rolled back, cache data corresponding to the identification information of the cache data recorded by the database transaction is automatically deleted, so that when the cache data corresponding to the identification information needs to be queried, corresponding target data is automatically obtained from a database and stored in a local cache, thus ensuring that the database is consistent with data in the local cache, and avoiding the problem of errors in subsequent data operations caused by inconsistent data in the database and the local cache.
To solve the above technical problems, one or more embodiments of the present specification are implemented as follows:
one or more embodiments of the present specification provide a database transaction method, including:
when a business code of a target database transaction runs, acquiring a cache data identifier related to the target database transaction;
Storing the cache data identifier related to the target database transaction;
and if the target database transaction execution is completed, deleting the cache data corresponding to the cache data identifier.
One or more embodiments of the present specification provide a database transaction processing apparatus, including:
the cache identification acquisition module is used for acquiring a cache data identification related to a target database transaction when a service code of the target database transaction runs;
the cache identification storage module is used for storing the cache data identification related to the target database transaction;
and the cache data deleting module is used for deleting the cache data corresponding to the cache data identifier if the target database transaction execution is completed.
One or more embodiments of the present specification provide a database transaction device including: a processor; and
a memory arranged to store computer executable instructions that, when executed, cause the processor to:
when a business code of a target database transaction runs, acquiring a cache data identifier related to the target database transaction;
storing the cache data identifier related to the target database transaction;
And if the target database transaction execution is completed, deleting the cache data corresponding to the cache data identifier.
One or more embodiments of the present specification provide a storage medium storing computer-executable instructions that, when executed, implement the following:
when a business code of a target database transaction runs, acquiring a cache data identifier related to the target database transaction;
storing the cache data identifier related to the target database transaction;
and if the target database transaction execution is completed, deleting the cache data corresponding to the cache data identifier.
In one or more embodiments of the present disclosure, a method and an apparatus for processing a database transaction acquire a cache data identifier related to a target database transaction when a service code of the target database transaction runs; storing a cache data identifier related to a target database transaction; and if the target database transaction execution is completed, deleting the cache data corresponding to the stored cache data identifier. In one or more embodiments of the present disclosure, in the execution process of a database transaction, identification information of cache data related to the database transaction is recorded, so that after the database transaction is submitted or rolled back, cache data corresponding to the identification information of the cache data recorded for the database transaction is automatically deleted, so that when the cache data corresponding to the identification information needs to be queried, corresponding target data is automatically obtained from the database and stored in a local cache, so that the database and the data in the local cache can be ensured to be kept consistent, and a problem that errors occur in subsequent data operations due to inconsistent data in the database and the local cache is avoided.
Drawings
For a clearer description of one or more embodiments of the present description or of the solutions of the prior art, the drawings that are necessary for the description of the embodiments or of the prior art will be briefly described, it being apparent that the drawings in the description below are only some of the embodiments described in one or more of the present description, from which other drawings can be obtained, without inventive faculty, for a person skilled in the art.
FIG. 1 is a first flow diagram of a database transaction method according to one or more embodiments of the present disclosure;
FIG. 2 is a second flow diagram of a database transaction method according to one or more embodiments of the present disclosure;
FIG. 3 is a third flow diagram of a database transaction method according to one or more embodiments of the present disclosure;
FIG. 4 is a schematic diagram illustrating an implementation of a database transaction method according to one or more embodiments of the present disclosure;
FIG. 5 is a schematic diagram illustrating a block diagram of a database transaction device according to one or more embodiments of the present disclosure;
fig. 6 is a schematic structural diagram of a database transaction device according to one or more embodiments of the present disclosure.
Detailed Description
In order for those skilled in the art to better understand the solutions in one or more embodiments of the present specification, the solutions in one or more embodiments of the present specification will be clearly and completely described below with reference to the drawings in one or more embodiments of the present specification, and it is apparent that the described embodiments are only a part of one or more embodiments of the present specification, not all embodiments. All other embodiments, which can be made by one or more persons of ordinary skill in the art without undue burden from the disclosure, are intended to be within the scope of one or more of the disclosure.
One or more embodiments of the present disclosure provide a method and an apparatus for processing a database transaction, where in a process of executing the database transaction, identification information of cache data related to the database transaction is recorded, so that after the database transaction is submitted or rolled back, cache data corresponding to the identification information of the cache data recorded for the database transaction is automatically deleted, so when the cache data corresponding to the identification information needs to be queried, corresponding target data is automatically obtained from a database and stored in a local cache, so that it can be ensured that the database is kept consistent with data in the local cache, and a problem that errors occur in subsequent data operations due to inconsistent data in the database and the local cache is avoided.
FIG. 1 is a first flowchart of a database transaction method according to one or more embodiments of the present disclosure, as shown in FIG. 1, the method at least includes the following steps:
s101, when a business code aiming at a target database transaction runs, acquiring a cache data identifier related to the target database transaction, wherein after the target database transaction is started, the business code of the target database transaction is automatically run, and the business code comprises the following steps: based on the byte code obtained by compiling the source code and the target logic code woven into the byte code by utilizing a dynamic proxy technology, the service code can be dynamically generated during the compiling of the byte code or can be dynamically generated during the running of the byte code;
specifically, running a service code for a target database transaction, that is, executing a preset data operation related to the database transaction on service data in the target database, for example, for a certain database transaction operation, a series of data adding, deleting and checking operations may be executed on service data in the target database, and if the service data in the operated target database is cached, determining a cache key corresponding to the service data operated when executing the target database transaction;
S102, storing a cache data identifier acquired for a target database transaction, specifically, storing the acquired cache data identifier, and storing the cache data identifier in a designated storage position;
considering that the thread context is a container bound to a java thread, and the java thread is created for a database transaction, different java threads corresponding to different database transactions, that is, the thread context has a certain corresponding relation with the database transaction, so in order to ensure that when corresponding cache data is deleted for a certain database transaction, a cache data identifier recorded for the database transaction can be accurately read, preferably, the cache data identifier acquired for a target database transaction is written into the thread context, and the cache key corresponding to the service data in the database operated when the target database transaction is about to be executed is written into the thread context;
s103, if the target database transaction execution is completed, deleting the cache data corresponding to the cache data identifier acquired for the target database transaction, wherein the target database transaction execution completion comprises: transaction commit completions, or database data rollback completions, that characterize a series of data operations of a target database transaction are completely performed completions, and database data rollback completions that characterize a series of data operations of a target database transaction are not completely performed.
In one or more embodiments of the present disclosure, in the execution process of a database transaction, identification information of cache data related to the database transaction is recorded, so that after the database transaction is submitted or rolled back, cache data corresponding to the identification information of the cache data recorded for the database transaction is automatically deleted, so that when the cache data corresponding to the identification information needs to be queried, corresponding target data is automatically obtained from the database and stored in a local cache, so that the database and the data in the local cache can be ensured to be kept consistent, and a problem that errors occur in subsequent data operations due to inconsistent data in the database and the local cache is avoided.
Further, since processing logic about recording the cached data identifier and deleting the cached data is required to be added during the execution of the database transaction, it is required to generate a service code containing a new processing logic code based on the source code of the database transaction, and in order to ensure that the source code is not intrusive, the new processing logic code is organized into the bytecode by using a dynamic proxy technology to obtain the required service code, and correspondingly, as shown in fig. 2, before the step S101 of obtaining the cached data identifier related to the target database transaction, the method further includes:
S104, a target logic code is woven into byte codes of the target database transaction by utilizing a dynamic proxy technology to obtain service codes of the target database transaction, wherein the target logic code comprises the following components: a first logic code for implementing an intercept cache operation and a second logic code for implementing an intercept transaction commit or rollback;
the method comprises the steps of compiling a source code of a target database transaction to obtain an original class file which does not contain target logic codes, wherein the byte code is a target class file obtained by adding the target logic codes into the byte code by utilizing a dynamic proxy technology; the first logic code comprises a class function for recording the identification of the cache data, and the second logic code comprises a class function for deleting the cache data;
the dynamic proxy technology refers to a design mode in java language, and can implement executing a section of target logic code before and after a designated interface or method call in a byte code related to a source code of a target database transaction, so as to implement adding a newly added business logic into the byte code, thereby implementing automatically determining and storing at least one operated cache key in a business code running process aiming at the target database transaction, and deleting cache data corresponding to the at least one cache key after the target database transaction is executed, wherein the dynamic proxy can enable a system to dynamically create proxy classes according to actual needs, and enable the same proxy class to proxy a plurality of different real theme classes and proxy different methods;
Specifically, during the compiling period or the running period of the byte code of the target database transaction, intercepting a designated interface or method for caching operation in the byte code by utilizing a dynamic proxy technology, namely, before a class function for operating the cache in the byte code is perceived, inserting a first logic code into the designated interface or method for caching operation in the byte code, specifically, perceiving the class function for caching operation in the byte code by utilizing the dynamic proxy technology, and adding the class function for recording the identification of the cached data into the byte code before the class function for operating the cache;
and intercepting a specified interface or method of the transaction commit or rollback operation in the byte code by utilizing a dynamic proxy technology, namely, perceiving a class function for the transaction commit or rollback operation in the byte code, inserting a second logic code into the byte code after the specified interface or method of the transaction commit or rollback operation, specifically, perceiving the class function for the transaction commit or rollback operation in the byte code by utilizing the dynamic proxy technology, and adding the class function for deleting the cache data into the byte code after the class function for the transaction commit or rollback operation;
the process of adding the target logic code into the byte code obtained based on source code compiling can add the target logic code during the process of compiling the source code into the byte code, and can also add the target logic code during the operation of the byte code, generate a new byte code added with the target logic code, and take the new byte code as a business code of a target database transaction, wherein the generation process of the business code specifically comprises the following steps:
(1) Correspondingly, the step S104 of using the dynamic proxy technology to weave the target logic code into the byte code of the target database transaction to obtain the service code of the target database transaction includes:
when the source code of the target database transaction is compiled to obtain the byte code, a dynamic proxy technology is utilized to add the target logic code into the byte code to obtain the service code of the target database transaction.
(2) Correspondingly, the step S104 of using the dynamic proxy technology to weave the target logic code into the byte code of the target database transaction to obtain the service code of the target database transaction includes:
compiling the source code of the target database transaction to obtain the byte code of the target database transaction;
and when the byte code of the target database transaction is operated, adding a target logic code into the byte code by utilizing a dynamic proxy technology to obtain the service code of the target database transaction.
In one or more embodiments of the present disclosure, whether a service code is obtained by adding a target logic code during compiling a source code into a bytecode or by adding a target logic code during running a bytecode, a dynamic proxy technique is adopted to weave a first logic code before or after a class function used for operating a cache in the bytecode of a target database transaction, and weave a second logic code after a class function used for submitting or rolling back a transaction in the bytecode of the target database transaction, so that service logic of the source code is unchanged, technical details are shielded, the source code is non-invasive, a user is not required to manually modify and write the source code, and the weave efficiency of the target logic code is improved.
The step S101 of acquiring the cache data identifier related to the target database transaction specifically includes:
if a first logic code in the operation target logic code is detected, intercepting class functions adjacent to the first logic code and used for operating the cache, namely, perceiving class functions which are used for operating the cache and correspond to database operations involved in a target database transaction;
wherein, for the business code generation process, if the first logic code is inserted before the class function for operating the cache in the byte code, the class function for operating the cache adjacent to and after the first logic code is intercepted; intercepting a class function for operating the cache adjacent to and before the first logic code if the first logic code is inserted after the class function for operating the cache in the byte code;
determining a cache data identifier contained in the intercepted class function for operating the cache, and specifically extracting a value of a parameter for representing a cache key in the class function for operating the cache;
and taking the determined cache data identifier as the cache data identifier related to the target database transaction.
Specifically, since most caching technologies do not support transactions, if a database and a cache are operated at the same time in a transaction, the cache may be inconsistent with data in the database for the same data identifier under the condition of high concurrency, for example, when the database transaction is abnormal in the execution process, data rollback is required, at this time, the data in the database is rolled back, but the data in the cache is not rolled back, so that the data corresponding to a certain data identifier in the database is changed into data before change, and the data corresponding to the data identifier in the cache is still changed data;
taking consumption transaction as an example, account balances stored in a database and a cache are 100 yuan before the database transaction is started, aiming at a database transaction with the payment application amount of 10 yuan, the data stored in the database is changed from 100 yuan to 90 yuan, at the moment, if data rollback is required in the execution process of the database transaction due to errors, the data in the database rollback at the moment, but the data in the cache are not rolled back, so that the account balance in the database rolls back to 100 yuan, but the account balance in the cache is still 90 yuan, and when a user inquires the account balance again, error prompt information with the account balance of 90 yuan is displayed.
For another example, before the target database transaction is submitted, the data corresponding to a certain data identifier in the cache is deleted, because the database transaction is not completed, the data corresponding to the data identifier in the database is still the data before the change, if other threads request to query the data corresponding to the data identifier at the moment, the data before the change in the database is automatically loaded into the cache, but after the database transaction is submitted, the data corresponding to the data identifier in the database is changed into the data after the change, and the data corresponding to the data identifier in the cache is still the data before the change;
taking refund transaction as an example, the account balance stored in the database and the cache is 100 yuan before the database transaction is started, aiming at a database transaction with 50 yuan about refund application amount, if a user requests to inquire the account balance in the execution process of the database transaction, the account balance stored in the database is still 100 yuan because the database transaction is not completed, at the moment, the system automatically stores the account balance into the cache for the request of inquiring the account balance, but after the database transaction is submitted, the account balance stored in the database is changed into 150 yuan (containing 50 yuan refund amount), and the account balance stored in the cache is still 100 yuan; however, after the database transaction is submitted, the user is prompted to pay back successfully, but the account balance stored in the cache is still 100 yuan at this time, so that when the user inquires the account balance again, error prompt information with the account balance of 100 yuan is displayed.
Therefore, in order to ensure that the cache is consistent with the data in the database, a target logic code needs to be added in the byte code of the target database transaction, so that the data identifier operated in the target database transaction is recorded in the execution process of the target database transaction, and the cache data corresponding to the data identifier in the local cache is deleted after the target database transaction is completed, so that when the cache data corresponding to the data identifier needs to be queried, the latest data corresponding to the data identifier is automatically acquired from the database and stored in the local cache;
in the execution process of a certain database transaction, a plurality of data adding, deleting and checking operations on service data in a target database may be involved, and if the service data in the operated target database is cached, all cache keys corresponding to the cache operated in the execution process of the database transaction need to be determined; specifically, a dynamic proxy technology is used, and a first logic code is added before all class functions used for operating the cache in the byte code of the target database transaction, so that when the first logic code is operated, all cache keys corresponding to the class functions used for operating the cache are recorded.
Taking a transaction template Transaction Template of a spring framework and a cache service tair as examples for illustration, and utilizing a dynamic proxy technology, organizing a first logic code into a byte code of a target database transaction to realize interception of interface classes for operating the tair cache service, for example, interception of an instance of a refreshable common tair cache manager Refreshable Common Tair Cache Manager;
specifically, using dynamic proxy techniques, the relevant methods of put Object, incr, decr, etc. in the Refreshable Common Tair Cache Manager instance, i.e., any method that includes a cache update operation, are intercepted, e.g., put Object With Expire, put Object, put Object Modify Date, etc.
The variable of the thread context bound on the java thread is stored, the information is always accessed at different times to obtain the same value, and the thread context has a certain corresponding relation with the database transaction, so that the cache data identifiers stored for different database transactions can be isolated, therefore, the cache data identifiers are stored in the corresponding thread context, so that the cache data identifiers recorded for the target database transaction can be accurately read out from the thread context when the subsequent cache data is deleted, thereby ensuring that the cache data identifiers stored in the transaction execution process are the same as the cache data identifiers read after the transaction execution is completed, further improving the accuracy of cache data deletion, ensuring that the corresponding cache data is accurately deleted for a certain database transaction, and based on the cache data identifiers, as shown in fig. 3, the step S102 stores the cache data identifiers acquired for the target database transaction, and specifically comprises:
S1021, storing the cache data identifier related to the target database transaction into the thread context corresponding to the target database transaction, and specifically triggering the cache key corresponding to the cache operation to be stored into the thread context before the cache operation is executed.
Specifically, for the storing process of the cache data identifier, since the cache data identifier may be extracted from the class function used for operating the cache, the corresponding target thread may be determined according to the class function, and then the corresponding thread context may be determined according to the target thread, so as to store the cache data identifier into the thread context bound on the target thread corresponding to the class function, and specifically, the step S1021 stores the cache data identifier related to the target database transaction into the thread context corresponding to the target database transaction, including:
determining a target thread corresponding to intercepted class functions for operating the cache, wherein the threads are minimum units of execution codes, each class function corresponds to one thread, and codes related to the class functions are executed in thread contexts bound on the respective threads;
writing the determined cache data identifier into the thread context bound on the target thread, specifically, storing the cache data identifier into the thread context on the target thread corresponding to the class function for operating the cache, so that when the cache data is deleted for the target database transaction, the cache data identifier is directly read from the thread context bound on the thread executing all codes of the class function for operating the cache running for the target database transaction.
Specifically, a static Thread Local variable is defined, wherein the Thread Local variable refers to a class used for operating the Thread context in the java Thread, and the Thread Local variable can be used for storing a cache key into the Thread context bound on the Thread corresponding to the cache operation; for the case that the first logic code is inserted before the class function used for operating the cache in the byte code, before the class function used for operating the cache is executed, the value of the parameter used for representing the cache key in the class function used for operating the cache is stored in a Thread Local variable, wherein each Thread reads and writes data into the corresponding Thread Local, the threads are isolated, and the threads are isolated from each other and do not influence each other.
In the process of deleting the cache data corresponding to the cache data identifier, considering that there may be a situation that a plurality of database transactions are executed in parallel, therefore, in the process of executing the cache data deleting operation on the database transaction submitted or rolled back by the completed transaction, it is required to ensure that the deleted cache data is the cache data corresponding to the cache key stored for the database transaction, that is, it is required to ensure that the cache data identifier of the transaction for completing reading is the same as the cache data identifier stored in the process of executing the transaction, so as to avoid the problem of deleting the cache data corresponding to the cache key stored by other database transactions by mistake or deleting the cache data corresponding to the cache data identifier obtained for the target database transaction by mistake, specifically, the step S103 includes:
If a second logic code in the operation target logic code is detected, intercepting class functions adjacent to the second logic code and used for submitting or rolling back operation transactions, namely, class functions for perceiving the submitting or rolling back of the operation transactions in the service code;
determining a database transaction identifier contained in the intercepted class function for submitting or rolling back the operation transaction, and specifically extracting a value of a parameter for representing the transaction identifier in the class function for submitting or rolling back the operation transaction;
searching cache data corresponding to the cache data identifier in a local cache aiming at each cache data identifier corresponding to the determined database transaction identifier, wherein each cache data identifier is read from thread contexts bound on a plurality of target threads corresponding to the determined database transaction identifier;
specifically, reading cache data identifiers in thread contexts bound on a plurality of target threads corresponding to the determined database transaction identifiers; searching the cache data corresponding to the read cache data identifiers in the local cache, namely searching the Value of the cache data corresponding to each cache key of the target database transaction record in the local cache;
Deleting the searched cache data corresponding to the cache data identifier from the local cache, and deleting the cache data identifier stored in the thread context, wherein the thread context is a thread context bound on a plurality of target threads corresponding to the determined database transaction identifier;
specifically, a dynamic proxy technology is used to organize a second logic code into byte codes of a target database transaction to realize interception of transaction operation templates, after the operation transaction is perceived to be submitted or rolled back, the cache data corresponding to the stored cache data identifier in the local cache is triggered to be deleted, and the cache data identifier stored in the thread context is triggered to be deleted, namely the cache data corresponding to the cache key operated in the execution process of the database transaction is deleted, so that the hidden trouble that the value corresponding to the cache key in the local cache and the value corresponding to the cache key in the database are inconsistent due to high concurrency can be eliminated.
Taking a transaction template Transaction Template and a cache service tair of the spring framework as examples, and using a dynamic proxy technology to weave a second logic code into a byte code of a target database transaction to realize interception of transaction operation templates in the spring framework, for example, interception of a transaction template Transaction Template instance;
Specifically, a dynamic proxy technology is used to intercept an execution (commit transaction) method in a Transaction Template instance, a try.
As shown in fig. 4, in a specific embodiment, a schematic implementation diagram of a database transaction processing method is provided, which specifically includes:
s40, starting a target database transaction, and automatically running a service code of the target database transaction after the transaction is started, wherein the service code comprises the following steps: a byte code compiled based on source code and a target logic code woven into the byte code by dynamic proxy technology, the target logic code comprising: first logic code for implementing an intercept cache operation and second logic code for implementing an intercept transaction commit or rollback
Specifically, the service code may be dynamically generated during the compiling period of the byte code, or may be dynamically generated during the running period of the byte code;
S41, executing database operations contained in the service codes, for example, performing an adding, deleting and checking operation on data in the database;
s42, if a first logic code in the operation service code is detected, a cache key corresponding to the cache operation is obtained, and the cache key is stored in a corresponding thread context;
s43, executing the cache operation contained in the service code, wherein the data aimed at by the database operation in S41 is cached, so that corresponding operations, such as updating, inserting and the like, are required to be executed on the corresponding data in the cache;
s44, submitting or rolling back the transaction, wherein a plurality of S41, S42 and S43 can be included between S43 and S44, namely, in the execution process of the database transaction, a plurality of database operations and cache operations can be executed, correspondingly, a plurality of cache keys aiming at the database transaction are acquired, and the cache keys are respectively stored in thread contexts bound on corresponding threads;
s45, if the second logic code in the running service code is detected, deleting the cache data corresponding to the cache key stored in the thread context in the cache, and clearing the cache key in the thread context.
According to the database transaction processing method in one or more embodiments of the present disclosure, when a service code of a target database transaction runs, a cache data identifier related to the target database transaction is obtained; storing a cache data identifier related to a target database transaction; and if the target database transaction execution is completed, deleting the cache data corresponding to the stored cache data identifier. In one or more embodiments of the present disclosure, in the execution process of a database transaction, identification information of cache data related to the database transaction is recorded, so that after the database transaction is submitted or rolled back, cache data corresponding to the identification information of the cache data recorded for the database transaction is automatically deleted, so that when the cache data corresponding to the identification information needs to be queried, corresponding target data is automatically obtained from the database and stored in a local cache, so that the database and the data in the local cache can be ensured to be kept consistent, and a problem that errors occur in subsequent data operations due to inconsistent data in the database and the local cache is avoided.
Corresponding to the database transaction method described in fig. 1 to 4, based on the same technical concept, one or more embodiments of the present disclosure further provide a database transaction device, and fig. 5 is a schematic block diagram of the database transaction device provided in one or more embodiments of the present disclosure, where the device is configured to perform the database transaction method described in fig. 1 to 4, as shown in fig. 5, and the device includes:
A cache identifier obtaining module 501, configured to obtain a cache data identifier related to a target database transaction when a service code of the target database transaction runs;
a cache identifier storage module 502, configured to store the cache data identifier related to the target database transaction;
and the cache data deleting module 503 is configured to delete the cache data corresponding to the cache data identifier if the target database transaction is executed.
In one or more embodiments of the present disclosure, in the execution process of a database transaction, identification information of cache data related to the database transaction is recorded, so that after the database transaction is submitted or rolled back, cache data corresponding to the identification information of the cache data recorded for the database transaction is automatically deleted, so that when the cache data corresponding to the identification information needs to be queried, corresponding target data is automatically obtained from the database and stored in a local cache, so that the database and the data in the local cache can be ensured to be kept consistent, and a problem that errors occur in subsequent data operations due to inconsistent data in the database and the local cache is avoided.
Optionally, the above device further includes a service code generating module, configured to:
And utilizing a dynamic proxy technology to weave target logic codes into byte codes of target database transactions to obtain service codes of the target database transactions, wherein the target logic codes comprise: a first logic code for implementing an intercept cache operation and a second logic code for implementing an intercept transaction commit or rollback.
Optionally, the cache identifier obtaining module 501 is specifically configured to:
if the first logic code is detected to run, intercepting class functions for operating the cache;
determining a cache data identifier contained in the class function for operating the cache;
and using the cache data identifier as the cache data identifier related to the target database transaction.
Optionally, the cache identifier storage module 502 is specifically configured to:
and storing the cached data identifier related to the target database transaction into a thread context.
Optionally, the service code generating module is specifically configured to:
when compiling the source code of the target database transaction to obtain a byte code, adding a target logic code into the byte code by utilizing a dynamic proxy technology to obtain the service code of the target database transaction.
Optionally, the service code generating module is further specifically configured to:
Compiling a source code of a target database transaction to obtain a byte code of the target database transaction;
and when the byte codes are operated, adding target logic codes into the byte codes by utilizing a dynamic proxy technology to obtain service codes of target database transactions.
Optionally, the cache identifier storage module 502 is further specifically configured to:
determining a target thread corresponding to the intercepted class function for operating the cache;
and writing the cached data identification into a thread context bound on the target thread.
Optionally, the cache data deleting module 503 is specifically configured to:
if the second logic code is detected to run, intercepting a class function for operating transaction submission or rollback;
determining a database transaction identifier contained in the class function for operating transaction commit or rollback;
searching cache data corresponding to the cache data identifier in a local cache for each cache data identifier corresponding to the database transaction identifier;
deleting the searched cache data from the local cache, and deleting the cache data identifier stored in the thread context.
The database transaction processing device in one or more embodiments of the present disclosure obtains a cache data identifier related to a target database transaction when a service code of the target database transaction runs; storing a cache data identifier related to a target database transaction; and if the target database transaction execution is completed, deleting the cache data corresponding to the stored cache data identifier. In one or more embodiments of the present disclosure, in the execution process of a database transaction, identification information of cache data related to the database transaction is recorded, so that after the database transaction is submitted or rolled back, cache data corresponding to the identification information of the cache data recorded for the database transaction is automatically deleted, so that when the cache data corresponding to the identification information needs to be queried, corresponding target data is automatically obtained from the database and stored in a local cache, so that the database and the data in the local cache can be ensured to be kept consistent, and a problem that errors occur in subsequent data operations due to inconsistent data in the database and the local cache is avoided.
It should be noted that, in the present specification, the embodiments related to the database transaction device and the embodiments related to the database transaction method in the present specification are based on the same inventive concept, so the specific implementation of this embodiment may refer to the implementation of the corresponding database transaction method, and the repetition is omitted.
Further, according to the method shown in fig. 1 to fig. 4, based on the same technical concept, one or more embodiments of the present disclosure further provide a database transaction processing device, which is configured to perform the database transaction processing method as described above, as shown in fig. 6.
Database transaction devices may vary widely in configuration or performance, may include one or more processors 601 and memory 602, and may have one or more stored applications or data stored in memory 602. Wherein the memory 602 may be transient storage or persistent storage. The application programs stored in the memory 602 may include one or more modules (not shown) each of which may include a series of computer executable instructions for use in a database transaction device. Still further, the processor 601 may be arranged to communicate with the memory 602 and execute a series of computer executable instructions in the memory 602 on a database transaction device. The database transaction device may also include one or more power supplies 603, one or more wired or wireless network interfaces 604, one or more input/output interfaces 605, one or more keyboards 606, and the like.
In a particular embodiment, a database transaction device includes a memory, and one or more programs, wherein the one or more programs are stored in the memory, and the one or more programs may include one or more modules, and each module may include a series of computer-executable instructions for the database transaction device, and configured to be executed by one or more processors, the one or more programs comprising computer-executable instructions for:
when a business code of a target database transaction runs, acquiring a cache data identifier related to the target database transaction;
storing the cache data identifier related to the target database transaction;
and if the target database transaction execution is completed, deleting the cache data corresponding to the cache data identifier.
In one or more embodiments of the present disclosure, in the execution process of a database transaction, identification information of cache data related to the database transaction is recorded, so that after the database transaction is submitted or rolled back, cache data corresponding to the identification information of the cache data recorded for the database transaction is automatically deleted, so that when the cache data corresponding to the identification information needs to be queried, corresponding target data is automatically obtained from the database and stored in a local cache, so that the database and the data in the local cache can be ensured to be kept consistent, and a problem that errors occur in subsequent data operations due to inconsistent data in the database and the local cache is avoided.
Optionally, the computer-executable instructions, when executed, further comprise computer-executable instructions for:
and utilizing a dynamic proxy technology to weave target logic codes into byte codes of target database transactions to obtain service codes of the target database transactions, wherein the target logic codes comprise: a first logic code for implementing an intercept cache operation and a second logic code for implementing an intercept transaction commit or rollback.
Optionally, the obtaining the cached data identifier related to the target database transaction when the computer executable instructions are executed includes:
if the first logic code is detected to run, intercepting class functions for operating the cache;
determining a cache data identifier contained in the class function for operating the cache;
and using the cache data identifier as the cache data identifier related to the target database transaction.
Optionally, the storing the cached data identification referred to by the target database transaction when the computer executable instructions are executed comprises:
and storing the cached data identifier related to the target database transaction into a thread context.
Optionally, when executed, the computer executable instructions utilize dynamic proxy technology to weave target logic code into byte code of the target database transaction to obtain service code of the target database transaction, including:
When compiling the source code of the target database transaction to obtain a byte code, adding a target logic code into the byte code by utilizing a dynamic proxy technology to obtain the service code of the target database transaction.
Optionally, when executed, the computer executable instructions utilize dynamic proxy technology to weave target logic code into byte code of the target database transaction to obtain service code of the target database transaction, including:
compiling a source code of a target database transaction to obtain a byte code of the target database transaction;
and when the byte codes are operated, adding target logic codes into the byte codes by utilizing a dynamic proxy technology to obtain service codes of target database transactions.
Optionally, the storing the cached data identifier related to the target database transaction in a thread context when the computer executable instructions are executed includes:
determining a target thread corresponding to the intercepted class function for operating the cache;
and writing the cached data identification into a thread context bound on the target thread.
Optionally, when the computer executable instructions are executed, the deleting the cache data corresponding to the cache data identifier includes:
If the second logic code is detected to run, intercepting a class function for operating transaction submission or rollback;
determining a database transaction identifier contained in the class function for operating transaction commit or rollback;
searching cache data corresponding to the cache data identifier in a local cache for each cache data identifier corresponding to the database transaction identifier;
deleting the searched cache data from the local cache, and deleting the cache data identifier stored in the thread context.
In one or more embodiments of the present disclosure, a database transaction processing device obtains a cache data identifier related to a target database transaction when a service code of the target database transaction runs; storing a cache data identifier related to a target database transaction; and if the target database transaction execution is completed, deleting the cache data corresponding to the stored cache data identifier. In one or more embodiments of the present disclosure, in the execution process of a database transaction, identification information of cache data related to the database transaction is recorded, so that after the database transaction is submitted or rolled back, cache data corresponding to the identification information of the cache data recorded for the database transaction is automatically deleted, so that when the cache data corresponding to the identification information needs to be queried, corresponding target data is automatically obtained from the database and stored in a local cache, so that the database and the data in the local cache can be ensured to be kept consistent, and a problem that errors occur in subsequent data operations due to inconsistent data in the database and the local cache is avoided.
Further, according to the method shown in fig. 1 to fig. 4, based on the same technical concept, one or more embodiments of the present disclosure further provide a storage medium, which is used to store computer executable instructions, in a specific embodiment, the storage medium may be a U disc, an optical disc, a hard disk, or the like, where the computer executable instructions stored in the storage medium can implement the following flow when executed by a processor:
when a business code of a target database transaction runs, acquiring a cache data identifier related to the target database transaction;
storing the cache data identifier related to the target database transaction;
and if the target database transaction execution is completed, deleting the cache data corresponding to the cache data identifier.
In one or more embodiments of the present disclosure, in the execution process of a database transaction, identification information of cache data related to the database transaction is recorded, so that after the database transaction is submitted or rolled back, cache data corresponding to the identification information of the cache data recorded for the database transaction is automatically deleted, so that when the cache data corresponding to the identification information needs to be queried, corresponding target data is automatically obtained from the database and stored in a local cache, so that the database and the data in the local cache can be ensured to be kept consistent, and a problem that errors occur in subsequent data operations due to inconsistent data in the database and the local cache is avoided.
Optionally, the computer executable instructions stored by the storage medium, when executed by the processor, further implement the following:
and utilizing a dynamic proxy technology to weave target logic codes into byte codes of target database transactions to obtain service codes of the target database transactions, wherein the target logic codes comprise: a first logic code for implementing an intercept cache operation and a second logic code for implementing an intercept transaction commit or rollback.
Optionally, the computer executable instructions stored on the storage medium, when executed by the processor, obtain the cache data identifier related to the target database transaction, including:
if the first logic code is detected to run, intercepting class functions for operating the cache;
determining a cache data identifier contained in the class function for operating the cache;
and using the cache data identifier as the cache data identifier related to the target database transaction.
Optionally, the storage medium stores computer executable instructions that, when executed by a processor, store the cached data identification referred to by the target database transaction, comprising:
and storing the cached data identifier related to the target database transaction into a thread context.
Optionally, the computer executable instructions stored in the storage medium, when executed by the processor, utilize the dynamic proxy technique to weave in target logic code in the byte code of the target database transaction to obtain the service code of the target database transaction, including:
when compiling the source code of the target database transaction to obtain a byte code, adding a target logic code into the byte code by utilizing a dynamic proxy technology to obtain the service code of the target database transaction.
Optionally, the computer executable instructions stored in the storage medium, when executed by the processor, utilize the dynamic proxy technique to weave in target logic code in the byte code of the target database transaction to obtain the service code of the target database transaction, including:
compiling a source code of a target database transaction to obtain a byte code of the target database transaction;
and when the byte codes are operated, adding target logic codes into the byte codes by utilizing a dynamic proxy technology to obtain service codes of target database transactions.
Optionally, the computer executable instructions stored on the storage medium, when executed by the processor, said storing the cached data identification related to the target database transaction into a thread context, comprising:
Determining a target thread corresponding to the intercepted class function for operating the cache;
and writing the cached data identification into a thread context bound on the target thread.
Optionally, the computer executable instructions stored on the storage medium, when executed by the processor, delete the cache data corresponding to the cache data identifier, including:
if the second logic code is detected to run, intercepting a class function for operating transaction submission or rollback;
determining a database transaction identifier contained in the class function for operating transaction commit or rollback;
searching cache data corresponding to the cache data identifier in a local cache for each cache data identifier corresponding to the database transaction identifier;
deleting the searched cache data from the local cache, and deleting the cache data identifier stored in the thread context.
The storage medium in one or more embodiments of the present disclosure stores computer-executable instructions that, when executed by the processor, obtain a cache data identification associated with the target database transaction when the business code of the target database transaction is running; storing a cache data identifier related to a target database transaction; and if the target database transaction execution is completed, deleting the cache data corresponding to the stored cache data identifier. In one or more embodiments of the present disclosure, in the execution process of a database transaction, identification information of cache data related to the database transaction is recorded, so that after the database transaction is submitted or rolled back, cache data corresponding to the identification information of the cache data recorded for the database transaction is automatically deleted, so that when the cache data corresponding to the identification information needs to be queried, corresponding target data is automatically obtained from the database and stored in a local cache, so that the database and the data in the local cache can be ensured to be kept consistent, and a problem that errors occur in subsequent data operations due to inconsistent data in the database and the local cache is avoided.
In the 90 s of the 20 th century, improvements to one technology could clearly be distinguished as improvements in hardware (e.g., improvements to circuit structures such as diodes, transistors, switches, etc.) or software (improvements to the process flow). However, with the development of technology, many improvements of the current method flows can be regarded as direct improvements of hardware circuit structures. Designers almost always obtain corresponding hardware circuit structures by programming improved method flows into hardware circuits. Therefore, an improvement of a method flow cannot be said to be realized by a hardware entity module. For example, a programmable logic device (Programmable Logic Device, PLD) (e.g., field programmable gate array (Field Programmable Gate Array, FPGA)) is an integrated circuit whose logic function is determined by the programming of the device by a user. A designer programs to "integrate" a digital system onto a PLD without requiring the chip manufacturer to design and fabricate application-specific integrated circuit chips. Moreover, nowadays, instead of manually manufacturing integrated circuit chips, such programming is mostly implemented with "logic compiler" software, which is similar to the software compiler used in program development and writing, and the original code before being compiled is also written in a specific programming language, which is called hardware description language (Hardware Description Language, HDL), but also HDL is not only one, but a plurality of, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), confluence, CUPL (Cornell University Programming Language), HD Cal, JHDL (Java Hardware Description Language), lava, lola, my HDL, palam, RHDL (Ruby Hardware Description Language), etc., VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog are currently most commonly used. It will also be apparent to those skilled in the art that a hardware circuit implementing the logic method flow can be readily obtained by merely slightly programming the method flow into an integrated circuit using several of the hardware description languages described above.
The controller may be implemented in any suitable manner, for example, the controller may take the form of, for example, a microprocessor or processor and a computer readable medium storing computer readable program code (e.g., software or firmware) executable by the (micro) processor, logic gates, switches, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable logic controllers, and embedded microcontrollers, examples of which include, but are not limited to, the following microcontrollers: ARC 625D, atmel AT91SAM, microchip PIC18F26K20, and Silicone Labs C8051F320, the memory controller may also be implemented as part of the control logic of the memory. Those skilled in the art will also appreciate that, in addition to implementing the controller in a pure computer readable program code, it is well possible to implement the same functionality by logically programming the method steps such that the controller is in the form of logic gates, switches, application specific integrated circuits, programmable logic controllers, embedded microcontrollers, etc. Such a controller may thus be regarded as a kind of hardware component, and means for performing various functions included therein may also be regarded as structures within the hardware component. Or even means for achieving the various functions may be regarded as either software modules implementing the methods or structures within hardware components.
The system, apparatus, module or unit set forth in the above embodiments may be implemented in particular by a computer chip or entity, or by a product having a certain function. One typical implementation is a computer. In particular, the computer may be, for example, a personal computer, a laptop computer, a cellular telephone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
For convenience of description, the above devices are described as being functionally divided into various units, respectively. Of course, the functions of each element may be implemented in one or more software and/or hardware elements when one or more of the present description are implemented.
One skilled in the relevant art will recognize that one or more of the embodiments of the present description may be provided as a method, system, or computer program product. Accordingly, one or more of the present specification may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, one or more of the present description can take the form of a computer program product on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
One or more of the present description is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to one or more embodiments of the specification. It will be understood that each flow and/or block of the flowchart illustrations and/or block diagrams, and combinations of flows and/or blocks in the flowchart illustrations and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
In one typical configuration, a computing device includes one or more processors (CPUs), input/output interfaces, network interfaces, and memory.
The memory may include volatile memory in a computer-readable medium, random Access Memory (RAM) and/or nonvolatile memory, such as Read Only Memory (ROM) or flash memory (flash RAM). Memory is an example of computer-readable media.
Computer readable media, including both non-transitory and non-transitory, removable and non-removable media, may implement information storage by any method or technology. The information may be computer readable instructions, data structures, modules of a program, or other data. Examples of storage media for a computer include, but are not limited to, phase change memory (PRAM), static Random Access Memory (SRAM), dynamic Random Access Memory (DRAM), other types of Random Access Memory (RAM), read Only Memory (ROM), electrically Erasable Programmable Read Only Memory (EEPROM), flash memory or other memory technology, compact disc read only memory (CD-ROM), digital Versatile Discs (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices, or any other non-transmission medium, which can be used to store information that can be accessed by a computing device. Computer-readable media, as defined herein, does not include transitory computer-readable media (transmission media), such as modulated data signals and carrier waves.
It should also be noted that the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising one … …" does not exclude the presence of other like elements in a process, method, article or apparatus that comprises the element.
One skilled in the relevant art will recognize that one or more of the embodiments of the present description may be provided as a method, system, or computer program product. Accordingly, one or more of the present specification may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, one or more of the present description can take the form of a computer program product on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, etc.) having computer-usable program code embodied therein.
One or more of the present description may be described in the general context of computer-executable instructions, such as program modules, being executed by a computer. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform particular tasks or implement particular abstract data types. One or more of the present description may also be practiced in distributed computing environments where tasks are performed by remote processing devices that are linked through a communications network. In a distributed computing environment, program modules may be located in both local and remote computer storage media including memory storage devices.
In this specification, each embodiment is described in a progressive manner, and identical and similar parts of each embodiment are all referred to each other, and each embodiment mainly describes differences from other embodiments. In particular, for system embodiments, since they are substantially similar to method embodiments, the description is relatively simple, as relevant to see a section of the description of method embodiments.
The foregoing description is merely illustrative of one or more embodiments of the present disclosure and is not intended to limit the one or more embodiments of the present disclosure. Various modifications and alterations to one or more of this description will become apparent to those skilled in the art. Any modifications, equivalent substitutions, improvements, or the like, which are within the spirit and principles of one or more of the present description, are intended to be included within the scope of the claims of one or more of the present description.

Claims (18)

1. A database transaction method, comprising:
when a business code of a target database transaction runs, acquiring a cache data identifier related to the target database transaction, wherein the cache data identifier related to the target database transaction comprises: the cached data identifier corresponding to the cached business data in the target database operated by the target database transaction when the target database transaction is executed;
storing the cache data identifier related to the target database transaction;
and if the target database transaction execution is completed, deleting the cache data corresponding to the cache data identifier, so that when the cache data corresponding to the cache data identifier is queried, the corresponding target data is automatically acquired from the database and stored in the local cache.
2. The method of claim 1, further comprising:
and utilizing a dynamic proxy technology to weave target logic codes into byte codes of target database transactions to obtain service codes of the target database transactions, wherein the target logic codes comprise: a first logic code for implementing an intercept cache operation and a second logic code for implementing an intercept transaction commit or rollback.
3. The method of claim 2, wherein the obtaining the cached data identity to which the target database transaction relates comprises:
if the first logic code is detected to run, intercepting class functions for operating the cache;
determining a cache data identifier contained in the class function for operating the cache;
and using the cache data identifier as the cache data identifier related to the target database transaction.
4. A method according to claim 3, wherein said storing said cached data identity to which said target database transaction relates comprises:
and storing the cached data identifier related to the target database transaction into a thread context.
5. The method of claim 2, wherein the step of using the dynamic proxy technique to weave the target logical code into the bytecode of the target database transaction to obtain the service code of the target database transaction includes:
when compiling the source code of the target database transaction to obtain a byte code, adding a target logic code into the byte code by utilizing a dynamic proxy technology to obtain the service code of the target database transaction.
6. The method of claim 2, wherein the step of using the dynamic proxy technique to weave the target logical code into the bytecode of the target database transaction to obtain the service code of the target database transaction includes:
Compiling a source code of a target database transaction to obtain a byte code of the target database transaction;
and when the byte codes are operated, adding target logic codes into the byte codes by utilizing a dynamic proxy technology to obtain service codes of target database transactions.
7. The method of claim 4, wherein said storing the cached data identification referred to by the target database transaction into a thread context comprises:
determining a target thread corresponding to the intercepted class function for operating the cache;
and writing the cached data identification into a thread context bound on the target thread.
8. The method of claim 4, wherein the deleting the cached data corresponding to the cached data identifier comprises:
if the second logic code is detected to run, intercepting a class function for operating transaction submission or rollback;
determining a database transaction identifier contained in the class function for operating transaction commit or rollback;
searching cache data corresponding to the cache data identifier in a local cache for each cache data identifier corresponding to the database transaction identifier;
Deleting the searched cache data from the local cache, and deleting the cache data identifier stored in the thread context.
9. A database transaction processing apparatus, comprising:
the cache identification acquisition module is used for acquiring a cache data identification related to a target database transaction when a service code of the target database transaction runs, wherein the cache data identification related to the target database transaction comprises: the cached data identifier corresponding to the cached business data in the target database operated by the target database transaction when the target database transaction is executed;
the cache identification storage module is used for storing the cache data identification related to the target database transaction;
and the cache data deleting module is used for deleting the cache data corresponding to the cache data identifier if the target database transaction execution is completed, so that when the cache data corresponding to the cache data identifier is queried, the corresponding target data is automatically acquired from the database and stored in the local cache.
10. The apparatus of claim 9, further comprising a service code generation module to:
and utilizing a dynamic proxy technology to weave target logic codes into byte codes of target database transactions to obtain service codes of the target database transactions, wherein the target logic codes comprise: a first logic code for implementing an intercept cache operation and a second logic code for implementing an intercept transaction commit or rollback.
11. The apparatus of claim 10, wherein the cache identifier obtaining module is specifically configured to:
if the first logic code is detected to run, intercepting class functions for operating the cache;
determining a cache data identifier contained in the class function for operating the cache;
and using the cache data identifier as the cache data identifier related to the target database transaction.
12. The apparatus of claim 11, wherein the cache identity storage module is specifically configured to:
and storing the cached data identifier related to the target database transaction into a thread context.
13. The apparatus of claim 10, wherein the service code generation module is specifically configured to:
when compiling the source code of the target database transaction to obtain a byte code, adding a target logic code into the byte code by utilizing a dynamic proxy technology to obtain the service code of the target database transaction.
14. The apparatus of claim 10, wherein the service code generation module is further specifically configured to:
compiling a source code of a target database transaction to obtain a byte code of the target database transaction;
And when the byte codes are operated, adding target logic codes into the byte codes by utilizing a dynamic proxy technology to obtain service codes of target database transactions.
15. The apparatus of claim 12, wherein the cache identity storage module is further specifically configured to:
determining a target thread corresponding to the intercepted class function for operating the cache;
and writing the cached data identification into a thread context bound on the target thread.
16. The apparatus of claim 12, wherein the cache data deletion module is specifically configured to:
if the second logic code is detected to run, intercepting a class function for operating transaction submission or rollback;
determining a database transaction identifier contained in the class function for operating transaction commit or rollback;
searching cache data corresponding to the cache data identifier in a local cache for each cache data identifier corresponding to the database transaction identifier;
deleting the searched cache data from the local cache, and deleting the cache data identifier stored in the thread context.
17. A database transaction processing device, comprising:
A processor; and
a memory arranged to store computer executable instructions that, when executed, cause the processor to:
when a business code of a target database transaction runs, acquiring a cache data identifier related to the target database transaction, wherein the cache data identifier related to the target database transaction comprises: the cached data identifier corresponding to the cached business data in the target database operated by the target database transaction when the target database transaction is executed;
storing the cache data identifier related to the target database transaction;
and if the target database transaction execution is completed, deleting the cache data corresponding to the cache data identifier, so that when the cache data corresponding to the cache data identifier is queried, the corresponding target data is automatically acquired from the database and stored in the local cache.
18. A storage medium storing computer-executable instructions that when executed implement the following:
when a business code of a target database transaction runs, acquiring a cache data identifier related to the target database transaction, wherein the cache data identifier related to the target database transaction comprises: the cached data identifier corresponding to the cached business data in the target database operated by the target database transaction when the target database transaction is executed;
Storing the cache data identifier related to the target database transaction;
and if the target database transaction execution is completed, deleting the cache data corresponding to the cache data identifier, so that when the cache data corresponding to the cache data identifier is queried, the corresponding target data is automatically acquired from the database and stored in the local cache.
CN201910176345.5A 2019-03-08 2019-03-08 Database transaction processing method and device Active CN110008224B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910176345.5A CN110008224B (en) 2019-03-08 2019-03-08 Database transaction processing method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910176345.5A CN110008224B (en) 2019-03-08 2019-03-08 Database transaction processing method and device

Publications (2)

Publication Number Publication Date
CN110008224A CN110008224A (en) 2019-07-12
CN110008224B true CN110008224B (en) 2023-08-11

Family

ID=67166683

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910176345.5A Active CN110008224B (en) 2019-03-08 2019-03-08 Database transaction processing method and device

Country Status (1)

Country Link
CN (1) CN110008224B (en)

Families Citing this family (17)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110955539A (en) * 2019-11-26 2020-04-03 杭州迪普信息技术有限公司 Process quitting method and device, electronic equipment and machine-readable storage medium
CN111062684B (en) * 2019-11-29 2023-10-20 普元信息技术股份有限公司 System and method for realizing consistency processing of business data and process data under cloud process platform
CN111177197B (en) * 2019-12-26 2023-03-14 北京仁科互动网络技术有限公司 Cache processing method and system
CN111367718B (en) * 2020-02-26 2023-05-02 上海达梦数据库有限公司 Database starting method, device, equipment and storage medium
CN111526184B (en) * 2020-04-07 2022-07-29 中国建设银行股份有限公司 Business auditing method and device
CN111930478A (en) * 2020-06-08 2020-11-13 北京每日优鲜电子商务有限公司 Service calling method and device based on dynamic bytecode
CN111737331B (en) * 2020-06-22 2023-08-18 中国银行股份有限公司 Transaction consistency processing method and system for database and object storage
CN111797015B (en) * 2020-06-30 2024-02-09 中国工商银行股份有限公司 Dynamic byte code based test method and device
CN112199391B (en) * 2020-09-30 2024-02-23 深圳前海微众银行股份有限公司 Data locking detection method, equipment and computer readable storage medium
CN112463810A (en) * 2020-12-08 2021-03-09 佳讯飞鸿(北京)智能科技研究院有限公司 Data processing method, device, equipment and storage medium based on distributed transaction
CN112559570A (en) * 2020-12-16 2021-03-26 中国平安财产保险股份有限公司 Cache data acquisition method, device, equipment and storage medium
CN112540834B (en) * 2020-12-18 2023-04-14 郑州阿帕斯数云信息科技有限公司 Cache processing method, device and equipment in distributed transaction
CN113761077B (en) * 2021-01-04 2023-11-03 北京京东振世信息技术有限公司 Method and device for processing bill task
CN113010495B (en) * 2021-03-19 2023-01-06 北京三快在线科技有限公司 Database optimization method and device
CN113094430B (en) * 2021-03-25 2023-10-03 北京达佳互联信息技术有限公司 Data processing method, device, equipment and storage medium
CN113254425B (en) * 2021-06-24 2022-01-11 阿里云计算有限公司 Method, apparatus, system, program and storage medium for database transaction retention
CN117193670B (en) * 2023-11-06 2024-01-30 之江实验室 Method and device for clearing cache, storage medium and electronic equipment

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6272602B1 (en) * 1999-03-08 2001-08-07 Sun Microsystems, Inc. Multiprocessing system employing pending tags to maintain cache coherence
CN106294607A (en) * 2016-07-29 2017-01-04 北京奇虎科技有限公司 Data cached update method and updating device
CN106815329A (en) * 2016-12-29 2017-06-09 网易无尾熊(杭州)科技有限公司 A kind of data cached update method and device
CN108958955A (en) * 2018-07-06 2018-12-07 美利车(北京)网络技术有限公司 A kind of transaction methods and device based on message-driven

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6272602B1 (en) * 1999-03-08 2001-08-07 Sun Microsystems, Inc. Multiprocessing system employing pending tags to maintain cache coherence
CN106294607A (en) * 2016-07-29 2017-01-04 北京奇虎科技有限公司 Data cached update method and updating device
CN106815329A (en) * 2016-12-29 2017-06-09 网易无尾熊(杭州)科技有限公司 A kind of data cached update method and device
CN108958955A (en) * 2018-07-06 2018-12-07 美利车(北京)网络技术有限公司 A kind of transaction methods and device based on message-driven

Also Published As

Publication number Publication date
CN110008224A (en) 2019-07-12

Similar Documents

Publication Publication Date Title
CN110008224B (en) Database transaction processing method and device
EP3547240A1 (en) Block chain-based data storage and query method and device
US20200273034A1 (en) Payment process configuration and execution method, apparatus and device
US20200293494A1 (en) Data synchronization methods, apparatuses, and devices
CN110134668B (en) Data migration method, device and equipment applied to blockchain
CN108628688B (en) Message processing method, device and equipment
CN110989939A (en) Data cache processing method, device and equipment and cache component
CN108415792B (en) Disaster recovery system, method, device and equipment
CN108615184B (en) Accounting method and device
CN110263050B (en) Data processing method, device, equipment and storage medium
WO2023160289A1 (en) Mini-program storage call
CN111861454B (en) Method and device for displaying unique identifier of digital object
CN110399359B (en) Data backtracking method, device and equipment
CN108647112B (en) Data backup method and device and distributed transaction processing system
CN116048977B (en) Test method and device based on data reduction
CN113254163B (en) Processing method and device of block chain data
CN111339117B (en) Data processing method, device and equipment
CN115391337A (en) Database partitioning method and device, storage medium and electronic equipment
CN112286572A (en) Configuration method and device of business process
CN112699129A (en) Data processing system, method and device
US11474837B2 (en) Method and apparatus for efficient programming of electronic payment processing
CN107645541B (en) Data storage method and device and server
CN112434486B (en) Automatic paging method, device, equipment and medium for device in PCB design
CN116541407B (en) Data processing method and device, storage medium and electronic equipment
CN109408497B (en) Data rendering method, device and equipment

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
TA01 Transfer of patent application right
TA01 Transfer of patent application right

Effective date of registration: 20200923

Address after: Cayman Enterprise Centre, 27 Hospital Road, George Town, Grand Cayman, British Islands

Applicant after: Advanced innovation technology Co.,Ltd.

Address before: A four-storey 847 mailbox in Grand Cayman Capital Building, British Cayman Islands

Applicant before: Alibaba Group Holding Ltd.

Effective date of registration: 20200923

Address after: Cayman Enterprise Centre, 27 Hospital Road, George Town, Grand Cayman, British Islands

Applicant after: Innovative advanced technology Co.,Ltd.

Address before: Cayman Enterprise Centre, 27 Hospital Road, George Town, Grand Cayman, British Islands

Applicant before: Advanced innovation technology Co.,Ltd.

GR01 Patent grant
GR01 Patent grant