Distributed transaction processing method, device and electronic equipment

By generating rollback instructions and obtaining proxy sub-transaction log data, the main transaction database data is automatically restored, solving the data inconsistency problem caused by main transaction exceptions after code migration, and achieving automatic recovery and cost savings.

CN113868340BActive Publication Date: 2025-09-23INDUSTRIAL AND COMMERCIAL BANK OF CHINA
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111212329.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-10-18
Publication Date
2025-09-23
Estimated Expiration
2041-10-18

AI Technical Summary

Technical Problem

In the financial industry, after the code is migrated from the mainframe to the distributed platform, data cannot be automatically restored when an exception occurs in the main transaction, resulting in inconsistent database data and requiring manual intervention, resulting in wasted labor costs.

Method used

By generating a rollback instruction, determining the proxy sub-transaction corresponding to the main transaction, and obtaining the database operation information in its log data, the main transaction database data is automatically restored.

Benefits of technology

It realizes automatic data recovery when the main transaction is abnormal, avoids manual intervention, saves labor costs, and ensures the consistency of database data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN113868340B_ABST
    Figure CN113868340B_ABST
Patent Text Reader

Abstract

The present invention discloses a method, device, and electronic device for processing distributed transactions, relating to the field of financial technology. The method comprises: upon detecting an exception in a main transaction, generating a rollback instruction, and determining at least one proxy sub-transaction corresponding to the main transaction based on the rollback instruction, wherein the at least one proxy sub-transaction corresponds to a transaction branch corresponding to the main transaction, thereby obtaining at least one log data corresponding to the at least one proxy sub-transaction, wherein the at least one log data stores database operation information for operating data in a database, and then performing a recovery operation on the data in the database corresponding to the main transaction based on the at least one log data. The present invention at least solves the technical problem in the prior art of data inconsistency caused by the inability to automatically recover data after the code is migrated from the host to the distributed platform.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of financial technology, and in particular to a method, device and electronic device for processing distributed transactions. Background Art

[0002] With the development of big data technology, data storage and processing have become increasingly important. Compared to other industries, the financial industry generates more data every day. Therefore, the financial industry generally adopts distributed platforms to store data and uses a distributed transaction processing model to handle transactions.

[0003] The transaction processing model of distributed transactions requires that corresponding data recovery operations be performed when an exception occurs in the main transaction to ensure data consistency in the database. However, in the financial industry, there are many scenarios where code is written on the mainframe and then migrated to the distributed platform. For this code, when an exception occurs in the main transaction, automatic data recovery is not supported and manual intervention is required to restore the data. This process consumes a lot of manpower and results in unnecessary waste of labor costs. Summary of the Invention

[0004] Embodiments of the present invention provide a method, apparatus, and electronic device for processing distributed transactions, to at least solve the problem of data inconsistency in the prior art caused by the inability to automatically restore data after code is migrated from a host to a distributed platform.

[0005] According to one aspect of an embodiment of the present invention, a method for processing distributed transactions is provided. The method includes: generating a rollback instruction when an exception is detected in a main transaction, and determining at least one proxy sub-transaction corresponding to the main transaction based on the rollback instruction, wherein the at least one proxy sub-transaction corresponds to a transaction branch corresponding to the main transaction, thereby obtaining at least one log data corresponding to the at least one proxy sub-transaction, wherein the at least one log data stores database operation information for operating on data in a database, and then performing a recovery operation on the data in the database corresponding to the main transaction based on the at least one log data.

[0006] Furthermore, the distributed transaction processing method also includes: before obtaining at least one log data corresponding to at least one proxy sub-transaction, after the main transaction is started and an operation on the data in the database is detected, obtaining database operation information, and storing the database operation information in at least one log data.

[0007] Furthermore, the distributed transaction processing method also includes: when storing database operation information in at least one log data, obtaining a main transaction identifier corresponding to the main transaction and a proxy sub-transaction identifier corresponding to at least one proxy sub-transaction, and associating at least one log data with the main transaction based on the main transaction identifier and the proxy sub-transaction identifier, wherein one main transaction identifier may correspond to at least one proxy sub-transaction identifier, and the at least one log data includes at least: the main transaction identifier, the proxy sub-transaction identifier, first data before the data in the database is modified, second data after the data in the database is modified, and the database operation type.

[0008] Furthermore, the distributed transaction processing method also includes: obtaining at least one log data from a preset storage area based on the main transaction identifier and the proxy sub-transaction identifier, and determining the database operation type corresponding to the at least one log data, thereby performing a recovery operation on the data in the database based on the database operation type.

