CN111209092A - Distributed transaction processing method based on Saga mode - Google Patents

Distributed transaction processing method based on Saga mode Download PDF

Info

Publication number
CN111209092A
CN111209092A CN202010020449.XA CN202010020449A CN111209092A CN 111209092 A CN111209092 A CN 111209092A CN 202010020449 A CN202010020449 A CN 202010020449A CN 111209092 A CN111209092 A CN 111209092A
Authority
CN
China
Prior art keywords
terminal
target service
transaction
engine server
execution
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.)
Withdrawn
Application number
CN202010020449.XA
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.)
Jiangsu Aijia Household Products Co Ltd
Original Assignee
Jiangsu Aijia Household Products 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 Jiangsu Aijia Household Products Co Ltd filed Critical Jiangsu Aijia Household Products Co Ltd
Priority to CN202010020449.XA priority Critical patent/CN111209092A/en
Publication of CN111209092A publication Critical patent/CN111209092A/en
Withdrawn 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
    • G06F8/00Arrangements for software engineering
    • G06F8/30Creation or generation of source code
    • G06F8/31Programming languages or programming paradigms

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • General Engineering & Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Computing Systems (AREA)
  • Information Retrieval, Db Structures And Fs Structures Therefor (AREA)

Abstract

The invention relates to a distributed transaction processing method based on a Saga mode, based on the locking-free Saga mode, compensating the transaction through a self-defined compensation process, thereby achieving the final consistency, wherein a state machine engine and a simple dsl state definition language are designed, the self-defined business process arrangement and the business flow state recording are realized, the state machine engine can self-define the compensation service, when an abnormality occurs, the state machine engine calls the compensation service to perform rollback or retry operation, and the data consistency is ensured; in application, the method has high performance, and is submitted to a local database in one stage without a global lock; with high throughput, transactional participants execute asynchronously on an event-driven basis; with high flexibility, based on a state machine engine and a simple state definition language, service orchestration capability can be provided, and compensation services can be rolled back or retried.

Description

