Transaction rollback method and system in distributed scenario and electronic device

By generating and storing operation rollback parameters in thread variables in a distributed scenario, independent transaction rollback is achieved, which solves the problem that transaction rollback in the existing technology depends on middleware or specific databases, improves the applicability of transaction rollback and reduces system performance consumption.

CN116955381BActive Publication Date: 2026-04-14广域铭岛数字科技有限公司 +1
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-07-28
Publication Date
2026-04-14

AI Technical Summary

Technical Problem

In distributed scenarios, existing technologies cannot achieve independent transaction rollback, resulting in a limited scope of application for transaction rollback and high system performance consumption due to reliance on middleware or specific databases.

Method used

By obtaining the results of the transaction request's interface call, the operation rollback parameters are generated and stored in the thread variable of the transaction thread. The transaction rollback is performed using the thread variable, independent of the middleware or a specific server.

Benefits of technology

It enables independent transaction rollback in distributed scenarios, improves the applicability of transaction rollback, reduces system performance consumption, and avoids the need for database locking.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN116955381B_ABST
    Figure CN116955381B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of transaction rollback, and discloses a transaction rollback method and system in a distributed scenario and electronic equipment, the method receives operation results corresponding to each interface calling operation after each interface calling operation of a transaction request is executed, and when the operation result corresponding to a target operation includes operation success, stores operation rollback parameters corresponding to the target operation in a thread variable of a transaction thread, so that when the execution of the transaction request is aborted, the transaction request is subjected to transaction rollback according to the operation rollback parameters in the thread variable, the operation rollback parameters are established according to the interface calling operations that have been completed, the operation rollback parameters are stored through the thread variable, and the transaction is subjected to transaction rollback according to the operation rollback parameters stored in the thread variable, independent transaction rollback of the distributed scenario is realized, the transaction rollback no longer depends on a middleware or a specific server, and therefore the application range of the transaction rollback is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of transaction rollback technology, and in particular to a transaction rollback method, system and electronic device in a distributed scenario. Background Technology

[0002] In distributed environments, because a transaction is a set of logically combined units of work, transaction operations often rely on multiple different service interfaces. In the event of an exception, it's necessary to roll back the transactions across these different service interfaces, restoring the services and database to their state before the transaction began, thus maintaining consistency. For example, in a banking application transferring funds from one account to another, one account credits a certain amount to a database table, while another account debits the same amount to a different database table. Since computers may fail due to power outages, network interruptions, etc., it's possible that rows in one table are updated but not in another. If the database supports transactions, database operations can be grouped into a single transaction to prevent inconsistencies caused by such events. If a failure occurs at some point within the transaction, all updates can be rolled back to the state before the transaction began. If no failure occurs, the updates are completed by committing the transaction in a finished state.

[0003] Currently, transaction rollback typically employs two methods: one is to use additional event rollback middleware for event rollback, and the other relies on a specific database that supports transaction rollback protocols. For example, the XA protocol specifies the communication interface between the Transaction Manager (TM) and the Resource Manager (RM), forming a bidirectional communication bridge between the TM and multiple RMs, thereby guaranteeing the four properties of atomicity (or indivisibility), consistency, isolation (or independence), and durability across multiple database resources.

[0004] However, since transaction rollback depends on middleware or a specific database as an execution condition, additional deployment is required for distributed scenarios. Distributed scenarios cannot perform transaction rollback independently, resulting in a limited scope of application for transaction rollback. Summary of the Invention

[0005] To provide a basic understanding of some aspects of the disclosed embodiments, a brief summary is given below. This summary is not intended as a general commentary, nor is it intended to identify key / important components or describe the scope of protection of these embodiments, but rather as a prelude to the detailed description that follows.

[0006] In view of the shortcomings of the prior art described above, the present invention discloses a transaction rollback method, system and electronic device in a distributed scenario, so as to realize independent transaction rollback in a distributed scenario, thereby improving the applicability of transaction rollback.

[0007] This invention provides a transaction rollback method in a distributed scenario, comprising: obtaining a transaction request, wherein the transaction request includes multiple interface call operations; executing each interface call operation of the transaction request according to a preset transaction thread, and receiving the operation results corresponding to each interface call operation; if the operation result corresponding to the target operation includes operation success, generating operation rollback parameters according to the target operation, and storing the operation rollback parameters in the thread variable of the transaction thread, wherein the target operation is any interface call operation; if the execution of the transaction request is aborted, performing a transaction rollback on the transaction request according to the operation rollback parameters in the thread variable.

