CN113778631A - Distributed transaction compensation method and device, electronic equipment and readable storage medium - Google Patents

Distributed transaction compensation method and device, electronic equipment and readable storage medium Download PDF

Info

Publication number
CN113778631A
CN113778631A CN202110132749.1A CN202110132749A CN113778631A CN 113778631 A CN113778631 A CN 113778631A CN 202110132749 A CN202110132749 A CN 202110132749A CN 113778631 A CN113778631 A CN 113778631A
Authority
CN
China
Prior art keywords
execution
service
compensation
transaction
created
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202110132749.1A
Other languages
Chinese (zh)
Inventor
李明昊
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Original Assignee
Beijing Jingdong Century Trading Co Ltd
Beijing Wodong Tianjun Information Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Beijing Jingdong Century Trading Co Ltd, Beijing Wodong Tianjun Information Technology Co Ltd filed Critical Beijing Jingdong Century Trading Co Ltd
Priority to CN202110132749.1A priority Critical patent/CN113778631A/en
Publication of CN113778631A publication Critical patent/CN113778631A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/466Transaction processing
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/23Updating
    • G06F16/2365Ensuring data consistency and integrity
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F16/00Information retrieval; Database structures therefor; File system structures therefor
    • G06F16/20Information retrieval; Database structures therefor; File system structures therefor of structured data, e.g. relational data
    • G06F16/27Replication, distribution or synchronisation of data between databases or within a distributed database system; Distributed database system architectures therefor
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/46Multiprogramming arrangements
    • G06F9/50Allocation of resources, e.g. of the central processing unit [CPU]
    • G06F9/5083Techniques for rebalancing the load in a distributed system