[0009] Furthermore, the distributed transaction processing method also includes: when the database operation type is a data update operation, obtaining second data from at least one log data, and determining the current data after the data update in the database based on the first primary key of the second data, and judging whether the current data is the same as the second data, so that when the current data is the same as the second data, the current data is updated to the first data.

[0010] Furthermore, the distributed transaction processing method also includes: when the current data is different from the second data, determining that the main transaction is in a preset state and generating a rollback failure prompt message, wherein the preset state represents that other main transactions have performed data operations on the second data.

[0011] Furthermore, the distributed transaction processing method also includes: when the database operation type is a data insertion operation, obtaining second data from at least one log data, thereby determining the data insertion position in the database based on the second primary key of the second data, and deleting the current data at the data insertion position.

[0012] Furthermore, the distributed transaction processing method also includes: when the database operation type is a data deletion operation, obtaining first data from at least one log data, thereby determining the data deletion position in the database based on the third primary key of the first data, and inserting the first data into the data deletion position.

[0013] According to another aspect of an embodiment of the present invention, a distributed transaction processing device is provided, comprising: a generation module for generating a rollback instruction when an exception is detected in a main transaction; a determination module for determining, based on the rollback instruction, at least one proxy sub-transaction corresponding to the main transaction, wherein the at least one proxy sub-transaction corresponds to a transaction branch corresponding to the main transaction; an acquisition module for acquiring at least one piece of log data corresponding to the at least one proxy sub-transaction, wherein the at least one log data piece stores database operation information for operating on data in the database; and a recovery module for performing a recovery operation on the data in the database corresponding to the main transaction based on the at least one piece of log data.

[0014] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is further provided, characterized in that a computer program is stored in the computer-readable storage medium, wherein the computer program is configured to execute the above-mentioned distributed transaction processing method when running.

[0015] According to another aspect of an embodiment of the present invention, an electronic device is also provided, characterized in that the electronic device includes one or more processors; a storage device for storing one or more programs, which, when the one or more programs are executed by the one or more processors, enables the one or more processors to run the programs, wherein the programs are configured to execute the above-mentioned distributed transaction processing method at runtime.

[0016] In an embodiment of the present invention, database operation information is stored through at least one log data, and data in the database is recovered based on the at least one log data. When an exception is detected in a main transaction, a rollback instruction is generated, and at least one proxy sub-transaction corresponding to the main transaction is determined based on the rollback instruction. The at least one proxy sub-transaction corresponds to a transaction branch corresponding to the main transaction, and at least one log data corresponding to the at least one proxy sub-transaction is obtained. The at least one log data stores database operation information on operations performed on the data in the database. Then, a recovery operation is performed on the data in the database corresponding to the main transaction based on the at least one log data.

[0017] In the above process, since the processor can obtain at least one corresponding log data through at least one proxy sub-transaction, and the at least one log data stores database operation information for operating the data in the database, when an exception occurs in the main transaction, the processor can perform a recovery operation on the data in the database corresponding to the main transaction based on the at least one log data, thereby avoiding the problem of data inconsistency in the database due to the inability to automatically recover data when an exception occurs in the main transaction after the code is migrated from the host to the distributed platform.

[0018] It can be seen that the solution provided by the present application achieves the purpose of automatically recovering the data in the database when an exception occurs in the main transaction, thereby avoiding a large amount of manual data recovery and saving labor costs, and further solving the problem of data inconsistency in the database caused by the inability to automatically recover data when an exception occurs in the main transaction after the code is migrated from the host to the distributed platform. BRIEF DESCRIPTION OF THE DRAWINGS

[0019] The drawings described herein are used to provide a further understanding of the present invention and constitute a part of this application. The exemplary embodiments of the present invention and their descriptions are used to explain the present invention and do not constitute an improper limitation of the present invention. In the drawings:

[0020] Figure 1 This is a flow chart of an optional distributed transaction processing method in the prior art;

[0021] Figure 2 is a flowchart of an optional distributed transaction processing method according to an embodiment of the present invention;

[0022] Figure 3 is a flowchart of an optional distributed transaction processing method according to an embodiment of the present invention;

[0023] Figure 4 is a flowchart of an optional distributed transaction processing method according to an embodiment of the present invention;

[0024] Figure 5 3 is a schematic diagram of an optional distributed transaction processing device according to an embodiment of the present invention. DETAILED DESCRIPTION

