Method, apparatus, device and computer-readable medium for controlling transaction consistency
By parsing and processing the service node identification and status of failed outbound transactions to be corrected, synchronous correction is achieved, which solves the problem of poor consistency of microservices in distributed transactions and improves the overall consistency and reliability of the system.
Patent Information
- Application Number
- CN202110753456.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-07-02
- Publication Date
- 2024-10-22
- Estimated Expiration
- 2041-07-02
AI Technical Summary
In distributed transaction processing, existing technology cannot effectively guarantee the consistency between multiple microservices, resulting in incomplete correction processing, partial success and partial failure, affecting the atomicity and consistency of the overall system.
By parsing outbound call failed transactions to be corrected, the service node identification is obtained, and processing is performed based on the transaction type and status to achieve synchronized correction processing in multiple microservices to ensure the final consistency of the transaction.
It improves the consistency between multiple microservices, reduces the complexity of manual processing of transaction inconsistencies, simplifies business logic, reduces repeated coding and business coupling, and improves the overall reliability of the system.
Smart Images

Figure CN113486033B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of big data technology, and in particular to a method, device, equipment and computer-readable medium for controlling transaction consistency. Background Art
[0002] For a transaction system, a complete account transaction request may consist of multiple microservices. If the transaction fails, the atomicity of the multiple microservices as a whole, that is, the overall consistency, must be guaranteed.
[0003] In the logic of processing distributed transactions, exception handling is added to each outbound call microservice. For example, if a transaction requires outbound calls to microservices a, b, and c, then exception logic is added when calling microservices a, b, and c. Because it is a distributed system, network fluctuations between servers are unavoidable, and outbound call timeouts and other abnormal situations often occur, which need to be corrected.
[0004] In the process of implementing the present invention, the inventors found that there are at least the following problems in the prior art: the correction process cannot guarantee the success of the correction, and there are partial successes and partial failures, which leads to poor consistency between multiple microservices. Summary of the invention
[0005] In view of this, embodiments of the present invention provide a method, apparatus, device and computer-readable medium for controlling transaction consistency, which can improve the consistency between multiple microservices.
[0006] To achieve the above object, according to one aspect of an embodiment of the present invention, a method for controlling transaction consistency is provided, comprising:
[0007] Parse the outbound call failed transaction to be reversed, and obtain the service node identifier of the outbound call failed transaction to be reversed;
[0008] According to the type of the outbound call failed transaction to be reversed and the service node identifier, query the status of the outbound call failed transaction to be reversed;
[0009] The outbound call failure transaction to be reversed is processed based on the status to synchronize the outbound call failure transaction to be reversed in multiple microservices.
[0010] The parsing of the outbound call failure transaction to be reversed to obtain the service node identifier of the outbound call failure transaction to be reversed includes:
[0011] Based on the identifier of the outbound call failed transaction to be reversed, a service node identifier of the outbound call failed transaction to be reversed is obtained.
[0012] The querying the status of the outbound call failed transaction to be reversed according to the type of the outbound call failed transaction to be reversed and the service node identifier includes:
[0013] In the transaction corresponding to the service node identifier, the status of the outbound call failed transaction to be reversed is queried according to the type of the outbound call failed transaction to be reversed.
[0014] The querying the status of the outbound call failed transaction to be reversed according to the type of the outbound call failed transaction to be reversed and the service node identifier includes:
[0015] According to the external reversal request, determining that the type of the outbound call failed transaction to be reversal is an external reversal;
[0016] Based on the global reversal serial number in the external reversal request, the transaction status of the serial number corresponding to the service node identifier is queried to obtain the status of the outbound call failed transaction to be reversal.
[0017] The processing of the outbound call failure transaction to be reversed based on the status to synchronize the outbound call failure transaction to be reversed in multiple microservices includes:
[0018] Based on the status, it is known that the outbound call failure transaction to be reversed has failed or has been reversed, and then a reversal success flag is sent to synchronize the outbound call failure transaction to be reversed in multiple microservices.
[0019] The processing of the outbound call failure transaction to be reversed based on the status to synchronize the outbound call failure transaction to be reversed in multiple microservices includes:
[0020] Based on the status, it is known that the outbound call failure transaction to be reversed has been successful, and the local reversal is successful, then a reversal success flag is sent to synchronize the outbound call failure transaction to be reversed in multiple microservices.
[0021] The processing of the outbound call failure transaction to be reversed based on the status to synchronize the outbound call failure transaction to be reversed in multiple microservices includes:
[0022] Based on the status, it is known that the outbound call failure transaction to be reversed has been successful, and the local execution of the reversal has failed, then a reversal reprocessing flag is sent to synchronize the outbound call failure transaction to be reversed in multiple microservices.
[0023] The processing of the outbound call failure transaction to be reversed based on the status to synchronize the outbound call failure transaction to be reversed in multiple microservices includes:
[0024] If it is known based on the status that the outbound call failure transaction to be reversed has not occurred, a reversal failure flag is sent to synchronize the outbound call failure transaction to be reversed in multiple microservices.
[0025] The querying the status of the outbound call failed transaction to be reversed according to the type of the outbound call failed transaction to be reversed and the service node identifier includes:
[0026] According to the internal reversal request, determining that the type of the outbound call failed transaction to be reversed is internal reversal;
[0027] Based on the internal reversal request, the status of the outbound call failure transaction to be reversal is obtained, and the status of the outbound call failure transaction to be reversal includes at least one outbound call microservice failure among multiple outbound call microservices, and the outbound call of the microservice in the first outbound call sequence among the multiple outbound call microservices is successful.
[0028] The processing of the outbound call failure transaction to be reversed based on the status to synchronize the outbound call failure transaction to be reversed in multiple microservices includes:
[0029] Based on the state, if the failed outbound call microservice in multiple outbound call microservices is successfully reconciled, the outbound call failed transaction to be reconciled is sent successfully, and the outbound call failed transaction to be reconciled in multiple microservices is synchronized.
[0030] The processing of the outbound call failure transaction to be reversed based on the status to synchronize the outbound call failure transaction to be reversed in multiple microservices includes:
[0031] Based on the state, if the outbound call microservice that failed in multiple outbound call microservices fails to be reconciled, then sending the outbound call failure to be reconciled transaction fails, then performing asynchronous reconciliation to synchronize the outbound call failure to be reconciled transactions in multiple microservices.
[0032] The method further comprises:
[0033] Among the outbound call transactions to be corrected, select the outbound call failed transactions to be corrected;
[0034] Based on the reversal order of the outbound call failure transactions to be reversal, reversal processing is performed on the microservices in the outbound call failure transactions to be reversal one by one.
[0035] The reversal processing of the microservices in the outbound call failure transaction to be reversal one by one includes:
[0036] The microservices in the outbound call failure transaction to be corrected are corrected one by one. If each microservice is successfully corrected, a transaction failure message is fed back.
[0037] The reversal processing of the microservices in the outbound call failure transaction to be reversal one by one includes:
[0038] The microservices in the outbound call failure to be reversed transaction are reversed one by one. If the reversal of one microservice fails, asynchronous reversal is performed.
[0039] The reversal order is the reverse order of the outbound call microservices in the outbound call failure to be reversal transaction.
[0040] The asynchronous reversal includes asynchronously reversing outbound calls that have failed and require reversal of transactions through an asynchronous reversal table.
[0041] The outbound call transactions to be corrected are screened out as outbound call failed transactions to be corrected, including:
[0042] Among the outbound call transactions to be corrected, the outbound call failed transactions to be corrected are screened out periodically.
[0043] According to a second aspect of an embodiment of the present invention, there is provided a device for controlling transaction consistency, including:
[0044] A parsing module, used for parsing the outbound call failed transaction to be reversed, and obtaining the service node identifier of the outbound call failed transaction to be reversed;
[0045] A status module, used for querying the status of the outbound call failure transaction to be reversed according to the type of the outbound call failure transaction to be reversed and the service node identifier;
[0046] A synchronization module is used to process the outbound call failure transaction to be reversed based on the status to synchronize the outbound call failure transaction to be reversed in multiple microservices.
[0047] According to a third aspect of an embodiment of the present invention, there is provided an electronic device for controlling transaction consistency, including:
[0048] one or more processors;
[0049] a storage device for storing one or more programs,
[0050] When the one or more programs are executed by the one or more processors, the one or more processors implement the above method.
[0051] According to a fourth aspect of an embodiment of the present invention, there is provided a computer-readable medium on which a computer program is stored, and when the program is executed by a processor, the method as described above is implemented.
[0052] An embodiment of the above invention has the following advantages or beneficial effects: parsing the outbound call failure transaction to be reconciled to obtain the service node identifier of the outbound call failure transaction to be reconciled; querying the status of the outbound call failure transaction to be reconciled according to the type of the outbound call failure transaction to be reconciled and the service node identifier; processing the outbound call failure transaction to be reconciled based on the status to synchronize the outbound call failure transaction to be reconciled in multiple microservices. Since the outbound call failure transaction to be reconciled can be processed in a timely manner, the consistency between multiple microservices can be improved.
[0053] The further effects of the above-mentioned non-conventional optional manner will be described below in conjunction with the specific implementation manner. BRIEF DESCRIPTION OF THE DRAWINGS
[0054] The accompanying drawings are used to better understand the present invention and do not constitute an improper limitation of the present invention.
[0055] Figure 1 is a schematic diagram of the main process of a method for controlling transaction consistency according to an embodiment of the present invention;
[0056] Figure 2 is a flow chart of querying the status of a transaction to be reversed for a failed outbound call according to an embodiment of the present invention;
[0057] Figure 3 is another flowchart of querying the status of a transaction to be reversed for a failed outbound call according to an embodiment of the present invention;
[0058] Figure 4 is a schematic diagram of a process of external correction according to an embodiment of the present invention;
[0059] Figure 5 is a schematic diagram of the process of internal correction according to an embodiment of the present invention;
[0060] Figure 6 is a schematic diagram of a synchronous correction process according to an embodiment of the present invention;
[0061] Figure 7 is a schematic diagram of the main structure of a device for controlling transaction consistency according to an embodiment of the present invention;
[0062] Figure 8 is an exemplary system architecture diagram to which embodiments of the present invention may be applied;
[0063] Fig. 9 It is a schematic diagram of the structure of a computer system of a terminal device or a server suitable for implementing an embodiment of the present invention. DETAILED DESCRIPTION
[0064] The following is a description of exemplary embodiments of the present invention in conjunction with the accompanying drawings, including various details of the embodiments of the present invention to facilitate understanding, which should be considered as merely exemplary. Therefore, it should be recognized by those of ordinary skill in the art that various changes and modifications may be made to the embodiments described herein without departing from the scope and spirit of the present invention. Similarly, for clarity and conciseness, the description of well-known functions and structures is omitted in the following description.
[0065] The atomicity of the entire microservice refers to the overall consistency. Specifically, an accounting operation consists of microservices a, b, and c. If microservices a, b, and c are called, they must either all succeed or all fail. Microservices a, b, and c may be developed with multiple components and deployed on different servers, so some transactions may succeed while others fail. If not all transactions are successful, the partially successful transactions need to be reversed to ensure overall atomicity. Therefore, it is essential to support reversal operations in a distributed system architecture and maintain eventual consistency between multiple microservices.
[0066] When consistency cannot be guaranteed, inconsistent transaction data can only be processed manually, which makes the overall reversal too complicated. Moreover, if there are too many branch transactions, the business logic is often more complicated, there is too much repeated coding, the coupling between businesses is also increasing, and the expected final consistency results are not satisfactory. Therefore, there is a technical problem of poor consistency between multiple microservices.
[0067] Specifically, poor consistency between multiple microservices can be caused by the following situations.
[0068] Case 1:
[0069] The positive transaction logic of each transaction and the reversal logic after the positive transaction fails are highly coupled. The abnormal reversal is captured immediately when the positive transaction fails, and the transaction logic is chaotic.
[0070] Case 2:
[0071] The reversal logic for most transactions is similar. For each transaction, the correct transaction is processed first and then the reversal is processed if there is an exception. There are too many similar codes for repeated outbound calls and reversals.
[0072] In order to solve the technical problem of poor consistency between multiple microservices, the following technical solution in the embodiment of the present invention can be adopted.
[0073] See also Figure 1 , Figure 1 Schematic diagram of the main process of the method for controlling transaction consistency according to an embodiment of the present invention. Based on the status of the transaction to be reversed due to outbound call failure, the transaction to be reversed can be processed in time, and then the transaction synchronization is realized in multiple microservices. Figure 1 As shown, the specific steps include:
[0074] S101. Analyze the outbound call failure transaction to be reversed, and obtain the service node identifier of the outbound call failure transaction to be reversed.
[0075] When a positive transaction is processed, the basket number information of the positive transaction is recorded. In the case of a positive transaction failure, a reversal request message is constructed and the basket number information is added to the reversal request message. A positive transaction represents a positive transaction logic, which is a type of transaction developed to achieve a certain business effect. A reversal transaction is a type of transaction with a reverse logic to a positive transaction, which is a reverse transaction logic developed to eliminate the business effect of the positive transaction.
[0076] In an embodiment of the present invention, based on the identifier of the outbound call failure transaction to be reconciled, the service node identifier of the outbound call failure transaction to be reconciled is obtained. Specifically, based on the basket number information of the reconciliation request message of the outbound call failure transaction to be reconciled, the service node location of the outbound call failure transaction to be reconciled can be quickly addressed and found, and then the service node identifier of the outbound call failure transaction to be reconciled is determined according to the above service node location.
[0077] S102. Query the status of the outbound call failed transaction to be reversed according to the type of the transaction to be reversed and the service node identifier.
[0078] Outbound call failed transactions to be reversed can be divided into two types: external reversal and internal reversal. Internal reversal is initiated when the internal system identifies inconsistent transaction information. For example, when calling a downstream system transaction, a timeout is received or the first downstream service is successfully called, but the second downstream service fails. In the above cases, an internal reversal is initiated. In addition to similar scenarios to internal reversal, external reversal is a reversal initiated by the external system.
[0079] Among them, external correction involves external services, and internal correction involves internal services. External services refer to services of external systems, that is, services of the caller. Internal services refer to downstream services.
[0080] The status of the outbound call failure transaction to be reconciled is different for different types of outbound call failure transaction to be reconciled. Then, the status of the outbound call failure transaction to be reconciled can be queried in the transaction corresponding to the service node identifier according to the type of the outbound call failure transaction to be reconciled.
[0081] See also Figure 2 , Figure 2 The present invention is a flowchart of querying the status of a transaction to be reversed for an outbound call failure according to an embodiment of the present invention, which specifically includes the following steps:
[0082] S201. According to an external reversal request, determine that the type of the outbound call failed transaction to be reversed is an external reversal.
[0083] After receiving the external reversal request sent by the caller, it can be determined that the type of the outbound call failed transaction to be reversed is external reversal.
[0084] S202. Based on the global reversal serial number in the external reversal request, query the transaction status corresponding to the service node identifier to obtain the status of the outbound call failed transaction to be reversal.
[0085] The transaction status corresponding to the service node identifier includes the status of multiple reversal transactions. Based on the reversal global serial number in the external reversal request, the transaction status corresponding to the service node identifier can be queried to obtain the status of the transaction to be reversed due to the failed outbound call.
[0086] exist Figure 2 In the embodiment, when the type of the outbound call failed transaction to be reversed is external reversal, the status of the outbound call failed transaction to be reversed is obtained.
[0087] See also Figure 3 , Figure 3 The present invention is another flowchart of querying the status of a failed outbound call transaction to be reversed according to an embodiment of the present invention, which specifically includes the following steps:
[0088] S301. According to an internal reversal request, determine whether the type of the outbound call failed transaction to be reversed is an internal reversal.
[0089] After receiving the internal reversal request sent by the internal system, it can be determined that the type of the outbound call failed transaction to be reversed is internal reversal.
[0090] Internal reversal adopts real-time synchronous reversal and quasi-real-time asynchronous reversal. If there is inconsistency in the transaction, the reversal is initiated synchronously. If the reversal is successful, the transaction failure is returned; if the reversal fails, the unknown status is returned and the asynchronous process is entered.
[0091] S302. Based on the internal reversal request, obtain the status of the outbound call failure transaction to be reversal, where the status of the outbound call failure transaction to be reversal includes at least one outbound call microservice failure among multiple outbound call microservices, and the outbound call of the microservice in the first outbound call sequence among the multiple outbound call microservices is successful.
[0092] According to the internal reversal request, the status of the outbound call failure transaction to be reversal can be obtained. The reversal transaction includes multiple outbound call microservices, and the multiple outbound call microservices are executed sequentially. As an example, the reversal transaction includes a1, a2 and a 3, a total of three outbound call microservices. The above three outbound call microservices are executed in the order of a1, a2 and a 3. In the case of a1 outbound call failure, since a2 and a3 have not been executed, no reversal is required. It can be seen that when the microservice in the first outbound call sequence among multiple outbound call microservices succeeds in making an outbound call, and any other outbound call microservice fails, reversal is required, that is, the status of the outbound call failure transaction to be reversal needs to be obtained.
[0093] exist Figure 3In the embodiment, when the type of the outbound call failed transaction to be reversed is internal reversal, the status of the outbound call failed transaction to be reversed is obtained.
[0094] S103. Process the outbound call failure transactions to be corrected based on the status to synchronize the outbound call failure transactions to be corrected in multiple microservices.
[0095] In a distributed environment, consistency means that data can be kept consistent across multiple copies. When a system performs an update operation in a data-consistent state, it should ensure that the system data remains in a consistent state. In a distributed system, if all users can read the latest value of a data item after the update operation is successfully executed, then such a system is considered to have strong consistency.
[0096] In an embodiment of the present invention, outbound call failure transactions to be corrected are processed based on the state to synchronize outbound call failure transactions to be corrected in multiple microservices to achieve eventual consistency in multiple microservices. Eventual consistency emphasizes that all data copies in the system can eventually reach a consistent state after a period of synchronization.
[0097] In the embodiment of the present invention, for different types of outbound call failure transactions to be reversed, the following exemplary methods are used to process outbound call failure transactions to be reversed:
[0098] For external correction, there are four scenarios, namely, scenario A1, scenario A2, scenario A3 and scenario A4.
[0099] Scenario A1
[0100] The external service initiates a reversal transaction and queries the transaction status based on the global reversal serial number. Based on the transaction status, if the outbound call failure to be reversed transaction is known to have failed or has been reversal, a reversal success flag is sent. As an example, the reversal success return code 00 is directly returned to the caller, thereby synchronizing the outbound call failure to be reversal transactions in multiple microservices.
[0101] Scenario A2
[0102] The external service initiates a reversal transaction and queries the transaction status based on the global reversal serial number. Based on the transaction status, it is learned that the outbound call failed to be reversed transaction has been successful, and the local reversal is successful, so a reversal success flag is sent. As an example, the reversal success return code 00 is directly returned to the caller to inform the caller that the reversal has been successful, thereby synchronizing the outbound call failed to be reversed transactions in multiple microservices.
[0103] Scenario A3
[0104] The external service initiates a reversal transaction and queries the transaction status based on the global reversal serial number. Based on the transaction status, it is learned that the outbound call failed to be reversed transaction has been successful, and the local reversal failed, so the reversal reprocessing flag is sent. As an example, the reversal reprocessing flag 02 is directly returned to the caller to inform the caller that the reversal failure needs to be reprocessed, thereby synchronizing the outbound call failed to be reversed transactions in multiple microservices.
[0105] Scene A4
[0106] The external service initiates a reversal transaction and queries the transaction status of the reversal transaction according to the global reversal serial number. Based on the transaction status of the reversal transaction, it is learned that the outbound call failed to be reversed transaction has not occurred, and the reversal failure flag is sent. As an example, the reversal failure flag 02 is directly returned to the caller to inform the caller of the reversal failure. At the same time, a special reversal transaction is recorded. In this way, the outbound call failed to be reversed transactions in multiple microservices are synchronized.
[0107] See also Figure 4 , Figure 4 1 is a schematic diagram of the process of external correction according to an embodiment of the present invention, which specifically includes:
[0108] S401: External reversal request.
[0109] Received an external reversal request from the caller.
[0110] S402, traverse the flow.
[0111] According to the global transaction number of the reversal, traverse the transaction to query the transaction status.
[0112] S403, correction processing.
[0113] Reverse the failed outbound call transactions that need to be reversed.
[0114] S404: Determine whether there is any unflushed transaction water.
[0115] If there are still uncorrected transactions, the process returns to step S402; if there are no uncorrected transactions, the correction is completed.
[0116] There are four scenarios for internal correction, namely, Scenario B1, Scenario B2, Scenario B3 and Scenario B4.
[0117] If transaction a requires three outbound calls to microservices, namely a1, a2, and a3, the outbound call sequence is a1 first, then a2, and finally a3.
[0118] Scenario B1: a1, a2, and a3 all make successful outbound calls, indicating that the transaction is successful and the return is successful.
[0119] Scenario B2: a1 outbound call fails. In fact, a2 and a3 have not yet started to execute. This means that the transaction has failed and is atomic. The return failure does not need to be reversed.
[0120] It should be noted that no correction is required for scene B1 and scene B2.
[0121] Scenario B3: a1 and a2 make outbound calls successfully, but a3 fails. At this time, there is inconsistency and a1 and a2 need to be reversed. If the reversal is successful, it means that all transactions of a1, a2 and a3 have failed, and failure is returned.
[0122] That is to say, based on the status of the outbound call failure to be reversed transaction, if the failed outbound call microservice in multiple outbound call microservices is reversed successfully, the outbound call failure to be reversed transaction success is sent, and the outbound call failure to be reversed transactions in multiple microservices are synchronized.
[0123] Scenario B4: a1 and a2 make successful outbound calls, but a3 fails. At this time, there is inconsistency, and a1 and a2 need to be reversed. Then, they are reversed synchronously immediately. If the reversal fails, it means that there are successful transactions and failed transactions. At this time, the asynchronous reversal table is recorded, and the reversal will continue when the reversal record is scanned next time. At this time, it returns to unknown first, waiting for the reversal process to continue.
[0124] That is to say, based on the status of the outbound call failure to be reversed transaction, if the reversal of the failed outbound call microservice in multiple outbound call microservices fails, the outbound call failure to be reversed transaction fails, and asynchronous reversal is performed to synchronize the outbound call failure to be reversed transactions in multiple microservices.
[0125] During the internal reversal process, after the business logic is executed, determine whether there is an inconsistency based on the execution result. If there is no inconsistency, the business transaction is successful or failed as a whole. If it complies with atomicity and has no impact, no reversal is required, such as: Scenario B1. If there is an inconsistency, a synchronous reversal will be initiated immediately for the successful part of the transaction. If the reversal is successful, it means that the transaction as a whole has not been processed and the transaction failure is returned. For example: Scenario B3. If the reversal fails, the reversal table record is recorded and the transaction status is returned as unknown. Wait for the next scan of the reversal table record to continue reversing the transaction until it succeeds. For example: Scenario B4
[0126] See also Figure 5 , Figure 5 1 is a schematic diagram of the process of internal correction according to an embodiment of the present invention, which specifically includes:
[0127] S501: Internal reversal request.
[0128] Receive internal reversal requests sent by internal systems.
[0129] S502, outbound microservices are all successful.
[0130] If it is determined that all outbound call microservices are successful, no correction is required and the process ends; if it is determined that all outbound call microservices are not successful, correction is required and the process goes to S503.
[0131] S503, synchronous correction.
[0132] Synchronous reversal, outbound call failed and transaction to be reversal.
[0133] S504: Determine whether the reversal is successful.
[0134] If the reversal is successful, the process ends; if the reversal fails, asynchronous reversal is performed.
[0135] In one embodiment of the present invention, in order to improve the consistency between multiple microservices, active synchronous reversal can also be implemented for the screened outbound call failed transactions to be reversed.
[0136] See also Figure 6 , Figure 6 1 is a schematic diagram of a synchronous correction process according to an embodiment of the present invention, which specifically includes the following steps:
[0137] S601. Filter out outbound call failed transactions to be corrected from the outbound call transactions to be corrected.
[0138] Among multiple outbound call transactions to be reconciled, outbound call failed transactions to be reconciled are screened out to actively perform synchronous reconciliation. As an example, among the outbound call transactions to be reconciled, outbound call failed transactions to be reconciled are periodically screened out.
[0139] S602. Based on the reversal order of the outbound call failure transactions to be reversal, reversal processing is performed on the microservices in the outbound call failure transactions to be reversal one by one.
[0140] The transaction includes multiple outbound call microservices, and each outbound call microservice is executed in sequence. The reversal order is the reverse order of the outbound call microservices in the outbound call failure to be reversal transaction. In order to improve the efficiency of the reversal process, based on the reversal order of the outbound call failure to be reversal transaction, the microservices in the outbound call failure to be reversal transaction are reversal processed one by one.
[0141] In one embodiment of the present invention, the microservices in the outbound call failure transaction to be reversed are reversed one by one, and if each microservice is successfully reversed, a transaction failure message is fed back.
[0142] Accordingly, the microservices in the outbound call failed transaction to be corrected are corrected one by one. If one microservice fails to correct, asynchronous correction is performed to ensure that the normal execution of other transactions is not affected.
[0143] Specifically, asynchronous reversal includes asynchronously reversing outbound call failure transactions to be reversed through an asynchronous reversal table. The outbound call failure transactions to be reversed are recorded in the asynchronous reversal table, and asynchronous reversal is achieved when the asynchronous reversal conditions are met.
[0144] exist Figure 6 In the embodiment, the outbound call failure to be corrected is proactively corrected synchronously to improve the consistency between multiple microservices.
[0145] In the above-mentioned embodiment of the present invention, the outbound call failure transaction to be reconciled is parsed to obtain the service node identifier of the outbound call failure transaction to be reconciled; the status of the outbound call failure transaction to be reconciled is queried according to the type of the outbound call failure transaction to be reconciled and the service node identifier; the outbound call failure transaction to be reconciled is processed based on the status to synchronize the outbound call failure transaction to be reconciled in multiple microservices. Since the outbound call failure transaction to be reconciled can be processed in a timely manner, the consistency between multiple microservices can be improved.
[0146] In the actual transaction processing process, the combined transaction needs to call multiple microservices based on multiple sub-transactions. When executing the outbound call logic, the overall positive transaction logic and the reversal logic after the positive transaction fails are extracted separately, and the transaction flow details of each outbound call are recorded, including whether the outbound call is successful, etc. Then, the transactions that need to be reversed due to outbound call failure are analyzed separately for reversal processing to ensure consistency among multiple microservices.
[0147] See also Figure 7 , Figure 7 is a schematic diagram of the main structure of the device for controlling transaction consistency according to an embodiment of the present invention. The device for controlling transaction consistency can implement a method for controlling transaction consistency, such as Figure 7 As shown, the device for controlling transaction consistency specifically includes:
[0148] The parsing module 701 is used to parse the outbound call failure transaction to be reversed, and obtain the service node identifier of the outbound call failure transaction to be reversed;
[0149] A status module 702, configured to query the status of the outbound call failure transaction to be reversed according to the type of the outbound call failure transaction to be reversed and the service node identifier;
[0150] The synchronization module 703 is used to process the outbound call failure transaction to be reversed based on the status to synchronize the outbound call failure transaction to be reversed in multiple microservices.
[0151] In one embodiment of the present invention, the parsing module 701 is specifically configured to obtain a service node identifier of the outbound call failure transaction to be reversed based on an identifier of the outbound call failure transaction to be reversed.
[0152] In one embodiment of the present invention, the status module 702 is specifically used to query the status of the outbound call failure transaction to be reversed in the transaction corresponding to the service node identifier according to the type of the outbound call failure transaction to be reversed.
[0153] In one embodiment of the present invention, the state module 702 is specifically used to determine, according to the external reversal request, that the type of the outbound call failure transaction to be reversed is an external reversal;
[0154] Based on the global reversal serial number in the external reversal request, the transaction status of the serial number corresponding to the service node identifier is queried to obtain the status of the outbound call failed transaction to be reversal.
[0155] In one embodiment of the present invention, the synchronization module 703 is specifically used to obtain, based on the status, whether the outbound call failure transaction to be reversed has failed or has been reversed, and then send a reversal success mark to synchronize the outbound call failure transaction to be reversed in multiple microservices.
[0156] In one embodiment of the present invention, the synchronization module 703 is specifically used to obtain information based on the status that the outbound call failure to be reversed transaction has been successful, and the local execution of the reversal is successful, and then send a reversal success flag to synchronize the outbound call failure to be reversed transactions in multiple microservices.
[0157] In one embodiment of the present invention, the synchronization module 703 is specifically used to obtain, based on the status, that the outbound call failure transaction to be reversed has been successful, and if the local execution of the reversal fails, a reversal reprocessing flag is sent to synchronize the outbound call failure transaction to be reversed in multiple microservices.
[0158] In one embodiment of the present invention, the synchronization module 703 is specifically used to send a reversal failure flag to synchronize the outbound call failure reversal transactions in multiple microservices based on the status that the outbound call failure reversal transaction has not occurred.
[0159] In one embodiment of the present invention, the state module 702 is specifically used to determine, according to the internal reversal request, that the type of the outbound call failure transaction to be reversed is an internal reversal;
[0160] Based on the internal reversal request, the status of the outbound call failure transaction to be reversal is obtained, and the status of the outbound call failure transaction to be reversal includes at least one outbound call microservice failure among multiple outbound call microservices, and the outbound call of the microservice in the first outbound call sequence among the multiple outbound call microservices is successful.
[0161] In one embodiment of the present invention, the synchronization module 703 is specifically used to obtain, based on the status, that a failed outbound call microservice among multiple outbound call microservices is successfully reversal, and then send the outbound call failure to be reversal transaction successfully, and synchronize the outbound call failure to be reversal transactions in multiple microservices.
[0162] In one embodiment of the present invention, the synchronization module 703 is specifically used to obtain, based on the status, that if the reversal of a failed outbound call microservice in multiple outbound call microservices fails, then send the outbound call failure to be reversal transaction failure, and perform asynchronous reversal to synchronize the outbound call failure to be reversal transactions in multiple microservices.
[0163] In one embodiment of the present invention, the synchronization module 703 is further used to filter out outbound call failed transactions to be reversed from the outbound call transactions to be reversed;
[0164] Based on the reversal order of the outbound call failure transactions to be reversal, reversal processing is performed on the microservices in the outbound call failure transactions to be reversal one by one.
[0165] In one embodiment of the present invention, the synchronization module 703 is specifically used to perform reversal processing on the microservices in the outbound call failure transaction to be reversal one by one, and if each microservice is reversal successfully, a transaction failure message is fed back.
[0166] In one embodiment of the present invention, the synchronization module 703 is specifically used to perform reversal processing on the microservices in the outbound call failure to be reversal transaction one by one. If the reversal of one of the microservices fails, asynchronous reversal is performed.
[0167] In one embodiment of the present invention, the reversal order is the reverse order of the outbound call microservices in the outbound call failure to be reversal transaction.
[0168] In one embodiment of the present invention, the asynchronous reversal includes asynchronously reversing the failed outbound call transactions to be reversed through an asynchronous reversal table.
[0169] In one embodiment of the present invention, the synchronization module 703 is specifically used to periodically screen out outbound call failed transactions to be reversed from the outbound call transactions to be reversed.
[0170] Figure 8 An exemplary system architecture 800 is shown to which the method for controlling transaction consistency or the apparatus for controlling transaction consistency according to the embodiments of the present invention can be applied.
[0171] like Figure 8As shown, system architecture 800 may include terminal devices 801, 802, 803, a network 804, and a server 805. Network 804 is used to provide a medium for communication links between terminal devices 801, 802, 803 and server 805. Network 804 may include various connection types, such as wired, wireless communication links, or optical fiber cables, etc.
[0172] Users can use terminal devices 801, 802, and 803 to interact with server 805 through network 804 to receive or send messages, etc. Various communication client applications can be installed on terminal devices 801, 802, and 803, such as shopping applications, web browser applications, search applications, instant messaging tools, email clients, social platform software, etc. (only examples).
[0173] The terminal devices 801 , 802 , and 803 may be various electronic devices having a display screen and supporting web browsing, including but not limited to smart phones, tablet computers, laptop computers, desktop computers, and the like.
[0174] The server 805 may be a server that provides various services, such as a backend management server (only an example) that provides support for shopping websites browsed by users using the terminal devices 801, 802, and 803. The backend management server may analyze and process the received data such as product information query requests, and feed back the processing results (such as target push information, product information - only an example) to the terminal device.
[0175] It should be noted that the method for controlling transaction consistency provided in the embodiment of the present invention is generally executed by the server 805 , and accordingly, the device for controlling transaction consistency is generally set in the server 805 .
[0176] It should be understood that Figure 8 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.
[0177] Reference below Fig. 9 , which shows a schematic diagram of the structure of a computer system 900 of a terminal device suitable for implementing an embodiment of the present invention. Fig. 9 The terminal device shown is only an example and should not bring any limitation to the functions and scope of use of the embodiments of the present invention.
[0178] like Fig. 9As shown, the computer system 900 includes a central processing unit (CPU) 901, which can perform various appropriate actions and processes according to a program stored in a read-only memory (ROM) 902 or a program loaded from a storage part 908 into a random access memory (RAM) 903. In the RAM 903, various programs and data required for the operation of the system 900 are also stored. The CPU 901, the ROM 902, and the RAM 903 are connected to each other via a bus 904. An input / output (I / O) interface 905 is also connected to the bus 904.
[0179] The following components are connected to the I / O interface 905: an input section 906 including a keyboard, a mouse, etc.; an output section 907 including a cathode ray tube (CRT), a liquid crystal display (LCD), etc., and a speaker, etc.; a storage section 908 including a hard disk, etc.; and a communication section 909 including a network interface card such as a LAN card, a modem, etc. The communication section 909 performs communication processing via a network such as the Internet. A drive 910 is also connected to the I / O interface 905 as needed. A removable medium 911, such as a magnetic disk, an optical disk, a magneto-optical disk, a semiconductor memory, etc., is installed on the drive 910 as needed, so that a computer program read therefrom is installed into the storage section 908 as needed.
[0180] In particular, according to the embodiments disclosed in the present invention, the process described above with reference to the flowchart can be implemented as a computer software program. For example, the embodiments disclosed in the present invention include a computer program product, which includes a computer program carried on a computer-readable medium, and the computer program includes a program code for executing the method shown in the flowchart. In such an embodiment, the computer program can be downloaded and installed from the network through the communication part 909, and / or installed from the removable medium 911. When the computer program is executed by the central processing unit (CPU) 901, the above-mentioned functions defined in the system of the present invention are executed.
[0181] It should be noted that the computer-readable medium shown in the present invention may be a computer-readable signal medium or a computer-readable storage medium or any combination of the above two. The computer-readable storage medium may be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, device or device, or any combination of the above. More specific examples of computer-readable storage media may include, but are not limited to: an electrical connection with one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present invention, a computer-readable storage medium may be any tangible medium containing or storing a program that can be used by or in combination with an instruction execution system, device or device. In the present invention, a computer-readable signal medium may include a data signal propagated in a baseband or as part of a carrier wave, which carries a computer-readable program code. This propagated data signal may take a variety of forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. Computer-readable signal media may also be any computer-readable medium other than computer-readable storage media, which may send, propagate or transmit a program for use by or in conjunction with an instruction execution system, apparatus or device. The program code contained on the computer-readable medium may be transmitted using any appropriate medium, including but not limited to: wireless, wire, optical cable, RF, etc., or any suitable combination of the above.
[0182] The flow chart and block diagram in the accompanying drawings illustrate the possible architecture, function and operation of the system, method and computer program product according to various embodiments of the present invention. In this regard, each box in the flow chart or block diagram can represent a module, a program segment, or a part of a code, and the above-mentioned module, program segment, or a part of a code contains one or more executable instructions for realizing the specified logical function. It should also be noted that in some alternative implementations, the functions marked in the box can also occur in a different order from the order marked in the accompanying drawings. For example, two boxes represented in succession can actually be executed substantially in parallel, and they can sometimes be executed in the opposite order, depending on the functions involved. It should also be noted that each box in the block diagram or flow chart, and the combination of the boxes in the block diagram or flow chart can be implemented with a dedicated hardware-based system that performs a specified function or operation, or can be implemented with a combination of dedicated hardware and computer instructions.
[0183] The modules involved in the embodiments of the present invention may be implemented by software or hardware. The modules described may also be set in a processor, for example, they may be described as: a processor including a parsing module, a status module and a synchronization module. The names of these modules do not constitute a limitation on the modules themselves in certain cases. For example, the parsing module may also be described as "used to parse outbound call failure transactions to be corrected, and obtain the service node identifier of the outbound call failure transactions to be corrected".
[0184] As another aspect, the present invention further provides a computer-readable medium, which may be included in the device described in the above embodiment; or may exist independently without being assembled into the device. The above computer-readable medium carries one or more programs, and when the above one or more programs are executed by a device, the device includes:
[0185] Parse the outbound call failed transaction to be reversed, and obtain the service node identifier of the outbound call failed transaction to be reversed;
[0186] According to the type of the outbound call failed transaction to be reversed and the service node identifier, query the status of the outbound call failed transaction to be reversed;
[0187] The outbound call failure transaction to be reversed is processed based on the status to synchronize the outbound call failure transaction to be reversed in multiple microservices.
[0188] According to the technical solution of the embodiment of the present invention, the outbound call failure transaction to be corrected is parsed to obtain the service node identifier of the outbound call failure transaction to be corrected; the status of the outbound call failure transaction to be corrected is queried according to the type of the outbound call failure transaction to be corrected and the service node identifier; the outbound call failure transaction to be corrected is processed based on the status to synchronize the outbound call failure transaction to be corrected in multiple microservices. Since the outbound call failure transaction to be corrected can be processed in a timely manner, the consistency between multiple microservices can be improved.
[0189] The above specific implementations do not constitute a limitation on the protection scope of the present invention. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions may occur depending on design requirements and other factors. Any modification, equivalent substitution and improvement made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for controlling transaction consistency, characterized in that: include: Parse the outbound call failed transaction to be reversed, and obtain the service node identifier of the outbound call failed transaction to be reversed; According to the type of the outbound call failed transaction to be reversed and the service node identifier, query the status of the outbound call failed transaction to be reversed; Processing the outbound call failure transaction to be reversed based on the status to synchronize the outbound call failure transaction to be reversed in multiple microservices; The querying the status of the outbound call failed transaction to be reversed according to the type of the outbound call failed transaction to be reversed and the service node identifier includes: According to the external reversal request, determining that the type of the outbound call failed transaction to be reversal is an external reversal; Based on the global reversal serial number in the external reversal request, query the transaction status corresponding to the service node identifier to obtain the status of the outbound call failed transaction to be reversal; The querying the status of the outbound call failed transaction to be reversed according to the type of the outbound call failed transaction to be reversed and the service node identifier includes: According to the internal reversal request, determining that the type of the outbound call failure transaction to be reversed is an internal reversal; the internal reversal includes: calling a downstream system transaction, receiving a timeout or successfully calling the first downstream service, and failing the second downstream service; Based on the internal reversal request, the status of the outbound call failure transaction to be reversal is obtained, and the status of the outbound call failure transaction to be reversal includes at least one outbound call microservice failure among multiple outbound call microservices, and the outbound call of the microservice in the first outbound call sequence among the multiple outbound call microservices is successful.
2. The method for controlling transaction consistency according to claim 1, characterized in that: The parsing of the outbound call failure transaction to be reversed to obtain the service node identifier of the outbound call failure transaction to be reversed includes: Based on the identifier of the outbound call failed transaction to be reversed, a service node identifier of the outbound call failed transaction to be reversed is obtained.
3. The method for controlling transaction consistency according to claim 1, characterized in that: The querying the status of the outbound call failed transaction to be reversed according to the type of the outbound call failed transaction to be reversed and the service node identifier includes: In the transaction corresponding to the service node identifier, the status of the outbound call failed transaction to be reversed is queried according to the type of the outbound call failed transaction to be reversed.
4. The method for controlling transaction consistency according to claim 1, characterized in that: The processing of the outbound call failure transaction to be reversed based on the status to synchronize the outbound call failure transaction to be reversed in multiple microservices includes: Based on the status, it is known that the outbound call failure transaction to be reversed has failed or has been reversed, and then a reversal success flag is sent to synchronize the outbound call failure transaction to be reversed in multiple microservices.
5. The method for controlling transaction consistency according to claim 1, characterized in that: The processing of the outbound call failure transaction to be reversed based on the status to synchronize the outbound call failure transaction to be reversed in multiple microservices includes: Based on the status, it is known that the outbound call failure transaction to be reversed has been successful, and the local reversal is successful, then a reversal success flag is sent to synchronize the outbound call failure transaction to be reversed in multiple microservices.
6. The method for controlling transaction consistency according to claim 1, characterized in that: The processing of the outbound call failure transaction to be reversed based on the status to synchronize the outbound call failure transaction to be reversed in multiple microservices includes: Based on the status, it is known that the outbound call failure transaction to be reversed has been successful, and the local execution of the reversal has failed, then a reversal reprocessing flag is sent to synchronize the outbound call failure transaction to be reversed in multiple microservices.
7. The method for controlling transaction consistency according to claim 1, characterized in that: The processing of the outbound call failure transaction to be reversed based on the status to synchronize the outbound call failure transaction to be reversed in multiple microservices includes: If it is known based on the status that the outbound call failure transaction to be reversed has not occurred, a reversal failure flag is sent to synchronize the outbound call failure transaction to be reversed in multiple microservices.
8. The method for controlling transaction consistency according to claim 1, characterized in that: The processing of the outbound call failure transaction to be reversed based on the status to synchronize the outbound call failure transaction to be reversed in multiple microservices includes: Based on the state, if the failed outbound call microservice in multiple outbound call microservices is successfully reconciled, the outbound call failed transaction to be reconciled is sent successfully, and the outbound call failed transaction to be reconciled in multiple microservices is synchronized.
9. The method for controlling transaction consistency according to claim 1, characterized in that: The processing of the outbound call failure transaction to be reversed based on the status to synchronize the outbound call failure transaction to be reversed in multiple microservices includes: Based on the state, if the outbound call microservice that failed in multiple outbound call microservices fails to be reconciled, then sending the outbound call failure to be reconciled transaction fails, then performing asynchronous reconciliation to synchronize the outbound call failure to be reconciled transactions in multiple microservices.
10. The method for controlling transaction consistency according to claim 1, characterized in that: The method further comprises: Among the outbound call transactions to be corrected, select the outbound call failed transactions to be corrected; Based on the reversal order of the outbound call failure transactions to be reversal, reversal processing is performed on the microservices in the outbound call failure transactions to be reversal one by one.
11. The method for controlling transaction consistency according to claim 10, characterized in that: The reversal processing of the microservices in the outbound call failure transaction to be reversal one by one includes: The microservices in the outbound call failure transaction to be corrected are corrected one by one. If each microservice is successfully corrected, a transaction failure message is fed back.
12. The method for controlling transaction consistency according to claim 10, characterized in that: The reversal processing of the microservices in the outbound call failure transaction to be reversal one by one includes: The microservices in the outbound call failure to be remediated transaction are remediated one by one. If one microservice remediation fails, asynchronous remediation is performed.
13. The method for controlling transaction consistency according to claim 10, characterized in that: The reversal order is the reverse order of the outbound call microservices in the outbound call failure to be reversal transaction.
14. The method for controlling transaction consistency according to claim 9 or 12, characterized in that: The asynchronous reversal includes asynchronously reversing outbound calls that have failed and require reversal of transactions through an asynchronous reversal table.
15. The method for controlling transaction consistency according to claim 14, characterized in that: Among the outbound call transactions to be reversed, filter out the outbound call failed transactions to be reversed, including: Among the outbound call transactions to be corrected, the outbound call failed transactions to be corrected are screened out periodically.
16. A device for controlling transaction consistency, characterized in that: include: A parsing module, used for parsing the outbound call failed transaction to be reversed, and obtaining the service node identifier of the outbound call failed transaction to be reversed; A status module is used to query the status of the outbound call failure transaction to be reversed according to the type of the outbound call failure transaction to be reversed and the service node identifier; and, according to the external reversal request, determine that the type of the outbound call failure transaction to be reversed is an external reversal; based on the reversal global serial number in the external reversal request, query the transaction status corresponding to the service node identifier to obtain the status of the outbound call failure transaction to be reversed; And, according to the internal reversal request, determining that the type of the outbound call failure transaction to be reversed is an internal reversal; the internal reversal includes: calling a downstream system transaction, receiving a timeout or successfully calling the first downstream service, and failing the second downstream service; based on the internal reversal request, obtaining the status of the outbound call failure transaction to be reversed, the status of the outbound call failure transaction to be reversed includes at least one outbound call microservice failure among multiple outbound call microservices, and a microservice outbound call of the first outbound call sequence among multiple outbound call microservices is successful; A synchronization module is used to process the outbound call failure transaction to be reversed based on the status to synchronize the outbound call failure transaction to be reversed in multiple microservices.
17. An electronic device for controlling transaction consistency, characterized in that: include: one or more processors; a storage device for storing one or more programs, When the one or more programs are executed by the one or more processors, the one or more processors implement the method according to any one of claims 1 to 15.
18. A computer readable medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the method according to any one of claims 1 to 15 is implemented.