Distributed transaction processing method based on Saga mode
Technical Field
The invention relates to a distributed transaction processing method based on a Saga mode, and belongs to the technical field of distributed transaction data consistency under a micro-service architecture.
Background
At present, micro-service architecture has been widely applied to the industry, advocates to abstract and split complex single application into a plurality of services with simple functions and low coupling, so that development difficulty can be reduced, expansibility can be enhanced, and agile development is facilitated, but a lot of difficulties are brought at the same time. Such as: inter-system communication and fault handling measures are more complex, test deployment and monitoring are more difficult, the problem of distributed transaction of service invocation is more prominent, and for such difficult problems, the industry also provides a plurality of solutions, such as: two-phase commit under XA protocol, TCC scheme, final consistency scheme under message middleware, etc. The applicable scenes of each scheme are different, and the application process is troublesome.
Disclosure of Invention
The technical problem to be solved by the invention is to provide a distributed transaction processing method based on the Saga mode, which can effectively deal with services with multiple flows and long flows, ensure the final consistency of transactions and improve the efficiency of distributed transaction processing.
The invention adopts the following technical scheme for solving the technical problems: the invention designs a distributed transaction processing method based on a Saga mode, a terminal realizes scheduling processing aiming at a target service based on a state machine engine of the terminal, and the terminal is combined with an engine server to execute the following steps A to G:
a, loading a target service on a terminal, analyzing the target service, converting the analyzed target service into a corresponding Json file for storage through a dsl state definition language, and then entering a step B;
b, the terminal sends a transaction opening instruction corresponding to the target service to the engine server according to the Json file corresponding to the target service based on the state machine engine of the terminal, receives an xid file returned by the engine server, initializes n to 1, and enters the step C;
c, the terminal registers the nth branch transaction corresponding to the target service to the engine server according to the received xid file and the Json file corresponding to the target service based on the state machine engine of the terminal, receives the branched file corresponding to the nth branch transaction returned by the engine server, and then enters the step D;
step D, the terminal executes the nth branch transaction corresponding to the target service according to the received branched file, obtains the execution state result of the branch transaction, uploads the execution state result to the engine server, and then enters step E;
step E, judging whether N is equal to the number N of branch transactions in the target service, if yes, entering step F; otherwise, updating by adding 1 according to the value of n, and returning to the step C;
f, the engine server polls the execution state result of each branch transaction, judges whether the execution error state result exists, if yes, the engine server returns the execution error state result to the terminal, and the step G is carried out; otherwise, the execution of the target service is completed;
and G, the terminal executes the rollback transaction operation corresponding to the error state execution result in the target service according to the Json file corresponding to the target service conversion, and uploads the rollback transaction execution to the engine server.
As a preferred technical scheme of the invention: the terminal executes the steps A to G based on a state machine engine of the terminal and by combining a local database and an engine server, and in the process of realizing scheduling processing aiming at the target service:
in the step B, after the terminal receives the xid file returned by the engine server, the terminal records the starting of a state machine to a local database, then initializes n to 1, and enters the step C;
in the step C, after the terminal receiving engine server returns a branched file corresponding to the nth branch transaction, the terminal records the start of the nth branch transaction to a local database, and then the step D is carried out;
in step D, after the terminal obtains the execution state result of the nth branch transaction, the terminal records the execution state result of the nth branch transaction to a local database, uploads the execution state result to the engine server and enters step E;
in step E, when N is equal to the number N of branch transactions in the target service, the terminal records the state machine to the local database, and then enters step F.
As a preferred technical scheme of the invention: the terminal executes the steps A to G based on a state machine engine thereof in combination with a local database, a local event queue and an engine server, and in the process of realizing scheduling processing aiming at the target service:
in step D, after the terminal obtains the execution state result of the nth branch transaction, the terminal records the execution state result of the nth branch transaction to a local database, meanwhile, the terminal adds the execution state result of the nth branch transaction into a local event queue and uploads the execution state result of the nth branch transaction to an engine server.
Compared with the prior art, the distributed transaction processing method based on the Saga mode has the following technical effects by adopting the technical scheme:
the distributed transaction processing method based on the Saga mode is based on the locking-free Saga mode, and performs compensation operation on transactions through a self-defined compensation process so as to achieve final consistency, wherein a state machine engine and a simple dsl state definition language are designed to realize self-defined business process arrangement and record business flow states, the state machine engine can self-define compensation services, and when abnormity occurs, the state machine engine calls the compensation services to perform rollback or retry operation, so that the data consistency is ensured; in application, the method has high performance, and is submitted to a local database in one stage without a global lock; with high throughput, transactional participants execute asynchronously on an event-driven basis; with high flexibility, based on a state machine engine and a simple state definition language, service orchestration capability can be provided, and compensation services can be rolled back or retried.
Drawings
FIG. 1 is a schematic flow chart of a distributed transaction processing method based on the Saga model according to the present invention;
FIG. 2 is a block diagram of a state machine engine architecture according to the present invention;
FIG. 3 is a state diagram of a user transfer process as applied by an exemplary embodiment of the present invention;
Detailed Description
The following description will explain embodiments of the present invention in further detail with reference to the accompanying drawings.
The invention designs a distributed transaction processing method based on a Saga mode, as shown in figure 1, a terminal combines a local database, a local event queue and an engine server, and the terminal executes the following steps A to G based on a state machine engine thereof to realize scheduling processing aiming at target services.
And step A, loading a target service on the terminal, analyzing the target service, converting the analyzed target service into a corresponding Json file for storage through a dsl state definition language, and then entering the step B.
And step B, the terminal sends a transaction opening instruction corresponding to the target service to the engine server according to the Json file corresponding to the target service based on the state machine engine of the terminal, receives the xid file returned by the engine server, records the state machine starting to a local database, initializes n to 1, and enters the step C.
And C, the terminal registers the nth branch transaction corresponding to the target service to the engine server according to the received xid file and the Json file corresponding to the target service based on the state machine engine of the terminal, receives the branched file corresponding to the nth branch transaction returned by the engine server, records the start of the nth branch transaction to the local database, and then enters the step D.
And D, the terminal executes the nth branch transaction corresponding to the target service according to the received branched file to obtain the execution state result of the branch transaction, records the execution state result of the nth branch transaction to a local database, adds the execution state result of the nth branch transaction into a local event queue, uploads the execution state result of the nth branch transaction to an engine server, and then enters the step E.
E, judging whether N is equal to the number N of branch transactions in the target service, if yes, the terminal records the state machine to a local database, and then entering the step F; otherwise, adding 1 for updating the value of n and returning to the step C.
F, the engine server polls the execution state result of each branch transaction, judges whether the execution error state result exists, if yes, the engine server returns the execution error state result to the terminal, and the step G is carried out; otherwise, the execution of the target service is completed.
And G, the terminal executes the rollback transaction operation corresponding to the error state execution result in the target service according to the Json file corresponding to the target service conversion, and uploads the rollback transaction execution to the engine server.
Based on the above-designed distributed transaction processing method based on the Saga model, the design architecture of the state machine engine of the terminal is shown in fig. 2, and the state machine engine design is mainly divided into three major layers, namely: an event driven layer, a flow control layer and a state machine engine layer.
1) The event-driven layer is mainly composed of an event bus and an event consumption thread pool, uses a publish-subscribe mode,
and pushing the event and consuming the event by the consumption end, particularly executing the event by the flow control layer.
2) The flow control layer is a simple flow engine framework, executes the process method in each flow node, and then calls the dispatch method flow to go to the next flow node.
3) The state machine engine layer realizes the behavior and routing logic of each state node, provides an API interface and a state machine language library, and also has other components such as: logic generators, pipeline generators, interceptors, configuration management, transaction logging, and expression languages, among others.
In practical application, the last state definition language is mainly output as a JSON-formatted file, and includes two parts, namely a state machine attribute and a process state attribute, as shown by a code, namely a state custom language graph.
Figure BDA0002360576210000041
Defined by code such as that described above is the JSON file for the user transfer flow, which corresponds to the state shown in fig. 3. In applications, such as designing a list of state machine attributes, including name: the name representing the state machine, must be unique; comment: description of a state machine; version: a state machine definition version; startState: a first state of operation at start-up; states: the state list is a map structure, and the key is the name of the state and must be unique; in addition, a flow state attribute list is designed, and comprises a type: the status types, such as: service task, choice, compensation trigger, managed (normal end of state machine), fail, and substatemaccine; serviceName: a service name; a serviceMethod: a service method name; complementatelephone: a compensation state for this state; isForUpdate: whether the data identification is updated or not, the default is false, and the default is true if complementaset is configured; isPersist: whether to store an execution log; input: calling an input parameter list of the service; output: assigning the parameters returned by the service to the context of the state machine; status: performing state mapping by the service, wherein S is successful, F is failed, and U is unknown; catch: capturing and processing service exception; next: the next execution state after the service execution is finished; choices: the optional branch list, wherein the expression in the branch is a SpringEL expression, and the next is the next state executed when the expression is established; errorCode: error codes for fail type status; message: error information of fail type status.
The invention is designed for distributed transaction data consistency scenes under a micro-service architecture, and is based on Java programming language, and in the specific implementation: xml introduces client SDK dependencies first as follows code implementing application pom.
Figure BDA0002360576210000051
And any method realizes that the json file is arranged by the application self-defined service flow according to the following codes and stores the json file into src/main/resources/directory.
Figure BDA0002360576210000052
And finally, according to the following codes, realizing the application configuration state machine engine parameters and instantiating.
Figure BDA0002360576210000061
The distributed transaction processing method based on the Saga mode is designed based on the locking-free Saga mode, compensation operation is carried out on transactions through a self-defined compensation process, and therefore final consistency is achieved; in application, the method has high performance, and is submitted to a local database in one stage without a global lock; with high throughput, transactional participants execute asynchronously on an event-driven basis; with high flexibility, based on a state machine engine and a simple state definition language, service orchestration capability can be provided, and compensation services can be rolled back or retried.
The embodiments of the present invention have been described in detail with reference to the drawings, but the present invention is not limited to the above embodiments, and various changes can be made within the knowledge of those skilled in the art without departing from the gist of the present invention.