Landscapes

  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Software Systems (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Databases & Information Systems (AREA)
  • Data Mining & Analysis (AREA)
  • Computing Systems (AREA)
  • Computer Security & Cryptography (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The present disclosure provides a distributed transaction compensation method, including: when a business system executes a plurality of services according to a designated execution sequence, monitoring the execution states of the plurality of services, wherein the execution states comprise starting execution and failure in execution; when the execution state of the service is the starting execution state, creating a compensation transaction corresponding to the service; and when the execution state of the service is execution failure, acquiring the created compensation transactions, and sequentially sending the created compensation transactions to the service system according to the reverse order of the execution order. The present disclosure also provides a distributed transaction compensation apparatus, an electronic device, and a computer-readable storage medium.

Description

Distributed transaction compensation method and device, electronic equipment and readable storage medium
Technical Field
The present disclosure relates to the field of computer technologies, and in particular, to a distributed transaction compensation method and apparatus, an electronic device, and a computer-readable storage medium.
Background
Distributed transactions are a common transaction processing approach to achieve data consistency issues between different nodes in a distributed microservice architecture. The current implementation modes of distributed transaction mainly include the following: a two-phase commit transaction, a three-phase commit transaction, a compensation transaction, and so on. The two-phase commit transaction and the three-phase commit transaction utilize the XA protocol to implement commit or rollback of the transaction by way of the two-phase commit and the three-phase commit, respectively. The compensation transaction utilizes TCC protocol, and registers an operation of confirmation and compensation corresponding to the three processes of pre-processing (Try), confirmation (Confirm) and cancellation (Cancel) to realize the submission or rollback of the transaction.
In implementing the disclosed concept, the inventors found that there are at least the following problems in the related art: in most distributed architectures, recovery of data of an upstream service cannot be achieved when an anomaly occurs in the downstream service. Common solutions include implementation by modifying business execution logic, such as in a compensation transaction approach, which requires the developer to add a compensation algorithm during all three operations of each business branch, which increases the complexity of the business code. Also, for example, for two-phase and three-phase commit methods, locks may need to be applied to the application or database to ensure data consistency, which may significantly affect the performance of service execution.
Disclosure of Invention
In view of the above, the present disclosure provides a distributed transaction compensation method and apparatus for implementing isolation between transaction compensation logic and business transaction execution logic, and the transaction compensation process is lock-free and decoupled from the database.
One aspect of the present disclosure provides a distributed transaction compensation method, including:
when a business system executes a plurality of services according to a designated execution sequence, monitoring the execution states of the plurality of services, wherein the execution states comprise starting execution and failure in execution; when the execution state of the service is the starting execution state, creating a compensation transaction corresponding to the service; and when the execution state of the service is execution failure, acquiring the created compensation transactions, and sequentially sending the created compensation transactions to the service system according to the reverse order of the execution order.
According to an embodiment of the present disclosure, after the creating of the compensation transaction corresponding to the service when the execution state of the service is the start of execution, the method includes: and storing the compensation transactions in a pre-constructed compensation transaction stack according to the execution sequence.
According to an embodiment of the present disclosure, the creating a compensation transaction corresponding to the service when the execution state of the service is the start of execution includes: when the execution state of the service is the execution start state, acquiring the theme information of the service; based on the topic information, a compensation transaction corresponding to the service is created.
According to an embodiment of the present disclosure, the execution status includes a successful execution, the method further comprising: when the execution state of the service is successful, acquiring the context information of the service; determining whether the service is the last service executed in the execution order based on the context information; and if the service is the last service executed in the execution sequence, emptying the created compensation transaction.
According to an embodiment of the present disclosure, when the execution state of the service is an execution failure, acquiring the created compensation transactions, and sequentially sending the created compensation transactions to the service system according to a reverse order of the execution order, the method includes: when the execution state of the service is execution failure, acquiring the created compensation transaction; arranging the compensation transactions according to the execution sequence; and sending the arranged compensation affairs to the service system in sequence according to the reverse sequence of the execution sequence.
According to an embodiment of the present disclosure, when the execution state of the service is an execution failure, acquiring the created compensation transactions, and sequentially sending the created compensation transactions to the service system according to a reverse order of the execution order, the method includes: when the execution state of the service is execution failure, acquiring the times that the execution state of the service is execution failure; judging whether the times reach a threshold value; if the times are less than or equal to a threshold value, requesting the service system to execute the service again; and if the times are greater than a threshold value, sequentially sending the created compensation transactions to the service system according to the reverse sequence of the execution sequence.
According to the embodiment of the present disclosure, after acquiring the created compensation transactions and sequentially sending the created compensation transactions to the service system according to the reverse order of the execution order when the execution state of the service is failure, the method includes: and when the execution state of the service is execution failure, warning information is sent out.
Another aspect of the present disclosure provides a distributed transaction compensation apparatus, including: the system comprises a monitoring module, a processing module and a processing module, wherein the monitoring module is used for monitoring the execution states of a plurality of services when a business system executes the services according to a designated execution sequence, and the execution states comprise start and failure; the creating module is used for creating a compensation transaction corresponding to the service when the execution state of the service is the beginning; and the compensation module is used for acquiring the created compensation transactions when the execution state of the service is failure, and sequentially sending the created compensation transactions to the service system according to the reverse sequence of the execution sequence.
Another aspect of the present disclosure provides an electronic device comprising one or more processors; and memory for storing one or more programs, wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the method of any of the preceding claims.
Another aspect of the present disclosure provides a computer-readable storage medium storing computer-executable instructions for implementing the method as described above when executed.
According to the embodiment of the disclosure, because an independent transaction compensation device is utilized to monitor the execution process of the business system, a corresponding compensation transaction is created for each service, and the organized compensation transactions are utilized to perform reverse order compensation on the business system, the technical problem of how to compensate the distributed transactions on the premise of not modifying the business execution logic and not locking is at least partially overcome, and the technical effects of isolating the transaction compensation logic from the transaction execution logic, having no lock in the whole process of the transaction compensation process and being decoupled from the database are further achieved.
Drawings
The above and other objects, features and advantages of the present disclosure will become more apparent from the following description of embodiments of the present disclosure with reference to the accompanying drawings, in which:
FIG. 1 schematically illustrates an exemplary system architecture to which the disclosed method and apparatus for applying distributed transaction compensation may be applied;
FIG. 2 schematically illustrates a flow diagram of a distributed transaction compensation method according to an embodiment of the present disclosure;
fig. 3 schematically illustrates an application scenario of the distributed transaction compensation method and apparatus according to an embodiment of the present disclosure;
FIG. 4A schematically illustrates a flow diagram of a method of creating a compensation transaction according to an embodiment of the present disclosure;
FIG. 4B schematically illustrates a flow diagram of a method of sending compensation transactions, in accordance with an embodiment of the present disclosure;
FIG. 4C schematically illustrates a flow diagram of a method of sending a compensation transaction according to another embodiment of the present disclosure;
FIG. 4D schematically illustrates a flow diagram of a distributed transaction compensation method according to another embodiment of the present disclosure;
fig. 5 schematically illustrates a block diagram of a distributed transaction compensation arrangement according to an embodiment of the present disclosure;
FIG. 6A schematically illustrates a block diagram of a creation module according to an embodiment of the disclosure;
FIG. 6B schematically illustrates a block diagram of a compensation module according to an embodiment of the disclosure;
FIG. 6C schematically illustrates a block diagram of a compensation module according to another embodiment of the present disclosure;
fig. 6D schematically illustrates a block diagram of a distributed transaction compensation arrangement according to another embodiment of the present disclosure; and
fig. 7 schematically illustrates a block diagram of an electronic device suitable for implementing a robot in accordance with an embodiment of the disclosure.
Detailed Description
Hereinafter, embodiments of the present disclosure will be described with reference to the accompanying drawings. It should be understood that the description is illustrative only and is not intended to limit the scope of the present disclosure. In the following detailed description, for purposes of explanation, numerous specific details are set forth in order to provide a thorough understanding of the embodiments of the disclosure. It may be evident, however, that one or more embodiments may be practiced without these specific details. Moreover, in the following description, descriptions of well-known structures and techniques are omitted so as to not unnecessarily obscure the concepts of the present disclosure.
The terminology used herein is for the purpose of describing particular embodiments only and is not intended to be limiting of the disclosure. The terms "comprises," "comprising," and the like, as used herein, specify the presence of stated features, steps, operations, and/or components, but do not preclude the presence or addition of one or more other features, steps, operations, or components.
All terms (including technical and scientific terms) used herein have the same meaning as commonly understood by one of ordinary skill in the art unless otherwise defined. It is noted that the terms used herein should be interpreted as having a meaning that is consistent with the context of this specification and should not be interpreted in an idealized or overly formal sense.
Where a convention analogous to "at least one of A, B and C, etc." is used, in general such a construction is intended in the sense one having skill in the art would understand the convention (e.g., "a system having at least one of A, B and C" would include but not be limited to systems that have a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.). Where a convention analogous to "A, B or at least one of C, etc." is used, in general such a construction is intended in the sense one having skill in the art would understand the convention (e.g., "a system having at least one of A, B or C" would include but not be limited to systems that have a alone, B alone, C alone, a and B together, a and C together, B and C together, and/or A, B, C together, etc.).
Embodiments of the present disclosure provide a method for distributed transaction compensation and an apparatus to which the method can be applied. The method includes a monitoring process and a compensation process. In the monitoring process, when the service system executes a plurality of services according to a designated execution sequence, the execution states of the plurality of services are monitored, and the execution states comprise starting execution and failure in execution. When the execution state of the service is monitored as starting execution, a compensation transaction corresponding to the service is created. And when the execution state of the service is monitored to be execution failure, acquiring the created compensation affairs, and sequentially sending the created compensation affairs to the service system according to the reverse sequence of the execution sequence.
Fig. 1 schematically illustrates an exemplary system architecture 100 to which the methods and apparatus for distributed transaction compensation may be applied, according to an embodiment of the disclosure. It should be noted that fig. 1 is only an example of a system architecture to which the embodiments of the present disclosure may be applied to help those skilled in the art understand the technical content of the present disclosure, and does not mean that the embodiments of the present disclosure may not be applied to other devices, systems, environments or scenarios.
As shown in fig. 1, the system architecture 100 according to this embodiment may include terminal devices 101, 102, 103, a network 104 and a server 105. The network 104 serves as a medium for providing communication links between the terminal devices 101, 102, 103 and the server 105. Network 104 may include various connection types, such as wired and/or wireless communication links, and so forth.
The user may use the terminal devices 101, 102, 103 to interact with the server 105 via the network 104 to receive or send messages or the like. The terminal devices 101, 102, 103 may have installed thereon various communication client applications, such as a shopping-like application, a web browser application, a search-like application, an instant messaging tool, a mailbox client, and/or social platform software, etc. (by way of example only).
The terminal devices 101, 102, 103 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop portable computers, desktop computers, and the like.
The server 105 may be a server providing various services, such as a background management server (for example only) providing support for websites browsed by users using the terminal devices 101, 102, 103. The background management server may analyze and perform other processing on the received data such as the user request, and feed back a processing result (e.g., a webpage, information, or data obtained or generated according to the user request) to the terminal device.
It should be noted that the distributed transaction compensation method provided by the embodiment of the present disclosure may be generally executed by the server 105. Accordingly, the distributed transaction compensation apparatus provided by the embodiments of the present disclosure may be generally disposed in the server 105. The distributed transaction compensation method provided by the embodiments of the present disclosure may also be performed by a server or a server cluster that is different from the server 105 and is capable of communicating with the terminal devices 101, 102, 103 and/or the server 105. Accordingly, the distributed transaction compensation apparatus provided by the embodiment of the present disclosure may also be disposed in a server or a server cluster different from the server 105 and capable of communicating with the terminal devices 101, 102, 103 and/or the server 105. Alternatively, the distributed transaction compensation method provided by the embodiment of the present disclosure may also be executed by the terminal device 101, 102, or 103, or may also be executed by another terminal device different from the terminal device 101, 102, or 103. Accordingly, the distributed transaction compensation apparatus provided by the embodiment of the present disclosure may also be disposed in the terminal device 101, 102, or 103, or in another terminal device different from the terminal device 101, 102, or 103.
For example, the execution state of the service system is monitored in any one of the terminal devices 101, 102, or 103 (for example, the terminal device 101, but not limited thereto), or the execution state of the service system is monitored on an external device and the monitoring result is imported into the terminal device 101. Then, the terminal device 101 may locally execute the distributed transaction compensation method provided by the embodiment of the present disclosure, or send the monitoring result to another terminal device, a server, or a server cluster, and the other terminal device, the server, or the server cluster that receives the monitoring result executes the distributed transaction compensation method provided by the embodiment of the present disclosure.
It should be understood that the number of terminal devices, networks, and servers in fig. 1 is merely illustrative. There may be any number of terminal devices, networks, and servers, as desired for implementation.
Fig. 2 schematically shows a flow chart of a distributed transaction compensation method according to an embodiment of the present disclosure.
As shown in fig. 2, the method includes operations S201 to S203.
In operation S201, when the service system executes a plurality of services in a designated execution order, execution states of the plurality of services are monitored, the execution states including start of execution and execution failure.
In operation S202, when the execution state of the service is the start of execution, a compensation transaction corresponding to the service is created.
In operation S203, when the execution state of the service is an execution failure, the created compensation transactions are acquired, and the created compensation transactions are sequentially sent to the service system according to a reverse order of the execution order.
In an embodiment of the present disclosure, a business system is a system that handles distributed transactions. Services performed in a business system refer to programs, routines, or processes that perform specified system functions. For example, after receiving a shopping order placement request, service a needs to call service B to pay, if the payment is successful, the shopping order is processed to be in a to-be-issued state, otherwise, the shopping order needs to be processed to be in a failed state. In the actual payment process, it may happen that service B has successfully performed payment, but service a is not notified due to a network call problem, resulting in the user paying money, but the shopping order still shows a status of non-payment success. To protect the user's rights from being compromised, the above problem can be generally solved by a distributed transaction, i.e. combining service a and service B into one transaction. After the service B completes the payment, the service B needs to send a network request to the service A, and if the service A does not successfully receive the payment completion message, the order placing is determined to be failed and the payment process is finished. In this distributed transaction, the transaction is required to be either all successful or all rollback to ensure data consistency between different nodes. Wherein, the service A for executing the ordering request and the service B for executing the payment request are carried out in different distributed nodes.
The distributed transaction compensation device monitors the execution process of the business system, obtains the execution state of each service, and does not participate in the original execution process of the business system. Understandably, the distributed transaction compensation device of the present disclosure is a third party device, and the executed compensation logic is isolated from the business logic executed by the business system. The device does not modify the original service logic of the service system in the compensation process.
The execution state of the service includes the start of execution, the end of execution, the success of execution, the failure of execution, and the like of the service. When service A begins execution, a compensation transaction A' corresponding to service A is created. When service B starts executing, a compensation transaction B' corresponding to service B is created. The service system executes the services in sequence according to the execution sequence in the service execution logic, and the compensation device also creates corresponding compensation transactions according to the same execution sequence. If the compensation device monitors the information that the service B fails to execute, the compensation device acquires the created compensation affair A 'and the created compensation affair B', and then sequentially sends the compensation affair A 'and the compensation affair B' to the service system according to the reverse sequence of the execution sequence, namely, the compensation affair B 'is sent to the service system first, and then the compensation affair A' is sent. In particular, the compensation process includes clearing the service's associated data, and recovering the service's data through the sent compensation transaction.
Fig. 3 schematically illustrates an application scenario of the distributed transaction compensation method and apparatus according to an embodiment of the present disclosure.
As shown in fig. 3, the services are executed in the service flow queue in sequence according to the designated service execution sequence, and the present apparatus monitors the execution state of each service. When the execution state of a certain service is execution failure, the compensation transactions stored in the compensation transaction stack are sent to the business system in a reverse order according to a rule of 'first-in and last-out' so as to complete transaction compensation.
Understandably, service 1, service 2, and service 3 constitute a distributed transaction. In the execution logic, the service 2 needs to acquire the execution result of the service 1 before the execution can be started, and the service 3 needs to acquire the execution result of the service 2 before the execution can be started. Therefore, if the data of the service 1 is emptied first in the compensation process and the transaction compensation is performed on the data, the problems of system downtime and the like caused by data loss of the subsequently executed services 2 and 3 occur. To ensure proper execution, the services must be transaction compensated in reverse order.
Specifically, in order to ensure that the compensation transactions can be correctly and sequentially sent to the service system according to the reverse order of the execution order, a compensation transaction stack may be pre-constructed, and the created compensation transactions are stored in the compensation transaction stack. The stack is a linear table with limited operation, and because the stack can only perform operations such as insertion and deletion at the tail of the table, the created compensation transaction is stored in the monitoring process by using the characteristics of the stack. When the compensation affair is sent to the service system, the process of 'first-in last-out' of the compensation affair is realized.
In the embodiment of the present disclosure, a developer may also construct a specific list in advance, and define a manner of adding/deleting data to/from the list according to actual requirements. The services are sequentially executed in the forward list, the compensation transaction is stored in the reverse list, and the reverse order compensation can be accurately realized in the compensation process.
Preferably, the service execution process and the transaction compensation process can be completed in different interfaces, thereby realizing the isolation of the service execution logic and the transaction compensation logic and simplifying the transaction compensation process. In the transaction compensation process, the compensation transaction is directly acquired through a compensation interface without modifying the multi-phase operation executed by the service, and the data of the whole service is compensated.
In the embodiment of the present disclosure, after performing transaction compensation on the service system, if the service still has the problem of execution failure, the device may send a warning message indicating that the problem of current execution failure cannot be solved by sending the compensation transaction, and it is necessary to request manual intervention to check and correct the error of current service execution.
By the embodiment of the disclosure, the transaction arrangement and the transaction compensation are combined, and a compensation mechanism for the distributed transaction is realized. In a distributed service framework, transaction compensation is asynchronously executed, compensation transactions are arranged in the device by a compensation device, the arranged compensation transactions are sequentially sent to a service system, so that the compensation process does not need to acquire related information from a database, decoupling with the database is realized, no lock exists in the whole process, service logic and transaction logic are decoupled through different interfaces, the compensation process is simplified, and the influence on service execution performance is reduced.
The method shown in fig. 2 is further described with reference to fig. 4A-4D in conjunction with specific embodiments.
Fig. 4A schematically illustrates a flow chart of a method of creating a compensation transaction according to an embodiment of the present disclosure.
As shown in fig. 4A, when the execution state of the service is the start of execution, a compensation transaction corresponding to the service is created, including operations S301 to S302;
in operation S301, when the execution state of the service is the start of execution, topic information of the service is acquired.
In operation S302, a compensation transaction corresponding to the service is created based on the topic information.
In the embodiment of the present disclosure, the topic information of the service is topic of the service. When the execution of the service is monitored, the topic of the service is obtained, namely the identifier of the service is obtained, and a compensation transaction corresponding to the service is created based on the topic of the service. For example, service a is a get order request and service B is a get payment request. When the fact that the service A starts executing is monitored, the topic of the service A is acquired as 'initiating order', and a compensation transaction of 'initiating order' is created. When the execution of the service B is monitored, the topic of the service B is acquired as 'initiate payment', and a compensation transaction of 'initiate payment' is created. The compensation transaction includes data information such as a service name of a corresponding service and an input parameter of the service.
And in the compensation process, sending a corresponding compensation transaction for each service through topic of each service and compensation transaction, and compensating corresponding service data. According to the embodiment of the disclosure, the corresponding relation between the service and the compensation transaction is determined according to the topic information, and the compensation transaction corresponding to each service is accurately determined and the transaction compensation is completed during the transaction compensation.
Fig. 4B schematically illustrates a flow diagram of a method of sending a compensation transaction according to an embodiment of the disclosure.
As shown in fig. 4B, when the execution state of the service is an execution failure, the created compensation transactions are obtained, and the created compensation transactions are sequentially sent to the service system according to a reverse order of the execution order, including operations S303 to S305;
in operation S303, when the execution status of the service is execution failure, the created compensation transaction is acquired.
In operation S304, the compensation transactions are scheduled in execution order.
In operation S305, the scheduled compensation transactions are sequentially transmitted to the service system in a reverse order of the execution order.
In the embodiment of the present disclosure, in order to ensure data consistency and service execution process data integrity, the orchestration process of the compensation transaction needs to be completed before the compensation transaction is sent to the service system. Alternatively, the compensation transactions may be sequentially stored in the compensation transaction stack after the creation of the compensation transactions is completed, so as to implement the arrangement of the compensation transactions. The compensation affairs can also be stored in a common list, the created compensation affairs are arranged according to the appointed execution sequence before the compensation affairs are sent to the service system, and then the arranged compensation affairs are sent to the service system in sequence according to the reverse sequence of the execution sequence, so that the complexity of the storage process of the compensation affairs is reduced.
Fig. 4C schematically illustrates a flow chart of a method of sending a compensation transaction according to an embodiment of the disclosure.
As shown in fig. 4C, when the execution state of the service is an execution failure, the created compensation transactions are obtained, and the created compensation transactions are sequentially sent to the service system according to a reverse order of the execution order, including operations S306 to S309;
in operation S306, when the execution status of the service is an execution failure, the number of times the execution status of the service occurs as the execution failure is acquired.
In operation S307, it is determined whether the number of times reaches the threshold, and if the number of times is less than or equal to the threshold, operation S308 is performed; if the number of times is greater than the threshold value, operation S309 is performed.
In operation S308, the business system is requested to re-execute the service.
In operation S309, the created compensation transactions are sequentially transmitted to the service system in a reverse order of the execution order.
In the disclosed embodiments, the compensation types generally include forward compensation and backward compensation. The forward compensation is to retry the failed service and the backward compensation is to compensate by compensating the transaction. When the execution state of the service is monitored to be execution failure, and the caused reasons can be external factors such as network instability, server instability and the like, forward compensation is preferentially carried out on the service, the problem of execution failure caused by network disconnection and the like is avoided, the sending compensation transaction is executed, the execution unnecessary workload is reduced, and the working performance is improved.
Generally, the threshold value may be set to three times. After the service retries for three times, the service still has the state of execution failure, the reason of execution failure caused by network problems can be eliminated, and then transaction compensation is carried out on the service. Further reducing unnecessary operation and improving compensation efficiency. The threshold value of the retry can be set by one skilled in the art according to actual requirements, and the specific value of the threshold value is not limited by the disclosure.
Fig. 4D schematically illustrates a flow diagram of a distributed transaction compensation method according to another embodiment of the present disclosure.
As shown in FIG. 4D, the execution status includes successful execution, and the method includes operations S310-S312;
in operation S310, when the execution status of the service is execution success, context information of the service is acquired.
In operation S311, it is determined whether the service is the last service executed in the execution order based on the context information.
In operation S312, if the service is the last service executed in the execution order, the created compensation transaction is cleared.
In the embodiment of the present disclosure, the context information of the service mainly includes names of other sub-services on which the service is invoked. And judging whether the service is the most one executed in the execution sequence or not through the context information of the service, namely judging whether the service executed subsequently still exists after the service is executed successfully. If there is no subsequently performed service, the compensation transaction is flushed. When the last service is successfully executed, the distributed transaction may be considered to have been successfully executed. At this time, the created compensation transaction does not need to be called any more, and the created compensation transaction is emptied in order to improve the effective utilization rate of the storage space.
Through the embodiment of the disclosure, after each service is successfully executed, whether the subsequent service exists is judged, so that the storage space of the device is reasonably planned, and the operation efficiency of the device is improved.
Fig. 5 schematically shows a block diagram of a distributed transaction compensation arrangement according to an embodiment of the present disclosure.
As shown in fig. 5, the distributed transaction compensation apparatus 400 includes a monitoring module 410, a creation module 420, and a compensation module 430.
A monitoring module 410, configured to monitor execution states of the multiple services when the business system executes the multiple services according to a specified execution order, where the execution states include start and failure;
a creating module 420, configured to create a compensation transaction corresponding to the service when the execution state of the service is start;
and the compensation module 430 is configured to, when the execution state of the service is failure, obtain the created compensation transactions, and sequentially send the created compensation transactions to the service system according to a reverse order of the execution order.
Any number of modules, sub-modules, units, sub-units, or at least part of the functionality of any number thereof according to embodiments of the present disclosure may be implemented in one module. Any one or more of the modules, sub-modules, units, and sub-units according to the embodiments of the present disclosure may be implemented by being split into a plurality of modules. Any one or more of the modules, sub-modules, units, sub-units according to embodiments of the present disclosure may be implemented at least in part as a hardware circuit, such as a Field Programmable Gate Array (FPGA), a Programmable Logic Array (PLA), a system on a chip, a system on a substrate, a system on a package, an Application Specific Integrated Circuit (ASIC), or may be implemented in any other reasonable manner of hardware or firmware by integrating or packaging a circuit, or in any one of or a suitable combination of software, hardware, and firmware implementations. Alternatively, one or more of the modules, sub-modules, units, sub-units according to embodiments of the disclosure may be at least partially implemented as a computer program module, which when executed may perform the corresponding functions.
For example, any number of the monitoring module 410, the creation module 420, and the compensation module 430 may be combined in one module/unit/sub-unit to be implemented, or any one of the modules/units/sub-units may be split into a plurality of modules/units/sub-units. Alternatively, at least part of the functionality of one or more of these modules/units/sub-units may be combined with at least part of the functionality of other modules/units/sub-units and implemented in one module/unit/sub-unit. According to an embodiment of the present disclosure, at least one of the monitoring module 410, the creating module 420, and the compensating module 430 may be implemented at least in part as a hardware circuit, such as a Field Programmable Gate Array (FPGA), a Programmable Logic Array (PLA), a system on a chip, a system on a substrate, a system on a package, an Application Specific Integrated Circuit (ASIC), or may be implemented in hardware or firmware in any other reasonable manner of integrating or packaging a circuit, or in any one of or a suitable combination of software, hardware, and firmware. Alternatively, at least one of the monitoring module 410, the creation module 420 and the compensation module 430 may be at least partially implemented as a computer program module, which when executed may perform the respective functions.
FIG. 6A schematically shows a block diagram of a creation module according to an embodiment of the disclosure. In the embodiment of the present disclosure, the creating module 420 includes a first obtaining unit 4201, configured to obtain subject information of the service when the execution state of the service is the start of execution. A creating unit 4202 is configured to create a compensation transaction corresponding to the service based on the topic information.
Fig. 6B schematically illustrates a block diagram of a compensation module according to an embodiment of the disclosure. In the embodiment of the present disclosure, the compensation module 430 includes a second obtaining unit 4301, configured to obtain the created compensation transaction when the execution status of the service is execution failure. An orchestration unit 4302 is used to orchestrate the compensation transactions according to the execution order. The first sending unit 4303 sends the scheduled compensation transactions to the service system in sequence according to the reverse order of the execution order.
Fig. 6C schematically illustrates a block diagram of a compensation module according to another embodiment of the present disclosure. In the embodiment of the present disclosure, the compensation module 430 includes a third obtaining unit 4304, configured to obtain, when the execution state of the service is an execution failure, the number of times that the execution state of the service is the execution failure. A first judgment unit 4305, configured to judge whether the number of times reaches a threshold. A requesting unit 4306, configured to request the service system to re-execute the service if the number of times is smaller than or equal to the threshold. A second sending unit 4307, configured to send the created compensation transactions to the service system in sequence according to a reverse order of the execution order if the number of times is greater than the threshold.
Fig. 6D schematically illustrates a block diagram of a distributed transaction compensation apparatus according to another embodiment of the present disclosure. In this embodiment of the present disclosure, the distributed transaction compensation apparatus 400 further includes a fourth obtaining unit 4401, configured to obtain context information of the service when the execution state of the service is that the execution is successful. A second determining unit 4402 is configured to determine whether the service is the last service executed in the execution order based on the context information. A clearing unit 4403, configured to clear the created compensation transaction if the service is the last service executed in the execution order.
It should be noted that, the distributed transaction compensation apparatus portion in the embodiment of the present disclosure corresponds to the distributed transaction compensation method portion in the embodiment of the present disclosure, and the description of the distributed transaction compensation apparatus portion specifically refers to the distributed transaction compensation method portion, which is not described herein again.
Fig. 7 schematically shows a block diagram of an electronic device adapted to implement the above described method according to an embodiment of the present disclosure. The electronic device shown in fig. 7 is only an example, and should not bring any limitation to the functions and the scope of use of the embodiments of the present disclosure.
As shown in fig. 7, an electronic device 500 according to an embodiment of the present disclosure includes a processor 501 that can perform various appropriate actions and processes according to a program stored in a Read Only Memory (ROM)502 or a program loaded from a storage section 508 into a Random Access Memory (RAM) 503. The processor 501 may comprise, for example, a general purpose microprocessor (e.g., a CPU), an instruction set processor and/or associated chipset, and/or a special purpose microprocessor (e.g., an Application Specific Integrated Circuit (ASIC)), among others. The processor 501 may also include onboard memory for caching purposes. Processor 501 may include a single processing unit or multiple processing units for performing different actions of a method flow according to embodiments of the disclosure.
In the RAM 503, various programs and data necessary for the operation of the system 500 are stored. The processor 501, the ROM 502, and the RAM 503 are connected to each other by a bus 504. The processor 501 performs various operations of the method flows according to the embodiments of the present disclosure by executing programs in the ROM 502 and/or the RAM 503. Note that the programs may also be stored in one or more memories other than the ROM 502 and the RAM 503. The processor 501 may also perform various operations of method flows according to embodiments of the present disclosure by executing programs stored in the one or more memories.
According to an embodiment of the present disclosure, system 500 may also include an input/output (I/O) interface 505, input/output (I/O) interface 505 also being connected to bus 504. The system 500 may also include one or more of the following components connected to the I/O interface 505: an input portion 506 including a keyboard, a mouse, and the like; an output portion 507 including a display such as a Cathode Ray Tube (CRT), a Liquid Crystal Display (LCD), and the like, and a speaker; a storage portion 508 including a hard disk and the like; and a communication section 509 including a network interface card such as a LAN card, a modem, or the like. The communication section 509 performs communication processing via a network such as the internet. The driver 510 is also connected to the I/O interface 505 as necessary. A removable medium 511 such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, or the like is mounted on the drive 510 as necessary, so that a computer program read out therefrom is mounted into the storage section 508 as necessary.
According to embodiments of the present disclosure, method flows according to embodiments of the present disclosure may be implemented as computer software programs. For example, embodiments of the present disclosure include a computer program product comprising a computer program embodied on a computer readable storage medium, the computer program containing program code for performing the method illustrated by the flow chart. In such an embodiment, the computer program may be downloaded and installed from a network through the communication section 509, and/or installed from the removable medium 511. The computer program, when executed by the processor 501, performs the above-described functions defined in the system of the embodiments of the present disclosure. The systems, devices, apparatuses, modules, units, etc. described above may be implemented by computer program modules according to embodiments of the present disclosure.
The present disclosure also provides a computer-readable storage medium, which may be contained in the apparatus/device/system described in the above embodiments; or may exist separately and not be assembled into the device/apparatus/system. The computer-readable storage medium carries one or more programs which, when executed, implement the method according to an embodiment of the disclosure.
According to an embodiment of the present disclosure, the computer-readable storage medium may be a non-volatile computer-readable storage medium. Examples may include, but are not limited to: a portable computer diskette, a hard disk, a Random Access Memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing. In the present disclosure, a computer readable storage medium may be any tangible medium that can contain, or store a program for use by or in connection with an instruction execution system, apparatus, or device.
For example, according to embodiments of the present disclosure, a computer-readable storage medium may include ROM 502 and/or RAM 503 and/or one or more memories other than ROM 502 and RAM 503 described above.
The flowchart and block diagrams in the figures illustrate the architecture, functionality, and operation of possible implementations of systems, methods and computer program products according to various embodiments of the present disclosure. In this regard, each block in the flowchart or block diagrams may represent a module, segment, or portion of code, which comprises one or more executable instructions for implementing the specified logical function(s). It should also be noted that, in some alternative implementations, the functions noted in the block may occur out of the order noted in the figures. For example, two blocks shown in succession may, in fact, be executed substantially concurrently, or the blocks may sometimes be executed in the reverse order, depending upon the functionality involved. It will also be noted that each block of the block diagrams or flowchart illustration, and combinations of blocks in the block diagrams or flowchart illustration, can be implemented by special purpose hardware-based systems which perform the specified functions or acts, or combinations of special purpose hardware and computer instructions.
Those skilled in the art will appreciate that various combinations and/or combinations of features recited in the various embodiments and/or claims of the present disclosure can be made, even if such combinations or combinations are not expressly recited in the present disclosure. In particular, various combinations and/or combinations of the features recited in the various embodiments and/or claims of the present disclosure may be made without departing from the spirit or teaching of the present disclosure. All such combinations and/or associations are within the scope of the present disclosure.
The embodiments of the present disclosure have been described above. However, these examples are for illustrative purposes only and are not intended to limit the scope of the present disclosure. Although the embodiments are described separately above, this does not mean that the measures in the embodiments cannot be used in advantageous combination. The scope of the disclosure is defined by the appended claims and equivalents thereof. Various alternatives and modifications can be devised by those skilled in the art without departing from the scope of the present disclosure, and such alternatives and modifications are intended to be within the scope of the present disclosure.

Claims (10)

1. A distributed transaction compensation method, comprising:
when a business system executes a plurality of services according to a designated execution sequence, monitoring the execution states of the plurality of services, wherein the execution states comprise starting execution and failure in execution;
when the execution state of the service is the starting execution state, creating a compensation transaction corresponding to the service;
and when the execution state of the service is execution failure, acquiring the created compensation transactions, and sequentially sending the created compensation transactions to the service system according to the reverse order of the execution order.
2. The method of claim 1, wherein after the creating of the compensation transaction corresponding to the service when the execution state of the service is to start execution, comprising:
and storing the compensation transactions in a pre-constructed compensation transaction stack according to the execution sequence.
3. The method of claim 1, wherein the creating a compensation transaction corresponding to the service when the execution state of the service is to begin execution comprises:
when the execution state of the service is the execution start state, acquiring the theme information of the service;
based on the topic information, a compensation transaction corresponding to the service is created.
4. The method of claim 1, the execution status comprising a successful execution, wherein the method further comprises:
when the execution state of the service is successful, acquiring the context information of the service;
determining whether the service is the last service executed in the execution order based on the context information;
and if the service is the last service executed in the execution sequence, emptying the created compensation transaction.
5. The method of claim 1, wherein when the execution state of the service is an execution failure, acquiring the created compensation transactions, and sequentially sending the created compensation transactions to the service system according to a reverse order of the execution order, the method comprises:
when the execution state of the service is execution failure, acquiring the created compensation transaction;
arranging the compensation transactions according to the execution sequence;
and sending the arranged compensation affairs to the service system in sequence according to the reverse sequence of the execution sequence.
6. The method of claim 1, wherein when the execution state of the service is an execution failure, acquiring the created compensation transactions, and sequentially sending the created compensation transactions to the service system according to a reverse order of the execution order, the method comprises:
when the execution state of the service is execution failure, acquiring the times that the execution state of the service is execution failure;
judging whether the times reach a threshold value;
if the times are less than or equal to a threshold value, requesting the service system to execute the service again;
and if the times are greater than a threshold value, sequentially sending the created compensation transactions to the service system according to the reverse sequence of the execution sequence.
7. The method of claim 1, wherein after acquiring the created compensation transactions and sequentially sending the created compensation transactions to the business system in a reverse order of the execution order when the execution state of the service is failure, the method comprises:
and when the execution state of the service is execution failure, warning information is sent out.
8. A distributed transaction compensation apparatus, comprising:
the system comprises a monitoring module, a processing module and a processing module, wherein the monitoring module is used for monitoring the execution states of a plurality of services when a business system executes the services according to a designated execution sequence, and the execution states comprise start and failure;
the creating module is used for creating a compensation transaction corresponding to the service when the execution state of the service is the beginning;
and the compensation module is used for acquiring the created compensation transactions when the execution state of the service is failure, and sequentially sending the created compensation transactions to the service system according to the reverse sequence of the execution sequence.
9. An electronic device, comprising:
one or more processors;
a memory for storing one or more programs,
wherein the one or more programs, when executed by the one or more processors, cause the one or more processors to implement the method of any of claims 1-7.
10. A computer readable storage medium having stored thereon executable instructions which, when executed by a processor, cause the processor to carry out the method of any one of claims 1 to 7.
CN202110132749.1A 2021-01-29 2021-01-29 Distributed transaction compensation method and device, electronic equipment and readable storage medium Pending CN113778631A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110132749.1A CN113778631A (en) 2021-01-29 2021-01-29 Distributed transaction compensation method and device, electronic equipment and readable storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110132749.1A CN113778631A (en) 2021-01-29 2021-01-29 Distributed transaction compensation method and device, electronic equipment and readable storage medium

Publications (1)

Publication Number Publication Date
CN113778631A true CN113778631A (en) 2021-12-10

Family

ID=78835694

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110132749.1A Pending CN113778631A (en) 2021-01-29 2021-01-29 Distributed transaction compensation method and device, electronic equipment and readable storage medium

Country Status (1)

Country Link
CN (1) CN113778631A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114024999A (en) * 2022-01-10 2022-02-08 中航信移动科技有限公司 Task compensation method, system, device, electronic equipment and storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114024999A (en) * 2022-01-10 2022-02-08 中航信移动科技有限公司 Task compensation method, system, device, electronic equipment and storage medium

Similar Documents

Publication Publication Date Title
CN111277639A (en) Method and device for maintaining data consistency
CN113110963A (en) Service processing method, service processing device, electronic equipment and readable storage medium
CN112068973A (en) Asynchronous information processing method and device of policy mode, server and storage medium
WO2023226627A1 (en) Order information management method, apparatus and system, and electronic device and storage medium
CN111127181A (en) Voucher bookkeeping method and device
CN110223179B (en) Data processing method, device, system and medium for fund
CN112288577A (en) Transaction processing method and device for distributed service, electronic equipment and medium
CN114827280A (en) Request processing method, device, equipment and medium
CN113778631A (en) Distributed transaction compensation method and device, electronic equipment and readable storage medium
CN112825525B (en) Method and apparatus for processing transactions
CN113132400A (en) Business processing method, device, computer system and storage medium
CN113778699A (en) Distributed transaction processing method, device, computer system and readable storage medium
CN116166390A (en) Service processing method and device, electronic equipment and storage medium
CN116302271A (en) Page display method and device and electronic equipment
CN112953769B (en) Data transmission method, device, computer system and readable storage medium
CN115934378A (en) Service data processing method and device, electronic equipment and storage medium
CN115374098A (en) High concurrent payment order anti-duplication method, apparatus, system, device, medium, and program product
CN116503005A (en) Method, device, system and storage medium for dynamically modifying flow
CN113781154A (en) Information rollback method, system, electronic equipment and storage medium
CN115250276A (en) Distributed system and data processing method and device
US9092779B2 (en) Heuristics processing
CN109840073B (en) Method and device for realizing business process
CN114793232B (en) Service processing method, device, electronic equipment and storage medium
CN112150126A (en) Information processing method, information processing apparatus, electronic device, and medium
CN110430256B (en) Method, device and computer system for pushing transaction message

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination