Method for processing affairs, device for processing affairs and electronic equipment

By using combined services in distributed transaction processing, combined with the functions of transaction coordinator and transaction manager, the problem of excessive communication in distributed transaction execution is solved, and more efficient transaction processing and improved transaction throughput is achieved.

CN116319241BActive Publication Date: 2025-05-16中国邮政储蓄银行股份有限公司
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202310267804.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-03-14
Publication Date
2025-05-16
Estimated Expiration
2043-03-14

Smart Images

  • Figure CN116319241B_ABST
    Figure CN116319241B_ABST
Patent Text Reader

Abstract

The present application provides a method for processing transactions, an apparatus for processing transactions, and an electronic device. The composite service has the functions of a transaction coordinator TC and a transaction manager TM, and the composite service includes at least one atomic service; the information of the atomic service is stored in a database, so that the composite service obtains the information of the target atomic service before the target atomic service processes the target transaction, and uses the target atomic service to process the target transaction. The composite service can be used to combine TC and TM, so that there is no need to deploy TC and TM independently, which can shorten the communication time between the composite service and the atomic service, and the information of the target atomic service is stored in the database before the target atomic service processes the target transaction. The composite service can determine the target atomic service and the information of the target atomic service before processing the target transaction, and there is no need for frequent communication between TC and TM, thereby shortening the execution time of the transaction and improving the throughput of the transaction.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of microservice technology, and in particular to a method for processing transactions, a device for processing transactions, and an electronic device. Background Art

[0002] The global transaction manager (TM) and resource manager (RM) of Seata (Simple Extensible Autonomous Transaction Architecture, a distributed transaction framework) are called by applications as SDKs, and the transaction coordinator (TC) is deployed separately as an independent service. TM, RM and TC are not real servers, but services used to implement specific functions. The opening and submission of global transactions are reported to TC by TM, the opening and status changes of branch transactions are reported to TC by RM, and the submission and rollback of branch transactions are notified by TC to RM. The reason why Seata adopts such a design is that TC cannot obtain the information of the node where the branch transaction is located before the execution of the branch transaction, so RM needs to actively report the relevant information of its own node to TC, so that TC can accurately notify RM to make submission and rollback actions when the subsequent two-stage submission or rollback occurs. Therefore, in the current solution, the execution of a distributed transaction involves a large amount of communication between TM, RM and TC, which will increase the execution time of the transaction and reduce the throughput of the transaction. Summary of the invention

[0003] The main purpose of the present application is to provide a method for processing transactions, an apparatus for processing transactions and an electronic device, so as to at least solve the problem in the prior art that the execution of a distributed transaction involves a large number of communications between TMs, RMs and TCs, which increases the execution time of the transaction and reduces the transaction throughput.

[0004] In order to achieve the above-mentioned purpose, according to one aspect of the present application, a method for processing transactions is provided, comprising: obtaining a combined service, wherein the combined service has the functions of a transaction coordinator TC and a transaction manager TM, and the combined service is used for at least one of the following: maintaining a global transaction, maintaining a branch transaction, starting the global transaction, and coordinating the global transaction, and the combined service includes at least one atomic service, and the atomic service refers to the smallest service unit that executes a single service; obtaining request message information, wherein the request message information is information requesting processing of a target transaction; determining at least one target atomic service for processing the target transaction according to the request message information; and when both the combined service and the atomic service have established a communication connection with a database, storing the information of the atomic service in the database, so that the combined service obtains the information of the target atomic service before the target atomic service processes the target transaction, and uses the target atomic service to process the target transaction.

[0005] Optionally, obtaining a composite service includes: obtaining multiple atomic services and determining the role of each of the atomic services; obtaining multiple transactions and determining at least one of the atomic services used to process each of the transactions; in the case where there is only one atomic service used to process the transaction, determining that the atomic service is the composite service; in the case where there are multiple atomic services used to process the transaction, determining the execution order of the multiple atomic services, combining the multiple atomic services according to the execution order, and obtaining the composite service.

[0006] Optionally, storing the information of the atomic service in the database includes: when the composite service includes the start identifier of the global transaction, generating a global transaction identifier, inserting a start record of the global transaction in a first data table of the database, wherein the primary key in the first data table is the global transaction identifier, the state of the global transaction is the start state, the global transaction corresponds to the target transaction, and the global transaction refers to a collection of information of at least one target atomic service; before the target atomic service is executed, inserting a to-be-executed record of the target atomic service in a second data table of the database, wherein the primary key in the second data table is composed of the global transaction identifier and the to-be-executed sequence of the target atomic service, and the state of the target atomic service is the initialization state; after the target atomic service is executed, inserting an execution record of the target atomic service in a third data table of the database, wherein the primary key in the third data table is composed of the global transaction identifier and the execution sequence of the target atomic service, and the state of the target atomic service is the prepared state; using the target atomic service to process the target transaction includes: using the target atomic service to process the target transaction, and updating information of at least one data table among the first data table, the second data table, and the third data table.

[0007] Optionally, the target atomic service is used to process the target transaction, and the information of at least one of the first data table, the second data table and the third data table is updated, including: based on the request message information, the target atomic service is used to execute the local transaction; when multiple target atomic services have executed the local transaction once, the combined service is used to update the status of the global transaction in the first data table to a delegating state; the combined service is used to send a delegation request to the target atomic service, and the target atomic service is used to update the status of the target atomic service in the third data table to a delegated state based on the delegation request; the target atomic service is used to execute the local transaction again, and the combined service is used to update the status of the global transaction in the first data table to a delegated state.

[0008] Optionally, the target atomic service is used to process the target transaction, and the information of at least one of the first data table, the second data table and the third data table is updated, including: when the records in the second data table and the records in the third data table do not correspond, determining that the target atomic service is abnormal; using the combined service to initiate a rollback request to the target atomic service according to the records in the second data table, wherein the rollback request refers to a request to restore the last execution record of the target atomic service and a request to roll back the target transaction; using the target atomic service to determine whether a rollback is required based on the information in the second data table and the third data table, and performing a rollback operation when it is determined that a rollback is required, and at least updating the information in the third data table, wherein the rollback operation refers to an operation to restore the last execution record of the target atomic service and roll back the target transaction.

[0009] Optionally, the target atomic service is used to determine whether a rollback is required based on the information in the second data table and the third data table. When a rollback is required, a rollback operation is performed and at least the information in the third data table is updated, including: determining whether there is a corresponding primary key in the third data table based on the primary key in the second data table; when there is no primary key in the third data table corresponding to the primary key in the second data table, determining that the target transaction is not committed and does not need to be rolled back, inserting an exception record of the target atomic service into the third data table, and the state of the target atomic service in the exception record is a suspended state; when there is a primary key in the third data table corresponding to the primary key in the second data table, determining that the target transaction has been committed and needs to be rolled back; updating the state of the target atomic service in the third data table to a rolled back state, using the atomic service to perform a rollback operation, and updating the state of the global transaction in the first data table to a rolled back state.

[0010] Optionally, after using the target atomic service to process the target transaction, the method further includes: determining whether the information in the first data table, the information in the second data table, and the information in the third data table has been updated; if the information in the first data table, the information in the second data table, and the information in the third data table have not been updated, determining that the target atomic service processes the target transaction abnormally; and using an asynchronous service to re-execute the target transaction until it is determined that the target transaction is normal.

[0011] Optionally, the method further includes: when the number of times the target transaction is re-executed using the asynchronous service is greater than or equal to a number threshold, updating the state of the global transaction in the first data table to a processing exception state, and suspending processing of the target transaction.

[0012] According to another aspect of the present application, a device for processing transactions is provided, comprising: a first acquisition unit, used to acquire a combined service, wherein the combined service has the function of a transaction coordinator TC and the function of a transaction manager TM, and the combined service is used for at least one of the following: maintaining a global transaction, maintaining a branch transaction, opening the global transaction, and coordinating the global transaction, and the combined service includes at least one atomic service, and the atomic service refers to the smallest service unit that executes a single service; a second acquisition unit, used to acquire request message information, wherein the request message information is information requesting processing of a target transaction; a first determination unit, used to determine at least one target atomic service for processing the target transaction according to the request message information; a first processing unit, used to store the information of the atomic service in the database when both the combined service and the atomic service have established a communication connection with the database, so that the combined service acquires the information of the target atomic service before the target atomic service processes the target transaction, and uses the target atomic service to process the target transaction.

[0013] According to another aspect of the present application, an electronic device is provided, comprising: one or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by the one or more processors, and the one or more programs include methods for executing any one of the described methods.