Claims (3)

1. A distributed transaction processing method based on a Saga mode is characterized in that a terminal is combined with an engine server to execute the following steps A to G:
a, loading a target service on a terminal, analyzing the target service, converting the analyzed target service into a corresponding Json file for storage through a dsl state definition language, and then entering a step B;
b, the terminal sends a transaction opening instruction corresponding to the target service to the engine server according to the Json file corresponding to the target service based on the state machine engine of the terminal, receives an xid file returned by the engine server, initializes n to 1, and enters the step C;
c, the terminal registers the nth branch transaction corresponding to the target service to the engine server according to the received xid file and the Json file corresponding to the target service based on the state machine engine of the terminal, receives the branched file corresponding to the nth branch transaction returned by the engine server, and then enters the step D;
step D, the terminal executes the nth branch transaction corresponding to the target service according to the received branched file, obtains the execution state result of the branch transaction, uploads the execution state result to the engine server, and then enters step E;
step E, judging whether N is equal to the number N of branch transactions in the target service, if yes, entering step F; otherwise, updating by adding 1 according to the value of n, and returning to the step C;
f, the engine server polls the execution state result of each branch transaction, judges whether the execution error state result exists, if yes, the engine server returns the execution error state result to the terminal, and the step G is carried out; otherwise, the execution of the target service is completed;
and G, the terminal executes the rollback transaction operation corresponding to the error state execution result in the target service according to the Json file corresponding to the target service conversion, and uploads the rollback transaction execution to the engine server.
2. The distributed transaction processing method based on Saga model of claim 1, wherein: in one embodiment, the terminal, based on its state machine engine, in combination with a local database and an engine server, executes steps a to G, and in the process of implementing scheduling processing for a target service:
in the step B, after the terminal receives the xid file returned by the engine server, the terminal records the starting of a state machine to a local database, then initializes n to 1, and enters the step C;
in the step C, after the terminal receiving engine server returns a branched file corresponding to the nth branch transaction, the terminal records the start of the nth branch transaction to a local database, and then the step D is carried out;
in step D, after the terminal obtains the execution state result of the nth branch transaction, the terminal records the execution state result of the nth branch transaction to a local database, uploads the execution state result to the engine server and enters step E;
in step E, when N is equal to the number N of branch transactions in the target service, the terminal records the state machine to the local database, and then enters step F.
3. The distributed transaction processing method based on Saga model according to claim 2, wherein: in one embodiment, the terminal executes steps a to G based on its state machine engine in combination with a local database, a local event queue, and an engine server, and in the process of implementing scheduling processing for a target service:
in step D, after the terminal obtains the execution state result of the nth branch transaction, the terminal records the execution state result of the nth branch transaction to a local database, meanwhile, the terminal adds the execution state result of the nth branch transaction into a local event queue and uploads the execution state result of the nth branch transaction to an engine server.
CN202010020449.XA 2020-01-09 2020-01-09 Distributed transaction processing method based on Saga mode Withdrawn CN111209092A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202010020449.XA CN111209092A (en) 2020-01-09 2020-01-09 Distributed transaction processing method based on Saga mode

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202010020449.XA CN111209092A (en) 2020-01-09 2020-01-09 Distributed transaction processing method based on Saga mode

