TCC-based transaction processing methods, apparatuses, electronic devices, and storage media

By enabling independent transactions for transaction requests under the same account identifier during the trial phase of the TCC transaction mechanism, and performing account balance checks and reserved locks, the risk of transaction failure under the microservice architecture is resolved, and the smooth processing and independence of transactions are achieved.

CN119722312BActive Publication Date: 2025-11-14BEIJING PACTERA JINXIN TECH LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202411774412.0
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-12-04
Publication Date
2025-11-14
Estimated Expiration
2044-12-04

AI Technical Summary

Technical Problem

In a microservice architecture, the TCC transaction mechanism is prone to transaction failures due to insufficient account balance when processing batch transactions, and there is also a transaction risk.

Method used

For transaction requests under the same account identifier, an independent transaction is initiated during the TCC trial phase, and it is determined whether the account balance meets the transaction amount. The amount of the target transaction amount is reserved and locked, and the account balance is updated according to the target transaction amount during the confirmation phase.

Benefits of technology

By precisely reserving transaction amounts during the Try phase of TCC, the risk of reverting to the original state after a transaction failure is avoided, reducing the risk of transaction processing and ensuring the independence and smoothness of transaction requests.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119722312B_ABST
    Figure CN119722312B_ABST
Patent Text Reader

Abstract

This disclosure proposes a transaction processing method, apparatus, electronic device, and storage medium based on TCC. The method includes: acquiring at least two transaction requests under the same account identifier sent concurrently by the client; initiating an independent transaction for each transaction request; determining whether the account balance meets the transaction amount of the transaction request for which an independent transaction has been initiated; if there is a transaction request for which the account balance meets the transaction amount, reserving and locking the account balance for a target transaction amount, and using the transaction request for which the amount reservation and locking has been completed as the target transaction request; determining to respond to the target transaction request and updating the account balance of the corresponding account. Thus, independent transactions are initiated for each transaction request under the same account identifier, taking into account the possibility of transaction failure due to insufficient account balance, and achieving accurate reservation of transaction amount for transaction requests.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This disclosure relates to the field of transaction processing technology, and in particular to a transaction processing method, apparatus, electronic device and storage medium based on TCC. Background Technology

[0002] Currently, in microservice architectures, the TCC (Try, Confirm, Cancel) transaction mechanism is often used to ensure transaction consistency. The TCC transaction mechanism consists of three phases: the Try phase, the Confirm phase, and the Cancel phase.

[0003] In related technologies, the TCC transaction mechanism, in order to ensure atomicity in the processing of different transactions, requires the execution of Try, Confirm, and Cancel phases for each transaction. However, when a batch of transactions are received, the TCC transaction mechanism typically performs resource checks and reservations on all transactions concurrently during the Try phase, and then executes the transactions with reserved resources in the Confirm phase, deducting the reserved amount from the corresponding account balance. However, if there are cases where the account balance does not meet the sum of the reserved resources for a transaction, some transactions may fail. In the Cancel phase, regardless of whether the transaction was successful or failed, it is restored to its state before the transaction, causing the TCC-based batch processing of transactions to be disrupted and easily triggering transaction risks. Summary of the Invention

[0004] This disclosure provides a transaction processing method and apparatus based on TCC (Transaction Control Classification), to at least partially solve one of the technical problems in related technologies. The technical solution of this disclosure is as follows:

[0005] According to a first aspect of the present disclosure, a transaction processing method based on TCC is provided, comprising: acquiring at least two transaction requests under the same account identifier sent concurrently by a client; wherein the transaction request carries an account identifier of the account to be transacted and transaction information, the transaction information including at least a transaction amount; for each of the concurrently received transaction requests under the same account identifier, in the TCC trial phase, initiating an independent transaction for the transaction request; determining whether the account balance of the account corresponding to the transaction request with the initiated independent transaction meets the transaction amount of the transaction request; if there is a transaction request with an account balance that meets the transaction amount, reserving and locking the account balance for a target transaction amount, and using the transaction request with the completed amount reservation and locking as a target transaction request; wherein the target transaction amount represents the transaction amount corresponding to the transaction request; determining to respond to the target transaction request; and in the TCC confirmation phase, updating the account balance of the corresponding account according to the target transaction amount associated with the target transaction request.

[0006] According to a second aspect of the present disclosure, a transaction processing apparatus based on TCC is provided, comprising: a first acquisition module, configured to acquire at least two transaction requests under the same account identifier sent concurrently by a client; wherein the transaction request carries an account identifier of the account to be transacted and transaction information, the transaction information including at least a transaction amount; an initiation module, configured to, during the TCC trial phase, initiate an independent transaction for each of the concurrently received transaction requests under the same account identifier; and a judgment module, configured to determine the account identifier of the account corresponding to the transaction request for which the independent transaction has been initiated. The system determines whether the account balance meets the transaction amount of the transaction request. If there is an account balance that meets the transaction amount of the transaction request, the system reserves and locks the account balance for the target transaction amount, and uses the transaction request that has completed the amount reservation and locking as the target transaction request. The target transaction amount is used to represent the transaction amount corresponding to the transaction request. The first determining module is used to determine the response to the target transaction request, and during the TCC confirmation stage, updates the account balance of the corresponding account according to the target transaction amount associated with the target transaction request.