[0014] By applying the technical solution of the present application, a composite service can be used to combine TC and TM, so that there is no need to deploy TC and TM independently. The communication time between the composite service and the atomic service can be shortened, and the information of the target atomic service can be stored in the database before the target atomic service processes the target transaction. The composite service can determine the target atomic service and the information of the target atomic service before processing the target transaction. There is no need for frequent communication between TC and TM, which can shorten the execution time of the transaction and improve the transaction throughput. BRIEF DESCRIPTION OF THE DRAWINGS

[0015] The drawings constituting part of the present application are used to provide a further understanding of the present application. The exemplary embodiments and descriptions of the present application are used to explain the present application and do not constitute an improper limitation on the present application. In the drawings:

[0016] Figure 1 A schematic diagram showing a distributed transaction commit process in some scenarios;

[0017] Figure 2 A schematic diagram showing a distributed transaction rollback process in some scenarios;

[0018] Figure 3A hardware structure block diagram of a mobile terminal for executing a transaction processing method provided in an embodiment of the present application is shown;

[0019] Figure 4 A schematic diagram of a process flow of a method for processing transactions provided according to an embodiment of the present application is shown;

[0020] Figure 5 A schematic diagram of service orchestration is shown;

[0021] Figure 6 A schematic diagram of the architecture of a distributed transaction function based on service orchestration is shown;

[0022] Figure 7 A schematic diagram showing the processing of a successful distributed transaction submission;

[0023] Figure 8 A schematic diagram showing the process of successfully rolling back a distributed transaction;

[0024] Fig. 9 A schematic diagram of an architecture for re-executing a target transaction using an asynchronous service is shown;

[0025] Fig.10 A schematic diagram showing the state of a global transaction;

[0026] Fig.11 A structural block diagram of a device for processing transactions provided according to an embodiment of the present application is shown.

[0027] The above drawings include the following reference numerals:

[0028] 102, processor; 104, memory; 106, transmission device; 108, input and output devices. DETAILED DESCRIPTION

[0029] It should be noted that, in the absence of conflict, the embodiments and features in the embodiments of the present application can be combined with each other. The present application will be described in detail below with reference to the accompanying drawings and in combination with the embodiments.

[0030] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of the present application.

[0031] It should be noted that the terms "first", "second", etc. in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequential order. It should be understood that the data used in this way can be interchanged where appropriate, so that the embodiments of the present application described here. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device comprising a series of steps or units is not necessarily limited to those steps or units clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.

[0032] For the convenience of description, some nouns or terms involved in the embodiments of the present application are explained below:

[0033] TCC: It is one of the solutions in the field of distributed transactions. The TCC mode is a two-phase commit model. The global transaction consists of several sub-transactions. The sub-transactions meet the two-phase commit requirements. Each sub-transaction needs to implement three methods: the try method realizes resource detection and reservation, the commit method executes the submission of business operations, and the commit method must succeed if the try method succeeds; the cancel method releases the reserved resources.

[0034] Local transaction: A database transaction bound to a database connection. Cross-database transactions are not allowed, and the atomicity of the transaction is guaranteed by the database.

[0035] Microservice Architecture: Microservice Architecture is an architectural concept that is characterized by creating applications around business domain components that can be independently developed, managed, and iterated. Using cloud architecture and platform-based deployment, management, and service capabilities in decentralized components makes product delivery simpler.

[0036] Transaction Coordinator TC: maintains the status of global and branch transactions, communicates with TM and RM, drives the commit and rollback of global transactions, that is, the server side of seata.

[0037] Transaction Manager TM: Communicates with TC to start, commit, or roll back global transactions.

[0038] Resource Manager RM: manages branch transaction processing, interacts with TC to register branch transactions and report the status of branch transactions, and drives branch transactions to commit or rollback, that is, the server that executes atomic services.

[0039] Anti-duplicate: refers to repeatedly calling the second phase interface of the same branch transaction of the same distributed transaction. Therefore, the second phase Confirm and Cancel interfaces of TCC are required to ensure idempotence and not reuse or release resources. If idempotence control is not done well, it is likely to cause serious problems such as asset loss.

[0040] Anti-hanging: Try times out due to network congestion, the transaction manager generates a rollback, triggers the Cancel interface, and finally receives a Try interface call, but Cancel arrives before Try. According to the logic of allowing empty rollbacks, the rollback will return success, and the transaction manager believes that the transaction has been rolled back successfully. At this time, the Try interface should not be executed, otherwise data inconsistency will occur.

[0041] Empty rollback: refers to a distributed transaction in which the second-stage Cancel method is called without calling the TCC resource Try method. The Cancel method needs to recognize that this is an empty rollback and return success directly.

[0042] Seata is an open source distributed transaction framework that supports two distributed transaction models, SAGA and TCC. It is currently the most widely used open source distributed transaction implementation solution in the industry. Seata consists of three parts: TM, RM and TC.

[0043] In the microservice architecture, background processing services are split and independently deployed according to business areas. Data is often split into multiple databases horizontally or vertically according to business areas. A transaction is often processed through multiple remote service calls, involving update operations on multiple databases. Traditional XA global database transactions are committed in two phases. Although they can achieve strong data consistency, they have to lock resources during the entire transaction and have poor performance. They cannot be used in most scenarios with high performance requirements. Therefore, the industry has proposed flexible distributed transaction solutions for such scenarios. It does not require that data is always in a strongly consistent state, but only that the eventual consistency of transactions is guaranteed. TCC is one of the flexible solutions.

[0044] TM communicates with TC and is responsible for starting global transactions, committing or rolling back global transactions. RM is responsible for managing branch transactions, interacting with TC to register branch transactions and report the status of branch transactions, and driving branch transactions to commit or roll back. TC maintains the status of global and branch transactions, communicates with TM and RM, and drives the commit and rollback of global transactions.

[0045] In some scenarios, the commit process of a distributed transaction is as follows: Figure 1 As shown, the following steps are included:

[0046] 1. The application calls the TM API to start a global transaction and report the global transaction start event to the TC. The TC generates a unique global transaction ID, registers the global transaction record persistently into the database, and the global transaction status is Begin (started status). The global transaction ID is returned to the TM.

[0047] 2. Before RM executes branch transaction 1, it reports the branch transaction 1 start event to TC in advance;

[0048] 3. RM executes the Prepare operation of branch transaction 1 successfully and reports it to TC. TC persists the execution record of branch transaction 1 into the database. The initial status is Prepared.

[0049] 4. Before RM executes branch transaction 2, it reports the branch transaction start event to TC in advance;

[0050] 5. RM executes the Prepare operation of branch transaction 2 successfully and reports it to TC. TC persists the execution record of branch transaction 2 into the database, and the initial status is Prepared.

[0051] 6. The application calls the TM API to submit the global transaction, and the TM reports it to the TC;

[0052] 7. TC sends the commit event of branch transaction 1 to RM. RM executes the Commit operation of the application successfully. TC updates the status of branch transaction 1 to Committed.

[0053] 8. TC sends the commit event of branch transaction 2 to RM. RM executes the Commit operation of the application successfully, and TC updates the status of branch transaction 2 to Committed.

[0054] 9. TC updates the global transaction status to Committed.

[0055] In some scenarios, the rollback process of distributed transactions is as follows Figure 2 As shown, the following steps are included:

[0056] 1. The application calls the TM API to start a global transaction and report the global transaction start event to the TC. The TC generates a unique global transaction ID, registers the global transaction record persistently into the database, sets the global transaction status to Begin, and returns the global transaction ID to the TM.

[0057] 2. Before RM executes branch transaction 1, it reports the branch transaction 1 start event to TC in advance;

[0058] 3. RM executes the Prepare operation of branch transaction 1 successfully and reports it to TC. TC persists the execution record of branch transaction 1 into the database, and the initial status is Prepared.

[0059] 4. Before RM executes branch transaction 2, it reports the branch transaction start event to TC in advance;

[0060] 5. RM executes the Prepare operation of branch transaction 2 successfully and reports it to TC. TC persists the execution record of branch transaction 2 into the database, and the initial status is Prepared.

[0061] 6. Due to other abnormal reasons, the application calls the TM API to roll back the global transaction, and the TM reports it to the TC;

[0062] 7. TC sends a branch transaction 2 rollback request to RM. RM executes the Cancel operation on the application side successfully. TC updates the status of branch transaction 2 to Rollbacked.

[0063] 8. TC sends a branch transaction 1 rollback request to RM. RM executes the Cancel operation on the application side successfully. TC updates the status of branch transaction 1 to Rollbacked.

