A method, device and storage medium for solving the problem of last-come-first-served in distributed application transactions
By using transaction flow table T1 and verification table T2 in distributed applications, it is ensured that the processing status of transaction requests is accurately recorded and queried, solving the problem of status inconsistency caused by transactions coming first, improving the efficiency of the verification interface and reducing the cost of transformation. Cost, applicable to all scenarios.
Patent Information
- Application Number
- CN202111436757.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-11-30
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2041-11-30
AI Technical Summary
In distributed applications, transactions come first, resulting in inconsistent transaction status between the channel end and the bank. Existing solutions cannot completely solve this problem, leading to the risk of business errors.
The transaction flow table T1 and the verification table T2 are used, and the transaction submission mechanism is inserted through the unique primary key to ensure that the processing status of the transaction request is accurately recorded and queried, and to avoid the problem of status inconsistency during congestion.
It effectively solves business errors caused by late-come first-come transactions in distributed systems, improves the efficiency of verification interfaces, and reduces transformation costs. It is applicable to all scenarios and covers state consistency in extreme situations.
Abstract
Description
Technical Field
[0001] The present invention relates to the field of information technology, and specifically provides a method, device and storage medium for solving the problem of last-come-first-served distributed application transactions. Background Art
[0002] This technology is mainly used in the field of Internet distributed microservice architecture. As a service provider, it is basically deployed on multiple machines. Due to network or machine resource problems, the consumer's request may be processed first by the service provider. If the system handles it improperly, it will inevitably bring certain impacts. This technology can solve the problem of late-coming-first-coming transactions in distributed applications, ensuring that consumers can obtain accurate transaction results.
[0003] Currently, banks cooperate with major Internet traffic platforms and connect through APIs. Banks are mainly responsible for the output of underlying products, while channels are responsible for front-end display and sales. Most channels cache transaction data and display local data when customers view it, reducing frequent interactions with banks and improving customer experience.
[0004] For a purchase transaction, the bank needs to provide two interfaces, one for purchase and one for verification. The current channel practice is to first call the purchase interface. If the interface times out, the verification interface is called periodically through the original serial number to obtain the final status of the transaction, thereby achieving the purpose of consistency with the bank's transaction status. As a service provider, if the verification interface receives and processes the same transaction serial number first, and then receives the purchase request, the verification interface will fail because it cannot find the original transaction, while the actual purchase transaction processing is successful, resulting in the problem that the transaction status recorded locally by the channel is inconsistent with that of the bank.
[0005] We call this problem of verification arriving before the transaction "latest sent, first arrived". There are two main solutions for the current channel: one is to verify 10 minutes (configurable) after the channel transaction request is sent, on the premise that the transaction request cannot be received after 10 minutes; the other is to return a special error code in the verification interface for the serial number of the transaction request that has not been received. The channel continues to verify the error code. If the error code is still returned after more than 2 hours, it will be considered a failure. Neither of these two solutions can perfectly solve the problem. In extreme cases, there is still a risk of inconsistent status between the two parties.
[0006] To facilitate understanding of technical issues, here is an example:
[0007] The channel party sends a transaction request S containing a unique transaction serial number N to the distributed application. In the distributed application, after one of the application nodes A receives the request, if this application node A is blocked, the data of the transaction request sent by the channel party will not be processed and will not be written into the transaction flow table of the distributed application. When the request processing sent by the channel party times out, the channel party will initiate a verification request containing the transaction serial number N to the distributed application after a fixed interval to confirm the transaction processing status. At this time, after the distributed application node B receives the request, it searches for data in the transaction flow table according to the transaction serial number N. Because the transaction serial number N cannot be found in the transaction flow table in the distributed flow, the distributed application will return "failure" to the channel party. On the other hand, when the congestion of application node A ends and the transaction request S is completed, the processing status of the transaction request S in the distributed application is actually "successful", and then the verification result returned to the channel is "failure", which will cause the last send to arrive first, resulting in business errors.
[0008] It is worth noting that when the channel initiates a verification containing a unique primary key (serial number), if the corresponding data cannot be found through the unique primary key in the distributed microservice application, there may be two situations. First, the transaction corresponding to the unique primary key (serial number) may not exist. At this time, the verification result "failure" can be returned. Second, the transaction corresponding to the unique primary key (serial number) may not have been written due to congestion, but the transaction actually exists. At this time, if the verification result "failure" is returned, it will be contrary to the actual situation, because when the congestion disappears, the transaction is very likely to be executed "successfully", but the verification returns "failure", which is contrary to the actual situation and causes business errors. Summary of the invention
[0009] The purpose of the present invention is to solve the problem that the distributed system is latecomers but arrives first, thus causing business errors.
[0010] In order to solve the above technical problems, the present invention adopts the following technical means:
[0011] A method for solving the problem of last-come-first-served in distributed application transactions, comprising a transaction flow table T1, a verification table T2,
[0012] When the distributed microservice application is not blocked:
[0013] When the distributed microservice application receives a transaction request containing a unique primary key initiated by the channel end, the microservice application processes the unique primary key insertion transaction submission, inserts data information containing the unique primary key into the transaction flow table T1 and the insertion verification table T2 for subsequent application calls and execution, and updates the execution result field of the verification table T2 with the transaction request execution result "success" or "failure" as a constraint using the unique field, and returns the transaction request execution result "success" or "failure" to the channel end. When the connection between the channel end and the distributed microservice application times out, the channel end will initiate a verification request containing the unique primary key to the distributed microservice application because it obtains the transaction request execution result returned by the distributed microservice application. The distributed microservice application uses the unique primary key to determine the value of the execution result field of the transaction request in the verification table T2, and returns the value of the execution result field to the channel end.
[0014] When a distributed microservice application is blocked:
[0015] When the distributed microservice application receives a transaction request containing a unique primary key from the channel end, the microservice application will be stuck waiting for the unique primary key insertion transaction to be submitted, so it cannot insert data containing the unique primary key into the transaction flow table T1 and the insertion verification table T2 for the subsequent application to call and execute, until the connection between the channel end and the distributed microservice application times out. Because the channel end gets the transaction request execution result returned by the distributed microservice application, the channel end will initiate a verification request containing the unique primary key to the distributed microservice application. The distributed microservice application will insert the unique primary key in the verification table T2 according to the unique primary key. When searching for data, the unique primary key cannot be found because the verification table T2 does not contain data containing the unique primary key. The distributed microservice application returns "failure" to the channel end and writes the unique primary key and the result of "failure" into the verification table T2. When the distributed microservice application ends the congestion and performs the unique primary key insertion transaction, the unique primary key already exists in the verification table T2, so the unique primary key insertion into the verification table T2 will fail, and the unique primary key will not be inserted into the transaction flow table T1, and the transaction request will not be called and executed by the subsequent application, that is, the transaction request containing the unique primary key fails.
[0016] In the above technical solution, the unique primary key insertion transaction refers to:
[0017] Inserting the unique primary key into the transaction flow table T1 and inserting the unique primary key and transaction request processing status into the verification table T2 are committed in the same transaction. In the same transaction, if any of the insertion of the unique primary key into the transaction flow table T1 and the insertion into the verification table T2 fails, the unique primary key will not be inserted into either the transaction flow table T1 or the verification table T2.
[0018] The present invention also provides a device for solving the problem of late send first arrive in distributed application transactions, comprising a database module, wherein the database module is provided with a transaction flow table T1, a verification table T2,
[0019] It also includes a business non-blocking processing module. When the distributed microservice application is not blocked:
[0020] When the distributed microservice application receives a transaction request containing a unique primary key initiated by the channel end, the microservice application processes the unique primary key insertion transaction submission, inserts data information containing the unique primary key into the transaction flow table T1 and the insertion verification table T2 for subsequent application calls and execution, and updates the execution result field of the verification table T2 with the transaction request execution result "success" or "failure" as a constraint using the unique field, and returns the transaction request execution result "success" or "failure" to the channel end. When the connection between the channel end and the distributed microservice application times out, the channel end will initiate a verification request containing the unique primary key to the distributed microservice application because it obtains the transaction request execution result returned by the distributed microservice application. The distributed microservice application uses the unique primary key to determine the value of the execution result field of the transaction request in the verification table T2, and returns the value of the execution result field to the channel end.
[0021] It also includes a business congestion processing module. When a distributed microservice application is congested:
[0022] When the distributed microservice application receives a transaction request containing a unique primary key from the channel end, the microservice application will be stuck waiting for the unique primary key insertion transaction to be submitted, so it cannot insert data containing the unique primary key into the transaction flow table T1 and the insertion verification table T2 for the subsequent application to call and execute, until the connection between the channel end and the distributed microservice application times out. Because the channel end gets the transaction request execution result returned by the distributed microservice application, the channel end will initiate a verification request containing the unique primary key to the distributed microservice application. The distributed microservice application will insert the unique primary key in the verification table T2 according to the unique primary key. When searching for data, the unique primary key cannot be found because the verification table T2 does not contain data containing the unique primary key. The distributed microservice application returns "failure" to the channel end and writes the unique primary key and the result of "failure" into the verification table T2. When the distributed microservice application ends the congestion and performs the unique primary key insertion transaction, the unique primary key already exists in the verification table T2, so the unique primary key insertion into the verification table T2 will fail, and the unique primary key will not be inserted into the transaction flow table T1, and the transaction request will not be called and executed by the subsequent application, that is, the transaction request containing the unique primary key fails.
[0023] In the above technical solution, the unique primary key insertion transaction refers to:
[0024] Inserting the unique primary key into the transaction flow table T1 and inserting the unique primary key and transaction request processing status into the verification table T2 are committed in the same transaction. In the same transaction, if any of the insertion of the unique primary key into the transaction flow table T1 and the insertion into the verification table T2 fails, the unique primary key will not be inserted into either the transaction flow table T1 or the verification table T2.
[0025] The present invention also provides a storage medium, which stores a program for solving the problem of last send first arrive in distributed application transactions. When a processor executes the program, a method for solving the problem of last send first arrive in distributed application transactions is implemented.
[0026] Because the present invention adopts the above technical means, it has the following beneficial effects:
[0027] 1. The present invention effectively solves the problem that when the distributed system is blocked, the distributed microservice application cannot process the request initiated by the channel end in time, and when the channel end initiates verification, a return result contrary to the actual situation will be obtained.
[0028] 2. This application proposal realizes small transformation on the existing business system, low cost, wide application scope, no new transactions and no need to lock the table, almost no impact on the original transaction performance, and covers all scenarios. While solving the problem of last-come-first-served, it also improves the efficiency of the verification interface. The original verification interface logic is to query the original transaction flow table according to the channel serial number, and then assemble the message to return. There will be various logical judgments for different transaction types. After adopting this technical proposal, the verification interface only needs to query the verification table, which is separated from the business logic and is applicable to the verification of all transactions. DETAILED DESCRIPTION
[0029] The following is a detailed description of the embodiments of the present invention. Although the present invention will be described and illustrated in conjunction with some specific embodiments, it should be noted that the present invention is not limited to these embodiments. On the contrary, modifications or equivalent substitutions made to the present invention should all be included in the scope of the claims of the present invention.
[0030] In addition, in order to better illustrate the present invention, numerous specific details are given in the following specific embodiments. It will be understood by those skilled in the art that the present invention can also be implemented without these specific details.
[0031] The general solution to the issue of transactions being sent last but arrived first is to make a unique judgment based on the channel serial number. If the verification interface receives it first and fails to find the original transaction, then the transaction interface will receive the channel serial number and directly return failure. The consumer needs to change the serial number and re-initiate the transaction.
[0032] A general business system will have an original transaction flow table T1, which is used to receive channel requests and record transaction status. To implement this solution, you only need to add a verification table T2 with the following fields: channel number, channel serial number, transaction status, return message, and last updated time (each operation is updated to the current date and time). The channel number and channel serial number are set as a joint primary key. The purpose of adding the channel number is to prevent different channels from using the same serial number.
[0033] The server-side transaction interface processing logic: receive channel serial number A, insert into tables T1 and T2, set the transaction status of A record in T2 to P-processing, and submit in the same transaction as T1 table. If the insertion is successful, it means that serial number A is received for the first time, and the subsequent business logic is executed. After the business logic is processed, the transaction status and return message of A record in T2 are updated to the final state, and submitted in the same transaction as the normal T1 table update; if the insertion fails, it means that serial number A has been received, catch the exception of primary key conflict, in this exception handling, query the A record of this serial number in table T2, if the "transaction status" is P, it will directly return to processing, otherwise take the "return message" field content to return.
[0034] The server verification interface processing logic: after receiving the request serial number A, first check whether the serial number exists in table T2. If it exists, directly return the content of the "return message" field. If it does not exist, insert it into table T2, set the transaction status to F-processing failure, and commit the transaction. If the insertion fails, it means that serial number A has been received, which may be inserted by the transaction interface or the last verification interface. Similarly, catch the exception of primary key conflict. In this exception processing, first query the record of serial number A in table T1. If the "transaction status" is P, it will directly return to processing, otherwise return the content of the "return message" field.
[0035] At this point, we simulate three trading scenarios that are prone to problems:
[0036] The service provider first receives the verification request A, but does not find record A in the verification table T2, which means that the original transaction has not been received, or the original transaction has not been sent at all. At this time, a failure is returned. After the original transaction is received later, a failure is directly returned through the T2 table record, ensuring that the verification and transaction return status are consistent;
[0037] The service provider receives the transaction and verification request A at the same time. If the transaction interface inserts table T2 successfully first, the verification interface will fail to insert. At this time, if the transaction has not been processed, the verification will return to processing and wait for the next verification request. If the verification interface inserts table T2 successfully first, the verification interface will return the original transaction failure. The transaction interface will enter the exception processing of the insertion failure and directly return to the verification table status. The verification and transaction return status are consistent.
[0038] The service provider receives two requests with the same serial number at the same time. Only one of them will be successfully inserted into table T2, and the other will follow the insertion failure logic. If the first transaction has not been processed, the second transaction will return to being processed, and the channel will continue to go through the verification interface. If the first transaction is completed, the second transaction will return the result of the first transaction in an idempotent manner.
Claims
1. A method for solving the problem of last-come-first-served in distributed application transactions, characterized in that: Including transaction flow table T1, verification table T2, When the distributed microservice application is not blocked: When the distributed microservice application receives a transaction request containing a unique primary key initiated by the channel end, the microservice application processes the unique primary key insertion transaction submission, inserts data information containing the unique primary key into the transaction flow table T1 and the insertion verification table T2 for the subsequent application to call and execute, and updates the execution result field of the verification table T2 with the transaction request execution result "success" or "failure" with the unique field as the constraint, and returns the transaction request execution result "success" or "failure" to the channel end. When the connection between the channel end and the distributed microservice application times out, the channel end will initiate a verification request containing the unique primary key to the distributed microservice application because it obtains the transaction request execution result returned by the distributed microservice application. The distributed microservice application calculates the value of the execution result field of the transaction request in the verification table T2 based on the unique primary key, and returns the value of the execution result field to the channel end; When a distributed microservice application is blocked: When the distributed microservice application receives a transaction request containing a unique primary key from the channel end, the microservice application will be stuck waiting for the unique primary key insertion transaction to be submitted, so it cannot insert data containing the unique primary key into the transaction flow table T1 and the insertion verification table T2 for the subsequent application to call and execute, until the connection between the channel end and the distributed microservice application times out. Because the channel end gets the transaction request execution result returned by the distributed microservice application, the channel end will initiate a verification request containing the unique primary key to the distributed microservice application. The distributed microservice application will insert the unique primary key in the verification table T2 according to the unique primary key. The data is searched. At this time, because the verification table T2 does not contain data containing the unique primary key, the unique primary key cannot be found. The distributed microservice application returns "failure" to the channel end and writes the unique primary key and the result of "failure" into the verification table T2. When the distributed microservice application ends the blockage and performs the unique primary key insertion transaction, because the unique primary key already exists in the verification table T2, the unique primary key insertion into the verification table T2 will fail. As a result, the unique primary key will not be inserted into the transaction flow table T1, and the transaction request will not be called and executed by the subsequent application, that is, the transaction request containing the unique primary key fails to execute; A unique primary key insert transaction is: Inserting the unique primary key into the transaction flow table T1 and inserting the unique primary key and transaction request processing status into the verification table T2 are committed in the same transaction. In the same transaction, if any of the insertion of the unique primary key into the transaction flow table T1 and the insertion into the verification table T2 fails, the unique primary key will not be inserted into either the transaction flow table T1 or the verification table T2.
2. The device for solving the problem of last send first arrive in distributed application transactions according to claim 1, characterized in that: It includes a database module, which is provided with a transaction flow table T1, a verification table T2, It also includes a business non-blocking processing module. When the distributed microservice application is not blocked: When the distributed microservice application receives a transaction request containing a unique primary key initiated by the channel end, the microservice application processes the unique primary key insertion transaction submission, inserts data information containing the unique primary key into the transaction flow table T1 and the insertion verification table T2 for the subsequent application to call and execute, and updates the execution result field of the verification table T2 with the transaction request execution result "success" or "failure" with the unique field as the constraint, and returns the transaction request execution result "success" or "failure" to the channel end. When the connection between the channel end and the distributed microservice application times out, the channel end will initiate a verification request containing the unique primary key to the distributed microservice application because it obtains the transaction request execution result returned by the distributed microservice application. The distributed microservice application calculates the value of the execution result field of the transaction request in the verification table T2 based on the unique primary key, and returns the value of the execution result field to the channel end; It also includes a business congestion processing module. When a distributed microservice application is congested: When the distributed microservice application receives a transaction request containing a unique primary key from the channel end, the microservice application will be stuck waiting for the unique primary key insertion transaction to be submitted, so it cannot insert data containing the unique primary key into the transaction flow table T1 and the insertion verification table T2 for the subsequent application to call and execute, until the connection between the channel end and the distributed microservice application times out. Because the channel end gets the transaction request execution result returned by the distributed microservice application, the channel end will initiate a verification request containing the unique primary key to the distributed microservice application. The distributed microservice application will insert the unique primary key in the verification table T2 according to the unique primary key. The data is searched. At this time, because the verification table T2 does not contain data containing the unique primary key, the unique primary key cannot be found. The distributed microservice application returns "failure" to the channel end and writes the unique primary key and the result of "failure" into the verification table T2. When the distributed microservice application ends the blockage and performs the unique primary key insertion transaction, because the unique primary key already exists in the verification table T2, the unique primary key insertion into the verification table T2 will fail. As a result, the unique primary key will not be inserted into the transaction flow table T1, and the transaction request will not be called and executed by the subsequent application, that is, the transaction request containing the unique primary key fails to execute; A unique primary key insert transaction is: Inserting the unique primary key into the transaction flow table T1 and inserting the unique primary key and transaction request processing status into the verification table T2 are committed in the same transaction. In the same transaction, if any of the insertion of the unique primary key into the transaction flow table T1 and the insertion into the verification table T2 fails, the unique primary key will not be inserted into either the transaction flow table T1 or the verification table T2.
3. A storage medium, characterized in that: The storage medium stores a program for solving the problem of last send first arrive in distributed application transactions. When the processor executes the program, the method for solving the problem of last send first arrive in distributed application transactions as claimed in claim 1 is implemented.