[0007] According to a third aspect of the present disclosure, an electronic device is provided, comprising: a processor; and a memory for storing processor-executable instructions; wherein the processor is configured to execute the instructions to implement the TCC-based transaction processing method as described in the first aspect of the present disclosure.

[0008] According to a fourth aspect of the present disclosure, a computer-readable storage medium is provided that, when instructions in the computer-readable storage medium are executed by a processor of an electronic device, enables the electronic device to perform a TCC-based transaction processing method as described in the first aspect of the present disclosure.

[0009] According to a fifth aspect of the present disclosure, a computer program product is provided, comprising: a computer program that, when executed by a processor, implements the TCC-based transaction processing method as described in the first aspect of the present disclosure.

[0010] The technical solutions provided by the embodiments of this disclosure have at least the following beneficial effects:

[0011] In this technical solution, at least two transaction requests under the same account identifier sent concurrently by the client are obtained. Each transaction request carries the account identifier of the account to be transacted and transaction information, including at least the transaction amount. For each transaction request received concurrently under the same account identifier, an independent transaction is initiated for the transaction request during the TCC trial phase. It is determined whether the account balance of the account corresponding to the transaction request with the initiated independent transaction meets the transaction amount of the transaction request. If there is a transaction request with an account balance that meets the transaction amount, the account balance is reserved and locked for a target transaction amount, and the transaction request with the completed amount reservation and locking is used as the target transaction request. The target transaction amount represents the transaction amount corresponding to the transaction request. The target transaction request is responded to, and during the TCC confirmation phase, the account balance of the corresponding account is updated according to the target transaction amount associated with the target transaction request. Therefore, by initiating independent transactions for at least two transaction requests under the same account identifier during the TCC Try phase, the possibility of insufficient account balance triggering the subsequent Confirm phase is considered. In the event of a failed transaction, the Try phase precisely reserves the transaction amount for transaction requests under the same account identifier. This avoids the situation in the Cancel phase where, regardless of whether the transaction was successful or failed, it is necessary to restore the transaction to its previous state, which could prevent smooth response to transaction requests in a microservice architecture and reduce the risk of transaction processing. Specifically, when determining whether the account balance of the account corresponding to a transaction request that has started an independent transaction meets the transaction amount, for each transaction request, the determination is made according to the order in which the independent transactions were started. Although the transaction requests are received simultaneously, there may be issues of late-arriving or early-arriving for different transaction requests that started independent transactions. Since the transaction requests are obtained in batches, the determination of whether the account balance meets the transaction amount is implemented step by step based on the order in which the independent transactions were started, avoiding the disorder of the transaction mechanism and ensuring the independence between different transaction requests.

[0012] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description

[0013] The above and / or additional aspects and advantages of this disclosure will become apparent and readily understood from the following description of the embodiments taken in conjunction with the accompanying drawings, in which:

[0014] Figure 1 This is a flowchart illustrating the TCC-based transaction processing method shown in the first embodiment of this disclosure;

[0015] Figure 2 This is a flowchart illustrating the TCC-based transaction processing method shown in the second embodiment of this disclosure;

[0016] Figure 3 This is a flowchart illustrating the TCC-based transaction processing method according to the third embodiment of this disclosure;

[0017] Figure 4 This is a schematic diagram of the structure of a TCC-based transaction processing device as shown in the fourth embodiment of this disclosure;

[0018] Figure 5 This is a schematic diagram of the structure of an electronic device shown in an exemplary embodiment of the present disclosure. Detailed Implementation

[0019] To enable those skilled in the art to better understand the technical solutions of this disclosure, the technical solutions in the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings.

[0020] It should be noted that the terms "first," "second," etc., used in the specification, claims, and accompanying drawings of this disclosure are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of this disclosure described herein can be implemented in orders other than those illustrated or described herein. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.

[0021] It should be noted that the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved in the technical solution disclosed herein are all carried out with the consent of the user, and all comply with the provisions of relevant laws and regulations, and do not violate public order and good morals.

[0022] To address the aforementioned issues, this disclosure proposes a transaction processing method and apparatus based on TCC.

[0023] The TCC-based transaction processing method and apparatus of this disclosure are described below with reference to the accompanying drawings.

[0024] Figure 1 This is a flowchart illustrating the TCC-based transaction processing method provided in the first embodiment of this disclosure.

[0025] like Figure 1As shown, this TCC-based transaction processing method includes the following steps:

[0026] Step 101: Obtain at least two transaction requests under the same account identifier sent by the client in parallel; wherein, the transaction request carries the account identifier of the account to be traded and transaction information, and the transaction information includes at least the transaction amount.

[0027] It should be noted that the TCC-based transaction processing method provided in this application embodiment can be executed by a TCC-based transaction processing device (also referred to as a TCC-based transaction processor), which can be implemented by software and / or hardware. The TCC-based transaction processing device can be an electronic device or can be configured within an electronic device to implement TCC-based transaction processing functionality. This application embodiment uses an example of the TCC-based transaction processing method being configured within an electronic device for illustration.

[0028] Among them, electronic devices can be any device with computing capabilities, such as personal computers, mobile terminals, servers, etc. Mobile terminals can be hardware devices with various operating systems, touch screens and / or displays, such as in-vehicle devices, mobile phones, tablets, personal digital assistants, wearable devices, etc.

[0029] It should be noted that the specific number of transaction requests obtained is determined according to the actual needs of the client, and this embodiment does not impose a specific limit.

[0030] In addition, it should be noted that for different transaction requests, the account identifier of the account to be traded may be different or the same.

[0031] For example, three transaction requests sent by the client in parallel are obtained, namely transaction request A, transaction request B, and transaction request C. Assume that transaction request A carries the account identifier A of the account to be traded, transaction request B carries the account identifier A of the account to be traded, and transaction request C carries the account identifier B of the account to be traded. Among them, the account identifiers carried by transaction request A and transaction request B are the same, while the account identifiers carried by transaction request C are different from those carried by transaction request A and transaction request B.

[0032] Step 102: For each transaction request received in parallel under the same account identifier, during the TCC trial phase, an independent transaction is initiated for the transaction request.

[0033] Independent transactions: In the current TCC distributed transaction, a separate transaction is started for each transaction request under the same account identifier.

[0034] It is important to understand that when there are multiple transaction requests, in addition to the transaction requests under the same account identifier, there are other transaction requests that are being processed. In order to avoid the disruption of the transaction mechanism caused by multiple concurrent transaction processing, an independent transaction is opened for each transaction request under the same account identifier. Then, it is determined whether the account balance of the account corresponding to the transaction request that has opened an independent transaction meets the transaction amount of the transaction request.

[0035] In this example, for each transaction request that has started an independent transaction, the corresponding transaction record is inserted into the transaction database associated with the transaction request.

[0036] It should be noted that the transaction record is used to represent the account identifier, transaction amount, and transaction status, which is updated to "in transit".

[0037] It should be noted that different transaction requests can be associated with the same transaction database.

[0038] To accurately determine the transaction records to be inserted into the transaction database associated with a transaction request that initiates an independent transaction, one possible implementation is to insert the corresponding transaction records into the transaction database associated with the transaction request based on the account identifier carried in the transaction request and the transaction amount contained in the transaction information.

[0039] As an example, the order in which independent transactions were initiated for each transaction request is obtained. For each transaction request that has initiated an independent transaction, the corresponding transaction record is inserted into the transaction database associated with the transaction request, based on the account identifier carried in the transaction request and the transaction amount included in the transaction information, according to the order in which the independent transactions were initiated for each transaction request.

[0040] It is understandable that in a transaction database, the transaction status of a transaction record can be represented by a field. For example, "0" indicates that the transaction status of the record is "in transit" and "1" indicates that the record is "completed".

[0041] In essence, the transaction status of a transaction record indicates the specific progress of a corresponding transaction request during processing. For example, during the processing of a transaction request, for common transaction amounts, the transaction status includes: Pending Payment: The transaction is being processed, but the transaction amount has not yet been paid; Completed: The transaction has been completed, including the payment of the transaction amount; Cancelled: The transaction has been cancelled for some reason.

[0042] In this example, the transaction status is indicated as "in transit" to show that the corresponding transaction request is being processed and the transaction amount has not yet been paid.

[0043] Step 103: Determine whether the account balance of the account corresponding to the transaction request that has started an independent transaction meets the transaction amount of the transaction request. If there is a transaction request with an account balance that meets the transaction amount, reserve and lock the account balance for the target transaction amount, and take the transaction request that has completed the amount reservation and locking as the target transaction request.

[0044] It is understood that the target transaction amount is used to represent the transaction amount corresponding to the transaction request.

[0045] In order to accurately distinguish the transaction requests that have a greater impact on whether the transaction request is successfully responded to from at least two transaction requests, and to better implement accurate transaction amount reservation for transaction requests in the Try phase, as an example, the transaction status of the transaction record corresponding to the transaction request is updated.

[0046] For example, in the Try phase, for transaction request A and transaction request B that have started independent transactions under the same account identifier A, the corresponding transaction records are inserted into the transaction database associated with transaction request A and transaction request B. Transaction request A corresponds to transaction record A, and transaction request B corresponds to transaction record B. In the Try phase, the transaction status of transaction request A is updated to "in transit", and the transaction status of transaction request B is updated to "in transit".

[0047] Step 104: Determine the response to the target transaction request, and during the TCC confirmation phase, update the account balance of the corresponding account based on the target transaction amount associated with the target transaction request.

[0048] It's important to understand that when multiple transaction requests exist, the determination of whether the account balance corresponding to the account identifier meets the transaction amount of the transaction request will affect the determination of whether the account balance meets the transaction amount of subsequent transaction requests, even if the account balance has already been determined to meet the transaction amount. Therefore, it is not possible to simply determine whether the account balance meets the transaction amount of each transaction request and compare the account balance with the transaction amount of each transaction request one by one. This would prevent the accurate reservation of transaction amount for transaction requests under the same account identifier during the Try phase, resulting in transaction requests being judged as failing during the Cancel phase.

[0049] To prevent the transaction records corresponding to successfully responded transaction requests in the transaction database from affecting the determination of transaction results for subsequently received transaction requests, as an example, in the case of responding to a target transaction request, during the TCC confirmation phase, the target transaction record corresponding to the target transaction request is determined by searching the transaction records inserted into the transaction database based on the account identifier corresponding to the target transaction request, and the transaction status of the target transaction record is updated to "completed".

[0050] To determine the updated account balance of the account to be traded, as an example, based on the transaction amount and account identifier carried in the target transaction request, the transaction amount is deducted from the account balance of the account corresponding to the account identifier to determine the updated account balance.

[0051] In summary, the system retrieves at least two transaction requests under the same account identifier sent concurrently by the client. Each transaction request carries the account identifier of the account to be transacted and transaction information, including at least the transaction amount. For each transaction request received concurrently under the same account identifier, during the TCC trial phase, an independent transaction is initiated for each transaction request. The system then determines whether the account balance corresponding to the transaction request with the initiated independent transaction meets the transaction amount requirement. If a transaction request exists with an account balance that meets the transaction amount requirement, the account balance is reserved and locked for the target transaction amount. The transaction request with the completed reservation and locking is then used as the target transaction request. The target transaction amount represents the transaction amount corresponding to the transaction request. Finally, the system determines the response. The target transaction request, and in the TCC confirmation phase, the account balance of the corresponding account is updated according to the target transaction amount associated with the target transaction request. Thus, by starting independent transactions for at least two transaction requests under the same account identifier in the TCC Try phase, the possibility of transaction failure due to insufficient account balance in the subsequent Confirm phase is taken into account. The transaction amount is accurately reserved for transaction requests under the same account identifier in the Try phase, thereby avoiding the situation in the Cancel phase where, regardless of whether the transaction request is judged as successful or failed, it is necessary to restore to the state before the transaction request, which would prevent the smooth response of transaction requests in the microservice architecture and reduce the risk of transaction processing.

[0052] To clearly illustrate how the above embodiments determine whether the account balance of the account corresponding to the transaction request that has started an independent transaction meets the transaction amount of the transaction request, and if there is a transaction request with an account balance that meets the transaction amount, the account balance is reserved and locked for the target transaction amount, and the transaction request that has completed the amount reservation and locking is used as the target transaction request, this disclosure proposes another transaction processing method based on TCC.

[0053] Figure 2 This is a flowchart illustrating the TCC-based transaction processing method shown in the second embodiment of this disclosure.

[0054] like Figure 2 As shown, the TCC-based transaction processing method includes the following steps:

[0055] Step 201: Obtain at least two transaction requests under the same account identifier sent by the client in parallel; wherein, the transaction request carries the account identifier of the account to be traded and transaction information, and the transaction information includes at least the transaction amount.

[0056] Step 202: For each transaction request received in parallel under the same account identifier, during the TCC trial phase, an independent transaction is initiated for the transaction request.

[0057] It should be noted that the execution process of steps 201 to 202 can be implemented in any of the embodiments of this disclosure. This disclosure does not limit this and will not elaborate further.

[0058] Step 203: Obtain the time sequence of requests to start independent transactions for the transaction transactions.

[0059] It is important to understand that although transaction requests under the same account identifier are received concurrently, in practice there may be issues of later requests arriving first or earlier requests arriving later. Therefore, there is a time sequence for starting independent transactions for transaction requests. Consequently, the insertion of transaction records into the transaction database associated with the transaction requests also has a time sequence issue, meaning that the insertion of transaction records into the transaction database has a time sequence.

[0060] For example, at 23:59:56 on March 5, 2024, a transaction request A with account identifier A is received. Then, at 23:59:57 on March 5, 2024, a transaction request B with account identifier A is received. Since the two transaction requests are received at close times, there may be a situation where an independent transaction is initiated for transaction request A first, and then for transaction request B. According to the order in which transaction requests A and B are initiated, the corresponding transaction record A is inserted into the transaction database associated with the transaction request A, which has already initiated an independent transaction, and then the corresponding transaction record B is inserted into the transaction database associated with the transaction request B, which has already initiated an independent transaction. Therefore, there is a time order in which transaction records A and B are inserted into the transaction database.

[0061] Step 204: Determine the account balance of the account corresponding to the account identifier based on the account identifier carried in the transaction request.

[0062] It is understandable that transaction requests under the same account identifier correspond to the same account balance.

[0063] Step 205: For each transaction request that has started an independent transaction, determine whether the account balance meets the transaction amount of the transaction request according to the order in which the independent transaction requests were started. Then, determine the target transaction request from at least two transaction requests received in parallel under the same account identifier.

[0064] In some examples, if there is a transaction request where the account balance does not meet the transaction amount, the transaction record corresponding to the transaction request where the account balance does not meet the transaction amount will be deleted from the transaction database.

[0065] It's important to understand that, because each independent transaction request must be initiated in chronological order, it's cumbersome to check whether the account balances under the same account identifier meet the transaction amount requirements and to reserve and lock account balances accordingly. Therefore, to simplify the process and save time, before checking each account balance against the transaction amount requirements in chronological order, we can first check whether the sum of the transaction amounts in each account balance meets the transaction amount requirements. If it does, then it's unnecessary to check each account balance against the transaction amount of the first transaction record and to reserve and lock account balances accordingly.