[0008] Optionally, generating operation rollback parameters based on the target operation includes: pre-setting method correspondences between multiple first interface methods and second interface methods; extracting the current interface object, current method, and current execution parameters from the target operation; determining the rollback method corresponding to the current method from the second interface methods based on the matching result between the first interface method and the current method; and assembling the current interface object, the rollback method, and the current execution parameters into a parameter body to obtain the operation rollback parameters corresponding to the target operation.

[0009] Optionally, transaction rollback can be performed based on operation rollback parameters by: reading the current interface object, rollback method, and current execution parameters from the thread variable; and calling the rollback method on the current interface object based on the current execution parameters to perform transaction rollback.

[0010] Optionally, the interface call operations of the transaction request are executed by the following method: pre-setting the operation execution order corresponding to each interface call operation; executing each interface call operation sequentially according to the operation execution order until all interface call operations are completed, wherein, after receiving the operation result corresponding to the first operation, including operation success, the second operation corresponding to the first operation is then executed, where the first operation is any interface call operation and the second operation is the interface call operation located next to the first operation.

[0011] Optionally, storing the operation rollback parameters in the thread variables of the transaction thread includes: sequentially calling a preset thread variable storage method for the operation rollback parameters corresponding to each of the interface calls in the order of operation execution, wherein the thread variable storage method is used to store the operation rollback parameters in the thread variables of the transaction thread.

[0012] Optionally, rolling back the transaction request based on the operation rollback parameters in the thread variable includes: determining the reverse order of the operation execution order as the information reading order; sequentially reading the operation rollback parameters from the thread variable according to the information reading order, and rolling back the transaction request based on the read operation rollback parameters.

[0013] Optionally, obtaining a transaction request includes at least one of the following: receiving a transaction request sent by a presentation layer, wherein the presentation layer is configured to receive a transaction request initiated by a user through a preset client terminal; pre-setting transaction execution conditions and transaction requests corresponding to the transaction execution conditions, and obtaining the transaction request when the transaction execution conditions are met.

[0014] Optionally, the execution of the transaction request is aborted in at least one of the following ways: if any received operation result includes operation failure, the execution of the transaction request is aborted; if a domain layer error code is received from the domain layer, the execution of the transaction request is aborted; anomaly detection is performed on the aggregation layer to obtain anomaly detection results, and the execution of the transaction request is aborted when the anomaly detection results include an anomaly in the aggregation layer.

[0015] This invention provides a transaction rollback system in a distributed scenario, comprising: an acquisition module for acquiring a transaction request, wherein the transaction request includes multiple interface call operations; an execution module for executing each interface call operation of the transaction request according to a preset transaction thread, and receiving the operation results corresponding to each interface call operation; a storage module for generating operation rollback parameters according to the target operation if the operation result corresponding to the target operation includes operation success, and storing the operation rollback parameters in the thread variable of the transaction thread, wherein the target operation is any interface call operation; and a rollback module for performing transaction rollback on the transaction request according to the operation rollback parameters in the thread variable if the execution of the transaction request is aborted.

[0016] The present invention provides an electronic device, comprising: a processor and a memory; the memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory to cause the electronic device to perform the above-described method.

[0017] The beneficial effects of this invention are:

[0018] By receiving the operation results corresponding to each interface call operation after executing the transaction request, and storing the operation rollback parameters corresponding to the target operation in the thread variable of the transaction thread when the operation result for the target operation is successful, the transaction request can be rolled back based on the operation rollback parameters in the thread variable when the execution of the transaction request is aborted. In this way, by establishing operation rollback parameters based on completed interface calls, storing these parameters in thread variables, and performing transaction rollback based on these parameters, independent transaction rollback in distributed scenarios is achieved. Transaction rollback no longer depends on middleware or specific servers, thus improving the applicability of transaction rollback. Furthermore, transaction rollback does not require database locking, reducing system performance overhead. Attached Figure Description

[0019] Figure 1 This is a schematic diagram of the structure of an application environment for implementing a transaction rollback method in a distributed scenario, as described in an embodiment of the present invention.

[0020] Figure 2 This is a flowchart illustrating a transaction rollback method in a distributed scenario according to an embodiment of the present invention.

[0021] Figure 3 This is a flowchart illustrating a transaction rollback method in another distributed scenario according to an embodiment of the present invention.

[0022] Figure 4 This is a flowchart illustrating a transaction rollback method in another distributed scenario according to an embodiment of the present invention.

[0023] Figure 5 This is a schematic diagram of the structure of a transaction rollback system in a distributed scenario according to an embodiment of the present invention;

[0024] Figure 6 This is a schematic diagram of an electronic device according to an embodiment of the present invention. Detailed Implementation

[0025] The following specific examples illustrate the implementation of the present invention. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be noted that, unless otherwise specified, the following embodiments and sub-samples in the embodiments can be combined with each other.