Publications (1)

Publication Number Publication Date
CN111209092A true CN111209092A (en) 2020-05-29

Family

ID=70789006

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202010020449.XA Withdrawn CN111209092A (en) 2020-01-09 2020-01-09 Distributed transaction processing method based on Saga mode

Country Status (1)

Country Link
CN (1) CN111209092A (en)

Cited By (7)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111813791A (en) * 2020-06-17 2020-10-23 上海悦易网络信息技术有限公司 Method and equipment for distributed transaction compensation
CN112328611A (en) * 2020-11-03 2021-02-05 苏州浪潮智能科技有限公司 Implementation scheme for data consistency under micro-service framework
CN112612551A (en) * 2020-12-31 2021-04-06 中国农业银行股份有限公司 Method, device, equipment, medium and product for managing distributed transactions
CN112631696A (en) * 2020-12-29 2021-04-09 智慧神州(北京)科技有限公司 Service arranging method, arranging device, processor and service arranging system
CN112671827A (en) * 2020-11-25 2021-04-16 紫光云技术有限公司 Distributed transaction final consistency method
CN116126481A (en) * 2023-02-06 2023-05-16 安芯网盾(北京)科技有限公司 Distributed long transaction processing method and device
WO2023125384A1 (en) * 2021-12-31 2023-07-06 中冶南方工程技术有限公司 Distributed industrial data acquisition configuration release system and method