[0066] Therefore, as an example, the sum of the transaction amounts of the transaction requests is calculated to determine the total transaction amount; it is then determined whether the account balance meets the total transaction amount. If the account balance meets the total transaction amount, each transaction request is taken as the target transaction request.

[0067] For example, there are three transaction requests: Transaction Request A, Transaction Request B, and Transaction Request C. The transaction amount for Transaction Request A is 100, the transaction amount for Transaction Request B is 160, and the transaction amount for Transaction Request C is 140. For each transaction request, the account identifier corresponding to Transaction Request A, Transaction Request B, and Transaction Request C is account identifier A. The account balance of the account A to be traded corresponding to account identifier A is 600. First, the sum of the transaction amounts of Transaction Request A, Transaction Request B, and Transaction Request C is calculated, and the total transaction amount is determined to be 400 = 100 + 160 + 120. It is then judged whether the account balance (600) meets the total transaction amount (400). If the total transaction amount (400) is less than the account balance (600), then Transaction Request A, Transaction Request B, and Transaction Request C are all target transaction records.

[0068] Step 206: Determine the response to the target transaction request, and during the TCC confirmation phase, update the account balance of the corresponding account based on the target transaction amount associated with the target transaction request.

[0069] It should be noted that the execution process of step 206 can be implemented in any of the embodiments of this disclosure. This disclosure does not limit this and will not elaborate further.

[0070] To clearly illustrate how the above embodiments determine whether the account balance meets the transaction amount of each transaction request that has started an independent transaction, according to the order in which the independent transactions of the transaction request were started, and to determine the target transaction request from at least two transaction requests received in parallel under the same account identifier, this disclosure proposes another transaction processing method based on TCC.

[0071] Figure 3 This is a flowchart illustrating the TCC-based transaction processing method shown in the third embodiment of this disclosure.

[0072] like Figure 3 As shown, the TCC-based transaction processing method includes the following steps:

[0073] Step 301: Obtain at least two transaction requests under the same account identifier sent by the client in parallel; wherein, the transaction request carries the account identifier of the account to be traded and transaction information, and the transaction information includes at least the transaction amount.

[0074] Step 302: For each transaction request received in parallel under the same account identifier, during the TCC trial phase, an independent transaction is initiated for the transaction request.

[0075] Step 303: Obtain the time sequence of requests to start independent transactions for transaction transactions.

[0076] Step 304: Determine the account balance of the account corresponding to the account identifier based on the account identifier carried in the transaction request.

[0077] It should be noted that the execution process of steps 301 to 304 can be implemented in any of the embodiments of this disclosure. This disclosure does not limit this and will not elaborate further.

[0078] Step 305: For each transaction request that has started an independent transaction, determine whether the account balance meets the transaction amount of the transaction request according to the order in which the independent transaction requests started. If there is a transaction request whose account balance meets the transaction amount, reserve and lock the account balance for the target transaction amount to determine the locked account amount, and take the transaction request that has completed the amount reservation and locking as the target transaction request.

[0079] It should be noted that the target transaction amount is used to represent the transaction amount corresponding to the target transaction record.

[0080] For example, there are three transaction requests: Transaction Request A, Transaction Request B, and Transaction Request C. Transaction Request A initiates its independent transaction first, followed by Transaction Request B, and then Transaction Request C. Therefore, the order in which the three transaction requests initiate their independent transactions is Transaction Request A, Transaction Request B, and Transaction Request C. First, it is determined whether the account balance (600) meets the transaction amount (200) of Transaction Request A. If the transaction amount (200) is less than the account balance (600), then Transaction Request A is the target transaction request. Finally, the target transaction amount (200) is applied to the account balance (600). The amount is reserved and locked to determine the locked account amount as 600-200=400; then, it is judged whether the locked account amount (400) meets the transaction amount (360) of transaction request B. If the transaction amount (360) is less than the locked account amount (400), transaction request B is the target transaction request, and the amount of the target transaction amount (360) is reserved and locked to determine the locked account amount as 400-360=40; then, it is judged whether the locked account amount (40) meets the transaction amount (180) of transaction request C. If the transaction amount (180) is greater than the locked account amount (40).

[0081] It should be noted that the transaction amount for transaction request A is 200, the transaction amount for transaction request B is 360, and the transaction amount for transaction request C is 180. For each transaction request, the account identifier corresponding to transaction request A, transaction request B, and transaction request C is account identifier A, and the account balance of account A corresponding to account identifier A is 600.

[0082] Step 306: According to the order in which the transaction requests to open independent transactions are made, determine whether the locked account balance meets the transaction amount of the transaction request, until there is a transaction request where the locked account balance does not meet the transaction amount.

[0083] In some examples, if there is a transaction request where the locked account balance does not meet the transaction amount, the transaction record corresponding to the transaction request where the locked account balance does not meet the transaction amount will be deleted from the transaction database.

[0084] For example, based on the above example, if the locked account balance (40) does not meet the transaction transaction request C of the transaction amount (180), the transaction record corresponding to the transaction transaction request C will be deleted from the transaction database.

[0085] Step 307: Determine the response to the target transaction request, and during the TCC confirmation phase, update the account balance of the corresponding account based on the target transaction amount associated with the target transaction request.

[0086] It should be noted that the execution process of step 307 can be implemented in any of the embodiments of this disclosure. This disclosure does not limit this and will not elaborate further.

