Transaction coordination method and device based on XA
By developing transaction agents on C language transaction middleware and using the global transaction manager to coordinate Java and C language transaction branches, the difficulty of coordination and fusion of Java and C language transactions is solved, and smooth and over-the-top business system and data security are achieved.
Patent Information
- Application Number
- CN202411219801.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-09-02
- Publication Date
- 2025-01-14
- Estimated Expiration
- 2044-09-02
AI Technical Summary
In the transaction coordination across multiple databases, independent transaction coordinators in Java cannot be integrated with C language transaction coordination middleware, resulting in large workloads, long cycles, and security problems in redeveloping the business system.
Using XA transaction coordination method and device, the transaction agent is developed on C language transaction middleware, and the integration of Java and C language transactions is achieved, so as to avoid redeveloping the database interface, and the global transaction manager is used to register and coordinate transaction branches to ensure transaction consistency. sex.
It realizes the integration of Java and C business system transactions, reduces development difficulty and cost, avoids the workload of redevelopment, retains data-related configurations, and ensures data security across departments and units.
Smart Images

Figure CN119311377A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of data security, and in particular to an XA-based transaction coordination method and device. Background Art
[0002] At present, the international standard for transaction coordination across multiple databases is the XA protocol. Java language has its own jdbcXA transaction coordination mechanism coordinator, and C language has a special XA transaction coordination middleware - also called transaction middleware.
[0003] Due to historical reasons, the transaction coordination of Java language has its own independent coordinator and cannot be integrated with the traditional C language transaction coordination middleware. If Java language develops programs according to the C language transaction coordination middleware standard, the C language transaction coordination middleware can act as a global transaction coordinator to coordinate Java branch transactions, but conversely, if Java acts as a global transaction coordinator, there is no way to integrate.
[0004] Currently, Java is quite popular. In the actual development process, people tend to develop pure Java applications and use Java transaction coordinators, but this cannot be integrated with the C language transaction coordinator. The existing technical solution is basically to completely abandon the business system developed in C language and redevelop it in Java. The advantage is that the problem of incompatibility is completely solved.
[0005] However, the existing technology also has technical defects. The redevelopment workload is large, the cycle is long, and manpower and material resources are wasted. The original development cycle, investment, and manpower and material resources are wasted. Since the coordination of Java's global transactions requires connecting to the database, if it crosses departments and units, there will be security issues. It is impossible to give up security because of the coordination of transactions. Summary of the invention
[0006] The present invention proposes a transaction coordination method and device based on XA, which is used to develop a transaction agent based on C language transaction middleware, and achieve transaction coordination and consistency without opening a database interface to the global transaction initiator and without developing new applications, thereby overcoming the above two shortcomings.
[0007] In a first aspect, the present invention proposes a transaction coordination method based on XA, comprising:
[0008] When the global transaction manager declares the global transaction to start, the transaction branch is registered; wherein the transaction branch includes: Java branch transaction and C language transaction branch;
[0009] Calling a first business program of a java branch transaction through a client, and operating a first database through jdbc through the first business program;
[0010] Requesting the transaction middleware to call the client business program through the client to the C language transaction branch, and operating the second database through the client business program;
[0011] The execution information of the transaction branch is received through the client, a return result is determined, and returned to the client; wherein the return result includes a commit operation or a rollback operation.
[0012] In combination with the first aspect, the global transaction manager is a Java global transaction manager;
[0013] When receiving declaration information of the start of a global transaction, the Java global transaction manager starts a transaction branch; wherein the declaration information includes at least one Java branch transaction start information and at least one C language transaction branch start information.
[0014] In combination with the first aspect, when the client requests the transaction middleware to call the client business program through the C language transaction branch, it also includes:
[0015] The C language transaction agent of the C language transaction branch receives the call information, parses the call information, and determines the called client business program according to the parsed parsing parameters.
[0016] In combination with the first aspect, the Java global transaction manager is also used to retrieve transaction branches and initiate a pre-commit to the corresponding transaction branch when a transaction commit occurs; wherein the pre-commit result is used by the global transaction manager to determine whether all transaction branches have been successfully committed, and when a commit fails, all execution information of all transaction branches is rolled back.
[0017] In combination with the first aspect, the registration transaction branch further includes:
[0018] Obtaining branch index information contained in each branch transaction in the declaration information of the global transaction; wherein the branch index information is used to indicate the transaction sequence and transaction division identifier of each branch transaction;
[0019] Arrange transaction branches in sequence according to the transaction sequence, and generate index indication information according to the sequence arrangement and transaction division identifier;
[0020] Merge index indication information into each transaction branch.
[0021] In combination with the first aspect, the client is further used for:
[0022] Build the process framework of the transaction branch, correspond the process framework with the execution information, and determine the transaction response node;
[0023] According to the response node, build the session unit of each transaction branch;
[0024] The session message of each branch transaction is received at the client through the session unit; wherein the session message includes: transaction branch execution progress and transaction branch execution status;
[0025] Generate a transaction identifier in the global transaction manager according to the session message; wherein the transaction identifier includes a normalized transaction identifier and a faulty transaction identifier;
[0026] The execution scheduling of the transaction branch is performed according to the transaction identifier; wherein the execution scheduling includes execution switching and execution default.
[0027] In combination with the first aspect, the global transaction manager is further configured to:
[0028] Determine the operation data, operation status information and transaction efficiency of each transaction branch and the corresponding database in the global transaction;
[0029] Determine the coordination state vector of each transaction branch when executing the transaction branch according to the operation data;
[0030] According to the preset transaction supervision mechanism, the round-robin system executes the record behavior and operation status information, and records the operation status vector of each transaction branch;
[0031] Build a Gaussian distribution model based on the coordination state vector, operation state vector and transaction efficiency;
[0032] According to the Gaussian distribution model, determine the branches of things to be optimized that have differences in the global things.
[0033] In combination with the first aspect, the determining of the return result further includes:
[0034] When a rollback operation exists, obtaining a first abnormal event in the execution process of at least one transaction branch;
[0035] According to the execution content of the first abnormal event and the preset abnormal response mechanism, the first abnormal event is marked as abnormal in the abnormal transaction record log;
[0036] An emergency proxy replacement is performed on at least one transaction branch according to the abnormality identification.
[0037] In combination with the first aspect, the determining of the return result further includes:
[0038] When there is a commit operation, confirm all transaction branches between the client and the global transaction manager;
[0039] The client determines the standard operation data of all transaction branches; the standard operation data is the standard proxy operation and proxy process of each transaction branch in the execution operation;
[0040] The client inserts the operation standard data into the data unit associated with the corresponding transaction branch.
[0041] In a second aspect, a transaction coordination device based on XA is provided, characterized in that the device comprises:
[0042] Global transaction manager: used to register transaction branches when declaring the start of a global transaction; transaction branches include Java branch transactions and C language transaction branches;
[0043] Java global transaction controller: used to call the first business program of the java branch transaction through the client, and operate the first database through the first business program through jdbc;
[0044] C language business transaction agent: used to request the transaction middleware to call the client business program from the C language transaction branch, and operate the second database through the client business program;
[0045] Client: used to receive the execution information of the transaction branch and determine the return result; wherein the return result includes a commit operation or a rollback operation.
[0046] The beneficial effects of the present invention are:
[0047] The present invention executes the commands issued by the Java global transaction coordinator in the C language business system through an agent to complete the coordination of global transactions. On the basis of not adding new business development workload and not opening the database interface, the integration of the transactions of the Java business system and the C language business system is realized. The present invention can make it possible to integrate the transactions of the business system developed in C language and the business system developed in Java language without rewriting the C language business system in Java, thereby saving costs. When a Java developer develops a business system, it is not necessary to consider the complexity of transaction coordination between the C language business system and the C language business system. It is only necessary to develop the corresponding business processing module. The global transaction coordination is handled by the Java global transaction coordinator and the C language transaction agent. From a technical point of view, the development difficulty is reduced. If the purpose of development is to convert a traditional C language business system into a Java language business system, a part can be developed and a part can be put online without having to complete all the development and then put online, thereby achieving a smooth transition. Java global transactions generally require the database connection to be opened to the global transaction manager. If it is across departments and multiple units, the databases between different units are generally not open. Through this proposal, data-related configurations are still retained in the traditional C language business system, but global transaction coordination can be achieved.
[0048] Other features and advantages of the present invention will be described in the following description, and partly become apparent from the description, or understood by practicing the present invention. The purpose and other advantages of the present invention can be realized and obtained by the structures particularly pointed out in the written description and the accompanying drawings.
[0049] The technical solution of the present invention is further described in detail below through the accompanying drawings and embodiments. BRIEF DESCRIPTION OF THE DRAWINGS
[0050] The accompanying drawings are used to provide further understanding of the present invention and constitute a part of the specification. They are used to explain the present invention together with the embodiments of the present invention and do not constitute a limitation of the present invention.
[0051] In the attached picture:
[0052] Figure 1 A method flow chart of an XA transaction coordination method according to an embodiment of the present invention;
[0053] Figure 2 A diagram showing the composition of an XA transaction coordination device according to an embodiment of the present invention;
[0054] Figure 3 Schematic diagram of the hybrid transaction coordination process in an embodiment of the present invention. DETAILED DESCRIPTION
[0055] The preferred embodiments of the present invention are described below in conjunction with the accompanying drawings. It should be understood that the preferred embodiments described herein are only used to illustrate and explain the present invention, and are not used to limit the present invention.
[0056] This embodiment provides a transaction coordination method based on XA, including:
[0057] When the global transaction manager declares the global transaction to start, the transaction branch is registered; wherein the transaction branch includes: Java branch transaction and C language transaction branch;
[0058] Calling a first business program of a java branch transaction through a client, and operating a first database through jdbc through the first business program;
[0059] Requesting the transaction middleware to call the client business program through the client to the C language transaction branch, and operating the second database through the client business program;
[0060] The execution information of the transaction branch is received through the client, a return result is determined, and returned to the client; wherein the return result includes a commit operation or a rollback operation.
[0061] The principle of the above technical solution is:
[0062] In specific implementation, Figure 1 and Figure 3 As shown, the process of the present invention is as follows:
[0063] The global transaction starts:
[0064] The client declares a global transaction to the Java global transaction manager, and the Java global transaction manager will be ready.
[0065] The java branch transaction starts:
[0066] The client tells the global transaction manager that the java branch transaction has started. After the global transaction manager registers, it declares the start of the jdbc transaction branch to database A.
[0067] Java language branch business:
[0068] The client directly calls the Java business program, which operates database A through JDBC and returns the business results.
[0069] The C language transaction branch starts:
[0070] The client declares the start of the C language transaction branch to the global transaction manager. The global transaction manager registers it and initiates a call to the C language transaction agent. After receiving the request, the C language transaction agent declares the start of the branch transaction to database B.
[0071] The client calls the C language service:
[0072] The client initiates a call to the C language transaction agent. After receiving the call, the C language transaction agent parses the parameters, calls the customer's business program through the transaction middleware, operates database B, and returns the result to the agent after the operation is completed. The agent processes the result and returns it to the client program.
[0073] The client initiates a global commit or rollback:
[0074] The client initiates transaction commit or rollback based on the execution of the global business. The Java global transaction manager retrieves and finds the two branches of the global transaction. If it is a rollback, a rollback operation is initiated to both transaction branch databases and the result is returned. If the transaction is committed, a pre-commit is initiated to both transaction branches, as shown in Figure 6.1. The pre-commit returns the result to the global transaction manager, as shown in Figure 6.2. The global transaction manager determines whether all branches are pre-committed successfully. If one fails, a rollback operation is initiated to each branch database and all are rolled back. If all pre-commits are successful, a commit operation is initiated to each transaction branch, as shown in Figure 6.2. Then, based on the return result of each transaction branch, the result is returned to the client. In the above process, the transaction start declaration, pre-commit, commit, and result return of the C language are all completed through the proxy.
[0075] The global transaction result is returned to the client:
[0076] After the commit or rollback is completed, the result will be returned. The transaction manager will return the result to the front-end client after integrating the results returned by each branch.
[0077] The beneficial effects of the present invention are:
[0078] The present invention executes the commands issued by the Java global transaction coordinator in the C language business system through an agent to complete the coordination of global transactions. On the basis of not adding new business development workload and not opening the database interface, the integration of the transactions of the Java business system and the C language business system is realized. The present invention can make it possible to integrate the transactions of the business system developed in C language and the business system developed in Java language without rewriting the C language business system in Java, thereby saving costs. When a Java developer develops a business system, it is not necessary to consider the complexity of transaction coordination between the C language business system and the C language business system. It is only necessary to develop the corresponding business processing module. The global transaction coordination is handled by the Java global transaction coordinator and the C language transaction agent. From a technical point of view, the development difficulty is reduced. If the purpose of development is to convert a traditional C language business system into a Java language business system, a part can be developed and a part can be put online without having to complete all the development and then put online, thereby achieving a smooth transition. Java global transactions generally require the database connection to be opened to the global transaction manager. If it is across departments and multiple units, the databases between different units are generally not open. Through this proposal, data-related configurations are still retained in the traditional C language business system, but global transaction coordination can be achieved.
[0079] As an embodiment of the present invention: the global transaction manager is a java global transaction manager;
[0080] When receiving declaration information of the start of a global transaction, the Java global transaction manager starts a transaction branch; wherein the declaration information includes at least one Java branch transaction start information and at least one C language transaction branch start information.
[0081] The principle of the above technical solution is:
[0082] In order to improve the transaction coordination efficiency and reliability in a distributed system, multiple tasks can work together in a distributed system. One of the embodiments of the present invention is to implement multi-task processing in a distributed system by using a Java global transaction manager. The Java global transaction manager is a general, cross-platform, multi-threaded transaction coordination and management tool. It can manage multiple concurrent transactions and ensure their consistency and integrity. The advantage of the Java global transaction manager is that it has good compatibility and can be used in a variety of different operating systems and application environments. In another embodiment of the present invention, when the Java global transaction manager receives a declaration message of the start of a global transaction, it starts a transaction branch. This declaration message can be any type of declaration message, such as Java branch transaction start message and C language transaction branch start message. These declaration messages can be received and used by any application that supports the XA protocol. In an embodiment of the present invention, the information contained in the declaration message is critical. The Java branch transaction start message and the C language transaction branch start message contain basic information about the task to be executed, such as the name, description and parameters of the task. This information can be used by other tasks to coordinate their operations. In addition, when the Java global transaction manager starts a transaction branch, it ensures that all locks related to the transaction are released. This means that if a task has already acquired a lock on a resource, it will not be able to access that resource before the transaction branch. This can avoid problems such as data conflicts during transaction branches.
[0083] As an embodiment of the present invention:
[0084] When the client requests the transaction middleware to call the client business program through the C language transaction branch, it also includes:
[0085] The C language transaction agent of the C language transaction branch receives the call information, parses the call information, and determines the called client business program according to the parsed parsing parameters.
[0086] The principle of the above technical solution is:
[0087] The C language transaction agent is responsible for receiving the call information from the client and passing it to the entry point of the client business program. Then, the C language transaction agent determines the client business program to call based on the parsed parsing parameters. In this way, the C language transaction agent can act as an intermediary between the client and the client business program.
[0088] As an embodiment of the present invention:
[0089] The Java global transaction manager is also used to retrieve transaction branches and initiate a pre-commit to the corresponding transaction branch when a transaction commit occurs. The pre-commit result is used by the global transaction manager to determine whether all transaction branches have been successfully committed, and when a commit fails, all execution information of all transaction branches is rolled back.
[0090] The principle of the above technical solution is:
[0091] In addition to starting a transaction branch and releasing the lock associated with the transaction when starting the transaction branch, the present invention can also be used to retrieve the transaction branch and initiate a pre-commit to the corresponding transaction branch when there is a transaction commit. Specifically, after a transaction is completed, the Java global transaction manager can query the status of each branch transaction and determine which branch transactions have not been completed. If an unfinished branch transaction is found, the Java global transaction manager can initiate a pre-commit to the corresponding branch transaction to ensure the atomicity and consistency of the transaction. After issuing the pre-commit command, the Java global transaction manager will wait for the feedback information of each branch transaction and determine whether all branch transactions have completed the pre-commit. If it is found during the waiting process that the feedback information of any branch transaction indicates that the pre-commit has failed, the Java global transaction manager will roll back all the execution information of all branch transactions to ensure the correctness and consistency of the final data. The advantage of this method is that the integrity and consistency of the transaction can be guaranteed. Even if some branch transactions fail or errors occur, they can be restored to the state at the beginning of the transaction through a rollback operation, thereby avoiding the problem of data inconsistency. At the same time, through the pre-commit command, problems can be discovered and adjusted in time before the branch transaction is completed, thereby reducing the occurrence of errors.
[0092] As an embodiment of the present invention: the registration transaction branch further includes:
[0093] Obtaining branch index information contained in each branch transaction in the declaration information of the global transaction; wherein the branch index information is used to indicate the transaction sequence and transaction division identifier of each branch transaction;
[0094] Arrange transaction branches in sequence according to the transaction sequence, and generate index indication information according to the sequence arrangement and transaction division identifier;
[0095] Merge index indication information into each transaction branch.
[0096] The principle of the above technical solution is:
[0097] In specific implementation, when a global transaction is created, its declaration information will be broadcast to all other transactions participating in the transaction. These declaration information usually include information such as the index number and transaction division identifier of each branch transaction. This information can be used to sort transaction branches and generate index indication information.
[0098] After obtaining the index number and transaction demarcation identifier of each branch transaction, the transaction branches are sorted according to this information. The sorting can be based on the index number of the branch transaction or the transaction demarcation identifier. This ensures that the location and status of each transaction branch can be accurately found in the subsequent processing.
[0099] Finally, the generated index indication information will be merged into each transaction branch. These index indication information can indicate the position and status of each branch transaction in the global transaction, as well as its relationship with other branch transactions. In the subsequent processing, the position and status of each transaction branch, as well as its relationship with other transaction branches, can be quickly located based on these index indication information.
[0100] The technical effects of the above technical solution are:
[0101] When registering a transaction branch, the present invention can realize rapid search for the transaction branch and rapid judgment of the relationship between the transaction branches by integrating the transaction branch and the index indication information.
[0102] As an embodiment of the present invention: the client is also used for:
[0103] Build the process framework of the transaction branch, correspond the process framework with the execution information, and determine the transaction response node;
[0104] According to the response node, build the session unit of each transaction branch;
[0105] The session message of each branch transaction is received at the client through the session unit; wherein the session message includes: transaction branch execution progress and transaction branch execution status;
[0106] Generate a transaction identifier in the global transaction manager according to the session message; wherein the transaction identifier includes a normalized transaction identifier and a faulty transaction identifier;
[0107] The execution scheduling of the transaction branch is performed according to the transaction identifier; wherein the execution scheduling includes execution switching and execution default.
[0108] The principle of the above technical solution is:
[0109] In specific implementation, the present invention builds a process framework of a transaction branch, and makes the process framework correspond to the execution information to determine the transaction response node. Various technologies and algorithms are used to implement it, such as using a decision tree, a rule engine, etc. to define and describe the business logic, and determining the response node of each transaction branch according to the execution result. In this process, it is necessary to associate each transaction branch with its corresponding execution information, so that when there is session information of the transaction branch, such as the query of the transaction branch, the necessary information can be obtained in time. According to the response node, a session unit of each transaction branch is built. The session unit is an interface between the client and the global transaction manager, which receives and sends transaction-related messages. When establishing the session unit, it needs to be bound to the corresponding transaction branch. At the same time, the session unit also needs to have a certain degree of intelligence so that it can automatically process after receiving the message, thereby improving the work efficiency of the system. Through the session unit, the session message of each branch transaction is received at the client. In the collection of the session unit, the session message is the main data source, which includes information such as the execution progress and status of the transaction branch. The collection of session messages can provide the client with a more comprehensive and accurate understanding of the ability of the entire system, thereby quickly executing the design and optimization of scheduling. According to the session message, the global transaction manager generates a transaction identifier. The transaction identifier is a global identifier that is used as a unique identifier for a transaction and is used to distinguish normal transactions from faulty transactions. In the process of generating a transaction identifier, various factors need to be considered comprehensively, such as transaction type, execution time, execution result, etc., to generate a transaction identifier that is unique and stable. The execution of transaction branches is scheduled according to the transaction identifier. In the process of transaction execution, the execution switching and execution default methods need to be determined according to the actual situation. Execution switching can be used to deal with some abnormal situations, while execution default can be used to ensure the continuity and stability of the system in some cases. In the design of execution scheduling, various factors need to be considered comprehensively, such as transaction priority, execution time window, resource constraints, etc., in order to achieve efficient and reliable execution scheduling.
[0110] As an embodiment of the present invention: the global transaction manager is further used for:
[0111] Determine the operation data, operation status information and transaction efficiency of each transaction branch and the corresponding database in the global transaction;
[0112] Determine the coordination state vector of each transaction branch when executing the transaction branch according to the operation data;
[0113] According to the preset transaction supervision mechanism, the round-robin system executes the record behavior and operation status information, and records the operation status vector of each transaction branch;
[0114] Build a Gaussian distribution model based on the coordination state vector, operation state vector and transaction efficiency;
[0115] According to the Gaussian distribution model, determine the branches of things to be optimized that have differences in the global things.
[0116] The principle of the above technical solution is:
[0117] In the specific implementation process, the present invention obtains relevant information by querying a database or other data source, and associates it with the corresponding transaction branch. The coordination state vector is calculated according to the actual value of the operation data to determine the coordination status and potential problems between the transaction branches. In this process, some technical means, such as logging, monitoring, etc., are used to record the operation status of each transaction branch, and analyze and process it when necessary. The Gaussian distribution model in the present invention is a commonly used machine learning model for predicting and evaluating the differences and impacts between different transaction branches. When building the model, various factors are considered, such as historical data, business rules, etc., to obtain more accurate prediction and evaluation results. By comparing the differences and impacts between different transaction branches, those branches that may need to be optimized are identified, and corresponding improvement suggestions or strategies are provided to improve the overall performance and reliability of the system.
[0118] As an embodiment of the present invention: the determining of the return result further includes:
[0119] When a rollback operation exists, obtaining a first abnormal event in the execution process of at least one transaction branch;
[0120] According to the execution content of the first abnormal event and the preset abnormal response mechanism, the first abnormal event is marked as abnormal in the abnormal transaction record log;
[0121] An emergency proxy replacement is performed on at least one transaction branch according to the abnormality identification.
[0122] The principle of the above technical solution is:
[0123] In the specific implementation process, the present invention obtains the first abnormal event in the execution process of at least one transaction branch when there is a rollback operation, and is implemented by setting an abnormal detection mechanism, such as setting an abnormal threshold, a trigger, a monitoring program, etc., to monitor and capture the abnormal event. After the abnormal event is captured, the abnormal response mechanism can be triggered immediately for processing. According to the execution content of the first abnormal event and the preset abnormal response mechanism, the first abnormal event is abnormally calibrated in the abnormal transaction record log. Abnormal calibration refers to recording and classifying the relevant information of the abnormal event. During calibration, it is necessary to combine the type, cause, time and other information of the abnormal event for classification and marking, so as to perform subsequent processing and query. Emergency proxy replacement is performed on at least one transaction branch according to the abnormal calibration. Emergency proxy replacement refers to solving the abnormal problem by proxy replacement after the abnormal event occurs to ensure the normal operation of the system.
[0124] As an embodiment of the present invention: the determining of the return result further includes:
[0125] When there is a commit operation, confirm all transaction branches between the client and the global transaction manager;
[0126] The client determines the standard operation data of all transaction branches; the standard operation data is the standard proxy operation and proxy process of each transaction branch in the execution operation;
[0127] The client inserts the operation standard data into the data unit associated with the corresponding transaction branch.
[0128] The principle of the above technical solution is:
[0129] In the specific implementation, when there is a commit operation, all transaction branches between the client and the global transaction manager are confirmed. The commit operation refers to the request initiated by the client to the global transaction manager to submit the local transaction and obtain the response of the global transaction manager. After the client issues a commit request, the global transaction manager needs to confirm whether the local transaction submitted by the client is consistent with its status in the database. If so, it will send a response to the client, otherwise it will throw an exception. Therefore, before confirming all transaction branches submitted by the client, it is necessary to check the status of each transaction branch submitted by the client and record the status of each branch in the global transaction manager to ensure the consistency and reliability of the system. The client determines the standard operation data of all transaction branches. The standard operation data refers to the standard operation and operation process that needs to be followed during the execution of each transaction branch. It is generated by the client according to its own business logic and rules, and is used to guide the client's behavior on the branch. After determining the standard operation data, the client can store this data in a local or global database and call it in subsequent business processes.
[0130] As a second technical solution of the present invention, the present invention proposes an XA-based transaction coordination device, the device comprising:
[0131] Global transaction manager: used to register transaction branches when declaring the start of a global transaction; transaction branches include Java branch transactions and C language transaction branches;
[0132] Java global transaction controller: used to call the first business program of the java branch transaction through the client, and operate the first database through the first business program through jdbc;
[0133] C language business transaction agent: used to request the transaction middleware to call the client business program from the C language transaction branch, and operate the second database through the client business program;
[0134] Client: used to receive the execution information of the transaction branch and determine the return result; wherein the return result includes a commit operation or a rollback operation.
[0135] In specific implementation, Figure 2 and Figure 3 As shown, the process of the present invention is as follows:
[0136] The global transaction starts:
[0137] The client declares a global transaction to the Java global transaction manager, and the Java global transaction manager will be ready.
[0138] The java branch transaction starts:
[0139] The client tells the global transaction manager that the java branch transaction has started. After the global transaction manager registers, it declares the start of the jdbc transaction branch to database A.
[0140] Java language branch business:
[0141] The client directly calls the Java business program, which operates database A through JDBC and returns the business results.
[0142] The C language transaction branch starts:
[0143] The client declares the start of the C language transaction branch to the global transaction manager. The global transaction manager registers it and initiates a call to the C language transaction agent. After receiving the request, the C language transaction agent declares the start of the branch transaction to database B.
[0144] The client calls the C language service:
[0145] The client initiates a call to the C language transaction agent. After receiving the call, the C language transaction agent parses the parameters, calls the customer's business program through the transaction middleware, operates database B, and returns the result to the agent after the operation is completed. The agent processes the result and returns it to the client program.
[0146] The client initiates a global commit or rollback:
[0147] The client initiates transaction commit or rollback based on the execution of the global business. The Java global transaction manager retrieves and finds the two branches of the global transaction. If it is a rollback, a rollback operation is initiated to both transaction branch databases and the result is returned. If the transaction is committed, a pre-commit is initiated to both transaction branches, as shown in Figure 6.1. The pre-commit returns the result to the global transaction manager, as shown in Figure 6.2. The global transaction manager determines whether all branches are pre-committed successfully. If one fails, a rollback operation is initiated to each branch database and all are rolled back. If all pre-commits are successful, a commit operation is initiated to each transaction branch, as shown in Figure 6.2. Then, based on the return result of each transaction branch, the result is returned to the client. In the above process, the transaction start declaration, pre-commit, commit, and result return of the C language are all completed through the proxy.
[0148] The global transaction result is returned to the client:
[0149] After the commit or rollback is completed, the result will be returned. The transaction manager will return the result to the front-end client after integrating the results returned by each branch.
[0150] The beneficial effects of the present invention are:
[0151] The present invention executes the commands issued by the Java global transaction coordinator in the C language business system through an agent to complete the coordination of global transactions. On the basis of not adding new business development workload and not opening the database interface, the integration of the transactions of the Java business system and the C language business system is realized. The present invention can make it possible to integrate the transactions of the business system developed in C language and the business system developed in Java language without rewriting the C language business system in Java, thereby saving costs. When a Java developer develops a business system, it is not necessary to consider the complexity of transaction coordination between the C language business system and the C language business system. It is only necessary to develop the corresponding business processing module. The global transaction coordination is handled by the Java global transaction coordinator and the C language transaction agent. From a technical point of view, the development difficulty is reduced. If the purpose of development is to convert a traditional C language business system into a Java language business system, a part can be developed and a part can be put online without having to complete all the development and then put online, thereby achieving a smooth transition. Java global transactions generally require the database connection to be opened to the global transaction manager. If it is across departments and multiple units, the databases between different units are generally not open. Through this proposal, data-related configurations are still retained in the traditional C language business system, but global transaction coordination can be achieved.
[0152] Obviously, those skilled in the art can make various changes and modifications to the present invention without departing from the spirit and scope of the present invention. Thus, if these modifications and variations of the present invention fall within the scope of the claims of the present invention and their equivalents, the present invention is also intended to include these modifications and variations.
Claims
1. A transaction coordination method based on XA, characterized in that: include: When the global transaction manager declares the global transaction to start, the transaction branch is registered; wherein the transaction branch includes: Java branch transaction and C language transaction branch; Calling a first business program of a java branch transaction through a client, and operating a first database through jdbc through the first business program; Requesting the transaction middleware to call the client business program through the client to the C language transaction branch, and operating the second database through the client business program; The execution information of the transaction branch is received through the client, a return result is determined, and returned to the client; wherein the return result includes a commit operation or a rollback operation.
2. The XA-based transaction coordination method according to claim 1, characterized in that: The global transaction manager is a java global transaction manager; When receiving declaration information of the start of a global transaction, the Java global transaction manager starts a transaction branch; wherein the declaration information includes at least one Java branch transaction start information and at least one C language transaction branch start information.
3. The XA-based transaction coordination method according to claim 1, characterized in that: When the client requests the transaction middleware to call the client business program through the C language transaction branch, it also includes: The C language transaction agent of the C language transaction branch receives the call information, parses the call information, and determines the called client business program according to the parsed parsing parameters.
4. The XA-based transaction coordination method according to claim 2, characterized in that: The Java global transaction manager is also used to retrieve transaction branches and initiate a pre-commit to the corresponding transaction branch when a transaction commit occurs. The pre-commit result is used by the global transaction manager to determine whether all transaction branches have been successfully committed, and when a commit fails, all execution information of all transaction branches is rolled back.
5. The XA-based transaction coordination method according to claim 1, characterized in that: The registration transaction branch also includes: Obtaining branch index information contained in each branch transaction in the declaration information of the global transaction; wherein the branch index information is used to indicate the transaction sequence and transaction division identifier of each branch transaction; Arrange transaction branches in sequence according to the transaction sequence, and generate index indication information according to the sequence arrangement and transaction division identifier; Merge index indication information into each transaction branch.
6. The XA-based transaction coordination method according to claim 1, characterized in that: The client is also used to: Build the process framework of the transaction branch, correspond the process framework with the execution information, and determine the transaction response node; According to the response node, build the session unit of each transaction branch; The session message of each branch transaction is received at the client through the session unit; wherein the session message includes: transaction branch execution progress and transaction branch execution status; Generate a transaction identifier in the global transaction manager according to the session message; wherein the transaction identifier includes a normalized transaction identifier and a faulty transaction identifier; The execution scheduling of the transaction branch is performed according to the transaction identifier; wherein the execution scheduling includes execution switching and execution default.
7. The XA-based transaction coordination method according to claim 1, characterized in that: The global transaction manager is also used to: Determine the operation data, operation status information and transaction efficiency of each transaction branch and the corresponding database in the global transaction; Determine the coordination state vector of each transaction branch when executing the transaction branch according to the operation data; According to the preset transaction supervision mechanism, the round-robin system executes the record behavior and operation status information, and records the operation status vector of each transaction branch; Build a Gaussian distribution model based on the coordination state vector, operation state vector and transaction efficiency; According to the Gaussian distribution model, determine the branches of things to be optimized that have differences in the global things.
8. The XA-based transaction coordination method according to claim 1, characterized in that: The determining of the returned result further includes: When there is a rollback operation, obtaining a first abnormal event in the execution process of at least one transaction branch; According to the execution content of the first abnormal event and the preset abnormal response mechanism, the first abnormal event is marked as abnormal in the abnormal transaction record log; An emergency proxy replacement is performed on at least one transaction branch according to the abnormality identification.
9. The XA-based transaction coordination method according to claim 1, characterized in that: The determining of the returned result further includes: When there is a commit operation, confirm all transaction branches between the client and the global transaction manager; The client determines the standard operation data of all transaction branches; the standard operation data is the standard proxy operation and proxy process of each transaction branch in the execution operation; The client inserts the operation standard data into the data unit associated with the corresponding transaction branch.
10. A transaction coordination device based on XA, characterized in that: The device comprises: Global transaction manager: used to register transaction branches when declaring the start of a global transaction; transaction branches include Java branch transactions and C language transaction branches; Java global transaction controller: used to call the first business program of the java branch transaction through the client, and operate the first database through the first business program through jdbc; C language business transaction agent: used to request the transaction middleware to call the client business program from the C language transaction branch, and operate the second database through the client business program; Client: used to receive the execution information of the transaction branch and determine the return result; wherein the return result includes a commit operation or a rollback operation.
Citation Information
Patent Citations
Transaction implementation method and system for initiating transactions by client
CN103546440A
Distributed transaction processing method and system
CN110399429A
Distributed transaction management method
CN110532068A
Distributed transaction processing method and device and computer readable storage medium
CN110765178A
Transaction processing method and device
CN111475583A