CN112395104A - Method and device for realizing transmission of distributed transaction context at routing layer - Google Patents

Method and device for realizing transmission of distributed transaction context at routing layer Download PDF

Info

Publication number
CN112395104A
CN112395104A CN202011276567.3A CN202011276567A CN112395104A CN 112395104 A CN112395104 A CN 112395104A CN 202011276567 A CN202011276567 A CN 202011276567A CN 112395104 A CN112395104 A CN 112395104A
Authority
CN
China
Prior art keywords
transaction
sub
layer
confirmation
routing
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.)
Granted
Application number
CN202011276567.3A
Other languages
Chinese (zh)
Other versions
CN112395104B (en
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.)
Industrial and Commercial Bank of China Ltd ICBC
Original Assignee
Industrial and Commercial Bank of China Ltd ICBC
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 Industrial and Commercial Bank of China Ltd ICBC filed Critical Industrial and Commercial Bank of China Ltd ICBC
Priority to CN202011276567.3A priority Critical patent/CN112395104B/en
Publication of CN112395104A publication Critical patent/CN112395104A/en
Application granted granted Critical
Publication of CN112395104B publication Critical patent/CN112395104B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

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/54Interprogram communication
    • G06F9/545Interprogram communication where tasks reside in different layers, e.g. user- and kernel-space
    • 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)
  • Telephonic Communication Services (AREA)
  • Data Exchanges In Wide-Area Networks (AREA)

Abstract

The invention provides a method and a device for realizing the transmission of a distributed transaction context in a routing layer, wherein the method comprises the following steps: registering, in the transaction manager, an ID of a sub-transaction under the master transaction; and calling the method of the try phase to the sub-transaction so that the sub-transaction executes calling according to the type of the sub-transaction, wherein the type of the sub-transaction comprises the following steps: normal TCC service and routing service; and initiating a two-stage confirmation through the transaction manager after the call is successfully executed. The method and the device have the advantages that the transaction context is transmitted to the lower-layer sub-transaction of the routing service in a compatible and adaptive mode, and accordingly data consistency among a plurality of service nodes is guaranteed.

Description