[0026] It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of the present invention. Therefore, the drawings only show the components related to the present invention and are not drawn according to the actual number, shape and size of the components in the actual implementation. In the actual implementation, the form, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.

[0027] In the following description, numerous details are explored to provide a more thorough explanation of embodiments of the invention. However, it will be apparent to those skilled in the art that embodiments of the invention may be practiced without these specific details. In other embodiments, well-known structures and devices are shown in block diagram form rather than in detail to avoid obscuring embodiments of the invention.

[0028] The terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this disclosure are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate for the embodiments of this disclosure described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover non-exclusive inclusion.

[0029] Unless otherwise stated, the term "multiple" means two or more.

[0030] In this embodiment of the disclosure, the character " / " indicates that the objects before and after it are in an "or" relationship. For example, A / B means: A or B.

[0031] The term "and / or" describes an association between objects, indicating that three relationships can exist. For example, A and / or B means: A or B, or A and B.

[0032] Before providing a further detailed description of the embodiments of the present invention, the nouns and terms involved in the embodiments of the present invention will be explained, and the nouns and terms involved in the embodiments of the present invention shall be interpreted as follows.

[0033] Thread-local variables are variables that belong to the current thread and are isolated from other threads; that is, they are unique to the current thread. Thread-local variables create a copy of the variable for each thread, so each thread can access its own copy. ThreadLocal variables, being thread-local variables, have different copies of the same object contained in different threads. Several points need to be noted here: because each thread has its own instance copy, and this copy can only be used by the current thread. Since each thread has its own instance copy, and other threads cannot access it, there is no issue of sharing between multiple threads. Thread-local variables provide a thread-local instance, and the difference between them and ordinary variables is that each thread using the variable initializes a completely independent instance copy. Thread-local variables are usually modified with `privatestatic`. When a thread terminates, all instance copies of the Thread-local variables it used can be garbage collected.

[0034] Domain-Driven Design (DDD) is a software engineering approach that uses a common language that domain experts, designers, and developers can understand as a communication tool. During this communication process, domain concepts are discovered, and these concepts are then designed into a domain model. The domain model drives software design, and the domain model is implemented in code. The domain model includes presentation layers, aggregation layers, and domain layers.

[0035] Combination Figure 1 As shown, this embodiment of the disclosure provides an application environment for implementing a transaction rollback method in a distributed scenario, including a presentation layer 101, an aggregation layer 102, and a domain layer 103.

[0036] The presentation layer 101 is responsible for displaying information to the user and interpreting user commands.

[0037] The aggregation layer 102, also known as the application layer, is responsible for connecting application requirements and domain service capabilities. It implements capabilities such as service orchestration, transaction management, and service call flow, and also undertakes a small number of business capabilities such as data transformation. It cannot independently complete complex business logic. In addition to defining application services, the application layer can also perform security authentication, permission verification, persistent transaction control, or event-based message notification.

[0038] Domain layer 103 serves the various business centers within the middle platform, representing the accumulation of core business capabilities. It primarily implements services with relatively independent business logic. Based on business relevance and referring to domain modeling theory, services are divided into different business domains. Each domain service includes several business processing modules and several data processing modules. The business processing modules perform business logic processing and access the data model by calling the interfaces of the data processing modules.

[0039] In some embodiments, when the front-end service of the presentation layer receives a request, it calls the interface of the aggregation layer service. At the same time, the aggregation layer interface calls different domain layer services. Therefore, transaction rollback is required in this distributed scenario to ensure data consistency.

[0040] Combination Figure 2 As shown, this disclosure provides a transaction rollback method in a distributed scenario, including:

[0041] Step S201: Obtain a transaction request;

[0042] The transaction request includes multiple API call operations;

[0043] Step S202: Execute the interface call operations of the transaction request according to the preset transaction thread, and receive the operation results corresponding to each interface call operation;

[0044] Step S203: If the operation result corresponding to the target operation includes operation success, then generate operation rollback parameters according to the target operation and store the operation rollback parameters in the thread variable of the transaction thread;

[0045] The target operation is any interface call operation;

[0046] Step S204: If the execution of the transaction request is aborted, the transaction request is rolled back according to the operation rollback parameters in the thread variable.

[0047] The transaction rollback method for distributed scenarios provided in this disclosure receives the operation results corresponding to each interface call operation after executing the transaction request. When the operation result corresponding to the target operation is successful, the operation rollback parameters corresponding to the target operation are stored in the thread variable of the transaction thread. Therefore, when the execution of the transaction request is aborted, the transaction request is rolled back based on the operation rollback parameters in the thread variable. In this way, by establishing operation rollback parameters based on completed interface call operations and storing them in thread variables, and performing transaction rollback based on these parameters, independent transaction rollback in distributed scenarios is achieved. Transaction rollback no longer depends on middleware or specific servers, thereby improving the applicability of transaction rollback. Furthermore, transaction rollback does not require database locking, reducing system performance overhead.

