A method and device for distributed transaction processing

By listening to the storage unit to record and manage transaction status, the problems of consistency and development costs in distributed transaction processing are solved, and strong consistency and efficient distributed transaction processing are achieved.

CN112866316BActive Publication Date: 2024-11-19BEIJING WODONG TIANJUN INFORMATION TECH CO LTD +1
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN201911184880.1
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2019-11-27
Publication Date
2024-11-19
Estimated Expiration
2039-11-27

AI Technical Summary

Technical Problem

In the existing distributed transaction processing technology, compensation transactions have delays, TCC model development workloads are large, and Saga model cannot guarantee data isolation, resulting in data consistency and development cost issues.

Method used

Record the transaction status of the business unit by listening to the storage unit, and use the transaction status to notify the corresponding business unit to perform submission or rollback operations, ensuring transaction consistency and reducing development workload.

Benefits of technology

It realizes strong consistency of distributed transactions, reduces the development workload related to distributed business consistency, and improves the reliability and scalability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN112866316B_ABST
    Figure CN112866316B_ABST
Patent Text Reader

Abstract

The present invention discloses a method and apparatus for distributed transaction processing, and relates to the field of computer technology. A specific implementation of the method includes: a first business unit receives a first business request, forms a local unique identifier associated with the first business request, and executes a local business according to the first business request; in the case where there are one or more second business units that receive the business request of the first business unit, the first business unit sends a second business request to the second business unit, and the second business request indicates the local unique identifier associated with the first business unit. According to the execution result of the local business, the local transaction state associated with the local unique identifier is determined; this implementation can ensure the strong consistency of transactions in distributed transactions and reduce the workload of business code development related to distributed transaction processing.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

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

[0002] In recent years, as the scale of enterprise systems expands, the monolithic architecture will become increasingly complex due to business complexity, resulting in high maintenance costs, poor reliability, poor scalability, and repetitive development. Therefore, more and more companies have adopted a distributed microservice architecture. In order to ensure the loose coupling of the business, each service may have its own database, and each service's transactions are controlled by itself, which may result in inconsistent transactions when a request passes through multiple services, destroying the consistency principle of transactions.

[0003] The existing technology has the following solutions to the transaction consistency problem:

[0004] Compensation transaction: When the service receives a request, it records the current request and checks the consistency of related data regularly or asynchronously. If the data is inconsistent, a set of compensation principles is customized to modify the data to achieve final consistency of the data.

[0005] TCC mode: The TCC transaction model is composed of Try, Confirm, and Cancel operations. Try attempts to execute an operation, Confirm commits a transaction, and Cancel cancels a transaction. The three together complete the operation in the service link, and together perform recovery operations when an operation is abnormal.

[0006] Saga mode: Saga mode is defined as a long-term transaction, which divides a transaction into local sub-transactions in multiple stages. Each transaction is an independent atomic behavior, and each sub-transaction must have a corresponding failure compensation transaction. When the global transaction starts, after the first sub-transaction is submitted, it will notify the next sub-transaction to process the business. If the next sub-transaction is submitted normally, the next sub-transaction will continue to be notified; if the next sub-transaction fails to submit, the previous sub-transaction needs to be notified to process the failure compensation transaction.

[0007] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art:

[0008] Compensation transactions have a certain delay. This is because the compensation operation is performed by the later scheduled check to find the previous business processing errors. The delay time depends on the frequency and rules of the scheduled check. For businesses with strict data consistency requirements, there may be abnormal situations where the data is inconsistent for a period of time.

[0009] TCC mode: In the TCC mode, the business processing methods in each service need to be broken down into three methods, namely Try, Commit, and Cancel, which greatly increases the development workload and cost.

[0010] Saga mode: In Saga mode, data isolation cannot be guaranteed. If two transactions operate on a resource at the same time, data may be confused. If data is read twice within a transaction and other transactions modify the data during the period, the read values ​​may be inconsistent. Summary of the invention

[0011] In view of this, an embodiment of the present invention provides a method and device for distributed transaction processing, which can use the monitored storage unit to record the transaction status of the monitored local business unit and the associated business units, and notify the corresponding business unit to perform operations such as transaction submission or rollback by modifying the transaction status. While solving distributed transactions, the transaction consistency of distributed transactions is ensured and the development workload of achieving distributed business consistency is reduced.