Method and device for realizing transmission of distributed transaction context at routing layer
Technical Field
The present application belongs to the field of distributed system processing technology, and in particular, to a method and an apparatus for implementing transfer of a distributed transaction context at a routing layer.
Background
In a distributed transaction, the participants of the transaction, the servers supporting the transaction, the resource servers and the transaction manager are located on different nodes of the distributed system, and a routing service exists in the transaction link of part of the applications, namely the service is not a transaction call but is used as a middle layer to call other transaction services. TCC (Try-Confirm-Cancel) is a distributed transaction model used in the industry, which can solve the problem of distributed transactions after the architecture transformation, and provide high performance while ensuring isolation. Through the decomposition of the business logic, the TCC mode decomposes the business logic into two phases, wherein one phase is a try phase, and the two phases are a confirm or cancel phase:
and Try, completing all service checks, reserving necessary service resources, and ensuring that the Confirm can be successful after the Try is completed.
Confirm-really executed service logic, do not make any service check, only use the reserved service resources in try phase.
Cancel, releasing the reserved traffic resources in the try phase.
However, in a transaction link invoked by an application, except for a normal transaction, a routing service may be invoked, and the routing service initiates invocation of a lower-layer transaction, so that a transaction framework needs to provide compatibility capability, and a transaction context is transparently transferred to a lower-layer sub-transaction of the routing service in a compatible adaptation manner, thereby ensuring data consistency among a plurality of service nodes.
Disclosure of Invention
The application provides a method and a device for realizing the transmission of a distributed transaction context in a routing layer, which are used for solving the problem of compatibility and adaptation of a frame under the condition that a routing layer service exists in a transaction link under a two-stage distributed transaction frame.
According to one aspect of the present application, an implementation method for a distributed transaction context passing at a routing layer is provided, which includes:
registering, in the transaction manager, an ID of a sub-transaction under the master transaction;
and calling the method of the try phase to the sub-transaction so that the sub-transaction executes calling according to the type of the sub-transaction, wherein the type of the sub-transaction comprises the following steps: normal TCC service and routing service;
and initiating a two-stage confirmation through the transaction manager after the call is successfully executed.
In one embodiment, the invocation of the method to perform the try phase on the sub-transaction includes:
for the single-layer sub-transaction, directly calling the method;
for multiple layers of sub-transactions, the sub-transaction of the current layer is determined by localtxld, and localtxld in the context of the transaction is set to the ID of the next layer of sub-transaction when the next layer of sub-transaction is invoked.
In one embodiment, invoking the method of the try phase on the sub-transaction further comprises:
when all child transaction calls are complete, localtxld in the recovery transaction context is the ID of the child transaction at the current level.
In one embodiment, initiating a two-phase validation by the transaction manager after the call execution is successful comprises:
putting the ID of the called sub-transaction into localTxId in the transaction context and resetting the method field of the transaction context;
aiming at the sub-affairs of the routing service type, obtaining a method name in the try method field information, and finding a two-stage calling method according to the method name;
the transaction information is passed to the sub-transaction through the reflected call route so that the sub-transaction performs a two-phase validation according to the two-phase call method.
In one embodiment, initiating a two-phase validation by the transaction manager after the call execution is successful further comprises:
aiming at the sub-transaction of the common TCC service type, a two-stage method is obtained as a confirmation method of the sub-transaction;
the lost article information is passed to the sub-transaction by reflection call routing so that the sub-transaction performs a two-phase validation according to the validation method.
According to another aspect of the present application, there is also provided a method for implementing transfer of a distributed transaction context at a routing layer, including:
performing pre-processing according to the call initiated by the main transaction;
judging the type of the host, and executing the calling initiated by the main affair by adopting a corresponding method;
after the calling execution is completed, recovering localTxId in the transaction context and sending calling completion information to the main transaction so that the main transaction initiates two-stage confirmation;
and judging the type of the sub-transaction according to the two-stage confirmation initiated by the main transaction, and executing the two-stage confirmation by adopting a corresponding confirmation execution method according to the judgment result.
In one embodiment, determining the type of the self-transaction and executing the call initiated by the main transaction by using a corresponding method includes:
if the type of the self is routing service, executing a transmit method to complete calling;
if the type of the try method is the common TCC service, the try method is executed to complete the calling.
In one embodiment, the determining the type of the sub-transaction according to the two-stage validation initiated by the main transaction, and executing the two-stage validation according to the determination result by using a corresponding validation execution method includes:
inquiring the sub-transaction directly called under the current transaction layer;
if the type of the sub-transaction is the routing service, executing a confirmation method of the sub-transaction and verifying whether the sub-transaction is a routing method;
if the sub-transaction type is normal TCC service, executing the confirmation method of the next layer of sub-transaction and then executing the confirmation method of the current layer of sub-transaction.
According to another aspect of the present application, there is also provided an apparatus for implementing a distributed transaction context passing at a routing layer, including:
a sub-transaction ID registration unit operable to register an ID of a sub-transaction under the master transaction in the transaction manager;
and the method calling unit in the Try phase is used for calling the method in the Try phase on the sub-transaction so that the sub-transaction executes calling according to the type of the sub-transaction, and the type of the sub-transaction comprises the following steps: normal TCC service and routing service;
and the two-stage confirmation unit is used for initiating two-stage confirmation through the transaction manager after the call execution is successful.
In one embodiment, the method call unit of the Try phase comprises:
the single-layer sub-transaction processing module is used for directly calling the method for the single-layer sub-transaction;
and the multi-layer sub-transaction processing module is used for determining the sub-transaction of the current layer through the localTxId for the multi-layer sub-transaction, and setting the localTxId in the transaction context as the ID of the next-layer sub-transaction when the next-layer sub-transaction is called.
In one embodiment, the method call unit in the Try phase further includes:
and the recovery module is used for recovering the localtxId in the transaction context as the ID of the sub-transaction at the current layer when all the sub-transaction calls are completed.
In one embodiment, the two-stage validation unit includes:
the reset module is used for putting the ID of the called sub-transaction into localTxId in the transaction context and resetting the method field of the transaction context;
the two-stage calling and searching module is used for acquiring the method name in the try method field information aiming at the sub-transaction of the routing service type and finding the two-stage calling method according to the method name;
and the confirmation module is used for transmitting the transaction information to the sub-transaction through the reflection calling route so that the sub-transaction executes two-stage confirmation according to the two-stage calling method.
In one embodiment, the two-stage validation unit further comprises:
the confirmation method acquisition module is used for acquiring a two-stage method as a confirmation method of the sub-transaction aiming at the sub-transaction of the common TCC service type;
and the two-stage confirmation execution module is used for transmitting the lost article information to the sub-transaction through the reflection call route so that the sub-transaction executes two-stage confirmation according to the confirmation method.
According to another aspect of the present application, there is also provided an apparatus for implementing a distributed transaction context passing at a routing layer, including:
the pre-processing unit is used for carrying out pre-processing according to the call initiated by the main transaction;
the calling initiating unit is used for judging the type of the calling initiating unit and executing calling initiated by the main affair by adopting a corresponding method;
the recovery confirmation unit is used for recovering the localtxId in the transaction context and sending the call completion information to the main transaction after the call execution is completed so as to enable the main transaction to initiate two-stage confirmation;
and the judging and confirming unit is used for judging the type of the sub-transaction according to the two-stage confirmation initiated by the main transaction and executing the two-stage confirmation by adopting a corresponding confirmation execution method according to the judgment result.
In one embodiment, the call initiation unit includes:
the routing calling module is used for executing a transmit method to complete calling if the type of the routing calling module is routing service;
and the common calling module is used for executing the try method to complete calling if the type of the common calling module is common TCC service.
In one embodiment, the determination confirming unit includes:
the query module is used for querying the sub-transaction directly called under the current transaction layer;
the route confirmation module is used for executing a confirmation method of the sub-transaction and verifying whether the sub-transaction is a routing method if the type of the sub-transaction is the routing service;
and the common confirmation module is used for executing the confirmation method of the next layer of sub-transaction and then executing the confirmation method of the current layer of sub-transaction if the type of the sub-transaction is the common TCC service.
The method comprises the steps of analyzing the transaction type on the annotation when the annotation stage is generated through service starting, storing the information of the transmission type transaction as the information of a special two-stage TCC sub-transaction in a memory, executing a transmit method in a try method, and transferring the TCC transaction context to the lower-layer sub-transaction of the routing service as the special TCC sub-transaction in the two-stage house type method stored in the memory when the confirm method or the cancel method is executed in two stages.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, it is obvious that the drawings in the following description are only some embodiments of the present invention, and for those skilled in the art, other drawings can be obtained according to the drawings without creative efforts.
Fig. 1 is a diagram of a TCC distributed transaction system architecture in the present application.
Fig. 2 is a flowchart of an implementation method for transferring a distributed transaction context at a routing layer according to the present application.
FIG. 3 is a call flow diagram of a method for performing a try phase on a sub-transaction in an embodiment of the present application.
Fig. 4 is a flow chart of initiating two-phase validation by the transaction manager after the call execution is successful in the embodiment of the present application.
FIG. 5 is a flow diagram illustrating initiation of a two-phase acknowledgement by the transaction manager after successful execution of a call in another embodiment of the present application.
Fig. 6 is a flowchart of another implementation method for transferring a distributed transaction context at a routing layer according to the present application.
Fig. 7 is a call flow diagram of executing a main transaction initiation by using a corresponding method in the embodiment of the present application.
Fig. 8 is a flowchart illustrating a method for performing two-stage validation according to a determination result in the embodiment of the present application.
Fig. 9 is a block diagram of an implementation apparatus for transferring a distributed transaction context at a routing layer according to the present application.
Fig. 10 is a block diagram of a method call unit in the Try phase in the embodiment of the present application.
Fig. 11 is a block diagram of a two-stage validation unit according to an embodiment of the present application.
FIG. 12 is a block diagram of a two-stage validation unit according to another embodiment of the present application.
Fig. 13 is a specific implementation of an electronic device in an embodiment of the present application.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Based on the description in the background art, in order to solve the problem of transparent transmission of the transaction context when the routing service exists in the transaction link in the TCC mode, the intermediate node providing the routing service can transmit the transaction context to the lower layer by avoiding redundant service splitting, and the application provides a method for realizing transmission of the distributed transaction context at the routing layer.
Before introducing the method provided by the present application, a service invocation system is introduced, and as shown in fig. 1, each service node includes the following modules: a transaction manager, a resource manager and a front processor.
Transaction manager (Transactionmanager, TM): and creating and updating the states of the main transaction and the sub-transaction, and controlling to initiate two phases of confirm/cancel.
Resource Manager (RM): the starting phase stores a one-stage try method and two-stage call confirm, cancel methods and parameter related information in a resoureHolder. Persistent writing of the database during the service call phase.
Service pre-processor (PreProcessor): the transaction calls context information processing, including receiving and cleaning context.
Each service node service records its directly invoked sub-transactions, and each service node's TM can only coordinate its direct sub-transactions, e.g., in FIG. 1, service node A only knows that the sub-transactions of B and C also only need to record B, C two sub-transactions. But B knows the child transaction D and C knows the child transaction E, F and therefore can recursively reconcile. The service node of the transaction initiator needs to record both the main transaction and the sub-transactions it directly invokes, e.g., initiator a needs to record B, C the main transaction a and the sub-transactions it contains. The method of the transaction initiator needs to add a main transaction cut annotation @ DTX, and the transaction participant needs to add a sub-transaction cut annotation @ Action.
Each service node comprises the following modules: a transaction manager and a resource manager. Where A is the transaction initiator and A has B, C two sub-transactions, where transaction B is a routing service with no transaction calls within its method, but will invoke the transaction service D below it. The services C, D, E, F are all normal TCC sub-transactions, with C nesting two sub-transactions, D and E.
As shown in fig. 2, an implementation method for transferring a distributed transaction context with a transaction initiator (master transaction) as an execution subject at a routing layer provided by the present application includes:
s201: the ID of the sub-transaction under the master transaction is registered in the transaction manager.
In the service starting phase, generating an automatic proxy object for the service bean, specifically comprising: and judging the type of the sub-transaction according to the comment @ Action added on the service bean implementation interface. If the type field of the @ Action annotation has no type set, then it is a normal TCC sub-transaction service by default, and if it is a routing service, then it is annotated as @ TCC Action (type ═ subtxtype. If the service is the ordinary sub-transaction service, the resource manager records the service target object (the proxied object), the try method, the confirm method name and the cancel method name in the memory object resourceHolder. If the routing service is adopted, the service target object is recorded in the resourceHolder, the transmit method is recorded in the resourceHolders, and the parts of the try method name and the confirm method name are recorded as the transmit method name.
The service initiation phase is followed by a phase of transaction initiation, where the transaction initiator enters the master transaction slot and obtains the master transaction ID, i.e., globaltxld, from the transaction manager. The globalttxid will be propagated in the transaction link to distinguish between sub-transactions belonging to the same master transaction. For example, in the system fig. 1, a records the main transaction information, and enters the main transaction method after the recording is completed, so as to execute the service transaction.
S202: and calling the method of the try phase to the sub-transaction so that the sub-transaction executes calling according to the type of the sub-transaction, wherein the type of the sub-transaction comprises the following steps: normal TCC service and routing service.
In one embodiment, as shown in FIG. 3, the invocation of the method to perform the try phase on the sub-transaction includes:
s301: for single-layer sub-transactions, the method is directly called.
S302: for multiple layers of sub-transactions, the sub-transaction of the current layer is determined by localtxld, and localtxld in the context of the transaction is set to the ID of the next layer of sub-transaction when the next layer of sub-transaction is invoked.
In a specific embodiment, the initiator sub-transaction section registers the next layer of sub-transactions through the transaction manager, records the call of the method of the try phase of the initiator transaction, and transmits the context to the caller of the sub-transaction through the RPC interface. For nested multiple layers of sub-transactions, each layer determines the transaction of the current layer by localtxId, and sets localtxId in the context to the transaction ID of the sub-transaction, namely, SubTxId, when the next layer of sub-transaction is called.
In one embodiment, invoking the method of the try phase on the sub-transaction further comprises:
when all child transaction calls are complete, localtxld in the recovery transaction context is the ID of the child transaction at the current level.
In one embodiment, the localtxld in the reconverting context after all child transaction calls are completed is the transaction ID of the current transaction layer. And calling a child transaction try method, wherein a transaction calling chain reaches a child transaction side, namely a provider side. For example, in the system diagram 1, a service caller a first enters a transaction B, records a main transaction B on the tangent plane side of the caller, initiates a call to a method in the try phase of B when the recording is successful, and updates the localTxId of the context to the substxid corresponding to the sub-transaction B when a remote service call is initiated. The transaction B proceeds to the next link try phase and performs a similar operation after completing the transaction C.
S203: and initiating a two-stage confirmation through the transaction manager after the call is successfully executed.
In one embodiment, initiating a two-phase validation by the transaction manager after the call execution succeeds, as shown in FIG. 4, includes:
s401: the ID of the invoked sub-transaction is placed in localTxId in the transaction context and the method field of the transaction context is reset.
S402: and aiming at the sub-transactions of the routing service type, acquiring the method name in the try method field information, and finding a two-stage calling method according to the method name.
S403: the transaction information is passed to the sub-transaction through the reflected call route so that the sub-transaction performs a two-phase validation according to the two-phase call method.
In one embodiment, the transaction manager of the initiator cycles through two-phase confirm calls for each sub-transaction: each sub-transaction ID in the table is put into LocalTxId in the context and the method field that sets the context is set to method. For example, the transaction manager of A initiates a two-stage confirm call, which first queries the local database for sub-transaction B and sub-transaction C, and then initiates the confirm call of the bottle opener transaction. For the routing sub-transaction B, a method name stored in the try method field information and parameter information stored in the parameter field are obtained, a two-stage calling method name in resource holder, namely a transmit method, is found according to the try method name, and the routing method is called through reflection, so that the transaction information is downloaded to a transaction link, namely to the sub-transaction B.
In an embodiment, initiating a two-phase validation by the transaction manager after the call execution succeeds, as shown in fig. 5, further includes:
s501: aiming at the sub-transaction of the common TCC service type, a two-phase method is obtained and is a confirmation method of the sub-transaction.
S502: the lost article information is passed to the sub-transaction by reflection call routing so that the sub-transaction performs a two-phase validation according to the validation method.
In a specific embodiment, if the sub-transaction C is a normal sub-transaction C, the two-phase method acquired from the resourceHolder is a confirm method of the C-transaction, and the transaction link is also transferred to the sub-transaction C through a reflection call, and the transaction is executed to the service provider side in the call chain.
From the perspective of a service provider, taking the service provider as an execution subject, the implementation method for delivering a distributed transaction context at a routing layer provided by the present application is, as shown in fig. 6, including:
s601: preprocessing is performed according to the call initiated by the master transaction.
S602: judging the type of the host, and executing the call initiated by the main transaction by adopting a corresponding method.
S603: after the call execution is complete, the localtxld in the transaction context is restored and call completion information is sent to the master transaction so that the master transaction initiates a two-phase validation.
S604: and judging the type of the sub-transaction according to the two-stage confirmation initiated by the main transaction, and executing the two-stage confirmation by adopting a corresponding confirmation execution method according to the judgment result.
In an embodiment, the determining the type of the self-transaction and executing the call initiated by the main transaction by using the corresponding method, as shown in fig. 7, includes:
s701: and if the type of the self is the routing service, executing a transmit method to complete calling.
S702: if the type of the try method is the common TCC service, the try method is executed to complete the calling.
In an embodiment, the determining the type of the sub-transaction according to the two-stage validation initiated by the main transaction, and performing the two-stage validation according to the determination result by using a corresponding validation execution method, as shown in fig. 8, includes:
s801: and inquiring the sub-transaction directly called under the current transaction layer.
S802: if the type of the sub-transaction is a routing service, a validation method of the sub-transaction is performed and it is verified whether itself is a routing method.
S803: if the sub-transaction type is normal TCC service, executing the confirmation method of the next layer of sub-transaction and then executing the confirmation method of the current layer of sub-transaction.
In a specific embodiment, a pre-processor of a service provider receives a context called by the service provider, judges whether globalttxid is lost, throws out an execution exception if the globalttxid is lost, clears a method calling parameter, the context and the like, and terminates downward transmission of a transaction link. Meanwhile, the pre-processor sets the flag aopFlag of the transaction context to false, and when entering the section of the provider, the pre-processor directly executes the target method by judging the flag aopFlag if the flag aopFlag is false, so that the transaction information of the current transaction layer is not repeatedly and durably recorded, and meanwhile, the aopFlag is set back to true, so that the sub-transaction section called by the pre-processor is enabled to take effect. After the pre-processing is completed, the try method of executing the sub-transaction is used, the routing service is used as a special sub-transaction, and the try phase is executed as the transmit method of the routing service. For example, a calls the method of the try phase of B or C, initiates a remote call, the pre-processor at B, C on the provider side first parses out the context information from the call parameters, and if globaltxld is lost, throws the exception. If the routing service is B, a transmit method is executed, and if the routing service is C, a try method is executed, and the routing service and the normal TCC sub-transaction service are processed in the same phase. For the case of lower level nesting, it is also similar to the A call B, C. Returning to the service consumer's profile, restoring the context of that layer, restoring the localtxld of the context to the transaction ID of the current transaction call layer, and if it is the end of transaction a call B, C, restoring the localtxld in the context to the transaction ID of transaction a. And in the try stage, the leaf nodes are reached from top to bottom from the transaction initiator, if the process is abnormal, the leaf nodes are thrown layer by layer from bottom to top, and if the leaf nodes are not abnormally thrown, the leaf nodes are successfully thrown. If the service call is abnormal, the service call is thrown to the upper layer to the main affair, and the cancel call is initiated by the affair manager of the main affair. When the sub-transaction of the lower layer is successful (without exception throwing) and the transaction method of the layer is successfully executed, the transaction of the layer is successful.
Based on the same inventive concept, the embodiment of the present application further provides an implementation apparatus for transferring a distributed transaction context at a routing layer, which can be used to implement the method described in the foregoing embodiment, as described in the following embodiments. Because the principle of the implementation apparatus for transferring the distributed transaction context at the routing layer to solve the problem is similar to the implementation method for transferring the distributed transaction context at the routing layer, the implementation of the implementation apparatus for transferring the distributed transaction context at the routing layer can refer to the implementation of the implementation method for transferring the distributed transaction context at the routing layer, and repeated details are not repeated. As used hereinafter, the term "unit" or "module" may be a combination of software and/or hardware that implements a predetermined function. While the system described in the embodiments below is preferably implemented in software, implementations in hardware, or a combination of software and hardware are also possible and contemplated.
With a transaction initiator as an execution subject, the present application provides an implementation apparatus for transferring a distributed transaction context at a routing layer, as shown in fig. 9, including:
a sub-transaction ID registration unit 901 for registering the ID of a sub-transaction under the master transaction in the transaction manager;
and a method calling unit 902 in the Try phase, configured to make a call to the method in the Try phase on the sub-transaction, so that the sub-transaction performs the call according to its type, where the type of the sub-transaction includes: normal TCC service and routing service;
and a two-phase confirmation unit 903, configured to initiate a two-phase confirmation through the transaction manager after the call is successfully executed.
In one embodiment, as shown in fig. 10, the method call unit 902 of the Try phase includes:
a single-layer sub-transaction processing module 1001, configured to directly call a method for a single-layer sub-transaction;
the multi-layer sub-transaction processing module 1002 is configured to determine, for multiple layers of sub-transactions, a sub-transaction at a current layer through localTxId, and set localTxId in a context of a transaction as an ID of a next layer of sub-transaction when a next layer of sub-transaction is invoked.
In one embodiment, the method call unit in the Try phase further includes:
and the recovery module is used for recovering the localtxId in the transaction context as the ID of the sub-transaction at the current layer when all the sub-transaction calls are completed.
In one embodiment, as shown in FIG. 11, the two-stage validation unit 903 comprises:
a reset module 1101, configured to put the ID of the called sub-transaction into localTxId in the transaction context and reset the method field of the transaction context;
a two-stage calling and searching module 1102, configured to obtain, for a sub-transaction of the routing service type, a method name in the try method field information, and find a two-stage calling method according to the method name;
a confirmation module 1103, configured to pass the transaction information to the sub-transaction through the reflection call route, so that the sub-transaction performs two-phase confirmation according to the two-phase call method.
In one embodiment, as shown in fig. 12, the two-stage verification unit 903 further includes:
a confirmation method obtaining module 1201, configured to, for a sub-transaction of a common TCC service type, obtain a two-phase method as a confirmation method for the sub-transaction;
and a two-stage confirmation execution module 1202, configured to transfer the loss information to the sub-transaction through a reflection call route, so that the sub-transaction executes two-stage confirmation according to the confirmation method.
The invention provides a system and a method for transaction cross-service transmission compatible adaptation, which aims to solve the problem of compatible adaptation of a frame under the condition that a routing layer service exists in a transaction link under a two-stage distributed transaction frame and transmit a transaction context to a lower-layer sub-transaction of the routing service. Analyzing the transaction type on the annotation when the annotation phase is started by the service to generate the automatic agent, storing the information of the transmission type transaction as the information of a special two-phase TCC sub-transaction in a memory, executing a transmit method in a try method in one phase, calling the transmit method in a two-phase attribute method stored in the memory as the special TCC sub-transaction when a confirm method or a cancel method is executed in two phases, and transmitting the TCC transaction context to the lower-layer sub-transaction of the routing service. The method does not need a null confirm method and a cancel method written by a routing service provider, has small business invasion to the routing service and does not need meaningless logic splitting.
As will be appreciated by one skilled in the art, embodiments of the present invention may be provided as a method, system, or computer program product. Accordingly, the present invention may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, the present invention may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and the like) having computer-usable program code embodied therein.
The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be stored in a computer-readable memory that can direct a computer or other programmable data processing apparatus to function in a particular manner, such that the instructions stored in the computer-readable memory produce an article of manufacture including instruction means which implement the function specified in the flowchart flow or flows and/or block diagram block or blocks.
These computer program instructions may also be loaded onto a computer or other programmable data processing apparatus to cause a series of operational steps to be performed on the computer or other programmable apparatus to produce a computer implemented process such that the instructions which execute on the computer or other programmable apparatus provide steps for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
The principle and the implementation mode of the invention are explained by applying specific embodiments in the invention, and the description of the embodiments is only used for helping to understand the method and the core idea of the invention; meanwhile, for a person skilled in the art, according to the idea of the present invention, there may be variations in the specific embodiments and the application scope, and in summary, the content of the present specification should not be construed as a limitation to the present invention.
An embodiment of the present application further provides a specific implementation manner of an electronic device capable of implementing all steps in the method in the foregoing embodiment, and referring to fig. 13, the electronic device specifically includes the following contents:
a processor (processor)1301, a memory 1302, a Communications Interface (Communications Interface)1303, a bus 1304, and a non-volatile memory 1305;
the processor 1301, the memory 1302 and the communication interface 1303 complete communication with each other through the bus 1304;
the processor 1301 is configured to call the computer programs in the memory 1302 and the non-volatile storage 1305, and the processor implements all the steps of the method in the above embodiments when executing the computer programs, for example, the processor implements all the steps of the method when executing the computer programs.
Embodiments of the present application also provide a computer-readable storage medium capable of implementing all the steps of the method in the above embodiments, and the computer-readable storage medium stores thereon a computer program, which when executed by a processor implements all the steps of the method in the above embodiments, for example, the processor implements all the steps of the method when executing the computer program.
The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the hardware + program class embodiment, since it is substantially similar to the method embodiment, the description is simple, and the relevant points can be referred to the partial description of the method embodiment. Although embodiments of the present description provide method steps as described in embodiments or flowcharts, more or fewer steps may be included based on conventional or non-inventive means. The order of steps recited in the embodiments is merely one manner of performing the steps in a multitude of orders and does not represent the only order of execution. When an actual apparatus or end product executes, it may execute sequentially or in parallel (e.g., parallel processors or multi-threaded environments, or even distributed data processing environments) according to the method shown in the embodiment or the figures. The terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, the presence of additional identical or equivalent elements in a process, method, article, or apparatus that comprises the recited elements is not excluded. For convenience of description, the above devices are described as being divided into various modules by functions, and are described separately. Of course, in implementing the embodiments of the present description, the functions of each module may be implemented in one or more software and/or hardware, or a module implementing the same function may be implemented by a combination of multiple sub-modules or sub-units, and the like. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one logical division, and other divisions may be realized in practice, for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection through some interfaces, devices or units, and may be in an electrical, mechanical or other form. The present invention is described with reference to flowchart illustrations and/or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of the invention. It will be understood that each flow and/or block of the flow diagrams and/or block diagrams, and combinations of flows and/or blocks in the flow diagrams and/or block diagrams, can be implemented by computer program instructions. These computer program instructions may be provided to a processor of a general purpose computer, special purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, create means for implementing the functions specified in the flowchart flow or flows and/or block diagram block or blocks.
As will be appreciated by one skilled in the art, embodiments of the present description may be provided as a method, system, or computer program product. Accordingly, embodiments of the present description may take the form of an entirely hardware embodiment, an entirely software embodiment or an embodiment combining software and hardware aspects. Furthermore, embodiments of the present description may take the form of a computer program product embodied on one or more computer-usable storage media (including, but not limited to, disk storage, CD-ROM, optical storage, and so forth) having computer-usable program code embodied therein. The embodiments in the present specification are described in a progressive manner, and the same and similar parts among the embodiments are referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, for the system embodiment, since it is substantially similar to the method embodiment, the description is simple, and for the relevant points, reference may be made to the partial description of the method embodiment. In the description herein, references to the description of the term "one embodiment," "some embodiments," "an example," "a specific example," or "some examples," etc., mean that a particular feature, structure, material, or characteristic described in connection with the embodiment or example is included in at least one embodiment or example of an embodiment of the specification.
In this specification, the schematic representations of the terms used above are not necessarily intended to refer to the same embodiment or example. Furthermore, various embodiments or examples and features of different embodiments or examples described in this specification can be combined and combined by one skilled in the art without contradiction. The above description is only an example of the embodiments of the present disclosure, and is not intended to limit the embodiments of the present disclosure. Various modifications and variations to the embodiments described herein will be apparent to those skilled in the art. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the embodiments of the present specification should be included in the scope of the claims of the embodiments of the present specification.