[0025] In order to enable those skilled in the art to better understand the solutions of the present invention, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the embodiments described are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without making creative efforts should fall within the scope of protection of the present invention.

[0026] It should be noted that the terms "first", "second", etc. in the description and claims of the present invention and the above-mentioned drawings are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that the numbers used in this way can be interchanged where appropriate, so that the embodiments of the present invention described herein can be implemented in an order other than those illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0027] Example 1

[0028] According to an embodiment of the present invention, an embodiment of a method for processing distributed transactions is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0029] It should be noted that in this embodiment, the processor in a computer device can be used as the execution subject of the distributed transaction processing method in this embodiment. The computer device includes but is not limited to: laptop computers, desktop computers, smart tablet computers, smart phones and other devices.

[0030] Figure 2 is a flow chart of an optional distributed transaction processing method according to an embodiment of the present invention, such as Figure 2 As shown, the method includes the following steps:

[0031] Step S202: When an exception is detected in the main transaction, a rollback instruction is generated.

[0032] Optionally, the processor can process transactions using the SAGA (Long Running Transaction Mode) mode of distributed transactions, where distributed transactions can be divided into transaction initiators, transaction participants, and transaction coordinators according to different participating roles. A distributed transaction consists of a main transaction and at least one sub-transaction.

[0033] In addition, the main transaction is started by the transaction initiator, and the subtransaction is started by the transaction participant. The subtransaction can be a local database subtransaction or a remote subtransaction. During the entire transaction cycle, if there are no abnormalities in the transaction initiator, transaction participant, and transaction coordinator, the subtransaction will be submitted first, and then the main transaction will be submitted. Otherwise, all transactions will be rolled back. Furthermore, after the main transaction is started, the processor will generate a unique main transaction number. The main transaction number is used to mark the unique main transaction. After the subtransaction is started, the processor will generate a unique subtransaction number. The subtransaction number is used to mark the unique subtransaction. The SAGA mode of distributed transactions requires that each subtransaction can perform data recovery. Once the main transaction is abnormal, the transaction coordinator will notify each transaction participant to perform data recovery.

[0034] Furthermore, the reasons for the main transaction exception include at least: a sub-transaction error, an interruption in the transaction processing, and an error in the main transaction itself. The rollback instruction indicates that the main transaction has an exception and data recovery is required on the database, i.e., a transaction rollback.

[0035] In the above process, by detecting the status of the main transaction in real time, it is possible to promptly understand whether the main transaction has any abnormalities and whether data recovery operations are required, which is conducive to timely recovery of data and ensuring data consistency.

[0036] Step S204: determining at least one proxy sub-transaction corresponding to the main transaction according to the rollback instruction.

[0037] In step S204, at least one proxy sub-transaction corresponds to the transaction branch corresponding to the main transaction. The transaction branch corresponding to the main transaction can be any one of the at least one sub-transaction. For example, the main transaction is transaction A, and the sub-transactions are sub-transactions 001, 002, and 003, where each sub-transaction is a transaction branch corresponding to the main transaction. Furthermore, the processor determines whether the current sub-transaction is a local database sub-transaction or a remote sub-transaction based on the different regions in which each sub-transaction is located in the current distributed platform. For example, if sub-transaction numbered 001 is in the local database in the current distributed platform, and sub-transactions numbered 002 and 003 are in non-local databases in the current distributed platform, 001 can be determined to be a local database sub-transaction, and 002 and 003 can be determined to be remote sub-transactions. The proxy sub-transaction can be used to proxy the local database sub-transactions in at least one sub-transaction.

[0038] Step S206: Obtain at least one piece of log data corresponding to at least one proxy sub-transaction.

[0039] Optional, Figure 1 This is a flow chart of an optional distributed transaction processing method in the prior art, such as Figure 1As shown in the figure, after migrating the code on the host to the distributed platform, when using the transaction processing mode of distributed transactions for transaction processing, the processor will first start the main transaction and generate a main transaction number, and save it in the preset storage area. Then, the processor will start the database local sub-transaction corresponding to the main transaction. The database local sub-transaction is wrapped in the main transaction. If the database local sub-transaction fails, it will cause the main transaction to roll back. Among them, local database operations and remote sub-transaction calls are interspersed. For example, Figure 2 The processing of local sub-transactions in the database involves local data operation 1, local database operation 2, and local database operation 3. During the local database operation, different remote sub-transactions can be called interspersed, for example, Figure 1 As shown in the remote subtransaction call 1, remote subtransaction call 2, and remote subtransaction call 3. If the local subtransaction of the database has no exceptions, it will be committed normally; if the local subtransaction of the database fails to commit or an exception occurs, it will result in a rollback; if the main transaction has no exceptions, it will be committed normally; if the main transaction fails to commit or an exception occurs, it will result in a rollback.

