CN115576657A - Distributed transaction creating method - Google Patents

Distributed transaction creating method Download PDF

Info

Publication number
CN115576657A
CN115576657A CN202211157357.1A CN202211157357A CN115576657A CN 115576657 A CN115576657 A CN 115576657A CN 202211157357 A CN202211157357 A CN 202211157357A CN 115576657 A CN115576657 A CN 115576657A
Authority
CN
China
Prior art keywords
transaction
mode
txmanager
distributed
global
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
CN202211157357.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.)
Southern Power Grid Digital Grid Research Institute Co Ltd
Original Assignee
Southern Power Grid Digital Grid Research Institute 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 Southern Power Grid Digital Grid Research Institute Co Ltd filed Critical Southern Power Grid Digital Grid Research Institute Co Ltd
Priority to CN202211157357.1A priority Critical patent/CN115576657A/en
Publication of CN115576657A publication Critical patent/CN115576657A/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

Landscapes

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

Abstract

The invention provides a distributed transaction creating method, which comprises the following steps: creating a transaction group, namely calling a TxManager to create a transaction group object before a transaction initiator starts to execute a service code, and taking a transaction identifier Groupid; and adding the transaction group, namely notifying the transaction information to the TxManager after the participator executes the business method. Standard support for TX-LCN is provided, with both transaction initiators and participants belonging to TxClient. The TxManager acts as a controller of the distributed transaction and controls the whole transaction.

Description

