A transaction processing method, system and apparatus

By acquiring and executing compensation tasks, the problem of data inconsistency in transaction processing in distributed architecture is solved, data recovery and consistency guarantee are achieved under abnormal conditions, and the stability of the system is improved.

CN114327792BActive Publication Date: 2025-11-04BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202111436919.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2021-11-29
Publication Date
2025-11-04
Estimated Expiration
2041-11-29

AI Technical Summary

Technical Problem

In a distributed architecture, how can we ensure data consistency during transaction processing, especially in order transaction processing involving multiple application services, to ensure that data consistency is not compromised?

Method used

By obtaining the compensation task whose execution result is a failure recorded in the first database, a compensation task is sent to the corresponding application service, so that the application service executes the compensation task and updates the compensation task recorded in the database according to the execution result, thereby realizing the recovery and retry of sub-transaction data and ensuring data consistency.

Benefits of technology

During transaction processing, it can effectively recover data inconsistencies caused by anomalies, and ensure data consistency of pending transactions by retrying compensation tasks, thereby improving the stability and reliability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114327792B_ABST
    Figure CN114327792B_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a transaction processing method, system and device, and relate to the technical field of Internet, obtaining a first compensation task with a record in a first database whose execution result is failure; wherein the first compensation task is used for recovering data processed by a corresponding sub-transaction in a to-be-processed transaction; sending the first compensation task to a corresponding first application service, so that the first application service executes the first compensation task; and updating the compensation task with the record in the first database according to an execution result of the first compensation task sent by the first application service. In this way, the consistency of data corresponding to the to-be-processed transaction can be ensured.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of Internet, in particular to a transaction processing method, system and device. BACKGROUND

[0002] With the rapid development of Internet technology, the business system in many fields gradually changes from monolithic architecture to distributed architecture, so that a transaction needs to be completed by multiple application services.

[0003] For example, an order transaction of generating an order can be jointly participated by four application services, which are order service, user service, account service and kitchen service. The processing flow of the order transaction is as follows: a user creates an order waiting for approval through the order service; the user service verifies whether the user has the right to place an order; the account service provides an authorization operation for the user to pay; the kitchen service changes the order state to a state of waiting for acceptance; the order service changes the order state to an accepted state; and the order transaction is completed. In the processing of the order transaction, the data consistency in the order service, the user service, the account service and the kitchen service needs to be ensured.

[0004] How to ensure the consistency of the data of a transaction in multiple application services is a problem to be solved by distributed transactions. SUMMARY

[0005] The purpose of the embodiments of the present application is to provide a transaction processing method, system and device, which can ensure the consistency of the data corresponding to a to-be-processed transaction. The specific technical solutions are as follows:

[0006] In a first aspect, the present application provides a transaction processing method, which comprises the following steps:

[0007] obtaining a first compensation task recorded in a first database, wherein the execution result of the first compensation task is failure; and wherein the first compensation task is used to recover the data processed by a corresponding sub-transaction in a to-be-processed transaction;

[0008] sending the first compensation task to a corresponding first application service, so that the first application service executes the first compensation task;

[0009] updating the compensation task recorded in the first database according to the execution result of the first compensation task sent by the first application service.

[0010] In a second aspect, the present application also provides a transaction processing system, which comprises an application service cluster and a control server, wherein:

[0011] the control server is configured to execute the transaction processing method of the first aspect;

[0012] each application server in the application service cluster is configured to execute a corresponding sub-transaction in the to-be-processed transaction and a corresponding compensation task of the sub-transaction through the application service.

[0013] In a third aspect, the application provides a transaction processing device, which comprises:

[0014] a first obtaining module configured to obtain a first compensation task recorded in the first database and having a failed execution result, wherein the first compensation task is configured to recover data processed by a corresponding sub-transaction in the to-be-processed transaction;

[0015] a first sending module configured to send the first compensation task to a corresponding first application service, so that the first application service executes the first compensation task;

[0016] a first updating module configured to update the compensation task recorded in the first database according to an execution result of the first compensation task sent by the first application service.

[0017] The application also provides an electronic device, which comprises a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory can communicate with each other through the communication bus.

[0018] The memory is configured to store a computer program.

[0019] The processor is configured to execute the program stored in the memory, so as to implement the transaction processing method.

[0020] The application also provides a computer readable storage medium, which stores a computer program, and the computer program is executed by a processor to implement the transaction processing method.

[0021] The application also provides a computer program product comprising instructions, which, when executed on a computer, cause the computer to perform the transaction processing method.

[0022] The application has the following beneficial effects:

[0023] The distributed transaction compensation method provided by the application comprises the following steps: obtaining a first compensation task recorded in a first database and having a failed execution result, wherein the first compensation task is configured to recover data processed by a corresponding sub-transaction in a to-be-processed transaction; sending the first compensation task to a corresponding first application service, so that the first application service executes the first compensation task; and updating a compensation task recorded in the first database according to an execution result of the first compensation task sent by the first application service.

[0024] Based on the above processing, the compensation task with the execution result of failure is recorded in the first database, and the compensation task is used to compensate the sub-transaction, therefore, the application service is sent the compensation task with the execution result of failure, so that the application service can compensate the corresponding sub-transaction, and the data processed by the corresponding sub-transaction can be recovered. That is, if there is a sub-transaction with execution exception in the to-be-processed transaction, based on the method of the embodiment of the application, the corresponding compensation task can be executed to recover the data, and when the compensation task fails, the compensation task can be continuously retried, and thus the consistency of the data corresponding to the to-be-processed transaction is ensured.