[0040] It should be noted that in the prior art, if the main transaction fails to commit, it will cause the main transaction to roll back, and the main transaction rollback will cause all participating sub-transactions to roll back. However, the database local sub-transaction has been committed in the previous step and will not be able to be rolled back, that is, the data in the database cannot be automatically restored, thus causing data inconsistency problems.

[0041] In step S206, data operation information of the local data operation corresponding to the local sub-transaction of the database is recorded through at least one proxy sub-transaction and stored in at least one log data. Therefore, when an exception occurs in the main transaction, the processor can query the corresponding log data to recover the data in the database, thereby achieving the effect of ensuring data consistency.

[0042] Step S208: Perform a recovery operation on the data in the database corresponding to the primary transaction according to at least one log data.

[0043] In step S208, the recovery operation includes at least: data insertion, data modification, and data deletion operations, wherein at least one log data includes at least: a main transaction identifier, a proxy subtransaction identifier, first data before the data in the database is modified, second data after the data in the database is modified, and a database operation type.

[0044] Furthermore, based on the main transaction identifier and the proxy sub-transaction identifier, at least one log data corresponding to the abnormal main transaction can be determined, and based on the first data, the second data and the database operation type in the at least one log data, the data change can be determined, and corresponding data recovery can be performed based on the data change. For example, for inserted data, a deletion operation is performed, and for deleted data, a data reinsertion operation is performed.

[0045] It should be noted that when an exception occurs in the main transaction, the processor can restore the data in the database corresponding to the main transaction based on at least one log data, thereby avoiding the problem of data inconsistency in the database due to the inability to automatically restore data when an exception occurs in the main transaction after the code is migrated from the host to the distributed platform.

[0046] Based on the scheme defined in steps S202 to S208, it can be seen that in an embodiment of the present invention, a method of storing database operation information through at least one log data and thus recovering data in the database based on the at least one log data is adopted. When an exception is detected in a main transaction, a rollback instruction is generated, and at least one proxy sub-transaction corresponding to the main transaction is determined based on the rollback instruction, wherein the at least one proxy sub-transaction corresponds to a transaction branch corresponding to the main transaction, and at least one log data corresponding to the at least one proxy sub-transaction is obtained, wherein the at least one log data stores database operation information for operating on the data in the database, and then a recovery operation is performed on the data in the database corresponding to the main transaction based on the at least one log data.

[0047] It is easy to notice that in the above process, since the processor can obtain at least one corresponding log data through at least one proxy sub-transaction, and the at least one log data will store database operation information for operating the data in the database, therefore, when an exception occurs in the main transaction, the processor can perform recovery operations on the data in the database corresponding to the main transaction based on the at least one log data, thereby avoiding the problem of data inconsistency in the database due to the inability to automatically recover data when an exception occurs in the main transaction after the code is migrated from the host to the distributed platform.

[0048] It can be seen that the solution provided by the present application achieves the purpose of automatically recovering the data in the database when an exception occurs in the main transaction, thereby avoiding a large amount of manual data modification and saving labor costs, and further solving the problem of data inconsistency in the database caused by the inability to automatically recover data if an exception occurs in the main transaction after the code is migrated from the host to the distributed platform.

[0049] In an optional embodiment, after the main transaction is started and an operation on data in the database is detected, the processor obtains database operation information and stores the database operation information in at least one log data.

[0050] Optional, Figure 3 is a flow chart of an optional distributed transaction processing method according to an embodiment of the present invention, such as Figure 3 As shown, after the main transaction is started, the processor will immediately start a proxy sub-transaction to proxy the database local sub-transaction. At the same time, after the database local sub-transaction is started, the processor will detect the local database operation in real time and obtain database operation information, such as the database operation type, the change information of the data in the database, the database operation time, and the database operator.

[0051] Further, such as Figure 3 As shown, after obtaining database operation information, the processor stores the database operation information in at least one log data item. For example, upon completing local database operations 1, 2, and 3, the processor obtains the database operation information corresponding to local database operations 1, 2, and 3 in real time and stores it in at least one log data item. The processor can then call the remote subtransaction normally. After the local database subtransaction is committed, the proxy subtransaction commits, ultimately completing the commit of the main transaction.

