Distributed transaction management method and related device

By introducing multiple branch transaction strategies into the distributed transaction management method, the coordinator can automatically select appropriate policies based on business scenarios and context, solving the problem that the existing technology cannot meet business needs, and achieving higher transaction success rate and system flexibility.

CN119597409APending Publication Date: 2025-03-11AGRICULTURAL BANK OF CHINA
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411743772.4
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-11-30
Publication Date
2025-03-11

AI Technical Summary

Technical Problem

Existing distributed transaction management technologies cannot meet business needs when sub-transactions fail and cannot provide multiple branch transaction strategies to deal with different business scenarios.

Method used

Provides a distributed transaction management method, obtains the branch transaction context of the target global transaction through the coordinator, and obtains matching branch transaction policies from the branch policy storage module, including multiple compensation policies, multiple retry policies, termination compensation policies, termination retry policies and transaction suspend policies, and performs corresponding operations to meet business needs.

Benefits of technology

By providing multiple branch transaction strategies, the appropriate strategies can be automatically selected according to different business scenarios and contexts, improving transaction success rate and system flexibility, and meeting the needs of different businesses.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119597409A_ABST
    Figure CN119597409A_ABST
Patent Text Reader

Abstract

The invention discloses a distributed transaction management method and a related device, and relates to the field of distributed transactions, and the method comprises the steps that a coordinator obtains a context of a target branch transaction included in a target global transaction; the coordinator obtains a branch transaction policy matched with the context from a branch policy storage module, the branch policy storage module stores a branch policy configuration table, and the context and the branch transaction policy are correspondingly stored in the branch policy configuration table; the branch transaction strategies in the branch strategy configuration table at least comprise a multi-compensation strategy, a multi-retry strategy, a compensation termination strategy, a retry termination strategy and a transaction suspension strategy; and the coordinator executes an operation corresponding to the obtained branch transaction policy. According to the method and the device, the requirements of different services can be met.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the technical field of distributed transactions, and in particular to a distributed transaction management method and related devices. Background Art

[0002] With the rapid development of the Internet, it is difficult for single applications to support large-volume, high-concurrency requests, so the software system has gradually transitioned from the original single application to a distributed one. After the application is deployed in a distributed manner, there will be multiple services to complete the operation of a transaction, and these services may exist in different servers or network environments. Servers collaborate remotely through the network to complete transactions, thus generating distributed transactions.

[0003] The current distributed transaction management technology will compensate all completed subtransactions when a subtransaction fails. However, this distributed transaction management technology cannot meet business needs. Summary of the invention

[0004] In view of the above problems, the present application provides a distributed transaction management method and related devices to provide multiple branch transaction strategies to meet business needs. The specific solution is as follows:

[0005] The first aspect of the present application provides a distributed transaction management method, comprising:

[0006] The coordinator obtains the context of the target branch transaction included in the target global transaction;

[0007] The coordinator obtains a branch transaction strategy matching the context from a branch strategy storage module, wherein the branch strategy storage module stores a branch strategy configuration table, wherein the context and the branch transaction strategy are correspondingly stored in the branch strategy configuration table, and the branch transaction strategy in the branch strategy configuration table includes at least: multiple compensation strategy, multiple retry strategy, termination compensation strategy, termination retry strategy and transaction suspension strategy;

[0008] The coordinator performs an operation corresponding to the obtained branch transaction strategy.

[0009] In a possible implementation, the coordinator performs an operation corresponding to the obtained branch transaction strategy, including:

[0010] If the branch transaction strategy obtained is a multiple compensation strategy, a compensation operation is performed on the target branch transaction, and it is determined whether the compensation is successful. If the compensation fails, it is determined whether the number of compensation times for the target branch transaction is greater than the first target number. If not, the step of performing the compensation operation on the target branch transaction is returned. If greater, the target branch transaction is suspended. If the compensation is successful, the compensation operation is continued on the branch transaction before the target branch transaction.

[0011] and / or,

[0012] If the branch transaction strategy obtained is a termination compensation strategy, determine whether the forward operation of the target branch transaction is successful. If successful, stop performing the compensation operation on the target branch transaction and continue to perform the forward operation on the subsequent branch transactions of the target branch transaction. If the forward operation of the target branch transaction fails, continue to perform the compensation operation on the target branch transaction.

[0013] In a possible implementation, the coordinator performs an operation corresponding to the obtained branch transaction strategy, including:

[0014] If the branch transaction strategy obtained is a multiple retry strategy, the target branch transaction is forward operated again, and it is determined whether the forward operation is successful. If it fails, it is determined whether the number of forward operations on the target branch transaction is greater than the second target number. If it is not greater, it returns to the step of performing the forward operation on the target branch transaction again. If it is greater, the target branch transaction is suspended. If the forward operation is successful, the forward operation is continued on the branch transaction after the target branch transaction.

[0015] and / or,

[0016] If the branch transaction strategy obtained is a termination retry strategy, the forward operation on the target branch transaction is stopped and a compensation operation is performed on the branch transaction before the target branch transaction.

[0017] In a possible implementation, the coordinator performs an operation corresponding to the obtained branch transaction strategy, including:

[0018] If the obtained branch transaction strategy is a transaction suspension strategy, the target branch transaction is suspended, and after the target branch transaction is suspended, the compensation operation on the branch transaction before the target branch transaction is stopped.

[0019] In a possible implementation, the context includes an error code, and if the error code is an error code indicating network instability, the branch transaction strategy matching the context obtained by the coordinator from the branch strategy storage module is the multiple retry strategy;