Cited By (10)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111813791A (en) * 2020-06-17 2020-10-23 上海悦易网络信息技术有限公司 Method and equipment for distributed transaction compensation
CN111813791B (en) * 2020-06-17 2024-05-21 上海万物新生环保科技集团有限公司 Distributed transaction compensation method and equipment
CN112328611A (en) * 2020-11-03 2021-02-05 苏州浪潮智能科技有限公司 Implementation scheme for data consistency under micro-service framework
CN112671827A (en) * 2020-11-25 2021-04-16 紫光云技术有限公司 Distributed transaction final consistency method
CN112671827B (en) * 2020-11-25 2023-03-07 紫光云技术有限公司 Distributed transaction final consistency method
CN112631696A (en) * 2020-12-29 2021-04-09 智慧神州(北京)科技有限公司 Service arranging method, arranging device, processor and service arranging system
CN112612551A (en) * 2020-12-31 2021-04-06 中国农业银行股份有限公司 Method, device, equipment, medium and product for managing distributed transactions
WO2023125384A1 (en) * 2021-12-31 2023-07-06 中冶南方工程技术有限公司 Distributed industrial data acquisition configuration release system and method
CN116126481A (en) * 2023-02-06 2023-05-16 安芯网盾(北京)科技有限公司 Distributed long transaction processing method and device
CN116126481B (en) * 2023-02-06 2023-08-25 安芯网盾(北京)科技有限公司 Distributed long transaction processing method and device

Similar Documents

Publication Publication Date Title
CN111209092A (en) Distributed transaction processing method based on Saga mode
US8788565B2 (en) Dynamic and distributed queueing and processing system
Rosenberg et al. An end-to-end approach for QoS-aware service composition
US7912804B1 (en) Change management in a distributed system based on triggered policy rules
US8924931B2 (en) Method and system for determining dependencies in a mainframe development environment
US20110178946A1 (en) Systems and methods for redundancy using snapshots and check pointing in contact handling systems
US20070118414A1 (en) Business process system management method
US11544125B2 (en) Method and system for processing a stream of incoming messages sent from a specific input message source and validating each incoming message of that stream before sending them to a specific target system
US20110179304A1 (en) Systems and methods for multi-tenancy in contact handling systems
US20100131745A1 (en) Exceptional events
CN112463144A (en) Distributed storage command line service method, system, terminal and storage medium
CN109739624B (en) Distributed transaction processing method and device, electronic equipment and computer readable medium
CN113778545A (en) Data processing method, device, equipment and storage medium
CN111208992A (en) System scheduling workflow generation method and system
CN115629737A (en) Method for implementing process arrangement engine and process arrangement engine system
CN110457132B (en) Method and device for creating functional object and terminal equipment
CN112365239A (en) Event-based cloud service management handling method and system
CN112328406A (en) Micro-service distributed transaction system based on TCC (transmission control center) and service processing method
CN115829715A (en) Banking transaction dispatching center control method and banking transaction dispatching center
Mangler et al. Cloud process execution engine: architecture and interfaces
Mania et al. Developing performance models from nonintrusive monitoring traces
CN117033033B (en) Method for efficient configuration and interaction of public service in service bus
CN114726911B (en) Routing parameter transfer method for distributed industrial robot online service arrangement
CN117667362B (en) Method, system, equipment and readable medium for scheduling process engine
Jefford et al. Professional BizTalk Server 2006

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
WW01 Invention patent application withdrawn after publication

Application publication date: 20200529

WW01 Invention patent application withdrawn after publication