[0052] In the above process, by obtaining database operation information and storing the database operation information in at least one log data, the effect of obtaining data changes in the database in real time is achieved, thereby providing a data basis for subsequent data recovery.

[0053] In an optional embodiment, the processor may further obtain a main transaction identifier corresponding to the main transaction and a proxy subtransaction identifier corresponding to at least one proxy subtransaction, and associate at least one piece of log data with the main transaction based on the main transaction identifier and the proxy subtransaction identifier, wherein one main transaction identifier may correspond to at least one proxy subtransaction identifier, and the at least one piece of log data includes at least: the main transaction identifier, the proxy subtransaction identifier, first data before modifying data in the database, second data after modifying data in the database, and a database operation type.

[0054] Optionally, when an exception occurs in a main transaction, the processor may obtain a main transaction identifier corresponding to the abnormal main transaction and a proxy sub-transaction identifier corresponding to at least one proxy sub-transaction, and associate the abnormal main transaction with at least one piece of log data, wherein the at least one associated log data includes at least: the main transaction identifier of the abnormal main transaction, the proxy sub-transaction identifier, the first data, the second data, and the database operation type.

[0055] Furthermore, the database operation types include at least: data update operation, data deletion operation and data insertion operation.

[0056] In the above process, at least one log data corresponding to the main transaction can be determined through the main transaction identifier and the proxy sub-transaction identifier in at least one log data, and the data change can be determined based on the first data, the second data and the database operation type in the at least one log data, thereby achieving the effect of associating the main transaction and the corresponding log data.

[0057] In an optional embodiment, the processor may also obtain at least one piece of log data from a preset storage area based on the main transaction identifier and the proxy sub-transaction identifier, and determine the database operation type corresponding to the at least one piece of log data, thereby performing a recovery operation on the data in the database based on the database operation type.

[0058] Optional, Figure 4 is a flow chart of an optional distributed transaction processing method according to an embodiment of the present invention, such as Figure 4 As shown, when the main transaction fails to commit and needs to be rolled back, the main transaction first initiates the rollback, and the transaction coordinator notifies all sub-transaction participants to roll back the transaction. Then, the proxy sub-transaction rolls back the corresponding database local sub-transaction. The proxy sub-transaction retrieves at least one log data item corresponding to the main transaction from a preset storage area based on the main transaction identifier and the proxy sub-transaction identifier, and detects the corresponding database operation type in the at least one log data item. The database operation type includes at least: data update operation, data deletion operation, and data insertion operation. After determining the database operation type, the processor can perform corresponding recovery operations on the data in the database based on the database operation type.

[0059] In the above process, by determining the database operation type, corresponding data recovery operations can be performed for different data operations, thereby ensuring the accuracy of data recovery.

[0060] In an optional embodiment, when the database operation type is a data update operation, the processor obtains the second data from at least one log data, thereby determining the current data after the data update in the database based on the first primary key of the second data, and judging whether the current data is the same as the second data, and when the current data is the same as the second data, updating the current data to the first data.

[0061] Optional, such as Figure 4As shown, when the processor determines that the database operation type in at least one log data is a data update operation, the processor will further use the second data recorded in at least one log data to determine whether the current data has changed, wherein the second data is the data after the data in the database is modified, and the current data can be determined from the database based on the first primary key corresponding to the second data.

[0062] Furthermore, when the processor determines that the current data is the same as the second data, it means that the current data is generated through the above-mentioned data update operation. Since the data needs to be restored, the current data can be updated to the first data recorded in at least one log data, wherein the first data is the data before the data in the database is modified.

[0063] Through the above process, when the database operation type is a data update operation, the processor can restore the data in the database based on the first data and the second data in at least one log data, thereby avoiding the problem of manual data recovery and achieving the effect of saving labor costs.

[0064] In an optional embodiment, when the database operation type is a data update operation, if the processor determines that the current data is different from the second data, the processor determines that the main transaction is in a preset state and generates a prompt message of rollback failure, wherein the preset state indicates that other main transactions have performed data operations on the second data.

[0065] Optional, such as Figure 4 As shown, when the database operation type is a data update operation, if the processor determines that the current data and the second data in at least one log data are different, it means that another main transaction has performed a data operation on the second data. For example, the second data recorded in at least one log data is 20, and the first data is 10, which means that the data update operation recorded in at least one log data is to update 10 to 20. If no other main transaction has performed a data operation on the second data, the current data should be 20. If the current data is not 20, for example, the current data is 30, it means that another main transaction has performed a data operation based on the second data. Therefore, the processor will determine the main transaction at this time as a preset state and generate a prompt message indicating a rollback failure, so that the operator can intervene and handle it in a timely manner.

