A global transaction collaboration method, device, equipment and medium
By introducing local proxies into services, the problem of transaction sharing after single application service is solved, the reference of unvalidated data between services and the simplification of service deployment are realized, and the service heterogeneous data stack and fine-grained expansion and contraction are supported.
Patent Information
- Application Number
- CN202010662963.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-07-10
- Publication Date
- 2024-09-10
- Estimated Expiration
- 2040-07-10
AI Technical Summary
After the single application is service-oriented, database transaction sharing becomes a big problem. Traditional methods are difficult to implement unvalidated business data references between services, which increases the difficulty of splitting the single application into microservices and makes it difficult to implement service-oriented deployment.
It uses a local agent deployed in the same process as the service to receive service requests from external clients in real time. It implements data operations on unvalidated transactions through the local agent, supports intra-transaction data to be visible to third-party services, and reduces the difficulty of splitting microservices in a single application. , to achieve smooth splitting of services.
It realizes the reference of unvalidated business data between services, supports the evolution of service heterogeneous data stacks and fine-grained on-demand expansion or contraction, and simplifies the service-oriented deployment process.
Smart Images

Figure CN113992750B
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a global transaction collaboration method, apparatus, device, and computer-readable storage medium. Background Art
[0002] Traditional monolithic applications often have difficulty responding to business demands quickly when the business grows. For this reason, monolithic applications can be transformed into services. However, after the monolithic application is service-oriented, database transaction sharing becomes a big problem. A database transaction refers to a sequence of database operations that access and possibly operate various data items. These operations are either all executed or not executed at all, and are an indivisible unit of work. A database transaction consists of all database operations executed between the start and end of a transaction.
[0003] At present, the traditional practice in the industry is to vertically split the business, realize business logic reconstruction, and avoid the problem of intermediate transactions that reference the same resources during database processing. Specifically, after the business is split into multiple services, the global transaction coordinator can be used to realize collaborative segmented transactions and collaborative transaction submission between services. For example, the global transaction coordinator starts a global transaction, then tries service A, and tries service B, that is, reserves corresponding business resources for service A and service B respectively, and then can confirm service A and service B at the same time, or cancel service A and service B at the same time, ensuring transaction consistency.
[0004] However, this method requires each service to be split and submitted in segments, and cannot reference each other's ineffective business data. This increases the difficulty of splitting a monolithic application into microservices and makes it difficult to achieve service-oriented deployment. Summary of the invention
[0005] The present application provides a global transaction coordination method, which solves the problem in the related art that the microservices split from the monolithic application cannot reference ineffective business data, which increases the difficulty of splitting the microservices from the monolithic application and makes it difficult to implement service-oriented deployment. The present application also provides a device, equipment, computer-readable storage medium and computer program product corresponding to the above method.
[0006] In a first aspect, the present application provides a global transaction coordination method, which utilizes a local proxy deployed in the same process as the service to proxy service requests from external clients, receive transaction operations of external related services in real time, and implement data operations of ineffective transactions.
[0007] Specifically, the first service receives a first service request from a client, the first service request is used to request to call the first service, and then the first service calls the first local agent to create a first local transaction, and sends a first remote service request to the second service, so that the second service can call the second local agent to create a second local transaction. Then the first service calls the first local agent to receive the transaction operation of the associated business, that is, the second service, and submits the transaction operation to the first local transaction for execution. The first service calls the first local agent to send a global transaction submission request, so that the first local agent submits the first local transaction, and the second local agent submits the second local transaction.
[0008] In this method, when an external client calls the first service and the first service remotely calls the second service, the first service can also receive the transaction operation of the second service through a local proxy and submit it to the first local transaction for execution, thereby enabling the second service to reference the ineffective business data of the first service. This makes it possible to support data within a transaction to be visible to third-party services, reduces the difficulty of splitting a monolithic application into microservices and the difficulty of service-oriented deployment, and achieves smooth service splitting. Furthermore, this method also supports the evolution of heterogeneous data stacks of services, as well as fine-grained on-demand expansion or reduction of capacity.
[0009] In some possible implementations, services may reference ineffective business data through service requests. Specifically, before the first service calls the first local agent to receive the transaction operation of the second service, the first service receives a second remote service request from the second service calling the second local agent, the second remote service request is used to remotely call the first service, and the second remote service request includes a global transaction identifier.
[0010] In some possible implementations, the first service may call the first local agent to create a transaction agent for a first local transaction, and the first service submits the transaction operation to the first local transaction for execution through the transaction agent.
[0011] In some possible implementations, the second service can operate resources corresponding to the first service, such as a database, through the second local agent, thereby referencing the ineffective business data of the first service. Specifically, before the first service calls the first local agent to receive the transaction operation of the second service, the first service calls the first local agent to receive the change registration information of the second resource called by the second service.
[0012] In some possible implementations, a service usually has multiple copies. To this end, the first service calls the first local agent to query the service node corresponding to the second service, and calls the first local agent to start a global transaction. Then the first service calls the first local agent to generate a first remote service request. The first remote service request carries a global transaction identifier. The first remote service request can be sent to the service node corresponding to the second service for remotely calling the second service.
[0013] In some possible implementations, the first service may call the first local agent to send a global transaction commit request to the cluster transaction manager, so that the cluster transaction manager sends a local transaction commit request to the local agent corresponding to each local transaction when each transaction is successfully executed.
[0014] In some possible implementations, the first service may also call the first local agent to register with the cluster transaction manager, and when the first local agent is in a normal state, the first service calls the first local agent to send feedback in response to a health check request sent by the cluster transaction manager.
[0015] In some possible implementations, when the first local agent recovers from an abnormal state to a normal state, the first service may call the first local agent to re-register with the cluster transaction manager, and the first service calls the first local agent to receive a rollback request from the cluster transaction manager to roll back the transaction.
[0016] In a second aspect, the present application provides a global transaction coordination device. The device comprises:
[0017] A communication module, configured to receive a first service request from a client, wherein the first service request is used to request to call a first service;
[0018] A creation module, used for calling a first local agent to create a first local transaction;
[0019] The communication module is further configured to call the first local agent to send a first remote service request to the second service, so that the second service calls the second local agent to create a second local transaction;
[0020] The communication module is further used to call the first local agent to receive the transaction operation of the second service;
[0021] A submission module, configured to call the first local agent to submit the transaction operation to the first local transaction execution;
[0022] The communication module is further configured to call the first agent to send a global transaction submission request, so that the first service calls the first local agent to submit the first local transaction, and the second service calls the second local agent to submit the second local transaction.
[0023] In some possible implementations, the communication module is further configured to:
[0024] Before calling the first local agent to receive the transaction operation of the second service, a second remote service request from the second service to call the second local agent is received, the second remote service request is used to remotely call the first service, and the second remote service request includes a global transaction identifier.
[0025] In some possible implementations, the creation module is further configured to:
[0026] Calling the first local agent to create a transaction agent for a first local transaction;
[0027] The submission module is specifically used for:
[0028] The transaction operation is submitted to the first local transaction execution through the transaction agent.
[0029] In some possible implementations, the communication module is further configured to:
[0030] Before the first service calls the first local agent to receive the transaction operation of the second service, the first local agent is called to receive the change registration information of the second resource caused by the second service calling the second local agent.
[0031] In some possible implementations, the device further includes:
[0032] A query module, configured to call the first local agent to query a service node corresponding to the second service;
[0033] An opening module, used for calling the first local agent to open a global transaction;
[0034] A generating module is used to call the first local agent to generate a first remote service request, wherein the first remote service request carries a global transaction identifier, and the first remote service request is used to remotely call the second service.
[0035] In some possible implementations, the communication module is specifically used to:
[0036] The first local agent is called to send a global transaction commit request to the cluster transaction manager, so that the cluster transaction manager sends a local transaction commit request to the local agent corresponding to each local transaction when each transaction is successfully executed.
[0037] In some possible implementations, the device further includes:
[0038] A registration module, used for calling the first local agent to register with the cluster transaction manager;
[0039] The communication module is configured to, when the first local agent is in a normal state, call the first local agent to send feedback in response to a health check request sent by the cluster transaction manager.
[0040] In some possible implementations, the device further includes a rollback module;
[0041] The registration module is further configured to call the first local agent to re-register with the cluster transaction manager when the first local agent recovers from an abnormal state to a normal state;
[0042] The rollback module is used to receive a rollback request from the cluster transaction manager and perform transaction rollback.
[0043] In a third aspect, the present application provides a device, comprising a processor and a memory. The processor and the memory communicate with each other. The processor is used to execute instructions stored in the memory, so that the device executes the global transaction coordination method as described in the first aspect or any implementation of the first aspect.
[0044] In a fourth aspect, the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores instructions, wherein the instructions instruct a device to execute the global transaction collaboration method described in the first aspect or any one of the implementations of the first aspect.
[0045] In a fifth aspect, the present application provides a computer program product comprising instructions, which, when executed on a device, enables the device to execute the global transaction coordination method described in the first aspect or any one of the implementations of the first aspect.
[0046] Based on the implementations provided in the above aspects, this application can also be further combined to provide more implementations. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] In order to more clearly illustrate the technical method of the embodiments of the present application, the drawings required for use in the embodiments are briefly introduced below.
[0048] Figure 1 A system architecture diagram of a global transaction collaboration method provided in an embodiment of the present application;
[0049] Figure 2An interactive flow chart of a global transaction collaboration method provided in an embodiment of the present application;
[0050] Figure 3 An interactive flow chart of a global transaction collaboration method provided in an embodiment of the present application;
[0051] Figure 4 An interactive flow chart of a global transaction collaboration method provided in an embodiment of the present application;
[0052] Figure 5 An interactive flow chart of a global transaction collaboration method provided in an embodiment of the present application;
[0053] Figure 6 An interactive flow chart of a global transaction collaboration method provided in an embodiment of the present application;
[0054] Figure 7 An interactive flow chart of a global transaction collaboration method provided in an embodiment of the present application;
[0055] Figure 8 A schematic diagram of splitting an application into microservices provided in an embodiment of the present application;
[0056] Fig. 9 A schematic diagram of splitting an application into microservices provided in an embodiment of the present application;
[0057] Fig.10 A schematic diagram of the structure of a global transaction coordination device provided in an embodiment of the present application;
[0058] Fig.11 A schematic diagram of the structure of a device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0059] The terms "first" and "second" in the embodiments of the present application are used for descriptive purposes only and should not be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features. Therefore, the features defined as "first" and "second" may explicitly or implicitly include one or more of the features.
[0060] First, some technical terms involved in the embodiments of the present application are introduced.
[0061] Monolithic applications are applications that integrate different functional modules into one process. Monolithic applications usually have only one package file, such as a war package. Monolithic applications are easy to develop and do not rely on other interfaces, so monolithic interfaces are also easier to test. In addition, the deployment of a monolithic application can be achieved by deploying the directory of the monolithic application in the operating environment, which shows that monolithic applications are also easy to deploy. For this reason, office systems such as supply chain management (SCM), enterprise resource planning (ERP), and customer relationship management (CRM) often use monolithic applications.
[0062] Monolithic applications have relatively poor scalability and often have difficulty responding to business demands quickly when the business grows. To this end, monolithic applications can be transformed into services. Service transformation refers to transforming different functional modules of monolithic applications into independent services or microservices, which call each other through remote procedure call interfaces (RPC).
[0063] A transaction specifically refers to a program execution unit that accesses and possibly updates various data items in a database. The program execution unit can be a database operation sequence, in which all operations are either executed or not executed, and is an indivisible unit of work. A transaction consists of all operations executed between the start and end of a transaction.
[0064] From the perspective of resource management, transactions can be divided into global transactions and local transactions. Among them, global transactions refer to transactions coordinated and managed by resource managers. Global transactions are usually distributed transactions across databases. Local transactions refer to transactions directly controlled by resource managers, and local transactions usually do not have distributed transaction processing capabilities.
[0065] For ease of understanding, global transactions and local transactions are illustrated below with specific examples. For example, in an e-store application, the application may include an order system and a product system. The order system uses the order database db_order, and the product system uses the product database db_product. In the order system, only transactions for order-related operations can be guaranteed, and in the product system, only transactions for product-related operations can be guaranteed. When a create order operation is performed in the order system, a transaction for creating an order is generated. This transaction is a local transaction. When a create order operation is performed in the order system and an inventory deduction operation is performed in the product system, a transaction for creating an order and deducting inventory is generated. This transaction is a global transaction.
[0066] Based on this, when a monolithic application is transformed into a service, the transaction corresponding to the call of two or more services can be regarded as a global transaction. For example, when an application calls service A, service A also needs to call service B, then a global transaction is generated.
[0067] After the monolithic application is service-oriented, database transaction sharing becomes a big problem. The traditional practice in the industry is to vertically split the business, reconstruct the business logic, and avoid the problem of intermediate transactions that reference the same resources during database processing. Specifically, after the business is split into multiple services, the global transaction coordinator can be used to achieve collaborative segmented transactions and collaborative transaction submission between services. For example, the global transaction coordinator starts a global transaction, then tries service A and service B, that is, reserves the corresponding business resources for service A and service B respectively, and then can confirm service A and service B at the same time, or cancel service A and service B at the same time, ensuring the consistency of global transactions.
[0068] However, this method requires each service to be split and submitted in segments, and cannot reference each other's ineffective business data. This increases the difficulty of splitting a monolithic application into microservices and makes it difficult to achieve service-oriented deployment.
[0069] In view of this, an embodiment of the present application provides a global transaction collaboration method. The method provides a local proxy mechanism, that is, a local proxy deployed in the same process as the service is used to proxy the service's external resource operation requests and / or database operation requests. When the service calls other services through the RPC interface, the business process of the current service is recorded and suspended as needed, and a remote service request is initiated to the above-mentioned other services through the local proxy. The local agent of the other service can create a corresponding local transaction. The service on the calling side can also receive the transaction operation of the service on the called side and submit it to the original local transaction execution. When the service on the calling side sends a global transaction submission request through the local agent, the service on the calling side and other services on the called side submit their respective local transactions through their respective local agents, thereby realizing the reference to the ineffective business data. This can reduce the difficulty of splitting a monolithic application into microservices, and facilitate service-oriented deployment.
[0070] For ease of description, the present application refers to the service on the calling side as the first service, and the service on the called side as the second service. The local proxy corresponding to the first service is referred to as the first local proxy, and the local proxy corresponding to the second service is referred to as the second local proxy.
[0071] The first local agent receives a first service request, where the first service request is used to request to call a first service. Then, the first local agent creates a first local transaction according to the first service request, and sends a first remote service request to a second service, so that a second local agent corresponding to the second service creates a second local transaction. The first local agent sends a global transaction commit request, so that the first local agent commits the first local transaction, and the second local agent commits the second local transaction.
[0072] For ease of understanding, the present application also provides a specific example. In this example, the first local transaction created by the first local agent can be a new data table, in which data is written. Since the transaction has not been submitted, the above data has not taken effect. When the first service calls an external service, such as the second service, through the first local agent, the second service can create a second local transaction through the second local agent. The second service can also call the second local agent to trigger a transaction operation on the data in the first local transaction. The first service can receive the transaction operation of the second service through the first local agent, and submit the transaction operation to the first local transaction for execution, thereby enabling the second service to reference the ineffective business data of the first service. In some implementations, the local agent can also interact with the cluster transaction manager, so that the cluster transaction manager can track the service health of each service in the cluster scenario, the call relationship of the service operation in the cluster and the associated resource operation record, and coordinate the synchronous submission or synchronous rollback of the overall transaction.
[0073] See also Figure 1 The system architecture diagram of the global transaction coordination method shown in FIG. Figure 1 As shown, the system includes a client (e.g., an external client), a service, and a local agent deployed in the same process as the service. Furthermore, the system may also include a cluster transaction manager. In related technologies, an external client usually makes a service call by initiating a service request to the service itself, such as Figure 1 As shown in the original call relationship, in the embodiment of the present application, the external client makes a service call through a local agent deployed in the same process as the service, such as calling a remote service interface or a local transaction interface, so as to reference ineffective business data.
[0074] Among them, the local agent is used to proxy the service's external resource operation requests and / or database operation requests, record and suspend the current business process as needed, call the cluster transaction manager and other service's local agents as needed to implement related business processing, and receive transaction operations of external related businesses in real time to implement data operations of ineffective transactions.
[0075] The cluster transaction manager is responsible for tracking the service health of each service in the cluster scenario, the corresponding relationship between each service in the cluster, the call relationship of service operations in the cluster and the associated resource operation records, and coordinating the synchronous submission or synchronous rollback of the overall transaction.
[0076] The local proxy and the service are deployed in the same process. The service can be deployed in a computer cluster. The computer cluster can include at least one computer device, the service can be deployed in the at least one computer device, and the local proxy of the service is specifically deployed in the computer device running the service.
[0077] Next, the global transaction collaboration method provided in the embodiment of the present application is introduced in conjunction with the method flow chart.
[0078] See also Figure 2 The flowchart of the global transaction coordination method shown in FIG. 1 includes:
[0079] S202: The first service receives a first service request from a client.
[0080] The first service request is used to request to call the first service. When an external client such as an external application or an external process has a service call requirement, it can generate a service request and send the service request. For example, when an external client has a call requirement for the first service, it generates a first service request and sends the first service request. The first service receives the first service request.
[0081] The first service request includes at least a service identifier of the first service. In some implementations, the first service request may also include a parameter of the first service, which refers to a call parameter of the first service. In some examples, the call parameter of the first service may be an input parameter and / or an output parameter of a call interface of the first service.
[0082] S204: The first service calls the first local agent to create a first local transaction.
[0083] The first local transaction is specifically an operation sequence formed by the transaction operations included in the first service. Among them, the transaction operations can be divided into operation types such as database operations and non-database operations. Database operations refer to operations that add, delete, search and / or modify (i.e., add, delete, search and / or correct) a database. Non-database operations refer to operations other than database operations, such as alarm operations.
[0084] The first local proxy is a local proxy of the first service, and is used to proxy the first service's external operation requests, such as database operation requests, resource operation requests, and the like. The first local proxy and the first service are deployed in the same process, and the first local proxy and the first service can be regarded as different components of the same process. Specifically, the first service calls the first local proxy and creates a first local transaction using the function provided by the corresponding programming language framework. For example, under the spring framework, the first service can call the first local proxy in response to the first service request and create a first local transaction using the createTransactonIfNecessary() function. Among them, after creating the transaction, the following operations can be performed: start transaction, commit transaction, and / or rollback transaction.
[0085] When the first service needs to call other services such as the second service, the first service can also call the first local agent to create a global transaction. The global transaction is specifically an operation series formed by the transaction operations included in the first service and the transaction operations included in the second service.
[0086] S206: The first service calls the first local agent to send a first remote service request to the second service.
[0087] The first remote service request is used to request a remote call to a second service. Similar to the first service request, the first remote service request may include a service identifier of the second service to be remotely called. Further, the first remote service request may also include a parameter of the second service, which refers to a call parameter of the second service. In some examples, the call parameter of the second service may be an input parameter and / or an output parameter of a call interface of the second service.
[0088] In the embodiment of the present application, the service called by the external client request is the originating service, and the transaction created by the local agent of the originating service is the originating transaction. The originating service creates the global transaction after receiving the service request. Based on this, the local agent can also carry the identifier of the global transaction, that is, the global transaction ID, in the service request sent to the non-originating service to distinguish between the originating service and the non-originating service. If the service request does not have any global transaction ID, a new transaction is created. The service that receives this type of request is the originating service, and the corresponding transaction is the originating transaction, which is responsible for the overall transaction submission initiation operation (global transaction submission initiation operation) in cluster transaction coordination.
[0089] Specifically, when the first service calls the second service, it can first call the first local agent to query the service node corresponding to the second service, call the first local agent to start a global transaction, and call the first local agent to generate a first remote service request. The remote service request carries a global transaction identifier. In this way, the first service can send the first remote service request to the service node of the second service through the first local agent.
[0090] S208: The second service calls the second local agent to create a second local transaction.
[0091] The second local transaction is specifically an operation sequence formed by the transaction operations included in the second service. Among them, the transaction operations include operation types such as database operations and non-database operations. Database operations refer to operations that add, delete, search and / or modify (i.e., add, delete, search and / or correct) a database. Non-database operations refer to operations other than database operations, such as alarm operations.
[0092] Specifically, the second service creates a second local transaction in response to the first remote service request. The second service may call the second local agent and use the function provided by the corresponding programming language framework to create the second local transaction. For example, in the spring framework, the second service calls the second local agent and uses the createTransactonIfNecessary() function to create the second local transaction. After the second transaction is created, the following operations may be performed: begin transaction, committransaction, and / or rollback transaction.
[0093] S210: The first service calls the first local agent to receive the transaction operation of the second service, and submits the transaction operation to the first local transaction for execution.
[0094] The first local transaction created by the first local agent and the second local transaction created by the second local agent are not submitted, so the data corresponding to the first local transaction and the data corresponding to the second local transaction are not effective. In some cases, the second service can also trigger a transaction operation for the data in the first local transaction. The first service calls the first local agent to receive the transaction operation of the second service, and submits the transaction operation to the first local transaction for execution. In this way, the second service references the ineffective business data of the first service.
[0095] In some implementations, services can reference ineffective business data through service requests. Specifically, the second service can also send a second remote service request to the first service through a second local agent, and the second remote service request is used to request a remote call to the first service. That is, the second service calls back the first service. The second remote service request carries a global transaction identifier so that the first service can find the transaction branch of the global transaction in the first service (such as the first local transaction) through the first local agent according to the global transaction identifier.
[0096] Furthermore, after receiving the second remote service request, the first service can query the transaction according to the global transaction identifier in the remote service request to determine that a corresponding local transaction branch exists locally, namely, the first local transaction. The first service can call the first local agent to create a transaction agent for the first local transaction, and the first service can submit the transaction operation of the second service to the first local transaction for execution through the transaction agent.
[0097] In some other implementations, the first resource of the first service and the second resource of the second service may share a database, and in this case, the resource needs to be operated on the originating service (e.g., the first service). Based on this, the second service registers resource changes through the second local agent. For example, to register changes to the second resource, the first service calls the first local agent to receive the change registration information of the second service calling the second local agent for the second resource. Then, the first service can call the first local agent to receive the transaction operation of the second service and submit it to the first local transaction for execution.
[0098] S212: The first service calls the first local agent to send a global transaction commit request.
[0099] As an originating service, the first service can call the first local agent to send a global transaction submission request, so that the first service calls the first local agent to submit the first local transaction, and the second service calls the second local agent to submit the second local transaction, thereby making the data corresponding to the first local transaction and the second local transaction effective.
[0100] In some implementations, the first service may call the first local agent to send a global transaction commit request to the cluster transaction manager, so that the cluster transaction manager sends a local transaction commit request to the local agent corresponding to each local transaction when each transaction is successfully executed. In this way, the local agent corresponding to each local transaction may respond to the local transaction commit request and submit the local transaction through the local agent corresponding to each local transaction. For example, the first service may respond to the local transaction commit request and call the first local agent to submit the first local transaction; the second service may respond to the local transaction commit request and call the second local agent to submit the second local transaction.
[0101] Based on the above description, an embodiment of the present application provides a global transaction collaboration method. This method uses a local proxy deployed in the same process as the service to proxy the service's external resource operation requests and / or database operation requests. When the service calls other services through the RPC interface, the business process of the current service is recorded and suspended as needed, and a remote service request is initiated to the above-mentioned other services through the local proxy. The local proxy of the other service can create a corresponding local transaction. The service on the calling side can receive the transaction operation of the service on the called side and submit it to the original local transaction for execution. When the service on the calling side can also send a global transaction submission request through the local proxy, the service on the calling side and other services on the called side submit their respective local transactions through their respective local proxies, thereby realizing the reference to the ineffective business data. This can reduce the difficulty of splitting a monolithic application into microservices, and facilitate service-oriented deployment.
[0102] In order to make the technical solution of the present application easier to understand, the global transaction collaboration method provided by the embodiment of the present application is described in detail below in combination with more specific embodiments from the perspectives of the second service calling back the first service through a service request and the second service operating the resources of the first service through a second local agent.
[0103] See also Figure 3 The flowchart of the global transaction coordination method shown in FIG. Figure 3 As shown, the first service is service A, the second service is service B, the first local agent is agent A, the second local agent is agent B, the first resource corresponding to the first service is local resource A, and the second resource corresponding to the second service is local resource B. Service A and agent A are deployed in the same process, such as the first process. Service B and agent B are deployed in the same process, such as the second process. The method includes:
[0104] 1. An external client sends a first service request, where the first service request is used to call service A.
[0105] In response to the first service request, the server performs the following steps:
[0106] 1.1: Service A performs an operation on local resource A.
[0107] The operation on local resource A may include the following steps:
[0108] 1.1.1: Service A calls Agent A to create the first local transaction;
[0109] 1.1.2: Service A calls agent A to perform resource change registration for local resource A.
[0110] Specifically, service A calls agent A to register resource changes for local resource A in the cluster manager.
[0111] 1.2: Service A calls external service (service name: service B, service parameters)
[0112] Among them, calling external services may include the following steps:
[0113] 1.2.1: Service A calls proxy A to query the service node of service B;
[0114] Specifically, agent A queries the service node of service B to obtain the address of the service node, so as to subsequently send a service request to the service node according to the address.
[0115] 1.2.2: Service A calls Agent A to start a global transaction.
[0116] When calling an external service, service A calls proxy A and checks whether there is a corresponding transaction through the global transaction identifier (global transaction ID). If there is a corresponding transaction, proxy A is called to forward the transaction operation of service B to the original service process for processing, otherwise the original transaction cannot be used. If there is no corresponding transaction, one is forwarded as a normal request.
[0117] 1.3: Service A calls agent A to send the first remote service request.
[0118] The first remote service request includes service parameters and metadata, and the metadata includes a global transaction ID.
[0119] 1.4: Service B calls proxy B to perform operations on local resource B.
[0120] The operation on the local resource B may include the following steps:
[0121] 1.4.1: Service B calls Agent B to create a second local transaction;
[0122] 1.4.2: Service B calls agent B to perform resource change registration for local resource B.
[0123] Service B calls agent B to create a second local transaction, and after executing the transaction exit, the transaction may not be automatically committed, but a two-phase commit method may be adopted. Specifically, agent B may wait for the processing notification of the originating service to realize unified submission and / or unified rollback of transactions.
[0124] Service B can also add a transaction operation through agent B. As shown in step 1.4.2.1, the additional transaction operation carries the following parameters: operation service, global transaction ID, and operation key data. The operation service can be service B.
[0125] 1.5: Service B calls an external service (service name: service A, service parameters).
[0126] Among them, calling external services may include the following steps:
[0127] 1.5.1: Service B calls Agent B to query the service node of Service A;
[0128] Service A may be provided by multiple service nodes. Agent B may search for the service node that creates the first local transaction according to the global transaction ID to obtain the address of the service node.
[0129] 1.5.2: Service B calls Agent B to send a second remote service request.
[0130] The second remote service request carries service parameters and metadata, which is specifically a global transaction ID.
[0131] After receiving the second remote service request, service A calling agent A executes the following steps:
[0132] 1.5.2.1: Service A calls proxy A to perform operations on local resource A;
[0133] 1.5.2.2: Service A calls Agent A to create a transaction agent for an existing transaction.
[0134] Specifically, service A calls proxy A, and first queries whether a transaction already exists locally through the global transaction ID in the second remote service request. If it does, proxy A is called to create a transaction proxy, which is used to forward the transaction operation to the original transaction (the first local transaction in this example). If it does not exist, proxy A creates a new session.
[0135] 1.5.2.3: Service A calls agent A to perform resource change registration for local resource A.
[0136] It should be noted that the operations performed by agent A on local resource A in step 1.1 and step 1.5.2.1 may be the same or different. For ease of description, the above operation in step 1.1 is referred to as operation 1 on local resource A, and the above operation in step 1.5.2.1 is referred to as operation 2 on local resource A.
[0137] Similarly, the resource change registration performed by agent B for local resource A in step 1.1.2 and step 1.5.2.3 may be the same or different. For ease of description, the above operation in step 1.1.2 is referred to as resource change registration 1, and the above operation in step 1.5.2.3 is referred to as resource change registration 2 in this embodiment of the application.
[0138] 1.5.2.4: Service A calls proxy A to submit the transaction operation of service B to the original local transaction execution.
[0139] Specifically, service A forwards transaction operations such as change operations to the original local transaction execution through the transaction proxy.
[0140] 1.5.2.5: Service A can also call proxy A to add transaction operations.
[0141] For example, service A is a product and service B is an order. An external client calls service A to add a product to a shopping cart, and service A calls service B to generate an order. At this time, service A can also call proxy A to add a transaction operation to increase the number of products in the order.
[0142] 1.6: Service A calls Agent A to send a global transaction commit request to the cluster transaction manager.
[0143] 1.7: The cluster transaction manager sends a local transaction commit request to agent A so that agent A commits the local transaction.
[0144] 1.8: The cluster transaction manager sends a local transaction commit request to agent B to enable agent B to commit the local transaction.
[0145] Figure 3 Call back service A from service B, and introduce the global transaction collaboration method by referring to the ineffective business data of service A. Next, operate the resources of service A from service B, and introduce the global transaction collaboration method because of the ineffective business data of service A.
[0146] See also Figure 4 The flowchart of the global transaction coordination method shown in FIG. Figure 4 As shown, the first service is service A, the second service is service B, the first local agent is agent A, the second local agent is agent B, the first resource of the first service is local resource A, and the second resource of the second service is local resource B. Service A and agent A are deployed in the same process, such as the first process. Service B and agent B are deployed in the same process, such as the second process. The method includes:
[0147] 1. An external client sends a first service request, where the first service request is used to call service A.
[0148] In response to the first service request, the server performs the following steps:
[0149] 1.1: Service A calls proxy A to perform operations on local resource A.
[0150] The operation on local resource A may include the following steps:
[0151] 1.1.1: Service A calls Agent A to create the first local transaction;
[0152] Agent A creates a first local transaction and can obtain a first local transaction ID and a global transaction ID, wherein the global transaction ID can be a universally unique identifier (UUID).
[0153] 1.1.2: Service A calls agent A to perform resource change registration for local resource A.
[0154] 1.2: Service A calls external service (service name: service B, service parameters)
[0155] Among them, calling external services may include the following steps:
[0156] 1.2.1: Service A calls proxy A to query the address of service B;
[0157] 1.2.2: Service A calls Agent A to start a global transaction.
[0158] When calling an external service, service A can call proxy A and check whether there is a corresponding transaction through the global transaction ID. If there is a corresponding transaction, it needs to be forwarded to the original service process for processing, otherwise the original transaction cannot be used. If there is no corresponding transaction, it is forwarded as a normal request.
[0159] 1.3: Service A calls Agent A to append a transaction operation.
[0160] 1.4: Service A calls agent A to send the first remote service request.
[0161] The first remote service request includes service parameters and metadata, and the metadata includes a global service ID.
[0162] Service B performs the following steps in response to the first remote service request:
[0163] 1.4.1: Service B calls proxy B to perform operations on local resource B.
[0164] The operation on the local resource B may include the following steps:
[0165] 1.4.2: Service B calls Agent B to create an association for an existing transaction.
[0166] Specifically, service B calls agent B to create a transaction agent.
[0167] 1.4.3: Service B calls proxy B to query the address of service A.
[0168] 1.4.4: Service B calls agent B to perform resource change registration for local resource B.
[0169] 1.4.5: Service B calls agent B to feedback the resource change registration for local resource B to agent A.
[0170] 1.4.6: Service A calls proxy A to submit the change operation to the original local transaction (first local transaction) for execution.
[0171] 1.4.7: Service A calls Agent A to append a transaction operation.
[0172] 1.5: Service A calls Agent A to send a global transaction commit request.
[0173] In response to the global transaction commit request, the cluster transaction manager performs the following steps:
[0174] 1.6.1: The cluster transaction manager sends a local transaction commit request to agent B.
[0175] 1.6.2: The cluster transaction manager sends a local transaction commit request to agent A.
[0176] In some implementations, services can also implement in-process transaction references through local agents. This will be described in detail below in conjunction with specific embodiments.
[0177] See also Figure 5 The flowchart of the global transaction coordination method shown in FIG. Figure 5 As shown, the first service is service A, the second service is service B, the first local agent is agent A, and the second local agent is agent B. Service A and agent A are deployed in the same process, such as the first process. Service B and agent B are deployed in the same process, such as the second process. The method includes:
[0178] 1. Agent A registers a local transaction.
[0179] Specifically, agent A may register a local transaction with the cluster transaction manager.
[0180] 2. Agent A starts local transaction request listening.
[0181] Specifically, when a local service (such as service A) calls another service (such as service B), agent A needs to first create a listening queue locally, which is used to receive possible external service requests, such as the first service request mentioned above. The service request can be a database service request. Then agent A continues to listen to requests in the transaction process, and directly executes the relevant operations if there are externally added database operations.
[0182] The steps of agent A starting local transaction request monitoring specifically include the following:
[0183] 2.1 When the remote call is not completed, agent A monitors the task queue and executes data operation tasks.
[0184] Proxy A continuously listens to the service requests in the queue, performs transaction operations based on the service requests, and provides a callback notification mechanism to return the relevant request results to the caller. Since local transactions share the same connection, related operations are executed once according to the queue.
[0185] 3. Agent A sends the first remote service request.
[0186] Specifically, the agent A initiates the first remote service request in an asynchronous manner in the original thread, provides a callback interface to monitor the return value, and the original thread continues to execute the database queue monitoring operation.
[0187] Correspondingly, in response to the first remote service request, agent B executes the following steps:
[0188] 3.1 Agent B calls service B;
[0189] Service B can perform change operations on local resource B. Service B also operates the resources of service A to reference business data that is not effective for service A.
[0190] 3.2 Service B sends service A transaction operation to proxy B.
[0191] 3.2.1 Agent B performs database operations remotely.
[0192] The operation itself is asynchronous across processes, but it synchronously blocks the business request of the business party. When the receiver receives the database operation request submitted by the local agent of the external service process, it directly initiates the external request in an asynchronous manner in the original thread, provides a callback interface to monitor the return value, and the original thread continues to execute the database queue monitoring operation.
[0193] 3.2.2 Agent A searches and adds tasks to the original session task queue.
[0194] Agent A searches for the task queue corresponding to the local transaction ID based on the global transaction ID passed in, adds the database operation request to the queue, and registers a callback interface for asynchronously obtaining the database operation results.
[0195] 3.2.3 Agent A returns the execution result to Agent B.
[0196] Proxy A directly calls back the originally registered interface and returns the request result along the original path.
[0197] 3.2.4 Agent B returns the transaction operation results of Service A to Service B.
[0198] 3.3 Service B business processing.
[0199] 3.4 Service B returns the service B result.
[0200] Service B can return the service B result to proxy B, and then proxy B performs the following operations:
[0201] 3.4.1 Agent B returns the remote service call result to Agent A.
[0202] Agent B does not commit the transaction immediately, but directly suspends and waits for notification from the cluster transaction manager.
[0203] 4. Agent A ends local transaction request monitoring.
[0204] 5. Agent A returns the result of the service A operation to service A.
[0205] In some implementations, the present application also provides a registration keep-alive mechanism for the local proxy. Registration keep-alive is similar to registration keep-alive of microservices, and is used for service health checks. If a service anomaly is detected, scheduling is stopped and related transactions are notified to roll back to ensure transaction consistency.
[0206] Specifically, Figure 6 As shown, after the service is started, the local agent corresponding to the service, for example, the first local agent corresponding to the first service (agent A in this example) can be registered with the cluster transaction manager. When the first local agent is in a normal state, the first local agent can send feedback in response to the health check request sent by the cluster transaction manager. The cluster transaction manager can start a timer. When the timer reaches the set time, the cluster transaction manager does not receive feedback from the first local agent, then it can be considered that the first local agent is abnormal and the health check of the first service fails.
[0207] Based on this, the cluster transaction manager can record the health status of each service according to whether the local agent of each service sends feedback. When the service is abnormal or unhealthy, the cluster transaction manager can initiate the rollback of the associated transaction. Specifically, the cluster transaction manager can facilitate the associated transaction list and then roll back the transaction according to the associated transaction list.
[0208] In some implementations, the local proxy mainly rolls back external third-party resources (such as file requests, external SAAS service requests). Since these requests vary, the cluster transaction manager directly notifies the original service to roll back based on the registered logs, and the specific rollback method is customized by each service. Local transaction-related exceptions directly prompt risks for manual intervention.
[0209] Furthermore, if Figure 7As shown, when the first local agent recovers from an abnormal state to a normal state, the first local agent can re-register with the cluster transaction manager. The first local agent receives a rollback request from the cluster transaction manager and performs a transaction rollback.
[0210] The transaction collaboration method provided in the embodiment of the present application mainly splits the monolithic application into services or microservices, enables mutual reference of ineffective business data between services or microservices, supports data in transactions to be visible to third-party services, and realizes smooth service splitting. This can support the evolution of heterogeneous data stacks for different services and fine-grained on-demand expansion and contraction.
[0211] For ease of understanding, this application also provides a specific example. Figure 8 As shown in the figure, each plug-in of Openstack Neutron, such as service plug-in, core plug-in and driver, is deployed as an independent process and supports transparent calls between each other, thus realizing transaction coordination of plug-in and driver cross-process calls.
[0212] Furthermore, the embodiment of the present application also provides a schematic diagram of the Service Plugin and Core Plugin split process. Fig. 9 As shown, the service plugin uses a proxy to access the Core Plugin's related APIs, notifications, and databases.
[0213] Specifically, the service entry of Neutron Server is Pecan. Global transactions can be passed through custom Headers. By adding extensions by customizing Hooks in Pecan, the Header fields in Restful are identified and stored locally in the thread. At the same time, ContextProxy is provided in the hook to extend SessionProxy. When the business obtains the session through the context, the local transaction acquisition method is determined based on the global transaction ID. If a local session with the same transaction already exists, a proxy is created to forward related requests.
[0214] In the ServerPlugin service process, configure Proxy for other Plugins (here CorePlugin is used as an example), proxy all CorePlugin API requests, and forward them to other processes. The proxy method here can be inheritance or function hook.
[0215] Furthermore, the embodiment of the present application also provides a CallbackManager proxy. The relevant registrations of the Service Plugin listening to the CorePlugin's resource change events will be uniformly recorded in the cluster transaction manager. The cluster transaction manager notifies the Core Plugin process of the service subscription status. When a resource change occurs in the CorePlugin process, a Service Plugin will be selected according to the transaction status to send a resource change notification. The local callback component of the Service Plugin can notify the relevant callback interface to implement cross-process notification.
[0216] Combination of the above Figures 1 to 9 The global transaction collaboration method provided in the embodiment of the present application is introduced in detail. The apparatus and device provided in the embodiment of the present application will be introduced below in conjunction with the accompanying drawings.
[0217] See also Fig.10 The structural diagram of the global transaction coordination device shown in FIG. Fig.10 As shown, the device 1000 includes:
[0218] The communication module 1002 is used to receive a first service request from a client, where the first service request is used to request to call a first service;
[0219] A creation module 1004, configured to call a first local agent to create a first local transaction;
[0220] The communication module 1002 is further configured to call the first local agent to send a first remote service request to the second service, so that the second service calls the second local agent to create a second local transaction;
[0221] The communication module 1002 is further configured to call the first local agent to receive a transaction operation of the second service;
[0222] A submission module 1006, configured to call the first local agent to submit the transaction operation to the first local transaction execution;
[0223] The communication module 1002 is further configured to call the first agent to send a global transaction commit request, so that the first service calls the first local agent to commit the first local transaction, and the second service calls the second local agent to commit the second local transaction.
[0224] In some possible implementations, the communication module 1002 is further configured to:
[0225] Before calling the first local agent to receive the transaction operation of the second service, a second remote service request from the second service to call the second local agent is received, the second remote service request is used to remotely call the first service, and the second remote service request includes a global transaction identifier.
[0226] In some possible implementations, the creation module 1004 is further configured to:
[0227] Calling the first local agent to create a transaction agent for a first local transaction;
[0228] The submitting module 1006 is specifically used for:
[0229] The transaction operation is submitted to the first local transaction execution through the transaction agent.
[0230] In some possible implementations, the communication module 1002 is further configured to:
[0231] Before the first service calls the first local agent to receive the transaction operation of the second service, the first local agent is called to receive the change registration information of the second resource caused by the second service calling the second local agent.
[0232] In some possible implementations, the apparatus 1000 further includes:
[0233] A query module, configured to call the first local agent to query a service node corresponding to the second service;
[0234] An opening module, used for calling the first local agent to open a global transaction;
[0235] A generating module is used to call the first local agent to generate a first remote service request, wherein the first remote service request carries a global transaction identifier, and the first remote service request is used to remotely call the second service.
[0236] In some possible implementations, the communication module 1002 is specifically configured to:
[0237] The first local agent is called to send a global transaction commit request to the cluster transaction manager, so that the cluster transaction manager sends a local transaction commit request to the local agent corresponding to each local transaction when each transaction is successfully executed.
[0238] In some possible implementations, the apparatus 1000 further includes:
[0239] A registration module, used for calling the first local agent to register with the cluster transaction manager;
[0240] The communication module is configured to, when the first local agent is in a normal state, call the first local agent to send feedback in response to a health check request sent by the cluster transaction manager.
[0241] In some possible implementations, the apparatus 1000 further includes a rollback module;
[0242] The registration module is further configured to call the first local agent to re-register with the cluster transaction manager when the first local agent recovers from an abnormal state to a normal state;
[0243] The rollback module is used to receive a rollback request from the cluster transaction manager and perform transaction rollback.
[0244] The global transaction coordination device 1000 according to the embodiment of the present application may correspond to executing the method described in the embodiment of the present application, and the above and other operations and / or functions of each module / unit of the global transaction coordination device 1000 are respectively to implement Figures 2 to 7 For the sake of brevity, the corresponding processes of each method in the illustrated embodiment are not described in detail here.
[0245] The present application also provides a device. The device may be a terminal device such as a laptop computer or a desktop computer, or a computer cluster in a cloud environment or an edge environment. The global transaction coordination device 1000 is deployed in the device, and the device is specifically used to implement the following Fig.10 The functions of the global transaction coordination device 1000 in the illustrated embodiment.
[0246] Fig.11 A schematic diagram of the structure of a device 1100 is provided, such as Fig.11 As shown, the device 1100 includes a bus 1101, a processor 1102, a communication interface 1103, and a memory 1104. The processor 1102, the memory 1104, and the communication interface 1103 communicate with each other via the bus 1101.
[0247] The bus 1101 may be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Fig.11 Only one thick line is used in the diagram, but this does not mean that there is only one bus or only one type of bus.
[0248] The processor 1102 may be any one or more of a central processing unit (CPU), a graphics processing unit (GPU), a microprocessor (MP), or a digital signal processor (DSP).
[0249] The communication interface 1103 is used for communicating with the outside, for example, receiving a first service request from a client, calling a first local agent to send a first remote service request to a second service, calling the first local agent to receive a transaction operation of the second service, and the like.
[0250] The memory 1104 may include a volatile memory, such as a random access memory (RAM). The memory 1104 may also include a non-volatile memory, such as a read-only memory (ROM), a flash memory, a hard drive (HDD), or a solid state drive (SSD).
[0251] The memory 1104 stores executable codes, and the processor 1102 executes the executable codes to perform the aforementioned global transaction coordination method.
[0252] Specifically, in implementing Fig.10 In the case of the embodiment shown, and Fig.10 When each module of the global transaction coordination device described in the embodiment is implemented by software, Fig.10 The software or program code required for the functions of the creation module 1004 and the submission module 1006 is stored in the memory 1104. The communication module function is implemented through the communication interface 1103.
[0253] The communication interface 1103 receives the first service request from the client and transmits it to the processor 1102 through the bus 1101. The processor 1102 executes the program code corresponding to each unit stored in the memory 1104, such as the program code corresponding to the creation module 1004 and the submission module 1006, to execute the aforementioned global transaction collaboration method.
[0254] Specifically, the communication interface 1103 receives a first service request from the client, the processor 1102 executes the program code corresponding to the creation module 1004 to perform the step of calling the first local agent to create a first local transaction, and the communication interface 1103 also calls the first local agent to send a first remote service request to the second service, so that the second service calls the second local agent to create a second local transaction.
[0255] The communication interface 1103 calls the first local agent to receive the transaction operation of the second service, and the processor 1102 executes the program code corresponding to the submission module 1006 to execute the step of calling the first local agent to submit the transaction operation to the first local transaction execution. The communication interface 1103 also calls the first local agent to send a global transaction submission request, so that the first service calls the first local agent to submit the first local transaction, and the second service calls the second local agent to submit the second local transaction.
[0256] In some implementations, the communication interface 1103 is further used to:
[0257] A second remote service request is received from the second service to call the second local agent, where the second remote service request is used to remotely call the first service, and the second remote service request includes a global transaction identifier.
[0258] In some implementations, the processor 1102 is further configured to execute program codes corresponding to the creation module 1004 to perform the following method steps:
[0259] Calling the first local agent to create a transaction agent for a first local transaction;
[0260] The processor 1102 is specifically configured to execute the program code corresponding to the submitting module 1006 to perform the following method steps:
[0261] The transaction operation is submitted to the first local transaction execution through the transaction agent.
[0262] In some implementations, the communication interface 1103 is further used to:
[0263] The first local agent is called to receive the change registration information of the second resource called by the second local agent by the second service.
[0264] In some implementations, the processor 1102 is further configured to execute program codes corresponding to the query module, the start module, and the generation module to perform the following method steps:
[0265] Calling the first local agent to query a service node corresponding to the second service;
[0266] The first local agent is called to start a global transaction, and the first local agent is called to generate a first remote service request, where the first remote service request carries a global transaction identifier, and the first remote service request is used to remotely call the second service.
[0267] In some implementations, the communication interface 1103 is specifically used to:
[0268] The first local agent is called to send a global transaction commit request to the cluster transaction manager, so that the cluster transaction manager sends a local transaction commit request to the local agent corresponding to each local transaction when each transaction is successfully executed.
[0269] In some implementations, the processor 1102 is further configured to execute a program code corresponding to the registration module to perform the following method steps:
[0270] Calling the first local agent to register with the cluster transaction manager;
[0271] The communication interface 1103 is also used for:
[0272] When the first local agent is in a normal state, the first service calls the first local agent to send feedback in response to a health check request sent by the cluster transaction manager.
[0273] In some implementations, the processor 1102 is further configured to execute program codes corresponding to the registration module and the rollback module to perform the following method steps:
[0274] When the first local agent recovers from an abnormal state to a normal state, calling the first local agent to re-register with the cluster transaction manager;
[0275] The first local agent is called to receive a rollback request from the cluster transaction manager to perform transaction rollback.
[0276] An embodiment of the present application further provides a computer-readable storage medium, which includes instructions, and the instructions instruct a computer to execute the global transaction collaboration method of the global transaction collaboration device 1000.
[0277] The embodiment of the present application also provides a computer program product, and when the computer program product is executed by a computer, the computer executes any of the aforementioned global transaction collaboration methods. The computer program product can be a software installation package, and when any of the aforementioned global transaction collaboration methods is needed, the computer program product can be downloaded and executed on a computer.
[0278] It should also be noted that the device embodiments described above are merely schematic, wherein the units described as separate components may or may not be physically separated, and the components displayed as units may or may not be physical units, that is, they may be located in one place, or they may be distributed over multiple network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the scheme of this embodiment. In addition, in the drawings of the device embodiments provided by the present application, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines.
[0279] Through the description of the above implementation mode, the technicians in the field can clearly understand that the present application can be implemented by means of software plus necessary general hardware, and of course, it can also be implemented by special hardware including special integrated circuits, special CPUs, special memories, special components, etc. In general, all functions completed by computer programs can be easily implemented by corresponding hardware, and the specific hardware structure used to implement the same function can also be various, such as analog circuits, digital circuits or special circuits. However, for the present application, software program implementation is a better implementation mode in more cases. Based on such an understanding, the technical solution of the present application is essentially or the part that contributes to the prior art can be embodied in the form of a software product, which is stored in a readable storage medium, such as a computer floppy disk, a U disk, a mobile hard disk, a ROM, a RAM, a disk or an optical disk, etc., including a number of instructions to enable a computer device (which can be a personal computer, a training device, or a network device, etc.) to execute the methods described in each embodiment of the present application.
[0280] In the above embodiments, all or part of the embodiments may be implemented by software, hardware, firmware or any combination thereof. When implemented by software, all or part of the embodiments may be implemented in the form of a computer program product.
[0281] The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present application is generated in whole or in part. The computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices. The computer instructions may be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions may be transmitted from a website site, a computer, a training device, or a data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) mode to another website site, computer, training device, or data center. The computer-readable storage medium may be any available medium that a computer can store or a data storage device such as a training device, a data center, etc. that includes one or more available media integrations. The available medium may be a magnetic medium, (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state drive (SSD)), etc.
Claims
1. A global transaction coordination method, characterized in that: The method comprises: The first service receives a first service request from a client, where the first service request is used to request to call the first service; The first service calls a first local agent to create a first local transaction, and sends a first remote service request to a second service, so that the second service calls a second local agent to create a second local transaction; The first service calls the first local agent to receive the transaction operation of the second service, and submits the transaction operation to the first local transaction for execution; The first service calls the first local agent to send a global transaction commit request to the cluster transaction manager, so that the cluster transaction manager sends a local transaction commit request to the local agent corresponding to each local transaction when each transaction is successfully executed.
2. The method according to claim 1, characterized in that: Before the first service calls the first local agent to receive the transaction operation of the second service, the method further includes: The first service receives a second remote service request from the second service calling the second local agent, where the second remote service request is used to remotely call the first service, and the second remote service request includes a global transaction identifier.
3. The method according to claim 2, characterized in that The step of submitting the transaction operation to the first local transaction for execution includes: The first service calls the first local agent to create a transaction agent for a first local transaction; The first service submits the transaction operation to the first local transaction execution through the transaction agent.
4. The method according to claim 1, characterized in that: Before the first service calls the first local agent to receive the transaction operation of the second service, the method further includes: The first service calls the first local agent to receive the change registration information of the second resource called by the second service.
5. The method according to any one of claims 1 to 4, characterized in that: The method further comprises: The first service calls the first local agent to query a service node corresponding to the second service; The first service calls the first local agent to start a global transaction, calls the first local agent to generate a first remote service request, the first remote service request carries a global transaction identifier, and the first remote service request is used to remotely call the second service.
6. The method according to any one of claims 1 to 5, characterized in that: The method further comprises: The first service calls the first local agent to register with the cluster transaction manager; When the first local agent is in a normal state, the first service calls the first local agent to send feedback in response to a health check request sent by the cluster transaction manager.
7. The method according to claim 6, characterized in that The method further comprises: When the first local agent recovers from an abnormal state to a normal state, the first service calls the first local agent to re-register with the cluster transaction manager; The first service calls the first local agent to receive a rollback request from the cluster transaction manager to perform a transaction rollback.
8. A global transaction coordination device, characterized in that: The device comprises: A communication module, configured to receive a first service request from a client, wherein the first service request is used to request to call a first service; A creation module, used for calling a first local agent to create a first local transaction; The communication module is further configured to call the first local agent to send a first remote service request to the second service, so that the second service calls the second local agent to create a second local transaction; The communication module is further used to call the first local agent to receive the transaction operation of the second service; A submission module, configured to call the first local agent to submit the transaction operation to the first local transaction execution; The communication module is further configured to call the first local agent to send a global transaction commit request to the cluster transaction manager, so that the cluster transaction manager sends a local transaction commit request to the local agent corresponding to each local transaction when each transaction is successfully executed.
9. The device according to claim 8, characterized in that The communication module is also used for: Before calling the first local agent to receive the transaction operation of the second service, a second remote service request from the second service to call the second local agent is received, the second remote service request is used to remotely call the first service, and the second remote service request includes a global transaction identifier.
10. The device according to claim 9, characterized in that The creation module is also used to: Calling the first local agent to create a transaction agent for a first local transaction; The submission module is specifically used for: The transaction operation is submitted to the first local transaction execution through the transaction agent.
11. The device according to claim 8, characterized in that The communication module is also used for: Before the first service calls the first local agent to receive the transaction operation of the second service, the first local agent is called to receive the change registration information of the second resource caused by the second service calling the second local agent.
12. The device according to any one of claims 8 to 11, characterized in that The device also includes: A query module, configured to call the first local agent to query a service node corresponding to the second service; An opening module, used for calling the first local agent to open a global transaction; A generating module is used to call the first local agent to generate a first remote service request, wherein the first remote service request carries a global transaction identifier, and the first remote service request is used to remotely call the second service.
13. The device according to any one of claims 8 to 12, characterized in that The device also includes: A registration module, used for calling the first local agent to register with the cluster transaction manager; The communication module is configured to, when the first local agent is in a normal state, call the first local agent to send feedback in response to a health check request sent by the cluster transaction manager.
14. The device according to claim 13, characterized in that The device also includes a rollback module; The registration module is further configured to call the first local agent to re-register with the cluster transaction manager when the first local agent recovers from an abnormal state to a normal state; The rollback module is used to receive a rollback request from the cluster transaction manager and perform transaction rollback.
15. A device, characterized in that The device comprises a processor and a memory; The processor is configured to execute instructions stored in the memory, so that the device performs the method according to any one of claims 1 to 7.
16. A computer-readable storage medium, characterized in that: The method comprises instructions, wherein the instructions instruct a device to execute the method according to any one of claims 1 to 7.