[0020] If the error code is an error code indicating that a service is unavailable, the branch transaction strategy that matches the context and is obtained by the coordinator from the branch strategy storage module is the transaction suspension strategy.

[0021] A second aspect of the present application provides a distributed transaction management system, including: a coordinator and a branch strategy storage module,

[0022] The coordinator is used to obtain the context of the target branch transaction included in the target global transaction;

[0023] The coordinator is further used to obtain a branch transaction strategy matching the context from the branch strategy storage module, wherein the branch strategy storage module stores a branch strategy configuration table, wherein the context and the branch transaction strategy are correspondingly stored in the branch strategy configuration table, and the branch transaction strategy in the branch strategy configuration table includes at least: multiple compensation strategy, multiple retry strategy, termination compensation strategy, termination retry strategy and transaction suspension strategy;

[0024] The coordinator is further configured to execute an operation corresponding to the obtained branch transaction strategy.

[0025] In a possible implementation, the coordinator that performs the operation corresponding to the obtained branch transaction strategy is specifically configured to:

[0026] If the branch transaction strategy obtained is a multiple compensation strategy, a compensation operation is performed on the target branch transaction, and it is determined whether the compensation is successful. If the compensation fails, it is determined whether the number of compensation times for the target branch transaction is greater than the first target number. If not, the step of performing the compensation operation on the target branch transaction is returned. If greater, the target branch transaction is suspended. If the compensation is successful, the compensation operation is continued on the branch transaction before the target branch transaction.

[0027] If the branch transaction strategy obtained is a termination compensation strategy, determine whether the forward operation of the target branch transaction is successful; if successful, stop performing the compensation operation on the target branch transaction and continue to perform the forward operation on the subsequent branch transaction of the target branch transaction; if the forward operation of the target branch transaction fails, continue to perform the compensation operation on the target branch transaction;

[0028] If the branch transaction strategy obtained is a multiple retry strategy, the target branch transaction is forward operated again, and it is determined whether the forward operation is successful. If it fails, it is determined whether the number of forward operations on the target branch transaction is greater than the second target number. If it is not greater, it returns to the step of performing the forward operation on the target branch transaction again. If it is greater, the target branch transaction is suspended. If the forward operation is successful, the forward operation is continued on the branch transaction after the target branch transaction.

[0029] If the branch transaction strategy obtained is a termination retry strategy, then stopping the forward operation on the target branch transaction and performing a compensation operation on the branch transaction before the target branch transaction;

[0030] If the obtained branch transaction strategy is a transaction suspension strategy, the target branch transaction is suspended, and after the target branch transaction is suspended, the compensation operation on the branch transaction before the target branch transaction is stopped.

[0031] A third aspect of the present application provides a computer program product, comprising computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements the method for managing distributed transactions of the first aspect or any implementation of the first aspect.

[0032] A fourth aspect of the present application provides an electronic device, comprising at least one processor and a memory connected to the processor, wherein:

[0033] The memory is used to store computer programs;

[0034] The processor is used to execute the computer program so that the electronic device can implement the distributed transaction management method of the above-mentioned first aspect or any implementation manner of the first aspect.

[0035] A fifth aspect of the present application provides a computer storage medium, which carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement the method for managing distributed transactions according to the first aspect or any implementation of the first aspect.

[0036] By means of the above technical solution, the management method and related devices of distributed transactions provided by the present application can provide multiple branch transaction strategies such as multiple compensation strategies, multiple retry strategies, termination compensation strategies, termination retry strategies, and transaction suspension strategies, and each branch transaction strategy has its own corresponding context. In this way, the present application can determine and execute the operation corresponding to the branch transaction strategy corresponding to the context according to the context of the target branch transaction. Through a variety of different branch transaction strategies, the present application can meet the needs of different businesses. At the same time, through the branch strategy configuration table, the present application can automatically execute matching operations according to the context, which is very convenient. BRIEF DESCRIPTION OF THE DRAWINGS

[0037] The above and other features, advantages and aspects of the embodiments of the present disclosure will become more apparent with reference to the following detailed description in conjunction with the accompanying drawings. Throughout the accompanying drawings, the same or similar reference numerals represent the same or similar elements. It should be understood that the drawings are schematic and the originals and elements are not necessarily drawn to scale.

[0038] Figure 1 A schematic diagram of a system architecture provided for this application;

[0039] Figure 2 A schematic diagram of the structure of a terminal provided for this application;

[0040] Figure 3 A schematic diagram of the structure of a server provided for this application;

[0041] Figure 4 It is the business logic diagram of the existing SAGA model;

[0042] Figure 5 A schematic diagram of a process flow of a distributed transaction management method provided in an embodiment of the present application;

[0043] Figure 6 A schematic diagram of a branch transaction strategy executed by a compensation module provided in an embodiment of the present application;

[0044] Figure 7 A schematic diagram of a branch transaction strategy executed by a retry module provided in an embodiment of the present application;

[0045] Figure 8 A schematic diagram of an application of a distributed transaction management method provided in an embodiment of the present application;

[0046] Fig. 9 A schematic diagram of the structure of a distributed transaction management system provided in an embodiment of the present application;

[0047] Fig.10 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0048] The following describes the embodiments of the present application in conjunction with the drawings in the embodiments of the present application. The terms used in the implementation method section of the present application are only used to explain the specific embodiments of the present application, and are not intended to limit the present application.

[0049] The embodiments of the present application are described below in conjunction with the accompanying drawings. Those skilled in the art will appreciate that, with the development of technology and the emergence of new scenarios, the technical solutions provided in the embodiments of the present application are also applicable to similar technical problems.