[0066] In the above process, when the database operation type is a data update operation and the processor determines that the current data is different from the second data, by determining the main transaction as a preset state and generating a prompt message, the rigor of data recovery is ensured, which is conducive to improving data accuracy.

[0067] In an optional embodiment, when the database operation type is a data insertion operation, the processor obtains second data from at least one log data, thereby determining the data insertion position in the database based on the second primary key of the second data, and deletes the current data at the data insertion position.

[0068] Optional, such as Figure 4 As shown, when the processor determines that the database operation type in at least one log data is a data insertion operation, the processor will determine the data insertion position in the data based on the second primary key corresponding to the second data recorded in at least one log data, thereby deleting the current data at the data insertion position.

[0069] In the above process, the data insertion position corresponding to the second data in the database is determined by the second primary key, and the current data at the data insertion position is deleted, thereby achieving the effect of restoring the data in the database when the database operation type is a data insertion operation, thereby avoiding the problem of manual data recovery and achieving the purpose of saving labor costs.

[0070] In an optional embodiment, when the database operation type is a data deletion operation, the processor obtains the first data from at least one log data, thereby determining the data deletion position in the database according to the third primary key of the first data, and inserts the first data into the data deletion position.

[0071] Optional, such as Figure 4 As shown, when the processor determines that the database operation type in at least one log data is a data deletion operation, the processor will obtain the first data from at least one log data, and determine the data deletion position in the data based on the third primary key corresponding to the first data, thereby inserting the first data to the data deletion position to complete data recovery.

[0072] Furthermore, after the data is successfully recovered, the processor will generate prompt information indicating that the main transaction is rolled back successfully and the proxy sub-transaction is rolled back successfully.

[0073] Through the above process, when the database operation type is a data deletion operation, the processor can restore the data in the database based on the first data in at least one log data, thereby avoiding the problem of manual data recovery and achieving the effect of saving labor costs.

[0074] As can be seen from the above content, in the above process, since the processor can obtain at least one corresponding log data through at least one proxy sub-transaction, and the at least one log data will store database operation information for operating the data in the database, therefore, when an exception occurs in the main transaction, the processor can perform a recovery operation on the data in the database corresponding to the main transaction based on the at least one log data, thereby avoiding the problem of data inconsistency in the database due to the inability to automatically recover data when an exception occurs in the main transaction after the code is migrated from the host to the distributed platform.

[0075] Example 2

[0076] According to an embodiment of the present invention, there is also provided an embodiment of a distributed transaction processing device, wherein: Figure 5 FIG. 1 is a schematic diagram of an optional distributed transaction processing device according to an embodiment of the present invention. Figure 5 As shown, the processing device includes: a generating module 501 , a determining module 503 , an acquiring module 505 and a recovering module 507 .

[0077] The generation module 501 is configured to generate a rollback instruction when an exception is detected in a main transaction. The determination module 503 is configured to determine, based on the rollback instruction, at least one proxy sub-transaction corresponding to the main transaction, wherein the at least one proxy sub-transaction corresponds to a transaction branch corresponding to the main transaction. The acquisition module 505 is configured to acquire at least one piece of log data corresponding to the at least one proxy sub-transaction, wherein the at least one log data piece stores database operation information regarding operations performed on data in the database. The recovery module 507 is configured to perform a recovery operation on the data in the database corresponding to the main transaction based on the at least one piece of log data.

[0078] It should be noted that the above-mentioned generation module 501, determination module 503, acquisition module 505 and recovery module 507 correspond to steps S202 to S208 in the above-mentioned embodiment. The examples and application scenarios implemented by the four modules and the corresponding steps are the same, but are not limited to the contents disclosed in the above-mentioned embodiment 1.

[0079] Optionally, the distributed transaction processing device further includes: a first acquisition module and a storage module. The first acquisition module is configured to acquire database operation information after the main transaction is started and an operation on data in the database is detected; and the storage module is configured to store the database operation information in at least one log data item.