[0048] Optionally, obtaining a transaction request includes at least one of the following: receiving a transaction request sent by the presentation layer, wherein the presentation layer is used to receive a transaction request initiated by a user through a preset client terminal; pre-setting transaction execution conditions and transaction requests corresponding to the transaction execution conditions, and obtaining the transaction request when the transaction execution conditions are met.

[0049] In some embodiments, the client terminal includes a mobile APP (Application), a computer Web (World Wide Web) terminal, etc.

[0050] In this way, each transaction request is assigned a transaction thread for processing, and the thread variables are shared by each thread. Therefore, the rollback parameters of each transaction request are independent of each other, avoiding data loss, data errors and other problems caused by mutual interference.

[0051] Optionally, the interface call operations of the transaction request are executed by the following method: pre-setting the operation execution order corresponding to each interface call operation; executing each interface call operation in sequence according to the operation execution order until all interface call operations are completed. Among them, when the operation result corresponding to the first operation is received, including operation success, the second operation corresponding to the first operation is then executed. The first operation is any interface call operation, and the second operation is the interface call operation located next to the first operation.

[0052] Optionally, generating operation rollback parameters based on the target operation includes: pre-setting method correspondences between multiple first interface methods and second interface methods; extracting the current interface object, current method, and current execution parameters from the target operation; determining the rollback method corresponding to the current method from the second interface methods based on the matching result between the first interface methods and the current method; and assembling the current interface object, rollback method, and current execution parameters into a parameter body to obtain the operation rollback parameters corresponding to the target operation.

[0053] Optionally, storing the operation rollback parameters in the thread variables of the transaction thread includes: sequentially calling the preset thread variable storage method for the operation rollback parameters corresponding to each interface according to the operation execution order, wherein the thread variable storage method is used to store the operation rollback parameters in the thread variables of the transaction thread.

[0054] In some embodiments, the @BizRevert annotation is applied to the interface of the aggregation layer service. Whenever the aggregation layer successfully calls the domain layer interface, a rollback request parameter body BizRevertEntity is assembled based on the current interface object, the rollback method, and the current execution parameters to obtain the operation rollback parameters. Then, the thread variable storage method BizRevertUtil.setBizRevert() is called to store the operation rollback parameters into the thread variable in turn.

[0055] Optionally, the execution of a transaction request is aborted in at least one of the following ways: if any received operation result includes an operation failure, the execution of the transaction request is aborted; if a domain layer error code is received from the domain layer, the execution of the transaction request is aborted; anomaly detection is performed on the aggregation layer to obtain anomaly detection results, and the execution of the transaction request is aborted when the anomaly detection results include an anomaly in the aggregation layer.

[0056] In some embodiments, if an exception occurs in the called domain layer interface, an error code will be sent back to the aggregation layer. In response to receiving the error code, the aggregation layer will package the error code as a business exception and abort the execution of the transaction request. Through the exception handling mechanism of the aggregation layer, when a business exception is captured, the operation rollback parameters are retrieved from the thread variables in reverse order of storage order, so as to call the rollback interface corresponding to the operation of the domain layer calling interface, so that the service and the database return to the state before the execution of the transaction request.

[0057] Optionally, the transaction request is rolled back based on the operation rollback parameters in the thread variable, including: determining the reverse order of the operation execution order as the information reading order; reading the operation rollback parameters from the thread variable sequentially according to the information reading order, and rolling back the transaction request based on the read operation rollback parameters.

[0058] Optionally, transaction rollback can be performed based on the operation rollback parameters by: reading the current interface object, rollback method, and current execution parameters from the operation rollback parameters in the thread variable; and calling the rollback method on the current interface object based on the current execution parameters to perform transaction rollback.

[0059] Optionally, the method further includes: generating an error log after the transaction rollback is completed, and sending the error log to the presentation layer; performing error analysis on the error log, and displaying the error analysis results to the user to remind the user to adjust the interfaces of the aggregation layer and the domain layer.

[0060] In some embodiments, a transaction request to create a product is initiated by the client terminal to the presentation layer application; the presentation layer application calls the product creation interface of the aggregation layer according to the transaction request; and after the product creation interface is called, the aggregation layer sequentially calls multiple domain layer interfaces such as the SKU (StockKeeping Unit) creation interface, the price creation interface, and the inventory increase interface.