[0012] To achieve the above-mentioned purpose, according to one aspect of an embodiment of the present invention, a method for distributed transaction processing is provided, characterized in that it includes: a first business unit receives a first business request, forms a local unique identifier associated with the first business request, and executes a local business according to the first business request; in the presence of one or more second business units that receive the business request of the first business unit, the first business unit sends a second business request to the second business unit, and the second business request indicates the local unique identifier associated with the first business unit; and according to the execution result of the local business, determines the local transaction status associated with the local unique identifier.

[0013] Optionally, the distributed transaction processing method is characterized in that the local transaction status includes: registered, committed, rollback, pending commit, pending rollback, and committed.

[0014] Optionally, the distributed transaction processing method is characterized in that determining the local transaction state associated with the local unique identifier according to the execution result of the local service includes:

[0015] The first business unit monitors the local transaction state associated with the local unique identifier of the second business unit, and determines the local transaction state of the first business unit according to the local transaction state of the second business unit.

[0016] Optionally, the distributed transaction processing method is characterized by monitoring changes in the local transaction state and determining operations corresponding to the first transaction state.

[0017] Optionally, the distributed transaction processing method is characterized in that the local transaction state is changed by an upper-level unit of the first business unit, and the upper-level business unit is a business unit that sends the first business request to the first business unit.

[0018] Optionally, the distributed transaction processing method is characterized in that the monitored storage unit is used to correspondingly record the local unique identifier and local transaction status of the first business unit, and the local unique identifier and local transaction status of the second business unit.

[0019] To achieve the above-mentioned purpose, according to a second aspect of an embodiment of the present invention, a distributed transaction processing device is provided, characterized in that it includes: a transaction identification management module, a transaction execution module and a transaction status management module; wherein the transaction identification management module is used to receive a first business request and form a local unique identifier associated with the first business request; the transaction execution module is used to execute a local business according to the first business request; in the case where there are one or more second business units that receive the business request of the device, the device sends a second business request to the second business unit, and the second business request indicates the local unique identifier associated with the device; the transaction status management module is used to determine the local transaction status associated with the local unique identifier according to the execution result of the local business.

[0020] Optionally, the distributed transaction processing device is characterized in that the local transaction status includes: registered, committed, rollback, pending commit, pending rollback, and committed.

[0021] Optionally, the distributed transaction processing device is characterized in that determining the local transaction state associated with the local unique identifier according to the execution result of the local service comprises:

[0022] The device monitors the local transaction state associated with the local unique identifier of the second service unit, and determines the local transaction state of the device according to the local transaction state of the second service unit.

[0023] Optionally, the distributed transaction processing device is characterized by monitoring changes in the local transaction state and determining an operation corresponding to the first transaction state based on the first transaction state.

[0024] Optionally, the distributed transaction processing device is characterized by:

[0025] The local transaction state is changed by an upper-level unit of the device, and the upper-level service unit is a service unit that sends the first service request to the device.

[0026] Optionally, the distributed transaction processing device is characterized by:

[0027] The monitored storage unit is used to correspondingly record the local unique identifier and the local transaction state of the device, and the local unique identifier and the local transaction state of the second service unit.

[0028] To achieve the above-mentioned purpose, according to the third aspect of an embodiment of the present invention, a server for distributed transaction processing is provided, characterized in that it includes: one or more processors; a storage device for storing one or more programs, when the one or more programs are executed by the one or more processors, the one or more processors implement any method described in the above-mentioned distributed transaction processing methods.

[0029] To achieve the above-mentioned purpose, according to a fourth aspect of an embodiment of the present invention, a computer-readable medium is provided, on which a computer program is stored, characterized in that when the program is executed by a processor, any method as described in the above-mentioned distributed transaction processing method is implemented.

[0030] An embodiment of the above invention has the following advantages or beneficial effects: a first business unit receives a first business request, forms a local unique identifier associated with the first business request, and executes a local business according to the first business request; in the case where there are one or more second business units that receive the business request of the first business unit, the first business unit sends a second business request to the second business unit, and the second business request indicates the local unique identifier associated with the first business unit; based on the execution result of the local business, the local transaction state associated with the local unique identifier is determined. It can be seen from this that the method of distributed transaction processing can ensure the strong consistency of transactions in distributed transactions and reduce the workload of business code development related to distributed transaction processing.

[0031] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS

[0032] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.

[0033] Figure 1 It is a flowchart of a distributed transaction processing method provided by the first embodiment of the present invention;

[0034] Figure 2 It is a flowchart of a transaction state and transaction operation provided by the first embodiment of the present invention;

[0035] Figure 3is a flow chart of a distributed transaction processing method provided by the second embodiment of the present invention;