[0025] Of course, implementing any product or method of the application does not necessarily require all the advantages described above to be achieved at the same time. BRIEF DESCRIPTION OF DRAWINGS

[0026] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or prior art description will be briefly introduced as follows. Obviously, the drawings in the following description only constitute some embodiments of the present application, and other embodiments can also be obtained by those skilled in the art based on these drawings.

[0027] Figure 1a A structural diagram of a transaction processing system provided by an embodiment of the present application;

[0028] Figure 1b A structural diagram of another transaction processing system provided by an embodiment of the present application;

[0029] Figure 2a A flowchart of a transaction processing method provided by an embodiment of the present application;

[0030] Figure 2b A flowchart of another transaction processing method provided by an embodiment of the present application;

[0031] Figure 3 A flowchart of another transaction processing method provided by an embodiment of the present application;

[0032] Figure 4 A flowchart of another transaction processing method provided by an embodiment of the present application;

[0033] Figure 5 A flowchart of another transaction processing method provided by an embodiment of the present application;

[0034] Figure 6 A flowchart of another transaction processing method provided by an embodiment of the present application;

[0035] Figure 7 A flowchart of a transaction processing method provided by an embodiment of the present application;

[0036] Figure 8a A structural diagram of a transaction processing device provided in an embodiment of the present invention;

[0037] Figure 8b A structural diagram of a transaction processing device provided in an embodiment of the present invention;

[0038] Figure 9 This is a schematic diagram of the structure of an electronic device provided in an embodiment of the present invention. Detailed Implementation

[0039] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art based on the present invention are within the scope of protection of the present invention.

[0040] This invention provides a transaction processing system. See also... Figure 1a , Figure 1a This is a structural diagram of a transaction processing system provided in an embodiment of the present invention. The system includes: application service 101a, application service 102a, application service 103a, and control service 104a. This embodiment of the invention only uses three application services as an example for illustration, and is not limited to this. A transaction to be processed can be divided into multiple sub-transactions, each sub-transaction being executed by a corresponding application service. For example, an application service can be an open process used to execute the corresponding sub-transaction. Control service 104a can be a process that manages each application service. The first application service is any of the above-mentioned application services.

[0041] Control service 104a is used to obtain compensation tasks recorded in the first database whose execution results are failures, as the first compensation task; wherein, the compensation task in the first database is: a task used to compensate each sub-transaction obtained by dividing the pending transaction; and to send the first compensation task to the first application service used to process the first sub-transaction corresponding to the first compensation task.

[0042] The first application service is used to perform the first compensation task to restore the data processed by the first sub-entity and send the execution result of the first compensation task to the control service 104a.

[0043] Control service 104a is also used to update the compensation task recorded in the first database based on the execution result of the first compensation task.

[0044] Based on the transaction processing system provided by the embodiment of the present application, if there is an abnormal sub-transaction in the to-be-processed transaction, the corresponding compensation task can be executed to restore the data, and when the compensation task fails, the compensation task can be continuously retried, thereby ensuring the consistency of the data corresponding to the to-be-processed transaction.

[0045] The above Figure 1a Each application service can be a service (for example, a process) started in the same server, or can also be a service separately started in different servers. For example, each application service is a service separately started in each application server in a cluster (that is, the application service cluster in the embodiment of the present application), and in addition, the control service can be a service (for example, a process) started in the control server.

[0046] Referring to 1b, Figure 1b The structure diagram of another transaction processing system provided by the embodiment of the present application is shown. The system includes an application server cluster and a control server 104b, wherein the application server cluster includes an application server 101b, an application server 102b and an application server 103b. The embodiment of the present application is only used as an example to contain three application servers, and is not limited thereto in practice. The control server is used to execute any transaction processing method in the embodiment of the present application. Application services can be started in each application server in the application service cluster, and the corresponding sub-transaction in the to-be-processed transaction is executed through the application service, and the compensation task corresponding to the sub-transaction is executed.

[0047] In one embodiment, the transaction processing system further includes a transaction management server, and the transaction management server and the control server communicate through a message middleware.

[0048] The control server is configured to send, to the transaction management server, an identifier of the compensation task recorded in the first database and having a failed execution result when the compensation task recorded in the first database is updated; and the transaction management server is configured to update, by a transaction manager, the compensation task recorded in the second database and having a failed execution result according to the identifier of the compensation task sent by the control server.

[0049] The transaction manager can be a service (for example, a process) started in the transaction management server and used to manage the control services corresponding to the plurality of to-be-processed transactions.

[0050] Based on the above processing, the backup of the compensation task recorded in the first database can be implemented, the loss of data is prevented, and the consistency of the data corresponding to the to-be-processed transaction is further ensured.

[0051] In an embodiment, the transaction management server is further configured to send, to the control server via the transaction manager, an identifier of the compensation task whose execution result recorded in the second database is failure; and the control server is configured to send the compensation task to the corresponding application server according to the identifier of the compensation task sent by the transaction management server.

[0052] Based on the above processing, if the data in the first database is lost, the control service can determine the failed compensation task from the information received by the transaction manager, so as to retry the failed compensation task, so that the control service can perform asynchronous compensation.

[0053] For other embodiments of the transaction processing system described above, refer to the specific description of the embodiments of the transaction processing method below.