Distributed transaction creating method
Technical Field
The invention relates to the field of database management, in particular to a distributed transaction creation method.
Background
Under the micro-service architecture, distributed transactions are a difficult point, the realization is complex, and commercial solutions and open source solutions exist.
In the prior art, in order to perform the desktop deployment in the main data, the service system retains the service data, and in order to ensure the consistency of the main data and the service data, a problem of distributed transaction is generated.
Disclosure of Invention
In view of the above, the present invention has been made to provide a distributed transaction creation method that overcomes or at least partially solves the above problems.
According to an aspect of the present invention, there is provided a distributed transaction creation method including:
creating a transaction group, namely calling a TxManager to create a transaction group object before a transaction initiator starts to execute a service code, and taking a transaction identifier Groupid;
and adding the transaction group, namely notifying the transaction information to the TxManager after the participator executes the business method.
Optionally, the method for creating further includes:
the notification of the transaction group means that the state of the execution result of the initiator is notified to the TxManager after the initiator executes the service code;
the TxManager informs the corresponding participating modules to submit and/or rollback the transaction according to the information of the final state and the transaction group of the transaction, and sends the return result to the transaction initiator.
Optionally, the transaction mode specifically includes: LCN mode, TCC mode, and TXC mode;
the LCN mode is to realize the operation of local affairs by means of acting on Connection in JDBC, and the TxManager uniformly coordinates and controls the affairs;
when the local transaction commits to roll back and/or close the connection, false operation is executed, and the connection of the proxy is managed by the LCN connection pool;
the TCC mode realizes distributed transaction by scheduling service logic, and comprises three operation steps: try to perform the business Try; confirm and carry out the business; cancel, cancel and carry out the business;
the TXC mode is to query the SQL influence data, save the executed SQL information and create a lock before executing SQL.
Optionally, the transaction mode further includes: distributed transactions of Seata;
the method specifically comprises the following steps: the transaction coordinator is used for maintaining the running state of the global transaction and is responsible for coordinating and driving the submission and/or rollback of the global transaction;
controlling the boundary of the global transaction, and being responsible for starting the global transaction and finally initiating a resolution of global submission and/or global rollback;
and controlling the branch transaction, taking charge of branch registration and state report, receiving an instruction of the transaction coordinator, and driving the submission and rollback of the branch transaction.
The invention provides a distributed transaction creating method, which comprises the following steps: creating a transaction group, namely calling a TxManager to create a transaction group object before a transaction initiator starts to execute a service code, and taking a transaction identifier Groupid; and adding the transaction group, namely notifying the transaction information to the TxManager after the participator executes the business method. Standard support for TX-LCN is provided, with both transaction initiators and participants belonging to TxClient. The TxManager is used as a controller of the distributed transaction to control the whole transaction.
The foregoing description is only an overview of the technical solutions of the present invention, and the embodiments of the present invention are described below in order to make the technical means of the present invention more clearly understood and to make the above and other objects, features, and advantages of the present invention more clearly understandable.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings used in the description of the embodiments will be briefly introduced below, and it is obvious that the drawings in the description below are only some embodiments of the present invention, and it is obvious for those skilled in the art that other drawings can be obtained according to the drawings without creative efforts.
Fig. 1 is a schematic flowchart of a distributed transaction creating method according to an embodiment of the present invention.
Detailed Description
Exemplary embodiments of the present disclosure will be described in more detail below with reference to the accompanying drawings. While exemplary embodiments of the present disclosure are shown in the drawings, it should be understood that the present disclosure may be embodied in various forms and should not be limited to the embodiments set forth herein. Rather, these embodiments are provided so that this disclosure will be thorough and complete, and will fully convey the scope of the disclosure to those skilled in the art.
The terms "comprises" and "comprising," and any variations thereof, in the present description and claims and drawings are intended to cover a non-exclusive inclusion, such as a list of steps or elements.
The technical solution of the present invention is further described in detail with reference to the accompanying drawings and embodiments.
As shown in FIG. 1, the TX-LCN consists of two major modules, txClient, txManager.
TxClient is used as a dependency framework of a module and provides standard support of TX-LCN, and a transaction initiator and a participant belong to TxClient. The TxManager is used as a controller of the distributed transaction to control the whole transaction.
Central content in theory
1) Creating the transaction group refers to a process of calling the TxManager to create a transaction group object before the transaction initiator starts to execute the business code, and then taking the transaction identifier Groupid.
2) And adding the transaction group, wherein adding the transaction group means that the participator notifies the transaction information of the module to the TxManager after executing the business method.
3) And the step of informing the transaction group means that after the initiator executes the service code, the TxManager is informed of the state of the execution result of the initiator, and the TxManager is used for informing the corresponding participating module to submit or rollback the transaction according to the final state of the transaction and the information of the transaction group, and returning the result to the transaction initiator.
TX-LCN transaction mode
Tx-LCN 5.0 begins to support three transaction modes, respectively: LCN, TCC, TXC mode.
Principle of LCN mode:
the LCN mode is to realize the operation of local transaction by means of the Connection in the proxy JDBC, and then the TxManager uniformly coordinates and controls the transaction. When a local transaction commits to roll back or close a connection, a dummy operation is performed and the proxy's connection is managed by the LCN connection pool.
The mode is characterized in that: the embeddability of the pattern into the code is low. The schema is limited to modules that have connection objects locally present and through which transactions can be controlled. The transaction submission and rollback in the mode are controlled by a local transaction party, and higher guarantee is provided for data consistency. The mode is disadvantageous in that the connection of the agent needs to be released along with the transaction initiator, increasing the time taken for the connection.
To summarize: the LCN schema fits all transaction-supported databases that can be connected with JDBC.
The TCC transaction mode principle includes:
the TCC transaction mechanism is characterized over the traditional transaction mechanism in that it does not rely on XA support by the Resource Manager (RM), but rather implements distributed transactions through the scheduling of the business logic (provided by the business system). The method mainly comprises three steps of Try, trying to execute the service, confirm to execute the service, cancel and Cancel to execute the service.
The mode characteristics include: the mode has high embeddability in the code, and each service needs to write more than two steps of operation. The mode can support the control of the existence of local affairs, and the use range is wider. The data consistency control is almost completely controlled by a developer, and the requirement on the difficulty of business development is high.
To summarize: tcc mode applies to all software that does not support XA transactions. For example: redis, mongodb.
The TXC transaction mode principles include: TXC mode naming comes from Taobao, and the implementation principle is that before SQL is executed, the influence data of the SQL is inquired, and then executed SQL information is stored and locks are created. These recorded data are used to rollback the database when rollback is required, and current lock implementations rely on redis distributed lock control.
The mode is characterized in that: the embeddability of the pattern into the code is also low. The mode is only supported by the module supporting the SQL mode. The schema consumes more resources and time than the LCN schema because it requires querying the impact data before each SQL execution. The schema does not occupy the connection resources of the database.
To summarize: can only be used in databases that support SQL. The resource consumption is high. The LCN mode is recommended.
Seata's distributed transaction solution is a business-level solution that relies only on the transaction capabilities of a single database. One distributed transaction in the Seata framework contains roles in 3:
transaction Coordinator (TC): and the transaction coordinator is used for maintaining the running state of the global transaction and is responsible for coordinating and driving the submission or rollback of the global transaction.
Transformation Manager (TM): controlling the boundary of the global transaction, and being responsible for starting a global transaction and finally initiating a resolution of global commit or global rollback.
Resource Manager (RM): and controlling branch transaction, taking charge of branch registration and state report, receiving the instruction of the transaction coordinator, and driving the submission and rollback of the branch transaction.
Execution flow of a distributed transaction in Seata:
the TM applies to the TC for opening a global transaction, the global transaction is successfully created, and a globally unique XID is generated.
The XID propagates in the context of the microservice call link.
The RM registers a branch transaction with the TC, then executes the branch transaction and commits (important: the RM has already performed local transaction commit/rollback in the first phase), and finally reports the execution result to the TC.
The TM initiates a global commit or rollback resolution based on the execution of all branch transactions in the TC.
The TC schedules all branch transactions governed under the XID to complete a commit or rollback request.
Has the beneficial effects that: and the reliability of the message data is realized from the aspect of application design development, the reliability of the message data does not depend on the message middleware, and the dependence on the characteristics of the MQ middleware is weakened. The scheme is light and easy to realize.
The above embodiments, objects, technical solutions and advantages of the present invention are further described in detail, it should be understood that the above embodiments are only examples of the present invention, and are not intended to limit the scope of the present invention, and any modifications, equivalent substitutions, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.