[0061] In some embodiments, after the aggregation layer calls the SKU creation interface, it receives the operation result corresponding to the SKU creation interface from the domain layer; the domain layer analyzes the operation result and finds that the domain layer operation failed; if the aggregation layer does not extract the operation rollback parameters from the thread variables, it does not perform a rollback operation.

[0062] In some embodiments, after the aggregation layer calls the SKU creation interface, it receives the operation result corresponding to the SKU creation interface from the domain layer; the domain layer analyzes the operation result and concludes that the domain layer operation was successful; the domain layer assembles the rollback request parameter body BizRevertEntity according to the current interface object (domain layer - product call object), rollback method (delete product) and current execution parameters (product ID) corresponding to the SKU creation interface, obtains the operation rollback parameters corresponding to the SKU creation interface, and stores the operation rollback parameters corresponding to the SKU creation interface in a thread variable.

[0063] In some embodiments, after the aggregation layer successfully calls the SKU creation interface, the aggregation layer calls the price creation interface and receives the operation result corresponding to the price creation interface from the domain layer; the domain layer analyzes the operation result and finds that the domain layer operation failed; the aggregation layer packages the operation result as a business exception and extracts the operation rollback parameters corresponding to the SKU creation interface from the thread variables; the aggregation layer executes the delete product method in the domain layer-product call object to perform transaction rollback on the transaction request.

[0064] In some embodiments, after the aggregation layer successfully calls the SKU creation interface, it calls the price creation interface and receives the operation result from the domain layer corresponding to the price creation interface. The domain layer analyzes the operation result and concludes that the domain layer operation was successful. The domain layer assembles the rollback request parameter body BizRevertEntity based on the current interface object, rollback method, and current execution parameters corresponding to the price creation interface to obtain the operation rollback parameters corresponding to the price creation interface, and stores the operation rollback parameters corresponding to the price creation interface into a thread variable.

[0065] In some embodiments, the aggregation layer sends an error message to the presentation layer after the transaction rollback is complete.

[0066] Combination Figure 3As shown, this disclosure provides a transaction rollback method in a distributed scenario, including:

[0067] Step S301: The application layer initiates a transaction request to the aggregation layer;

[0068] The transaction request includes multiple API call operations;

[0069] Step S302: The aggregation layer sequentially executes each interface call operation to the domain layer;

[0070] Step S303: The domain layer sends the operation result corresponding to the interface call operation to the aggregation layer;

[0071] Step S304: If the operation result corresponding to the interface call operation includes operation success, the aggregation layer generates the operation rollback parameters corresponding to the interface call operation.

[0072] In step S305, the aggregation layer stores the operation rollback parameters in a thread variable;

[0073] Step S306: If the transaction request is aborted, the aggregation layer extracts the operation rollback parameters from the thread variables in reverse order of storage order.

[0074] Step S307: The aggregation layer performs transaction rollback according to the operation rollback parameters in the order of extraction.

[0075] In step S308, if the transaction rollback is completed, the aggregation layer sends a transaction request failure message to the application layer.

[0076] The transaction rollback method for distributed scenarios provided in this disclosure receives the operation results corresponding to each interface call operation after executing the transaction request. When the operation result corresponding to the target operation is successful, the operation rollback parameters corresponding to the target operation are stored in the thread variable of the transaction thread. Therefore, when the execution of the transaction request is aborted, the transaction request is rolled back based on the operation rollback parameters in the thread variable. In this way, by establishing operation rollback parameters based on completed interface call operations and storing them in thread variables, and performing transaction rollback based on these parameters, independent transaction rollback in distributed scenarios is achieved. Transaction rollback no longer depends on middleware or specific servers, thereby improving the applicability of transaction rollback. Furthermore, transaction rollback does not require database locking, reducing system performance overhead.

[0077] Combination Figure 4 As shown, this disclosure provides a transaction rollback method in a distributed scenario, including:

[0078] Step S401: The aggregation layer obtains the transaction request from the presentation layer;

[0079] The transaction request includes multiple API call operations;

[0080] In step S402, the aggregation layer executes various interface call operations on the domain layer according to the preset transaction thread, so that the domain layer returns the operation results of each interface call operation.

[0081] Step S403: Determine whether the operation result of the interface call operation is successful. If yes, proceed to step S404; otherwise, proceed to step S408.

[0082] Step S404: The aggregation layer generates operation rollback parameters based on the interface call operation;

[0083] In step S405, the aggregation layer stores the operation rollback parameters in a thread variable;

[0084] Step S406: Determine whether each interface call operation of the transaction request has been completed. If yes, proceed to step S407; otherwise, proceed to step S402.

[0085] In step S407, the aggregation layer sends a transaction request completion message to the presentation layer.

[0086] Step S408: Extract the operation rollback parameters from the thread variables in reverse order of storage order;