[0054] Embodiments of the present application provide a transaction processing method, which can be applied to Figure 1b the control server 104b, and specifically, can be applied to Figure 1a the control service 104a. Referring to Figure 2a , Figure 2a a flowchart of a transaction processing method provided by an embodiment of the present application can include the following steps:

[0055] S201a: obtaining a first compensation task whose execution result recorded in the first database is failure.

[0056] The first compensation task is used to restore the data processed by the corresponding sub-transaction in the to-be-processed transaction.

[0057] S202a: sending the first compensation task to the corresponding first application service, so that the first application service executes the first compensation task.

[0058] S203a: updating the compensation task recorded in the first database according to the execution result of the first compensation task sent by the first application service.

[0059] Based on the transaction processing method provided by the embodiment of the present application, if there is an execution-exception sub-transaction in the to-be-processed transaction, the corresponding compensation task can be executed to restore the data, and when the compensation task fails, the compensation task can be continuously retried, thereby ensuring the consistency of the data corresponding to the to-be-processed transaction.

[0060] The present application provides a transaction processing method applied to a control service. Referring to Figure 2b , Figure 2b a flowchart of a transaction processing method provided by an embodiment of the present application includes:

[0061] S201b: obtaining a compensation task whose execution result recorded in the first database is failure as a first compensation task.

[0062] S202b: sending the first compensation task to a first application service used for processing a first sub-transaction corresponding to the first compensation task, so that the first application service executes the first compensation task to recover data processed by the first sub-transaction.

[0063] S203b: updating a compensation task recorded in a first database according to an execution result of the first compensation task sent by the first application service.

[0064] The compensation task recorded in the first database is a task used for compensating each sub-transaction obtained by dividing the to-be-processed transaction.

[0065] Based on the transaction processing method provided in the embodiments of the present application, if there is a sub-transaction with an execution exception in the to-be-processed transaction, a corresponding compensation task can be executed to recover data, and when the compensation task fails, the compensation task can be continuously retried, thereby ensuring the consistency of data corresponding to the to-be-processed transaction.

[0066] One application service executes one sub-transaction, and can execute a compensation task corresponding to the sub-transaction.

[0067] In an implementation manner, the execution result of the compensation task can be success, that is, the application service corresponding to the compensation task has successfully recovered data processed by the sub-transaction corresponding to the compensation task, or the execution result of the compensation task can be failure, that is, the application service corresponding to the compensation task has not successfully recovered data processed by the sub-transaction corresponding to the compensation task.

[0068] The control service can update the compensation task recorded in the first database according to the execution result of the first compensation task. The first database can be a database local to a node running the control service.

[0069] In an implementation manner, only the compensation task with the execution result of failure is recorded in the first database, and if the execution result of the first compensation task is success, the control service can delete the first compensation task recorded in the first database. In another implementation manner, only the compensation task and the execution result corresponding to the compensation task are recorded in the first database, and if the execution result of the first compensation task is success, the control service updates the execution result of the first compensation task recorded in the first database to success.

[0070] In addition, if the execution result of the first compensation task is failure, the control service does not update the compensation task recorded in the first database.

[0071] In one implementation, if the execution result of the received compensation task is failure, the sub-transaction corresponding to the compensation task can be compensated again until the sub-transaction is compensated successfully, thereby ensuring the consistency of the corresponding data of the to-be-processed transaction.

[0072] In one embodiment, referring to Figure 3 , on the basis of Figure 2b , before step S201b, the method further comprises:

[0073] S204: obtaining the to-be-processed transaction.

[0074] S205: dividing the to-be-processed transaction to obtain a plurality of sub-transactions.

[0075] The plurality of sub-transactions have a specified execution order.

[0076] S206: sending each sub-transaction to the application service corresponding to the sub-transaction respectively, so that the application service corresponding to the sub-transaction executes the sub-transaction.

[0077] S207: when the execution failure message of the second sub-transaction sent by the second application service is received, determining the sub-transaction executed before the second sub-transaction in the to-be-processed transaction as a third sub-transaction according to the specified execution order.

[0078] S208: recording a third compensation task for compensating the third sub-transaction in the first database.

[0079] In one implementation, the to-be-processed transaction can be divided into a plurality of sub-transactions, when any sub-transaction of the to-be-processed transaction fails, the sub-transactions of the to-be-processed transaction that have been executed successfully need to be compensated, that is, the data processed by the sub-transactions that have been executed successfully is restored to the state before the sub-transactions are executed. The consistency of the data of the application services corresponding to the sub-transactions of the to-be-processed transaction can be ensured.

[0080] In one implementation, the second sub-transaction corresponding to the second application service can be any one of the plurality of sub-transactions of the to-be-processed transaction. When the execution failure message sent by the second application service is received, it indicates that the second application service fails to execute the second sub-transaction, that is, the second application service fails to modify the data of the second sub-transaction. The application service corresponding to the sub-transaction executed before the second sub-transaction (executed sub-transaction) has modified the data of the executed sub-transaction, therefore, in order to ensure the consistency of the data, the data of the executed sub-transaction needs to be restored, that is, all the data is restored to the state before the executed sub-transaction is executed.