[0050] The terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and need not be used to describe a specific order or sequential order. It should be understood that the terms used in this way can be interchangeable under appropriate circumstances, which is only to describe the distinction mode adopted by the objects of the same attributes when describing in the embodiments of the present application. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, so that the process, method, system, product or equipment comprising a series of units need not be limited to those units, but may include other units that are not clearly listed or inherent to these processes, methods, products or equipment.

[0051] See also Figure 1 , Figure 1 A schematic diagram of a system architecture is shown. The system may include a terminal 100 and a server 200. The server 200 may include one or more servers ( Figure 1 In the example, a server is included, and the server 200 can provide the method provided in the embodiment of the present application for one or more terminals.

[0052] Among them, a distributed transaction management application can be installed on the terminal 100. The above application and web page can provide an interface. The terminal 100 can receive relevant parameters entered by the user on the interface (such as the transaction identifier of the target branch transaction included in the target global transaction), and send the above parameters to the server 200. The server 200 can obtain the processing result (such as the result of executing the operation corresponding to the obtained branch transaction strategy) based on the received parameters, and return the processing result to the terminal 100.

[0053] It should be understood that in some optional implementations, the terminal 100 can also complete the action of obtaining the processing result based on the received parameters by itself without the cooperation of the server, and the embodiments of the present application are not limited to this.

[0054] Next describe Figure 1 The product form of the mid-terminal 100;

[0055] The terminal 100 in the embodiment of the present application can be a mobile phone, a tablet computer, a wearable device, a vehicle-mounted device, an augmented reality (AR) / virtual reality (VR) device, a laptop computer, an ultra-mobile personal computer (UMPC), a netbook, a personal digital assistant (PDA), etc., and the embodiment of the present application does not impose any limitation on this.

[0056] Figure 2 An optional hardware structure diagram of the terminal 100 is shown.

[0057] refer to Figure 2 As shown, the terminal 100 may include a radio frequency unit 110, a memory 120, an input unit 130, a display unit 140, a camera 150 (optional), an audio circuit 160 (optional), a speaker 161 (optional), a microphone 162 (optional), an earphone jack 163 (optional), a processor 170, an external interface 180, a power supply 190 and other components. Those skilled in the art will appreciate that Figure 2 These are merely examples of terminals or multi-function devices and do not constitute limitations on the terminals or multi-function devices, which may include more or fewer components than those shown in the figures, or combinations of certain components, or different components.

[0058] The input unit 130 can be used to receive input digital or character information, and generate key signal input related to the user settings and function control of the portable multifunctional device. Specifically, the input unit 130 may include a touch screen 131 (optional) and / or other input devices 132. The touch screen 131 can collect the user's touch operations on or near it (such as the user's operation on or near the touch screen using any suitable object such as fingers, joints, stylus, etc.), and drive the corresponding connection device according to a pre-set program. The touch screen can detect the user's touch action on the touch screen, convert the touch action into a touch signal and send it to the processor 170, and can receive and execute the command sent by the processor 170; the touch signal at least includes the touch point coordinate information. The touch screen 131 can provide an input interface and an output interface between the terminal 100 and the user. In addition, the touch screen can be implemented using multiple types such as resistive, capacitive, infrared and surface acoustic wave. In addition to the touch screen 131, the input unit 130 can also include other input devices. Specifically, other input devices 132 may include, but are not limited to, one or more of a physical keyboard, function keys (such as a volume control key, a switch key, etc.), a trackball, a mouse, a joystick, and the like.

[0059] Among them, the input device 132 can receive input data and the like.

[0060] The display unit 140 may be used to display information input by the user or provided to the user, various menus of the terminal 100, interactive interfaces, file displays, and / or playback of any multimedia files. In an embodiment of the present application, the display unit 140 may be used to display an input interface of a target branch transaction identifier, processing results, and the like.

[0061] The memory 120 can be used to store instructions and data. The memory 120 can mainly include an instruction storage area and a data storage area. The data storage area can store various data, such as multimedia files, texts, etc.; the instruction storage area can store software units such as operating systems, applications, instructions required for at least one function, or their subsets and extensions. It can also include a non-volatile random access memory; provide the processor 170 with hardware, software and data resources including management of computing and processing equipment, and support control software and applications. It is also used for the storage of multimedia files, and the storage of running programs and applications.

[0062] The processor 170 is the control center of the terminal 100. It uses various interfaces and lines to connect various parts of the entire terminal 100. By running or executing instructions stored in the memory 120 and calling data stored in the memory 120, it executes various functions of the terminal 100 and processes data, thereby controlling the terminal device as a whole. Optionally, the processor 170 may include one or more processing units; preferably, the processor 170 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface and application program, and the modem processor mainly processes wireless communication. It is understandable that the above-mentioned modem processor may not be integrated into the processor 170. In some embodiments, the processor and the memory may be implemented on a single chip, and in some embodiments, they may also be implemented separately on separate chips. The processor 170 may also be used to generate corresponding operation control signals, send them to corresponding components of the computing and processing device, read and process data in the software, especially read and process data and programs in the memory 120, so that each functional module therein performs corresponding functions, thereby controlling the corresponding components to act according to the requirements of the instructions.

[0063] Among them, the memory 120 can be used to store software codes related to the distributed transaction management method, the processor 170 can execute the steps of the distributed transaction management method, and can also schedule other units (such as the above-mentioned input unit 130 and display unit 140) to implement corresponding functions.