[0087] Step S409: Roll back transactions sequentially according to the operation rollback parameters in the extraction order;

[0088] In step S410, after completing the transaction rollback, the aggregation layer sends a transaction request failure message to the presentation layer.

[0089] The transaction rollback method in a distributed scenario provided in this disclosure receives the operation results corresponding to each interface call operation after executing the transaction request, and stores the operation rollback parameters corresponding to the target operation in the thread variable of the transaction thread when the operation result corresponding to the target operation is successful. Therefore, when the execution of the transaction request is aborted, the transaction request is rolled back according to the operation rollback parameters in the thread variable. This method has the following advantages:

[0090] First, operation rollback parameters are established based on the completed interface call operations, and the operation rollback parameters are stored in thread variables. Transaction rollback is performed based on the operation rollback parameters stored in thread variables, realizing independent transaction rollback in distributed scenarios. Transaction rollback no longer depends on middleware or specific servers, thereby improving the applicability of transaction rollback.

[0091] Second, transaction rollback does not require database locking, reducing system performance consumption;

[0092] Third, each transaction request is assigned a transaction thread for processing, and the thread variables are shared by each thread. Therefore, the rollback parameters of each transaction request are independent of each other, avoiding data loss, data errors and other problems caused by mutual interference.

[0093] Combination Figure 5 As shown, this disclosure provides a transaction rollback system in a distributed scenario, including an acquisition module 501, an execution module 502, a storage module 503, and a rollback module 504.

[0094] The acquisition module 501 is used to acquire transaction requests, which include multiple interface call operations.

[0095] The execution module 502 is used to execute the interface call operations of the transaction request according to the preset transaction thread, and to receive the operation results corresponding to each interface call operation.

[0096] The storage module 503 is used to generate operation rollback parameters based on the target operation if the operation result corresponding to the target operation includes operation success, and store the operation rollback parameters in the thread variable of the transaction thread, wherein the target operation is any interface call operation.

[0097] The rollback module 504 is used to roll back the transaction request according to the operation rollback parameters in the thread variable if the execution of the transaction request is aborted.

[0098] The transaction rollback system for distributed scenarios provided in this disclosure receives the operation results corresponding to each interface call operation after executing the transaction request. When the operation result corresponding to the target operation is successful, the operation rollback parameters corresponding to the target operation are stored in the thread variable of the transaction thread. Therefore, when the execution of the transaction request is aborted, the transaction request is rolled back based on the operation rollback parameters in the thread variable. In this way, by establishing operation rollback parameters based on completed interface call operations and storing them in thread variables, and performing transaction rollback based on these parameters, independent transaction rollback in distributed scenarios is achieved. Transaction rollback no longer depends on middleware or specific servers, thereby improving the applicability of transaction rollback. Furthermore, transaction rollback does not require database locking, reducing system performance overhead.

[0099] Figure 6 A schematic diagram of a computer system suitable for implementing the embodiments of this application is shown. It should be noted that... Figure 6 The computer system 600 of the electronic device shown is merely an example and should not impose any limitation on the functionality and scope of use of the embodiments of this application.

[0100] like Figure 6As shown, the computer system 600 includes a Central Processing Unit (CPU) 601, which can perform various appropriate actions and processes, such as executing the methods described in the above embodiments, based on a program stored in Read-Only Memory (ROM) 602 or a program loaded from Storage Section 608 into Random Access Memory (RAM) 603. The RAM 603 also stores various programs and data required for system operation. The CPU 601, ROM 602, and RAM 603 are interconnected via a bus 604. An Input / Output (I / O) interface 605 is also connected to the bus 604.

[0101] The following components are connected to I / O interface 605: an input section 606 including a keyboard, mouse, etc.; an output section 607 including a cathode ray tube (CRT), liquid crystal display (LCD), etc., and speakers, etc.; a storage section 608 including a hard disk, etc.; and a communication section 609 including a network interface card such as a LAN (Local Area Network) card, modem, etc. The communication section 609 performs communication processing via a network such as the Internet. Drive 160 is also connected to I / O interface 605 as needed. Removable media 611, such as a disk, optical disk, magneto-optical disk, semiconductor memory, etc., are installed on drive 160 as needed so that computer programs read from them can be installed into storage section 608 as needed.

[0102] Specifically, according to embodiments of this application, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, embodiments of this application include a computer program product comprising a computer program carried on a computer-readable medium, the computer program including a computer program for performing the methods shown in the flowcharts. In such embodiments, the computer program can be downloaded and installed from a network via communication section 609, and / or installed from removable medium 611. When the computer program is executed by central processing unit (CPU) 601, it performs various functions defined in the system of this application.