[0081] For example, an order transaction of online shopping can be completed by 4 application services, which are an order service, a payment service, an inventory service and a shipping service respectively. The processing flow of the order transaction is as follows: the order service creates an order and sets the order status as success; the payment service receives the payment of the user, and modifies the account fund data; the inventory service takes the goods out of the warehouse, and modifies the inventory information; the shipping service monitors the delivery of the goods, and sets the shipping status as success when the goods are delivered successfully; and the order service changes the order status to order completion, i.e., the order transaction is completed. The above 4 application services are executed in sequence according to the specified execution order, and modify the corresponding data. The specified execution order is: first, the order service modifies the order status; then, the payment service modifies the account fund data; then, the inventory service modifies the inventory information; and finally, the shipping service modifies the shipping status. When the order service and the payment service are executed successfully, and the inventory service fails, the order service and the payment service need to be compensated, i.e., the payment service refunds the user, and modifies the account fund data, and the order service sets the order status as failure.

[0082] When the third compensation task is recorded in the first database, the execution result of the third compensation task can also be marked as failure.

[0083] In an implementation manner, only the compensation tasks with the execution result of failure are recorded in the first database, and subsequently, the control service can acquire the compensation tasks recorded in the database, and continue to retry the compensation tasks with the execution result of failure.

[0084] In another implementation manner, the compensation tasks and the corresponding execution results are recorded in the first database, and subsequently, the control service can acquire the compensation task with the execution result of failure, and continue to retry the compensation task.

[0085] In an implementation manner, when the third compensation task is recorded in the first database for the first time, the third compensation task is a compensation task with the execution result of failure by default.

[0086] In an embodiment, for the compensation task with the execution result of failure, Figure 2a Before step S201a, the method can also include steps S204-S208 described above.

[0087] In an embodiment, referring to Figure 4 On the basis of Figure 3 After step S208, the method further includes:

[0088] S209: sending the third compensation task to a third application service used to execute the third sub-transaction, so that the third application service executes the third compensation task to recover the data processed by the third sub-transaction.

[0089] S2010: updating the compensation task recorded in the first database according to the execution result of the third compensation task sent by the third application service.

[0090] In an implementation, the control service can compensate the third sub-transaction when receiving the execution failure message sent by the second application service, and can execute the corresponding compensation task when the sub-transaction is determined to fail (which can be referred to as real-time compensation). That is, the sub-transaction executed before the second sub-transaction is compensated, and the real-time performance of the control service is improved.

[0091] Correspondingly, if the real-time compensation fails, the compensation result of the compensation task in the database is updated, and based on S201b-S202b, the compensation task can be continued to be retried, that is, the sub-transaction for which the compensation fails is compensated asynchronously.

[0092] In order to further ensure the consistency of data, in an embodiment, the transaction processing system can further include a transaction manager. See Figure 5 , on the basis of Figure 4 , after step S207, the method further includes:

[0093] S2011: sending a second compensation message to the second message queue, so that the transaction manager obtains the second compensation message from the second message queue, records the third compensation task in the second database, and sends a first compensation message to the first message queue.

[0094] The second compensation message carries the identifier of the third compensation task; and the first compensation message carries the identifier of the compensation task with the execution result recorded in the second database as failure.

[0095] S2012: obtaining the first compensation message from the first message queue.

[0096] S2013: determining a fourth compensation task to which the identifier of the compensation task carried in the first compensation message belongs.

[0097] S2014: sending the fourth compensation task to a fourth application service for processing a fourth sub-transaction corresponding to the fourth compensation task, so that the fourth application service executes the fourth compensation task to recover the data processed by the fourth sub-transaction.

[0098] The transaction manager can be a process for managing a plurality of control services corresponding to the to-be-processed transactions.

[0099] In an implementation, the first message queue and the second message queue can be Kafka message queues. The transaction manager records the third compensation task in the second database through the identifier of the third compensation task. The second database can be a database local to the node running the transaction manager, which is different from the first database.

[0100] In an implementation, the transaction manager can record each compensation task of the plurality of pending transactions in the second database. The compensation task recorded in the second database is included in the compensation task recorded in the first database. Based on the above processing, the transaction manager and the control service can achieve synchronization of the compensation task. The transaction manager can send the information synchronized from the control service to the control service at a time, and accordingly, if the data in the first database is lost, the control service can determine the failed compensation task from the information received from the transaction manager, to retry the failed compensation task, so that the control service can perform asynchronous compensation.

[0101] In an implementation, referring to Figure 6 , after step S2014, the method further includes: Figure 5

[0102] S2015: obtaining an execution result of the fourth compensation task sent by the fourth application service.

[0103] S2016: sending a third compensation message to the second message queue, so that the transaction manager obtains the third compensation message from the second message queue, and updates the compensation task recorded in the second database according to the execution result of the fourth compensation task.

[0104] The third compensation message carries the execution result of the fourth compensation task.

[0105] In an implementation, the second database only records the compensation task with the execution result of failure, and if the execution result of the fourth compensation task is success, the transaction manager can delete the fourth compensation task recorded in the second database. In another implementation, the second database records the compensation task and the corresponding execution result, and if the execution result of the fourth compensation task is success, the transaction manager updates the execution result of the fourth compensation task recorded in the second database to success.

[0106] In addition, if the execution result of the fourth compensation task is failure, the transaction manager does not update the compensation task recorded in the second database.

[0107] In an implementation, after sending the fourth compensation task to the fourth application service, the method further includes: obtaining an execution result of the fourth compensation task sent by the fourth application service; and updating the compensation task recorded in the first database according to the obtained execution result.