[0064] 9. TC updates the global transaction status to Rollbacked.

[0065] In the current solution, the execution of a distributed transaction involves a large amount of communication between TMs, RMs, and TCs, and remote communication involves network communication overhead (it should be noted that the remote here does not refer to physical remote communication, but communication between services. It is possible that the services will be deployed on one server or on different servers), which increases the transaction execution time and reduces the transaction throughput.

[0066] As introduced in the background technology, the execution of a distributed transaction in the prior art involves a large amount of communication between TMs, RMs and TCs, which increases the execution time of the transaction and reduces the transaction throughput. To solve the above problems, the embodiments of the present application provide a method for processing transactions, an apparatus for processing transactions and an electronic device.

[0067] The technical solutions in the embodiments of the present invention will be described clearly and completely below in conjunction with the accompanying drawings in the embodiments of the present invention.

[0068] The method embodiments provided in the embodiments of the present application can be executed in a mobile terminal, a computer terminal or a similar computing device. Taking running on a mobile terminal as an example, Figure 3 FIG. 1 is a hardware structure diagram of a mobile terminal of a method for processing transactions according to an embodiment of the present invention. Figure 3 As shown, the mobile terminal may include one or more ( Figure 3 Only one is shown in the figure) a processor 102 (the processor 102 may include but is not limited to a processing device such as a microprocessor MCU or a programmable logic device FPGA) and a memory 104 for storing data, wherein the mobile terminal may also include a transmission device 106 and an input / output device 108 for communication functions. It can be understood by those skilled in the art that Figure 3 The structure shown is only for illustration and does not limit the structure of the mobile terminal. Figure 3 More or fewer components as shown, or with Figure 3 Different configurations are shown.

[0069] The memory 104 can be used to store computer programs, for example, software programs and modules of application software, such as the computer program corresponding to the display method of device information in the embodiment of the present invention. The processor 102 executes various functional applications and data processing by running the computer program stored in the memory 104, that is, the above method is implemented. The memory 104 may include a high-speed random access memory, and may also include a non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include a memory remotely arranged relative to the processor 102, and these remote memories can be connected to the mobile terminal via a network. Examples of the above-mentioned network include but are not limited to the Internet, an intranet, a local area network, a mobile communication network, and a combination thereof. The transmission device 106 is used to receive or send data via a network. The above-mentioned specific examples of the network may include a wireless network provided by a communication provider of the mobile terminal. In one example, the transmission device 106 includes a network adapter (Network Interface Controller, referred to as NIC), which can be connected to other network devices through a base station so as to communicate with the Internet. In one example, the transmission device 106 may be a radio frequency (RF) module, which is used to communicate with the Internet wirelessly.

[0070] In this embodiment, a method for processing transactions running on a mobile terminal, a computer terminal or a similar computing device is provided. It should be noted that the steps shown in the flowchart of the accompanying drawings can be executed in a computer system such as a set of computer executable instructions, and although a logical order is shown in the flowchart, in some cases, the steps shown or described can be executed in an order different from that shown here.

[0071] Figure 4 FIG. 1 is a flow chart of a method for processing transactions according to an embodiment of the present application. Figure 4 As shown, the method comprises the following steps:

[0072] Step S201, obtaining a composite service, wherein the composite service has the functions of a transaction coordinator TC and a transaction manager TM, and the composite service is used for at least one of the following: maintaining a global transaction, maintaining a branch transaction, starting the global transaction, and coordinating the global transaction, and the composite service includes at least one atomic service, which refers to the smallest service unit that executes a single service;

[0073] Specifically, TC and TM can be combined to obtain a composite service, which has the functions of TC and TM. This only involves communication between the composite service and RM, and does not require communication among TC, TM and RM, thereby shortening the time for processing transactions.

[0074] Step S202, obtaining request message information, wherein the request message information is information requesting to process a target transaction;

[0075] Specifically, the request message may be sent by a terminal, or may be sent by other servers, or may be sent by other systems. There are many kinds of transactions, and the request message information sent includes the target transaction that the sender needs to process.

[0076] Step S203, determining at least one target atomic service for processing the target transaction according to the request message information;

[0077] Specifically, different atomic services are used to process different transactions, so the target atomic service used to process the target transaction can be determined, and then the target atomic service can be used to process the target transaction.

[0078] Step S204, when the above-mentioned composite service and the above-mentioned atomic service have established communication connections with the database, the information of the above-mentioned atomic service is stored in the above-mentioned database, so that the above-mentioned composite service obtains the information of the above-mentioned target atomic service before the above-mentioned target atomic service processes the above-mentioned target transaction, and uses the above-mentioned target atomic service to process the above-mentioned target transaction.

[0079] Specifically, the information of the atomic service includes at least one of the following: server IP, service port, and request message.

[0080] Specifically, before the target atomic service processes the target transaction, the database is used to store the relevant information of the target atomic service. In this way, the composite service can obtain information from the database before the target atomic service processes the target transaction, and can determine the information of the target atomic service used to process the target transaction. There is no need for RM to return the execution record to TC after processing the target transaction, which further shortens the execution time of the transaction.

[0081] Through this embodiment, the composite service can be used to combine TC and TM, so there is no need to deploy TC and TM independently, the communication time between the composite service and the atomic service can be shortened, and the information of the target atomic service can be stored in the database before the target atomic service processes the target transaction. The composite service can determine the target atomic service and the information of the target atomic service before processing the target transaction, and there is no need for frequent communication between TC and TM, thereby shortening the execution time of the transaction and improving the transaction throughput.

[0082] The composite service is obtained based on the atomic service. The atomic services can be orchestrated in a service orchestration manner to obtain the composite service. In the specific implementation process, the composite service can be obtained through the following steps: obtain multiple atomic services and determine the role of each of the above atomic services respectively; obtain multiple transactions and determine at least one of the above atomic services used to process each of the above transactions; when there is only one of the above atomic services used to process the above transactions, determine the above atomic service as the above composite service; when there are multiple above atomic services used to process the above transactions, determine the execution order of the multiple above atomic services, and combine the multiple above atomic services according to the above execution order to obtain the above composite service.

[0083] In this solution, the roles of different atomic services can be determined first. For example, some atomic services are used to deduct money, some atomic services are used to lock user accounts, and some atomic services are used to query accounts. In this way, the role (or function) of the atomic service is determined first, and then at least one atomic service used to process different transactions is determined. In this way, the specific atomic services required to process the transaction can be determined, and then the transaction and the atomic service are bound to obtain a combined service. In this way, the combined service and the atomic service can be used to process the transaction more efficiently. At the same time, since the processing of the transaction only involves the atomic service and the combined service, the time for processing the transaction can be further shortened.

[0084] Specifically, the atomic services can be arranged in a graphical service arrangement to form a composite service. The service arrangement file can be an XML file, which can be developed by dragging and dropping the integrated drive electronics (IDE) (in the arrangement file, the atomic service only needs to specify the service name, configure the input and output mapping converter, and formulate the service type that needs to be converted). Of course, it can support calling atomic services in sequence, branch, loop, parallel, etc. The composite service can parse the service arrangement file with the help of the service arrangement engine, and determine the execution order of the atomic services to be executed in sequence according to the branch conditions.

[0085] like Figure 5 As shown, for example, there are 4 atomic services, namely atomic service A, atomic service B, atomic service C, and atomic service D. The role of atomic service A is function A, the role of atomic service B is function B, the role of atomic service C is function C, and the role of atomic service D is function D. The atomic services used in processing transaction A are atomic service A, atomic service B, and atomic service D. The atomic services used in processing transaction B are atomic service A, atomic service C, and atomic service D. Therefore, atomic service A, atomic service B, and atomic service D are bound to transaction A, and atomic service A, atomic service C, and atomic service D are bound to transaction B. If the target transaction received later is transaction A, it can be directly determined that the required atomic services are atomic service A, atomic service B, and atomic service D.

[0086] In this solution, the composite service combines TC and TM into one. The composite service engine acts as a transaction manager and transaction coordinator. The composite service can provide the functions of opening and coordinating global transactions. According to the execution order recorded during service orchestration, the global transaction is opened, and branch transactions are prepared, committed, and rolled back in sequence. The atomic service engine acts as a resource manager, providing branch transaction opening, committing, rolling back, anti-duplicate, and anti-hanging functions.

[0087] Specifically, Figure 6 As shown, this solution includes a composite service, multiple atomic services, and multiple databases. An atomic service communicates with one database respectively, and the composite service also communicates with one database. The composite service records the status of global transactions and the execution records of branch transactions in the database. The composite service orchestrates and calls multiple atomic services. The atomic service executes branch transactions and records the status of branch transactions in the database communicating with it.