[0087] In summary, for each transaction request that has initiated an independent transaction, the system determines whether the account balance meets the transaction amount requirement based on the order in which the independent transactions were initiated. If there are transaction requests with account balances meeting the transaction amount requirement, the account balance is reserved and locked for the target transaction amount to determine the locked account amount. Transaction requests that have already completed the amount reservation and locking are then used as target transaction requests. The system continues to determine whether the locked account amount meets the transaction amount requirement based on the order in which the independent transactions were initiated, until there are transaction requests with locked account balances that do not meet the transaction amount requirement. Thus, for transactions that have initiated independent transactions... When determining whether the account balance of the account corresponding to a transaction request meets the transaction amount of the transaction request, for each transaction request, the system checks whether the account balance under the same account identifier meets the transaction amount of the transaction request according to the order in which the independent transactions of the transaction requests are started. Although the transaction requests are received at the same time, there is an issue of late-to-first or first-to-last order when the independent transactions of different transaction requests are started. Since the transaction requests are obtained in batches, the system checks whether the account balance meets the transaction amount of the transaction request step by step based on the order in which the independent transactions of the transaction requests are started. This avoids the disorder of the transaction mechanism and ensures the independence between different transaction requests.

[0088] Corresponding to the TCC-based transaction processing method provided in the above embodiments, this disclosure also provides a TCC-based transaction processing apparatus. Since the TCC-based transaction processing apparatus provided in this disclosure corresponds to the TCC-based transaction processing method provided in the above embodiments, the implementation methods of the TCC-based transaction processing method are also applicable to the TCC-based transaction processing apparatus provided in this disclosure, and will not be described in detail in this disclosure.

[0089] Figure 4 This is a schematic diagram of the structure of a TCC-based transaction processing device as shown in the fourth embodiment of this disclosure.

[0090] like Figure 4As shown, the TCC-based transaction processing device 400 includes: a first acquisition module 401, an opening module 402, a judgment module 403, and a first determination module 404.

[0091] The system includes a first acquisition module 401, which acquires at least two transaction requests under the same account identifier sent concurrently by the client. Each transaction request carries the account identifier of the account to be transacted and transaction information, including at least the transaction amount. An initiation module 402, during the TCC trial phase, initiates an independent transaction for each transaction request under the same account identifier received concurrently. A judgment module 403, which determines whether the account balance of the account corresponding to the transaction request with the initiated independent transaction meets the transaction amount requirement. If a transaction request with an account balance meets the transaction amount requirement exists, the account balance is reserved for a target transaction amount, and the transaction request with the reserved amount is designated as the target transaction request. The target transaction amount represents the transaction amount corresponding to the transaction request. A first determination module, which determines the response to the target transaction request and, during the TCC confirmation phase, updates the account balance of the corresponding account based on the target transaction amount associated with the target transaction request.

[0092] As one possible implementation of this disclosure, the judgment module 403 is specifically used for: obtaining the time sequence of the transaction request to start an independent transaction; determining the account balance of the account corresponding to the account identifier based on the account identifier carried in the transaction request; for each transaction request that has started an independent transaction, judging whether the account balance meets the transaction amount of the transaction request according to the time sequence of the transaction request to start an independent transaction, and determining the target transaction request from at least two transaction requests received in parallel under the same account identifier.

[0093] As one possible implementation of this disclosure, the judgment module 403 is specifically used to: for each transaction request that has started an independent transaction, judge whether the account balance meets the transaction amount of the transaction request according to the order of time of starting the independent transaction of the transaction request; if there is a transaction request whose account balance meets the transaction amount, reserve and lock the account balance for the target transaction amount to determine the locked account amount, and take the transaction request that has completed the amount reservation and locking as the target transaction request;

[0094] Based on the order in which independent transactions are initiated for each transaction request, it is determined whether the locked account balance meets the transaction amount requested for the transaction, until there is a transaction request where the locked account balance does not meet the transaction amount.

[0095] As one possible implementation of this disclosure, the determination module 403 is specifically used for:

[0096] Calculate the sum of the transaction amounts requested for each transaction to determine the total transaction amount;

[0097] The system checks whether the account balance meets the total transaction amount. If the account balance meets the total transaction amount, each transaction request that has started an independent transaction is used as the target transaction request.

[0098] As one possible implementation of this disclosure, the apparatus further includes a transaction database module, specifically used for:

[0099] For transactions that have started independent transactions, insert the corresponding transaction record into the associated transaction database; where the transaction record is used to represent the account identifier, transaction amount, and transaction status, and the transaction status is updated to "in transit".

[0100] As one possible implementation of this disclosure, the transaction database module is specifically used for:

[0101] In response to a target transaction request, during the TCC confirmation phase, the system searches the transaction records inserted into the transaction database based on the account identifier corresponding to the target transaction request to determine the target transaction record corresponding to the target transaction request, and updates the transaction status of the target transaction record to "completed".

[0102] If there is a transaction request where the account balance is insufficient to meet the transaction amount, the transaction record corresponding to the transaction request where the account balance is insufficient to meet the transaction amount will be deleted from the transaction database;

[0103] If there is a transaction request where the locked account balance does not meet the transaction amount, the corresponding transaction record for that transaction request will be deleted from the transaction database.