[0108] ​In this embodiment of the invention, after obtaining the execution result of the fourth compensation task, the control service can update the compensation tasks recorded in the first database. The update method is similar to the method used in the above embodiment where the transaction manager updates the compensation tasks recorded in the second database based on the execution result of the fourth compensation task; please refer to its detailed description therein.

[0109] In one embodiment, the method may further include the following steps:

[0110] When the compensation task recorded in the first database is updated, a second compensation message is sent to the second message queue so that the transaction manager can retrieve the second compensation message from the second message queue and update the compensation task recorded in the second database according to the second compensation message.

[0111] The second compensation message contains an identifier indicating that the compensation task failed to execute.

[0112] In this embodiment of the invention, when the compensation task recorded in the first database is updated, the control service can synchronize the compensation task with the transaction manager.

[0113] In one implementation, when a third sub-transaction is identified and the third compensation task corresponding to the third sub-transaction is recorded in the first database, the control service can synchronize the compensation task with the transaction manager through the second message queue.

[0114] In addition, when updating the compensation task recorded in the first database based on the execution result of the first compensation task sent by the first application service, the control service can also synchronize the compensation task with the transaction manager through the second message queue.

[0115] Secondly, when updating the compensation task recorded in the first database based on the execution result of the third compensation task sent by the third application service, the control service can also synchronize the compensation task with the transaction manager through the second message queue.

[0116] Furthermore, when updating the compensation task recorded in the first database based on the execution result of the fourth compensation task sent by the fourth application service, the control service can also synchronize the compensation task with the transaction manager through the second message queue.

[0117] In one embodiment, see Figure 7 , Figure 7 This is an overall flowchart of a transaction processing method provided in an embodiment of the present invention.

[0118] The comprehensive service corresponds to the control service and a plurality of application services. The control service can perform transaction orchestration, i.e., divide a to-be-processed transaction into a plurality of sub-transactions, and send the plurality of sub-transactions to corresponding application services. According to a specified execution order of the plurality of sub-transactions, each application service executes the corresponding sub-transaction in turn.

[0119] When the transaction flow execution is abnormal, i.e., a sub-transaction (corresponding to the second sub-transaction described above) fails, the control service can initiate real-time compensation, i.e., compensate the sub-transaction that has been successfully executed through the application service corresponding to the sub-transaction that has been successfully executed (corresponding to the third sub-transaction executed before the second sub-transaction described above). The control service records the compensation task (corresponding to the third compensation task described above) in the compensation task table of the DB (Data Base, database) A (corresponding to the first database described above), and sends the identification of the third compensation task to the middleware Kafka message queue (corresponding to the second message queue described above). The control service can execute a timing task, acquire the failed compensation task (corresponding to the first compensation task described above) from the first database according to a preset period, and initiate asynchronous compensation, i.e., send the first compensation task to the first application service used to process the first sub-transaction corresponding to the first compensation task. The control service updates the compensation task table of the first database according to the execution result of the first compensation task sent by the first application service.

[0120] The transaction manager can consume the message in the second message queue, acquire the identification of the third compensation task sent by the control service, and record it in the compensation task total table of the DB B (corresponding to the second database described above). That is, in addition to recording the compensation task of the comprehensive service corresponding to the current transaction, the second database can also record the compensation task of the comprehensive service corresponding to other transactions. The transaction manager can execute a timing task, acquire the failed compensation task (corresponding to the fourth compensation task described above) of the comprehensive service corresponding to the current transaction from the second database according to a preset period, and send the identification of the fourth compensation task to the middleware Kafka message queue (corresponding to the first message queue described above).

[0121] The control service can consume the message in the first message queue, acquire the identification of the fourth compensation task sent by the transaction manager, and update the compensation task table in the first database. In this way, the control service can perform asynchronous compensation through the fourth compensation task, and send the identification of the fourth compensation task to the second message queue, so that the transaction manager updates the compensation task total table of the second database.

[0122] In an embodiment, each application service is any application service in the transaction processing system described above.

[0123] For Figure 1aThe control service 104a is further configured to, before obtaining the first compensation task as the compensation task for which the execution result of the local record is failure, obtain a to-be-processed transaction, divide the to-be-processed transaction to obtain a plurality of sub-transactions, wherein the plurality of sub-transactions have a specified execution order, and send each sub-transaction to an application service corresponding to the sub-transaction.

[0124] Each application service is configured to execute the received corresponding sub-transaction.

[0125] The control service 104a is further configured to, when receiving an execution failure message of a second sub-transaction sent by a second application service, determine, according to the specified execution order, a sub-transaction executed before the second sub-transaction in the to-be-processed transaction as a third sub-transaction, and record, in the first database, a third compensation task for compensating the third sub-transaction.

[0126] In an embodiment, the third application service is any application service in the transaction processing system.

[0127] The control service 104a is further configured to, after determining, according to the specified execution order, the sub-transaction executed before the second sub-transaction in the to-be-processed transaction as the third sub-transaction, send the third compensation task to a third application service for executing the third sub-transaction.

[0128] The third application service is configured to execute the third compensation task to restore data processed by the third sub-transaction, and send an execution result of the third compensation task to the control service 104a.

[0129] The control service 104a is further configured to update the compensation task recorded in the first database according to the execution result of the third compensation task.

[0130] In an embodiment, the transaction processing system further includes a transaction manager, and the fourth application service is any application service in the transaction processing system.