[0088] In order to ensure that the subsequent composite service can obtain the status of the global transaction, obtain the information of the target atom before the target atom is executed, obtain the information of the target atom after the target atom is executed, and update the information of the target atom in real time after the target atom processes the transaction, the present application stores the information of the above-mentioned atomic service in the above-mentioned database, which can be achieved through the following steps: in the case where the above-mentioned composite service includes the opening mark of the above-mentioned global transaction, generate a global transaction mark, insert the opening record of the above-mentioned global transaction into the first data table of the above-mentioned database, wherein the primary key in the above-mentioned first data table is the above-mentioned global transaction mark, the status of the above-mentioned global transaction is the opening state, the above-mentioned global transaction corresponds to the above-mentioned target transaction, and the above-mentioned global transaction refers to the collection of information of at least one of the above-mentioned target atomic services; before the above-mentioned target atomic service is executed, Inserting a pending execution record of the target atomic service into the second data table of the database, wherein the primary key in the second data table is composed of the global transaction identifier and the pending execution order of the target atomic service, and the state of the target atomic service is an initialization state; after the target atomic service is executed, inserting an execution record of the target atomic service into the third data table of the database, wherein the primary key in the third data table is composed of the global transaction identifier and the execution order of the target atomic service, and the state of the target atomic service is a prepared state; using the target atomic service to process the target transaction can be achieved through the following steps: using the target atomic service to process the target transaction, and updating information of at least one of the first data table, the second data table and the third data table.

[0089] In this solution, the first data table can be used to store information about global transactions, the second data table can be used to store information about the target atomic service and records to be executed before the target atomic service processes the target transaction, and the third data table can be used to store information about the target atomic service and records that have been executed after the target atomic service processes the target transaction. In this way, the composite service can obtain information from the second data table before the target atomic service processes the target transaction, and can determine the information of the target atomic service used to process the target transaction. There is no need for RM to return the executed records to TC after processing the target transaction, which further shortens the execution time of the transaction. In addition, the third data table can be used to verify the execution order of the target atomic service to process the target transaction, thereby ensuring the accuracy of the processing process. At the same time, the information of at least one data table can be updated to ensure the real-time performance of the information in the data table.

[0090] Specifically, during the execution of the composite service, if a global transaction start mark is found in the service orchestration, a global transaction ID can be generated, and a global transaction start record can be inserted into the first data table (database global transaction registration table, table name TxnLog). The primary key is the global transaction ID, and the initial global transaction state is Begin.

[0091] When a target atomic service node is encountered during the execution of the composite service, before the target atomic service is executed, a pending record of the target atomic service is inserted into the second data table (database transaction execution record table, represented as RunLog), with the global transaction ID and the service orchestration execution sequence number (the execution order of the target atomic service) as the joint primary key, and the initial state is INIT (initialization state). At the same time, the necessary information required for addressing the target atomic service is inserted into RunLog.

[0092] The target atomic service is registered with the service registration center when it is started. If the target atomic service is not deployed in units, you only need to know the target atomic service name to obtain the target service address from the service registration center. If the target atomic service is deployed in sub-libraries and units, such as sub-libraries according to customer dimensions, and each unit deploys 4 databases, you can access the global routing service based on the customer information in the request message, obtain the target database, and then find the target unit based on the database and unit mapping configuration, so as to find the addressing related information of the target service and register it in the database, so as to prepare for the subsequent composite service to initiate branch transaction submission or rollback. That is, in the scenario of sub-library and unit deployment, deploy a separate global routing service to find and return service addressing information such as customer ID and unit ID based on the key business information in the transaction request message. In the scenario where sub-library and unit deployment is not required, rely on the service registration center to achieve service addressing.

[0093] This solution integrates TC and TM. There is no need to deploy TC independently. Reliable distributed transactions can be achieved by using service orchestration, global routing services, and service addressing capabilities of the service registration center. TC no longer needs to communicate frequently with RM remotely, which improves the efficiency and reliability of distributed transactions.

[0094] The target atomic service starts a local transaction in the pre-processing step. After the target atomic service successfully executes the Prepare business operation, it inserts a record in the third data table (branch transaction status table, named BranchLog) with the local transaction. The primary key of the BranchLog table is the same as the primary key of the RunLog table, which is also the global transaction ID and the service orchestration execution sequence number. The initial status is Prepared. After the record is successfully inserted, the local transaction is committed.

[0095] The RunLog table uses the global transaction ID and the service orchestration execution sequence number as the joint primary key, and records information such as the atomic service name, unit ID, and atomic service request message, so that there is a trace to follow for the subsequent two-stage commit and rollback. The composite service registers the RunLog record in advance before the execution of the atomic service first-stage Try action. The initial status is INIT. After the second-stage synchronous commit is successful or the rollback is successful, the status of the transaction in the table is not updated. The status of the transaction in the table is only updated to Committed after the asynchronous commit is successful, and is updated to Rollbacked after the asynchronous rollback is successful. The status of the transaction in the table is not updated if the asynchronous operation fails.

[0096] The primary key of the BranchLog table is the global transaction ID and the service orchestration execution sequence number. After the Prepare operation of the branch transaction is successful, in the atomic service post-processing, a record with the Prepare status is inserted with the Prepare business operation and the local transaction. If the primary key conflicts during the insertion, the local transaction fails to commit and can only be rolled back, which can prevent the Prepare from being executed repeatedly. After receiving the Commit request from the composite service, the atomic service pre-processing checks the table with the same primary key record. If no record is found, it means that the first-stage Prepare operation has not been executed yet, and the second-stage Commit cannot be performed; if a Committed record is found, it means that the branch transaction has been committed and does not need to be committed again; if a Suspended or Rollbacked record is found, it means that the branch transaction has been rolled back or the rollback arrives before the first-stage Prepare, and it cannot be committed; only when a record in the Prepared status is found, is it allowed to commit. Similarly, if the atomic service receives a rollback request from the composite service, it will also check this table to confirm the status of the branch transaction. Only records in the Prepared state can specify the rollback business action. After the rollback is successful, the state is updated to Rollbacked. If no record is found, it means that the rollback arrives before the Prepare action. A record in the Suspended state is inserted into the table to indicate that the branch transaction is suspended and does not need to be rolled back. If a record in the Rollbacked state is found, it means that the branch transaction has been rolled back and does not need to be rolled back again. If a record in the Committed state is found, it means that the branch transaction has been committed and rollback is not allowed. By using this table, you can prevent repeated, empty rollbacks, and suspensions.

[0097] The process of processing the target transaction of the target atomic service can be processed by the target atomic service submitting a local transaction, and after each target transaction is processed, the information of at least one data table can also be updated. In some embodiments, the target atomic service is used to process the target transaction, and the information of at least one of the first data table, the second data table and the third data table is updated. Specifically, it can be achieved by the following steps: based on the request message information, the target atomic service is used to execute the local transaction; when multiple target atomic services have executed the local transaction once, the combined service is used to update the status of the global transaction in the first data table to the delegating state; the combined service is used to send a delegation request to the target atomic service, and the target atomic service is used to update the status of the target atomic service in the third data table to the delegated state based on the delegation request; the target atomic service is used to execute the local transaction again, and the combined service is used to update the status of the global transaction in the first data table to the delegated state.

[0098] In this solution, the target atomic service can process the target transaction by executing (committing) the local transaction twice. For example, if the user account balance needs to be updated, the first execution of the local transaction is to lock the user account first, and the second execution of the local transaction is to update the account balance, that is, the local transaction is executed step by step. Of course, it can also be executed synchronously once and the target atomic service is used directly to process the target transaction. In this way, there is no need for back-and-forth communication between RM and TC, which further shortens the execution time of the transaction. At the same time, the information of at least one data table can be updated to further ensure the real-time performance of the information in the data table.

[0099] Specifically, after all target atomic services are executed successfully, the composite service updates the status of the global transaction in the first data table to Committing (delegating status), the composite service generates a Commit request, and sends it to the target atomic service, the target atomic service checks the third data table, updates the status of the branch transaction, and updates the status of the target atomic service from Prepared to Committed. After the commit business operation of the target atomic service is successful, the local transaction is submitted again, and the composite service updates the status of the global transaction in the first data table to Committed.

[0100] Specifically, the process of successful submission of distributed transactions is as follows: Figure 7 As shown, the circular steps are performed by composite services, and the diamond steps are performed by atomic services, including the following steps:

[0101] 1. During the execution of the composite service, if a global transaction start mark is found in the service arrangement, a global transaction ID can be generated, and a global transaction start record can be inserted into the first data table (database global transaction registration table, table name TxnLog) (pre-processing step of the composite service);

[0102] 2. When the node of the target atomic service is encountered during the execution of the composite service, before the target atomic service is executed, a record of the target atomic service to be executed is inserted into the second data table (database transaction execution record table, table name RunLog) (this step corresponds to the target atomic service 1);

[0103] 3. The target atomic service starts a local transaction in the pre-processing step. After the target atomic service successfully executes the Prepare business operation, it inserts a record into the third data table (branch transaction status table, table name BranchLog) with the local transaction. After the record is successfully inserted, the local transaction is committed (post-processing step of target atomic service 1);

[0104] 4. Same as step 2, corresponding to target atomic service 2;

[0105] 5. Same as step 3, corresponding to target atomic service 2;

[0106] 6. After all target atomic services are successfully executed, the composite service updates the status of the global transaction in the first data table to Committing (post-processing step of the composite service);

[0107] 7. The composite service generates a Commit request and sends it to the target atomic service. The target atomic service checks the third data table, updates the status of the branch transaction, and updates the status of the target atomic service from Prepared to Committed (pre-processing step of target atomic service 1).

[0108] 8. After the commit business operation of the target atomic service is successful, the local transaction is submitted again (pre-processing step of target atomic service 2);

[0109] 9. Same as step 7, corresponding to target atomic service 2;

[0110] 10. Same as step 8, corresponding to target atomic service 2;

[0111] 11. The combined service updates the status of the global transaction in the first data table to Committed (a post-processing step of the combined service).

[0112] For the process of the target atomic service processing the target transaction, if the target atomic service processes the exception, it can be remedied and a rollback operation can be performed on the target transaction. In the specific implementation process, the target atomic service is used to process the target transaction and update the information of at least one of the first data table, the second data table and the third data table. This can be achieved through the following steps: when the records in the second data table and the records in the third data table do not correspond, determine that the target atomic service is abnormal; use the combined service to initiate a rollback request to the target atomic service according to the records in the second data table, wherein the rollback request refers to a request to restore the last execution record of the target atomic service and roll back the target transaction; use the target atomic service to determine whether a rollback is required based on the information in the second data table and the third data table, and when it is determined that a rollback is required, perform a rollback operation and at least update the information in the third data table, wherein the rollback operation refers to an operation to restore the last execution record of the target atomic service and roll back the target transaction.

[0113] In this solution, if the target atomic service is abnormal, it can be determined whether a rollback operation is required based on the information in the second data table and the third data table. Only when it is determined that a rollback operation is required will the rollback operation be performed. The target atomic service is used directly to perform the rollback operation. This eliminates the need for back-and-forth communication between RM and TC, further shortening the transaction execution time. At the same time, the information of at least one data table can be updated to further ensure that the information in the data table is more real-time.

[0114] The condition for determining whether a rollback is required can be determined based on the information in the second data table and the information in the third data table. In some embodiments, the target atomic service is used to determine whether a rollback is required based on the information in the second data table and the third data table. When a rollback is required, a rollback operation is performed and at least the information in the third data table is updated. This can be achieved by the following steps: based on the primary key in the second data table, determine whether there is a corresponding primary key in the third data table; if there is no primary key in the third data table corresponding to the primary key in the second data table, determine that the target transaction is not committed and does not need to be rolled back, insert an exception record of the target atomic service in the third data table, and the state of the target atomic service in the exception record is a suspended state; if there is a primary key in the third data table corresponding to the primary key in the second data table, determine that the target transaction has been committed and needs to be rolled back; update the state of the target atomic service in the third data table to a rolled back state, use the atomic service to perform a rollback operation, and update the state of the global transaction in the first data table to a rolled back state.

[0115] In this solution, since the information in the second data table already exists before the target atomic service is executed, the information in the third data table is directly compared with the information in the second data table. The information in the second data table is used as reference information. It can be determined whether the information in the third data table does not correspond to the information in the second data table, and then it can be more accurately determined whether the target atomic service has submitted the transaction. It can then be determined based on the comparison result whether a rollback operation is required. If a rollback operation is required, the target atomic service is used to perform the rollback operation, and the target atomic service can resubmit the transaction. This ensures that the solution can process the target transaction more efficiently and accurately, and avoid processing exceptions.

[0116] Specifically, when an exception occurs in the Prepare operation of the target atomic service (the judgment condition can be set according to the actual situation, for example, an account needs to be locked but is not locked successfully), the local transaction is rolled back, and it is found that there is no record in the third data table. The combined service initiates a rollback operation on PBS (a batch job and computer system resource management software package) in reverse order according to the records in the second data table (i.e., initiates a rollback on the target atomic service). The target atomic service checks the third data table and does not find the corresponding record according to the primary key, indicating that the branch transaction has not been committed and does not need to be rolled back. A record is inserted in the third data table, and the state of the target atomic service is changed to Suspended. If the target atomic service checks the third data table and finds the corresponding record according to the primary key, it means that the branch transaction has been committed and needs to be rolled back. The state of the target atomic service is updated to Rollbacked, and the business rollback operation is performed with the transaction. After the rollback is successful, the local transaction is committed, and the combined service updates the state of the global transaction in the first data table to Rollbacked.

[0117] Specifically, the process of successful submission of distributed transactions is as follows: Figure 8 As shown, the circular steps are performed by composite services, and the diamond steps are performed by atomic services, including the following steps:

[0118] 1. During the execution of the composite service, if a global transaction start mark is found in the service arrangement, a global transaction ID can be generated, and a global transaction start record can be inserted into the first data table (database global transaction registration table, table name TxnLog) (pre-processing step of the composite service);

[0119] 2. When the node of the target atomic service is encountered during the execution of the composite service, before the target atomic service is executed, a record of the target atomic service to be executed is inserted into the second data table (database transaction execution record table, table name RunLog) (this step corresponds to the target atomic service 1);

[0120] 3. The target atomic service starts a local transaction in the pre-processing step. After the target atomic service successfully executes the Prepare business operation, it inserts a record into the third data table (branch transaction status table, table name BranchLog) with the local transaction. After the record is successfully inserted, the local transaction is committed (post-processing step of target atomic service 1);

[0121] 4. Same as step 2, corresponding to target atomic service 2, but the Prepare operation of the target atomic service has an exception, the local transaction is rolled back, and there is no record in the third data table;

[0122] 5. The composite service initiates a rollback operation on the PBS in reverse order according to the RunLog record (the exception handling step of the composite service);

[0123] 6. Target atomic service 2 receives the rollback request from the composite service. It checks BranchLog in the pre-processing process and finds no record based on the primary key, indicating that the first-stage operation of this branch transaction has not been committed and does not need to be rolled back. The same transaction inserts a record into BranchLog with the status Suspended (pre-processing step of target atomic service 2).

[0124] 7. Target atomic service 1 receives the rollback request from the composite service. In the pre-processing, it checks the branch transaction status table BranchLog and finds a record in the Prepared state according to the primary key, indicating that the first phase of the branch transaction has been committed and needs to be rolled back. It updates the BranchLog record to Rollbacked and executes the business rollback operation with the transaction (pre-processing step of target atomic service 1).

[0125] 8. Commit the local transaction after the rollback is successful (post-processing step of target atomic service 1);

[0126] 9. The composite service updates the status of the global transaction in the first data table to Rollbacked (an exception handling step of the composite service).

[0127] The composite service can perform a two-stage synchronous commit or rollback operation on the target atomic service, but in some scenarios, the synchronous commit or rollback may fail. For example, in some cases, the server is powered off or crashes, and the two-stage synchronization attempt has no chance to execute. At this time, an asynchronous service can be deployed to perform asynchronous processing. After using the above-mentioned target atomic service to process the above-mentioned target transaction, the above-mentioned method also includes the following steps: determining whether the information in the above-mentioned first data table, the information in the above-mentioned second data table, and the information in the above-mentioned third data table have been updated; when the information in the above-mentioned first data table, the information in the above-mentioned second data table, and the information in the above-mentioned third data table have not been updated, determining that the above-mentioned target atom processes the above-mentioned target transaction abnormally; using the asynchronous service to re-execute the above-mentioned target transaction until it is determined that the above-mentioned target transaction is normal.

[0128] In this solution, in order to avoid multiple submission and rollback failures that lead to the target transaction being unable to be processed normally, an asynchronous service can be deployed to re-execute the target transaction through the asynchronous service, thereby ensuring that the target transaction can be executed normally.