[0103] It should be noted that the computer-readable medium shown in the embodiments of this application can be a computer-readable signal medium or a computer-readable storage medium, or any combination of the two. A computer-readable storage medium can be, for example, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination thereof. More specific examples of a computer-readable storage medium may include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, random access memory (RAM), read-only memory (ROM), erasable programmable read-only memory (EPROM), flash memory, optical fiber, portable compact disc read-only memory (CD-ROM), optical storage device, magnetic storage device, or any suitable combination thereof. In this application, a computer-readable signal medium may include a data signal propagated in baseband or as part of a carrier wave, carrying a computer-readable computer program. Such propagated data signals can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination thereof. Computer-readable signal media can also be any computer-readable medium other than computer-readable storage media, which can send, propagate, or transmit a program for use by or in connection with an instruction execution system, apparatus, or device. The computer program contained on the computer-readable medium can be transmitted using any suitable medium, including but not limited to wireless, wired, etc., or any suitable combination thereof.

[0104] The electronic device disclosed in this embodiment includes a processor, a memory, a transceiver, and a communication interface. The memory and the communication interface are connected to the processor and the transceiver and complete communication between them. The memory is used to store computer programs, the communication interface is used to perform communication, and the processor and the transceiver are used to run the computer programs, so that the electronic device performs the various steps of the above method.

[0105] In this embodiment, the memory may include random access memory (RAM) and may also include non-volatile memory, such as at least one disk storage device.

[0106] The processors mentioned above can be general-purpose processors, including central processing units (CPUs), graphics processing units (GPUs), network processors (NPs), etc.; they can also be digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.

[0107] The foregoing description and accompanying drawings fully illustrate embodiments of this disclosure to enable those skilled in the art to practice them. Other embodiments may include structural, logical, electrical, procedural, and other changes. The embodiments represent only possible variations. Individual components and functions are optional unless explicitly required, and the order of operation may vary. Parts and subsamples of some embodiments may be included in or replace parts and subsamples of other embodiments. Moreover, the terminology used in this application is for describing embodiments only and is not intended to limit the claims. As used in the description of embodiments and claims, the singular forms “a,” “an,” and “the” are intended to equally include the plural forms unless the context clearly indicates otherwise. Similarly, the term “and / or” as used herein means including one or more of the associated listed items and all possible combinations thereof. Additionally, when used in this application, the term "comprise" and its variations "comprises" and / or "comprising" refer to the presence of stated subsamples, wholes, steps, operations, elements, and / or components, but do not exclude the presence or addition of one or more other subsamples, wholes, steps, operations, elements, components, and / or groups thereof. Without further limitations, an element defined by the phrase "comprising a..." does not exclude the presence of other identical elements in the process, method, or apparatus that includes the element. In this document, each embodiment may focus on the differences from other embodiments, and similar or identical parts between embodiments can be referred to mutually. For methods, products, etc., disclosed in the embodiments, if they correspond to the method section disclosed in the embodiments, the relevant parts can be referred to the description of the method section.

[0108] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of the embodiments of this disclosure. Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0109] The methods and products (including but not limited to devices and equipment) disclosed in the embodiments herein can be implemented in other ways. For example, the device embodiments described above are merely illustrative. For instance, the division of units may be merely a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some sub-samples may be ignored or not executed. In addition, the mutual coupling or direct coupling or communication connection shown or discussed may be through some interfaces, and the indirect coupling or communication connection of devices or units may be electrical, mechanical, or other forms. Units described as separate components may or may not be physically separate, and components shown as units may or may not be physical units, that is, they may be located in one place or distributed across multiple network units. Some or all of the units may be selected to implement this embodiment according to actual needs. Furthermore, the functional units in the embodiments of this disclosure may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit.

[0110] The flowcharts and block diagrams in the accompanying drawings illustrate the architecture, functionality, and operation of possible implementations of systems, methods, and computer program products according to embodiments of this disclosure. In this regard, each block in a flowchart or block diagram may represent a module, segment, or portion of code containing one or more executable instructions for implementing a specified logical function. In some alternative implementations, the functions marked in the blocks may occur in a different order than that shown in the drawings. For example, two consecutive blocks may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. In the descriptions corresponding to the flowcharts and block diagrams in the accompanying drawings, the operations or steps corresponding to different blocks may also occur in a different order than disclosed in the description, and sometimes there is no specific order between different operations or steps. For example, two consecutive operations or steps may actually be executed substantially in parallel, and they may sometimes be executed in reverse order, depending on the functions involved. Each block in a block diagram and / or flowchart, and combinations of blocks in a block diagram and / or flowchart, can be implemented using a dedicated hardware-based system that performs the specified function or action, or using a combination of dedicated hardware and computer instructions.

Claims