[0131] The control service 104a is further configured to, after determining, according to the specified execution order, the sub-transaction executed before the second sub-transaction in the to-be-processed transaction as the third sub-transaction, send a second compensation message to a second message queue, wherein the second compensation message carries an identifier of the third compensation task.

[0132] The transaction manager is configured to obtain the second compensation message from the second message queue, record the third compensation task in a second database, and send a first compensation message to a first message queue, wherein the first compensation message carries an identifier of a compensation task for which an execution result recorded in the second database is failure.

[0133] The control service 104a is further configured to acquire the first compensation message from the first message queue; determine a fourth compensation task to which an identifier of the compensation task carried in the first compensation message belongs; and send the fourth compensation task to a fourth application service configured to process a fourth sub-transaction corresponding to the fourth compensation task.

[0134] The fourth application service is configured to execute the fourth compensation task to recover data processed by the fourth sub-transaction.

[0135] In an embodiment, the fourth application service is further configured to send an execution result of the fourth compensation task to the control service 104a after executing the fourth compensation task to recover the data processed by the fourth sub-transaction.

[0136] The control service 104a is further configured to send a third compensation message to the second message queue; wherein the third compensation message carries the execution result of the fourth compensation task.

[0137] The transaction manager is further configured to acquire the third compensation message from the second message queue, and update the compensation task recorded in the second database according to the execution result of the fourth compensation task.

[0138] Based on the same inventive concept, the present application further provides a transaction processing apparatus. See Figure 8a , Figure 8a A structural diagram of a transaction processing apparatus provided by an embodiment of the present application is shown in FIG. 1. The apparatus includes:

[0139] The first obtaining module 801 is configured to obtain a compensation task with a failed execution result recorded in a first database as a first compensation task; wherein the compensation task recorded in the first database is a task for compensating each sub-transaction obtained by dividing a to-be-processed transaction;

[0140] The first sending module 802 is configured to send the first compensation task to a first application service configured to process a first sub-transaction corresponding to the first compensation task, so that the first application service executes the first compensation task to recover data processed by the first sub-transaction;

[0141] The first updating module 803 is configured to update the compensation task recorded in the first database according to an execution result of the first compensation task sent by the first application service.

[0142] In an embodiment, the apparatus further includes:

[0143] The second obtaining module is configured to obtain a to-be-processed transaction before obtaining a compensation task with a failed execution result recorded locally as a first compensation task.

[0144] The transaction division module is configured to divide the to-be-processed transaction to obtain a plurality of sub-transactions, wherein the plurality of sub-transactions have a specified execution order;

[0145] The second sending module is configured to send each sub-transaction to an application service corresponding to the sub-transaction, so that the application service corresponding to the sub-transaction executes the sub-transaction.

[0146] The sub-transaction determination module is configured to, when receiving an execution failure message of a second sub-transaction sent by the second application service, determine, according to the specified execution order, a sub-transaction executed before the second sub-transaction in the to-be-processed transaction as a third sub-transaction.

[0147] The task recording module is configured to record, in the first database, a third compensation task for compensating the third sub-transaction.

[0148] In an embodiment, the apparatus further includes:

[0149] The third sending module is configured to, after determining, according to the specified execution order, a sub-transaction executed before the second sub-transaction in the to-be-processed transaction as the third sub-transaction, send, to a third application service for executing the third sub-transaction, the third compensation task, so that the third application service executes the third compensation task to restore data processed by the third sub-transaction.

[0150] The second updating module is configured to update the compensation task recorded in the first database according to an execution result of the third compensation task sent by the third application service.

[0151] In an embodiment, the apparatus further includes:

[0152] The fourth sending module is configured to, after determining, according to the specified execution order, a sub-transaction executed before the second sub-transaction in the to-be-processed transaction as the third sub-transaction, send, to the second message queue, a second compensation message, wherein the second compensation message carries an identifier of the third compensation task, so that the transaction manager acquires the second compensation message from the second message queue, records the third compensation task in the second database, and sends, to the first message queue, a first compensation message carrying an identifier of a compensation task with a failure execution result recorded in the second database.

[0153] The third acquiring module is configured to acquire the first compensation message from the first message queue.

[0154] The task determination module is configured to determine a fourth compensation task to which an identifier of a compensation task carried in the first compensation message belongs.

[0155] The fifth sending module is configured to send the fourth compensation task to a fourth application service for processing a fourth sub-transaction corresponding to the fourth compensation task, so that the fourth application service executes the fourth compensation task to recover data processed by the fourth sub-transaction.

[0156] In one embodiment, the apparatus further comprises:

[0157] The fourth obtaining module is configured to obtain an execution result of the fourth compensation task sent by the fourth application service after the fourth application service executes the fourth compensation task to recover data processed by the fourth sub-transaction.

[0158] The sixth sending module is configured to send a third compensation message to the second message queue, wherein the third compensation message carries the execution result of the fourth compensation task, so that the transaction manager obtains the third compensation message from the second message queue and updates the compensation task recorded in the second database according to the execution result of the fourth compensation task.

[0159] Based on the same inventive concept, the present application also provides a transaction processing apparatus. Referring to Figure 8b , Figure 8b The present application provides a transaction processing apparatus.

[0160] The second obtaining module 804 is configured to obtain a first compensation task with a failed execution result recorded in the first database, wherein the first compensation task is used to recover data processed by a corresponding sub-transaction in the to-be-processed transaction; the second sending module 805 is configured to send the first compensation task to a corresponding first application service, so that the first application service executes the first compensation task; and the second updating module 806 is configured to update the compensation task recorded in the first database according to an execution result of the first compensation task sent by the first application service.