[0129] In order to avoid abnormal situations caused by excessive execution of asynchronous services, the above method also includes the following steps: when the number of times the above target transaction is re-executed using the above asynchronous service is greater than or equal to the number threshold, the status of the above global transaction in the above first data table is updated to a processing abnormal state, and the processing of the above target transaction is suspended.

[0130] In this solution, if the asynchronous service executes the target transaction multiple times and exceptions occur, the asynchronous service will reprocess the target transaction. If the execution is too many times, it will cause the entire machine or the entire system to be abnormal. Therefore, the number of times the asynchronous service executes the target transaction can be limited. Once the number threshold is exceeded, the target transaction can be stopped, avoiding waste of resources.

[0131] Specifically, the specific description of re-executing the target transaction using asynchronous services is as follows: Fig. 9As shown, for the failure of synchronous submission or rollback of transactions due to power outages, technical anomalies, etc., the Timer (asynchronous service) asynchronously initiates submission and rollback retries; the Timer service has multiple instances with high availability deployment, and the instances are stateless. Multiple instances grab locks to process tasks. Any Timer service instance downtime can be continued by other healthy instances (other asynchronous services); the Timer extracts the transactions with the status of Begin in the first data table and the execution time has timed out and inserts them into the transaction register for asynchronous rollback, extracts the transactions with the status of Committing in the first data table and the execution time has timed out and inserts them into the transaction register for asynchronous submission, and both asynchronous submission and rollback operations support retry. Whenever a branch transaction is asynchronously submitted successfully, the corresponding RunLog record is updated to Committed. If all branch transactions are submitted successfully, the global transaction status in TxnLog is updated to Committed. Similarly, whenever a branch transaction is rolled back successfully, the corresponding RunLog record is updated to Rollbacked. If all branch transactions are rolled back successfully, the global transaction status in TxnLog is updated to Rollbacked. Asynchronous processing has an upper limit on the number of retries. When the retry threshold is reached and the commit is not successful, the global transaction status in TxnLog is updated to CommitFailed (commit abnormal status); similarly, when the rollback is not successful after the retry threshold is reached, the global transaction status in TxnLog is updated to RollbackFailed (rollback abnormal status); manual intervention is required for records in the CommitFailed and RollbackFailed states.

[0132] More specifically, the state of the global transaction in this solution is as follows Fig.10 As shown, a transaction with a status of Begin is extracted from the first data table. If Prepare fails and times out, but the synchronous Rollback succeeds, the status of the transaction is changed to Rollbacked. If Prepare fails and times out, and the synchronous Rollback fails, the Timer service extracts the transaction with a status of Rollbacking from the first data table. The Timer service repeatedly executes Rollback. If the number of synchronous Rollback successes is less than or equal to 6 times, the status of the transaction is changed to Rollbacked. If the number of synchronous Rollback failures is greater than or equal to 6 times, it is determined that the Timer service synchronous Rollback fails, and the global transaction status in TxnLog is updated to RollbackFailed.

[0133] If Prepare succeeds, from the transactions in the first data table whose transaction status is Committing, if the synchronous commit succeeds, the transaction status is changed to Committed. If the synchronous commit fails, the Timer service repeats the commit from the transactions in the first data table whose transaction status is Committing. If the number of synchronous commit successes is less than or equal to 6 times, the transaction status is changed to Committed. If the number of synchronous commit failures is greater than or equal to 6 times, it is determined that the Timer service synchronous commit has failed, and the global transaction status in TxnLog is updated to CommitFailed.

[0134] The present application embodiment also provides a kind of device for processing affairs, it should be noted that the device for processing affairs of the embodiment of the present application can be used to execute the method for processing affairs provided by the embodiment of the present application. The device is used to implement the above-mentioned embodiment and preferred implementation mode, and the description has been made and will not be repeated. As used below, the term "module" can implement a combination of software and / or hardware of a predetermined function. Although the device described in the following embodiments is preferably implemented in software, the implementation of hardware, or a combination of software and hardware is also possible and conceived.

[0135] The following is an introduction to the device for processing transactions provided in an embodiment of the present application.

[0136] Fig.11 is a structural block diagram of a device for processing transactions according to an embodiment of the present application. Fig.11 As shown, the device comprises:

[0137] A first acquisition unit 10 is used to acquire a composite service, wherein the composite service has the functions of a transaction coordinator TC and a transaction manager TM, and the composite service is used for at least one of the following: maintaining a global transaction, maintaining a branch transaction, starting the global transaction, and coordinating the global transaction. The composite service includes at least one atomic service, and the atomic service refers to the smallest service unit that executes a single service.

[0138] A second acquisition unit 20 is used to acquire request message information, wherein the request message information is information requesting to process a target transaction;

[0139] A first determining unit 30, configured to determine at least one target atomic service for processing the target transaction according to the request message information;

[0140] The first processing unit 40 is used to store the information of the atomic service in the database when the composite service and the atomic service have established communication connection with the database, so that the composite service obtains the information of the target atomic service before the target atomic service processes the target transaction, and uses the target atomic service to process the target transaction.

[0141] Through this embodiment, the composite service can be used to combine TC and TM, so there is no need to deploy TC and TM independently, the communication time between the composite service and the atomic service can be shortened, and the information of the target atomic service can be stored in the database before the target atomic service processes the target transaction. The composite service can determine the target atomic service and the information of the target atomic service before processing the target transaction, and there is no need for frequent communication between TC and TM, thereby shortening the execution time of the transaction and improving the transaction throughput.

[0142] The composite service is obtained based on the atomic service, and the atomic services can be orchestrated in a service orchestration manner to obtain the composite service. In the specific implementation process, the first acquisition unit includes a first acquisition module, a second acquisition module, a determination module and a first processing module. The first acquisition module is used to obtain multiple atomic services and respectively determine the role of each of the above atomic services; the second acquisition module is used to obtain multiple transactions and determine at least one of the above atomic services used to process each of the above transactions; the determination module is used to determine that the above atomic service is the above composite service when there is only one of the above atomic services used to process the above transaction; the first processing module is used to determine the execution order of the above atomic services when there are multiple of the above atomic services used to process the above transaction, and combine the multiple atomic services according to the above execution order to obtain the above composite service.

[0143] In this solution, the roles of different atomic services can be determined first. For example, some atomic services are used to deduct money, some atomic services are used to lock user accounts, and some atomic services are used to query accounts. In this way, the role (or function) of the atomic service is determined first, and then at least one atomic service used to process different transactions is determined. In this way, the specific atomic services required to process the transaction can be determined, and then the transaction and the atomic service are bound to obtain a combined service. In this way, the combined service and the atomic service can be used to process the transaction more efficiently. At the same time, since the processing of the transaction only involves the atomic service and the combined service, the time for processing the transaction can be further shortened.

[0144] In order to ensure that the subsequent composite service can obtain the status of the global transaction, obtain the information of the target atom before the target atom is executed, obtain the information of the target atom after the target atom is executed, and update the information of the target atom in real time after the target atom processes the transaction, the first processing unit includes a second processing module, a third processing module, a fourth processing module and a fifth processing module, the second processing module is used to generate a global transaction identifier when the above-mentioned composite service includes the opening identifier of the above-mentioned global transaction, and insert the opening record of the above-mentioned global transaction into the first data table of the above-mentioned database, wherein the primary key in the above-mentioned first data table is the above-mentioned global transaction identifier, the status of the above-mentioned global transaction is the opening state, the above-mentioned global transaction corresponds to the above-mentioned target transaction, and the above-mentioned global transaction refers to a collection of information of at least one of the above-mentioned target atomic services; the third processing module Used to insert a to-be-executed record of the target atomic service into the second data table of the database before the target atomic service is executed, wherein the primary key in the second data table is composed of the global transaction identifier and the to-be-executed sequence of the target atomic service, and the state of the target atomic service is an initialized state; the fourth processing module is used to insert an execution record of the target atomic service into the third data table of the database after the target atomic service is executed, wherein the primary key in the third data table is composed of the global transaction identifier and the execution sequence of the target atomic service, and the state of the target atomic service is a prepared state; the fifth processing module is used to use the target atomic service to process the target transaction, and update the information of at least one of the first data table, the second data table and the third data table.