1. A transaction rollback method in a distributed scenario, characterized in that, include: Obtain a transaction request, wherein the transaction request includes multiple interface call operations; The transaction request is executed according to a preset transaction thread, and the operation results corresponding to each of the interface calls are received. If the operation result corresponding to the target operation includes operation success, then operation rollback parameters are generated according to the target operation, and the operation rollback parameters are stored in the thread variable of the transaction thread, wherein the target operation is any interface call operation; Generating operation rollback parameters based on the target operation includes: pre-setting method correspondences between multiple first interface methods and second interface methods; extracting the current interface object, current method, and current execution parameters from the target operation; determining the rollback method corresponding to the current method from the second interface methods based on the matching result between the first interface methods and the current method; and assembling the current interface object, the rollback method, and the current execution parameters into a parameter body to obtain the operation rollback parameters corresponding to the target operation. If the execution of the transaction request is aborted, the transaction request is rolled back according to the operation rollback parameter in the thread variable.

2. The method according to claim 1, characterized in that, Transaction rollback can be performed based on the operation rollback parameters using the following method: Read the current interface object, rollback method, and current execution parameters from the operation rollback parameters in the thread variable; The rollback method is invoked on the current interface object according to the current execution parameters to perform transaction rollback.

3. The method according to claim 1, characterized in that, The interface call operations for the transaction request are executed using the following methods: The execution order of each of the aforementioned interface call operations is pre-set; Each of the interface call operations is executed sequentially according to the operation execution order until all interface call operations are completed. When the operation result corresponding to the first operation is received, including operation success, the second operation corresponding to the first operation is then executed. The first operation is any interface call operation, and the second operation is the interface call operation located after the first operation.

4. The method according to claim 3, characterized in that, Storing the operation rollback parameters in the thread variable of the transaction thread includes: According to the operation execution order, the preset thread variable storage method is called sequentially for the operation rollback parameters corresponding to each interface call operation, wherein the thread variable storage method is used to store the operation rollback parameters in the thread variable of the transaction thread.

5. The method according to claim 4, characterized in that, Rollback the transaction request according to the operation rollback parameters in the thread variable, including: The reverse order of the operation execution sequence is determined as the information reading order; According to the information reading order, the operation rollback parameters are read sequentially from the thread variables, and the transaction request is rolled back according to the read operation rollback parameters.

6. The method according to any one of claims 1 to 5, characterized in that, Obtain a transaction request, including at least one of the following: Receive transaction requests sent by the presentation layer, wherein the presentation layer is used to receive transaction requests initiated by users through a preset client terminal; Transaction execution conditions and corresponding transaction requests are pre-set, and the transaction requests are obtained when the transaction execution conditions are met.

7. The method according to any one of claims 1 to 5, characterized in that, The application environment for implementing the transaction rollback method in the distributed scenario includes a presentation layer, an aggregation layer, and a domain layer. The abort of the transaction request includes at least one of the following: If any received operation result includes an operation failure, then the execution of the transaction request is aborted; If a domain layer error code is received from the domain layer, the execution of the transaction request is aborted. Anomaly detection is performed on the aggregation layer to obtain anomaly detection results. If the anomaly detection results indicate that there is an anomaly in the aggregation layer, the execution of the transaction request is aborted.

8. A transaction rollback system in a distributed scenario, characterized in that, include: The acquisition module is used to acquire transaction requests, wherein the transaction requests include multiple interface call operations; The execution module is used to execute each interface call operation of the transaction request according to a preset transaction thread, and to receive the operation results corresponding to each interface call operation. The storage module is used to generate operation rollback parameters based on the target operation if the operation result corresponding to the target operation includes operation success, and store the operation rollback parameters in the thread variable of the transaction thread, wherein the target operation is any interface call operation; The storage module generates operation rollback parameters based on the target operation in the following manner: pre-setting multiple method correspondences between first interface methods and second interface methods; extracting the current interface object, current method, and current execution parameters from the target operation; determining the rollback method corresponding to the current method from the second interface methods based on the matching result between the first interface method and the current method; and assembling the current interface object, the rollback method, and the current execution parameters into a parameter body to obtain the operation rollback parameters corresponding to the target operation. The rollback module is used to roll back the transaction request according to the operation rollback parameters in the thread variable if the execution of the transaction request is aborted.

9. An electronic device, characterized in that, include: Processor and memory; The memory is used to store a computer program, and the processor is used to execute the computer program stored in the memory to cause the electronic device to perform the method as described in any one of claims 1 to 7.

Citation Information

Patent Citations

  • Database transaction management method and device, equipment and storage medium

    CN114490769A

  • Method and apparatus for providing in-memory checkpoint services within a distributed transaction

    US8095826B1