[0036] Figure 4 is a flowchart of a transaction state and transaction operation provided by the second embodiment of the present invention;

[0037] Figure 5 is a flow chart of a distributed transaction processing method provided by the third embodiment of the present invention;

[0038] Figure 6 is a flowchart of a transaction state and transaction operation provided by the third embodiment of the present invention;

[0039] Figure 7 is a schematic diagram of the structure of a distributed transaction processing device provided by an embodiment of the present invention;

[0040] Figure 8 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;

[0041] Fig. 9 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION

[0042] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.

[0043] like Figure 1 and Figure 2 As shown, the first embodiment of the present invention provides a distributed transaction processing method, which may include the following steps: Figure 1 As shown:

[0044] Step S101: a first service unit receives a first service request, forms a local unique identifier associated with the first service request, and executes a local service according to the first service request.

[0045] To further illustrate step S101, the commodity purchase process is taken as an example, and the Zookeeper software and its monitoring mechanism are used as an example. Now it is assumed that the commodity trading module receives a user's purchase request, and a temporary address / root / tradeUUID / is created in Zookeeper, where tradeUUID records the user's commodity purchase request. It can be understood that the tradeUUID corresponding to each different request is also different. UUID can be a number or letter generated according to a predefined rule. For example, the tradeUUID corresponding to one purchase business request is trade123456789abc, and the tradeUUID corresponding to another purchase business request is trade987654321efg. The following examples do not specify the value of UUID, and use UUID instead, such as tradeUUID, storageUUID, orderUUID, etc.

[0046] It can be seen that the commodity purchase business request is the first business request received by the first business unit described in step S101, the commodity trading module is the first business unit, and the address / root / tradeUUID / is the local unique identifier associated with the first business request.

[0047] At the same time, the commodity transaction module executes the service related to the purchase request according to the commodity purchase request, that is, executes the local service according to the first service request.

[0048] Step S102: when there are one or more second service units that receive the service request of the first service unit, the first service unit sends a second service request to the second service unit, where the second service request indicates the local unique identifier associated with the first service unit.

[0049] Specifically, still taking the commodity purchase process of step S101 as an example, as shown in step S101, the commodity trading module indicates that the unique identifier of this commodity purchase request is / root / tradeUUID, and at the same time, the commodity trading module needs to notify the inventory module to modify the inventory information, that is, the trading module sends an inventory modification request to the inventory module, and the inventory modification request indicates the unique identifier of the commodity trading module / root / tradeUUID; wherein the commodity trading module is the first business unit, the inventory module is the second business unit, the business request to modify the inventory is the second business request, and the address / root / tradeUUID is the local unique identifier associated with the first business unit; that is, in the case where there are one or more second business units that receive the business request of the first business unit, the first business unit sends a second business request to the second business unit, and the second business request indicates the local unique identifier associated with the first business unit. Further, it can be understood that, as shown in step S101, still taking the commodity purchase process as an example, the inventory module creates a temporary address / root / tradeUUID / storageUUID in Zookeeper, and the temporary address is the unique identifier of the commodity purchase inventory modification request indicated by the inventory module, and the unique identifier is associated with the unique identifier / root / tradeUUID of the commodity purchase request of the commodity trading module.

[0050] Step S103: Determine the local transaction state associated with the local unique identifier according to the execution result of the local service.

[0051] Specifically, according to the execution result of the local business, the associated transaction state is changed. Figure 2 Explain the above steps, such as Figure 2 As shown,

[0052] Step S201: The first service unit executes the local service. According to the execution result, if the result is successful, step S204 is executed; if the result is failed, step S202 is executed.

[0053] Step S202: Execute the transaction rollback operation, mark the local transaction status as rollback, and execute step S203.

[0054] Specifically, the transaction rollback operation is indicated as a local transaction operation, which refers to the behavior of restoring the local business or data to the last correct state when the local business execution fails or the data is abnormal. It can be understood that the transaction rollback operation in this step is due to the result of the execution of the local business described in step S201 being a failure. The transaction rollback operation is combined with other transaction operations to ensure the consistency of the transaction;

[0055] Step S203: marking the transaction status of the second business unit that receives the business request of the first business unit as pending rollback.

[0056] Specifically, the to-be-rolled-back indicates a local transaction state, and the to-be-rolled-back indicates that the next transaction operation to be executed by the local business is a rollback. Further, optionally, the transaction state to be rolled back is marked by the superior business unit of the local business unit.

[0057] Step S204: Mark the local transaction status as committed.

[0058] Specifically, the commit indicates a local transaction state, indicating that the operation related to the local transaction is in a normal state. It can be understood that the transaction commit operation in this step is due to the result of the execution of the local business described in step S201 being successful.

[0059] Specifically, still taking the commodity purchase process described in step S101-step S103 as an example, steps S201-step S204 are explained. The commodity trading module is the first business unit, and the inventory module is the second business unit. The commodity trading module runs the purchase business and sends an inventory modification request to the inventory module at the same time; if the purchase business execution result is successful, optionally, the transaction status corresponding to its unique identifier / root / tradeUUID is marked as committed; if the purchase business execution result is failed, the transaction rollback operation is performed, optionally, the transaction status corresponding to its unique identifier / root / tradeUUID is marked as rollback, and the transaction status corresponding to the inventory module unique identifier / root / tradeUUID / storageUUID is marked as to be rolled back; it can be understood that if the first business unit has no upper-level business unit, there is no need to mark the transaction status of the local business as committed after the business execution is successful, and there is no need to mark the transaction status of the local business as rollback after the business execution fails; if the first business unit has no lower-level business unit, there is no need to mark the transaction status of the unique identifier of the business request corresponding to the lower-level business unit.

[0060] Among them, the commodity trading module in the above example is the first business unit, and its corresponding unique identifier of the purchase business request is / root / tradeUUID. Optionally, the corresponding transaction status is rollback. The above inventory module is the second business unit, and its corresponding unique identifier of the purchase business request inventory modification request is / root / tradeUUID / storageUUID, and the corresponding transaction status is to be rolled back, that is, the monitored storage unit is used to correspondingly record the local unique identifier and the first transaction status of the first business unit, and the unique identifier and the second transaction status of the second business unit.

[0061] It can be seen that the unique identifier and transaction status of the purchase business of the commodity trading module, and the unique identifier and transaction status of the inventory module, are recorded using the monitored storage unit; the embodiment of the present invention uses the monitoring mechanism of Zookeeper and the monitored storage unit as an example, and the product to which the monitoring mechanism belongs can also include Eureka, etc., but is not limited to the above products; the present invention does not limit the product to which the monitoring mechanism belongs.

[0062] This implementation can ensure strong consistency of transactions in distributed transactions and reduce the workload of developing business codes related to distributed transaction processing.

[0063] like Figure 3 and Figure 4 As shown, the second embodiment of the present invention provides a distributed transaction processing method, which may include the following steps:

[0064] like Figure 3 As shown, the process of distributed transaction processing in step S301-step S302 is consistent with the description of step S101-step S102, and will not be repeated here.

[0065] Step S303: Determining the first transaction state associated with the local unique identifier based on the execution result of the local business includes: the first business unit monitors the second transaction state associated with the unique identifier of the second business unit, and determines the first transaction state based on the second transaction state.

[0066] Specifically, the first transaction state associated with the local unique identifier is determined based on the execution result of the local business. When there is a second business unit that receives the business request sent by the first business unit, the first business unit monitors the second transaction state associated with the unique identifier of the second business unit, and determines the first transaction state based on the second transaction state.

[0067] Furthermore, still taking the commodity purchase process as an example to illustrate the above step S303, the commodity transaction module not only sends an inventory modification request to the inventory module, but also needs to send a purchase request to the order module:

[0068] Among them, the commodity trading module is the first business unit, the inventory module is the second business unit, and the ordering module is another second business unit. It can be understood that, as described in step S301-step S302, the inventory module indicates that the unique identifier of the purchase business request is / root / tradeUUID / storageUUID, and the ordering module indicates that the unique identifier of the purchase business request is / root / tradeUUID / orderUUID. The commodity shopping module monitors the transaction status corresponding to the unique identifier / root / tradeUUID of the commodity trading module corresponding to the above purchase business request, and the transaction status corresponding to the unique identifier / root / tradeUUID of the inventory module The transaction status of the ordering module and the transaction status corresponding to the unique identifier / root / tradeUUID / orderUUID of the ordering module are recorded. When the transaction status corresponding to the unique identifier / root / tradeUUID / storageUUID of the inventory module changes to rollback, the inventory module executes the transaction rollback operation corresponding to the business request of the unique identifier / root / tradeUUID / storageUUID; the commodity trading module marks the transaction status corresponding to the unique identifier / root / tradeUUID / orderUUID of the ordering module as pending rollback; the ordering module monitors that the transaction status corresponding to the unique identifier / root / tradeUUID / orderUUID changes to pending rollback, and executes the transaction rollback operation of the local business. Furthermore, if the shopping module marks the transaction status corresponding to the unique identifier / root / tradeUUID / orderUUID of the ordering module as submitted, the transaction commit operation of the local business is executed. It can be understood that if the first business unit has no subordinate business unit, there is no need to monitor the second transaction status associated with the unique identifier of the subordinate business unit.

[0069] Combine the following Figure 4 The flowchart shown in FIG. 1 further illustrates the above transaction status and transaction operation. Figure 4 As shown:

[0070] Step S401: monitor the transaction status of the unique identifier of the second business unit that receives the business request of the first business unit, and if the transaction status of the second business unit changes to rollback, execute step S402. If the transaction status of the second business unit changes to committed, execute step S403, and if the transaction status of the second business unit changes to committed or registered, execute step S404.

[0071] Specifically, the rollback is indicated as a local transaction state; when the local business execution fails or the data is abnormal, the local transaction state is marked as rollback;

[0072] The "committed" indicates a local transaction state; when a local transaction is committed, the local transaction is marked as committed;

[0073] The commit indicates a local transaction state; if the local business is successfully executed, the local transaction is marked as committed;

[0074] The registration indicates a local transaction state; when the first business unit sends a service request to the second business unit and the second business unit forms a unique identifier associated with the first business unit, the local transaction state is marked as registered;

[0075] Step S402: The first business unit marks the transaction status of one or more second business units that receive the business request of the first unit as pending rollback.

[0076] Step S403: Execute transaction commit operation.

[0077] Specifically, the transaction commit operation is indicated as a local transaction operation, that is, a transaction commit operation for executing local business. Furthermore, the changes made to the data storage module by executing the transaction commit operation are persistent, for example, the changes made to the data in the database are permanent and cannot be rolled back.

[0078] Step S404: Execute a no-action operation.

[0079] Specifically, the no-action operation indicates that under a predetermined condition, the local service does not need to perform a transaction operation; for example, the transaction status of the second service unit is submission or registration, and the second service unit performs a no-action operation.

[0080] like Figure 4 The process shown further explains that determining the first transaction state associated with the local unique identifier based on the execution result of the local business includes: the first business unit monitors the second transaction state associated with the unique identifier of the second business unit, and determines the first transaction state based on the second transaction state.

[0081] Monitor changes in the first transaction state, and determine, according to the first transaction state, an operation of a local transaction corresponding to the first transaction state.

[0082] It can be seen that the unique identifier and transaction status of the purchase business of the commodity trading module, and the unique identifier and transaction status of the inventory module, are recorded using the monitored storage unit; the embodiment of the present invention uses the monitoring mechanism of Zookeeper and the monitored storage unit as an example, and the product to which the monitoring mechanism belongs can also include Eureka, etc., but is not limited to the above products; the present invention does not limit the product to which the monitoring mechanism belongs.

[0083] This implementation can ensure strong consistency of transactions in distributed transactions and reduce the workload of developing business codes related to distributed transaction processing.

[0084] like Figure 5 and Figure 6 As shown, the third embodiment of the present invention provides a method for distributed transaction processing, which may include the following steps:

[0085] like Figure 5 As shown, the process of steps S501 to S503 regarding distributed transaction processing is consistent with the description of steps S101 to S103, and will not be repeated here.

[0086] Step S504: Regarding monitoring the change of the first transaction state, determining the operation of the local transaction corresponding to the first transaction state according to the first transaction state, which is consistent with the description of step S303 and will not be repeated here.

[0087] Step S505: the first transaction state is changed by an upper-level unit of the first service unit, where the upper-level service unit is a service unit that sends the first service request to the first service unit.

[0088] Specifically, the first transaction state is changed by an upper-level unit of the first service unit, and the upper-level service unit is a service unit that sends the first service request to the first service unit.

[0089] Furthermore, still taking the commodity purchase process as an example to illustrate the above steps, the commodity transaction module sends an inventory modification request to the inventory module and sends an order request to the order module:

[0090] Among them, the commodity trading module is the first business unit, the inventory module is the second business unit, and the ordering module is another second business unit. The inventory module indicates that the unique identifier of this purchase business request is / root / tradeUUID / storageUUID, and the ordering module indicates that the unique identifier of this purchase business request is / root / tradeUUID / orderUUID. The shopping module monitors the transaction status of the unique identifier of the purchase business request of the inventory module as / root / tradeUUID / storageUUID, and at the same time monitors the transaction status of the unique identifier of the purchase business request as / root / tradeUUID / orderUUID. When the inventory module indicates that the transaction status of the / root / tradeUUID / storageUUID is rollback and the ordering module indicates that the transaction status of the / root / tradeUUID / orderUUID is commit, the commodity trading module marks the transaction status of the / root / tradeUUID / orderUUID of the ordering module as to be rolled back. It is understandable that the commodity trading module is the superior business module of the inventory module and the ordering module, and the transaction status of the / root / tradeUUID / orderUUID of the ordering module changes from commit to pending rollback, which is changed by the commodity trading module, that is, the first transaction status is also changed by the superior unit of the first business unit, and the superior business unit is the business unit that sends the first business request to the first business unit. It is understandable that if the first business unit does not have an superior business unit, the first transaction status does not need to be changed by the superior unit of the first business unit; if the first business unit does not have a subordinate business unit, there is no need to mark the transaction status of the unique identifier of the business request corresponding to the subordinate business unit.

[0091] The following combination Figure 6 The flowchart shown in FIG. 1 further illustrates the transaction status and transaction operations in the above steps. Figure 6 Shown:

[0092] Step S601: monitor the transaction status corresponding to the unique identifier of the first business unit transaction, if the transaction status of the first business unit changes to pending rollback, execute step S602. If the transaction status of the first business unit changes to pending commit, execute steps S603 and S603.

[0093] Step S602: The first business unit performs a transaction rollback operation

[0094] Step S603: The first business unit executes a transaction commit operation.

[0095] Step S604: marking the transaction status of the first business unit as submitted, and marking the transaction status of the second business unit that receives the business request of the first business unit as pending submission.

[0096] Specifically, the pending submission is a transaction state, and the pending submission indicates that the next transaction operation to be performed by the local business is a transaction submission. Further, optionally, the pending submission transaction state is marked by the superior business unit of the local business unit.

[0097] Furthermore, the unique identification and transaction status of the purchase business of the commodity transaction module, the unique identification and transaction status of the inventory module, and the unique identification and transaction status of the order module are recorded by using the monitored storage unit;

[0098] It can be seen that the unique identifier and transaction status of the purchase business of the commodity trading module, and the unique identifier and transaction status of the inventory module, are recorded using the monitored storage unit; the embodiment of the present invention uses the monitoring mechanism of Zookeeper and the monitored storage unit as an example, and the product to which the monitoring mechanism belongs can also include Eureka, etc., but is not limited to the above products; the present invention does not limit the product to which the monitoring mechanism belongs.

[0099] This implementation can ensure strong consistency of transactions in distributed transactions and reduce the workload of developing business codes related to distributed transaction processing.

[0100] Furthermore, the local transaction status includes: registered, committed, rollback, pending commit, pending rollback, and committed; the transaction operations of the local business include: transaction commit, transaction rollback, and no action.

[0101] Specifically, as described in the above embodiments:

[0102] The registration indicates a local transaction state; when the first business unit sends a service request to the second business unit and the second business unit forms a unique identifier associated with the first business unit, the local transaction state is marked as registered.

[0103] The commit indicates a local transaction state; when the local service is successfully executed, the local transaction is marked as committed.

[0104] The rollback indicates a local transaction state; when the local business execution fails or the data is abnormal, the local transaction state is marked as rollback.

[0105] The to-be-rolled-back indication is a local transaction state, and the to-be-rolled-back indicates that the transaction operation to be executed next by the local business is a rollback. Further, optionally, the transaction state to be rolled back is marked by the superior business unit of the local business unit.

[0106] The pending submission is a transaction state, which indicates that the next transaction operation to be performed by the local business is transaction submission. Further, optionally, the pending submission transaction state is marked by the superior business unit of the local business unit.

[0107] The "committed" indicates a local transaction state; when a local transaction commit operation is performed, the local transaction is marked as committed.

[0108] The transaction rollback operation is indicated as a local transaction operation, which refers to the behavior of restoring local business or data to the last correct state when local business execution fails or data is abnormal. It can be understood that the transaction rollback operation is combined with other transaction operations to ensure the consistency of the transaction.

[0109] The transaction commit operation is indicated as a local transaction operation, that is, a transaction commit operation for executing local business. Further, the commit transaction is persistent, that is, the changes made to the data storage module by executing the commit transaction operation, such as changes to data in the database, are permanent and cannot be rolled back.

[0110] The no-action operation indicates that under a predetermined condition, the local service does not need to perform a transaction operation; for example, the transaction status of the local service unit is commit or register, and the no-action operation is performed.