[0145] In this solution, the first data table can be used to store information about global transactions, the second data table can be used to store information about the target atomic service and records to be executed before the target atomic service processes the target transaction, and the third data table can be used to store information about the target atomic service and records that have been executed after the target atomic service processes the target transaction. In this way, the composite service can obtain information from the second data table before the target atomic service processes the target transaction, and can determine the information of the target atomic service used to process the target transaction. There is no need for RM to return the executed records to TC after processing the target transaction, which further shortens the execution time of the transaction. In addition, the third data table can be used to verify the execution order of the target atomic service to process the target transaction, thereby ensuring the accuracy of the processing process. At the same time, the information of at least one data table can be updated to ensure the real-time performance of the information in the data table.

[0146] For the process of processing the target transaction of the target atomic service, it can be processed by the target atomic service submitting a local transaction, and after each target transaction is processed, the information of at least one data table can also be updated. In some embodiments, the fifth processing module includes a first processing sub-module, a second processing sub-module, a third processing sub-module and a fourth processing sub-module. The first processing sub-module is used to use the above-mentioned target atomic service to execute the local transaction based on the above-mentioned request message information; the second processing sub-module is used to use the above-mentioned combined service to update the status of the above-mentioned global transaction in the above-mentioned first data table to a delegating state when multiple above-mentioned target atomic services have executed the above-mentioned local transaction once; the third processing sub-module is used to use the above-mentioned combined service to send a delegation request to the above-mentioned target atomic service, and use the above-mentioned target atomic service to update the status of the above-mentioned target atomic service in the above-mentioned third data table to a delegated state based on the above-mentioned delegation request; the fourth processing sub-module is used to use the above-mentioned target atomic service to execute the above-mentioned local transaction again, and use the above-mentioned combined service to update the status of the above-mentioned global transaction in the above-mentioned first data table to a delegated state.

[0147] In this solution, the target atomic service can process the target transaction by executing (committing) the local transaction twice. For example, if the user account balance needs to be updated, the first execution of the local transaction is to lock the user account first, and the second execution of the local transaction is to update the account balance, that is, the local transaction is executed step by step. Of course, it can also be executed synchronously once and the target atomic service is used directly to process the target transaction. In this way, there is no need for back-and-forth communication between RM and TC, which further shortens the execution time of the transaction. At the same time, the information of at least one data table can be updated to further ensure the real-time performance of the information in the data table.

[0148] For the process of the target atomic service processing the target transaction, if the target atomic service processes the exception, it can be remedied and a rollback operation can be performed on the target transaction. In the specific implementation process, the fifth processing module includes a determination submodule, a fifth processing submodule and a sixth processing submodule. The determination submodule is used to determine that the target atomic service is abnormal when the records in the second data table and the records in the third data table do not correspond; the fifth processing submodule is used to use the combined service to initiate a rollback request to the target atomic service according to the records in the second data table, wherein the rollback request refers to a request to restore the last execution record of the target atomic service and a request to roll back the target transaction; the sixth processing submodule is used to use the target atomic service to determine whether a rollback is required based on the information in the second data table and the third data table, and perform a rollback operation when it is determined that a rollback is required, and at least update the information in the third data table, wherein the rollback operation refers to an operation to restore the last execution record of the target atomic service and roll back the target transaction.

[0149] In this solution, if the target atomic service is abnormal, it can be determined whether a rollback operation is required based on the information in the second data table and the third data table. Only when it is determined that a rollback operation is required will the rollback operation be performed. The target atomic service is used directly to perform the rollback operation. This eliminates the need for back-and-forth communication between RM and TC, further shortening the transaction execution time. At the same time, the information of at least one data table can be updated to further ensure that the information in the data table is more real-time.

[0150] The condition for determining whether a rollback is required can be determined based on the information in the second data table and the information in the third data table. In some embodiments, the sixth processing submodule is also used to determine whether there is a corresponding primary key in the third data table based on the primary key in the second data table; the sixth processing submodule is also used to determine that the target transaction is not committed and does not need to be rolled back when there is no primary key in the third data table corresponding to the primary key in the second data table, and insert an exception record of the target atomic service in the third data table, and the state of the target atomic service in the exception record is a suspended state; the sixth processing submodule is also used to determine that the target transaction has been committed and needs to be rolled back when there is a primary key in the third data table corresponding to the primary key in the second data table; update the state of the target atomic service in the third data table to a rolled back state, use the atomic service to perform a rollback operation, and update the state of the global transaction in the first data table to a rolled back state.

[0151] In this solution, since the information in the second data table already exists before the target atomic service is executed, the information in the third data table is directly compared with the information in the second data table. The information in the second data table is used as reference information. It can be determined whether the information in the third data table does not correspond to the information in the second data table, and then it can be more accurately determined whether the target atomic service has submitted the transaction. It can then be determined based on the comparison result whether a rollback operation is required. If a rollback operation is required, the target atomic service is used to perform the rollback operation, and the target atomic service can resubmit the transaction. This ensures that the solution can process the target transaction more efficiently and accurately, and avoid processing exceptions.

[0152] The composite service can perform a two-stage synchronous commit or rollback operation on the target atomic service, but in some scenarios, the synchronous commit or rollback may fail. For example, in some cases, the server is powered off or crashes, and the two-stage synchronization attempt has no chance to execute. At this time, an asynchronous service can be deployed to perform asynchronous processing. The above-mentioned device also includes a second determination unit, a third determination unit and a second processing unit. The second determination unit is used to determine whether the information in the first data table, the second data table, and the third data table has been updated after the above-mentioned target atomic service is used to process the above-mentioned target transaction; the third determination unit is used to determine that the above-mentioned target atomic service processes the above-mentioned target transaction abnormally when the information in the first data table, the second data table, and the third data table are not updated; the second processing unit is used to use the asynchronous service to re-execute the above-mentioned target transaction until it is determined that the above-mentioned target transaction is normal.

[0153] In this solution, in order to avoid multiple submission and rollback failures that lead to the target transaction being unable to be processed normally, an asynchronous service can be deployed to re-execute the target transaction through the asynchronous service, thereby ensuring that the target transaction can be executed normally.

[0154] In order to avoid abnormal situations caused by excessive execution of asynchronous services, the above-mentioned device also includes a third processing unit, which is used to update the status of the above-mentioned global transaction in the above-mentioned first data table to a processing abnormal state and suspend processing of the above-mentioned target transaction when the number of times the above-mentioned asynchronous service is re-executed is greater than or equal to a number threshold.

[0155] In this solution, if the asynchronous service executes the target transaction multiple times and exceptions occur, the asynchronous service will reprocess the target transaction. If the execution is too many times, it will cause the entire machine or the entire system to be abnormal. Therefore, the number of times the asynchronous service executes the target transaction can be limited. Once the number threshold is exceeded, the target transaction can be stopped, avoiding waste of resources.

[0156] The transaction processing device includes a processor and a memory, and the first acquisition unit, the second acquisition unit, the first determination unit, the first processing unit, etc. are all stored in the memory as program units, and the processor executes the program units stored in the memory to implement corresponding functions. The modules are all located in the same processor; or, the modules are located in different processors in any combination.

[0157] The processor contains a kernel, which calls the corresponding program unit from the memory. One or more kernels can be set, and the execution time of transactions can be shortened and the transaction throughput can be increased by adjusting the kernel parameters.

[0158] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.

[0159] An embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium includes a stored program, wherein when the program is executed, the device where the computer-readable storage medium is located is controlled to execute the method for processing transactions.

[0160] An embodiment of the present invention provides a processor, and the processor is used to run a program, wherein the method for processing transactions is executed when the program is run.

[0161] An embodiment of the present invention provides an electronic device, the device includes a processor, a memory, and a program stored in the memory and executable on the processor, and the method steps of processing a transaction are implemented when the processor executes the program. The device in this article may be a server, a PC, a PAD, a mobile phone, etc.

[0162] The present application also provides a computer program product, which, when executed on a data processing device, is suitable for executing a program for initiating at least the following method steps for processing a transaction:

[0163] Obviously, those skilled in the art should understand that the above modules or steps of the present invention can be implemented by a general computing device, they can be concentrated on a single computing device, or distributed on a network composed of multiple computing devices, they can be implemented by a program code executable by a computing device, so that they can be stored in a storage device and executed by the computing device, and in some cases, the steps shown or described can be executed in a different order than here, or they can be made into individual integrated circuit modules, or multiple modules or steps therein can be made into a single integrated circuit module for implementation. Thus, the present invention is not limited to any specific combination of hardware and software.

[0164] Those skilled in the art will appreciate that the embodiments of the present application may be provided as methods, systems, or computer program products. Therefore, the present application may adopt the form of a complete hardware embodiment, a complete software embodiment, or an embodiment in combination with software and hardware. Moreover, the present application may adopt the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that include computer-usable program code.