[0064] The radio frequency unit 110 (optional) can be used for receiving and sending information or receiving and sending signals during a call, for example, after receiving the downlink information of the base station, it is sent to the processor 170 for processing; in addition, the designed uplink data is sent to the base station. Generally, the RF circuit includes but is not limited to an antenna, at least one amplifier, a transceiver, a coupler, a low noise amplifier (Low Noise Amplifier, LNA), a duplexer, etc. In addition, the radio frequency unit 110 can also communicate with network devices and other devices through wireless communication. The wireless communication can use any communication standard or protocol, including but not limited to Global System of Mobile communication (Global System of Mobile communication, GSM), General Packet Radio Service (General Packet Radio Service, GPRS), Code Division Multiple Access (Code Division Multiple Access, CDMA), Wideband Code Division Multiple Access (Wideband Code Division Multiple Access, WCDMA), Long Term Evolution (Long Term Evolution, LTE), email, Short Messaging Service (SMS), etc.

[0065] In this embodiment of the present application, the RF unit 110 can send data to the server 200 and receive processing results sent by the server 200.

[0066] It should be understood that the radio frequency unit 110 is optional and can be replaced by other communication interfaces, such as a network port.

[0067] The terminal 100 also includes a power supply 190 (such as a battery) for supplying power to various components. Preferably, the power supply can be logically connected to the processor 170 through a power management system, so that the power management system can manage functions such as charging, discharging, and power consumption.

[0068] The terminal 100 further includes an external interface 180 , which may be a standard Micro USB interface or a multi-pin connector, and may be used to connect the terminal 100 to communicate with other devices, or to connect a charger to charge the terminal 100 .

[0069] Although not shown, the terminal 100 may also include a flashlight, a wireless fidelity (WiFi) module, a Bluetooth module, sensors with different functions, etc., which are not described in detail here. Some or all of the methods described below may be applied in the following embodiments. Figure 2 In the terminal 100 shown.

[0070] Next describe Figure 1 The product form of the server 200;

[0071] Figure 3 A structural diagram of a server 200 is provided, such as Figure 3 As shown, the server 200 includes a bus 201, a processor 202, a communication interface 203, and a memory 204. The processor 202, the memory 204, and the communication interface 203 communicate with each other via the bus 201.

[0072] The bus 201 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0073] The processor 202 may be any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).

[0074] The memory 204 may include a volatile memory, such as a random access memory (RAM). The memory 204 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard disk drive (HDD), or a solid state drive (SSD).

[0075] The memory 204 may be used to store software codes related to the distributed transaction management method, and the processor 202 may execute the steps of the distributed transaction management method of the chip, and may also schedule other units to implement corresponding functions.

[0076] It should be understood that the above-mentioned terminal 100 and server 200 can be centralized or distributed devices, and the processors in the above-mentioned terminal 100 and server 200 (such as processor 170 and processor 202) can be hardware circuits (such as application specific integrated circuit (ASIC), field-programmable gate array (FPGA), general-purpose processor, digital signal processor (DSP), microprocessor or microcontroller, etc.), or a combination of these hardware circuits. For example, the processor can be a hardware system with an instruction execution function, such as a CPU, DSP, etc., or a hardware system without an instruction execution function, such as an ASIC, FPGA, etc., or a combination of the above-mentioned hardware systems without an instruction execution function and hardware systems with an instruction execution function.

[0077] Among the current distributed transaction management technologies, the long transaction mode SAGA (Serializable Atomic Global Additive) is a commonly used method for processing distributed transactions, which is particularly suitable for long transaction scenarios in microservice architectures. It ensures that the entire business process can maintain eventual consistency even if some subtransactions fail through the orderly execution of a series of local transactions (subtransactions) and corresponding compensation actions (CompensationAction).

[0078] However, the SAGA model is the same as the XA model (strong consistency phased transaction model), AT model (eventually consistent phased transaction model, no business intrusion), and TCC model (eventually consistent phased transaction model, business intrusion). Its branch transaction strategy is too simple, and the complexity of business is increasing. A single branch transaction strategy cannot meet the needs of current business. Figure 4 As shown, the global transaction includes branch transactions 1 to 3 executed in sequence. If the forward operation of branch transaction 3 is successful, the global transaction is committed. If the forward operation of branch transaction 3 fails, reverse compensation is required to roll back the global transaction. Such a single branch transaction strategy cannot meet the needs of current business. For example: the business has high requirements for the success rate of transaction execution, and the global transaction cannot be rolled back as soon as the forward operation of the branch transaction fails. For another example: the business needs to control the rollback of global transactions in high-concurrency scenarios. When there are a large number of transactions to be processed, the priority of the global transaction rollback is lower. If the forward operation of the branch transaction fails and the global transaction is rolled back, the global transaction rollback will preempt the resources (such as computing resources, storage resources, network resources, etc.) relied on by other higher-priority transaction processing.

[0079] In order to solve the above problems, the present application embodiment provides a distributed transaction management method. The distributed transaction management method of the present application embodiment is described in detail below with reference to the accompanying drawings.

[0080] Reference Figure 5 , Figure 5 A process diagram of a distributed transaction management method provided in an embodiment of the present application is shown as follows: Figure 5 As shown, a distributed transaction management method provided in an embodiment of the present application may include steps 501 to 503, and these steps are described in detail below.

[0081] 501. The coordinator obtains the context of the target branch transaction included in the target global transaction.

[0082] It is understandable that a global transaction may include multiple branch transactions. In a business scenario, each branch transaction included in the global transaction may perform forward operations in sequence according to a preset order, and perform compensation operations in a reverse order to the preset order.