[0161] In one embodiment, the apparatus further comprises: a third sub-transaction determining module configured to determine a third sub-transaction executed before the second sub-transaction in the to-be-processed transaction according to a specified execution order when receiving an execution failure message of the second sub-transaction sent by the second application service; and a recording module configured to record a third compensation task corresponding to the third sub-transaction in the first database and mark an execution result of the third compensation task as failed.

[0162] In one embodiment, the apparatus further includes: a third compensation task sending module, configured to send the third compensation task to a corresponding third application service so that the third application service executes the third compensation task; and a third update module, configured to update the compensation task recorded in the first database according to the execution result of the third compensation task sent by the third application service.

[0163] In one embodiment, the apparatus further includes: a first compensation message acquisition module, configured to acquire a first compensation message from a first message queue; wherein the first compensation message carries an identifier of a compensation task whose execution result is a failure, recorded in a second database; the compensation task recorded in the second database is obtained by synchronizing the compensation task recorded in the first database; a fourth compensation task determination module, configured to determine the fourth compensation task to which the identifier of the compensation task carried in the first compensation message belongs; and a fourth compensation task sending module, configured to send the fourth compensation task to the corresponding fourth application service, so that the fourth application service executes the fourth compensation task.

[0164] In one embodiment, the apparatus further includes: a fourth update module, configured to obtain the execution result of the fourth compensation task sent by the fourth application service; and update the compensation task recorded in the first database according to the obtained execution result.

[0165] In one embodiment, the apparatus further includes: a second compensation message sending module, configured to send a second compensation message to a second message queue when the compensation task recorded in the first database is updated; wherein the second compensation message carries an identifier of a compensation task whose execution result is failure; so that the transaction manager obtains the second compensation message from the second message queue and updates the compensation task recorded in the second database according to the second compensation message.

[0166] In one embodiment, the apparatus further includes: a processing module, configured to acquire the transaction to be processed; divide the transaction to be processed into multiple sub-transactions; wherein the multiple sub-transactions have a specified execution order; and send each sub-transaction to the application service corresponding to the sub-transaction so that the application service corresponding to the sub-transaction executes the sub-transaction.

[0167] This invention also provides an electronic device, such as... Figure 9 As shown, it includes a processor 901, a communication interface 902, a memory 903, and a communication bus 904, wherein the processor 901, the communication interface 902, and the memory 903 communicate with each other through the communication bus 904.

[0168] Memory 903 is used to store computer programs;

[0169] The processor 901 is configured to implement the steps of the transaction processing method according to any one of the above embodiments when executing the program stored in the memory 903.

[0170] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For the convenience of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or only one type of bus.

[0171] The communication interface is configured to communicate between the above electronic device and other devices.

[0172] The memory can include a Random Access Memory (RAM) and can also include a Non-Volatile Memory (NVM), such as at least one disk memory. Optionally, the memory can also be at least one storage device located away from the above processor.

[0173] The above processor can be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; can also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA) or other programmable logic device, a discrete gate or transistor logic device, a discrete hardware component.

[0174] In another embodiment provided by the present application, a computer readable storage medium is also provided, and the computer readable storage medium stores a computer program. The computer program is executed by a processor to implement the steps of any one of the above transaction processing methods.

[0175] In another embodiment provided by the present application, a computer program product containing instructions is also provided, and when the computer program product is run on a computer, the computer is caused to execute any one of the above transaction processing methods.

[0176] In the embodiments described above, all or some of the steps can be implemented by software, hardware or firmware, or any combination thereof. When implemented by software, all or some of the steps can be implemented in the form of one or more computer programs. The computer program can be stored in any computer readable medium, and when loaded into a computer system, causes the computer system to perform one or more of the steps of the computer program. The computer readable medium can be located in the memory of the computer system’s storage device. The computer program product includes one or more computer programs.

[0177] It should be noted that, in the specification, the relative terms such as first and second, etc., are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply that there is any such actual relationship or order between these entities or operations. Moreover, the terms “include”, “contain” or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such process, method, article or device. Without more limitations, the element defined by the statement “including a…” does not exclude the presence of other identical elements in the process, method, article or device including the element.

[0178] Each of the embodiments in the specification is described in a relevant manner, and the same or similar parts between the embodiments can be referred to each other. Each embodiment focuses on the difference from other embodiments. In particular, for system, device, electronic device, computer readable storage medium and computer program product embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the part of the method embodiment.

[0179] The above merely describes the preferred embodiments of the present application, but is not used to limit the protection scope of the present application. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A transaction processing method, characterized by, The method comprises: obtaining a first compensation task recorded in a first database and having a failed execution result; wherein the first compensation task is used for recovering data processed by a corresponding sub-transaction in a to-be-processed transaction; the compensation tasks recorded in the first database are tasks used for compensating each sub-transaction obtained by dividing the to-be-processed transaction; one application service executes one sub-transaction and the compensation task corresponding to the sub-transaction; sending the first compensation task to a first application service used for processing a first sub-transaction corresponding to the first compensation task, so that the first application service executes the first compensation task to recover data processed by the first sub-transaction; updating the compensation tasks recorded in the first database according to an execution result of the first compensation task sent by the first application service; The method further comprises: when the compensation tasks recorded in the first database are updated, sending a second compensation message to a second message queue; wherein the second compensation message carries an identifier of a compensation task having a failed execution result; so that a transaction manager obtains the second compensation message from the second message queue and updates the compensation tasks recorded in a second database according to the second compensation message; The method further comprises: obtaining a first compensation message from a first message queue; wherein the first compensation message carries an identifier of a compensation task recorded in a second database and having a failed execution result; the compensation tasks recorded in the second database are obtained by synchronizing the compensation tasks recorded in the first database; the first compensation message is added to the first message queue by a transaction manager to which the second database belongs according to a preset period; determining a fourth compensation task to which the identifier of the compensation task carried in the first compensation message belongs; sending the fourth compensation task to a corresponding fourth application service, so that the fourth application service executes the fourth compensation task.