[0080] Optionally, the storage module further includes: a second acquisition module and an association module, wherein the second acquisition module is used to acquire a main transaction identifier corresponding to the main transaction and a proxy subtransaction identifier corresponding to at least one proxy subtransaction; and the association module is used to associate at least one piece of log data with the main transaction based on the main transaction identifier and the proxy subtransaction identifier, wherein one main transaction identifier may correspond to at least one proxy subtransaction identifier, and the at least one piece of log data includes at least: the main transaction identifier, the proxy subtransaction identifier, first data before the data in the database is modified, second data after the data in the database is modified, and a database operation type.

[0081] Optionally, the recovery module further includes: a third acquisition module, a first determination module, and a first recovery module. The third acquisition module is configured to acquire at least one piece of log data from a preset storage area based on the main transaction identifier and the proxy subtransaction identifier; the first determination module is configured to determine the database operation type corresponding to the at least one piece of log data; and the first recovery module is configured to perform a recovery operation on the data in the database based on the database operation type.

[0082] Optionally, the recovery module further includes: a fourth acquisition module, a second determination module, and an update module. The fourth acquisition module is configured to acquire the second data from at least one log data item when the database operation type is a data update operation; the second determination module is configured to determine the current data in the database after the data update based on the first primary key of the second data, and to determine whether the current data is identical to the second data; and the update module is configured to update the current data to the first data when the current data is identical to the second data.

[0083] Optionally, the distributed transaction processing device also includes: a third determination module, which is used to determine that the main transaction is in a preset state when the current data is different from the second data, and generate a prompt message of rollback failure, wherein the preset state represents that other main transactions have performed data operations on the second data.

[0084] Optionally, the recovery module further includes: a fifth acquisition module, a fourth determination module, and a deletion module. The fifth acquisition module is configured to acquire the second data from at least one log data entry when the database operation type is a data insert operation; the fourth determination module is configured to determine a data insertion position in the database based on a second primary key of the second data; and the deletion module is configured to delete the current data at the data insertion position.

[0085] Optionally, the recovery module further includes: a sixth acquisition module, a fifth determination module, and an insertion module. The sixth acquisition module is configured to acquire the first data from at least one log data entry when the database operation type is a data deletion operation; the fifth determination module is configured to determine a data deletion location in the database based on the third primary key of the first data; and the insertion module is configured to insert the first data into the data deletion location.

[0086] Example 3

[0087] According to another aspect of an embodiment of the present invention, a computer-readable storage medium is provided, characterized in that a computer program is stored in the computer-readable storage medium, wherein the computer program is configured to execute the above-mentioned distributed transaction processing method when running.

[0088] Example 4

[0089] According to another aspect of an embodiment of the present invention, an electronic device is also provided, which includes one or more processors; a storage device for storing one or more programs, which, when the one or more programs are executed by the one or more processors, enables the one or more processors to run the programs, wherein the programs are configured to execute the above-mentioned distributed transaction processing method at runtime.

[0090] The serial numbers of the above embodiments of the present invention are for description only and do not represent the advantages or disadvantages of the embodiments.

[0091] In the above embodiments of the present invention, the description of each embodiment has its own focus. For parts that are not described in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0092] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. Among them, the device embodiments described above are only exemplary. For example, the division of the units can be a logical function division. In actual implementation, there may be other division methods, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of units or modules, which can be electrical or other forms.

[0093] The units described as separate components may or may not be physically separate, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple units. Some or all of the units may be selected according to actual needs to achieve the purpose of the present embodiment.

[0094] In addition, the functional units in the various embodiments of the present invention may be integrated into a single processing unit, each unit may exist physically separately, or two or more units may be integrated into a single unit. The aforementioned integrated units may be implemented in the form of hardware or software functional units.

[0095] If the integrated unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or all or part of the technical solution can be embodied in the form of a software product. The computer software product is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, server or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), mobile hard disk, magnetic disk or optical disk, etc. Various media that can store program codes.

[0096] The above is only a preferred embodiment of the present invention. It should be pointed out that for ordinary technicians in this technical field, several improvements and modifications can be made without departing from the principles of the present invention. These improvements and modifications should also be regarded as the scope of protection of the present invention.

Claims

