XA transaction coordination method and apparatus
By developing a transaction agent on a C language transaction middleware, and utilizing the Java global transaction manager and the C language transaction agent to achieve cross-database transaction coordination, the problem of the incompatibility between Java and C language transaction coordinators is solved, the development difficulty and cost are reduced, and cross-departmental data coordination is supported.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- 北京东方通软件有限公司
- Filing Date
- 2024-09-02
- Publication Date
- 2026-07-03
AI Technical Summary
In existing technologies for coordinating transactions across multiple databases, the transaction coordinator in Java and the transaction coordination middleware in C cannot be integrated, resulting in a large amount of redevelopment work, a long cycle, and security issues.
Develop a transaction proxy on a C language transaction middleware, register branch transactions through a global transaction manager, and use a Java global transaction manager and a C language transaction proxy to achieve transaction coordination, avoiding the need to redevelop the application and expose the database interface.
It integrates Java and C language business system transactions, reduces development difficulty and cost, supports cross-departmental data coordination, and achieves a smooth transition.
Smart Images

Figure CN119311377B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of data security, and in particular to an XA-based transaction coordination method and apparatus. Background Technology
[0002] Currently, the international standard for transaction coordination across multiple databases is the XA protocol. The Java language has its own JDBC XA transaction coordination mechanism coordinator, while the C language has dedicated XA transaction coordination middleware—also known as transaction middleware.
[0003] Due to historical reasons, Java's transaction coordination has its own independent coordinator, which cannot be integrated with the traditional C language transaction coordination middleware. If Java programs are developed 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. However, if Java acts as the global transaction coordinator, there is no way to integrate them.
[0004] Currently, Java is a popular language, and in actual development, there's a tendency to develop pure Java applications using Java's transaction coordinator. However, this is incompatible with C's transaction coordinator. Existing technical solutions generally involve completely abandoning the business system developed in C and redeveloping it entirely in Java. The advantage is that it completely solves the incompatibility problem.
[0005] However, existing technologies also have limitations. Redevelopment would be labor-intensive, time-consuming, and wasteful of human and material resources, as well as historical investments. Furthermore, since Java's global transaction coordination requires database connections, security issues arise if transactions cross departments or units. It is impossible to sacrifice security for the sake of transaction coordination. Summary of the Invention
[0006] This invention proposes an XA-based transaction coordination method and apparatus, which is used to develop a transaction proxy based on C language transaction middleware. It achieves transaction coordination consistency without opening the database interface to the global transaction initiator or developing new applications, thus overcoming the two shortcomings mentioned above.
[0007] In a first aspect, the present invention proposes an XA-based transaction coordination method, comprising:
[0008] When the global transaction manager declares the start of a global transaction, it registers branch transactions; these branch transactions include Java branch transactions and C language branch transactions.
[0009] The client calls the first business program of the Java branch transaction, and the first business program operates the first database through JDBC.
[0010] The client requests the transaction middleware of the C language branch transaction to call the client business program, and operates the second database through the client business program.
[0011] The system receives execution information of branch transactions from the client, determines the return result, and returns it to the client; wherein the return result includes a commit operation or a rollback operation.
[0012] In conjunction with the first aspect, the global transaction manager is the Java global transaction manager;
[0013] When the Java Global Transaction Manager receives a declaration message indicating the start of a global transaction, it initiates a branch transaction. The declaration message includes at least one Java branch transaction start message and at least one C language branch transaction start message.
[0014] In conjunction with the first aspect, when the client requests the transaction middleware of the C language branch transaction to call the client's business program, it also includes:
[0015] The C language transaction proxy, which uses C language branch transactions, receives and parses the call information, and determines the client business program to be called based on the parsed parameters.
[0016] In conjunction with the first aspect, the Java global transaction manager is also used to retrieve branch transactions and, when a transaction has been committed, initiate a pre-commit to the corresponding branch transaction; wherein, the global transaction manager determines whether all branch transactions have been successfully committed based on the commit result of the pre-commit, and rolls back all execution information of all branch transactions when there is a commit failure.
[0017] In conjunction with the first aspect, the registration of branch transactions also includes:
[0018] Obtain the 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 order and transaction division identifier of each branch transaction;
[0019] Based on the transaction order, the branch transactions are arranged sequentially, and index indication information is generated based on the sequential arrangement and transaction division identifier.
[0020] Incorporate index indication information into each branch transaction.
[0021] In conjunction with the first aspect, the client is also used for:
[0022] Establish a process framework for branch transactions, and correlate the process framework with execution information to determine transaction response nodes;
[0023] Based on the response node, establish a session unit for each branch transaction;
[0024] Through the session unit, the client receives session messages for each branch transaction; the session messages include: branch transaction execution progress and branch transaction execution status;
[0025] Based on the session messages, a transaction identifier is generated in the global transaction manager; the transaction identifier includes a normalized transaction identifier and a faulty transaction identifier.
[0026] Branch transaction execution is scheduled based on transaction identifier; execution scheduling includes execution switching and execution default.
[0027] In conjunction with the first aspect, the global transaction manager is also used for:
[0028] Determine the operation data, operation status information, and transaction efficiency of each branch transaction in the global transaction and its corresponding database;
[0029] Determine the coordination state vector of each branch transaction when executing the branch transaction based on the operation data;
[0030] Based on the preset transaction monitoring mechanism, the execution record behavior and operation status information are polled and recorded, and the transaction operation status vector of each branch is recorded.
[0031] A Gaussian distribution model is constructed based on the coordination state vector, the operation state vector, and the transaction efficiency.
[0032] Based on the Gaussian distribution model, identify the branches of the global transaction that have discrepancies and need optimization.
[0033] In conjunction with the first aspect, determining the returned result also includes:
[0034] When a rollback operation exists, retrieve the first exception event during the execution of at least one branch transaction;
[0035] Based on the execution content of the first abnormal event and the preset abnormal response mechanism, the first abnormal event is marked as an abnormal event in the abnormal transaction log.
[0036] Emergency proxy replacement is performed on at least one branch transaction based on the anomaly label.
[0037] In conjunction with the first aspect, determining the returned result also includes:
[0038] When a commit operation exists, all branch transactions between the client and the global transaction manager are confirmed;
[0039] The client determines the standard operation data for all branch transactions; the standard operation data includes the standard proxy operations and proxy processes for each branch transaction during the execution of operations.
[0040] The client inserts standard operational data into the data unit associated with the corresponding branch transaction.
[0041] Secondly, an XA-based transaction coordination device, characterized in that the device comprises:
[0042] Global Transaction Manager: Used to register branch transactions when a global transaction begins; branch transactions include Java branch transactions and C language branch transactions.
[0043] Java Global Transaction Controller: Used to invoke the first business program of a Java branch transaction through the client, and to operate the first database through JDBC via the first business program;
[0044] C language business transaction proxy: used to request the transaction middleware of the C language branch transaction to call the client business program, and operate the second database through the client business program;
[0045] Client: Used to receive execution information of branch transactions and determine the return result; wherein the return result includes a commit operation or a rollback operation.
[0046] The beneficial effects of this invention are as follows:
[0047] This invention executes commands issued by the Java global transaction coordinator within the C language business system via a proxy, thus coordinating global transactions. It achieves the integration of transactions between the Java and C language business systems without increasing business development workload or exposing database interfaces. This invention allows for the integration of transactions between C and Java-developed business systems without rewriting the C language business system in Java, saving costs. For Java developers, the complexity of transaction coordination between the C and C language business systems is eliminated; they only need to develop the corresponding business processing modules. Global transaction coordination is handled by the Java global transaction coordinator and the C language transaction proxy, technically reducing development difficulty. If the goal is to convert a traditional C language business system to a Java language business system, development can proceed in stages, allowing for a smooth transition. Java global transactions typically require exposing database connections to the global transaction manager. However, in cross-departmental and multi-unit projects, databases between different units are usually not exposed. This proposal retains data-related configurations within the traditional C language business system while achieving global transaction coordination.
[0048] Other features and advantages of the invention will be set forth in the following description, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention may be realized and obtained by means of the structures particularly pointed out in the written description and the accompanying drawings.
[0049] The technical solution of the present invention will be further described in detail below with reference to the accompanying drawings and embodiments. Attached Figure Description
[0050] The accompanying drawings are provided to further illustrate the invention and form part of the specification. They are used together with the embodiments of the invention to explain the invention and do not constitute a limitation thereof.
[0051] In the attached diagram:
[0052] Figure 1 This is a flowchart of a method based on the XA transaction coordination method in an embodiment of the present invention;
[0053] Figure 2 This is a diagram illustrating the device composition of an XA-based transaction coordination device according to an embodiment of the present invention.
[0054] Figure 3 This is a schematic diagram of the hybrid transaction coordination process in an embodiment of the present invention. Detailed Implementation
[0055] The preferred embodiments of the present invention will be described below with reference to the accompanying drawings. It should be understood that the preferred embodiments described herein are for illustration and explanation only and are not intended to limit the present invention.
[0056] This embodiment provides an XA-based transaction coordination method, including:
[0057] When the global transaction manager declares the start of a global transaction, it registers branch transactions; these branch transactions include Java branch transactions and C language branch transactions.
[0058] The client calls the first business program of the Java branch transaction, and the first business program operates the first database through JDBC.
[0059] The client requests the transaction middleware of the C language branch transaction to call the client business program, and operates the second database through the client business program.
[0060] The system receives execution information of branch transactions from the client, determines the return result, and returns it to the client; wherein the return result includes a commit operation or a rollback operation.
[0061] The principle behind the above technical solution is as follows:
[0062] In specific implementation, such as Figure 1 and Figure 3 As shown, the process of the present invention is as follows:
[0063] Global transaction begins:
[0064] When a client declares a global transaction to the Java Global Transaction Manager, the Java Global Transaction Manager will prepare accordingly.
[0065] Java branch transaction begins:
[0066] The client notifies the global transaction manager that a Java branch transaction has begun. After the global transaction manager registers this, it declares the start of a JDBC branch transaction to database A.
[0067] Java language branch business:
[0068] The client directly calls the Java business program, which operates on database A via JDBC and returns the business results.
[0069] C language branch transaction begins:
[0070] The client declares the start of the C language branch transaction to the global transaction manager. The global transaction manager registers this 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 the database B.
[0071] Client calls C language business logic:
[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 client's business program through the transaction middleware, operates on 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 a transaction commit or rollback based on the execution status of the global business logic. The Java global transaction manager retrieves the two branches of the global transaction. If it's a rollback, a rollback operation is initiated to both branch transaction databases, and the result is returned. If the transaction is a commit, a pre-commit is initiated to both branch transactions, as shown in Figure 6.1. The pre-commit returns its result to the global transaction manager, as shown in Figure 6.2. The global transaction manager determines whether all branch pre-commits were successful. If any fails, a rollback operation is initiated to all branch databases, resulting in a complete rollback. If all pre-commits are successful, a commit operation is initiated to all branch transactions, as shown in Figure 6.2. Finally, based on the return results of each branch transaction, the result is returned to the client. In this process, the C language's transaction declaration, pre-commit, commit, and result return are all handled through a proxy.
[0075] The global transaction result is returned to the client:
[0076] After a commit or rollback is completed, the results will be returned. The transaction manager will synthesize the results from each branch and return them to the front-end client.
[0077] The beneficial effects of this invention are as follows:
[0078] This invention executes commands issued by the Java global transaction coordinator within the C language business system via a proxy, thus coordinating global transactions. It achieves the integration of transactions between the Java and C language business systems without increasing business development workload or exposing database interfaces. This invention allows for the integration of transactions between C and Java-developed business systems without rewriting the C language business system in Java, saving costs. For Java developers, the complexity of transaction coordination between the C and C language business systems is eliminated; they only need to develop the corresponding business processing modules. Global transaction coordination is handled by the Java global transaction coordinator and the C language transaction proxy, technically reducing development difficulty. If the goal is to convert a traditional C language business system to a Java language business system, development can proceed in stages, allowing for a smooth transition. Java global transactions typically require exposing database connections to the global transaction manager. However, in cross-departmental and multi-unit projects, databases between different units are usually not exposed. This proposal retains data-related configurations within the traditional C language business system while achieving global transaction coordination.
[0079] As one embodiment of the present invention: the global transaction manager is a Java global transaction manager;
[0080] When the Java Global Transaction Manager receives a declaration message indicating the start of a global transaction, it initiates a branch transaction. The declaration message includes at least one Java branch transaction start message and at least one C language branch transaction start message.
[0081] The principle behind the above technical solution is as follows:
[0082] To improve the efficiency and reliability of transaction coordination in distributed systems, enabling multiple tasks to work collaboratively, one implementation of this invention is to use a Java Global Transaction Manager (JGRM) to achieve multi-task processing in a distributed system. The JGRM is a general-purpose, 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 JGRM lies in its good compatibility, allowing it to be used in various operating systems and application environments. In another embodiment of this invention, when the JGRM receives a declaration message indicating the start of a global transaction, it initiates a branch transaction. This declaration message can be of any type, such as Java branch transaction start information or C language branch transaction start information. These declaration messages can be received and used by any application that supports the XA protocol. In this embodiment, the information contained in the declaration message is crucial. The Java branch transaction start information and the C language branch transaction start information contain basic information about the task to be executed, such as the task's name, description, and parameters. This information can be used by other tasks to coordinate their operations. Furthermore, when the JGRM initiates a branch transaction, it ensures that all locks associated with that 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 branch transaction. This avoids problems such as data conflicts during branch transactions.
[0083] As one embodiment of the present invention:
[0084] When the client requests the transaction middleware of the C language branch transaction to call the client's business program, it also includes:
[0085] The C language transaction proxy, which uses C language branch transactions, receives and parses the call information, and determines the client business program to be called based on the parsed parameters.
[0086] The principle behind the above technical solution is as follows:
[0087] The C language transaction proxy receives call information from the client and passes it to the entry point of the client's business logic. Then, the C language transaction proxy determines the client's business logic to be invoked based on the parsed parameters. In this way, the C language transaction proxy acts as an intermediary between the client and the client's business logic.
[0088] As one embodiment of the present invention:
[0089] The Java global transaction manager is also used to retrieve branch transactions and initiate a pre-commit to the corresponding branch transaction when a transaction has been committed. The pre-commit result is determined by the global transaction manager to determine whether all branch transactions have been successfully committed, and if any commit fails, the execution information of all branch transactions is rolled back.
[0090] The principle behind the above technical solution is as follows:
[0091] In addition to initiating branch transactions and releasing locks associated with those transactions upon initiation, this invention can also be used to retrieve branch transactions and, when a transaction has been committed, initiate a pre-commit to the corresponding branch transaction. Specifically, after a transaction completes, the Java Global Transaction Manager can query the status of each branch transaction and determine which branch transactions are not yet complete. If any incomplete branch transactions are 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 waits for feedback from each branch transaction and determines whether all branch transactions have completed the pre-commit. If, during the waiting process, feedback from any branch transaction indicates that the pre-commit has failed, the Java Global Transaction Manager will roll back the execution information of all branch transactions to ensure the correctness and consistency of the final data. The advantage of this method is that it guarantees the integrity and consistency of transactions. Even if some branch transactions fail or err, a rollback operation can restore the transaction to its initial state, thus avoiding data inconsistency. Simultaneously, the pre-commit command allows for timely detection and adjustment of problems before branch transactions complete, thereby reducing the occurrence of errors.
[0092] As one embodiment of the present invention: the registration branch transaction further includes:
[0093] Obtain the 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 order and transaction division identifier of each branch transaction;
[0094] Based on the transaction order, the branch transactions are arranged sequentially, and index indication information is generated based on the sequential arrangement and transaction division identifier.
[0095] Incorporate index indication information into each branch transaction.
[0096] The principle behind the above technical solution is as follows:
[0097] In practical implementation, when a global transaction is created, its declaration information is broadcast to all other transactions participating in that transaction. This declaration information typically includes information such as the index number and transaction partition identifier for each branch transaction. This information can be used to sort branch transactions and generate index indication information.
[0098] After obtaining the index number and transaction partition identifier of each branch transaction, the branch transactions are sorted based on this information. The sorting can be based on either the branch transaction index number or the transaction partition identifier. This ensures that the position and status of each branch transaction can be accurately located during subsequent processing.
[0099] Finally, the generated index indication information is merged into each branch transaction. This index indication information indicates the position and status of each branch transaction within the global transaction, as well as its relationship with other branch transactions. In subsequent processing, this index indication information is used to quickly locate the position and status of each branch transaction, and its relationship with other branch transactions.
[0100] The technical effects of the above technical solution are as follows:
[0101] When registering branch transactions, this invention integrates branch transactions and index indication information, enabling rapid retrieval of branch transactions and quick determination of the relationships between them.
[0102] As an embodiment of the present invention: the client is also used for:
[0103] Establish a process framework for branch transactions, and correlate the process framework with execution information to determine transaction response nodes;
[0104] Based on the response node, establish a session unit for each branch transaction;
[0105] Through the session unit, the client receives session messages for each branch transaction; the session messages include: branch transaction execution progress and branch transaction execution status;
[0106] Based on the session messages, a transaction identifier is generated in the global transaction manager; the transaction identifier includes a normalized transaction identifier and a faulty transaction identifier.
[0107] Branch transaction execution is scheduled based on transaction identifier; execution scheduling includes execution switching and execution default.
[0108] The principle behind the above technical solution is as follows:
[0109] In practical implementation, this invention establishes a process framework for branch transactions and correlates the process framework with execution information to determine transaction response nodes. Various technologies and algorithms are employed, such as decision trees and rule engines, to define and describe business logic, and the response node for each branch transaction is determined based on the execution results. During this process, each branch transaction needs to be associated with its corresponding execution information so that necessary information can be obtained promptly when branch transaction session information exists, such as in branch transaction queries. Based on the response nodes, a session unit for each branch transaction is established. The session unit serves as the interface between the client and the global transaction manager, receiving and sending transaction-related messages. When establishing a session unit, it needs to be bound to the corresponding branch transaction. Simultaneously, the session unit needs to possess a certain degree of intelligence to automatically process received messages, thereby improving system efficiency. Through the session unit, the client receives session messages for each branch transaction. Session messages are the primary data source in the collection of session units, including information such as the execution progress and status of branch transactions. The collection of session messages provides the client with a more comprehensive and accurate understanding of the entire system, enabling rapid design and optimization of scheduling. Based on the session messages, a transaction identifier is generated in the global transaction manager. The transaction identifier is a global identifier used to uniquely identify a transaction and distinguish between normal and faulty transactions. The generation of the transaction identifier requires comprehensive consideration of various factors, such as transaction type, execution time, and execution result, to produce a unique and stable identifier. Branch transaction execution is scheduled based on the transaction identifier. During transaction execution, the execution switching and default execution methods need to be determined according to the actual situation. Execution switching can be used to handle some abnormal situations, while default execution can be used to ensure system continuity and stability in certain situations. The design of execution scheduling requires comprehensive consideration of various factors, such as transaction priority, execution time window, and resource constraints, to achieve efficient and reliable execution scheduling.
[0110] As an embodiment of the present invention: the global transaction manager is also used for:
[0111] Determine the operation data, operation status information, and transaction efficiency of each branch transaction in the global transaction and its corresponding database;
[0112] Determine the coordination state vector of each branch transaction when executing the branch transaction based on the operation data;
[0113] Based on the preset transaction monitoring mechanism, the execution record behavior and operation status information are polled and recorded, and the transaction operation status vector of each branch is recorded.
[0114] A Gaussian distribution model is constructed based on the coordination state vector, the operation state vector, and the transaction efficiency.
[0115] Based on the Gaussian distribution model, identify the branch transactions in the global transaction that have differences and need to be optimized.
[0116] The principle behind the above technical solution is as follows:
[0117] In its implementation, this invention retrieves relevant information by querying databases or other data sources and associates it with corresponding branch transactions. A coordination state vector is calculated based on the actual values of the operational data to determine the coordination status and potential problems between branch transactions. During this process, technical means such as logging and monitoring are employed to record the operational status of each branch transaction and analyze and process it as needed. The Gaussian distribution model in this invention is a commonly used machine learning model for predicting and evaluating the differences and impacts between different branch transactions. When building the model, multiple factors are considered, such as historical data and business rules, to obtain more accurate prediction and evaluation results. By comparing the differences and impacts between different branch transactions, branches that may require optimization are identified, and corresponding improvement suggestions or strategies are provided to improve the overall performance and reliability of the system.
[0118] As one embodiment of the present invention: the determination of the returned result further includes:
[0119] When a rollback operation exists, retrieve the first exception event during the execution of at least one branch transaction;
[0120] Based on the execution content of the first abnormal event and the preset abnormal response mechanism, the first abnormal event is marked as an abnormal event in the abnormal transaction log.
[0121] Emergency proxy replacement is performed on at least one branch transaction based on the anomaly label.
[0122] The principle behind the above technical solution is as follows:
[0123] In its implementation, this invention, when a rollback operation is involved, acquires the first abnormal event during the execution of at least one branch transaction. This is achieved by setting an anomaly detection mechanism, such as setting an anomaly threshold, triggers, or monitoring programs, to monitor and capture abnormal events. Upon capturing an abnormal event, an anomaly response mechanism can be immediately triggered for processing. Based on the execution content of the first abnormal event and the preset anomaly response mechanism, the first abnormal event is marked as an anomaly in the abnormal transaction log. Anomaly marking refers to recording and classifying relevant information about the abnormal event. During marking, information such as the type, cause, and time of the abnormal event needs to be considered for classification and labeling, thereby facilitating subsequent processing and querying. Based on the anomaly marking, an emergency proxy replacement is performed on at least one branch transaction. Emergency proxy replacement refers to resolving the anomaly problem through proxy replacement after an abnormal event occurs, ensuring the normal operation of the system.
[0124] As one embodiment of the present invention: the determination of the returned result further includes:
[0125] When a commit operation exists, all branch transactions between the client and the global transaction manager are confirmed;
[0126] The client determines the standard operation data for all branch transactions; the standard operation data includes the standard proxy operations and proxy processes for each branch transaction during the execution of operations.
[0127] The client inserts standard operational data into the data unit associated with the corresponding branch transaction.
[0128] The principle behind the above technical solution is as follows:
[0129] In practical implementation, when a commit operation occurs, all branch transactions between the client and the global transaction manager are confirmed. A commit operation is a request initiated by the client to the global transaction manager to commit local transactions and obtain a response from the global transaction manager. After the client issues a commit request, the global transaction manager needs to confirm whether the local transaction committed by the client is consistent with its state in the database. If so, it will send a response to the client; otherwise, it will throw an exception. Therefore, before confirming all branch transactions committed by the client, it is necessary to check the state of each branch transaction committed by the client and record the state of each branch in the global transaction manager to ensure the consistency and reliability of the system. The client determines the standard operation data for all branch transactions. Standard operation data refers to the standard operations and procedures that need to be followed during the execution of each branch transaction. It is generated by the client based on its own business logic and rules to guide the client's behavior on that branch. After determining the standard operation data, the client can store this data in the 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 branch transactions when a global transaction begins; branch transactions include Java branch transactions and C language branch transactions.
[0132] Java Global Transaction Controller: Used to invoke the first business program of a Java branch transaction through the client, and to operate the first database through JDBC via the first business program;
[0133] C language business transaction proxy: used to request the transaction middleware of the C language branch transaction to call the client business program, and operate the second database through the client business program;
[0134] Client: Used to receive execution information of branch transactions and determine the return result; wherein the return result includes a commit operation or a rollback operation.
[0135] In specific implementation, such as Figure 2 and Figure 3 As shown, the process of the present invention is as follows:
[0136] Global transaction begins:
[0137] When a client declares a global transaction to the Java Global Transaction Manager, the Java Global Transaction Manager will prepare accordingly.
[0138] Java branch transaction begins:
[0139] The client notifies the global transaction manager that a Java branch transaction has begun. After the global transaction manager registers this, it declares the start of a JDBC branch transaction to database A.
[0140] Java language branch business:
[0141] The client directly calls the Java business program, which operates on database A via JDBC and returns the business results.
[0142] C language branch transaction begins:
[0143] The client declares the start of the C language branch transaction to the global transaction manager. The global transaction manager registers this 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 the database B.
[0144] Client calls C language business logic:
[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 client's business program through the transaction middleware, operates on 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 a transaction commit or rollback based on the execution status of the global business logic. The Java global transaction manager retrieves the two branches of the global transaction. If it's a rollback, a rollback operation is initiated to both branch transaction databases, and the result is returned. If the transaction is a commit, a pre-commit is initiated to both branch transactions, as shown in Figure 6.1. The pre-commit returns its result to the global transaction manager, as shown in Figure 6.2. The global transaction manager determines whether all branch pre-commits were successful. If any fails, a rollback operation is initiated to all branch databases, resulting in a complete rollback. If all pre-commits are successful, a commit operation is initiated to all branch transactions, as shown in Figure 6.2. Finally, based on the return results of each branch transaction, the result is returned to the client. In this process, the C language's transaction declaration, pre-commit, commit, and result return are all handled through a proxy.
[0148] The global transaction result is returned to the client:
[0149] After a commit or rollback is completed, the results will be returned. The transaction manager will synthesize the results from each branch and return them to the front-end client.
[0150] The beneficial effects of this invention are as follows:
[0151] This invention executes commands issued by the Java global transaction coordinator within the C language business system via a proxy, thus coordinating global transactions. It achieves the integration of transactions between the Java and C language business systems without increasing business development workload or exposing database interfaces. This invention allows for the integration of transactions between C and Java-developed business systems without rewriting the C language business system in Java, saving costs. For Java developers, the complexity of transaction coordination between the C and C language business systems is eliminated; they only need to develop the corresponding business processing modules. Global transaction coordination is handled by the Java global transaction coordinator and the C language transaction proxy, technically reducing development difficulty. If the goal is to convert a traditional C language business system to a Java language business system, development can proceed in stages, allowing for a smooth transition. Java global transactions typically require exposing database connections to the global transaction manager. However, in cross-departmental and multi-unit projects, databases between different units are usually not exposed. This proposal retains data-related configurations within the traditional C language business system while achieving global transaction coordination.
[0152] Obviously, those skilled in the art can make various modifications and variations to this invention without departing from its spirit and scope. Therefore, if these modifications and variations fall within the scope of the claims of this invention and their equivalents, this invention also intends 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 start of a global transaction, it registers branch transactions; these branch transactions include Java branch transactions and C language branch transactions, and the global transaction manager is the Java global transaction manager. The client calls the first business program of the Java branch transaction, and the first business program operates the first database through JDBC. The client requests a transaction middleware call from the C language branch transaction request to invoke the client's business program, and then operates the second database through the client's business program; whereby... When the client requests the transaction middleware of the C language branch transaction to call the client's business program, it also includes: The C language transaction proxy of the C language branch transaction receives the call information, parses the call information, and determines the client business program to be called based on the parsed parameters. The system receives branch transaction execution information from the client, determines the return result, and returns it to the client; the return result includes a commit operation or a rollback operation. The client is also used for: Establish a process framework for branch transactions, and correlate the process framework with execution information to determine transaction response nodes; Based on the response node, establish a session unit for each branch transaction; Through the session unit, the client receives session messages for each branch transaction; the session messages include: branch transaction execution progress and branch transaction execution status; Based on the session messages, a transaction identifier is generated in the global transaction manager; the transaction identifier includes a normalized transaction identifier and a faulty transaction identifier. Branch transaction execution is scheduled based on transaction identifier; execution scheduling includes execution switching and execution default.
2. The XA-based transaction coordination method as described in claim 1, characterized in that, When the Java Global Transaction Manager receives a declaration message indicating the start of a global transaction, it initiates a branch transaction; the declaration message includes at least one Java branch transaction start message and at least one C language branch transaction start message.
3. The XA-based transaction coordination method as described in claim 2, characterized in that, The Java global transaction manager is also used to retrieve branch transactions and, when a transaction has been committed, initiate a pre-commit to the corresponding branch transaction. The pre-commit result is determined by the global transaction manager to determine whether all branch transactions have been successfully committed, and if any commit fails, the execution information of all branch transactions is rolled back.
4. The XA-based transaction coordination method as described in claim 1, characterized in that, The registration of branch transactions also includes: Obtain the 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 order and transaction division identifier of each branch transaction; Based on the transaction order, the branch transactions are arranged sequentially, and index indication information is generated based on the sequential arrangement and transaction division identifier. Incorporate index indication information into each branch transaction.
5. The XA-based transaction coordination method as described in claim 1, characterized in that, The global transaction manager is also used for: Determine the operation data, operation status information, and transaction efficiency of each branch transaction in the global transaction and its corresponding database; Determine the coordination state vector of each branch transaction when executing the branch transaction based on the operation data; Based on the preset transaction monitoring mechanism, the execution record behavior and operation status information are polled and recorded, and the transaction operation status vector of each branch is recorded. A Gaussian distribution model is constructed based on the coordination state vector, the operation state vector, and the transaction efficiency. Based on the Gaussian distribution model, identify the branch transactions in the global transaction that have differences and need to be optimized.
6. The XA-based transaction coordination method as described in claim 1, characterized in that, The determination of the returned result also includes: When a rollback operation exists, retrieve the first exception event during the execution of at least one branch transaction; Based on the execution content of the first abnormal event and the preset abnormal response mechanism, the first abnormal event is marked as an abnormal event in the abnormal transaction log. Emergency proxy replacement is performed on at least one branch transaction based on the anomaly label.
7. The XA-based transaction coordination method as described in claim 1, characterized in that, The determination of the returned result also includes: When a commit operation exists, all branch transactions between the client and the global transaction manager are confirmed; The client determines the standard operation data for all branch transactions; the standard operation data includes the standard proxy operations and proxy processes for each branch transaction during the execution of operations. The client inserts standard operational data into the data unit associated with the corresponding branch transaction.
8. An XA-based transaction coordination device, characterized in that, The device includes: Global Transaction Manager: Used to register branch transactions when a global transaction begins; branch transactions include Java branch transactions and C language branch transactions, and the global transaction manager is the Java global transaction manager; Java Global Transaction Controller: Used to invoke the first business program of a Java branch transaction through the client, and to operate the first database through JDBC via the first business program; C language business transaction proxy: used to request transaction middleware to call client business programs in C language branch transactions, and then operate the second database through the client business programs; whereby... When the client requests the transaction middleware of the C language branch transaction to call the client's business program, it also includes: The C language transaction proxy of the C language branch transaction receives the call information, parses the call information, and determines the client business program to be called based on the parsed parameters. Client: Used to receive execution information of branch transactions and determine the return result; wherein, the return result includes a commit operation or a rollback operation; The client is also used for: Establish a process framework for branch transactions, and correlate the process framework with execution information to determine transaction response nodes; Based on the response node, establish a session unit for each branch transaction; Through the session unit, the client receives session messages for each branch transaction; the session messages include: branch transaction execution progress and branch transaction execution status; Based on the session messages, a transaction identifier is generated in the global transaction manager; the transaction identifier includes a normalized transaction identifier and a faulty transaction identifier. Branch transaction execution is scheduled based on transaction identifier; execution scheduling includes execution switching and execution default.