[0104] The transaction processing apparatus based on TCC in this embodiment of the present disclosure acquires at least two transaction requests under the same account identifier sent concurrently by the client. Each transaction request carries the account identifier of the account to be transacted and transaction information, including at least the transaction amount. For each transaction request received concurrently under the same account identifier, during the TCC trial phase, an independent transaction is initiated for each transaction request. It is determined whether the account balance of the account corresponding to the transaction request with the initiated independent transaction meets the transaction amount of the transaction request. If there is a transaction request with an account balance that meets the transaction amount, the account balance is reserved and locked for a target transaction amount, and the transaction request with the completed reservation and locking is designated as the target transaction request. The target transaction amount represents the transaction amount corresponding to the transaction request. The system determines the transaction amount to respond to the target transaction request and updates the account balance of the corresponding account based on the target transaction amount associated with the target transaction request during the TCC confirmation phase. This is achieved by starting independent transactions for at least two transaction requests under the same account identifier during the TCC Try phase. This addresses the possibility of transaction failures due to insufficient account balances during the subsequent Confirm phase. The Try phase accurately reserves the transaction amount for transaction requests under the same account identifier, thus avoiding the need to restore the transaction to its previous state during the Cancel phase, regardless of whether the transaction is considered successful or failed. This prevents the smooth response to transaction requests in a microservice architecture and reduces the risk of transaction processing issues.

[0105] In an exemplary embodiment, an electronic device is also proposed.

[0106] The electronic devices include:

[0107] processor;

[0108] Memory used to store processor-executable instructions;

[0109] The processor is configured to execute instructions to implement the TCC-based transaction processing method as proposed in any of the foregoing embodiments.

[0110] As an example, Figure 5 This is a schematic diagram of the structure of an electronic device 500 as shown in an exemplary embodiment of this disclosure, as follows: Figure 5 As shown, the above-mentioned electronic device 500 may further include:

[0111] The present invention includes a memory 510 and a processor 520, and a bus 530 connecting different components (including the memory 510 and the processor 520). The memory 510 stores a computer program, and when the processor 520 executes the program, it implements the TCC-based transaction processing method described in the embodiments of the present disclosure.

[0112] Bus 530 represents one or more of several bus architectures, including a memory bus or memory controller, a peripheral bus, a graphics acceleration port, a processor, or a local bus using any of the various bus architectures. Examples of these architectures include, but are not limited to, the Industry Standard Architecture (ISA) bus, the Micro Channel Architecture (MAC) bus, the Enhanced ISA bus, the Video Electronics Standards Association (VESA) local bus, and the Peripheral Component Interconnect (PCI) bus.

[0113] Electronic device 500 typically includes a variety of electronic device readable media. These media can be any available media that can be accessed by electronic device 500, including volatile and non-volatile media, removable and non-removable media.

[0114] Memory 510 may also include computer system readable media in the form of volatile memory, such as random access memory (RAM) 540 and / or cache memory 550. Server 500 may further include other removable / non-removable, volatile / non-volatile computer system storage media. By way of example only, storage system 560 may be used to read and write non-removable, non-volatile magnetic media (… Figure 5 Not shown; usually referred to as a "hard drive package"). Although Figure 5 Not shown, a disk drive package for reading and writing to removable non-volatile disks (e.g., "floppy disks") and an optical disk drive package for reading and writing to removable non-volatile optical disks (e.g., CD-ROMs, DVD-ROMs, or other optical media) may be provided. In these cases, each drive package may be connected to bus 530 via one or more data media interfaces. Memory 510 may include at least one program product having a set (e.g., at least one) of program modules configured to perform the functions of the embodiments of this disclosure.

[0115] A program / utility 580 having a set (at least one) of program modules 570 may be stored, for example, in memory 510. Such program modules 570 include, but are not limited to, an operating system, one or more application programs, other program modules, and program data. Each or some combination of these examples may include an implementation of a network environment. Program modules 570 typically perform the functions and / or methods described in the embodiments of this disclosure.

[0116] Electronic device 500 can also communicate with one or more external devices 560 (e.g., keyboard, pointing device, display 591, etc.), and with one or more devices that enable a user to interact with electronic device 500, and / or with any device that enables electronic device 500 to communicate with one or more other computing devices (e.g., network card, modem, etc.). This communication can be performed via input / output (I / O) interface 592. Furthermore, electronic device 500 can also communicate with one or more networks (e.g., local area network (LAN), wide area network (WAN), and / or public networks, such as the Internet) via network adapter 593. As shown, network adapter 593 communicates with other modules of electronic device 500 via bus 530. It should be understood that, although not shown in the figures, other hardware and / or software modules can be used in conjunction with electronic device 500, including but not limited to: microcode, device driver packages, redundant processing units, external disk drive package arrays, RAID systems, tape drive packages, and data backup storage systems.

[0117] The processor 520 performs various functional applications and data processing by running programs stored in the memory 510.

[0118] It should be noted that the implementation process and technical principles of the electronic device in this embodiment are explained in the foregoing description of the TCC-based transaction processing method of this disclosure embodiment, and will not be repeated here.

