[go: up one dir, main page]
More Web Proxy on the site http://driver.im/

CN111209142B - Cross-database transaction management method, device, equipment and storage medium - Google Patents

Cross-database transaction management method, device, equipment and storage medium Download PDF

Info

Publication number
CN111209142B
CN111209142B CN202010000435.1A CN202010000435A CN111209142B CN 111209142 B CN111209142 B CN 111209142B CN 202010000435 A CN202010000435 A CN 202010000435A CN 111209142 B CN111209142 B CN 111209142B
Authority
CN
China
Prior art keywords
data
executed
transaction
transactions
preset
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
CN202010000435.1A
Other languages
Chinese (zh)
Other versions
CN111209142A (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.)
Ping An Property and Casualty Insurance Company of China Ltd
Original Assignee
Ping An Property and Casualty Insurance Company of China 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 Ping An Property and Casualty Insurance Company of China Ltd filed Critical Ping An Property and Casualty Insurance Company of China Ltd
Priority to CN202010000435.1A priority Critical patent/CN111209142B/en
Publication of CN111209142A publication Critical patent/CN111209142A/en
Application granted granted Critical
Publication of CN111209142B publication Critical patent/CN111209142B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/07Responding to the occurrence of a fault, e.g. fault tolerance
    • G06F11/14Error detection or correction of the data by redundancy in operation
    • G06F11/1402Saving, restoring, recovering or retrying
    • G06F11/1446Point-in-time backing up or restoration of persistent data
    • G06F11/1448Management of the data involved in backup or backup restore
    • 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/2308Concurrency control
    • G06F16/2336Pessimistic concurrency control approaches, e.g. locking or multiple versions without time stamps
    • G06F16/2343Locking methods, e.g. distributed locking or locking implementation details
    • 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

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • Databases & Information Systems (AREA)
  • Computer Security & Cryptography (AREA)
  • Quality & Reliability (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention relates to the technical field of computers, and discloses a method, a device, equipment and a storage medium for managing transaction across databases, which are used for rollback and submitting distributed transactions according to a transaction mechanism and backup data, so as to ensure the correctness of the rollback data and the consistency of the distributed transactions across databases. The transaction management method across databases comprises the following steps: determining data operation sentences of a plurality of databases from a preset mapping object file, and configuring a first mapping label and a second mapping label for the data operation sentences to obtain a plurality of transactions to be executed; executing a plurality of transactions to be executed to obtain backup data; when all the transactions to be executed are detected to be successfully executed, submitting all the transactions; when detecting that any one of the plurality of transactions to be executed fails to execute, rolling back the transaction which fails to execute according to the backup data to obtain rolled back data, verifying the rolled back data according to the backup data, and performing data processing according to a verification result.

Description

Cross-database transaction management method, device, equipment and storage medium
Technical Field
The present invention relates to the field of computer technologies, and in particular, to a method, an apparatus, a device, and a storage medium for transaction management across databases.
Background
Database transactions typically include a sequence of read/write operations to the database that restore the sequence of database operations from failed to normal while ensuring that consistency is maintained in the abnormal state of the database. And provides an isolation between applications to prevent mutual interference when multiple applications are concurrently accessing the database.
Under the condition that a plurality of cross-database business requests are concurrent, the non-synchronous operation mode is adopted, the data inconsistency of the whole target database system is easy to be caused, if the distributed transaction processing interface XA transaction management mode is adopted, the performance is low, the distributed transaction processing interface XA transaction management mode can only be applied to a homologous database, the XA transaction cannot be configured in a heterogeneous database, and the data reduction is carried out through binary log files binlog or relaylog, so that the processing efficiency of the business requests is reduced.
Disclosure of Invention
The invention mainly aims to solve the technical problems that XA transactions cannot be configured in a heterogeneous database, and the processing efficiency of service requests is reduced due to data reduction through binary log files.
To achieve the above object, a first aspect of the present invention provides a transaction management method across databases, including: determining data operation sentences of a plurality of databases from a preset mapping object file, and configuring a first mapping label and a second mapping label for the data operation sentences of the plurality of databases to obtain a plurality of transactions to be executed, wherein the first mapping label is used for indicating triggering data backup, and the second mapping label is used for indicating triggering data rollback; executing the plurality of transactions to be executed through preliminary operations in a preset transaction mechanism to obtain backup data, wherein the preset transaction mechanism comprises the preliminary operations, the cancel operations and the confirm operations; when all the transactions to be executed are detected to be successfully executed, submitting all the successfully executed transactions through the confirmation operation; when detecting that any one of the plurality of transactions to be executed fails to execute, rollback the executed transaction according to the backup data through the cancel operation to obtain rollback data, and verifying the rollback data according to the backup data to obtain a verification result; judging whether the verification result is equal to a target value or not; if the verification result is equal to the target value, determining the rest executed transaction, and carrying out data rollback on the rest executed transaction according to the backup data; and if the verification result is not equal to the target value, determining difference data, and carrying out data recovery on the difference data according to the backup data.
Optionally, in a first implementation manner of the first aspect of the present invention, the determining data operation statements of a plurality of databases from a preset mapping object file, and configuring a first mapping tag and a second mapping tag for the data operation statements of the plurality of databases to obtain a plurality of transactions to be executed, where the first mapping tag is used to indicate triggering data backup, and the second mapping tag is used to indicate triggering data rollback, and includes: deploying a preset project framework to obtain a preset mapping object file; configuring connection information of a plurality of databases and data operation sentences of the databases in the preset mapping object file, wherein the data operation sentences of the databases are used for indicating to correlate with different function names of preset interface classes according to a first preset attribute; adding a first mapping tag into data operation sentences of the databases, and associating the first mapping tag with a preset query sentence according to a second preset attribute, wherein the first mapping tag is used for indicating triggering data backup; adding the second mapping tag to the data operation sentences of the databases, wherein the second mapping tag is used for indicating triggering data rollback; and reloading the preset mapping object file to obtain a plurality of transactions to be executed.
Optionally, in a second implementation manner of the first aspect of the present invention, the executing the plurality of transactions to be executed through a preliminary operation in a preset transaction mechanism to obtain backup data, where the preset transaction mechanism includes a preliminary operation, a cancel operation, and a confirm operation includes: reading connection information of the databases and the plurality of transactions to be executed from the preset mapping object file; connecting to the databases according to preset connection classes and connection information of the databases; executing the plurality of transactions to be executed through preliminary operations in a preset transaction mechanism to obtain backup data, and adding distributed transaction locks to the plurality of transactions to be executed, wherein the preset transaction mechanism comprises the preliminary operations, the confirmation operations and the cancellation operations.
Optionally, in a third implementation manner of the first aspect of the present invention, the executing the plurality of transactions to be executed through a preliminary operation in a preset transaction mechanism, to obtain backup data, and adding a distributed transaction lock to the plurality of transactions to be executed, where the preset transaction mechanism includes the preliminary operation, the confirmation operation, and the cancellation operation includes: executing the plurality of transactions to be executed one by one according to different function names of the preset interface class through preliminary operation in a preset transaction mechanism to obtain unique identifiers of the transactions, wherein the preset transaction mechanism comprises the preliminary operation, a confirmation operation and a cancellation operation; executing a preset query statement corresponding to the first mapping tag to obtain backup data; setting the unique identification of the transaction and the backup data into a target key value pair, and storing the target key value pair into a cache; and adding distributed transaction locks to the plurality of transactions to be executed, and executing data operation sentences of the plurality of databases.
Optionally, in a fourth implementation manner of the first aspect of the present invention, when detecting that any one of the plurality of transactions to be executed fails to execute, rolling back the executed transaction according to the backup data through the cancel operation to obtain rolled-back data, and verifying the rolled-back data according to the backup data, where obtaining a verification result includes: when detecting that any one of the plurality of transactions to be executed fails to be executed, acquiring the backup data according to the unique identifier of the transaction through the cancel operation; rollback the executed transaction according to the backup data, and releasing the distributed transaction lock to obtain the rollback data; and carrying out data consistency verification on the rolled-back data and the backup data to obtain a verification result.
Optionally, in a fifth implementation manner of the first aspect of the present invention, when detecting that all the plurality of transactions to be executed are executed successfully, submitting all the transactions that are executed successfully through the confirmation operation includes: when all the transactions to be executed are detected to be executed successfully, acquiring unique identifiers of all the successful transactions through the confirmation operation; submitting the transaction according to the unique identification of all the successful transactions to obtain a submitting state; judging whether the submitting state is a successful state or not; triggering the release operation of the distributed transaction lock if the commit status is a successful status; and if the commit status is the failure status, re-committing the transaction in the failure status, and counting the commit times until the commit times are not less than preset times or the commit status is the success status.
Optionally, in a sixth implementation manner of the first aspect of the present invention, after the submitting, by the confirmation operation, all the transactions that are executed successfully when it is detected that all the transactions to be executed are executed successfully, the transaction management method across databases further includes: acquiring different execution states of the transaction to be executed, wherein the different execution states comprise an execution success state of the transaction and an execution failure state of the transaction; recording the successful execution state of the transaction and the failed execution state of the transaction into a preset transaction log according to the unique identification of the transaction; and sending preset alarm information to the execution failure state of the transaction.
A second aspect of the present invention provides a transaction management device across databases, comprising: the configuration unit is used for determining data operation sentences of a plurality of databases from a preset mapping object file, configuring a first mapping label and a second mapping label for the data operation sentences of the plurality of databases to obtain a plurality of transactions to be executed, wherein the first mapping label is used for indicating triggering data backup, and the second mapping label is used for indicating triggering data rollback; the execution unit is used for executing the plurality of transactions to be executed through preliminary operations in a preset transaction mechanism to obtain backup data, wherein the preset transaction mechanism comprises the preliminary operations, the cancel operations and the confirm operations; a commit unit, configured to commit all the transactions that are executed successfully through the confirmation operation when all the transactions to be executed are detected to be executed successfully; the rollback verification unit is used for rollback the executed transaction according to the backup data through the cancel operation to obtain rollback data when detecting that any one of the plurality of transactions to be executed fails to execute, and verifying the rollback data according to the backup data to obtain a verification result; a judging unit for judging whether the verification result is equal to the target value; the processing unit is used for determining the rest of executed transactions and carrying out data rollback on the rest of executed transactions according to the backup data if the verification result is equal to the target value; and the recovery unit is used for determining difference data and carrying out data recovery on the difference data according to the backup data if the verification result is not equal to the target value.
Optionally, in a first implementation manner of the second aspect of the present invention, the configuration unit is specifically configured to: deploying a preset project framework to obtain a preset mapping object file; configuring connection information of a plurality of databases and data operation sentences of the databases in the preset mapping object file, wherein the data operation sentences of the databases are used for indicating to correlate with different function names of preset interface classes according to a first preset attribute; adding a first mapping tag into data operation sentences of the databases, and associating the first mapping tag with a preset query sentence according to a second preset attribute, wherein the first mapping tag is used for indicating triggering data backup; adding the second mapping tag to the data operation sentences of the databases, wherein the second mapping tag is used for indicating triggering data rollback; and reloading the preset mapping object file to obtain a plurality of transactions to be executed.
Optionally, in a second implementation manner of the second aspect of the present invention, the execution unit further includes: a reading subunit, configured to read connection information of the plurality of databases and the plurality of transactions to be executed from the preset mapping object file; a connection subunit, configured to connect to the plurality of databases according to a preset connection class and connection information of the plurality of databases; and the execution subunit is used for executing the plurality of transactions to be executed through the preliminary operation in a preset transaction mechanism to obtain backup data and adding a distributed transaction lock to the plurality of transactions to be executed, wherein the preset transaction mechanism comprises the preliminary operation, the confirmation operation and the cancellation operation.
Optionally, in a third implementation manner of the second aspect of the present invention, the execution subunit is specifically configured to: executing the plurality of transactions to be executed one by one according to different function names of the preset interface class through preliminary operation in a preset transaction mechanism to obtain unique identifiers of the transactions, wherein the preset transaction mechanism comprises the preliminary operation, a confirmation operation and a cancellation operation; executing a preset query statement corresponding to the first mapping tag to obtain backup data; setting the unique identification of the transaction and the backup data into a target key value pair, and storing the target key value pair into a cache; and adding distributed transaction locks to the plurality of transactions to be executed, and executing data operation sentences of the plurality of databases.
Optionally, in a fourth implementation manner of the second aspect of the present invention, the rollback verification unit is specifically configured to: when detecting that any one of the plurality of transactions to be executed fails to be executed, acquiring the backup data according to the unique identifier of the transaction through the cancel operation; rollback the executed transaction according to the backup data, and releasing the distributed transaction lock to obtain the rollback data; and carrying out data consistency verification on the rolled-back data and the backup data to obtain a verification result.
Optionally, in a fifth implementation manner of the second aspect of the present invention, the submitting unit is specifically configured to: when all the transactions to be executed are detected to be executed successfully, acquiring unique identifiers of all the successful transactions through the confirmation operation; submitting the transaction according to the unique identification of all the successful transactions to obtain a submitting state; judging whether the submitting state is a successful state or not; triggering the release operation of the distributed transaction lock if the commit status is a successful status; and if the commit status is the failure status, re-committing the transaction in the failure status, and counting the commit times until the commit times are not less than preset times or the commit status is the success status.
Optionally, in a sixth implementation manner of the second aspect of the present invention, the transaction management device across databases further includes: the acquisition unit is used for acquiring different execution states of the transaction to be executed, wherein the different execution states comprise an execution success state of the transaction and an execution failure state of the transaction; the recording unit is used for recording the execution success state of the transaction and the execution failure state of the transaction into a preset transaction log according to the unique identifier of the transaction; and the sending unit is used for sending preset alarm information to the execution failure state of the transaction.
A third aspect of the present invention provides a transaction management device across databases, comprising: the system comprises a memory and at least one processor, wherein instructions are stored in the memory, and the memory and the at least one processor are interconnected through a line; the at least one processor invokes the instructions in the memory to cause the cross-database transaction management device to perform the method of the first aspect described above.
A fourth aspect of the invention provides a computer readable storage medium having instructions stored therein which, when run on a computer, cause the computer to perform the method of the first aspect described above.
From the above technical scheme, the invention has the following advantages:
In the technical scheme provided by the invention, data operation sentences of a plurality of databases are determined from a preset mapping object file, and a first mapping label and a second mapping label are configured for the data operation sentences of the plurality of databases to obtain a plurality of transactions to be executed, wherein the first mapping label is used for indicating triggering data backup, and the second mapping label is used for indicating triggering data rollback; executing the plurality of transactions to be executed through preliminary operations in a preset transaction mechanism to obtain backup data, wherein the preset transaction mechanism comprises the preliminary operations, the cancel operations and the confirm operations; when all the transactions to be executed are detected to be successfully executed, submitting all the successfully executed transactions through the confirmation operation; when detecting that any one of the plurality of transactions to be executed fails to execute, rollback the executed transaction according to the backup data through the cancel operation to obtain rollback data, and verifying the rollback data according to the backup data to obtain a verification result; judging whether the verification result is equal to a target value or not; if the verification result is equal to the target value, determining the rest executed transaction, and carrying out data rollback on the rest executed transaction according to the backup data; and if the verification result is not equal to the target value, determining difference data, and carrying out data recovery on the difference data according to the backup data. In the embodiment of the invention, the backup data is obtained by configuring and executing the distributed mapping object files crossing the database, and the data rollback verification and the transaction submission are carried out on the distributed transaction according to the transaction mechanism and the backup data, so that the correctness of the rollback data and the consistency of a plurality of service data which are concurrently requested by the database crossing services are ensured.
Drawings
FIG. 1 is a diagram of one embodiment of a method of transaction management across databases in an embodiment of the present invention;
FIG. 2 is a diagram of another embodiment of a method of transaction management across databases in an embodiment of the present invention;
FIG. 3 is a schematic diagram of one embodiment of a transaction management device across databases in an embodiment of the present invention;
FIG. 4 is a schematic diagram of another embodiment of a transaction management device across databases in an embodiment of the present invention;
FIG. 5 is a schematic diagram of one embodiment of a transaction management device across databases in an embodiment of the invention.
Detailed Description
The embodiment of the invention provides a cross-database transaction management method, device, equipment and storage medium, which are used for obtaining backup data by configuring and executing a cross-database distributed mapping object file, carrying out data rollback verification and transaction submission on distributed transactions according to a transaction mechanism and the backup data, and ensuring the correctness of rollback data and the consistency of a plurality of cross-database service concurrent request service data.
In order to enable those skilled in the art to better understand the present invention, embodiments of the present invention will be described below with reference to the accompanying drawings.
The terms "first," "second," "third," "fourth" and the like in the description and in the claims and in the above drawings, if any, are used for distinguishing between similar objects and not necessarily for describing a particular sequential or chronological order. It is to be understood that the data so used may be interchanged where appropriate such that the embodiments described herein may be implemented in other sequences than those illustrated or otherwise described herein. Furthermore, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, system, article, or apparatus that comprises a list of steps or elements is not necessarily limited to those steps or elements expressly listed or inherent to such process, method, article, or apparatus.
For ease of understanding, a specific flow of an embodiment of the present invention is described below with reference to fig. 1, where an embodiment of a method for transaction management across databases in an embodiment of the present invention includes:
101. Determining data operation sentences of a plurality of databases from a preset mapping object file, configuring a first mapping label and a second mapping label for the data operation sentences of the plurality of databases to obtain a plurality of transactions to be executed, wherein the first mapping label is used for indicating triggering data backup, and the second mapping label is used for indicating triggering data rollback;
The server determines data operation sentences of a plurality of databases from a preset mapping object file, configures a first mapping label and a second mapping label for the data operation sentences of the plurality of databases to obtain a plurality of to-be-executed transactions, wherein the first mapping label is used for indicating triggering data backup, and the second mapping label is used for indicating triggering data rollback. The preset mapping object file is a mapper file, for example, mapper. The data operation statements include add operation statements, delete operation statements, and update operation statements, i.e., the data operation statements include insert tags, delete tags, and update tags. The first mapped label is a prior before label and the second mapped label is a rollback label. That is, the before tag and the rollback tag are pre-configured in the context of insert tags, delete tags, and update tags of multiple databases in the mapper.
102. Executing a plurality of transactions to be executed through preliminary operations in a preset transaction mechanism to obtain backup data, wherein the preset transaction mechanism comprises the preliminary operations, the cancel operations and the confirm operations;
The server executes a plurality of transactions to be executed through preliminary operations in a preset transaction mechanism to obtain backup data, wherein the preset transaction mechanism comprises the preliminary operations, the cancel operations and the confirm operations. The method comprises the steps that a primary operation is a try statement block, a preset transaction mechanism is a TCC transaction mechanism, a server tries to execute database connection, buffer backup data and apply for a distributed transaction lock according to the try statement block, data of a plurality of databases are logically locked, and further, when it is determined that data operations related to at least two transactions belong to different databases, the server generates an insertion statement of the distributed transaction lock; and the server executes the inserted statement of the distributed transaction lock to obtain the distributed transaction lock. For example, the server logically locks the data corresponding to the a library and the data corresponding to the B library, so as to ensure the consistency of the transaction.
It can be understood that the server generates the unique identifier of the transaction in the try statement block according to the prefabrication rule, sets the unique identifier of the transaction and the backup data as a target key value pair, and stores the target key value pair into the cache.
103. When all the transactions to be executed are detected to be successfully executed, submitting all the successfully executed transactions through a confirmation operation;
When all the transactions to be executed are detected to be successfully executed, submitting the transaction with the successful execution through a confirmation operation. The method comprises the steps that a confirmation operation is a confirm statement block, specifically, when all execution success of a plurality of to-be-executed transactions is detected, a server submits all the execution success through the confirmation operation, and a submitting state is obtained; when the submitting state is a successful state, the server triggers the release operation of the distributed transaction lock; when the commit status is the failure status, the server resubmits the transaction in the failure status and counts the commit times until the commit times are not less than the preset times or the commit status is the success status.
The server executes the incomplete items of the preliminary operation by executing the confirm statement blocks designated by the preliminary operation one by one. For example, if account A, B, C is a normally-in-state account and the balance of accounts a and B satisfy the preset conditions, the server performs a transfer operation from account a to account C and from account B to account C by 100 elements until both transfers are successful, and updates A, B and C stored account data for each, ensuring that the total amounts of the three accounts are equal before and after transfer, further ensuring that the transaction to be performed must be in a consistent state both before and after execution, and submitting the transaction ensures update data validity.
104. When detecting that any one of a plurality of transactions to be executed fails to be executed, rollback the executed transaction according to the backup data through cancelling operation to obtain rollback data, and verifying the rollback data according to the backup data;
when detecting that any one of the plurality of transactions to be executed fails to execute, the server rolls back the executed transaction according to the backup data through a cancel operation to obtain rolled-back data, and verifies the rolled-back data according to the backup data. The method comprises the steps that a cancel operation is a cancel statement block, specifically, when any one of a plurality of to-be-executed transactions is detected to fail execution, a server obtains backup data through the cancel operation, rolls back the executed transaction according to the backup data and releases a transaction lock to obtain rolled-back data; and the server performs data consistency verification on the rolled-back data and the backup data to obtain a verification result. For example, the statement is operated on for the following data:
update tmp set username = 'A1' where userid= '001'; - -marked A1
Update tmp set username = 'B1' where userid= '001'; marked B1
After the server rolls back to B1, all data modifications after B1 are considered invalid; the server rolls back to A1 again, where all data modifications after A1 are deemed invalid. The server rolls back all executed transactions through the backup data, namely, cancels all data modifications after the last submitted transaction.
It should be noted that, the executed transactions include a successful executed transaction and a failed executed transaction, and when a failed execution of the transaction is detected, the transaction is divided at the time of the execution failure.
105. Judging whether the verification result is equal to the target value;
The server judges whether the verification result is equal to the target value, for example, the target field value before the transaction is submitted is 3, the updated target field value is set to be 5, and because the transaction execution is abnormal, if the server rolls back the target field value to 5 according to the backup data, the server obtains the verification result to be 1, and if the target value is 1, the server determines that the verification result is equal to the target value, and the server executes step 106; if the server rolls back the target field value to 6 according to the backup data, the server obtains the verification result as 0 and the target value as 1, and determines that the verification result is not equal to the target value, and the server executes step 107.
106. If the verification result is equal to the target value, determining the remaining executed transactions, and carrying out data rollback on the remaining executed transactions according to the backup data;
if the verification result is equal to the target value, the server determines the remaining executed transactions, and performs data rollback on the remaining executed transactions according to the backup data. The remaining executed transactions are transaction sets obtained by removing rolled-back transactions from the executed transactions, for example, a server sequentially executes a transaction A and a transaction B, an exception occurs in the execution process of the transaction B, the server sequentially rolls back the transaction B and the transaction A according to backup data, a verification result C is obtained after the rolling back of the transaction B, and if the verification result C is equal to a target value, the server continues to roll back data on the remaining executed transaction A.
107. If the verification result is not equal to the target value, determining the difference data, carrying out data recovery on the difference data according to the backup data, and carrying out data rollback on the rest executed transactions after the data recovery is successful.
If the verification result is not equal to the target value, the server determines the difference data, performs data recovery on the difference data according to the backup data, and performs data rollback on the rest executed transactions after the data recovery is successful. For example, for the following statement:
update table name set target field name = value where primary key = primary key value;
the server adds a before tag and a rollback tag to the update tag, and the rollback tag is used for indicating that the statement is rolled back to backup data before the transaction is submitted. The target field value before the transaction is submitted is 3, the updated target field value is 5, but because of abnormal execution of the transaction, the server rolls back the target field value to 3, if the updated server detects that the target field value is 4, the server determines that difference data exists, and performs data recovery on the difference data 4 according to the backup data 2. It will be appreciated that the data rollback is performed on the remaining executed transactions after the data recovery is successful.
In the embodiment of the invention, the backup data is obtained by configuring and executing the distributed mapping object files crossing the database, and the data rollback verification and the transaction submission are carried out on the distributed transaction according to the transaction mechanism and the backup data, so that the correctness of the rollback data and the consistency of a plurality of service data which are concurrently requested by the database crossing services are ensured.
Referring to fig. 2, another embodiment of a transaction management method across databases in an embodiment of the present invention includes:
201. deploying a preset project framework to obtain a preset mapping object file;
The server deploys a preset project framework to obtain a preset mapping object file. The preset project framework comprises a persistence layer framework mybatis, a preset mapping object file is a mapper file, and a file format is identified in an xml form. Specifically, the server imports an installation package of a preset item frame, wherein the installation package comprises a jar package of mybatis; the server receives the jar packet installing command and executes the jar packet installing command; the server creates a mapping service interface; the server creates a database identifier and a dynamic data source, wherein the database identifier is used for indicating that each thread is stored by an independent object, and the dynamic data source is used for connecting different databases according to unused data indexes; the server creates an access object and an access task, the access task packages each request for accessing the database as an access object, writes the access object into a preset task management, waits for the execution of the task to be completed, and takes out an execution result, and further, the server executes the database access task through a preset thread pool; the server creates a mapper.xml file to obtain a preset mapping object file.
202. Configuring connection information of a plurality of databases and data operation sentences of the plurality of databases in a preset mapping object file, wherein the data operation sentences of the plurality of databases are used for indicating to correlate with different function names of preset interface classes according to a first preset attribute;
The server configures connection information of a plurality of databases and data operation sentences of the databases in a preset mapping object file, wherein the data operation sentences of the databases are used for indicating the association with different function names of preset interface classes according to a first preset attribute. Specifically, the server configures connection information of a plurality of databases in a preset mapping object file according to preset configuration information of the plurality of databases; the server configures data operation sentences of a plurality of databases in a preset mapping object file according to preset business and SQL grammar rules, wherein the data operation sentences of the plurality of databases comprise addition operation sentences, deletion operation sentences and update operation sentences of the plurality of databases. The preset mapping object file is a mapper configuration file, for example, a mapper. Xml configuration file or a configuration file in the form of a preset interface, which is not limited herein.
203. Adding a first mapping tag into data operation sentences of a plurality of databases, and associating the first mapping tag with a preset query sentence according to a second preset attribute, wherein the first mapping tag is used for indicating triggering data backup;
The server adds a first mapping tag into data operation sentences of a plurality of databases, associates the first mapping tag with a preset query sentence according to a second preset attribute, wherein the first mapping tag is used for indicating triggering data backup, and the first mapping tag is a prior before tag which is used for indicating caching data before the transaction to be executed is submitted. Further, the server confirms data operation sentences of a plurality of databases from a preset mapping object file, wherein the data operation sentences comprise update labels, insert labels and delete labels; the server acquires preset query sentences and adds first mapping labels for the data operation sentences of a plurality of databases; and the server associates the first mapping tag with the preset query statement according to the second preset attribute, wherein the first mapping tag is used for indicating triggering data backup. For example, a preset query statement that includes an identification id, and an attribute value of the identification id is querySegment, as follows:
<select id="querySegment">
select*from common_document_attachment WHERE document_id=#{documentId}
</select>
The server adds a before tag after the update starts the tag according to the preset query statement, and sets a backup identifier refid for before; the server sets the attribute value of the preset query statement identification id as the attribute value of refid; the server sets up an update statement. The method is specifically as follows:
204. Adding a second mapping tag to the data operation sentences of the databases, wherein the second mapping tag is used for indicating triggering data rollback;
The server adds a second mapping tag to the data operation sentences of the databases, wherein the second mapping tag is used for indicating to trigger data rollback, the second mapping tag is a rollback tag, the rollback tag is used for indicating that when the execution of the transaction across the databases fails, the data operation sentences of the databases configured with the before tag are rolled back according to cached backup data, and further the server adds the second mapping tag to the data operation sentences of the databases configured with the before tag is used for performing rollback operation when the update sentence is abnormal, for example, the server adds the rollback tag before the update end tag, and the method is as follows:
205. Reloading a preset mapping object file to obtain a plurality of transactions to be executed;
And reloading the preset mapping object file by the server to obtain a plurality of to-be-executed transactions. Specifically, restarting the service corresponding to the preset mapping object file by the server to obtain the reloaded preset mapping object file; the server confirms a first mapping label and a second mapping label from the reloaded preset mapping object file; the server determines that the second mapping tag is used for restoring backup data, and sets data operation sentences identified by the first mapping tag and the second mapping tag as a plurality of to-be-executed transactions.
It can be understood that after the mapper.xml file is modified, the service corresponding to the preset mapping object file is restarted according to the preset command, and the file modification can be effective.
206. Executing a plurality of transactions to be executed through preliminary operations in a preset transaction mechanism to obtain backup data, wherein the preset transaction mechanism comprises the preliminary operations, the cancel operations and the confirm operations;
The server executes a plurality of transactions to be executed through preliminary operations in a preset transaction mechanism to obtain backup data, wherein the preset transaction mechanism comprises the preliminary operations, the cancel operations and the confirm operations. The preset transaction mechanism is a TCC transaction mechanism, the preliminary operation is a try statement block, and the server tries to execute consistency judgment on preset business according to preset conditions and requests to reserve preset business resources according to the try statement block. Further, the server performs consistency judgment on the preset service according to preset conditions, for example, the server judges whether the account states of A, B and C are normal, the server judges whether the balance of the account A is not less than 30 yuan, and the server judges whether the balance of the account B is not less than 50 yuan; the server reserves preset service resources, for example, the frozen amount of the account A is increased by 30 yuan, and the frozen amount of the account B is increased by 50 yuan, so that the account B is ensured not to be influenced by other concurrent processes on the transfer operation of the two accounts.
Specifically, firstly, a server reads connection information of a plurality of databases and a plurality of transactions to be executed from a preset mapping object file; secondly, the server connects a plurality of databases according to the preset connection class and the connection information of the databases, and further, the server sets an abstract method getConnection in a Transaction interface Transaction of mybatis as the preset connection class; the server adds getConnection and connection information of the plurality of databases to the preliminary operation; the server connects a plurality of databases in a preliminary operation; finally, the server executes a plurality of transactions to be executed through preliminary operations in a preset transaction mechanism, and adds distributed transaction locks to the plurality of transactions to be executed, wherein the distributed transaction locks ensure that different processes mutually exclusive access to shared resources, the preset transaction mechanism comprises the preliminary operations, confirmation operations and cancellation operations, and the server applies for the distributed transaction locks in the execution process of a try statement block to logically lock data of a plurality of databases, and further, when determining that at least two transaction related data operations belong to different databases, the server generates an insertion statement of the distributed transaction locks; and the server executes the inserted statement of the distributed transaction lock to obtain the distributed transaction lock. For example, the server logically locks the data corresponding to the a library and the data corresponding to the B library, so as to ensure the consistency of the transaction.
Optionally, the server executes a plurality of transactions to be executed one by one according to different function names of the preset interface class through preliminary operation in a preset transaction mechanism, so as to obtain unique identifiers of the transactions; the server executes a preset query statement corresponding to the first mapping tag to obtain backup data; the server sets the unique identification of the transaction and the backup data as a target key value pair, and stores the target key value pair into a cache; the server adds distributed transaction locks to a plurality of transactions to be executed and executes data operation statements of a plurality of databases.
207. When all the transactions to be executed are detected to be successfully executed, submitting all the successfully executed transactions through a confirmation operation;
when detecting that all the plurality of transactions to be executed are successfully executed, the server submits all the successfully executed transactions through a confirmation operation. Wherein the confirmation operation is a confirm statement block, and the server executes the incomplete matters of the preliminary operation by executing the confirm statement block designated by the preliminary operation one by one. Specifically, when all the transactions to be executed are detected to be executed successfully, the server acquires the unique identification of all the successful transactions through the confirmation operation; submitting the transaction according to the unique identification of all the successful transactions to obtain a submitting state; the server judges whether the submitting state is a successful state or not, further, the server compares the submitting state with a target state value, if the submitting state is equal to the target state value, the server determines that the submitting state is a successful state, if the submitting state is not equal to the target state value, the server determines that the submitting state is a failed state, for example, the target state value is 1, if the submitting state is 1, the server determines that the submitting state is a successful state, and if the submitting state is 0, the server determines that the submitting state is a failed state; if the submitting state is a successful state, triggering the releasing operation of the distributed transaction lock, and simultaneously releasing the reserved preset service resources; if the commit status is the failure status, re-committing the transaction in the failure status, and counting the commit times until the commit times are not less than the preset times or the commit status is the success status. For example, if the database a adds one data and the database B reduces one data, after the transactions of the database a and the database B are executed successfully, the server submits the related transactions of a and B by confirming operation, and obtains the submitted states S1 and S2, until the submitted ends when all S1 and S2 are successful states.
208. When detecting that any one of a plurality of transactions to be executed fails to execute, rollback the executed transaction according to the backup data through cancelling operation to obtain rollback data, and verifying the rollback data according to the backup data to obtain a verification result;
When detecting that any one of the plurality of transactions to be executed fails to execute, the server rolls back the executed transaction according to the backup data through a cancel operation to obtain rolled-back data, and verifies the rolled-back data according to the backup data to obtain a verification result. The cancellation operation is used for canceling and executing preset business, the cancellation operation is a cancel statement block, the cancel statement block is used for releasing reserved preset business resources and distributed transaction locks, for example, in the initial operation execution process, a server detects that the balance of an account A meets preset conditions and corresponding amount is successfully frozen, but the balance of an account B does not meet the preset conditions and the amount of the account B is not frozen and fails, and the server adopts the cancel statement block and backup data C to defrost the frozen amount of the account A.
Specifically, when detecting that any one of a plurality of transactions to be executed fails in execution, acquiring backup data according to a unique identifier of the transaction through a cancel operation, for example, when a server executes an update transaction, the server firstly executes a before tag and caches corresponding data to obtain the backup data, and when detecting that the transaction fails in execution and the server detects that the transaction comprises a rollback tag, the server acquires the backup data according to the unique identifier of the transaction through the cancel operation; and the server rolls back the executed transaction according to the backup data, and releases the distributed transaction lock to obtain the rolled-back data. Wherein rollback of executed transactions is for the executing script, e.g., when the a database performs an a.update transaction operation, the server performs a local rollback, which is the execution of a.roller ack. The rolling back of the database B is B.rollback, and further, the server releases the distributed transaction lock and reserved preset service resources. And finally, the server performs data consistency verification on the rolled-back data and the backup data to obtain a verification result, and further, the server calls a corresponding equivalent () function to perform consistency verification on the rolled-back data and the backup data to obtain the verification result.
209. Judging whether the verification result is equal to the target value;
The server judges whether the verification result is equal to the target value, wherein the verification result is used for indicating whether difference data exists between the rolled-back data and the backup data. If the verification result is equal to the target value, the server executes step 210; if the verification result is not equal to the target value, step 211 is executed.
210. If the verification result is equal to the target value, determining the remaining executed transactions, and carrying out data rollback on the remaining executed transactions according to the backup data;
if the verification result is equal to the target value, the server determines the remaining executed transactions, and performs data rollback on the remaining executed transactions according to the backup data. The remaining executed transactions are transaction sets obtained by removing rolled-back transactions from the executed transactions, for example, a server sequentially executes a transaction A and a transaction B, an exception occurs in the execution process of the transaction B, the server sequentially rolls back the transaction B and the transaction A according to backup data, a verification result C is obtained after the rolling back of the transaction B, and if the verification result C is equal to a target value, the server continues to roll back data on the remaining executed transaction A.
211. If the verification result is not equal to the target value, determining the difference data, and carrying out data recovery on the difference data according to the backup data.
If the verification result is not equal to the target value, determining difference data, carrying out data recovery on the difference data according to the backup data, and further carrying out data rollback on the rest executed transactions after the data recovery is successful, namely, if the data recovery is successful, carrying out data consistency verification, and ensuring consistency of the rollback data and the backup data and correctness of the rollback data according to the verification result by the server.
Further, the server acquires different execution states of the transaction to be executed, wherein the different execution states comprise an execution success state of the transaction and an execution failure state of the transaction; the server records the successful execution state of the transaction and the failed execution state of the transaction into a preset transaction log according to the unique identification of the transaction; the server sends preset alarm information to the execution failure state of the transaction. For example, the server alarms the execution failure state of the transaction in real time in a mail mode or a short message mode, so that the target personnel can respond and process the transaction in time.
In the embodiment of the invention, the backup data is obtained by configuring and executing the distributed mapping object files crossing the database, and the data rollback verification and the transaction submission are carried out on the distributed transaction according to the transaction mechanism and the backup data, so that the correctness of the rollback data and the consistency of a plurality of service data which are concurrently requested by the database crossing services are ensured.
The method for managing transactions across databases in the embodiment of the present invention is described above, and the following describes a device for managing transactions across databases in the embodiment of the present invention, referring to fig. 3, one embodiment of the device for managing transactions across databases in the embodiment of the present invention includes:
The configuration unit 301 is configured to determine data operation sentences of a plurality of databases from a preset mapping object file, and configure a first mapping tag and a second mapping tag for the data operation sentences of the plurality of databases to obtain a plurality of transactions to be executed, where the first mapping tag is used to indicate triggering data backup, and the second mapping tag is used to indicate triggering data rollback;
The executing unit 302 is configured to execute a plurality of transactions to be executed through a preliminary operation in a preset transaction mechanism, so as to obtain backup data, where the preset transaction mechanism includes the preliminary operation, the cancel operation and the confirm operation;
a commit unit 303, configured to commit all the transactions that are executed successfully through a confirmation operation when all the execution of the plurality of transactions to be executed is detected to be successful;
the rollback verification unit 304 is configured to, when detecting that any one of the plurality of transactions to be executed fails to execute, rollback the failed transaction according to the backup data by cancelling the operation to obtain rollback data, and verify the rollback data according to the backup data to obtain a verification result;
a judging unit 305 for judging whether the verification result is equal to the target value;
the processing unit 306 is configured to determine remaining executed transactions if the verification result is equal to the target value, and perform data rollback on the remaining executed transactions according to the backup data;
and a recovery unit 307 for determining the difference data and recovering the difference data according to the backup data if the verification result is not equal to the target value.
In the embodiment of the invention, the backup data is obtained by configuring and executing the distributed mapping object files crossing the database, and the data rollback verification and the transaction submission are carried out on the distributed transaction according to the transaction mechanism and the backup data, so that the correctness of the rollback data and the consistency of a plurality of service data which are concurrently requested by the database crossing services are ensured.
Referring to fig. 4, another embodiment of a transaction management device across databases in an embodiment of the present invention includes:
The configuration unit 301 is configured to determine data operation sentences of a plurality of databases from a preset mapping object file, and configure a first mapping tag and a second mapping tag for the data operation sentences of the plurality of databases to obtain a plurality of transactions to be executed, where the first mapping tag is used to indicate triggering data backup, and the second mapping tag is used to indicate triggering data rollback;
The executing unit 302 is configured to execute a plurality of transactions to be executed through a preliminary operation in a preset transaction mechanism, so as to obtain backup data, where the preset transaction mechanism includes the preliminary operation, the cancel operation and the confirm operation;
a commit unit 303, configured to commit all the transactions that are executed successfully through a confirmation operation when all the execution of the plurality of transactions to be executed is detected to be successful;
the rollback verification unit 304 is configured to, when detecting that any one of the plurality of transactions to be executed fails to execute, rollback the failed transaction according to the backup data by cancelling the operation to obtain rollback data, and verify the rollback data according to the backup data to obtain a verification result;
a judging unit 305 for judging whether the verification result is equal to the target value;
the processing unit 306 is configured to determine remaining executed transactions if the verification result is equal to the target value, and perform data rollback on the remaining executed transactions according to the backup data;
and a recovery unit 307 for determining the difference data and recovering the difference data according to the backup data if the verification result is not equal to the target value.
Optionally, the configuration unit 301 may be further specifically configured to:
deploying a preset project framework to obtain a preset mapping object file;
Configuring connection information of a plurality of databases and data operation sentences of the plurality of databases in a preset mapping object file, wherein the data operation sentences of the plurality of databases are used for indicating to correlate with different function names of preset interface classes according to a first preset attribute;
Adding a first mapping tag into data operation sentences of a plurality of databases, and associating the first mapping tag with a preset query sentence according to a second preset attribute, wherein the first mapping tag is used for indicating triggering data backup;
Adding a second mapping tag to the data operation sentences of the databases, wherein the second mapping tag is used for indicating triggering data rollback;
And reloading the preset mapping object file to obtain a plurality of transactions to be executed.
Optionally, the execution unit 302 may further include:
A reading subunit 3021, configured to read connection information of a plurality of databases and a plurality of transactions to be executed from a preset mapping object file;
A connection subunit 3022 configured to connect to the plurality of databases according to a preset connection class and connection information of the plurality of databases;
The execution subunit 3023 is configured to execute a plurality of transactions to be executed through a preliminary operation in a preset transaction mechanism, to obtain backup data, and to add a distributed transaction lock to the plurality of transactions to be executed, where the preset transaction mechanism includes a preliminary operation, a confirmation operation, and a cancellation operation.
Optionally, the execution subunit 3023 may further be specifically configured to:
executing a plurality of transactions to be executed one by one according to different function names of preset interface classes through preliminary operations in a preset transaction mechanism to obtain unique identifiers of the transactions, wherein the preset transaction mechanism comprises the preliminary operations, the confirmation operations and the cancellation operations;
executing a preset query statement corresponding to the first mapping label to obtain backup data;
Setting the unique identification of the transaction and the backup data as a target key value pair, and storing the target key value pair into a cache;
And adding distributed transaction locks to a plurality of transactions to be executed, and executing data operation sentences of a plurality of databases.
Optionally, the rollback verification unit 304 may be further specifically configured to:
when detecting that any one of a plurality of transactions to be executed fails to be executed, acquiring backup data according to the unique identification of the transaction through a cancel operation;
rollback the failed execution transaction according to the backup data, and releasing the distributed transaction lock to obtain the rollback data;
and carrying out data consistency verification on the rolled-back data and the backup data to obtain a verification result.
Optionally, the submitting unit 303 may be further specifically configured to:
when all the transactions to be executed are detected to be executed successfully, acquiring unique identifiers of all the successful transactions through a confirmation operation;
Submitting the transaction according to the unique identification of all the successful transactions to obtain a submitting state;
judging whether the submitting state is a successful state or not;
if the submitted state is a successful state, triggering the release operation of the distributed transaction lock;
If the commit status is the failure status, re-committing the transaction in the failure status, and counting the commit times until the commit times are not less than the preset times or the commit status is the success status.
Optionally, the transaction management device across databases may further include:
an acquiring unit 308, configured to acquire different execution states of a transaction to be executed, where the different execution states include an execution success state of the transaction and an execution failure state of the transaction;
A recording unit 309, configured to record, according to the unique identifier of the transaction, an execution success state of the transaction and an execution failure state of the transaction into a preset transaction log;
and a transmitting unit 310 for transmitting preset alarm information for the execution failure state of the transaction.
In the embodiment of the invention, the backup data is obtained by configuring and executing the distributed mapping object files crossing the database, and the data rollback verification and the transaction submission are carried out on the distributed transaction according to the transaction mechanism and the backup data, so that the correctness of the rollback data and the consistency of a plurality of service data which are concurrently requested by the database crossing services are ensured.
The above-mentioned fig. 3 and fig. 4 describe the transaction management device across databases in the embodiment of the present invention in detail from the point of view of modularized functional entities, and the following describes the transaction management device across databases in the embodiment of the present invention in detail from the point of view of hardware processing.
Fig. 5 is a schematic structural diagram of a transaction management device across databases, where the transaction management device 500 across databases may vary greatly according to configuration or performance, and may include one or more processors (central processing units, CPU) 501 (e.g., one or more processors) and memory 509, one or more storage mediums 508 (e.g., one or more mass storage devices) storing applications 507 or data 506, according to an embodiment of the present invention. Wherein the memory 509 and storage medium 508 may be transitory or persistent storage. The program stored on the storage medium 508 may include one or more modules (not shown), each of which may include a series of instruction operations in managing transactions across databases. Still further, the processor 501 may be configured to communicate with a storage medium 508 to execute a series of instruction operations in the storage medium 508 on the transaction management device 500 across databases.
The transaction management device 500 across databases may also include one or more power supplies 502, one or more wired or wireless network interfaces 503, one or more input/output interfaces 504, and/or one or more operating systems 505, such as Windows Serve, mac OS X, unix, linux, freeBSD, and the like. It will be appreciated by those skilled in the art that the cross-database transaction management device structure shown in FIG. 5 does not constitute a limitation of cross-database transaction management devices, and may include more or fewer components than shown, or may combine certain components, or a different arrangement of components.
It will be clear to those skilled in the art that, for convenience and brevity of description, specific working procedures of the above-described systems, apparatuses and units may refer to corresponding procedures in the foregoing method embodiments, which are not repeated herein.
In the several embodiments provided in the present invention, it should be understood that the disclosed systems, devices, and methods may be implemented in other manners. For example, the apparatus embodiments described above are merely illustrative, e.g., the division of the units is merely a logical function division, and there may be additional divisions when actually implemented, e.g., multiple units or components may be combined or integrated into another system, or some features may be omitted or not performed. Alternatively, the coupling or direct coupling or communication connection shown or discussed with each other may be an indirect coupling or communication connection via some interfaces, devices or units, which may be in electrical, mechanical or other form.
The units described as separate units may or may not be physically separate, and units shown as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
In addition, each functional unit in the embodiments of the present invention may be integrated in one processing unit, or each unit may exist alone physically, or two or more units may be integrated in one unit. The integrated units may be implemented in hardware or in software functional units.
The integrated units, if implemented in the form of software functional units and sold or used as stand-alone products, may be stored in a computer readable storage medium. Based on such understanding, the technical solution of the present invention may be embodied essentially or in part or all of the technical solution or in part in the form of a software product stored in a storage medium, including instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to perform all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a read-only memory (ROM), a random access memory (random access memory, RAM), a magnetic disk, or an optical disk, or other various media capable of storing program codes.
The above embodiments are only for illustrating the technical solution of the present invention, and not for limiting the same; although the invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical scheme described in the foregoing embodiments can be modified or some technical features thereof can be replaced by equivalents; such modifications and substitutions do not depart from the spirit and scope of the technical solutions of the embodiments of the present invention.

Claims (10)

1. A method of transaction management across databases, comprising:
determining data operation sentences of a plurality of databases from a preset mapping object file, and configuring a first mapping label and a second mapping label for the data operation sentences of the plurality of databases to obtain a plurality of transactions to be executed, wherein the first mapping label is used for indicating triggering data backup, and the second mapping label is used for indicating triggering data rollback;
executing the plurality of transactions to be executed through preliminary operations in a preset transaction mechanism to obtain backup data, wherein the preset transaction mechanism comprises the preliminary operations, the cancel operations and the confirm operations;
When all the transactions to be executed are detected to be successfully executed, submitting all the successfully executed transactions through the confirmation operation;
When detecting that any one of the plurality of transactions to be executed fails to execute, rollback the executed transaction according to the backup data through the cancel operation to obtain rollback data, and verifying the rollback data according to the backup data to obtain a verification result;
Judging whether the verification result is equal to a target value or not;
If the verification result is equal to the target value, determining the rest executed transaction, and carrying out data rollback on the rest executed transaction according to the backup data;
and if the verification result is not equal to the target value, determining difference data, and carrying out data recovery on the difference data according to the backup data.
2. The method for managing transactions across databases according to claim 1, wherein determining data operation sentences of a plurality of databases from a preset mapping object file, and configuring a first mapping tag and a second mapping tag for the data operation sentences of the plurality of databases to obtain a plurality of transactions to be executed, wherein the first mapping tag is used for indicating triggering data backup, and the second mapping tag is used for indicating triggering data rollback, includes:
deploying a preset project framework to obtain a preset mapping object file;
configuring connection information of a plurality of databases and data operation sentences of the databases in the preset mapping object file, wherein the data operation sentences of the databases are used for indicating to correlate with different function names of preset interface classes according to a first preset attribute;
Adding a first mapping tag into data operation sentences of the databases, and associating the first mapping tag with a preset query sentence according to a second preset attribute, wherein the first mapping tag is used for indicating triggering data backup;
adding the second mapping tag to the data operation sentences of the databases, wherein the second mapping tag is used for indicating triggering data rollback;
and reloading the preset mapping object file to obtain a plurality of transactions to be executed.
3. The method for managing transactions across databases according to claim 2, wherein said executing said plurality of transactions to be executed by a preliminary operation in a preset transaction mechanism, resulting in backup data, said preset transaction mechanism including a preliminary operation, a cancel operation, and a confirm operation, includes:
reading connection information of the databases and the plurality of transactions to be executed from the preset mapping object file;
connecting to the databases according to preset connection classes and connection information of the databases;
Executing the plurality of transactions to be executed through preliminary operations in a preset transaction mechanism to obtain backup data, and adding distributed transaction locks to the plurality of transactions to be executed, wherein the preset transaction mechanism comprises the preliminary operations, the confirmation operations and the cancellation operations.
4. The method for transaction management across databases according to claim 3, wherein said executing said plurality of transactions to be executed by a preliminary operation in a preset transaction mechanism, obtaining backup data, and adding a distributed transaction lock to said plurality of transactions to be executed, said preset transaction mechanism including said preliminary operation, a validation operation, and a cancellation operation includes:
executing the plurality of transactions to be executed one by one according to different function names of the preset interface class through preliminary operation in a preset transaction mechanism to obtain unique identifiers of the transactions, wherein the preset transaction mechanism comprises the preliminary operation, a confirmation operation and a cancellation operation;
executing a preset query statement corresponding to the first mapping tag to obtain backup data;
setting the unique identification of the transaction and the backup data into a target key value pair, and storing the target key value pair into a cache;
And adding distributed transaction locks to the plurality of transactions to be executed, and executing data operation sentences of the plurality of databases.
5. The method for managing transactions across databases according to claim 4, wherein when it is detected that any one of the plurality of transactions to be executed fails to execute, rolling back the executed transaction according to the backup data by the cancel operation to obtain rolled-back data, and validating the rolled-back data according to the backup data, the validating result includes:
When detecting that any one of the plurality of transactions to be executed fails to be executed, acquiring the backup data according to the unique identifier of the transaction through the cancel operation;
Rollback the executed transaction according to the backup data, and releasing the distributed transaction lock to obtain the rollback data;
and carrying out data consistency verification on the rolled-back data and the backup data to obtain a verification result.
6. The method of cross-database transaction management according to claim 4, wherein when it is detected that all of the plurality of transactions to be executed are successful, committing all of the transactions that are successful to be executed through the validation operation comprises:
When all the transactions to be executed are detected to be executed successfully, acquiring unique identifiers of all the successful transactions through the confirmation operation;
submitting the transaction according to the unique identification of all the successful transactions to obtain a submitting state;
Judging whether the submitting state is a successful state or not;
Triggering the release operation of the distributed transaction lock if the commit status is a successful status;
And if the commit status is the failure status, re-committing the transaction in the failure status, and counting the commit times until the commit times are not less than preset times or the commit status is the success status.
7. The method for managing transactions across databases according to any one of claims 1 to 6, wherein when it is detected that all of the plurality of transactions to be executed are executed successfully, after submitting all of the executed successfully transactions by the confirmation operation, the method for managing transactions across databases further comprises:
Acquiring different execution states of the transaction to be executed, wherein the different execution states comprise an execution success state of the transaction and an execution failure state of the transaction;
Recording the successful execution state of the transaction and the failed execution state of the transaction into a preset transaction log according to the unique identification of the transaction;
and sending preset alarm information to the execution failure state of the transaction.
8. A cross-database transaction management device, the cross-database transaction management device comprising:
The configuration unit is used for determining data operation sentences of a plurality of databases from a preset mapping object file, configuring a first mapping label and a second mapping label for the data operation sentences of the plurality of databases to obtain a plurality of transactions to be executed, wherein the first mapping label is used for indicating triggering data backup, and the second mapping label is used for indicating triggering data rollback;
the execution unit is used for executing the plurality of transactions to be executed through preliminary operations in a preset transaction mechanism to obtain backup data, wherein the preset transaction mechanism comprises the preliminary operations, the cancel operations and the confirm operations;
a commit unit, configured to commit all the transactions that are executed successfully through the confirmation operation when all the transactions to be executed are detected to be executed successfully;
The rollback verification unit is used for rollback the executed transaction according to the backup data through the cancel operation to obtain rollback data when detecting that any one of the plurality of transactions to be executed fails to execute, and verifying the rollback data according to the backup data to obtain a verification result;
a judging unit for judging whether the verification result is equal to the target value;
The processing unit is used for determining the rest of executed transactions and carrying out data rollback on the rest of executed transactions according to the backup data if the verification result is equal to the target value;
and the recovery unit is used for determining difference data and carrying out data recovery on the difference data according to the backup data if the verification result is not equal to the target value.
9. A cross-database transaction management device, the cross-database transaction management device comprising: the system comprises a memory and at least one processor, wherein instructions are stored in the memory, and the memory and the at least one processor are interconnected through a line;
The at least one processor invoking the instructions in the memory to cause the cross-database transaction management device to perform the method of any of claims 1-7.
10. A computer-readable storage medium having stored thereon a computer program, characterized by: the computer program implementing the steps of the method according to any of claims 1-7 when executed by a processor.
CN202010000435.1A 2020-01-02 2020-01-02 Cross-database transaction management method, device, equipment and storage medium Active CN111209142B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010000435.1A CN111209142B (en) 2020-01-02 2020-01-02 Cross-database transaction management method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010000435.1A CN111209142B (en) 2020-01-02 2020-01-02 Cross-database transaction management method, device, equipment and storage medium

Publications (2)

Publication Number Publication Date
CN111209142A CN111209142A (en) 2020-05-29
CN111209142B true CN111209142B (en) 2024-09-13

Family

ID=70784114

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010000435.1A Active CN111209142B (en) 2020-01-02 2020-01-02 Cross-database transaction management method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN111209142B (en)

Families Citing this family (11)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111753013B (en) * 2020-06-24 2024-04-16 中国银行股份有限公司 Distributed transaction processing method and device
CN113971447B (en) * 2020-07-23 2024-05-10 美的智慧家居科技有限公司 Data processing method, system, device, electronic equipment and storage medium
CN112182082B (en) * 2020-09-24 2021-07-06 广州巨杉软件开发有限公司 System and method for realizing strong consistency of transactions across different database engines
CN112765126B (en) * 2020-12-31 2024-07-16 金蝶软件(中国)有限公司 Database transaction management method, device, computer equipment and storage medium
CN113157787A (en) * 2021-04-06 2021-07-23 中信百信银行股份有限公司 Accounting processing method and device, electronic equipment and readable storage medium
CN113065967B (en) * 2021-05-18 2024-12-10 中国农业银行股份有限公司 Multi-mode business processing method, device and equipment
CN113268470A (en) * 2021-06-17 2021-08-17 重庆富民银行股份有限公司 Efficient database rollback scheme verification method
CN113420011A (en) * 2021-06-29 2021-09-21 平安消费金融有限公司 Redis transaction rollback method, device, computer equipment and storage medium
CN113836579B (en) * 2021-09-26 2024-04-09 多点生活(成都)科技有限公司 Data processing method and device, electronic equipment and storage medium
CN114356888A (en) * 2021-12-30 2022-04-15 中国民航信息网络股份有限公司 Transaction processing method and device, storage medium and electronic equipment
CN117950917B (en) * 2024-03-27 2024-07-12 天津南大通用数据技术股份有限公司 Online backup method for large-scale distributed parallel database cluster system

Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104793988A (en) * 2014-01-20 2015-07-22 阿里巴巴集团控股有限公司 Cross-database distributed transaction implementation method and device
CN106445644A (en) * 2016-08-30 2017-02-22 中国民生银行股份有限公司 Distributed transaction processing method and device based on improved one-phase commit

Family Cites Families (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN106557514A (en) * 2015-09-29 2017-04-05 中兴通讯股份有限公司 A kind of distributed transaction rollback method and device

Patent Citations (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN104793988A (en) * 2014-01-20 2015-07-22 阿里巴巴集团控股有限公司 Cross-database distributed transaction implementation method and device
CN106445644A (en) * 2016-08-30 2017-02-22 中国民生银行股份有限公司 Distributed transaction processing method and device based on improved one-phase commit

Also Published As

Publication number Publication date
CN111209142A (en) 2020-05-29

Similar Documents

Publication Publication Date Title
CN111209142B (en) Cross-database transaction management method, device, equipment and storage medium
US7702660B2 (en) I/O free recovery set determination
US5737738A (en) Distributed read/write replication with primary copy first write and primary copy transfer features
WO2018103318A1 (en) Distributed transaction handling method and system
US6665814B2 (en) Method and apparatus for providing serialization support for a computer system
Eager et al. Achieving robustness in distributed database systems
US5799305A (en) Method of commitment in a distributed database transaction
US5724581A (en) Data base management system for recovering from an abnormal condition
US6980988B1 (en) Method of applying changes to a standby database system
CN107070919B (en) Idempotency for database transactions
US7240114B2 (en) Namespace management in a distributed file system
US6304882B1 (en) Data replication system and method
US7680795B2 (en) Shared disk clones
US20120054546A1 (en) Methods for detecting split brain in a distributed system
US20050125445A1 (en) High performance support for XA protocols in a clustered shared database
CN104793988A (en) Cross-database distributed transaction implementation method and device
CN111753013A (en) Distributed transaction processing method and device
CN110413687B (en) Distributed transaction fault processing method and related equipment based on node interaction verification
US9386073B2 (en) Techniques for performing processing for database
WO1996041263A1 (en) Management of units of work on a computer system log
US9330153B2 (en) System, method, and computer readable medium that coordinates between devices using exchange of log files
JP4461147B2 (en) Cluster database using remote data mirroring
US20050144299A1 (en) System and method for supporting XA 2-phase commit protocols with a loosely coupled clustered database server
JP5154843B2 (en) Cluster system, computer, and failure recovery method
Du et al. Fast one-sided RDMA-based state machine replication for disaggregated memory

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
GR01 Patent grant
GR01 Patent grant