[0111] It can be understood that, when the business unit does not have an upper-level business unit, that is, the root business unit, the transaction status of the root business unit does not need to be marked by the upper-level business unit, and the change of the transaction status does not need to be monitored by the upper-level business unit; further, when the transaction status of all subordinate business units associated with the root business unit is committed, the root business unit performs a local transaction commit operation; when the business unit does not have a subordinate business unit, the business unit does not need to monitor the transaction status of the subordinate business unit.

[0112] like Figure 7As shown, an embodiment of the present invention provides a distributed transaction processing device 700, comprising: a transaction identification management module 701, a transaction execution module 702 and a transaction status management module 703; wherein the transaction identification management module 701 is used to receive a first service request and form a local unique identifier associated with the first service request. The transaction execution module 702 is used to execute a local service according to the first service request; in the case where there are one or more second service units that receive the service request of the device, the device sends a second service request to the second service unit, and the second service request indicates the local unique identifier associated with the device. The transaction status management module 703 is used to determine the local transaction status associated with the local unique identifier according to the execution result of the local service.

[0113] Optionally, in the distributed transaction processing device, the local transaction status includes: registered, committed, rollback, pending commit, pending rollback, and committed.

[0114] Optionally, in the distributed transaction processing apparatus, determining, according to the execution result of the local service, the local transaction state associated with the local unique identifier comprises:

[0115] The device monitors the local transaction state associated with the local unique identifier of the second service unit, and determines the local transaction state of the device according to the local transaction state of the second service unit.

[0116] Optionally, the distributed transaction processing device monitors changes in the local transaction state, and determines an operation corresponding to the first transaction state based on the first transaction state.

[0117] Optionally, in the distributed transaction processing device, the local transaction state is changed by an upper-level unit of the device, and the upper-level business unit is a business unit that sends the first business request to the device.

[0118] Optionally, the distributed transaction processing device uses the monitored storage unit to correspondingly record the local unique identifier and local transaction status of the device, and the local unique identifier and local transaction status of the second business unit.

[0119] An embodiment of the present invention also provides a server for distributed transaction processing, comprising: one or more processors; a storage device for storing one or more programs, and when the one or more programs are executed by the one or more processors, the one or more processors implement the method provided in any of the above embodiments.

[0120] An embodiment of the present invention further provides a computer-readable medium on which a computer program is stored. When the program is executed by a processor, the method provided in any of the above embodiments is implemented.

[0121] Figure 8 An exemplary system architecture 800 is shown to which a distributed transaction processing method or a distributed transaction processing apparatus according to an embodiment of the present invention can be applied.

[0122] like Figure 8 As shown, system architecture 800 may include terminal devices 801, 802, 803, a network 804, and a server 805. Network 804 is used to provide a medium for communication links between terminal devices 801, 802, 803 and server 805. Network 804 may include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.

[0123] Users can use terminal devices 801, 802, 803 to interact with server 805 through network 804 to receive or send messages, etc. Terminal devices 801, 802, 803 can be installed with various communication client applications, such as web browser applications, search applications, instant messaging tools, and email clients.

[0124] The terminal devices 801 , 802 , and 803 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.

[0125] Server 805 may be a server that provides various services, such as a backend management server that provides support for shopping websites browsed by users using terminal devices 801, 802, and 803. The backend management server may analyze and perform logical operations on received data such as commodity purchase requests, and feed back results such as purchase orders to the terminal devices.

[0126] It should be noted that the distributed transaction processing method provided in the embodiment of the present invention is generally executed by the server 805 , and accordingly, a distributed transaction processing device is generally set in the server 805 .

[0127] It should be understood that Figure 8 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0128] Reference below Fig. 9 , which shows a schematic diagram of the structure of a computer system 900 of a terminal device suitable for implementing an embodiment of the present invention. Fig. 9The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.

[0129] like Fig. 9 As shown, the computer system 900 includes a central processing unit (CPU) 901, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 902 or a program loaded from a storage part 908 into a random access memory (RAM) 903. In the RAM 903, various programs and data required for the operation of the system 900 are also stored. The CPU 901, the ROM 902, and the RAM 903 are connected to each other via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.

[0130] The following components are connected to the I / O interface 905: an input section 906 including a keyboard, a mouse, etc.; an output section 907 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 908 including a hard disk, etc.; and a communication section 909 including a network interface card such as a LAN card, a modem, etc. The communication section 909 performs communication processing via a network such as the Internet. A drive 910 is also connected to the I / O interface 905 as needed. A removable medium 911, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 910 as needed, so that a computer program read therefrom is installed into the storage section 908 as needed.