2. The method of claim 1, wherein, Before the first compensation task recorded in the first database and having a failed execution result is obtained, the method further comprises: when an execution failure message of a second sub-transaction sent by a second application service is received, determining a third sub-transaction executed before the second sub-transaction in the to-be-processed transaction according to a specified execution order; recording a third compensation task corresponding to the third sub-transaction in the first database and marking an execution result of the third compensation task as failed.

3. The method of claim 2, wherein, After the third compensation task corresponding to the third sub-transaction is recorded in the first database and the execution result of the third compensation task is marked as failed, the method further comprises: sending the third compensation task to a corresponding third application service, so that the third application service executes the third compensation task; updating the compensation tasks recorded in the first database according to an execution result of the third compensation task sent by the third application service.

4. The method of claim 1, wherein, After the fourth compensation task is sent to the corresponding fourth application service, the method further comprises: obtaining an execution result of the fourth compensation task sent by the fourth application service; updating the compensation tasks recorded in the first database according to the obtained execution result.

5. The method of claim 1, wherein, Before the first compensation task with a failed execution result recorded in the first database is executed, the method further comprises: obtaining the to-be-processed transaction; dividing the to-be-processed transaction to obtain a plurality of sub-transactions; wherein the plurality of sub-transactions have a specified execution order; sending each sub-transaction to the application service corresponding to the sub-transaction, so that the application service corresponding to the sub-transaction executes the sub-transaction.

6. A transaction processing system, characterized by The transaction processing system comprises an application service cluster and a control server, wherein: The control server is configured to execute the method of any one of claims 1-5; Each application server in the application service cluster is configured to execute the corresponding sub-transaction in the to-be-processed transaction by the application service, and execute the compensation task corresponding to the sub-transaction.

7. The system of claim 6, wherein, The transaction processing system further comprises a transaction management server, and the transaction management server and the control server communicate through a message middleware; The control server is configured to send the identification of the compensation task with a failed execution result recorded in the first database to the transaction management server when the compensation task recorded in the first database is updated; The transaction management server is configured to update the compensation task with a failed execution result recorded in the second database through the transaction manager according to the identification of the compensation task sent by the control server.

8. The system of claim 7, wherein, The transaction management server is further configured to send the identification of the compensation task with a failed execution result recorded in the second database to the control server through the transaction manager; The control server is configured to send the compensation task to the corresponding application server according to the identification of the compensation task sent by the transaction management server.

9. A transaction processing apparatus, characterized by comprising: The apparatus comprises: A first obtaining module is configured to obtain the first compensation task with a failed execution result recorded in the first database; wherein the first compensation task is used to recover the data processed by the corresponding sub-transaction in the to-be-processed transaction; the compensation task in the first database is a task used to compensate each sub-transaction obtained by dividing the to-be-processed transaction; one application service executes one sub-transaction and the compensation task corresponding to the sub-transaction; A first sending module is configured to send the first compensation task to the first application service used to process the first sub-transaction corresponding to the first compensation task, so that the first application service executes the first compensation task to recover the data processed by the first sub-transaction; A first updating module is configured to update the compensation task recorded in the first database according to the execution result of the first compensation task sent by the first application service; The apparatus further comprises: A second compensation message sending module is configured to send a second compensation message to a second message queue when the compensation task recorded in the first database is updated; wherein the second compensation message carries the identification of the compensation task with a failed execution result; so that the transaction manager obtains the second compensation message from the second message queue, and updates the compensation task recorded in the second database according to the second compensation message; The apparatus further comprises: The first compensation message obtaining module is configured to obtain a first compensation message from a first message queue, wherein the first compensation message carries an identifier of a compensation task with a failed execution result recorded in a second database; the compensation task recorded in the second database is obtained by synchronizing a compensation task recorded in the first database; and the first compensation message is added to the first message queue by a transaction manager to which the second database belongs according to a preset period. The fourth compensation task determining module is configured to determine a fourth compensation task to which the identifier of the compensation task carried in the first compensation message belongs. The fourth compensation task sending module is configured to send the fourth compensation task to a corresponding fourth application service, so that the fourth application service executes the fourth compensation task.

10. An electronic device, comprising: The apparatus comprises a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory complete mutual communication through the communication bus. The memory is configured to store a computer program. The processor is configured to execute the program stored on the memory, and implement the method steps in any one of claims 1-5.

11. A computer readable storage medium, characterized in that, The computer readable storage medium stores a computer program, and the computer program is executed by the processor to implement the method steps in any one of claims 1-5.

Citation Information

Patent Citations

  • Distributed transaction processing method and framework

    CN111008202A

  • Distributed transaction compensation method and device

    CN111813791A