CN114461601A - Distributed transaction rollback method, device, terminal and storage medium based on sub-base and sub-table - Google Patents

Distributed transaction rollback method, device, terminal and storage medium based on sub-base and sub-table Download PDF

Info

Publication number
CN114461601A
CN114461601A CN202111518666.2A CN202111518666A CN114461601A CN 114461601 A CN114461601 A CN 114461601A CN 202111518666 A CN202111518666 A CN 202111518666A CN 114461601 A CN114461601 A CN 114461601A
Authority
CN
China
Prior art keywords
execution
statement
reverse
distributed transaction
sub
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.)
Pending
Application number
CN202111518666.2A
Other languages
Chinese (zh)
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.)
Shanghai Hujin Information Technology Co ltd
Original Assignee
Shanghai Hujin Information Technology 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 Shanghai Hujin Information Technology Co ltd filed Critical Shanghai Hujin Information Technology Co ltd
Priority to CN202111518666.2A priority Critical patent/CN114461601A/en
Publication of CN114461601A publication Critical patent/CN114461601A/en
Pending legal-status Critical Current

Links

Images

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/21Design, administration or maintenance of databases
    • G06F16/219Managing data history or versioning
    • 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/22Indexing; Data structures therefor; Storage structures
    • G06F16/2282Tablespace storage structures; Management thereof
    • 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/242Query formulation
    • G06F16/2433Query languages
    • 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/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Databases & Information Systems (AREA)
  • Physics & Mathematics (AREA)
  • Data Mining & Analysis (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Mathematical Physics (AREA)
  • Computational Linguistics (AREA)
  • Software Systems (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention provides a distributed transaction rollback method, a distributed transaction rollback device, a distributed transaction rollback terminal and a storage medium based on sub-libraries and sub-tables, wherein the method comprises the following steps: establishing a reverse execution statement record table in each sub-library; analyzing an execution statement of the distributed transaction, acquiring the content, the table name, the main key and the index of the execution statement, and if the content of the execution statement contains a deleted or updated statement, performing reverse query according to the execution statement to find out original data; assembling reverse execution sentences according to the analyzed execution sentences, table names, main keys, indexes and original data; storing the assembled reverse execution statements into a reverse execution statement record table in each sub-library; and in response to the execution failure of the execution statement of the distributed transaction, sequentially finding out the reverse execution statement corresponding to the execution statement with the execution failure in each sub-library according to the ID and the state of the current distributed transaction, and executing the reverse execution statement with the execution failure.

Description

Distributed transaction rollback method, device, terminal and storage medium based on sub-base and sub-table
Technical Field
The present disclosure relates to, but not limited to, the field of database and table partitioning, and in particular, to a distributed transaction rollback method, apparatus, terminal, and storage medium.
Background
The database sub-table is a table which divides the original table for storing a large amount of data into a plurality of tables with small data amount according to a certain rule and stores the tables in a plurality of databases. Traditional database maintenance changes are made to a single data source. And aiming at the situation of database division and table division, the same change operation needs to be carried out on all baskets with multiple data sources, and the workload is multiplied.
At present, a plurality of problems are faced to realize distributed transactions in a sub-library and a sub-table, wherein a key problem is how to roll back the distributed transactions effectively. The distributed transaction is different from a single-machine transaction, the biggest difference is that the distributed transaction is submitted at a plurality of database nodes at the same time, and if the distributed transaction can be successful, other subsequent operations are not needed; however, once a database node fails to commit due to an exception, other database nodes also need to ensure that the transaction committed to them can stop executing or roll back in time. Because the randomness of errors and the types of exceptions of database nodes are numerous, how to roll back distributed transactions effectively becomes a key problem for ensuring transaction consistency.
If data needs to be repaired in the sub-database sub-table, batch and global updating operation is often needed, meanwhile, for some basic configurations, the configurations are also inserted into all the databases, in such a scenario, a row of execution statements are frequently triggered to operate the scenarios of multiple databases, if one of the databases is in a problem, some data operations are successful, some data operations are failed, and in such a case, data rollback is needed.
Currently, most of the applications in the industry are the Mycat, and in the field of the current database and table partitioning, the method for the Mycat to perform distributed transactions is a two-stage weak-consistency transaction submission method. This approach is simply a local retry to achieve final consistency, not a strongly consistent solution. If the Mycat is executed to half, the database has problems, and at this time, the Mycat automatically rolls back the uncommitted rest of the transactions after being started, but the committed transaction data cannot be rolled back. If the system restarts due to an exception, Mycat can do so by rolling back the transactions that remain unrerolled, but the transaction data that has already been committed is not changed, so this is an imperfect solution.
This mode has the following disadvantages: firstly, data cannot be rolled back to the initial state, so that the data can be seriously inconsistent; and secondly, the local disk is relied on, so that the system performance is reduced.
Disclosure of Invention
The following presents a summary of various exemplary aspects. Some simplifications and omissions may be made in the following summary, which is intended to highlight and introduce some aspects of the various exemplary embodiments, but not to limit the scope of the invention. Detailed descriptions of exemplary embodiments sufficient to enable those of ordinary skill in the art to make and use the inventive concepts will be presented in the following sections.
In order to solve the above technical problems, a technical solution of the present invention provides a distributed transaction rollback method based on sub-base and sub-table, comprising: establishing a reverse execution statement record table in each sub-library; analyzing an execution statement of the distributed transaction, acquiring the content, the table name, the main key and the index of the execution statement, and if the content of the execution statement contains a deleted or updated statement, performing reverse query according to the execution statement to find out original data; assembling reverse execution sentences according to the analyzed execution sentences, table names, main keys, indexes and original data; storing the assembled reverse execution statements into a reverse execution statement record table in each sub-library; and in response to the execution failure of the execution statement of the distributed transaction, sequentially finding out the reverse execution statement corresponding to the execution statement with the execution failure in each sub-library according to the ID and the state of the current distributed transaction, and executing the reverse execution statement with the execution failure.
Optionally, the method further comprises: recording the execution state of the reverse execution statement, wherein the execution state comprises success and failure.
Optionally, the method further comprises: and regularly scanning the execution state of the reverse execution statement, and if the execution state is failure, continuing to execute the reverse execution statement of which the execution state is failure.
Optionally, the method further comprises: and sequencing the execution time of the distributed transaction execution statements failed to be executed in each sub-library from back to front, finding out the reverse execution statement corresponding to the execution statement failed to be executed in each sub-library according to the sequencing, and executing the reverse execution statement.
Optionally, the execution statement is an SQL statement.
Optionally, at least one of the autonomy key, the current distributed transaction ID, the forward execution statement, the database architecture, the execution statement execution state, the insertion time, the update time, and the encrypted value of the data is stored in the reverse execution statement record table.
Optionally, after the execution of the execution statement of the distributed transaction is completed, recording the executed data, when the execution of the execution statement of the distributed transaction fails and the failed reverse execution statement needs to be executed, checking whether the current data is consistent with the previously recorded executed data, if so, executing the failed reverse execution statement, and if not, executing the reverse execution statement.
Optionally, after the execution of the execution statement of the distributed transaction is completed, MD5 encryption is performed on the executed data to obtain a first encryption value, when the execution of the execution statement of the distributed transaction fails and a failed reverse execution statement needs to be executed, MD5 encryption is performed on the current data to obtain a second encryption value, the second encryption value is compared with the previous first encryption value, if the second encryption value is consistent with the previous first encryption value, the failed reverse execution statement is executed, and if the second encryption value is not consistent with the previous first encryption value, the reverse execution statement is not executed.
Another technical solution of the present invention provides a distributed transaction rollback apparatus for database and table partitioning, including: the table building module is configured to build a reverse execution statement record table in each sub-library; the analysis module is configured to analyze an execution statement of the distributed transaction, acquire the content, the table name, the main key and the index of the execution statement, and if the content of the execution statement contains a deleted or updated statement, perform reverse query according to the execution statement and find out original data; the assembling module is configured to assemble the reverse execution statement according to the analyzed execution statement, the table name, the main key, the index and the original data; the storage module is configured to store the assembled reverse execution statements into a reverse execution statement record table in each sub-library; and the rollback module is configured to respond to the execution failure of the execution statement of the distributed transaction, sequentially find out the reverse execution statement corresponding to the execution statement which fails in execution in each sub-library according to the ID and the state of the current distributed transaction, and execute the reverse execution statement which fails in execution.
Optionally, the apparatus further comprises: a recording module configured to record an execution state of the reverse execution statement, the execution state including success and failure; and the scanning module is configured to periodically scan the execution state of the reverse execution statement, and if the execution state is failure, continue to execute the reverse execution statement of which the execution state is failure.
Optionally, the apparatus further comprises: the comparison module is configured to record data after execution is completed after execution of an execution statement of the distributed transaction is completed, check whether current data is consistent with data after execution recorded before when execution of the execution statement of the distributed transaction fails and the failed reverse execution statement needs to be executed, if so, execute the failed reverse execution statement, and if not, do not execute the reverse execution statement.
Optionally, the apparatus further comprises: and the comparison module is configured to perform MD5 encryption on the executed data to obtain a first encryption value after the execution of the execution statement of the distributed transaction is finished, perform MD5 encryption on the current data to obtain a second encryption value when the execution of the execution statement of the distributed transaction fails and the failed reverse execution statement needs to be executed in response to the execution failure of the execution statement of the distributed transaction, compare the second encryption value with the previous first encryption value, execute the failed reverse execution statement if the second encryption value is consistent with the previous first encryption value, and not execute the reverse execution statement if the second encryption value is inconsistent with the previous first encryption value.
Another technical solution of the present invention also provides an electronic terminal, including: a processor, a memory, and a computer program stored in the memory for execution by the processor, wherein the processor implements the steps of the method according to any of the above aspects when executing the computer program.
Another aspect of the present invention further provides a computer readable storage medium, wherein the computer program is executed by a processor to implement the steps of the method according to any one of the above aspects.
The technical scheme of the invention mainly has the following beneficial effects:
first, all distributed transaction data can be rolled back to the initial state, and the scheme is strong in consistency.
The technical scheme does not depend on any external third-party component, does not need any reverse or callback interface, is simpler and more convenient to realize, and has better performance;
and thirdly, if a rollback failure is encountered, a compensation scheme is provided, so that the rollback becomes more reliable and accurate.
Drawings
For a better understanding of various exemplary embodiments, reference may be made to the accompanying drawings in which:
FIG. 1 is a flowchart illustrating a distributed transaction rollback method based on sub-base and sub-table according to an embodiment;
fig. 2 shows a schematic structural diagram of a distributed transaction rollback apparatus based on sub-base and sub-table according to an embodiment.
To facilitate understanding, the same reference numerals have been used to designate elements having substantially the same or similar structure and/or substantially the same or similar function.
Detailed Description
The description and drawings illustrate the principles of the invention. It will thus be appreciated that those skilled in the art will be able to devise various arrangements which, although not explicitly described or shown herein, embody the principles of the invention and are included within its scope. Moreover, all examples cited herein are principally intended expressly to be only for pedagogical purposes to aid the reader in understanding the principles of the invention and the concepts contributed by the inventor to furthering the art, and are to be construed as being without limitation to such specifically cited examples and conditions. Further, as used herein, the term "or" refers to a non-exclusive or (i.e., and/or) unless otherwise indicated (e.g., "or otherwise" or in the alternative). Moreover, the various embodiments described herein are not necessarily mutually exclusive, as some embodiments may be combined with one or more other embodiments to form new embodiments.
A first embodiment provides a distributed transaction rollback method based on sub-base and sub-table, referring to fig. 1, the method includes:
and S101, establishing a reverse execution statement record table in each sub-library.
The execution statement may be, but is not limited to, a Structured Query Language (SQL) statement. The reverse execution statement may refer to a statement that implements a function opposite to that of the original execution statement; for example, if the original execution statement is inserted, the corresponding reverse execution statement is deleted; for example, when the original sentence is executed, the A is changed into the B, and when the corresponding sentence is executed reversely, the B is changed into the A; for another example, if the original execution statement is plus 1, the corresponding reverse execution statement is minus 1. The following is exemplified with SQL statements as the execution statements.
And S102, analyzing the execution statement of the distributed transaction, acquiring the content, the table name, the main key and the index of the execution statement, and if the content of the execution statement contains the deleted or updated statement, performing reverse query according to the execution statement to find out the original data.
And S103, assembling the reverse execution statement according to the analyzed execution statement, the table name, the main key, the index and the original data.
Optionally, in each database, each time an SQL statement is executed, the SQL statement requests to enter the sub-library sub-table middleware, a reverse SQL statement is automatically generated by the sub-library sub-table middleware, and then, while the SQL statement is executed, the reverse SQL statement is stored in a reverse execution (SQL) statement record table (txc _ rollback _ SQL) table in each library, and then the transaction is submitted together with the service.
Optionally, the SQL statement is parsed by a SQL statement parsing tool of the DruID to obtain the table name, each field and corresponding value in the where condition, then the show index from table in the database is used to take the main key and index of the data table according to the table name, at this time, if the delete statement or update statement is judged, the main key and index are used as conditions to check the original data in the database, and then the assembly of the reverse SQL statement is performed according to the parsed SQL statement and the returned main key and index, which is the process of generating the reverse SQL statement.
Examples are: the original SQL statement is update order _ table set status 1where _ order _ name ljj 'and create _ time 2021-08-0111: 11: 11'
Resolve out using the DruID:
table name: order _ table
The content is as follows: status 1
Conditions are as follows: order _ name ═ ljj ', Create _ time ═ 2021-08-0111: 11: 11'
Judging the index to be from order _ table by using the show index: create _ time
The original data needs to be queried backwards:
Select*from order_table where order_name=’ljj’and Create_time=‘2021-08-01 11:11:11’
then, according to the queried result, assembling the reverse SQL statement, for example, if the original status is 0, the reverse SQL statement is:
update order_table set status=0where order_name=’ljj’and create_time=’2021-08-01 11:11:11’。
step S104, storing the assembled reverse execution statements into a reverse execution statement record table in each sub-library;
alternatively, in addition to executing the statements in reverse, the following may be recorded into a reverse SQL statement record (txc _ rolback _ SQL):
1. and the Id Long self-increment key is used for updating the condition field used by the state of the reverse SQL statement.
2. txc _ id String current transaction id, refers to the transaction id of this batch, and during the rollback process, it is necessary to use this as a condition to find out all the reverse SQL statements of this batch.
3. The reverse SQL statement generated by the roll _ back _ SQL String refers to the reverse SQL statement needing to be executed.
4. SQL String Forward SQL statement
5. The schema of the schema String database refers to the value of the schema in which the reverse SQL statement is located, and generally refers to the names of the database, such as DB1 and DB 2.
6. The status Integer SQL statement execution state refers to the current state, for example, 0 after being inserted into the database, and is changed to 1 after the forward SQL statement is completely executed, and is changed to 2 after the reverse SQL statement is completely executed if the business error report is abnormal. The timing task of compensation needs to judge, for example, if 10 minutes is exceeded, and the state is still data of 0, that is, data needing to compensate for rollback, and the timing task is changed to 2 after compensation.
7. The insertion time of the create _ time Date is determined by the field, which is described above as exceeding 10 minutes.
8. update _ time Date update time, reverse SQL statement execution time, and when the state is modified, the state is updated together.
9. After dataMD5 String executes the distributed transactional SQL statement, the resulting MD5 value is encrypted via MD5 tool.
And S105, responding to the execution failure of the execution statement of the distributed transaction, sequentially finding out the reverse execution statement corresponding to the execution statement which fails to execute in each sub-library according to the ID and the state of the current distributed transaction, and executing the reverse execution statement which fails to execute.
Optionally, the step S105 further includes: and sequencing the execution time of the distributed transaction execution statements failed to be executed in each sub-library from back to front, finding out the reverse execution statement corresponding to the execution statement failed to be executed in each sub-library according to the sequencing, and executing the reverse execution statement, namely rolling back data. For example, distributed transaction execution statements are executed in sequence at commit: A. b, C, respectively; if the reverse execution statement generated by A is A ', the reverse execution statement generated by B is B ', and the reverse execution statement generated by C is C ', then the following steps are carried out: the order of C ', B', A executes the reverse execution statements.
Optionally, after the execution of the execution statement of the distributed transaction is completed, recording the executed data, when the execution of the execution statement of the distributed transaction fails and the failed reverse execution statement needs to be executed, checking whether the current data is consistent with the previously recorded executed data, if so, executing the failed reverse execution statement, and if not, executing the reverse execution statement.
Optionally, after the execution of the execution statement of the distributed transaction is completed, MD5 encryption is performed on the executed data to obtain a first encryption value, when the execution of the execution statement of the distributed transaction fails and a failed reverse execution statement needs to be executed, MD5 encryption is performed on the current data to obtain a second encryption value, and the second encryption value is compared with the previous first encryption value, if the second encryption value is consistent with the previous first encryption value, the failed reverse execution statement is executed, and if the second encryption value is not consistent with the previous reverse execution statement, the reverse execution statement is not executed. Specifically, after the forward SQL language is executed, and after the forward SQL statement is executed, the query is performed again to obtain the complete row data, and then the MD5 values of the row data are calculated through the MD5 tool and updated to the current data table. Before executing the reverse SQL, whether the value of the current data MD5Z is consistent with the value of MD5 in the database needs to be verified, if the inconsistency shows that the data is updated by others, the rollback cannot be directly reported, and if the inconsistency is consistent, the rollback action is carried out. For example, if the original data is a, after the forward SQL statement, a becomes B, and then its MD5 value is MD5B, and it is recorded in the data table, after the forward SQL statement has an error, we will look at the data currently becoming B, and its MD5 value is MD5B, which is consistent with MD5B recorded in the data table, and it indicates that the data has only undergone the forward SQL statement once, then the reverse SQL statement can be executed, and the rollback is implemented. For another example, if the original data is a, the data is changed into B through a forward SQL statement, then there is a forward SQL statement, and then B is changed into C, then the MD5 value of the data is MD5C, and when rollback is required, if it is found that the current MD5C is not consistent with the original MD5B, it means that the data cannot execute a reverse SQL statement after two or more times of forward SQL language, and cannot roll back to directly report an error. In this alternative, data that has undergone a forward SQL statement only is rolled back once.
Optionally, the method further comprises the following steps:
and step S106, recording the execution state of the reverse execution statement, wherein the execution state comprises success and failure.
And step S107, periodically scanning the execution state of the reverse execution statement, and if the execution state is failure, continuing to execute the reverse execution statement of which the execution state is failure.
Optionally, retry is performed if the reverse SQL statement fails to be executed, and in the current transaction, a statement for updating the execution state of the reverse SQL statement table is taken, after the execution succeeds, and when the current transaction is submitted, the state of the reverse SQL statement of the batch of reverse SQL statements of the reverse SQL statement table is updated, and after the complete reverse SQL statement is executed, the user returns, and the submission of the SQL statement fails.
Optionally, if an exception occurs during the rollback process, when the sub-library sub-table middleware restarts, a timing task is started, for example, every second, every hour, every day, or a certain cycle time, and the like, the execution states of all the reverse execution statements of all the libraries are scanned, where the execution states record whether the current SQL has executed the rollback operation, the reverse SQL records that have not been rolled back before are searched, and then the reverse SQL is sequentially executed continuously, that is, the rollback is continuously executed. And if the execution fails, alarming is needed until the execution is finished. And after all the reverse execution statements are executed, summarizing and feeding back to the user.
Optionally, when the SQL is executed from the first database DB1, and the execution fails to the nth sub-database DBN, rollback is triggered, the sub-database sub-table middleware sequences all current sub-databases, and then uses the current transaction ID and the current state to find out all reverse SQL statements that the current database needs to be rolled back this time, and sequentially executes all reverse SQL in the previous database according to the sequence in which the database DB is configured in the sub-database sub-table, and executes reverse SQL from the DBN to the DB1 to perform transaction rollback, and when the reverse SQL is executed, the SQL may fail, and the failure is retried.
Optionally, a timing task is started, and the log table which has executed the reverse SQL before 1 hour is cleared, so that the performance is prevented from being influenced by excessive data.
Alternatively, the steps of the above method can be realized by the library and table middleware.
The scheme of the embodiment is a strong consistency scheme, can ensure that data can be rolled back to an initial state, and is a scheme which is very suitable for transaction rolling back by an unconscious stateless middleware such as branch base and branch table.
A second embodiment provides a distributed transaction rollback apparatus 200 for banking and sub-table, referring to fig. 2, the apparatus comprising:
a table building module 201 configured to build a reverse execution statement record table in each sub-library;
the analysis module 202 is configured to analyze an execution statement of the distributed transaction, obtain content, a table name, a primary key and an index of the execution statement, and if the content of the execution statement contains a deleted or updated statement, perform reverse query according to the execution statement to find out original data;
the assembling module 203 is configured to assemble the reverse execution statement according to the analyzed execution statement, the table name, the main key, the index and the original data;
a storage module 204 configured to store the assembled reverse execution statements into a reverse execution statement record table in each of the sub-libraries;
and the rollback module 205 is configured to, in response to the execution of the execution statement of the distributed transaction failing, sequentially find out, in each sub-library, a reverse execution statement corresponding to the execution statement that fails to execute according to the ID and the state of the current distributed transaction, and execute the reverse execution statement that fails to execute.
Optionally, the apparatus further comprises: a recording module 206 configured to record an execution status of the reverse execution statement, the execution status including success and failure;
the scanning module 207 is configured to periodically scan the execution status of the reverse execution statement, and if the execution status is failure, continue to execute the reverse execution statement whose execution status is failure.
Alternatively, the distributed transaction rollback apparatus of the sub-library and sub-table may be a sub-library and sub-table middleware.
Optionally, the apparatus further comprises a comparison module: the method comprises the steps of recording data after execution is finished after execution statements of the distributed transaction are executed, checking whether current data are consistent with data after execution recorded before when the execution statements of the distributed transaction fail and the failed reverse execution statements need to be executed, executing the failed reverse execution statements if the current data are consistent with the data after execution recorded before, and not executing the reverse execution statements if the current data are inconsistent with the data after execution.
Optionally, the apparatus further comprises a comparison module: and the distributed transaction processing system is configured to perform MD5 encryption on executed data to obtain a first encryption value after execution of an execution statement of the distributed transaction is finished, perform MD5 encryption on current data to obtain a second encryption value when the execution of a reverse execution statement which fails in response to execution failure of the execution statement of the distributed transaction needs to be executed, compare the second encryption value with the previous first encryption value, if the second encryption value is consistent with the previous first encryption value, execute the failed reverse execution statement, and if the second encryption value is inconsistent with the previous first encryption value, not execute the reverse execution statement.
A third embodiment also provides an electronic terminal, comprising: a processor, a memory and a computer program stored in the memory, wherein the processor implements the steps of the method of any one of the above embodiments, such as steps S101 to S105, when executing the computer program, or implements the functions of the modules/units in each of the above embodiments, such as the functions of units 201 to 205 shown in fig. 1, when executing the computer program. The computer program may be divided into one or more modules/units, which are stored in the memory and executed by the processor. The one or more modules/units may be a series of computer program instruction segments capable of performing specific functions, which are used to describe the execution of the computer program in the terminal.
The terminal can be a mobile terminal such as a smart phone or a computing device such as a desktop computer, a notebook, a palm computer and a cloud server. The terminal may include, but is not limited to, a processor, memory, may include more or fewer components, or may combine certain components, e.g., the terminal may also include an input-output device, a network access device, a bus, etc. The Processor may be a Central Processing Unit (CPU), other general purpose Processor, a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), an off-the-shelf Programmable Gate Array (FPGA) or other Programmable logic device, discrete Gate or transistor logic, discrete hardware components, etc. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. The memory may be an internal storage unit of the terminal, such as a hard disk or a memory of the terminal. The memory may also be an external storage device of the terminal, such as a plug-in hard disk, a Smart Media Card (SMC), a Secure Digital (SD) Card, a Flash memory Card (Flash Card), and the like provided on the terminal. Further, the memory may also include both an internal storage unit and an external storage device of the terminal.
A fourth embodiment also provides a computer readable storage medium, which when executed by a processor implements the steps of the method of any of the above embodiments.
Each functional unit in the embodiments of the present application may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit. The integrated unit can be realized in a form of hardware, and can also be realized in a form of a software functional unit. The integrated module/unit, if implemented in the form of a software functional unit and sold or used as a stand-alone product, may be stored in a computer readable storage medium. Based on such understanding, all or part of the flow in the method of the embodiments described above can be realized by a computer program, which can be stored in a computer-readable storage medium and can realize the steps of the embodiments of the methods described above when the computer program is executed by a processor. Wherein the computer program comprises computer program code, which may be in the form of source code, object code, an executable file or some intermediate form, etc. The computer-readable medium may include: any entity or device capable of carrying the computer program code, recording medium, usb disk, removable hard disk, magnetic disk, optical disk, computer Memory, Read-Only Memory (ROM), Random Access Memory (RAM), electrical carrier wave signals, telecommunications signals, software distribution medium, and the like. It should be noted that the computer readable medium may contain content that is subject to appropriate increase or decrease as required by legislation and patent practice in jurisdictions, for example, in some jurisdictions, computer readable media does not include electrical carrier signals and telecommunications signals as is required by legislation and patent practice.
It will be apparent to those skilled in the art that, for convenience and brevity of description, only the above-mentioned division of the functional units and modules is illustrated, and in practical applications, the above-mentioned function distribution may be performed by different functional units and modules according to needs, that is, the internal structure of the apparatus is divided into different functional units or modules to perform all or part of the above-mentioned functions. Each functional unit and module in the embodiments may be integrated in one processing unit, or each unit may exist alone physically, or two or more units are integrated in one unit, and the integrated unit may be implemented in a form of hardware, or in a form of software functional unit. In addition, specific names of the functional units and modules are only used for distinguishing one functional unit from another, and are not used for limiting the protection scope of the present application. The specific working processes of the units and modules in the system may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the above embodiments, the descriptions of the respective embodiments have respective emphasis, and reference may be made to the related descriptions of other embodiments for parts that are not described or illustrated in a certain embodiment. Those of ordinary skill in the art will appreciate that the various illustrative elements and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware or combinations of computer software and electronic hardware. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present application.
In the embodiments provided in the present application, it should be understood that the disclosed system, terminal and method can be implemented in other ways. For example, the above-described system and terminal embodiments are merely illustrative, and for example, the division of the modules or units is only one type of logical function division, and other division manners may exist in actual implementation, for example, multiple units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, systems or units, and may be in an electrical, mechanical or other form. The units described as separate parts may or may not be physically separate, and parts displayed 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 can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
The above-mentioned embodiments are only used for illustrating the technical solutions of the present application, and not for limiting the same; although the present application has been described in detail with reference to the foregoing embodiments, it should be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; such modifications and substitutions do not substantially depart from the spirit and scope of the embodiments of the present application and are intended to be included within the scope of the present application.

Claims (14)

1. A distributed transaction rollback method based on sub-base and sub-table is characterized by comprising the following steps:
establishing a reverse execution statement record table in each sub-library;
analyzing an execution statement of the distributed transaction, acquiring the content, the table name, the main key and the index of the execution statement, and if the content of the execution statement contains a deleted or updated statement, performing reverse query according to the execution statement to find out original data;
assembling reverse execution sentences according to the analyzed execution sentences, table names, main keys, indexes and original data;
storing the assembled reverse execution statements into a reverse execution statement record table in each sub-library;
and in response to the execution failure of the execution statement of the distributed transaction, sequentially finding out the reverse execution statement corresponding to the execution statement with the execution failure in each sub-library according to the ID and the state of the current distributed transaction, and executing the reverse execution statement with the execution failure.
2. The method for distributed transaction rollback based on sub-base and sub-table according to claim 1, wherein the method further comprises: recording the execution state of the reverse execution statement, wherein the execution state comprises success and failure.
3. The method for distributed transaction rollback based on sub-base and sub-table according to claim 2, wherein the method further comprises: and regularly scanning the execution state of the reverse execution statement, and if the execution state is failure, continuing to execute the reverse execution statement of which the execution state is failure.
4. The method for distributed transaction rollback based on sub-base and sub-table according to claim 1, wherein the method further comprises: and sequencing the execution time of the distributed transaction execution statements failed to be executed in each sub-library from back to front, finding out the reverse execution statement corresponding to the execution statement failed to be executed in each sub-library according to the sequencing, and executing the reverse execution statement.
5. The method of claim 1, wherein the execution statement is an SQL statement.
6. The distributed transaction rollback method based on bank and table division according to claim 1, wherein at least one of the autonomy key, the current distributed transaction ID, the forward execution statement, the database architecture, the execution state of the execution statement, the insertion time, the update time, and the encrypted value of the data is stored in the backward execution statement record table.
7. The distributed transaction rollback method based on sub-base and sub-table as claimed in claim 1, wherein after execution of execution statements of the distributed transaction is completed, data after execution is recorded, when execution of the execution statements of the distributed transaction fails and a failed reverse execution statement needs to be executed, whether current data is consistent with previously recorded data after execution is checked, if so, the failed reverse execution statement is executed, and if not, the reverse execution statement is not executed.
8. The distributed transaction rollback method based on bank and table division of claim 1, wherein after execution of execution statements of the distributed transaction is completed, MD5 encryption is performed on the executed data to obtain a first encryption value, when execution of the execution statements of the distributed transaction fails and a failed reverse execution statement needs to be executed in response to the execution of the execution statements of the distributed transaction, MD5 encryption is performed on the current data to obtain a second encryption value, the second encryption value is compared with the previous first encryption value, if the second encryption value is consistent, the failed reverse execution statement is executed, and if the second encryption value is inconsistent, the reverse execution statement is not executed.
9. A distributed transaction rollback apparatus for banking and tabulation, comprising:
the table building module is configured to build a reverse execution statement record table in each sub-library;
the analysis module is configured to analyze an execution statement of the distributed transaction, acquire the content, the table name, the main key and the index of the execution statement, and if the content of the execution statement contains a deleted or updated statement, perform reverse query according to the execution statement and find out original data;
the assembling module is configured to assemble the reverse execution statement according to the analyzed execution statement, the table name, the main key, the index and the original data;
the storage module is configured to store the assembled reverse execution statements into a reverse execution statement record table in each sub-library;
and the rollback module is configured to respond to the execution failure of the execution statement of the distributed transaction, sequentially find out the reverse execution statement corresponding to the execution statement which fails in execution in each sub-library according to the ID and the state of the current distributed transaction, and execute the reverse execution statement which fails in execution.
10. The apparatus for distributed transaction rollback according to claim 9, further comprising:
a recording module configured to record an execution state of the reverse execution statement, the execution state including success and failure;
and the scanning module is configured to periodically scan the execution state of the reverse execution statement, and if the execution state is failure, continue to execute the reverse execution statement of which the execution state is failure.
11. The apparatus for distributed transaction rollback according to claim 9, further comprising:
a comparison module: the method comprises the steps of recording data after execution is finished after execution statements of the distributed transaction are executed, checking whether current data are consistent with data after execution recorded before when the execution statements of the distributed transaction fail and the failed reverse execution statements need to be executed, executing the failed reverse execution statements if the current data are consistent with the data after execution recorded before, and not executing the reverse execution statements if the current data are inconsistent with the data after execution.
12. The apparatus for distributed transaction rollback according to claim 9, further comprising:
a comparison module: and the distributed transaction processing system is configured to perform MD5 encryption on executed data to obtain a first encryption value after execution of an execution statement of the distributed transaction is finished, perform MD5 encryption on current data to obtain a second encryption value when the execution of a reverse execution statement which fails in response to execution failure of the execution statement of the distributed transaction needs to be executed, compare the second encryption value with the previous first encryption value, if the second encryption value is consistent with the previous first encryption value, execute the failed reverse execution statement, and if the second encryption value is inconsistent with the previous first encryption value, not execute the reverse execution statement.
13. An electronic terminal, comprising: a processor, a memory, and a computer program stored for execution on the memory, the processor, when executing the computer program, implementing the method of any of claims 1-8.
14. A computer-readable storage medium, characterized in that the computer program, when being executed by a processor, implements the method of any one of claims 1-8.
CN202111518666.2A 2021-12-13 2021-12-13 Distributed transaction rollback method, device, terminal and storage medium based on sub-base and sub-table Pending CN114461601A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111518666.2A CN114461601A (en) 2021-12-13 2021-12-13 Distributed transaction rollback method, device, terminal and storage medium based on sub-base and sub-table

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111518666.2A CN114461601A (en) 2021-12-13 2021-12-13 Distributed transaction rollback method, device, terminal and storage medium based on sub-base and sub-table

Publications (1)

Publication Number Publication Date
CN114461601A true CN114461601A (en) 2022-05-10

Family

ID=81405726

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111518666.2A Pending CN114461601A (en) 2021-12-13 2021-12-13 Distributed transaction rollback method, device, terminal and storage medium based on sub-base and sub-table

Country Status (1)

Country Link
CN (1) CN114461601A (en)

Similar Documents

Publication Publication Date Title
US11429641B2 (en) Copying data changes to a target database
US20220245127A1 (en) Applications of automated discovery of template patterns based on received requests
WO2015144003A1 (en) Systems and methods to optimize multi-version support in indexes
US20160147834A1 (en) Set-Orientated Visibility State Retrieval Scheme
CN111522631B (en) Distributed transaction processing method, device, server and medium
CN111259004B (en) Method for indexing data in storage engine and related device
US8874519B1 (en) Method and apparatus for restoring a table in a database
US7809764B2 (en) Method and apparatus for preserving dependancies during data transfer and replication
US8667010B2 (en) Database table partitioning allowing overlaps used in full text query
US9454561B2 (en) Method and a consistency checker for finding data inconsistencies in a data repository
CN115145943B (en) Method, system, equipment and storage medium for rapidly comparing metadata of multiple data sources
US7546311B2 (en) Optimization of left and right outer join operations in database management systems
CN110609860A (en) Data ETL processing method, device, equipment and storage medium
CN111324620A (en) Data processing method, device and storage medium
CN111444199A (en) Data processing method and device, storage medium and processor
US10838947B2 (en) Consistency check for foreign key definition
CN115687392A (en) SQL statement optimized execution method and device, electronic equipment and medium
CN114461601A (en) Distributed transaction rollback method, device, terminal and storage medium based on sub-base and sub-table
CN116089394A (en) Data rollback method, storage medium and device of database
CN113419896B (en) Data recovery method, device, electronic equipment and computer readable medium
CN114490865A (en) Database synchronization method, device, equipment and computer storage medium
CN113268483A (en) Request processing method and device, electronic equipment and storage medium
CN113282600B (en) Batch primary key updating processing method and system under Oracle database synchronization environment
US20220253546A1 (en) System and method for representing and verifying a data set using a tree-based data structure
CN117874082A (en) Method for searching associated dictionary data and related components

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