Claims (4)

1. A distributed transaction creation method, the creation method comprising:
creating a transaction group, namely calling a TxManager to create a transaction group object before a transaction initiator starts to execute a service code, and taking a transaction identifier Groupid;
and adding the transaction group, namely notifying the transaction information to the TxManager after the participator executes the business method.
2. The distributed transaction creation method of claim 1, wherein the method to create further comprises:
the notification of the transaction group means that the state of the execution result of the initiator is notified to the TxManager after the initiator executes the service code;
and the TxManager informs the corresponding participating modules to submit and/or rollback the transaction according to the final state of the transaction and the information of the transaction group, and sends a return result to the transaction initiator.
3. The distributed transaction creation method according to claim 1, wherein the transaction mode specifically includes: LCN mode, TCC mode, and TXC mode;
the LCN mode is to realize the operation of local affairs by means of proxying Connection in JDBC, and TxManager uniformly coordinates and controls affairs;
when the local transaction commits to roll back and/or close the connection, false operation is executed, and the connection of the proxy is managed by the LCN connection pool;
the TCC mode realizes distributed transaction by scheduling service logic, and comprises three operation steps: try to perform the business by the Try; confirm and carry out the business; cancel the execution service;
the TXC mode is to query the SQL influence data, save the executed SQL information and create a lock before executing SQL.
4. A distributed transaction creation method as recited in claim 1 wherein said transaction pattern further comprises: distributed transactions of Seata;
the method specifically comprises the following steps: the transaction coordinator is used for maintaining the running state of the global transaction and is responsible for coordinating and driving the submission and/or rollback of the global transaction;
controlling the boundary of the global transaction, and being responsible for starting the global transaction and finally initiating a resolution of global submission and/or global rollback;
and controlling branch transaction, taking charge of branch registration and state report, receiving the instruction of the transaction coordinator, and driving the submission and rollback of the branch transaction.
CN202211157357.1A 2022-09-22 2022-09-22 Distributed transaction creating method Pending CN115576657A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202211157357.1A CN115576657A (en) 2022-09-22 2022-09-22 Distributed transaction creating method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202211157357.1A CN115576657A (en) 2022-09-22 2022-09-22 Distributed transaction creating method

Publications (1)

Publication Number Publication Date
CN115576657A true CN115576657A (en) 2023-01-06

Family

ID=84580659

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202211157357.1A Pending CN115576657A (en) 2022-09-22 2022-09-22 Distributed transaction creating method

Country Status (1)

Country Link
CN (1) CN115576657A (en)

Similar Documents

Publication Publication Date Title
US9305047B2 (en) Commit-one-phase distributed transactions with multiple starting participants
CN107045454B (en) Cross-process distributed transaction control method and related system
US8396961B2 (en) Dynamic control of transaction timeout periods
US7900085B2 (en) Backup coordinator for distributed transactions
US6832238B1 (en) Local transaction management
CN103425225B (en) Application programmer in portable data device operating system and operation method thereof
US5956506A (en) System and method for functionally enhancing procedural software using objects
US20110055313A1 (en) Heuristic control of interposition in transactional systems
US9201919B2 (en) Bandwidth optimized two-phase commit protocol for distributed transactions
US7873604B2 (en) Batch recovery of distributed transactions
US20040230670A1 (en) Method and system for representing, configuring and deploying distributed applications
CN103995691B (en) Service state consistency maintenance method based on transactions
US20090300022A1 (en) Recording distributed transactions using probabalistic data structures
US20130132458A1 (en) System and method for managing participant order in distributed transactions
EP2196906B1 (en) Cluster-based business process management through eager displacement and on-demand recovery
US20040153349A1 (en) Delayed creation of global transactions
CN114996337A (en) Multi-cluster database management system and method
US20170153911A1 (en) Distributed transactions on mobile devices via a messaging service provided by a mobile network operator
CN114327799A (en) Distributed transaction processing method and device, electronic equipment and storage medium
CN114356596A (en) Message processing method and device for distributed system
CN109408201B (en) Transaction management method based on distributed database
CN113726828B (en) High concurrency trusted blockchain system and method supporting micro-services
GB2346990A (en) Client/server transaction processing system with automatic distributed co-ordinator set-up into a linear chain for use of linear commit optimisation
CN115576657A (en) Distributed transaction creating method
US20130239088A1 (en) Transactional object container

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