Message processing method and device, distributed transaction processing system and computer equipment
The message processing method reduces the coupling degree of transaction processing in distributed transaction processing, solves the problem of high coupling degree of distributed transaction processing in the existing technology, and achieves consistency of distributed transaction results and simplification of system maintenance.
Patent Information
- Application Number
- CN202111231248.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-22
- Publication Date
- 2024-10-29
- Estimated Expiration
- 2041-10-22
AI Technical Summary
The high coupling degree of distributed transaction processing in the existing technology leads to increased system maintenance costs and complexity, making it difficult to ensure the consistency of distributed transactions.
Through the message processing method, receive the application transaction start request initiated by the transaction initiator, save the transaction message in the message cache pool, initialize the message status, modify the message status according to the execution result, pass it to the transaction collaborator to process the local transaction, and finally based on the result Feedback to the transaction initiator for commit or rollback operation reduces the coupling of transaction processing.
It achieves the consistency of distributed transaction processing results and reduces system maintenance complexity and cost. It decouples transaction initiators and transaction collaborators through an independent message processing system, simplifying the implementation of passive transaction threads.
Smart Images

Figure CN114168358B_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer application technology, and in particular to a message processing method and apparatus, a distributed transaction processing system and computer equipment, and also to a computer-readable storage medium. Background Art
[0002] One of the main functions of the cloud management platform system is to simplify the management of cloud devices, such as virtual machines, storage devices, and networks. These resource management will be related to transaction issues. For example, the virtual machine creation function requires the cooperation of multiple modules such as network, storage, and memory to complete successfully. The failure of any module will lead to the failure of the entire virtual machine creation function. With the implementation of the microservice architecture of the cloud management platform system, each functional module is relatively more independent, so similar distributed transaction processing becomes more complicated. How to ensure the consistency of distributed transactions is very important for the business scenario requirements of the cloud management platform.
[0003] In the related art, in order to solve the transaction consistency problem in a distributed environment, the "two-phase commit (2PC)" and "three-phase commit (3PC)" methods are usually used. "Two-phase commit" means defining a coordinator node, and all participants notify the coordinator node of the success or failure of the operation. The coordinator node decides whether the participant should commit the operation or terminate the operation based on the feedback information. "Three-phase commit" is an improved version of "two-phase commit". A timeout mechanism is introduced in the coordinator and the participants, and the first stage of "two-phase commit" is divided into two steps, namely, first asking, and then locking the resources, to ensure that the status of each participant before the final commit stage is consistent. Based on the above 2PC and 3PC technologies, the AT (Automatic Transaction) mode and TCC (Try-Confirm-Cancel) mode are usually used in the related art to ensure the consistency of distributed transactions. However, the implementation method of the above mode is highly coupled with the code, resulting in the subsequent modification and maintenance costs of the original system. Summary of the invention
[0004] Based on this, it is necessary to provide a message processing method and apparatus, a distributed transaction processing system and a computer device that can reduce the coupling degree of distributed transaction processing in order to address the above technical problems.
[0005] In a first aspect, the present application provides a message processing method, the method comprising:
[0006] Receiving a start request of an application transaction initiated by a transaction initiator, saving a transaction message of the application transaction in a message buffer pool in response to the start request, initializing a message state of the transaction message, and feeding back a first reply message to the transaction initiator;
[0007] receiving a first execution result obtained by the transaction initiator executing the local transaction according to the first feedback message, and modifying the state information of the transaction message in the message buffer pool from the initialization state to the ready state according to the first execution result;
[0008] Delivering the transaction message in a ready state to the transaction coordinator according to the state information of the transaction message, so that the transaction coordinator processes the corresponding local transaction;
[0009] The second execution result obtained by the transaction collaborator in processing the local transaction is obtained, and a second feedback message is fed back to the transaction initiator according to the second execution result, so that the transaction initiator performs a commit or rollback operation according to the second feedback message.
[0010] In one implementation manner, the start request carries a unique transaction message identifier corresponding to the application transaction; the application transaction includes at least one associated sub-transaction;
[0011] The step of storing the transaction message of the application transaction in the message buffer pool in response to the start request includes:
[0012] Responding to the start request, obtaining a transaction message identifier corresponding to the application transaction;
[0013] If it is determined according to the transaction message identifier that the transaction message corresponding to the transaction message identifier does not exist in the message cache pool, the transaction message is stored in the message cache pool, and the message status of each associated sub-transaction corresponding to the application transaction is set to an initialization state; wherein the message content of the transaction message includes: the transaction message identifier and the corresponding relationship between the transaction message identifier and at least one associated sub-transaction.
[0014] In one embodiment, the step of modifying the state information of the transaction message in the message buffer pool from the initialization state to the ready state according to the first execution result includes:
[0015] If it is determined according to the first execution result that the execution result of the associated subtransaction executed by the transaction initiator is successful, the message state corresponding to the associated subtransaction in the message buffer pool is modified from the initialization state to the ready state.
[0016] In one embodiment, the step of delivering a transaction message in a ready state to a transaction coordinator according to the state information of the transaction message so that the transaction coordinator processes the corresponding local transaction includes:
[0017] According to the status information of the transaction message, the associated sub-transaction in the ready state is captured from the message buffer pool and published to the message channel, so that the transaction collaborator who subscribes to the message channel performs local transaction processing according to the associated sub-transaction and publishes the transaction processing result of the associated sub-transaction to the message channel.
[0018] In one embodiment, the step of obtaining the second execution result obtained by the transaction collaborator in processing the local transaction includes:
[0019] Subscribe to the second execution result obtained by executing the associated sub-transaction published to the message channel by the transaction collaborator;
[0020] If it is determined according to the second execution result that the execution result of the associated sub-transaction executed by the transaction collaborator is successful, the message state corresponding to the associated sub-transaction is modified to a completed state, and the associated sub-transaction is marked.
[0021] In one embodiment, the step of feeding back a second feedback message to the transaction initiator according to the second execution result so that the transaction initiator performs a commit or rollback operation according to the second feedback message includes:
[0022] According to the marks of all associated sub-transactions corresponding to the transaction message, determine whether all associated sub-transactions are marked as preset results. If so, a commit operation message is fed back to the transaction initiator to notify the transaction initiator to perform the commit operation of the application transaction; otherwise, a rollback operation message is fed back to the transaction initiator and transaction collaborators to roll back the transaction message.
[0023] In a second aspect, the present application further provides a message processing device, the device comprising:
[0024] A first feedback module is used to receive a start request of an application transaction initiated by a transaction initiator, save a transaction message of the application transaction in a message buffer pool in response to the start request, initialize a message state of the transaction message, and feed back a first reply message to the transaction initiator;
[0025] A state modification module, used for receiving a first execution result obtained by the transaction initiator executing the local transaction according to the first feedback message, and modifying the state information of the transaction message in the message buffer pool from the initialization state to the ready state according to the first execution result;
[0026] A message delivery module, used for delivering a transaction message in a ready state to a transaction coordinator according to the state information of the transaction message, so that the transaction coordinator processes the corresponding local transaction;
[0027] The second feedback module is used to obtain the second execution result obtained by the transaction collaborator in processing the local transaction, and feedback a second feedback message to the transaction initiator according to the second execution result, so that the transaction initiator performs a commit or rollback operation according to the second feedback message.
[0028] In a third aspect, the present application further provides a distributed transaction processing system, including: a message processing system and a business system, the business system including a transaction initiator and a transaction collaborator;
[0029] The transaction initiator initiates a request to start an application transaction to the message processing system;
[0030] The message processing system saves the transaction message of the application transaction in the message buffer pool in response to the start request, initializes the message state of the transaction message, and feeds back a first reply message to the transaction initiator;
[0031] The transaction initiator executes the local transaction according to the first feedback message to obtain a first execution result;
[0032] The message processing system receives the first execution result, modifies the state information of the transaction message in the message buffer pool from the initialization state to the ready state according to the first execution result, and transmits the transaction message in the ready state to the transaction collaborator according to the state information of the transaction message, so that the transaction collaborator processes the corresponding local transaction;
[0033] The transaction collaborator processes the transaction message to obtain a second execution result;
[0034] The message processing system obtains the second execution result, and feeds back a second feedback message to the transaction initiator according to the second execution result;
[0035] The transaction initiator commits or rolls back the application transaction according to the second reply message.
[0036] In a fourth aspect, the present application also provides a computer device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the message processing method mentioned in the first aspect when executing the computer program.
[0037] In a fifth aspect, the present application also provides a computer-readable storage medium having a computer program stored thereon, which implements the steps of the message processing method mentioned in the first aspect when the computer program is executed by a processor.
[0038] The message processing method and device, distributed transaction processing system, computer equipment and storage medium receive a start request of an application transaction initiated by a transaction initiator, save the transaction message and initialize the message state of the transaction message according to the start request, and feed back a first report message to the transaction initiator; modify the state information of the transaction message to a ready state according to the first execution result obtained by the transaction initiator executing the local transaction in response to the first report message; pass the transaction message in the ready state to the transaction collaborator, so that the transaction collaborator processes the corresponding local transaction and obtains the corresponding second execution result, and feeds back a second report message to the transaction initiator according to the second execution result, so that the transaction initiator performs a commit or rollback operation according to the second report message. In the present technical solution, the message processing system does not execute a transaction, but obtains the execution result of the local transaction by the transaction initiator or the transaction collaborator, modifies the state information of the transaction message accordingly, and uses the state information to instruct the transaction initiator to perform a commit or rollback operation, thereby ensuring the consistency of the distributed transaction processing results. In addition, since the message processing system is independent of the transaction initiator and transaction collaborators, and the transaction main thread corresponding to the transaction initiator is decoupled from the passive transaction threads corresponding to each transaction collaborator, the coupling degree of distributed transaction processing is reduced, which is beneficial to subsequent system maintenance and reduces the complexity and cost of system maintenance. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] Figure 1 A schematic diagram of an application scenario of a message processing method in an embodiment;
[0040] Figure 2 is a flowchart of a message processing method provided by an embodiment;
[0041] Figure 3 is a schematic diagram of a storage structure of a transaction message provided by an embodiment;
[0042] Figure 4 is another flow chart of a message processing method provided by an embodiment;
[0043] Figure 5 is a schematic diagram of the structure of a distributed transaction processing system provided by an embodiment;
[0044] Figure 6 This is a structural diagram of a message processing device provided by an embodiment;
[0045] Figure 7 FIG. 4 is a diagram showing the internal structure of a computer device in one embodiment. DETAILED DESCRIPTION
[0046] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0047] Those skilled in the art will appreciate that, unless otherwise stated, the singular forms "a", "an", "said" and "the" used herein may also include plural forms. It should be further understood that the term "comprising" used in the specification of the present application refers to the presence of features, integers, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, integers, steps, operations, elements, components and / or groups thereof.
[0048] In order to facilitate the understanding of this application, the technical terms involved in this application are first explained.
[0049] The transaction initiator, also known as the transaction initiator node, can be regarded as a global transaction in a distributed transaction. Each global transaction includes at least one application service. Each application service can be handed over to a node server for execution. Among them, the node server that initiates the global transaction is called the transaction initiator.
[0050] Transaction coordinators, also known as transaction coordinator nodes, are node servers other than the transaction initiator that can become transaction coordinators in the processing of distributed transactions to assist the transaction initiator in completing the processing of global transactions. Transaction initiators and transaction coordinators are often in the same distributed system.
[0051] 2PC (Two-phase-commit): also known as the two-phase commit protocol, the specific steps of using 2PC to process distributed transactions are: a transaction is divided into two phases. The first phase is the preparation phase, which is initiated by the transaction initiator, asking all transaction participants whether they can be adjusted, and the transaction participants participate in the voting; the second phase is the commit phase, and the transaction initiator decides whether to commit or roll back based on the voting results of the transaction collaborators. The commit operation can only be performed when all transaction participants agree to commit, thereby ensuring the transaction consistency of all transaction collaborators.
[0052] 3PC (Three-phase commit): also known as the three-phase commit protocol, is an improved version of the two-phase commit (2PC). In addition to introducing a timeout mechanism, 3PC divides the preparation phase of 2PC into two again, so that the three-phase commit includes three phases: CanCommit, PreCommit, and DoCommit. The transaction coordinator sends a CanCommit request to the transaction participant, asking whether the transaction commit operation can be performed, and then waits for the response of the transaction participant. Response feedback After the transaction participant receives the CanCommit request, under normal circumstances, if it believes that the transaction can be successfully executed, it returns a Yes response and enters the preparation state, otherwise it returns a No response. If all transaction participants return a Yes response, the transaction enters the PreCommit phase for pre-committing the transaction. At this time, the transaction coordinator and the transaction participants have introduced a timeout mechanism (only the coordinator in 2PC can time out, and the participants do not have a timeout mechanism). After receiving the Commit request, the transaction participant will formally execute the local transaction Commit operation and release the transaction resources occupied during the entire transaction execution after the commit is completed.
[0053] Rollback: refers to the act of restoring to the most recent correct version when a program or data error occurs. When a distributed transaction fails, you need to perform a rollback operation separately to achieve eventual consistency.
[0054] ACID characteristics refer to the four characteristics that a database management system (DBMS) must possess to ensure that transactions are correct and reliable during the process of writing or updating data: atomicity (also known as indivisibility), consistency (consistency), isolation (also known as independence), and durability.
[0055] The application environment to which the embodiments of the present application are applicable is described below.
[0056] In a distributed system architecture, the entire business process is completed by multiple business nodes providing multiple services. A business logic often requires data from multiple services. In order to ensure data consistency among multiple services, a distributed transaction mechanism is usually introduced. Each transaction contains different business operations on multiple nodes, and the execution result of the transaction can only be either all successful or all failed.
[0057] Figure 1 FIG. 1 is a schematic diagram of an application scenario of a message processing method in an embodiment. Figure 1As shown, the application scenario includes a message processing system 110, a transaction initiator 120, and a transaction coordinator 130 connected to a network. The transaction initiator 120 and the transaction coordinator 130 can be a database or a server, etc. The message processing system 110 is a computer device for message processing, which can be a server. The server can be implemented as an independent server or a server cluster composed of multiple physical servers.
[0058] The message processing system 110 may receive a start request for an application transaction initiated by a transaction initiator 120, and in response to the start request, determine whether the transaction message of the application transaction exists in the message buffer pool according to the transaction message identifier of the application transaction carried in the start request, and if not, save the transaction message in the message buffer pool, and feed back a first report message to the transaction initiator. The transaction initiator 120 executes the local transaction according to the first report message to obtain a first execution result. The message processing system 110 receives the first execution result, modifies the state information of the transaction message in the message buffer pool from the initialization state to the ready state according to the first execution result, and transmits the transaction message in the ready state to the transaction coordinator 130, so that the transaction coordinator 130 processes the corresponding local transaction. The transaction coordinator 130 processes the transaction message to obtain a second execution result. The message processing system 110 obtains the second execution result, and feeds back a second report message to the transaction initiator 120 according to the second execution result, so as to instruct the transaction initiator 120 to commit or roll back the transaction. The transaction initiator 120 commits or rolls back the application transaction according to the second reply message.
[0059] In this technical solution, the transaction initiator executes the transaction main thread, the transaction coordinator executes each passive transaction thread, and each transaction coordinator performs a local transaction under the instruction of the corresponding status of the transaction message issued by the message processing system. If the execution results of the transaction coordinators are all successful, the message status of the transaction messages corresponding to the message processing system are consistent, thereby ensuring the ACID characteristics of the local transaction, greatly simplifying the implementation of the passive transaction thread, thereby decoupling the transaction main thread from the passive transaction threads, and reducing the coupling degree of distributed transaction processing.
[0060] The message processing method and device, distributed transaction processing system and computer equipment provided in this application solve the above technical problems in the prior art.
[0061] The following specific embodiments are used to describe in detail the technical solution of the present application and how the technical solution of the present application solves the above technical problems. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments.
[0062] Figure 2It is a flowchart of a message processing method provided by an embodiment, and the message processing method can be executed in a message processing system.
[0063] Specifically, Figure 2 As shown, the message processing method may include the following steps:
[0064] S210: Receive a start request for an application transaction initiated by a transaction initiator, save a transaction message of the application transaction in a message buffer pool in response to the start request, initialize a message state of the transaction message, and feed back a first reply message to the transaction initiator.
[0065] For application transactions, it refers to a series of operations performed as a single logical unit of work. In this application, application transactions refer to distributed transactions, which means that the participants of the transaction, the server supporting the transaction, the database, and the transaction manager are located on different nodes of the distributed system to jointly perform a series of operations of the transaction.
[0066] In this embodiment, the message transmission between the transaction initiator and the message processing system can be executed based on RPC (Remote Procedure Call Protocol), thereby ensuring the synchronization and timeliness of the message communication between the message processing system and the transaction initiator.
[0067] The transaction initiator initiates a start request of an application transaction to the message processing system. The message processing system receives the start request of the application transaction and checks whether the application transaction has been stored in the message buffer pool of the message processing system in response to the start request.
[0068] Optionally, in one embodiment, a unique transaction message identifier corresponding to the application transaction may be determined according to the start request, and a query is made according to the transaction message identifier to determine whether a transaction message corresponding to the transaction message identifier already exists in the message buffer pool.
[0069] Optionally, in one embodiment, if the transaction message of the application transaction already exists in the message buffer pool, it means that the application transaction has been processed by the message processing system, and then transaction duplication information can be fed back to the transaction initiator to inform the transaction initiator not to repeat the application transaction; if the transaction message of the application transaction does not exist in the message buffer pool, it means that the application transaction is not currently executing related message processing in the message processing system, and then the transaction message is stored in the message buffer pool, and the message state of the transaction message is initialized, that is, the message state of the transaction message is modified to the initialization state, and transaction reception confirmation information is fed back to inform the transaction initiator that the start request of the application transaction has been confirmed to be received and processed, and the transaction initiator is instructed to proceed to the next step.
[0070] S220: Receive a first execution result obtained by the transaction initiator when executing the local transaction according to the first feedback message, and modify the status information of the transaction message in the message buffer pool from the initialization state to the ready state according to the first execution result.
[0071] In this embodiment, the status information of the transaction message includes: initialization status, ready status, executing status, successful execution status, and failed execution status.
[0072] In this embodiment, the message processing system updates the message status of the transaction message stored in the message buffer pool according to the execution result of the transaction message transmitted by the transaction initiator or the transaction collaborator.
[0073] For example, the message status of a transaction message in the message cache pool is initially in the initialization status. If the transaction execution result passed by the transaction initiator is received, the message status of the transaction message is updated to the ready status. Then, according to the transaction execution status of the transaction collaborator, the message status of the transaction message is updated to the executing status. Finally, after receiving the transaction execution result passed by the transaction collaborator, the message status of the transaction message is updated to the execution success status or the execution failure status, etc.
[0074] In this embodiment, the message processing system does not actually execute the application transaction, but updates the message status of the transaction message stored in the message buffer pool according to the execution result of the application transaction by the transaction initiator or transaction collaborator, and transmits information to the transaction initiator or transaction collaborator according to the message status to instruct the transaction initiator or transaction collaborator to process the corresponding transaction.
[0075] The ready state can be understood as a message state that is suitable for being delivered to a transaction collaborator for transaction processing, and the initialization state can be understood as the most initial state of a transaction message, or the state of the previous stage of the ready state.
[0076] S230. Deliver the transaction message in a ready state to the transaction coordinator according to the state information of the transaction message, so that the transaction coordinator processes the corresponding local transaction.
[0077] The transaction message that can be used for the next operation is determined according to the status information of the transaction message. In this embodiment, the initial state of the transaction message stored in the message buffer pool is the initialization state. When the transaction initiator successfully completes the first execution result of the local transaction, the status information of the transaction message is modified from the initialization state to the ready state. The transaction message in the ready state is published to the corresponding transaction collaborator to inform the transaction collaborator to perform the next operation.
[0078] S240: Obtain a second execution result obtained by the transaction collaborator in processing the local transaction, and feed back a second reply message to the transaction initiator according to the second execution result, so that the transaction initiator performs a commit or rollback operation according to the second reply message.
[0079] The transaction collaborator obtains the transaction message in the processing ready state, performs local transaction processing on the transaction message, obtains a second execution result, the second execution result includes an execution success result and an execution failure result, and returns the second execution result to the message processing system.
[0080] The message processing system receives the second execution result, and modifies the message status of the transaction message in the message buffer pool according to the second execution result. Specifically, if the second execution result is a successful execution result, the status information of the corresponding transaction message is modified to a successful execution status; if the second execution result is an execution failure, the status information of the transaction message is modified to an execution failure status.
[0081] Furthermore, the message processing system feeds back a second feedback message to the transaction initiator according to the status information of the transaction message in the message buffer pool.
[0082] In this embodiment, if all transaction messages corresponding to the application transaction are in the execution success status, it is determined that all transaction collaborators have successfully executed the transaction corresponding to the application transaction, and then the transaction completion confirmation information is reported to the transaction initiator. The transaction initiator determines that the data of each server node is consistent based on the transaction completion confirmation information, and then the transaction initiator performs a commit operation on the application transaction.
[0083] If the transaction messages corresponding to the application transaction are not all in the execution success state, that is, some transaction messages are in the execution failure state, it is determined that there is a transaction collaborator that failed to successfully execute the transaction corresponding to the application transaction, and then the transaction failure confirmation information is reported to the transaction initiator. The transaction initiator determines that the data of each server node is inconsistent based on the transaction failure confirmation information, and then the transaction initiator performs a rollback operation on the application transaction. In one embodiment, when it is determined that the data of each server node is inconsistent, all transaction collaborators also perform a rollback operation on the associated sub-transactions corresponding to the application transaction.
[0084] It should be noted that the message processing system is independent of the transaction initiator and transaction coordinator. The message processing system does not execute application transactions. Instead, it modifies the status of transaction messages stored in the message processing system according to the transaction execution results of the transaction initiator and transaction coordinator, and sends corresponding feedback information to the transaction initiator and transaction coordinator based on the message status of the transaction message to instruct the transaction initiator and transaction coordinator to perform corresponding transaction processing or actions based on the feedback information, thereby managing and controlling the processing of distributed transactions to ensure the local transaction integrity and consistency of each node such as the transaction initiator and transaction coordinator.
[0085] The message processing method provided in this embodiment is applied to a message processing system. The method receives a start request of an application transaction initiated by a transaction initiator, saves the transaction message in response to the start request, initializes the message state of the transaction message, and feeds back a first report message to the transaction initiator; receives a first execution result obtained by the transaction initiator executing a local transaction according to the first report message, and modifies the state information of the transaction message to a ready state according to the first execution result; transmits the transaction message in the ready state to the transaction coordinator, so that the transaction coordinator processes the corresponding local transaction; obtains a second execution result obtained by the transaction coordinator processing the local transaction, and feeds back a second report message to the transaction initiator according to the second execution result, so that the transaction initiator performs a commit or rollback operation according to the second report message, thereby ensuring the consistency of the distributed transaction processing results; because the message processing system is independent of the transaction initiator and the transaction coordinator, and the transaction main thread corresponding to the transaction initiator is decoupled from the passive transaction threads corresponding to each transaction coordinator, the coupling degree of distributed transaction processing is reduced, which is beneficial to subsequent system maintenance and reduces the system maintenance complexity and maintenance cost.
[0086] In order to more clearly illustrate the technical solution of the present application, multiple steps of the message processing method are further explained below.
[0087] In one embodiment, the start request carries a unique transaction message identifier corresponding to the application transaction, and the application transaction includes at least one associated sub-transaction, that is, an application transaction can be divided into multiple associated sub-transactions for execution, and multiple associated sub-transactions can be processed in parallel or in series. The message content of the transaction message stored in the message buffer pool by the message processing system includes the transaction message identifier and the corresponding relationship between the transaction message identifier and the at least one associated sub-transaction.
[0088] For example, an application transaction A includes multiple associated sub-transactions, such as A-1, A-2, A-3, A-4, and A-5. The unique transaction message identifier corresponding to the application transaction is a, and the message content of the transaction message includes the transaction message identifier a of the application transaction A, and the corresponding relationship between the transaction message identifier a and at least one associated sub-transaction of the application transaction A, such as aA-1, aA-2, aA-3, aA-4, and aA-5.
[0089] Furthermore, in one embodiment, each associated subtransaction corresponds to a unique subtransaction type, and the subtransaction type is used to characterize the transaction execution logic type executed by the associated subtransaction, such as addition, deletion, modification, etc. The subtransaction types of each associated subtransaction included in the same application transaction can be different or the same. For example, an application transaction A includes 2 associated subtransactions of "addition" logic and 1 associated subtransaction of "modification" logic. Optionally, different subtransaction types can correspond to different subtransaction identifiers.
[0090] Optionally, in one embodiment, the message content stored in the message buffer pool of the message processing system can be stored in a hash structure of redis (Remote Dictionary Server), where redis is a key-value storage database. Figure 3 As shown, Figure 3 It is a schematic diagram of a storage structure of a transaction message provided by an embodiment.
[0091] See also Figure 3 , the transaction messages corresponding to multiple application transactions are stored in the message cache pool in the form of redis hash structure. The transaction message identifier (i.e. transaction message id) corresponding to each transaction message is the key of Redis, and the message status corresponding to each transaction message is the value of Redis. In addition, each transaction message can correspond to multiple associated sub-transaction messages. Optionally, each associated sub-transaction message corresponds to a different sub-transaction execution type.
[0092] For associated sub-transaction messages, each associated sub-transaction message corresponds to a unique associated sub-transaction message identifier. Optionally, the associated sub-transaction message identifier and the corresponding message status are also stored in a hash structure, with the associated sub-transaction message identifier as the key and the message status of the associated sub-transaction message as the value, wherein the message status of the associated sub-transaction message includes: initialization, running, success, and failure, etc. Optionally, a transaction message can be divided into multiple associated sub-transaction messages according to the execution type of the transaction message. For example, if a transaction message involves execution logics such as "addition", "subtraction", and "clearing", the transaction message can be divided into multiple associated sub-transaction messages according to different execution types according to the execution logic.
[0093] like Figure 3 As shown, the transaction message identifier corresponding to transaction message A is a, and its corresponding message status is: in execution. According to the execution logic type involved in the application transaction, the transaction message A includes multiple associated sub-transaction messages, namely associated sub-transaction message 1 and associated sub-transaction message 2, etc., among which the message status of associated sub-transaction message 1 is "in execution", and the message status of associated sub-transaction message 2 is "successful", etc.
[0094] In one embodiment, the step S210 of storing the transaction message of the application transaction in the message buffer pool may include the following steps:
[0095] S2101. In response to a start request, obtain a transaction message identifier corresponding to an application transaction.
[0096] In this embodiment, the start request carries a unique transaction message identifier corresponding to the application transaction. The message processing system parses the start request to obtain the transaction message identifier corresponding to the application transaction.
[0097] S2102: If it is determined according to the transaction message identifier that the transaction message corresponding to the transaction message identifier does not exist in the message buffer pool, the message content is stored in the message buffer pool, and the message status of each associated sub-transaction corresponding to the message identifier is set to an initialization status.
[0098] When the message processing system processes an application transaction, the transaction message of the application transaction is stored in the message buffer pool. The message processing system obtains the transaction message of the application transaction, determines the transaction message identifier corresponding to the application transaction from the transaction message, and queries the current message buffer pool based on the transaction message identifier whether the transaction message identifier exists. If it exists, it means that the application transaction corresponding to the transaction message identifier is already in the execution process. If it does not exist, it means that the application transaction corresponding to the transaction message identifier has not been received and executed. The start request of the application transaction is accepted, and the message content of the transaction message, such as the transaction message identifier corresponding to the transaction message of the application transaction, and multiple associated sub-transaction messages corresponding to the transaction message identifier, are stored.
[0099] After storing the message content, the message processing system sets the message status of each associated sub-transaction corresponding to the application transaction to the initialization state, and notifies the transaction initiator to confirm that the application transaction can be processed.
[0100] In one embodiment, the step S220 of modifying the state information of the transaction message from the initialization state to the ready state according to the first execution result may include the following steps:
[0101] S2201: Determine, according to the first execution result, that the execution result of the associated subtransaction executed by the transaction initiator is successful, and then modify the message state corresponding to the associated subtransaction from the initialization state to the ready state.
[0102] After receiving the transaction confirmation information fed back by the message processing system, the transaction initiator starts to execute the local transaction and obtains the first execution result, which includes the execution success result and the execution failure result. If the transaction initiator executes the local transaction successfully, the execution success result is obtained; if the transaction initiator fails to execute the local transaction, the execution failure result is obtained. The transaction initiator reports the first execution result to the message processing system.
[0103] The message processing system updates the state information of the transaction message in the message buffer pool according to the first execution result. In this embodiment, if the first execution result is a successful execution result, the state information of the transaction message in the message buffer pool is modified from the initialization state to the ready state, and the next action is performed according to the message state of the transaction message. If the first execution result is a failed execution result, the transaction message is rolled back.
[0104] Optionally, in another embodiment, if the first execution result is an execution failure result, the transaction message of the application transaction stored in the message buffer pool is cleared so that the transaction initiator can re-initiate the start request of the application transaction to execute the transaction message processing of the application transaction.
[0105] In one embodiment, the step S230 of delivering the transaction message in a ready state to the transaction coordinator according to the state information of the transaction message so that the transaction coordinator processes the corresponding local transaction may include the following steps:
[0106] S2301. According to the status information of the transaction message, the associated sub-transaction in the ready state is captured from the message buffer pool and published to the message channel, so that the transaction collaborator subscribed to the message channel performs local transaction processing according to the associated sub-transaction and publishes the transaction processing result of the associated sub-transaction to the message channel.
[0107] In this embodiment, the message transmission between the message processing system and the transaction collaborator can be performed through the Redis publish and subscribe mechanism. Redis provides publish and subscribe functions, which can be used for message transmission. The Redis publish and subscribe mechanism includes three parts: publisher, subscriber and message channel. The publisher publishes the message to a message channel, and the subscriber who subscribes to this message channel can receive the message.
[0108] In this step, the message processing system is the publisher and the transaction collaborator is the subscriber. The message processing system publishes each associated sub-transaction message of the ready transaction message to the message channel according to the message status of the transaction message. The transaction collaborator subscribes to the message channel and can receive the transaction message in the ready state from the message channel to process the corresponding associated sub-transaction.
[0109] In one embodiment, obtaining the second execution result obtained by the transaction collaborator in processing the local transaction in step S240 may include the following steps:
[0110] S2401. Subscribe to the second execution result of the associated sub-transaction published in the message channel by the transaction coordinator.
[0111] In this step, the transaction coordinator is the publisher and the message processing system is the subscriber. The transaction coordinator publishes the second execution result obtained by executing the corresponding associated sub-transaction to the message channel, and the message processing system subscribes to the message channel, so that it can receive the second execution result from the message channel.
[0112] It should be noted that multiple transaction collaborators respectively execute corresponding associated sub-transactions. Due to the different execution efficiency of different transaction collaborators, the time when each transaction collaborator publishes the second execution result to the message channel is also different, and the time when the message processing system receives the second execution result is also different, resulting in different message status update times for each associated sub-transaction in the message cache pool.
[0113] S2402: If it is determined according to the second execution result that the execution result of the associated sub-transaction executed by the transaction collaborator is successful, the message status corresponding to the associated sub-transaction is modified to a completed status, and the associated sub-transaction is marked.
[0114] If the transaction collaborator successfully executes the associated sub-transaction, the second execution result returned is the successful execution of the associated sub-transaction, the message status of the associated sub-transaction is modified to the execution success status, and it is marked as "completed" execution; otherwise, the second execution result returned is the failed execution of the associated sub-transaction, the message status of the associated sub-transaction is modified to the execution failure status, and it is marked as "failed" execution.
[0115] In one embodiment, feeding back a second feedback message to the transaction initiator according to the second execution result in step S240 may include the following steps:
[0116] S2403. According to the marks of all associated sub-transactions corresponding to the transaction message, determine whether all associated sub-transactions are marked as preset results. If so, execute step S2404; otherwise, execute step S2405.
[0117] The message processing system periodically captures the marks of all associated sub-transactions corresponding to the transaction message, and determines whether the marks of all associated sub-transactions are marked as "completed".
[0118] S2404: Feedback a commit operation message to the transaction initiator to notify the transaction initiator to perform a commit operation on the application transaction.
[0119] If all associated subtransactions are marked as "completed", it means that all associated subtransactions of the transaction message are successfully executed and the data in the distributed application transaction is consistent. Then a commit operation message is fed back to the transaction initiator to notify the transaction initiator to perform the commit operation of the application transaction.
[0120] S2405. Feedback a rollback operation message to the transaction initiator and the transaction coordinator to perform a rollback operation on the transaction message.
[0121] If all the associated subtransactions are not marked as "completed", or some of the associated subtransactions are marked as "completed" and some are marked as "failed", it means that all the associated subtransactions of the transaction message are not successfully executed, and the data in the distributed application transaction is inconsistent. In this case, a rollback operation message is fed back to the transaction initiator and each transaction collaborator to roll back the transaction message and repeat the application transaction.
[0122] like Figure 4 As shown, Figure 4 : is another flow chart of a message processing method provided by an embodiment. The message processing method is executed in a message processing system. The execution steps of the message processing method are as follows:
[0123] S501: Receive a request to start an application transaction initiated by a transaction initiator.
[0124] S502: Determine whether the transaction message of the application transaction already exists in the message buffer pool. If so, execute step S503; otherwise, execute step S504.
[0125] In this embodiment, the transaction message identifier of the application transaction may be obtained, and whether the transaction message of the application transaction already exists in the message buffer pool may be determined based on the transaction message identifier.
[0126] S503: Refuse to receive the transaction message, and feedback transaction re-execution information.
[0127] If the transaction message of the application transaction already exists in the message buffer pool, the transaction message of the application transaction is refused to be received, and the transaction initiator is informed not to repeat the execution of the application transaction.
[0128] S504: Save the transaction message of the application transaction in the message buffer pool, and feed back a first reply message to the transaction initiator.
[0129] If the transaction message of the application transaction does not exist in the message buffer pool, the transaction message of the application transaction is received and the transaction message identifier is saved in the message buffer pool, the message state of the transaction message is initialized, and the transaction initiator is informed that the application transaction can be processed.
[0130] S505: Receive a first execution result obtained by the transaction initiator when executing the local associated sub-transaction according to the first feedback message.
[0131] The transaction initiator confirms, based on the first feedback message, that the local transaction of the application transaction can be processed, obtains a first execution result, and sends the first execution result to the message processing system.
[0132] S506. Determine whether the associated sub-transaction executed by the transaction initiator is successfully executed according to the first execution result. If so, execute step S507; otherwise, execute step S508.
[0133] If the first execution result is successful execution, it is determined that the associated subtransaction corresponding to the local transaction executed by the transaction initiator is successfully executed; if the first execution result is failed execution, it is determined that the associated subtransaction corresponding to the local transaction executed by the transaction initiator is failed execution.
[0134] S507: Change the message state corresponding to the associated subtransaction from the initialization state to the ready state.
[0135] If it is determined that the associated subtransaction executed by the transaction initiator is successfully executed, the message state corresponding to the associated subtransaction is changed from the initialization state to the ready state.
[0136] S508: Roll back the associated sub-transaction and clear the transaction message in the message buffer pool.
[0137] If it is determined that the associated subtransaction executed by the transaction initiator fails to execute, the associated subtransaction is rolled back and the transaction message in the message buffer pool is cleared.
[0138] S509: Capture the associated sub-transaction message in the ready state and publish it to the message channel, so that the transaction coordinator subscribing to the message channel executes the local associated sub-transaction.
[0139] Due to differences in execution efficiency, the message states corresponding to the associated sub-transactions in the message buffer pool may be different. In this embodiment, the associated sub-transaction messages in the ready state can be captured regularly and published to the message channel so that the transaction coordinator who subscribes to the message channel executes the local associated sub-transaction.
[0140] S510: Subscribe to the second execution result of the associated sub-transaction published by the transaction coordinator, modify the message state of the corresponding associated sub-transaction according to the second execution result, and mark it.
[0141] The transaction collaborator who subscribes to the message channel obtains the message status of the associated sub-transaction, and executes the local transaction corresponding to the associated sub-transaction according to the message status of the associated sub-transaction to obtain the second execution result. If the second execution result is successful execution, the message status of the corresponding associated sub-transaction is modified to successful execution and marked as "completed". If the second execution result is failed execution, the message status of the corresponding associated sub-transaction is modified to failed execution and marked as "failed".
[0142] S511. Determine whether the message status of all associated sub-transactions are marked as completed. If so, execute step S512; otherwise, execute step S513.
[0143] All associated sub-transactions that have been marked for the application transaction are captured, and it is determined whether all associated sub-transactions that have been marked are marked as "completed".
[0144] S512: Feedback a commit operation message to the transaction initiator to notify the transaction initiator to perform a commit operation on the application transaction.
[0145] If all associated sub-transactions are marked as "completed", it means that the distributed transaction data of each server node is consistent, and a commit operation message is fed back to the transaction initiator to notify the transaction initiator to perform the commit operation of the application transaction.
[0146] S513: Feedback a rollback operation message to the transaction initiator and all transaction collaborators to perform a rollback operation on the application transaction.
[0147] If all associated sub-transactions that have been marked are not all marked as "completed", it means that the distributed transaction data of each server node is inconsistent, and a rollback operation message is fed back to the transaction initiator and all transaction collaborators to roll back the application transaction.
[0148] The message processing method provided in this embodiment is applied to a message processing system. The message state of the transaction message is modified according to the execution results of the associated sub-transactions corresponding to the local transaction received by the transaction initiator and the transaction collaborator, and the execution behaviors of the transaction initiator and the transaction collaborator are controlled according to the message state, thereby ensuring the consistency of distributed transaction data. The main transaction thread corresponding to the transaction initiator is decoupled from the passive transaction thread corresponding to the transaction collaborator, thereby reducing the coupling degree of the distributed system, facilitating the maintenance of the subsequent system, and reducing the maintenance cost.
[0149] This technical solution also provides a distributed transaction processing system. Figure 5 It is a schematic diagram of the structure of a distributed transaction processing system provided by an embodiment.
[0150] like Figure 5 As shown, the distributed transaction processing system includes a message processing system and a business system; the message processing system is independent of the business system, and the business system includes a transaction initiator and a transaction collaborator;
[0151] The transaction initiator initiates a start request for an application transaction to the message processing system; in response to the start request, the message processing system saves the transaction message of the application transaction in a message buffer pool, initializes the message state of the transaction message, and feeds back a first reply message to the transaction initiator; the transaction initiator executes the local transaction according to the first reply message to obtain a first execution result; the message processing system receives the first execution result, modifies the state information of the transaction message in the message buffer pool from an initialization state to a ready state according to the first execution result, and transmits the transaction message in the ready state to the transaction coordinator according to the state information of the transaction message, so that the transaction coordinator processes the corresponding local transaction; the transaction coordinator processes the transaction message to obtain a second execution result; the message processing system obtains the second execution result, and feeds back a second reply message to the transaction initiator according to the second execution result; the transaction initiator commits or rolls back the application transaction according to the second reply message.
[0152] Further, in this embodiment, the message processing system may include a transaction message receiving module, a first message confirmation module, a second message confirmation module, a message buffer pool, a message sending module, and a message status maintenance module, etc. The transaction initiator may be a computing service module, and each transaction collaborator is a module involved in completing the corresponding application transaction, such as a storage service module, a network service module, or other modules, etc. The transaction initiator and each transaction collaborator cooperate to execute the local transaction to ensure the consistency of the application transaction data.
[0153] Specifically, according to business requirements, the transaction initiator initiates a request to start an application transaction to the message processing system.
[0154] The transaction message receiving module receives the start request of the application transaction, and verifies whether the application transaction has been initiated to the business processing system and stored in the message buffer pool according to the unique transaction message identifier corresponding to the application transaction. If it is determined through verification that the transaction message of the application transaction already exists in the message buffer pool, a first reply message is sent to the transaction initiator through the transaction message confirmation module. At this time, the content of the first reply message is to inform the transaction initiator that the application transaction has been processed and there is no need to repeat the application transaction. If it is determined through verification that the transaction message of the application transaction does not exist in the message buffer pool, the transaction message of the application transaction is stored in the message buffer pool, and the state of the transaction message is set to the initialization state. The first reply message is sent to the transaction initiator through the transaction message confirmation module. At this time, the content of the first reply message is to inform the transaction initiator that the message processing system has confirmed the acceptance of the processing request of the transaction message, and the next operation can be performed.
[0155] It should be noted that the application transaction can be divided into multiple associated sub-transactions. The transaction message of the application transaction corresponds to a unique transaction message identifier, and each associated sub-transaction corresponds to a unique associated sub-transaction message identifier. The associated sub-transactions include multiple execution types, such as addition, deletion, etc. The execution types of each associated sub-transaction can be different or the same.
[0156] The transaction initiator receives the first reply message sent by the first message confirmation module of the message processing system, and after obtaining confirmation information that the application transaction can be executed based on the first reply message, starts to execute the local transaction. Specifically, the application transaction can be divided into multiple associated sub-transactions, and each associated sub-transaction is executed in parallel locally to obtain a first execution result corresponding to each associated sub-transaction. The first execution result corresponding to each associated sub-transaction is sent to the message processing system. The message processing system modifies the status information of each associated sub-transaction in the message cache pool based on the received first execution result. Specifically, if the first execution result is a successful execution, the status of the associated sub-transaction is modified from the initialization state to the ready state. If the first execution result is a failed execution, the associated sub-transaction corresponding to the first execution result is rolled back.
[0157] The message status maintenance module in the message processing system periodically captures the transaction messages of the associated sub-transactions in the ready state stored in the message cache pool, and sends the transaction messages of the associated sub-transactions in the ready state to the Redis message channel through the message sending module. The Redis message channel sends and receives messages based on the publish and subscribe mechanism.
[0158] Each transaction collaborator subscribes to the transaction message of the associated sub-transaction published in the Redis message channel, performs local transaction processing according to the transaction message of each associated sub-transaction, obtains the second execution result, and publishes the second execution result to the Redis message channel.
[0159] The second message confirmation module subscribes to the second execution result of each associated sub-transaction published by the transaction collaborator to the Redis message channel, and modifies the status of the corresponding associated sub-transaction in the message cache pool according to the second execution result. If it is determined according to the second execution result that the associated sub-transaction is executed successfully, the status of the associated sub-transaction is modified to the execution completion status, and the associated sub-transaction is marked as completed; if it is determined according to the second execution result that the associated sub-transaction fails to execute, the status of the associated sub-transaction is modified to failure, and the associated sub-transaction is marked as failure.
[0160] The message status maintenance module periodically captures all associated sub-transactions to determine whether all associated sub-transactions are marked as completed. If so, the transaction initiator is notified that the application transaction can be committed. Otherwise, the transaction initiator and all transaction collaborators are notified to roll back the transaction.
[0161] The above examples are only used to assist in explaining the technical solution of the present disclosure, and the illustrated contents and specific processes involved do not constitute a limitation on the usage scenarios of the technical solution of the present disclosure.
[0162] The following is a detailed description of the relevant embodiments of the message processing device.
[0163] Figure 6 It is a structural diagram of a message processing device provided by an embodiment, and the message processing device can be executed in a message processing system.
[0164] like Figure 6 As shown, the message processing device 200 may include: a first feedback module 210, a state modification module 220, a message delivery module 230, and a second feedback module;
[0165] The first feedback module 210 is used to receive a start request of an application transaction initiated by a transaction initiator, save a transaction message of the application transaction in a message buffer pool in response to the start request, initialize the message state of the transaction message, and feed back a first reply message to the transaction initiator;
[0166] The state modification module 220 is used to receive a first execution result obtained by the transaction initiator executing the local transaction according to the first feedback message, and modify the state information of the transaction message in the message buffer pool from the initialization state to the ready state according to the first execution result;
[0167] A message delivery module 230, configured to deliver a transaction message in a ready state to a transaction coordinator according to the state information of the transaction message, so that the transaction coordinator processes the corresponding local transaction;
[0168] The second feedback module 240 is used to obtain the second execution result obtained by the transaction collaborator in processing the local transaction, and feedback a second feedback message to the transaction initiator according to the second execution result, so that the transaction initiator performs a commit or rollback operation according to the second feedback message.
[0169] The message processing device provided in this embodiment receives a start request of an application transaction initiated by a transaction initiator through a first feedback module, and feeds back a first report message to the transaction initiator; the state modification module modifies the state information of the transaction message to a ready state according to a first execution result obtained by the transaction initiator executing a local transaction; the message delivery module delivers the transaction message in the ready state to the transaction collaborator, so that the transaction collaborator processes the corresponding transaction message and feeds back a second execution result; the second feedback module feeds back a second report message to the transaction initiator according to the second execution result, so that the transaction initiator performs a commit or rollback operation, thereby ensuring the consistency of the distributed transaction processing results; since the message processing system is independent of the transaction initiator and the transaction collaborator, the coupling degree of the distributed transaction processing is reduced, which is beneficial to subsequent system maintenance and reduces the complexity and cost of system maintenance.
[0170] In a possible implementation, the start request carries a unique transaction message identifier corresponding to the application transaction; the application transaction includes at least one associated sub-transaction;
[0171] The first feedback module 210 includes: a message identifier acquisition unit and a message content storage unit; wherein the message identifier acquisition unit is used to obtain a transaction message identifier corresponding to the application transaction in response to the start request;
[0172] The message content storage unit is used to determine, based on the transaction message identifier, that the transaction message corresponding to the transaction message identifier does not exist in the message cache pool, then store the message content in the message cache pool, and set the message status of each associated sub-transaction corresponding to the message identifier to an initialization state; wherein the message content of the transaction message includes the transaction message identifier and the corresponding relationship between the transaction message identifier and at least one associated sub-transaction.
[0173] In a possible implementation, the state modification module 220 includes a ready state modification unit; wherein the ready state modification unit is used to determine, based on the first execution result, that the execution result of the associated sub-transaction executed by the transaction initiator is successful, and then modify the message state corresponding to the associated sub-transaction in the message buffer pool from the initialization state to the ready state.
[0174] In one possible implementation, the message delivery module 230 includes a message publishing unit; wherein the message publishing unit is used to capture the associated sub-transactions in a ready state from the message cache pool according to the status information of the transaction message and publish them to the message channel, so that the transaction collaborators who subscribe to the message channel perform local transaction processing according to the associated sub-transactions, and publish the transaction processing results of the associated sub-transactions to the message channel.
[0175] In a possible implementation, the second feedback module 240 includes an execution result subscription unit and a transaction marking unit; wherein the execution result subscription unit is used to subscribe to the second execution result obtained by executing the associated sub-transaction published by the transaction collaborator to the message channel; the transaction marking unit is used to determine that the execution result of the associated sub-transaction executed by the transaction collaborator is successfully executed based on the second execution result, then modify the message status corresponding to the associated sub-transaction to a completed status, and mark the associated sub-transaction.
[0176] In a possible implementation, the second feedback module 240 includes a marking judgment unit and a message feedback unit; wherein the marking judgment unit is used to judge whether all associated subtransactions are marked as preset results according to the marks of all associated subtransactions corresponding to the transaction message; the message feedback unit is used to feedback a commit operation message to the transaction initiator if all associated subtransactions are marked as preset results, so as to notify the transaction initiator to perform a commit operation on the application transaction; otherwise, feedback a rollback operation message to the transaction initiator and the transaction collaborator, so as to roll back the transaction message.
[0177] The message processing device of this embodiment can execute the message processing method shown in the previous embodiments of the present application. The implementation principle is similar and will not be repeated here.
[0178] Each module in the above message processing device can be implemented in whole or in part by software, hardware, or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute operations corresponding to each module above.
[0179] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Figure 7As shown. The computer device includes a processor, a memory and a network interface connected through a system bus. Among them, the processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The network interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a message processing method is implemented.
[0180] Those skilled in the art will understand that Figure 7 The structure shown in the figure is only a block diagram of a part of the structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than those shown in the figure, or combine certain components, or have a different arrangement of components.
[0181] In one embodiment, a computer device is provided, including a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the following steps when executing the computer program:
[0182] Receiving a start request of an application transaction initiated by a transaction initiator, saving a transaction message of the application transaction in a message buffer pool in response to the start request, initializing a message state of the transaction message, and feeding back a first reply message to the transaction initiator;
[0183] receiving a first execution result obtained by the transaction initiator executing the local transaction according to the first feedback message, and modifying the state information of the transaction message in the message buffer pool from the initialization state to the ready state according to the first execution result;
[0184] Delivering the transaction message in a ready state to the transaction coordinator according to the state information of the transaction message, so that the transaction coordinator processes the corresponding local transaction;
[0185] The second execution result obtained by the transaction collaborator in processing the local transaction is obtained, and a second feedback message is fed back to the transaction initiator according to the second execution result, so that the transaction initiator performs a commit or rollback operation according to the second feedback message.
[0186] In one embodiment, the start request carries a unique transaction message identifier corresponding to the application transaction; the application transaction includes at least one associated sub-transaction;
[0187] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0188] In response to a start request, a transaction message identifier corresponding to an application transaction is obtained; if it is determined based on the transaction message identifier that the transaction message corresponding to the transaction message identifier does not exist in a message cache pool, the message content is stored in the message cache pool, and the message status of each associated sub-transaction corresponding to the message identifier is set to an initialization state; wherein the message content of the transaction message includes the transaction message identifier and a corresponding relationship between the transaction message identifier and at least one associated sub-transaction.
[0189] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0190] If it is determined according to the first execution result that the execution result of the associated subtransaction executed by the transaction initiator is successful, the message state corresponding to the associated subtransaction in the message buffer pool is modified from the initialization state to the ready state.
[0191] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0192] According to the status information of the transaction message, the associated sub-transaction in the ready state is captured from the message buffer pool and published to the message channel, so that the transaction collaborator who subscribes to the message channel performs local transaction processing according to the associated sub-transaction and publishes the transaction processing result of the associated sub-transaction to the message channel.
[0193] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0194] Subscribe to the second execution result obtained by executing the associated sub-transaction published in the message channel by the transaction collaborator; determine according to the second execution result that the execution result of the associated sub-transaction executed by the transaction collaborator is successfully executed, then modify the message status corresponding to the associated sub-transaction to the completion status, and mark the associated sub-transaction.
[0195] In one embodiment, when the processor executes the computer program, the processor further implements the following steps:
[0196] According to the marks of all associated sub-transactions corresponding to the transaction message, determine whether all associated sub-transactions are marked as preset results. If so, a commit operation message is fed back to the transaction initiator to notify the transaction initiator to perform the commit operation of the application transaction; otherwise, a rollback operation message is fed back to the transaction initiator and transaction collaborators to roll back the transaction message.
[0197] In one embodiment, a computer readable storage medium is provided, on which a computer program is stored, and when the computer program is executed by a processor, the following steps are implemented:
[0198] Receiving a start request of an application transaction initiated by a transaction initiator, saving a transaction message of the application transaction in a message buffer pool in response to the start request, initializing a message state of the transaction message, and feeding back a first reply message to the transaction initiator;
[0199] receiving a first execution result obtained by the transaction initiator executing the local transaction according to the first feedback message, and modifying the state information of the transaction message in the message buffer pool from the initialization state to the ready state according to the first execution result;
[0200] Delivering the transaction message in a ready state to the transaction coordinator according to the state information of the transaction message, so that the transaction coordinator processes the corresponding local transaction;
[0201] The second execution result obtained by the transaction collaborator in processing the local transaction is obtained, and a second feedback message is fed back to the transaction initiator according to the second execution result, so that the transaction initiator performs a commit or rollback operation according to the second feedback message.
[0202] In one embodiment, the start request carries a unique transaction message identifier corresponding to the application transaction; the application transaction includes at least one associated sub-transaction;
[0203] When the computer program is executed by the processor, the following steps are also performed:
[0204] In response to a start request, a transaction message identifier corresponding to an application transaction is obtained; if it is determined based on the transaction message identifier that the transaction message corresponding to the transaction message identifier does not exist in a message cache pool, the message content is stored in the message cache pool, and the message status of each associated sub-transaction corresponding to the message identifier is set to an initialization state; wherein the message content of the transaction message includes the transaction message identifier and a corresponding relationship between the transaction message identifier and at least one associated sub-transaction.
[0205] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0206] If it is determined according to the first execution result that the execution result of the associated subtransaction executed by the transaction initiator is successful, the message state corresponding to the associated subtransaction in the message buffer pool is modified from the initialization state to the ready state.
[0207] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0208] According to the status information of the transaction message, the associated sub-transactions in the ready state are captured from the message buffer pool and distributed to the message channel, so that the transaction collaborators who subscribe to the message channel can perform local transaction processing according to the associated sub-transactions and publish the transaction processing results of the associated sub-transactions to the message channel.
[0209] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0210] Subscribe to the second execution result obtained by executing the associated sub-transaction published in the message channel by the transaction collaborator; determine according to the second execution result that the execution result of the associated sub-transaction executed by the transaction collaborator is successfully executed, then modify the message status corresponding to the associated sub-transaction to the completion status, and mark the associated sub-transaction.
[0211] In one embodiment, when the computer program is executed by a processor, the following steps are also implemented:
[0212] According to the marks of all associated sub-transactions corresponding to the transaction message, determine whether all associated sub-transactions are marked as preset results. If so, a commit operation message is fed back to the transaction initiator to notify the transaction initiator to perform the commit operation of the application transaction; otherwise, a rollback operation message is fed back to the transaction initiator and transaction collaborators to roll back the transaction message.
[0213] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to memory, storage, database or other media used in the embodiments provided in the present application can include non-volatile and / or volatile memory. Non-volatile memory can include read-only memory (ROM), programmable ROM (PROM), electrically programmable ROM (EPROM), electrically erasable programmable ROM (EEPROM) or flash memory. Volatile memory can include random access memory (RAM) or external cache memory. As an illustration and not limitation, RAM is available in many forms, such as static RAM (SRAM), dynamic RAM (DRAM), synchronous DRAM (SDRAM), double data rate SDRAM (DDRSDRAM), enhanced SDRAM (ESDRAM), synchronous link (Synchlink) DRAM (SLDRAM), memory bus (Rambus) direct RAM (RDRAM), direct memory bus dynamic RAM (DRDRAM), and memory bus dynamic RAM (RDRAM).
[0214] It should be understood that, although the various steps in the above-mentioned flow chart are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the above-mentioned figure may include a plurality of sub-steps or a plurality of stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these sub-steps or stages is not necessarily to be carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.
[0215] The technical features of the above embodiments may be combined arbitrarily. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0216] The above-mentioned embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the invention patent. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the patent of the present application shall be subject to the attached claims.
Claims
1. A message processing method, characterized in that: The method comprises: receiving a start request of an application transaction initiated by a transaction initiator, the start request carrying a unique transaction message identifier corresponding to the application transaction, the application transaction including at least one associated sub-transaction, obtaining a transaction message identifier corresponding to the application transaction in response to the start request, determining according to the transaction message identifier that a transaction message corresponding to the transaction message identifier does not exist in a message buffer pool, storing the transaction message in the message buffer pool, and setting a message state of each associated sub-transaction corresponding to the application transaction to an initialization state, wherein the message content of the transaction message includes: a transaction message identifier and a corresponding relationship between the transaction message identifier and the at least one associated sub-transaction, initializing the message state of the transaction message, and feeding back a first reply message to the transaction initiator; receiving a first execution result obtained by the transaction initiator executing the local transaction according to the first reply message, and modifying the state information of the transaction message in the message buffer pool from an initialization state to a ready state according to the first execution result; According to the status information of the transaction message, the associated sub-transaction in the ready state is captured from the message buffer pool and published to the message channel, so that the transaction collaborator subscribing to the message channel performs local transaction processing according to the associated sub-transaction and publishes the transaction processing result of the associated sub-transaction to the message channel; The second execution result obtained by the transaction collaborator in processing the local transaction is obtained, and a second feedback message is fed back to the transaction initiator according to the second execution result, so that the transaction initiator performs a commit or rollback operation according to the second feedback message.
2. The method according to claim 1, characterized in that The step of modifying the state information of the transaction message in the message buffer pool from the initialization state to the ready state according to the first execution result comprises: If it is determined according to the first execution result that the execution result of the associated subtransaction executed by the transaction initiator is successful, the message state corresponding to the associated subtransaction in the message buffer pool is modified from the initialization state to the ready state.
3. The method according to claim 1, characterized in that The step of obtaining the second execution result obtained by the transaction collaborator in processing the local transaction comprises: Subscribe to a second execution result obtained by executing the associated sub-transaction published by the transaction collaborator to the message channel; If it is determined according to the second execution result that the execution result of the associated sub-transaction executed by the transaction collaborator is successful, the message state corresponding to the associated sub-transaction is modified to a completed state, and the associated sub-transaction is marked.
4. The method according to claim 3, characterized in that The step of feeding back a second feedback message to the transaction initiator according to the second execution result so that the transaction initiator performs a commit or rollback operation according to the second feedback message includes: According to the marks of all associated subtransactions corresponding to the transaction message, it is determined whether all the associated subtransactions are marked as preset results. If so, a commit operation message is fed back to the transaction initiator to notify the transaction initiator to perform the commit operation of the application transaction; otherwise, a rollback operation message is fed back to the transaction initiator and the transaction collaborator to roll back the transaction message.
5. A message processing device, characterized in that: The device comprises: A first feedback module is configured to receive a start request of an application transaction initiated by a transaction initiator, wherein the start request carries a unique transaction message identifier corresponding to the application transaction, the application transaction includes at least one associated sub-transaction, obtain a transaction message identifier corresponding to the application transaction in response to the start request, determine according to the transaction message identifier that the transaction message corresponding to the transaction message identifier does not exist in a message cache pool, store the transaction message in the message cache pool, and set the message status of each associated sub-transaction corresponding to the application transaction to an initialization status, wherein the message content of the transaction message includes: a transaction message identifier and a corresponding relationship between the transaction message identifier and the at least one associated sub-transaction, initialize the message status of the transaction message, and feed back a first feedback message to the transaction initiator; A state modification module, configured to receive a first execution result obtained by the transaction initiator executing the local transaction according to the first reply message, and modify the state information of the transaction message in the message buffer pool from an initialization state to a ready state according to the first execution result; A message delivery module, used for capturing the associated sub-transaction in a ready state from the message buffer pool according to the state information of the transaction message and publishing it to the message channel, so that the transaction collaborator subscribing to the message channel performs local transaction processing according to the associated sub-transaction and publishes the transaction processing result of the associated sub-transaction to the message channel; The second feedback module is used to obtain the second execution result obtained by the transaction collaborator in processing the local transaction, and feedback a second feedback message to the transaction initiator according to the second execution result, so that the transaction initiator performs a commit or rollback operation according to the second feedback message.
6. A distributed transaction processing system, characterized in that: include: A message processing system and a business system, wherein the business system includes a transaction initiator and a transaction collaborator; The transaction initiator initiates a start request for an application transaction to the message processing system, wherein the start request carries a unique transaction message identifier corresponding to the application transaction, and the application transaction includes at least one associated sub-transaction; The message processing system obtains the transaction message identifier corresponding to the application transaction in response to the start request, determines according to the transaction message identifier that the transaction message corresponding to the transaction message identifier does not exist in the message cache pool, stores the transaction message in the message cache pool, and sets the message status of each associated sub-transaction corresponding to the application transaction to an initialization status, wherein the message content of the transaction message includes: the transaction message identifier and the corresponding relationship between the transaction message identifier and the at least one associated sub-transaction, initializes the message status of the transaction message, and feeds back a first reply message to the transaction initiator; The transaction initiator executes the local transaction according to the first reply message to obtain a first execution result; The message processing system receives the first execution result, modifies the state information of the transaction message in the message buffer pool from the initialization state to the ready state according to the first execution result, and fetches the associated sub-transaction in the ready state from the message buffer pool according to the state information of the transaction message and publishes it to the message channel, so that the transaction collaborator subscribing to the message channel performs local transaction processing according to the associated sub-transaction, and publishes the transaction processing result of the associated sub-transaction to the message channel; The transaction collaborator processes the transaction message to obtain a second execution result; The message processing system obtains the second execution result, and feeds back a second feedback message to the transaction initiator according to the second execution result; The transaction initiator commits or rolls back the application transaction according to the second reply message.
7. A computer device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, characterized in that: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 4 are implemented.
8. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 4 are implemented.
Citation Information
Patent Citations
Distributed transaction processing method and apparatus
CN106325978A
Queue message uniformity implementing method and device, equipment and storage medium
CN108009027A