1. A method for processing distributed transactions, characterized in that: include: When an exception is detected in the main transaction, a rollback instruction is generated; determining, according to the rollback instruction, at least one proxy sub-transaction corresponding to the main transaction, wherein the at least one proxy sub-transaction corresponds to a transaction branch corresponding to the main transaction, the transaction branch corresponding to the main transaction is any one of the at least one sub-transaction, and the proxy sub-transaction may be used to proxy a database local sub-transaction in the at least one sub-transaction; Acquire at least one piece of log data corresponding to the at least one proxy sub-transaction, wherein the at least one piece of log data stores database operation information of operating data in the database; Performing a recovery operation on the data in the database corresponding to the main transaction according to the at least one log data; Before obtaining at least one log data corresponding to the at least one proxy sub-transaction, the method further includes: after the main transaction is started and an operation on the data in the database is detected, obtaining the database operation information; storing the database operation information in the at least one log data; When storing the database operation information in the at least one piece of log data, the method further includes: obtaining a main transaction identifier corresponding to the main transaction and a proxy sub-transaction identifier corresponding to the at least one proxy sub-transaction; and associating the at least one piece of log data with the main transaction based on the main transaction identifier and the proxy sub-transaction identifier.

2. The method according to claim 1, characterized in that One main transaction identifier may correspond to at least one proxy sub-transaction identifier, and the at least one log data item includes at least: the main transaction identifier, the proxy sub-transaction identifier, first data before the data in the database is modified, second data after the data in the database is modified, and a database operation type.

3. The method according to claim 2, characterized in that Performing a recovery operation on the data in the database corresponding to the primary transaction according to the at least one log data includes: Acquire the at least one piece of log data from a preset storage area according to the main transaction identifier and the proxy sub-transaction identifier; Determining a database operation type corresponding to the at least one piece of log data; Perform a recovery operation on the data in the database according to the database operation type.

4. The method according to claim 3, characterized in that Performing a recovery operation on the data in the database according to the database operation type includes: When the database operation type is a data update operation, obtaining the second data from the at least one log data; determining the current data after the data in the database is updated according to the first primary key of the second data, and judging whether the current data is the same as the second data; When the current data is identical to the second data, the current data is updated to the first data.

5. The method according to claim 4, further comprising: When the current data is different from the second data, it is determined that the main transaction is in a preset state, and a rollback failure prompt message is generated, wherein the preset state indicates that other main transactions have performed data operations on the second data.

6. The method according to claim 3, characterized in that Performing a recovery operation on the data in the database according to the database operation type includes: When the database operation type is a data insert operation, obtaining the second data from the at least one log data; determining a data insertion position in the database according to a second primary key of the second data; Delete the current data at the data insertion position.

7. The method according to claim 3, characterized in that Performing a recovery operation on the data in the database according to the database operation type includes: When the database operation type is a data deletion operation, obtaining the first data from the at least one log data; determining a data deletion position in the database according to the third primary key of the first data; The first data is inserted into the data deletion position.

8. A distributed transaction processing device, characterized in that: include: A generation module is used to generate a rollback instruction when an exception is detected in the main transaction; a determination module, configured to determine, based on the rollback instruction, at least one proxy sub-transaction corresponding to the main transaction, wherein the at least one proxy sub-transaction corresponds to a transaction branch corresponding to the main transaction, the transaction branch corresponding to the main transaction is any one of the at least one sub-transaction, and the proxy sub-transaction may be used to proxy a database local sub-transaction in the at least one sub-transaction; an acquisition module, configured to acquire at least one piece of log data corresponding to the at least one proxy sub-transaction, wherein the at least one piece of log data stores database operation information of an operation performed on data in a database; A recovery module, configured to perform a recovery operation on the data in the database corresponding to the primary transaction according to the at least one log data; The distributed transaction processing device further includes: a first acquisition module configured to acquire the database operation information after the main transaction is started and an operation on the data in the database is detected, before acquiring the at least one log data corresponding to the at least one proxy sub-transaction; and a storage module configured to store the database operation information in the at least one log data; The storage module further includes: a second acquisition module, configured to acquire a main transaction identifier corresponding to the main transaction and a proxy sub-transaction identifier corresponding to the at least one proxy sub-transaction; and an association module, configured to associate the at least one log data item with the main transaction based on the main transaction identifier and the proxy sub-transaction identifier.

9. A computer-readable storage medium, characterized in that The computer-readable storage medium stores a computer program, wherein the computer program is configured to execute the method for processing distributed transactions as claimed in any one of claims 1 to 7 when running.

10. An electronic device, characterized in that: The electronic device includes one or more processors; A storage device for storing one or more programs, which, when executed by the one or more processors, enables the one or more processors to run the programs, wherein the programs are configured to execute the distributed transaction processing method described in any one of claims 1 to 7 at runtime.

Citation Information

Patent Citations

  • Internal store data base transaction method and system

    CN101089857A

  • Distributed type transaction management method and system

    CN106503132A