[0131] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 909, and / or installed from the removable medium 911. When the computer program is executed by the central processing unit (CPU) 901, the above-mentioned functions defined in the system of the present invention are executed.

[0132] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.

[0133] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.

[0134] The modules and / or units involved in the embodiments of the present invention may be implemented in software or hardware. The modules and / or units described may also be arranged in a processor, for example, they may be described as: a distributed transaction processing device including a transaction identification management module, a transaction execution module, and a transaction status management module. The names of these modules do not, in some cases, constitute limitations on the modules themselves, for example, the transaction status management module may also be described as a "module for monitoring a unique identifier associated with a transaction, and determining a transaction status and transaction operation".

[0135] As another aspect, the present invention also provides a computer-readable medium, which may be included in the device described in the above embodiment; or it may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs. When the above one or more programs are executed by a device, the device includes: a first business unit receives a first business request, forms a local unique identifier associated with the first business request, and executes a local business according to the first business request; in the case where there are one or more second business units that receive the business request of the first business unit, the first business unit sends a second business request to the second business unit, and the second business request indicates the local unique identifier associated with the first business unit. According to the execution result of the local business, the local transaction state associated with the local unique identifier is determined.

[0136] According to the technical solution of the embodiment of the present invention, the monitored storage unit is used to record the transaction status of the monitored local business unit and the associated business units, and the corresponding business unit is notified of operations such as transaction submission and rollback by modifying the transaction status. While solving distributed transactions, the transaction consistency of distributed transactions is ensured and the workload of business code development to achieve distributed business consistency is reduced.

[0137] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.

Claims

1. A distributed transaction processing method, characterized in that: include: The first service unit receives the first service request, forms a local unique identifier associated with the first service request, and executes a local service according to the first service request; In a case where there are one or more second business units that receive the business request of the first business unit, the first business unit sends a second business request to the second business unit, where the second business request indicates the local unique identifier associated with the first business unit; Determine, according to the execution result of the local service executed by the first service unit, a local transaction state corresponding to the first service unit and a local transaction state corresponding to the second service unit associated with the local unique identifier; The method further includes: using the monitored storage unit to correspondingly record the local unique identifier and local transaction status of the first business unit, and the local unique identifier and local transaction status of the second business unit.

2. The method according to claim 1, characterized in that The local transaction status includes: registered, committed, rollback, pending commit, pending rollback, and committed.

3. The method according to claim 1, characterized in that The determining, according to the execution result of the local service executed by the first service unit, the local transaction state associated with the local unique identifier comprises: The first business unit monitors the local transaction state associated with the local unique identifier of the second business unit, and determines the local transaction state of the first business unit according to the local transaction state of the second business unit.

4. The method according to claim 1, characterized in that: Monitor changes in the local transaction state and determine operations corresponding to the local transaction state.

5. The method according to claim 4, characterized in that The local transaction state is changed by an upper-level service unit of the first service unit, and the upper-level service unit is a service unit that sends the first service request to the first service unit.

6. A distributed transaction processing device, characterized in that: include: Transaction identification management module, transaction execution module and transaction status management module; wherein, The transaction identifier management module is used to receive a first service request and form a local unique identifier associated with the first service request; The transaction execution module is configured to execute a local service according to the first service request; in the case where there are one or more second service units that receive the service request of the device, the device sends a second service request to the second service unit, wherein the second service request indicates the local unique identifier associated with the device; The transaction status management module is used to determine the local transaction status associated with the local unique identifier based on the execution result of the local business, including: the device monitors the local transaction status associated with the local unique identifier of the second business unit, and determines the local transaction status of the device based on the local transaction status of the second business unit.

7. The device according to claim 6, characterized in that The local transaction status includes: registered, committed, rollback, pending commit, pending rollback, and committed.

8. The device according to claim 6, characterized in that Monitor changes in the local transaction state and determine operations corresponding to the local transaction state.

9. The device according to claim 8, characterized in that The local transaction state is changed by an upper-level service unit of the device, and the upper-level service unit is a service unit that sends the first service request to the device.

10. The device according to any one of claims 6 to 9, characterized in that: The monitored storage unit is used to correspondingly record the local unique identifier and the local transaction state of the device, and the local unique identifier and the local transaction state of the second service unit.

11. A server, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 5.

12. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 5 is implemented.