Claims (18)

1. A method for implementing the transfer of a distributed transaction context at a routing layer is characterized by comprising the following steps:
registering, in the transaction manager, an ID of a sub-transaction under the master transaction;
and calling the method of the try phase to the sub-transaction so that the sub-transaction executes calling according to the type of the sub-transaction, wherein the type of the sub-transaction comprises the following steps: normal TCC service and routing service;
and initiating a two-stage confirmation through the transaction manager after the call is successfully executed.
2. The method of claim 1, wherein the invoking of the try-phase method on the sub-transaction comprises:
for the single-layer sub-transaction, directly calling the method;
for multiple layers of sub-transactions, the sub-transaction at the current layer is determined by localtxld, and when the next layer of sub-transaction is called, localtxld in the transaction context is set to the ID of the next layer of sub-transaction, and the transaction context is passed down from the link by the call to the sub-transaction.
3. The method of claim 2, wherein the invoking of the try-phase method on the sub-transaction further comprises:
when all sub-transaction calls for this layer are complete, localtxld in the recovery transaction context is the ID of the sub-transaction for the current layer.
4. The method for implementing distributed transaction context passing at routing layer according to claim 1, wherein the initiating a two-phase confirmation by the transaction manager after the call is successfully executed comprises:
putting the ID of the called sub-transaction into localTxId in the transaction context and resetting the method field of the transaction context;
aiming at the sub-affairs of the routing service type, obtaining a method name in the try method field information, and finding a two-stage calling method stored in a memory according to the method name;
and transferring the transaction information to the sub-transaction by a reflection calling routing method so that the sub-transaction executes two-phase confirmation according to the two-phase calling method.
5. The method for implementing distributed transaction context passing at the routing layer according to claim 1, wherein the initiating a two-phase acknowledgement by the transaction manager after the call is successfully executed further comprises:
aiming at the sub-transaction of the common TCC service type, a two-stage method is obtained as a confirmation method of the sub-transaction;
and transferring the transaction information to the sub-transaction by calling a two-phase method through reflection so that the sub-transaction executes two-phase confirmation according to the confirmation method.
6. A method for implementing the transfer of a distributed transaction context at a routing layer is characterized by comprising the following steps:
performing pre-processing according to the call initiated by the main transaction;
judging the type of the host, and executing the calling initiated by the main affair by adopting a corresponding method;
after the calling execution is completed, recovering localTxId in the transaction context and sending calling completion information to the main transaction so that the main transaction initiates two-stage confirmation;
and judging the type of the sub-transaction according to the two-stage confirmation initiated by the main transaction, and executing the two-stage confirmation by adopting a corresponding confirmation execution method according to the judgment result.
7. The method for implementing distributed transaction context transfer at routing layer according to claim 6, wherein the determining the type of the self-transaction and executing the call initiated by the main transaction by using the corresponding method includes:
if the type of the self is routing service, executing a transmit method to complete calling;
if the type of the try method is the common TCC service, the try method is executed to complete the calling.
8. The method for implementing context transfer of distributed transaction at routing layer according to claim 6, wherein the determining the type of the sub-transaction according to the two-stage validation initiated by the main transaction and executing the two-stage validation according to the determination result by using the corresponding validation executing method comprises:
inquiring the sub-transaction directly called under the current transaction layer;
if the type of the sub-transaction is the routing service, executing the confirmation method of the sub-transaction and verifying whether the sub-transaction is the routing method, if the sub-transaction is the routing method, directly returning null when executing the confirmation method of the current layer through setting and judging of a zone bit, namely, not needing to execute;
if the sub-transaction type is normal TCC service, executing the confirmation method of the next layer of sub-transaction and then executing the confirmation method of the current layer of sub-transaction.
9. An apparatus for implementing a distributed transaction context passing at a routing layer, comprising:
the transaction manager comprises a sub-transaction information registration unit, a transaction manager and a transaction management unit, wherein the sub-transaction information registration unit is used for registering the ID of the sub-transaction under the main transaction and the try method related information of the sub-transaction into the database;
and the method calling unit in the Try phase is used for calling the method in the Try phase on the sub-transaction so that the sub-transaction executes calling according to the type of the sub-transaction, and the type of the sub-transaction comprises the following steps: normal TCC service and routing service;
and the two-stage confirmation unit is used for initiating two-stage confirmation through the transaction manager after the call execution is successful.
10. The apparatus for implementing distributed transaction context passing at routing layer according to claim 9, wherein the method call unit of the Try phase comprises:
the single-layer sub-transaction processing module is used for directly calling the method for the single-layer sub-transaction;
and the multi-layer sub-transaction processing module is used for determining the sub-transaction of the current layer through the localTxId for the multi-layer sub-transaction, and setting the localTxId in the transaction context as the ID of the next-layer sub-transaction when the next-layer sub-transaction is called.
11. The apparatus for implementing distributed transaction context passing at routing layer according to claim 10, wherein the method call unit of the Try phase further comprises:
and the recovery module is used for recovering the localtxId in the transaction context as the ID of the sub-transaction at the current layer when all the sub-transaction calls are completed.
12. The apparatus for implementing distributed transaction context transfer at a routing layer according to claim 9, wherein the two-stage validation unit comprises:
the reset module is used for putting the ID of the called sub-transaction into localTxId in the transaction context and resetting the method field of the transaction context;
the two-stage calling discovery searching module is used for acquiring the method name in the try method field information aiming at the sub-transaction of the routing service type and finding the two-stage calling method according to the method name;
and the confirmation module is used for transferring the transaction information to the routing sub-transaction layer by the routing method consumer, namely the current transaction layer, calling the two-phase method of the routing transaction through reflection so as to enable the routing method provider to execute two-phase confirmation according to the two-phase calling method.
13. The apparatus for implementing distributed transaction context transfer at a routing layer according to claim 9, wherein the two-stage validation unit further comprises:
the confirmation method acquisition module is used for acquiring a two-stage method as a confirmation method of the sub-transaction aiming at the sub-transaction of the common TCC service type;
and the two-stage confirmation execution module is used for transmitting the transaction information to the sub-transaction layer by the sub-transaction two-stage method consumer, namely the current transaction layer calling the two-stage method of the transaction through reflection, so that the sub-transaction two-stage method provider executes two-stage confirmation according to the confirmation method.
14. An apparatus for implementing a distributed transaction context passing at a routing layer, comprising:
the pre-processing unit is used for carrying out pre-processing according to the call initiated by the main transaction;
the calling initiating unit is used for judging the type of the calling initiating unit and executing calling initiated by the main affair by adopting a corresponding method;
the recovery confirmation unit is used for recovering the localtxId in the transaction context and sending the call completion information to the main transaction after the call execution is completed so as to enable the main transaction to initiate two-stage confirmation;
and the judging and confirming unit is used for judging the type of the sub-transaction according to the two-stage confirmation initiated by the main transaction and executing the two-stage confirmation by adopting a corresponding confirmation execution method according to the judgment result.
15. The apparatus for implementing distributed transaction context passing at routing layer according to claim 14, wherein the call initiating unit comprises:
the routing calling module is used for executing a transmit method to complete calling if the type of the routing calling module is routing service;
and the common calling module is used for executing the try method to complete calling if the type of the common calling module is common TCC service.
16. The apparatus for implementing distributed transaction context transfer at routing layer according to claim 14, wherein the determining and confirming unit comprises:
the query module is used for querying the sub-transaction directly called under the current transaction layer;
the route confirmation module is used for executing a confirmation method of the sub-transaction and verifying whether the sub-transaction is a routing method if the type of the sub-transaction is the routing service;
and the common confirmation module is used for executing the confirmation method of the next layer of sub-transaction and then executing the confirmation method of the current layer of sub-transaction if the type of the sub-transaction is the common TCC service.
17. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, wherein the processor implements the method for implementing the distributed transaction context transfer at the routing layer according to any one of claims 1 to 5 and 6 to 8 when executing the program.
18. A computer-readable storage medium, on which a computer program is stored, the computer program, when being executed by a processor, implementing the method for transferring a distributed transaction context at a routing layer according to any one of claims 1 to 5 and 6 to 8.
CN202011276567.3A 2020-11-16 2020-11-16 Method and device for realizing distributed transaction context transfer in routing layer Active CN112395104B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011276567.3A CN112395104B (en) 2020-11-16 2020-11-16 Method and device for realizing distributed transaction context transfer in routing layer

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011276567.3A CN112395104B (en) 2020-11-16 2020-11-16 Method and device for realizing distributed transaction context transfer in routing layer