[0083] The context of the target branch transaction is the environmental factor when the target branch transaction is running, which may include: system status, network status, data status, etc. Different contexts represent different situations of the target branch transaction running, for example: it may represent network instability or service unavailability.

[0084] The present application can pre-set corresponding branch transaction strategies for different contexts. For example, for contexts that characterize network instability, the present application can set the corresponding branch transaction strategy to a multiple retry strategy. In this way, through the multiple retry strategy, multiple attempts can be made to perform forward operations on the target branch transaction, which can greatly improve the success rate of the operation and avoid the situation where a forward operation fails due to network instability, causing the target global transaction to perform compensation operations.

[0085] The coordinator is a component used to manage and coordinate the interactions between various services in distributed transactions. Its main function is to ensure that distributed transactions can be executed in a predetermined order and to perform corresponding rollback operations in case of failure to restore system consistency.

[0086] 502. The coordinator obtains a branch transaction strategy that matches the context from a branch strategy storage module. The branch strategy storage module stores a branch strategy configuration table. The branch strategy configuration table stores the context and the branch transaction strategy accordingly. The branch transaction strategy in the branch strategy configuration table includes at least: multiple compensation strategy, multiple retry strategy, termination compensation strategy, termination retry strategy and transaction suspension strategy.

[0087] In one possible implementation, the coordinator may pre-load the branch strategy configuration table stored in the branch strategy storage module into the memory, so that the branch transaction strategy matching the context can be directly queried from the memory in subsequent use, thereby effectively improving the operating efficiency.

[0088] Optionally, the present application may pre-build a policy library, which stores at least one branch policy configuration table. The branch policy configuration table may store: retry method, compensation method, error code, policy configuration, module selection, number of retries, interval time, system status, user role and other elements.

[0089] Among them, error code, system status, user role, etc. are information in the context. Retry method, compensation method, policy configuration, module selection, number of retries, and interval time are information in the branch transaction strategy. For example, for multiple compensation strategies, it includes: compensation method, policy configuration, module selection, number of retries, interval time and other specific information.

[0090] The transaction suspension strategy refers to a strategy in which the coordinator no longer executes the second phase (such as the retry phase or the compensation phase) of the branch transaction when the transaction has started and some operations of the transaction have been persisted but have not yet reached the final state.

[0091] The termination compensation strategy refers to a two-stage compensation method for branch transactions that enter branch transactions due to timeout or failure. Before compensation, if the current branch forward logic is found to be successful, the compensation of the current branch transaction will no longer be executed, and the forward logic of the next branch transaction will be executed.

[0092] The termination retry strategy refers to the two-stage retry method of a branch transaction that enters the branch transaction due to timeout or failure. Since the business exception can never succeed, the current branch transaction will no longer be retried, and the compensation of the previous branch transaction will be executed.

[0093] The multiple compensation strategy refers to a two-stage compensation method for branch transactions due to failure or failure. If one compensation fails, multiple compensations are performed until the number of compensations is greater than the first target number.

[0094] The multiple retry strategy refers to a two-stage retry method for a branch transaction due to timeout or failure. If a retry fails once, multiple retries are performed until the number of retries exceeds the second target number.

[0095] Optionally, the context includes an error code. If the error code is an error code that represents network instability, the branch transaction strategy that matches the context obtained by the coordinator from the branch strategy storage module is a multiple retry strategy; if the error code is an error code that represents service unavailability, the branch transaction strategy that matches the context obtained by the coordinator from the branch strategy storage module is a transaction suspension strategy.

[0096] When the forward operation of the target branch transaction fails or is not committed due to network instability, the present application can attempt to execute the forward operation of the target branch transaction again based on a multiple retry strategy until the number of retries reaches a second target number, thereby avoiding global transaction rollback caused by temporary network instability (rather than network interruption).

[0097] When the service to be called by the target branch transaction is unavailable, the transaction can be suspended and the operation can be performed again when the subsequent service is available.

[0098] Optionally, if the obtained branch transaction strategy is a multiple compensation strategy, the coordinator performs a compensation operation on the target branch transaction and determines whether the compensation is successful. If the compensation fails, it determines whether the number of compensations for the target branch transaction is greater than the first target number. If not, it returns to the step of performing the compensation operation on the target branch transaction. If greater, the target branch transaction is suspended. If the compensation is successful, the compensation operation continues on the branch transaction before the target branch transaction.

[0099] Optionally, if the branch transaction strategy obtained is a termination compensation strategy, the coordinator determines whether the forward operation of the target branch transaction is successful. If successful, the coordinator stops performing the compensation operation on the target branch transaction and continues to perform the forward operation on the subsequent branch transactions of the target branch transaction. If the forward operation of the target branch transaction fails, the coordinator continues to perform the compensation operation on the target branch transaction.

[0100] Specifically, Figure 6 As shown, when the target branch transaction times out or fails, the present application can use the compensation module in the coordinator to perform operations. Specifically, Figure 6As shown, the compensation module can execute multiple compensation strategies, termination compensation strategies and transaction suspension strategies. When the compensation module executes multiple compensation strategies, if the compensation is successful, the compensation operation can continue to be performed on the branch transaction before the target branch transaction (all branches that have performed forward operations). If the compensation operation still fails or the compensation result is unknown after multiple compensation operations, the transaction suspension strategy can be executed to suspend the branch transaction. When the compensation module executes the termination compensation strategy, it can be determined whether the forward operation of the target branch transaction is successful. If successful, the compensation operation on the target branch transaction is stopped and the forward operation on the branch transaction after the target branch transaction is continued. If the forward operation of the target branch transaction fails, the compensation operation on the target branch transaction and the branch transaction before it continues.

[0101] Optionally, if the obtained branch transaction strategy is a multiple retry strategy, the coordinator performs a forward operation on the target branch transaction again and determines whether the forward operation is successful. If it fails, it determines whether the number of forward operations on the target branch transaction is greater than the second target number. If not, it returns to execute the step of performing the forward operation on the target branch transaction again. If it is greater, the target branch transaction is suspended. If the forward operation is successful, the forward operation continues to be performed on the branch transaction after the target branch transaction.

[0102] Optionally, if the obtained branch transaction strategy is a termination retry strategy, the coordinator stops performing forward operations on the target branch transaction and performs compensation operations on the branch transaction before the target branch transaction.

[0103] Specifically, Figure 7 As shown, when the target branch transaction times out or fails, the application can use the retry module in the coordinator to operate. Specifically, Figure 7 As shown, the retry module can execute multiple retry strategies, termination retry strategies and transaction suspension strategies. When the retry module executes the multiple retry strategies, if the retry is successful, the forward operation can continue to be performed on the branch transaction after the target branch transaction. If it still fails or the result is unknown after multiple retry operations, the transaction suspension strategy can be executed to suspend the branch transaction. When the retry module executes the termination retry strategy, the forward operation on the target branch transaction can be stopped and the compensation operation can be performed on the branch transaction before the target branch transaction.

[0104] Optionally, if the obtained branch transaction strategy is a transaction suspension strategy, the coordinator (such as a retry module or a compensation module) suspends the target branch transaction, and after the target branch transaction is suspended, stops performing compensation operations on branch transactions before the target branch transaction. Optionally, after the target branch transaction is suspended, stops performing forward operations on branch transactions after the target branch transaction.

[0105] Optionally, in order to further match the branch transaction strategy with the business, the branch strategy configuration table of the present application may store the context, business scenario and branch transaction strategy accordingly, and the coordinator obtains the branch transaction strategy that matches the context and business scenario of the target global transaction from the branch strategy storage module.

[0106] 503. The coordinator executes an operation corresponding to the obtained branch transaction strategy.

[0107] The distributed transaction management method provided by the present application can provide multiple branch transaction strategies such as multiple compensation strategies, multiple retry strategies, termination compensation strategies, termination retry strategies, and transaction suspension strategies, and each branch transaction strategy has its own corresponding context. In this way, the present application can determine and execute the operations corresponding to the branch transaction strategy corresponding to the context according to the context of the target branch transaction. Through a variety of different branch transaction strategies, the present application can meet the needs of different businesses. At the same time, through the branch strategy configuration table, the present application can automatically execute matching operations according to the context, which is very convenient.

[0108] In an optional implementation of the present application, in order to prevent the branch management strategies selected by different branch transactions from conflicting, causing the branch transactions themselves to form a loop and cause a deadlock, the coordinator of the present application can monitor whether the branch management strategies conflict according to the following rules:

[0109] Rule 1: Once a branch transaction uses the retry module, all subsequent branch transactions of this branch transaction can only use the retry module.

[0110] Rule 2: Only the first branch transaction that uses the retry module can choose the termination retry strategy. Other branch transactions can only choose multiple retry strategies and transaction suspension strategies when using the retry module.

[0111] Rule 3: Only the last branch transaction that uses the compensation module can choose to terminate the compensation strategy.

[0112] In an optional embodiment, the present application can regularly evaluate the effectiveness of the branch transaction strategy in the branch strategy configuration table, measure its key indicators such as performance, success rate, resource utilization rate in actual business scenarios, and use the evaluation results as the data basis for strategy optimization. Based on the evaluation results and business changes, the branch strategy configuration table is continuously iterated and optimized.

[0113] Figure 8 An application schematic diagram provided for an embodiment of the present application, such as Figure 8As shown, the client sends a request to the A application service cluster, and the global transaction G01 of the A application service cluster consists of the branch transaction G0101 and the branch transaction G0102. Among them, the branch transaction G0102 needs to call the RPC service of the B application service cluster through a remote procedure call (RPC). The RPC service is completed by the global transaction G0102, and the global transaction G0102 consists of the branch transaction G010201 and the branch transaction G010202. The branch strategy preloading module in the coordinator in the application service cluster can preload the branch strategy configuration table in the branch strategy storage module into the memory. The coordinator can perform corresponding operations on the branch transaction through the compensation module and the retry module. Transaction orchestration is a module used to set the forward operation sequence of each branch transaction.

[0114] A distributed transaction management method provided in an embodiment of the present application is introduced above, and a system for executing the above distributed transaction management method will be introduced below.

[0115] See also Fig. 9 , Fig. 9 A schematic diagram of the structure of a distributed transaction management system provided in an embodiment of the present application. Fig. 9 As shown, the distributed transaction management system includes: a coordinator 901 and a branch strategy storage module 902,

[0116] The coordinator 901 is used to obtain the context of the target branch transaction included in the target global transaction;

[0117] The coordinator 901 is further used to obtain a branch transaction strategy that matches the context from the branch strategy storage module 902. The branch strategy storage module 902 stores a branch strategy configuration table. The branch strategy configuration table stores the context and the branch transaction strategy accordingly. The branch transaction strategy in the branch strategy configuration table includes at least: multiple compensation strategy, multiple retry strategy, termination compensation strategy, termination retry strategy, and transaction suspension strategy.

[0118] The coordinator 901 is further configured to execute operations corresponding to the obtained branch transaction strategy.

[0119] Optionally, the coordinator 901 that performs operations corresponding to the obtained branch transaction strategy is specifically configured to:

[0120] If the obtained branch transaction strategy is a multiple compensation strategy, a compensation operation is performed on the target branch transaction, and it is determined whether the compensation is successful. If the compensation fails, it is determined whether the number of compensation times for the target branch transaction is greater than the first target number. If not, it returns to the step of performing the compensation operation on the target branch transaction. If it is greater, the target branch transaction is suspended. If the compensation is successful, the compensation operation is continued on the branch transaction before the target branch transaction.

[0121] If the branch transaction strategy obtained is the termination compensation strategy, determine whether the forward operation of the target branch transaction is successful. If successful, stop performing the compensation operation on the target branch transaction and continue to perform the forward operation on the subsequent branch transactions of the target branch transaction. If the forward operation of the target branch transaction fails, continue to perform the compensation operation on the target branch transaction.

[0122] If the branch transaction strategy obtained is a multiple retry strategy, the target branch transaction is operated forward again, and it is determined whether this forward operation is successful. If it fails, it is determined whether the number of forward operations on the target branch transaction is greater than the second target number. If not, it returns to execute the step of performing the forward operation on the target branch transaction again. If it is greater, the target branch transaction is suspended. If this forward operation is successful, the forward operation continues to be performed on the branch transaction after the target branch transaction.

[0123] If the obtained branch transaction strategy is a termination retry strategy, the forward operation on the target branch transaction is stopped and a compensation operation is performed on the branch transaction before the target branch transaction.

[0124] If the obtained branch transaction strategy is a transaction suspension strategy, the target branch transaction is suspended, and after the target branch transaction is suspended, the compensation operation on the branch transaction before the target branch transaction is stopped.

[0125] Optionally, the context includes an error code. If the error code is an error code indicating network instability, the branch transaction strategy matching the context obtained by the coordinator 901 from the branch strategy storage module 902 is a multiple retry strategy;

[0126] If the error code is an error code indicating that the service is unavailable, the branch transaction strategy that matches the context and is obtained by the coordinator 901 from the branch strategy storage module 902 is a transaction suspension strategy.

[0127] The distributed transaction management system provided by the present application can provide multiple branch transaction strategies such as multiple compensation strategies, multiple retry strategies, termination compensation strategies, termination retry strategies, and transaction suspension strategies, and each branch transaction strategy has its own corresponding context. In this way, the present application can determine and execute the operations corresponding to the branch transaction strategy corresponding to the context according to the context of the target branch transaction. Through a variety of different branch transaction strategies, the present application can meet the needs of different businesses. At the same time, through the branch strategy configuration table, the present application can automatically execute matching operations according to the context, which is very convenient.

[0128] The present application also provides an electronic device in an embodiment. Fig.10As shown, it shows a schematic diagram of the structure of an electronic device suitable for implementing the embodiment of the present application. The electronic device in the embodiment of the present application may include but is not limited to fixed terminals such as mobile phones, laptops, PDAs (personal digital assistants), PADs (tablet computers), desktop computers, etc. Fig.10 The electronic device shown is merely an example and should not bring any limitation to the functions and scope of use of the embodiments of the present application.

[0129] like Fig.10 As shown, the electronic device may include a processing device (e.g., a central processing unit, a graphics processing unit, etc.) 601, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 602 or a program loaded from a storage device 608 to a random access memory (RAM) 603. When the electronic device is powered on, various programs and data required for the operation of the electronic device are also stored in the RAM 603. The processing device 601, the ROM 602, and the RAM 603 are connected to each other via a bus 604. An input / output (I / O) interface 605 is also connected to the bus 604.

[0130] Typically, the following devices may be connected to the I / O interface 605: an input device 606 including, for example, a touch screen, a touch pad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 607 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 608 including, for example, a memory card, a hard disk, etc.; and a communication device 609. The communication device 609 may allow the electronic device to communicate with other devices wirelessly or by wire to exchange data. Although Fig.10 An electronic device having various devices is shown, but it should be understood that it is not required to implement or possess all the devices shown. More or fewer devices may be implemented or possessed instead.

[0131] An embodiment of the present application also provides a computer program product including computer-readable instructions. When the computer-readable instructions are executed on an electronic device, the electronic device implements any distributed transaction management method provided in the embodiment of the present application.

[0132] A computer-readable storage medium is also provided in an embodiment of the present application. The storage medium carries one or more computer programs. When the one or more computer programs are executed by an electronic device, the electronic device can implement any distributed transaction management method provided in the embodiment of the present application.

[0133] It should also be noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the drawings of the device embodiments provided by the present application, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines.

[0134] Through the description of the above implementation mode, the technicians in the field can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course, it can also be implemented by special hardware including special integrated circuits, special CPUs, special memories, special components, etc. In general, all functions completed by computer programs can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be various, such as analog circuits, digital circuits or special circuits. However, for the present application, software program implementation is a better implementation mode in more cases. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer floppy disk, a U disk, a mobile hard disk, a ROM, a RAM, a disk or an optical disk, etc., including a number of instructions to enable a computer device (which can be a personal computer, a training device, or a network device, etc.) to execute the methods described in each embodiment of the present application.

[0135] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.

[0136] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a training device, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, training device, or data center. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.

Claims

1. A distributed transaction management method, characterized in that: include: The coordinator obtains the context of the target branch transaction included in the target global transaction; The coordinator obtains a branch transaction strategy matching the context from a branch strategy storage module, wherein the branch strategy storage module stores a branch strategy configuration table, wherein the context and the branch transaction strategy are correspondingly stored in the branch strategy configuration table, and the branch transaction strategy in the branch strategy configuration table includes at least: multiple compensation strategy, multiple retry strategy, termination compensation strategy, termination retry strategy and transaction suspension strategy; The coordinator performs an operation corresponding to the obtained branch transaction strategy.