[0165] The present application is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of the present application. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to generate a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.

[0166] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.

[0167] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.

[0168] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.

[0169] The memory may include non-permanent memory in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.

[0170] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.

[0171] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.

[0172] From the above description, it can be seen that the above embodiments of the present application achieve the following technical effects:

[0173] 1) The transaction processing method of the present application can use a composite service to combine TC and TM, so that there is no need to deploy TC and TM independently, which can shorten the communication time between the composite service and the atomic service, and store the information of the target atomic service in the database before the target atomic service processes the target transaction. The composite service can determine the target atomic service and the information of the target atomic service before processing the target transaction, and there is no need for frequent communication between TC and TM, thereby shortening the execution time of the transaction and improving the transaction throughput.

[0174] 2) The transaction processing device of the present application can use a composite service to combine TC and TM, so that there is no need to deploy TC and TM independently, which can shorten the communication time between the composite service and the atomic service, and store the information of the target atomic service in the database before the target atomic service processes the target transaction. The composite service can determine the target atomic service and the information of the target atomic service before processing the target transaction, and there is no need for frequent communication between TC and TM, thereby shortening the execution time of the transaction and improving the transaction throughput.

[0175] The above description is only the preferred embodiment of the present application and is not intended to limit the present application. For those skilled in the art, the present application may have various modifications and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present application shall be included in the protection scope of the present application.

Claims

1. A method for processing transactions, characterized in that: include: Acquire a composite service, wherein the composite service has the functions of a transaction coordinator TC and a transaction manager TM, and the composite service is used for at least one of the following: maintaining a global transaction, maintaining a branch transaction, starting the global transaction, and coordinating the global transaction, and the composite service includes at least one atomic service, and the atomic service refers to the smallest service unit that executes a single service; Obtaining request message information, wherein the request message information is information requesting to process a target transaction; Determine at least one target atomic service for processing the target transaction according to the request message information; When both the composite service and the atomic service have established communication connections with a database, the information of the atomic service is stored in the database, so that the composite service obtains the information of the target atomic service before the target atomic service processes the target transaction, and uses the target atomic service to process the target transaction; Storing the information of the atomic service in the database includes: In the case where the composite service includes an opening identifier of the global transaction, a global transaction identifier is generated, and an opening record of the global transaction is inserted into a first data table of the database, wherein the primary key in the first data table is the global transaction identifier, the state of the global transaction is an opening state, the global transaction corresponds to the target transaction, and the global transaction refers to a collection of information of at least one target atomic service; Before the target atomic service is executed, inserting a to-be-executed record of the target atomic service into a second data table of the database, wherein the primary key in the second data table is composed of the global transaction identifier and the to-be-executed sequence of the target atomic service, and the state of the target atomic service is an initialization state; After the target atomic service is executed, inserting an execution record of the target atomic service into a third data table of the database, wherein a primary key in the third data table is composed of the global transaction identifier and the execution order of the target atomic service, and the state of the target atomic service is a prepared state; Using the target atomic service to process the target transaction includes: The target atomic service is used to process the target transaction, and information of at least one of the first data table, the second data table, and the third data table is updated.

2. The method according to claim 1, characterized in that Get a package of services including: Acquire multiple atomic services, and respectively determine the role of each of the atomic services; Acquire multiple transactions, and determine at least one of the atomic services used to process each of the transactions; In a case where there is only one atomic service used to process the transaction, determining that the atomic service is the composite service; In the case that there are multiple atomic services used to process the transaction, the execution order of the multiple atomic services is determined, and the multiple atomic services are combined according to the execution order to obtain the combined service.

3. The method according to claim 1, characterized in that Using the target atomic service to process the target transaction and updating information of at least one of the first data table, the second data table, and the third data table includes: Based on the request message information, using the target atomic service to execute the local transaction; In the case that the plurality of target atomic services have executed the local transaction once, using the combined service to update the state of the global transaction in the first data table to a delegating state; Using the combined service to send a delegation request to the target atomic service, and using the target atomic service to update the state of the target atomic service in the third data table to a delegated state based on the delegation request; The target atomic service is used to execute the local transaction again, and the combined service is used to update the state of the global transaction in the first data table to a delegated state.

4. The method according to claim 1, characterized in that: Using the target atomic service to process the target transaction and updating information of at least one of the first data table, the second data table, and the third data table includes: In the case where the records of the second data table and the records of the third data table do not correspond to each other, determining that the target atomic service is abnormal; Using the combined service, a rollback request is initiated to the target atomic service according to the record of the second data table, wherein the rollback request is a request to restore the last execution record of the target atomic service and to roll back the target transaction; The target atomic service is used to determine whether a rollback is required based on the information in the second data table and the third data table. When a rollback is required, a rollback operation is performed and at least the information in the third data table is updated, wherein the rollback operation refers to restoring the last execution record of the target atomic service and rolling back the target transaction.

5. The method according to claim 4, characterized in that Using the target atomic service, based on the information in the second data table and the third data table, determining whether a rollback is required, and when a rollback is required, performing a rollback operation and updating at least the information in the third data table, including: Determine, according to the primary key in the second data table, whether there is a corresponding primary key in the third data table; In the case that there is no primary key in the third data table corresponding to the primary key in the second data table, determining that the target transaction is not committed and does not need to be rolled back, inserting an exception record of the target atomic service into the third data table, wherein the state of the target atomic service in the exception record is a suspended state; In a case where there is a primary key in the third data table corresponding to the primary key in the second data table, determining that the target transaction has been committed and needs to be rolled back; The state of the target atomic service in the third data table is updated to a rolled-back state, the atomic service is used to perform a rollback operation, and the state of the global transaction in the first data table is updated to a rolled-back state.

6. The method according to claim 1, characterized in that After the target atomic service is used to process the target transaction, the method further includes: Determine whether the information in the first data table, the information in the second data table, and the information in the third data table have been updated; When the information in the first data table, the information in the second data table, and the information in the third data table are not updated, determining that the target atom processes the target transaction abnormally; The target transaction is re-executed using an asynchronous service until it is determined that the target transaction is normal.

7. The method according to claim 6, characterized in that The method further comprises: When the number of times the target transaction is re-executed using the asynchronous service is greater than or equal to a number threshold, the state of the global transaction in the first data table is updated to a processing exception state, and processing of the target transaction is suspended.

8. A device for processing transactions, characterized in that: include: A first acquisition unit is used to acquire a composite service, wherein the composite service has the functions of a transaction coordinator TC and a transaction manager TM, and the composite service is used for at least one of the following: maintaining a global transaction, maintaining a branch transaction, starting the global transaction, and coordinating the global transaction, and the composite service includes at least one atomic service, and the atomic service refers to the smallest service unit that executes a single service; A second acquiring unit, configured to acquire request message information, wherein the request message information is information requesting to process a target transaction; A first determining unit, configured to determine at least one target atomic service for processing the target transaction according to the request message information; A first processing unit is configured to store information of the atomic service in the database when both the composite service and the atomic service have established communication connections with the database, so that the composite service obtains information of the target atomic service before the target atomic service processes the target transaction, and uses the target atomic service to process the target transaction; The first processing unit includes a second processing module, a third processing module, a fourth processing module and a fifth processing module. The second processing module is used to generate a global transaction identifier when the combined service includes the start identifier of the global transaction, and insert the start record of the global transaction into the first data table of the database, wherein the primary key in the first data table is the global transaction identifier, the state of the global transaction is the start state, the global transaction corresponds to the target transaction, and the global transaction refers to a collection of information of at least one target atomic service; the third processing module is used to insert a to-be-executed record of the target atomic service into the second data table of the database before the target atomic service is executed, wherein the primary key in the second data table is composed of the global transaction identifier and the to-be-executed sequence of the target atomic service, and the state of the target atomic service is the initialization state; the fourth processing module is used to insert the execution record of the target atomic service into the third data table of the database after the target atomic service is executed, wherein the primary key in the third data table is composed of the global transaction identifier and the execution sequence of the target atomic service, and the state of the target atomic service is the prepared state; the fifth processing module is used to process the target transaction using the target atomic service, and update the information of at least one data table among the first data table, the second data table and the third data table.

9. An electronic device, characterized in that: include: One or more processors, a memory, and one or more programs, wherein the one or more programs are stored in the memory and are configured to be executed by the one or more processors, and the one or more programs include methods for executing any one of claims 1 to 7.

Citation Information

Patent Citations

  • Distributed transaction processing method and device

    CN111259083A

  • Transaction processing system, transaction processing method and transaction processing device

    CN113296895A