Publications (2)

Publication Number Publication Date
CN112395104A true CN112395104A (en) 2021-02-23
CN112395104B CN112395104B (en) 2023-12-01

Family

ID=74599892

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011276567.3A Active CN112395104B (en) 2020-11-16 2020-11-16 Method and device for realizing distributed transaction context transfer in routing layer

Country Status (1)

Country Link
CN (1) CN112395104B (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113515352A (en) * 2021-05-18 2021-10-19 中国工商银行股份有限公司 Distributed transaction different-base mode inverse transaction calling method and device

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108596768A (en) * 2018-05-09 2018-09-28 神州数码融信软件有限公司 A kind of distributed transaction processing method, apparatus and system
CN108733457A (en) * 2018-04-12 2018-11-02 阿里巴巴集团控股有限公司 The implementation method and device of distributed transaction
CN111045839A (en) * 2019-12-04 2020-04-21 中国建设银行股份有限公司 Sequence calling method and device based on two-phase transaction message in distributed environment
CN111813583A (en) * 2020-07-28 2020-10-23 厦门市易联众易惠科技有限公司 Transaction management method, device, equipment and storage medium under micro-service architecture

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN108733457A (en) * 2018-04-12 2018-11-02 阿里巴巴集团控股有限公司 The implementation method and device of distributed transaction
CN108596768A (en) * 2018-05-09 2018-09-28 神州数码融信软件有限公司 A kind of distributed transaction processing method, apparatus and system
CN111045839A (en) * 2019-12-04 2020-04-21 中国建设银行股份有限公司 Sequence calling method and device based on two-phase transaction message in distributed environment
CN111813583A (en) * 2020-07-28 2020-10-23 厦门市易联众易惠科技有限公司 Transaction management method, device, equipment and storage medium under micro-service architecture

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN113515352A (en) * 2021-05-18 2021-10-19 中国工商银行股份有限公司 Distributed transaction different-base mode inverse transaction calling method and device
CN113515352B (en) * 2021-05-18 2024-01-26 中国工商银行股份有限公司 Distributed transaction different-library mode anti-transaction calling method and device

Also Published As

Publication number Publication date
CN112395104B (en) 2023-12-01

Similar Documents

Publication Publication Date Title
CN110311790B (en) Method and device for sending authenticable message in cross-link mode
CN111163129B (en) Resource processing method and device based on cross-link network
CN109284197B (en) Distributed application platform based on intelligent contract and implementation method
US8788565B2 (en) Dynamic and distributed queueing and processing system
KR101863398B1 (en) Method and system for synchronization mechanism on multi-server reservation system
US10795906B1 (en) Transaction tracking
CN112862612A (en) Method and device for sending resources in cross-link mode
CN109951547B (en) Transaction request parallel processing method, device, equipment and medium
WO2021088641A1 (en) Data transmission method, data processing method, data reception method and device, and storage medium
US7970737B2 (en) Recovery administration of global transaction participants
CN108733457B (en) Method and device for realizing distributed transaction
CN112015811A (en) Method, node and computing device for node management of blockchain system
CN112181677A (en) Service processing method and device, storage medium and electronic device
CN112148436A (en) Decentralized TCC (transmission control protocol) transaction management method, device, equipment and system
CN113326272A (en) Distributed transaction processing method, device and system
CN106657187A (en) Message processing method and apparatus thereof
CN112395104A (en) Method and device for realizing transmission of distributed transaction context at routing layer
US20050144301A1 (en) System for aborting web services automatically and method thereof
US20180052754A1 (en) Performance metric contextualization in a distributed computing environment
CN113961332A (en) Method and device for realizing workflow engine, electronic equipment and storage medium
CN113297329A (en) Transaction processing method, device, equipment, storage medium and program product
CN110347659B (en) Data processing method and device and transaction data processing method and device
CN116974874A (en) Database testing method and device, electronic equipment and readable storage medium
CN111652605A (en) Creation system and creation method for creating cloud service package by public cloud service
CN111447273A (en) Cloud processing system and data processing method based on cloud processing system

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
GR01 Patent grant
GR01 Patent grant