2. The method according to claim 1, characterized in that The coordinator performs an operation corresponding to the obtained branch transaction strategy, including: If the branch transaction strategy obtained is a multiple compensation strategy, a compensation operation is performed on the target branch transaction, and it is determined whether the compensation is successful. If the compensation fails, it is determined whether the number of compensation times for the target branch transaction is greater than the first target number. If not, the step of performing the compensation operation on the target branch transaction is returned. If greater, the target branch transaction is suspended. If the compensation is successful, the compensation operation is continued on the branch transaction before the target branch transaction. and / or, If the branch transaction strategy obtained is a termination compensation strategy, determine whether the forward operation of the target branch transaction is successful. If successful, stop performing the compensation operation on the target branch transaction and continue to perform the forward operation on the subsequent branch transactions of the target branch transaction. If the forward operation of the target branch transaction fails, continue to perform the compensation operation on the target branch transaction.

3. The method according to claim 1, characterized in that The coordinator performs an operation corresponding to the obtained branch transaction strategy, including: If the branch transaction strategy obtained is a multiple retry strategy, the target branch transaction is forward operated again, and it is determined whether the forward operation is successful. If it fails, it is determined whether the number of forward operations on the target branch transaction is greater than the second target number. If it is not greater, it returns to the step of performing the forward operation on the target branch transaction again. If it is greater, the target branch transaction is suspended. If the forward operation is successful, the forward operation is continued on the branch transaction after the target branch transaction. and / or, If the branch transaction strategy obtained is a termination retry strategy, the forward operation on the target branch transaction is stopped and a compensation operation is performed on the branch transaction before the target branch transaction.

4. The method according to claim 1, characterized in that The coordinator performs an operation corresponding to the obtained branch transaction strategy, including: If the obtained branch transaction strategy is a transaction suspension strategy, the target branch transaction is suspended, and after the target branch transaction is suspended, the compensation operation on the branch transaction before the target branch transaction is stopped.

5. The method according to claim 1, characterized in that The context includes an error code. If the error code is an error code indicating network instability, the branch transaction strategy matching the context obtained by the coordinator from the branch strategy storage module is the multiple retry strategy; If the error code is an error code indicating that a service is unavailable, the branch transaction strategy that matches the context and is obtained by the coordinator from the branch strategy storage module is the transaction suspension strategy.

6. A distributed transaction management system, characterized in that: include: Coordinator and branch strategy storage modules, The coordinator is used to obtain the context of the target branch transaction included in the target global transaction; The coordinator is further used to obtain a branch transaction strategy matching the context from the branch strategy storage module, wherein the branch strategy storage module stores a branch strategy configuration table, wherein the context and the branch transaction strategy are correspondingly stored in the branch strategy configuration table, and the branch transaction strategy in the branch strategy configuration table includes at least: multiple compensation strategy, multiple retry strategy, termination compensation strategy, termination retry strategy and transaction suspension strategy; The coordinator is further configured to execute an operation corresponding to the obtained branch transaction strategy.

7. The system according to claim 6, characterized in that The coordinator that performs the operation corresponding to the obtained branch transaction strategy is specifically used to: If the branch transaction strategy obtained is a multiple compensation strategy, a compensation operation is performed on the target branch transaction, and it is determined whether the compensation is successful. If the compensation fails, it is determined whether the number of compensation times for the target branch transaction is greater than a first target number. If not, it returns to the step of performing the compensation operation on the target branch transaction. If greater, the target branch transaction is suspended. If the compensation is successful, continue to perform compensation operations on the branch transaction before the target branch transaction; If the branch transaction strategy obtained is a termination compensation strategy, determining whether the forward operation of the target branch transaction is successful; if successful, stopping the compensation operation on the target branch transaction and continuing to perform the forward operation on the subsequent branch transaction of the target branch transaction; if the forward operation of the target branch transaction fails, continuing to perform the compensation operation on the target branch transaction; If the branch transaction strategy obtained is a multiple retry strategy, then the target branch transaction is forward operated again, and it is determined whether the forward operation is successful. If it fails, it is determined whether the number of forward operations on the target branch transaction is greater than a second target number. If it is not greater, it returns to the step of performing the forward operation on the target branch transaction again. If it is greater, the target branch transaction is suspended. If the forward operation is successful, the forward operation is continued on the branch transaction after the target branch transaction; If the branch transaction strategy obtained is a termination retry strategy, then stopping the forward operation on the target branch transaction and performing a compensation operation on the branch transaction before the target branch transaction; If the obtained branch transaction strategy is a transaction suspension strategy, the target branch transaction is suspended, and after the target branch transaction is suspended, the compensation operation on the branch transaction before the target branch transaction is stopped.

8. A computer program product, characterized in that It comprises computer-readable instructions, and when the computer-readable instructions are executed on an electronic device, the electronic device implements the distributed transaction management method as claimed in any one of claims 1 to 5.

9. An electronic device, characterized in that: The method comprises at least one processor and a memory connected to the processor, wherein: The memory is used to store computer programs; The processor is used to execute the computer program so that the electronic device can implement the distributed transaction management method as described in any one of claims 1 to 5.

10. A computer storage medium, characterized in that: The storage medium carries one or more computer programs, and when the one or more computer programs are executed by an electronic device, the electronic device can implement the distributed transaction management method as described in any one of claims 1 to 5.