[0119] In an exemplary embodiment, a computer-readable storage medium including instructions is also provided, such as a memory including instructions, which can be executed by a processor of an electronic device to perform the TCC-based transaction processing method proposed in any of the above embodiments. Optionally, the computer-readable storage medium may be a ROM, random access memory (RAM), CD-ROM, magnetic tape, floppy disk, and optical data storage device, etc.

[0120] In an exemplary embodiment, a computer program product is also provided, including a computer program / instructions, characterized in that the computer program / instructions, when executed by a processor, implement the TCC-based transaction processing method proposed in any of the above embodiments.

[0121] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the following claims.

[0122] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.

Claims

1. A transaction processing method based on TCC, characterized in that, Includes the following steps: Obtain at least two transaction requests under the same account identifier sent by the client in parallel; wherein, the transaction request carries the account identifier of the account to be transacted and transaction information, and the transaction information includes at least the transaction amount; For each transaction request received concurrently under the same account identifier, an independent transaction is initiated for the transaction request during the TCC attempt phase; Obtain the time sequence in which the requests to open the independent transactions for the aforementioned transaction transactions are received; Based on the account identifier carried in the transaction request, determine the account balance of the account corresponding to the account identifier; For each transaction request that has started the independent transaction, the account balance is judged to determine whether it meets the transaction amount of the transaction request according to the order in which the independent transaction was started. The target transaction request is determined from at least two transaction requests received in parallel under the same account identifier. The system determines to respond to the target transaction request and, during the TCC confirmation phase, updates the account balance of the corresponding account based on the target transaction amount associated with the target transaction request.

2. The method according to claim 1, characterized in that, For each transaction request that has initiated the independent transaction, the system determines whether the account balance meets the transaction amount of the transaction request according to the order in which the independent transaction requests were initiated. It then determines the target transaction request from at least two transaction requests received concurrently under the same account identifier, including: For each transaction request that has started the independent transaction, the system determines whether the account balance meets the transaction amount of the transaction request according to the order in which the independent transaction request was started. If there is a transaction request where the account balance meets the transaction amount, the system reserves and locks the account balance for the target transaction amount to determine the locked account amount, and the transaction request that has completed the amount reservation and locking is taken as the target transaction request. Based on the order in which the independent transactions are initiated according to the transaction request, it is determined whether the locked account amount meets the transaction amount of the transaction request, until there is a transaction request where the locked account amount does not meet the transaction amount.

3. The method according to claim 1, characterized in that, Before determining whether the account balance meets the transaction amount of each transaction request that has started the independent transaction, according to the order in which the independent transactions were started, the process includes: The sum of the transaction amounts in the transaction requests is calculated to determine the total transaction amount; Determine whether the account balance meets the total transaction amount. If the account balance meets the total transaction amount, use each transaction request that has started the independent transaction as the target transaction request.

4. The method according to claim 1, characterized in that, During the TCC attempt phase, for each transaction request received concurrently under the same account identifier, while initiating an independent transaction for the transaction request, the following is included: Insert the corresponding transaction record into the transaction database associated with the transaction request that has started the independent transaction; wherein the transaction record is used to represent the account identifier, the transaction amount and the transaction status, and the transaction status is updated to be in transit.

5. The method according to any one of claims 1-4, characterized in that, The method includes: In response to the target transaction request, during the TCC confirmation phase, the target transaction record corresponding to the target transaction request is determined by searching the transaction records inserted into the transaction database based on the account identifier corresponding to the target transaction request, and the transaction status of the target transaction record is updated to complete. If there is a transaction request where the account balance does not meet the transaction amount, the transaction record corresponding to the transaction request where the account balance does not meet the transaction amount will be deleted from the transaction database; If there is a transaction request where the locked account balance does not meet the transaction amount, the transaction record corresponding to the transaction request where the locked account balance does not meet the transaction amount will be deleted from the transaction database.

6. A transaction processing apparatus based on TCC, characterized in that, include: The first acquisition module is used to acquire at least two transaction requests under the same account identifier sent synchronously by the client; wherein, the transaction request carries the account identifier of the account to be transacted and transaction information, and the transaction information includes at least the transaction amount; The enabling module is used to enable an independent transaction for each transaction request received in parallel under the same account identifier during the TCC attempt phase. The judgment module is used to obtain the time sequence of the independent transactions initiated by the transaction transaction requests; determine the account balance of the account corresponding to the account identifier based on the account identifier carried in the transaction transaction request; for each transaction transaction request that has initiated the independent transaction, judge whether the account balance meets the transaction amount of the transaction transaction request according to the time sequence of the independent transactions initiated by the transaction transaction requests; and determine the target transaction transaction request from at least two transaction transaction requests received in parallel under the same account identifier. The first determining module is used to determine the response to the target transaction request, and during the TCC confirmation phase, to update the account balance of the corresponding account according to the target transaction amount associated with the target transaction request.

7. An electronic device, characterized in that, include: A processor, and a memory communicatively connected to the processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory to implement the method as described in any one of claims 1-5.

8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1-5.

9. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method of any one of claims 1-5.

Citation Information

Patent Citations

  • Distributed transaction transaction control method and device, equipment and storage medium

    CN115719274A

  • Method, Apparatus, and System for Executing Distributed Transaction Resources

    US20170251051A1