Transaction processing method and device, computer equipment and storage medium
By dividing the trading account into asset units in the trading system and performing asset transactions in the main data center, the problem of low transaction processing efficiency in a multi-data center environment is solved, and high concurrency and high availability transaction processing is achieved.
Patent Information
- Application Number
- CN202311403425.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2023-10-26
- Publication Date
- 2025-04-29
AI Technical Summary
In a multi-data center environment, existing trading systems require high data consistency and integrity requirements, resulting in transaction data reconciliation and repair during failover, reducing system throughput and availability, and low transaction processing efficiency.
By dividing the transaction account into asset units, performing asset transactions in the main data center, updating the version identification, and syncing them to each data center, the transaction traceability and difference data recovery are achieved to avoid blockage of other transactions.
It improves the concurrent processing volume of transaction processing, improves the transaction throughput of each transaction account, and ensures high availability and efficiency of the transaction process.
Smart Images

Figure CN119904228A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a transaction processing method, apparatus, computer equipment, storage medium and computer program product. Background Art
[0002] With the development of computer technology, hot standby technology has emerged. Specifically, different data centers can be set up and different types of business applications can be connected to different data centers to prevent data conflicts. Data centers in different locations are generally synchronized in both directions through cross-city or cross-national dedicated lines to achieve the purpose of hot standby.
[0003] Considering that the transaction system has high requirements for strong data consistency and integrity, multiple data centers must run the same application and have the same data. Switching data centers in the event of a failure requires reconciliation and repair of transaction data. This process will reduce system throughput and availability, resulting in low efficiency in transaction processing. Summary of the invention
[0004] Based on this, it is necessary to provide a transaction processing method, apparatus, computer equipment, computer-readable storage medium and computer program product that can improve transaction processing efficiency in response to the above technical problems.
[0005] In a first aspect, the present application provides a transaction processing method. The method comprises:
[0006] In response to the transaction request, determining a transaction account participating in the transaction, wherein the transaction account includes at least one asset unit, the asset unit carries a version identifier updated according to the transaction behavior, and the sum of assets of each asset unit is used to represent the total asset amount of the transaction account;
[0007] Determine a primary data center for executing the transaction from among the data centers storing the asset units of the transaction account;
[0008] In the primary data center, executing asset transactions according to the asset units to obtain transaction asset units with updated version identifiers;
[0009] The transaction asset unit is synchronized to each of the data centers.
[0010] In a second aspect, the present application also provides a transaction processing device. The device comprises:
[0011] A transaction account determination module, configured to determine a transaction account participating in a transaction in response to a transaction request, wherein the transaction account includes at least one asset unit, the asset unit carries a version identifier updated according to the transaction behavior, and the sum of assets of each asset unit is used to represent the total asset amount of the transaction account;
[0012] A primary data center determination module, used to determine a primary data center for executing transactions from data centers storing asset units of the transaction account;
[0013] A transaction execution module, configured to execute asset transactions according to the asset units in the primary data center to obtain transaction asset units with updated version identifiers;
[0014] A data synchronization module is used to synchronize the transaction asset unit to each of the data centers.
[0015] In a third aspect, the present application further provides a computer device. The computer device includes a memory and a processor, the memory stores a computer program, and the processor implements the following steps when executing the computer program:
[0016] In response to the transaction request, determining a transaction account participating in the transaction, wherein the transaction account includes at least one asset unit, the asset unit carries a version identifier updated according to the transaction behavior, and the sum of assets of each asset unit is used to represent the total asset amount of the transaction account;
[0017] Determine a primary data center for executing the transaction from among the data centers storing the asset units of the transaction account;
[0018] In the primary data center, executing asset transactions according to the asset units to obtain transaction asset units with updated version identifiers;
[0019] The transaction asset unit is synchronized to each of the data centers.
[0020] In a fourth aspect, the present application further provides a computer-readable storage medium. The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0021] In response to the transaction request, determining a transaction account participating in the transaction, wherein the transaction account includes at least one asset unit, the asset unit carries a version identifier updated according to the transaction behavior, and the sum of assets of each asset unit is used to represent the total asset amount of the transaction account;
[0022] Determine a primary data center for executing the transaction from among the data centers storing the asset units of the transaction account;
[0023] In the primary data center, executing asset transactions according to the asset units to obtain transaction asset units with updated version identifiers;
[0024] The transaction asset unit is synchronized to each of the data centers.
[0025] In a fifth aspect, the present application further provides a computer program product. The computer program product includes a computer program, and when the computer program is executed by a processor, the following steps are implemented:
[0026] In response to the transaction request, determining a transaction account participating in the transaction, wherein the transaction account includes at least one asset unit, the asset unit carries a version identifier updated according to the transaction behavior, and the sum of assets of each asset unit is used to represent the total asset amount of the transaction account;
[0027] Determine a primary data center for executing the transaction from among the data centers storing the asset units of the transaction account;
[0028] In the primary data center, executing asset transactions according to the asset units to obtain transaction asset units with updated version identifiers;
[0029] The transaction asset unit is synchronized to each of the data centers.
[0030] The above-mentioned transaction processing method, apparatus, computer equipment, storage medium and computer program product, by dividing the transaction account into asset units, can directly process asset transactions at the granularity of the asset unit, which can effectively improve the concurrent processing volume of asset transaction processing. At the same time, the version identifier carried by the asset unit is updated according to the transaction behavior, and the transaction can be backtracked based on the version identifier between the synchronized transaction asset units in different data centers, so that the difference data of the account transaction can be directly restored from the granularity of the asset unit, which will not block the execution of other normal asset transactions, can improve the transaction throughput of each transaction account, ensure the high availability of the transaction process, and thus can effectively improve the transaction processing efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0031] Figure 1 An application environment diagram of a transaction processing method in an embodiment;
[0032] Figure 2 A flowchart of a transaction processing method in one embodiment;
[0033] Figure 3 A schematic diagram of the structure of an asset unit in a transaction processing method in one embodiment;
[0034] Figure 4 A schematic diagram of chain update of a transaction processing method in an embodiment;
[0035] Figure 5 A schematic diagram of the structure of a transaction processing system in one embodiment;
[0036] Figure 6 A schematic diagram of a transaction backtracking process of a transaction processing method in one embodiment;
[0037] Figure 7 A schematic diagram of a version rollback process of a transaction processing method in one embodiment;
[0038] Figure 8 It is a schematic diagram of a process of sharding an asset unit in one embodiment;
[0039] Fig. 9 A schematic diagram of a data recovery process of a transaction processing method in another embodiment;
[0040] Fig.10 is a structural block diagram of a transaction processing device in one embodiment;
[0041] Fig.11 is an internal structure diagram of a computer device in one embodiment;
[0042] Fig.12 FIG. 4 is a diagram showing the internal structure of a computer device in another embodiment. DETAILED DESCRIPTION
[0043] In order to make the purpose, technical solution and advantages of the present application more clearly understood, the present application is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application.
[0044] The transaction processing method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown. The application environment may include a trading system, and the trading system includes a terminal 102, a server 104, a server 106, etc. The terminal 102 communicates with the server 104, the server 106 through a network. The data storage system can store the data that the server 104, the server 106 needs to process. The data storage system can be integrated on the server 104, the server 106, or it can be placed on the cloud or other servers. The server 104 and the server 106 can both serve as data centers for executing transaction processing. In actual applications, the trading system allocates a data center (Base) to each trading account, and the read and write requests are based on the data of the Base. If the Base fails, the trading system can switch the Base of the trading account and continue to provide trading services to ensure the high availability of the trading account.
[0045] Specifically, taking the data center assigned to transaction account A as Base1 where server 104 is located as an example, server 104 determines the transaction account X participating in the transaction in response to the transaction request initiated by the user through terminal 102, wherein transaction account X includes at least one asset unit, and the asset unit carries a version identifier updated according to the transaction behavior. The sum of the assets of each asset unit is used to characterize the total asset amount of the transaction account. From the data centers storing the asset units of the transaction account, the main data center for executing the transaction, that is, Base1 where server 104 is located, is determined. In the main data center, asset transactions are executed according to the asset units to obtain transaction asset units with updated version identifiers, and the transaction asset units are synchronized to each data center, such as Base2 where server 106 is located.
[0046] Furthermore, each data center includes multiple replicas, which realize strong consistency data synchronization of single write and multiple reads. When a replica fails, the transaction system will automatically fill the replicas to the specified redundancy amount to ensure disaster recovery of data in a single data center.
[0047] In a specific application, taking the transaction account as a game account as an example, the transaction request can be a transaction request for game assets, and the game asset transaction between different game accounts is realized by executing the transaction. For example, taking the transaction account as a virtual asset account as an example, the transaction request can be a transaction request for virtual assets, and the virtual asset transaction between different virtual asset accounts is realized by executing the transaction.
[0048] Among them, the terminal 102 can be, but is not limited to, various desktop computers, laptops, smart phones, tablet computers, Internet of Things devices and portable wearable devices. The Internet of Things devices can be smart speakers, smart TVs, smart air conditioners, smart car-mounted devices, etc. Portable wearable devices can be smart watches, smart bracelets, head-mounted devices, etc. Servers 104 and 106 can be independent physical servers, or server clusters or distributed systems composed of multiple physical servers, or cloud servers that provide basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, CDN, and big data and artificial intelligence platforms. The terminal can be a smart phone, tablet computer, laptop computer, desktop computer, smart speaker, smart watch, etc., but is not limited to this. The terminal and the server can be directly or indirectly connected by wired or wireless communication, and this application is not limited here. In some embodiments, the assets used for transactions can be stored in a blockchain wallet, and the security of the assets is ensured by blockchain technology.
[0049] In one embodiment, Figure 2 As shown, a transaction processing method is provided, which is applied to Figure 1The trading system in is taken as an example to illustrate, including the following steps:
[0050] Step 202, in response to the transaction request, determine the transaction account participating in the transaction, the transaction account includes at least one asset unit, the asset unit carries a version identifier updated according to the transaction behavior, and the sum of assets of each asset unit is used to represent the total asset amount of the transaction account.
[0051] Among them, a transaction request refers to a data processing request for requesting an asset transfer. The types of asset transfer include asset transfer-in and asset transfer-out. For example, assets are transferred from transaction account A to transaction account B, and another example is that the system allocates corresponding assets to transaction account A through system recharge. The transferred assets may include various types of assets that match the actual application scenarios, such as game assets in game scenarios, item assets in item trading scenarios, etc. When executing a transaction, when the asset types of the two parties to the transaction are the same, the asset transaction can be carried out directly. When the asset types of the two parties to the transaction are different, the asset transaction can be carried out based on the same asset evaluation dimension through asset conversion.
[0052] The transaction accounts participating in the transaction can be determined according to the type of transaction request. When the transaction request type is recharge, the transaction accounts participating in the transaction may only be the transfer-in account. When the transaction request type is transfer, the transaction accounts participating in the transaction may include both the transfer-in account and the transfer-out account.
[0053] For each trading account, the trading account can be divided into asset units according to the total assets, so that each asset account has at least one asset unit. The number of asset units of a trading account can be fixed or variable, and can be set according to the actual scenario needs. For example, the number of asset units of a trading account is set to N (N is a positive integer). When the number of asset units of a trading account is less than N, some of the asset units can be divided into two or M (M≤N, and M is a positive integer) through asset unit sharding, so that the number of asset units of the trading account is maintained at N. For another example, the number of asset units of a trading account is not limited. When the number of transaction requests for a trading account is large, the asset unit sharding can be automatically performed to divide it into more asset units. When the asset amount of an asset unit in a trading account is less than a set minimum threshold, the asset unit can be merged with other asset units when the asset unit is in a state where merging is allowed, thereby ensuring that the asset amount of each asset unit is not less than the set minimum threshold. By further splitting each account and dividing it into several asset units, each trading account can automatically repair conflicting or missing data when switching the main data center, thereby improving efficiency and ensuring the ultimate consistency of asset data. In addition, each main data center can serve multiple trading accounts and each trading account carries several asset units, each of which can be traded, improving the system's high throughput, high availability and scalability.
[0054] The version identifier is used to record the transaction behavior of the asset unit. The version identifier can be updated according to the transaction behavior in which the asset unit participates. For each asset unit, there is an independent version identifier to match it. Different asset units in the same trading account have version identifiers for recording their transaction behaviors, so as to achieve the traceability of the transaction process of different asset units in the trading account. For example, Xiao Ming's trading account is divided into asset unit A and asset unit B according to the total assets. Asset unit A and asset unit B each have a version identifier. When trading through asset unit A, for example, if 20 assets are transferred from asset unit A, the asset amount of asset unit A will be reduced by 20, and the version identifier of asset unit A will be updated with the occurrence of the transaction. For example, the version identifier of asset unit A before the transaction is 4, and the version identifier of asset unit A after the transaction is updated to 5. However, since asset unit B will not participate in the transaction, the occurrence of the transaction will not affect the asset identifier of asset unit B. In the case of not participating in the transaction, the asset identifier of asset unit B will remain unchanged.
[0055] In some embodiments, the version identifier may specifically be a version number or other identification data. The updated version identifier is associated with the version identifier before the update, and the transaction behavior in which the asset unit participates can be backtracked based on the association relationship. For example, before asset unit K participates in the transaction behavior, its version identifier may be 1. After asset unit K participates in the transaction behavior, the version identifier of asset unit K may be increased by 1 on the basis of the original version identifier, and the version identifier may be updated to 2. For another example, before asset unit K participates in the transaction behavior, its version identifier may be 1. At the same time, the version identifier of another asset unit H participating in the transaction behavior is 3. After asset unit K and asset unit H participate in the transaction behavior, the version identifiers of asset unit K and asset unit H may both be updated to 4.
[0056] It should be noted that the updated version identifier and the version identifier before the update can be associated through a pre-set association rule. Based on the set association rule, the specific representation of the updated version identifier can be determined. In one embodiment, the version identifier is the version number, and the preset association rule is that the initial version number is 0, and the version number is +1 after each update. For example, for a certain transaction behavior of asset unit A, before the execution of this transaction, the version number before the update is 3, indicating that asset unit A has participated in three transactions. After the execution of this transaction, the updated version number is 3+1=4. Through the specific representation of the version identifier and the pre-set association rule, the number of transactions for each asset unit can be analyzed.
[0057] In one of the specific embodiments, when two asset units participate in the same transaction, the version identification of the two asset units will be updated. The specific updating method is: the updated version identification takes the version identification of the asset unit with more transactions as the updating benchmark, so that after the transaction is completed, the version identifications of the two asset units participating in the transaction remain consistent, which facilitates the traceability of the transaction process to both parties and ensures the reliability of transaction traceability.
[0058] Transaction behavior refers to the execution process of each transaction. Different transaction behaviors can be distinguished by different transaction identifiers. The transaction identifier is associated with the asset data before the transaction and the asset data after the transaction respectively. The detailed data of the transaction behavior represented by the transaction identifier can be found through the transaction identifier, including the specific data of the asset unit before the transaction and the specific data of the asset unit after the transaction.
[0059] Each asset unit can represent a certain amount of assets, and the sum of the assets of each asset unit of the same trading account is equal to the total assets of the trading account. The asset amounts of each asset unit of the same trading account can be equal or different. For example, the total assets of trading account A are equal to 100, and trading account A is divided into 4 asset units, and the asset amount of each asset unit is 25. For another example, the total assets of trading account A are equal to 100, and trading account A is divided into 4 asset units, one of which has an asset amount of 70, and the other three asset units have an asset amount of 10 each.
[0060] Step 204, determine the primary data center for executing the transaction from among the data centers storing the asset units of the transaction account.
[0061] Data centers are objects used to implement distributed storage of asset data of trading accounts. Asset data of the same trading account can be stored in each data center to implement data backup in different data centers. Specifically, business systems can be sharded according to business type or geographic location, and corresponding data centers can be set up in different regions. Different types of business applications are connected to different data centers to prevent data conflicts. Data centers in different locations are generally synchronized bidirectionally through cross-city or cross-national dedicated lines to achieve the purpose of hot standby. When a data center in a certain location fails, the business connected to it can be switched to another data center in real time and continue to provide services. Trading systems can be classified according to trading accounts. Considering that trading systems have high requirements for strong data consistency and integrity, multiple data centers must run the same application and have the same data.
[0062] The primary data center for executing transactions refers to a data center used to process transaction requests, and the data center is one of the data centers storing the asset units of the transaction account. The determination of the primary data center can be one randomly selected from the data centers storing the asset units of the transaction account, or one selected from the data centers storing the asset units of the transaction account according to a set selection rule. For example, the data centers storing the asset units of the transaction account A include data center 1 and data center 2. When the primary data center is selected by random selection, one data center can be randomly selected from data center 1 and data center 2 as the primary data center for processing the transaction request of the transaction account A. When the primary data center is selected by selection according to a selection rule, one of data center 1 and data center 2 that meets the selection rule can be determined as the primary data center for processing the transaction request.
[0063] The main data center for executing transactions can be specifically determined according to the selection rules that need to be configured in the actual scenario. In some embodiments, the main data center can be the data center assigned by default to the transaction accounts participating in the transaction. For example, the data center assigned to transaction accounts A and B is data center 1, and the data center assigned to transaction account C is data center 2. In the case where the transaction accounts participating in the transaction include at least one of transaction account A and transaction account B, the main data center for executing the transaction is data center 1. In the case where the transaction accounts participating in the transaction include transaction account C, the main data center for executing the transaction is data center 2. In the case where the transaction accounts participating in the transaction include both transaction account A and transaction account C, the main data center for executing the transaction is any one of data center 1 and data center 2.
[0064] In another embodiment, the primary data center may also be the data center assigned to the trading account that receives the trading request, for example, the data center assigned to trading account A and trading account B is data center 1, and the data center assigned to trading account C is data center 2. In the case where the trading request is a request initiated by trading account A to trading account C, the primary data center is data center 2 assigned to trading account C, and in the case where the trading request is a request initiated by trading account C to trading account B, the primary data center is data center 1 assigned to trading account B.
[0065] Step 206: In the main data center, asset transactions are performed according to asset units to obtain transaction asset units with updated version identifiers.
[0066] Among them, asset trading refers to the data processing process of asset transfer. Asset trading takes asset units as the object of resource transfer. In the process of transfer transaction, asset trading is to transfer the transaction assets from the asset unit to generate new asset units belonging to the transfer-in account. In the process of recharge transaction, asset trading is to directly generate new asset units belonging to the transfer-in account.
[0067] The transaction asset unit refers to the asset unit obtained after executing the asset transaction. The update method of the version identifier is related to the number of transaction input asset units in the transaction process. In the case that the transaction input asset unit in the transaction process is 1, the version identifier of the transaction asset unit can be directly updated based on the transaction input asset unit version identifier. For example, the asset unit participating in the transaction in transaction account A is AU with sufficient balance. a After the transaction is executed, two AUs will be generated: AU a 'With AU b , AU a 'With AU b Belong to account A and account B respectively. AU a Compared to AU aThe balance is reduced by the transaction asset amount, AU b The newly generated AU belongs to account B, AU b The balance is equal to the transaction asset amount, and AU a 'With AU b The version number Version is updated to the value of Version in the transaction input asset unit plus one. For example, the transaction input asset unit AU a If the version number is 5, then AU a 'With AU b The version number Version is updated to 6.
[0068] When the number of transaction input asset units is 2 or more, the version identifier of the transaction asset unit can first determine the number of transactions represented by the version identifiers of each transaction input asset unit, and then update the version identifier based on the one with the larger number of transactions. In one embodiment, taking the transfer of resources from transaction account A and transaction account B to transaction account C as an example, the asset unit involved in the transaction in transaction account A is AU a , the asset unit involved in the transaction in trading account B is AU b After the transaction is executed, three AUs will be generated: AU a ',AU b 'With AU c , AU a ',AU b 'With AU c They belong to account A, account B and account C respectively. a Compared to AU a The balance is reduced by the transaction asset Amount1, AU b Compared to AU b The balance is reduced by the transaction asset Amount2, AU c The newly generated AU belongs to account C, AU c The balance is equal to the sum of the transaction assets Amount1+Amount2. a ',AU b 'With AU c The version number Version is updated to the transaction input asset unit AU a and AU b The maximum value of Version plus one, for example, AU a- The version number is 5, AU b If the version number is 3, then AU a ',AU b 'With AU c The version number of Version is updated from 5 to 6.
[0069] Step 208: Synchronize the transaction asset unit to each data center.
[0070] After the asset transaction is completed, the transaction asset unit needs to be synchronized so that all data centers storing the asset units of the transaction account can achieve data synchronization. Specifically, the data synchronization between the main data center and other data centers can be achieved asynchronously. The main data center asynchronously synchronizes the transaction asset data to the other data centers, and the other data centers update their own asset sets of internal transaction accounts after receiving them.
[0071] The above-mentioned transaction processing method, by dividing the transaction account into asset units, can directly process asset transactions at the granularity of the asset unit, which can effectively improve the concurrent processing volume of asset transaction processing. At the same time, the version identifier carried by the asset unit is updated according to the transaction behavior, and the transaction can be backtracked based on the version identifier between the synchronized transaction asset units in different data centers, so that the difference data of the account transaction can be directly restored from the granularity of the asset unit, which will not block the execution of other normal asset transactions, can improve the transaction throughput of each transaction account, ensure the high availability of the transaction process, and thus effectively improve the transaction processing efficiency.
[0072] In some embodiments, when the transaction request is a transfer transaction request, the transaction account includes a transfer-in account and a transfer-out account; and the transaction processing method further includes:
[0073] Based on the transaction asset amount requested by the transaction request, a target asset unit participating in the transaction is determined from the asset units of the transaction account; the asset amount of the target asset unit is greater than or equal to the transaction asset amount.
[0074] Furthermore, asset transactions are performed according to asset units to generate updated asset units with updated version identifiers, including:
[0075] An asset transaction is performed on the target asset unit according to the transaction asset amount, and an updated asset unit belonging to the transfer-out account and a newly added asset unit belonging to the transfer-in account are generated; wherein the version identifier of the updated asset unit and the version identifier of the newly added asset unit are both associated with the version identifier of the target asset unit.
[0076] Among them, a transfer transaction request refers to a resource transfer request to transfer assets from one or more trading accounts to another trading account, or to transfer assets from one trading account to one or more trading accounts. A transfer-out account refers to a trading account from which assets are transferred out, and correspondingly, a transfer-in account refers to a trading account from which assets are transferred in. In the case where the transaction request is a transfer transaction request, the trading accounts include two categories: transfer-in accounts and transfer-out accounts. It can be understood that the number of transfer-in accounts and transfer-out accounts can be multiple; for example, one trading account transfers to multiple trading accounts, and another example is that multiple trading accounts transfer to one trading account. In other embodiments, the number of transfer-out accounts and transfer-in accounts can be limited to 1. For example, when the number of transfer-in accounts is multiple, asset transfers are performed separately through different asset units to improve data processing efficiency.
[0077] The transaction asset volume requested by the transaction request refers to the amount of resources that need to be transferred. The target asset unit refers to the asset unit in the transaction account whose asset volume is greater than or equal to the transaction asset volume. By determining the target asset unit, it can be ensured that the asset transaction can be directly executed through the divided asset unit, avoiding the impact of asset transaction failure on transaction processing efficiency, and improving the success rate of transaction execution.
[0078] The version identifier is used to record the transaction behavior of the asset unit. The version identifier can be updated according to the transaction behavior in which the asset unit participates. The version identifier can be a version number or other identification data. The updated version identifier is associated with the version identifier before the update, so that the transaction behavior in which the asset unit participates can be traced back according to the association relationship.
[0079] For the change of asset unit in the transfer transaction request, the transfer-out account A needs to have the original target asset unit AU a For the transfer to account B, there may be original asset units or no original asset units. Account A selects an AU with sufficient balance. a , transfer amount Amount, account B as the transaction input, and initiate the transaction. a The version identifier Version1 is the maximum value of Version in the transaction input AU set.
[0080] After the transaction is executed, two new asset units AU will be generated: the updated asset unit AU belonging to the transfer-out account A a 'With the newly added asset unit AU belonging to the transferred account B b Among them, AU a 'The assets represented are compared to AU a The transfer amount Amount is deducted and the transaction identifier FID of this transaction is used as AU a'Asset source ID, AU b The balance of the transaction is equal to the transfer amount. Similarly, the transaction identifier FID of this transaction is used as AU b The asset source ID, at the same time, you also need to a 'With AU b The version number is updated to Version2.
[0081] In this embodiment, by determining from the transaction account an asset unit whose asset amount is greater than or equal to the transaction asset amount as the target asset unit participating in the transaction, it can be ensured that the asset transaction can be executed directly through the divided asset units, avoiding the impact of asset transaction failure on transaction processing efficiency, and improving the success rate of transaction execution. By generating an updated asset unit belonging to the transfer-out account and a newly added asset unit belonging to the transfer-in account, and making the version identifier of the updated asset unit and the version identifier of the newly added asset unit associated with the version identifier of the target asset unit, it is possible to facilitate the associated version identifier to realize the backtracking of the transaction behavior in which the asset unit participates, and facilitate the asset synchronization of asset units that asynchronously participate in transactions in different data centers through backtracking.
[0082] In some embodiments, the method further includes: using the target asset units involved in the transaction as a transaction input set, and using the updated asset units and the newly added asset units as a transaction output set; constructing transaction metadata including a transaction identifier representing the transaction behavior, a transaction input set, and a transaction output set;
[0083] Furthermore, synchronizing the transaction asset unit to each data center includes: synchronizing the transaction metadata to each data center.
[0084] The transaction input set is a set of asset units used to represent the transferred assets, and the transaction output set is a set of asset units used to represent the newly generated asset units after the transaction is executed. For a transfer transaction, its transaction input set includes the target asset units participating in the transaction in the transfer-out account, and the transaction output set includes the updated asset units belonging to the transfer-out account and the newly added asset units belonging to the transfer-in account.
[0085] In one embodiment, Figure 3 As shown, the transaction metadata includes: transaction ID, input set {AU a}、Output set {AU a ',AU b}, where each asset unit has corresponding core fields, including: asset identifier UID, account identifier ID, balance Balance, version identifier Version, asset source ID (FID), where asset identifier UID is the unique identifier of the asset unit. After each related transaction is executed, the balance Balance and version identifier Version in the AU core field will be updated, and the asset source ID will be bound to the transaction ID.
[0086] In this embodiment, by constructing transaction metadata including a transaction identifier, a transaction input set, and a transaction output set that characterize the transaction behavior, the detailed data of the asset units before and after the transaction can be synchronized between different data centers, which can facilitate different data centers to trace the transaction behavior based on the transaction metadata, and enable data recovery to be achieved quickly and conveniently in the event of a data center switch.
[0087] In some of the embodiments, when the transaction request is a recharge transaction request, the transaction account includes a transfer-in account; executing asset transactions according to asset units and generating updated asset units with updated version identifiers include: executing asset transactions according to transaction asset amounts and generating newly added asset units belonging to the transfer-in account.
[0088] Among them, the recharge transaction request refers to the transaction request of the trading system as the asset provider. The transaction account for the recharge transaction behavior is only the transfer-in account. For the transfer-in account, the recharge transaction behavior can be to add one or more asset units in the transfer-in account, and the total balance of the newly added asset units is the recharged asset amount.
[0089] In some embodiments, a maximum allowable asset amount can be set for an asset unit. When the amount of assets recharged is greater than the maximum allowable asset amount, multiple new asset units belonging to the transferred account can be generated. When the amount of assets recharged is less than or equal to the maximum allowable asset amount, one new asset unit belonging to the transferred account can be generated.
[0090] In other embodiments, the number of newly added asset units may be set for the recharge transaction. For example, the number of newly added asset units may be set to 2. When the recharge transaction is executed, the recharged asset amount may be divided into two parts to generate two newly added asset units belonging to the transferred account.
[0091] In this embodiment, for recharge transactions, by directly executing asset transactions according to the transaction asset amount and generating new asset units belonging to the transferred account, the data processing process of the recharge transaction can be simplified without interfering with other transaction behaviors, which can effectively improve the overall data processing efficiency.
[0092] In some embodiments, each data center includes multiple replicas; in the primary data center, asset transactions are performed according to asset units to obtain transaction asset units with updated version identifiers, including:
[0093] From the replicas in the primary data center, determine the primary replica for participating in the transaction and the secondary replica for synchronizing data; execute the asset transaction based on the target asset unit stored in the primary replica to obtain the transaction asset unit with the updated version identifier;
[0094] Furthermore, in the master data center, after executing asset transactions according to asset units and obtaining transaction asset units with updated version identifiers, the process further includes: synchronizing the transaction asset units to each slave replica.
[0095] Among them, the replica is the basis for realizing local disaster recovery in the data center. In some embodiments, each trading account has at least 3 replicas in Base, and multiple replicas realize strong consistency data synchronization of single write and multiple read. When a replica fails, the system will automatically fill the replica to the specified redundancy to ensure disaster recovery of data in a single data center.
[0096] During the transaction processing process, the transaction system first determines the primary data center that executes the transaction, and then determines the primary replica used to participate in the transaction and the slave replica used to synchronize data from the replicas of the primary data center. During the transaction processing process, the transaction asset unit generated by the transaction is written based on the primary replica, and the transaction asset unit written to the primary replica is synchronized to each slave replica, thereby realizing data synchronization between multiple replicas of the primary data center.
[0097] In one embodiment, the transfer-out account A selects an AU with sufficient balance. a , transfer amount Amount, transfer to account B as the transaction input, and initiate the transaction, the transaction identifier is FID. After the transaction is executed, an updated asset unit AU belonging to the transfer-out account A will be generated a 'With the newly added asset unit AU belonging to the transferred account B b The transaction system will send the transaction metadata (transaction identifier FID, input set {AU a}、Output set {AU a ',AU b}) are saved in three copies of account A and account B respectively. After the three copies complete strong consistency synchronization, the transaction execution is completed and returned to the client. The main data center Base asynchronously synchronizes the transaction metadata to the other data centers. After receiving it, the other data centers update the asset collection of internal accounts A and B.
[0098] In this embodiment, the trading system divides the data replication process into two layers. Each trading account uses a strong synchronization method between multiple copies in the same data center to prevent single point failures in the copies and ensure the availability and consistency of the accounts in a single data center. At the same time, data synchronization across data centers uses an asynchronous method to prevent single point failures in the data center, ensure transaction execution efficiency and multi-data center disaster recovery. Combined with the above-mentioned data automatic repair function, the trading system can achieve a good balance between efficiency and disaster recovery.
[0099] In some embodiments, a primary data center for executing a transaction is determined from among data centers storing asset units of a transaction account, including: when the transaction request is a transfer transaction request, data centers that match the incoming account and the outgoing account are selected as candidate data centers; and a primary data center for executing the transaction is selected from among the candidate data centers.
[0100] The primary data center for executing transactions can be determined based on the transaction accounts involved in the transaction, so as to reduce the number and frequency of switching of data centers during the execution of transactions. Specifically, each transaction account can be pre-configured with a matching data center, with data center 1 being the primary data center for transaction accounts A and B, and data center 2 being the primary data center for transaction account C.
[0101] In one embodiment, the main data center of transaction accounts A and B is Base1, and the main data center of account C is Base2. The accounts have 3 copies in each Base and execute a strong consistency protocol. The transaction information is transmitted asynchronously between Bases. At the same time, each account also has several asset units AU. The AUs under the same account can be sharded or merged. AU is the smallest unit of transaction, and the total assets of a user are the collection of all AUs under his account ID. Figure 4 As shown, each version of AU can be understood as a node on a chain structure, and each transaction related to AU can be understood as an edge of this structure, which continuously drives the update of AU.
[0102] For example, Figure 5 As shown, in the case where the transaction request is a transfer transaction request, the data center Base1 matching the transfer-in account A and the data center Base2 matching the transfer-out account C are used as candidate data centers. When determining the primary data center for executing the transaction, Base1 can be used as the primary data center, or Base2 can be used as the primary data center.
[0103] When Base1 is used as the primary data center, the primary data center of the transfer-out account C needs to be switched from Base2 to Base1, and then the transaction is executed in Base1. When Base2 is used as the primary data center, the primary data center of the transfer-in account A needs to be switched from Base1 to Base2, and then the transaction is executed in Base2.
[0104] In some embodiments, when both Base1 and Base2 are in an abnormal state and cannot execute transactions, Base3 can be used as the main data center. At this time, the main data center of the transfer-out account A needs to be switched from Base1 to Base2, and the main data center of the transfer-out account C needs to be switched from Base2 to Base1, and then the transaction can be executed in Base3.
[0105] In this embodiment, by using the data centers that match the transfer-in account and the transfer-out account as candidate data centers to select the primary data center for executing the transaction, the number of transaction accounts that need to switch the primary data center can be reduced, the primary data center for executing the transaction can be quickly located, and the occupation of data resources in the process of switching the primary data center can be reduced, which can effectively improve resource utilization.
[0106] In some embodiments, determining a primary data center for executing transactions from among data centers storing asset units of trading accounts includes: determining a first data center currently assigned to a trading account as the primary data center for executing transactions from among data centers storing asset units of trading accounts.
[0107] Furthermore, the transaction processing method also includes: when the main data center is in an abnormal state, reallocating the second data center to the transaction account; switching the main data center for executing the transaction to the second data center.
[0108] During the transaction processing, the data center assigned to the transaction account can be switched. During the transaction execution, the first data center currently assigned to the transaction account is generally determined as the primary data center for executing the transaction. When the data centers currently assigned to the transaction parties are the same, the data center is used as the primary data center for executing the transaction. When the data centers currently assigned to the transaction parties are different, the data center assigned to the transfer-out account or the transfer-in account can be used as the primary data center for executing the transaction. When the primary data center is in an abnormal state, the second data center is reassigned to the transaction account, where the second data center can be any one of the data centers storing the asset units of the transaction account except the first data center.
[0109] For example, when the data centers currently assigned to the two parties to a transaction are different, the first data center assigned to the transfer-out account can be used as the primary data center for executing the transaction. When the first data center is in an abnormal state, the second data center originally assigned to the transfer-in account can be reallocated to the transfer-out account, thereby switching the primary data center for executing the transaction to the second data center, thereby achieving rapid search and switching of the primary data center.
[0110] In this embodiment, by switching the primary data center for executing transactions, when the primary data center currently allocated for executing transactions is in an abnormal state, rapid adjustment of the data center can be achieved to ensure that the transaction can be executed smoothly and improve the execution efficiency of the transaction.
[0111] In some embodiments, the method further includes: when the asset amount of each asset unit of the transfer-out account in the trading account is less than the trading asset amount, creating a virtual asset unit belonging to the transfer-out account in the second data center.
[0112] Furthermore, in the main data center, asset transactions are executed according to asset units to obtain transaction asset units with updated version identifiers, including: before completing asset unit synchronization in the second data center, asset transactions are executed according to virtual asset units to generate updated virtual asset units belonging to the transfer-out account and newly added asset units belonging to the transfer-in account; after completing asset unit synchronization in the second data center, the updated virtual asset units are merged with the synchronized asset units to generate updated asset units belonging to the transfer-out account.
[0113] Among them, virtual asset units are prepaid asset units. The difference between virtual asset units and asset units is that virtual asset units will be recorded as negative values by the trading system. When the trading system completes all data synchronization, they will be forcibly merged with normal asset units. When normal asset units are merged, the balances are added. When virtual asset units are merged with normal asset units, the balances are subtracted. When merging, the balance of normal asset units must be greater than the balance of virtual asset units. If the merged asset unit is a positive value, it means that the balance of the trading account is sufficient and subsequent transactions can continue. If the merged asset unit is a negative value, it means that the balance of the trading account is insufficient and subsequent transactions cannot be carried out.
[0114] In some of the embodiments, since the transaction data of account A in Base1 is previously backed up to Base2 in an asynchronous manner, data inconsistency may occur when the Base is switched, which may manifest as abnormal situations such as insufficient account balance and expired asset unit version.
[0115] In case of data inconsistency, if the balance of account A is insufficient before time t (the balance of no asset unit is greater than the transfer amount), a special asset unit, virtual asset unit (VAU), needs to be created for account A, and the transaction process is performed through the virtual asset unit. After the asset unit synchronization is completed and automatically repaired, after the trading system has processed all AUs with the same asset UID, the trading system will merge the VAUs and AUs in the account to obtain an updated AU.
[0116] The premise for starting the automatic repair function is that the original Base is restored and the data can be read. If the original Base has been down or disconnected from the network, the difference data cannot be synchronized and data inconsistency will always exist. Another condition for automatic repair is that AU merging is not allowed before the recovery is completed.
[0117] In this embodiment, by creating a virtual asset unit to execute transactions, asset transactions can be successfully executed in abnormal situations such as insufficient balance or expired asset unit version and other data inconsistencies, and data merging can be completed after automatic data repair, thereby avoiding the occurrence of asset transaction failures due to asynchronous data backup, and can effectively reduce the occurrence of transaction failures.
[0118] In some of the embodiments, the process of synchronizing the asset unit of the second data center includes: receiving a synchronized transaction asset unit sent by the first data center; obtaining a first transaction identifier of the synchronized transaction asset unit and a second transaction identifier of the actual transaction asset unit respectively when the first version identifier of the synchronized transaction asset unit is the same as the second version identifier of the actual transaction asset unit of the second data center; performing transaction backtracking based on the first transaction identifier and the second transaction identifier to obtain a root transaction asset unit with the same transaction identifier; and performing asset unit synchronization on the actual transaction asset unit based on the asset changes of the root transaction asset unit and the synchronized transaction asset unit.
[0119] Among them, after switching the main data center from the first data center to the second data center, the transaction data of the first data center may still have some transactions being executed, so the transaction data of the first data center needs to be synchronized to the second data center for data synchronization.
[0120] For the second data center, after the primary data center switches from the first data center to the second data center, the second data center will receive synchronization data sent from the first data center, specifically including the synchronization transaction asset unit sent by the first data center. In some embodiments, the synchronization data sent by the first data center may be transaction metadata, and the transaction metadata specifically includes a transaction identifier representing the transaction behavior, a transaction input set where the target asset unit of the transferred-out asset is located, and a transaction output set including the updated asset unit belonging to the transferred-out account and the newly added asset unit belonging to the transferred-in account.
[0121] After receiving the synchronous transaction asset unit, the second data center needs to determine the transaction behavior and transaction asset amount that occurred in the first data center through version rollback and transaction backtracking. Since the transaction metadata records the data corresponding to each transaction behavior, when performing version rollback and transaction backtracking, backtracking can be performed based on the transaction identifier and version identifier.
[0122] Specifically, when the first version identifier of the synchronous transaction asset unit is the same as the second version identifier of the actual transaction asset unit of the second data center, the second data center does not need to perform version rollback, but only needs to perform transaction backtracking. Specifically, the second data center obtains the first transaction identifier of the synchronous transaction asset unit and the second transaction identifier of the actual transaction asset unit respectively, and the synchronous transaction asset unit and the actual transaction asset unit are traced back to the same root transaction asset unit according to the first transaction identifier and the second transaction identifier respectively, that is, the first transaction identifier of the synchronous transaction asset unit is the same as the second transaction identifier of the actual transaction asset unit, and the first version identifier of the synchronous transaction asset unit is the same as the second version identifier of the actual transaction asset unit. The root transaction asset unit is the bifurcation point where different transactions are generated between the first data center and the second data center.
[0123] Based on the bifurcation point, the balance difference between the transaction asset unit of the first data center and the root transaction asset unit can be determined, and then the balance difference is added to the transaction asset unit of the second data center. If the balance difference is greater than 0, a new recharge transaction is created for transaction account A in the second data center to increase the balance of AU2. If the balance difference is less than 0, a new liability transaction is created for account A in the second data center. After the transaction is executed, a virtual asset unit will be created to repair the difference asset data.
[0124] like Figure 6As shown, for the synchronous transaction asset unit and the actual transaction asset unit with the same version identifier, if the transaction identifier is also the same, it means that the synchronous transaction asset unit and the actual transaction asset unit are the same transaction, that is, the root transaction asset unit. If the transaction identifiers are different, for example, the transaction identifier of the synchronous transaction asset unit is Tx3, and the transaction identifier of the actual transaction asset unit is Tx5, it is necessary to further trace the transaction through the transaction identifier to obtain the synchronous transaction asset unit and the actual transaction asset unit with the same transaction identifier, that is, the root transaction asset unit with the version identifier of Version3.
[0125] In this embodiment, by tracing back to the root transaction asset unit in which the first transaction identifier of the synchronization transaction asset unit is the same as the second transaction identifier of the actual transaction asset unit, and the first version identifier of the synchronization transaction asset unit is the same as the second version identifier of the actual transaction asset unit, the bifurcation point where different transactions are generated in the first data center and the second data center can be accurately located, and the synchronization of transaction data generated by different data centers can be achieved conveniently and quickly, thereby effectively improving data synchronization efficiency.
[0126] In some embodiments, when the first version identifier of the synchronous transaction asset unit is different from the second version identifier of the actual transaction asset unit of the second data center, the second data center needs to perform two processes of version rollback and transaction backtracking. Specifically, the asset transaction method also includes a process of determining the synchronous transaction asset unit and the actual transaction asset unit with the same version identifier through version rollback, and the process specifically includes:
[0127] Obtain a first version identifier of a synchronous transaction asset unit and a second version identifier of an actual transaction asset unit of a second data center; if the first version identifier is different from the second version identifier, determine a target asset unit with a larger number of updates between the first version identifier and the second version identifier; perform version rollback on the target asset unit to obtain a synchronous transaction asset unit and an actual transaction asset unit with the same version identifier.
[0128] During the actual data processing process, the version identifier of the synchronous transaction asset unit received by the second data center may be different from the version identifier of the actual transaction asset unit generated by the second data center. At this time, it is necessary to first perform version rollback on the synchronous transaction asset unit and the actual transaction asset unit until the first version identifier of the synchronous transaction asset unit is the same as the second version identifier of the actual transaction asset unit of the second data center.
[0129] In some specific embodiments, Figure 7As shown, the version identifier of the synchronous transaction asset unit most recently received by the second data center Base2 from the first data center Base1 is Version5, and the version identifier of the actual transaction asset unit generated by the second data center Base2 is Version10 (the version number of Version10 is greater than Version5). Through version rollback, the second data center can determine the synchronous transaction asset unit with version identifier Version4 and the actual transaction asset unit with version identifier Version4.
[0130] Among them, the transaction identifier of the synchronized transaction asset unit with the version identifier Version4 is Tx3, and the transaction identifier of the actual transaction asset unit with the version identifier Version4 is Tx5 (Tx3 and Tx5 are only used to represent different transactions, and other symbols can also be used to identify them). For synchronized transaction asset units and actual transaction asset units with the same version identifier, if the transaction identifiers are different, for example, the transaction identifier of the synchronized transaction asset unit is Tx3, and the transaction identifier of the actual transaction asset unit is Tx5, it is necessary to further perform transaction backtracking to obtain synchronized transaction asset units and actual transaction asset units with the same transaction identifier of Tx2, that is, the root transaction asset unit with the version identifier Version3.
[0131] In this embodiment, the synchronized transaction asset unit and the actual transaction asset unit with the same transaction identifier can be quickly determined through version rollback, so as to find the root transaction asset unit for asset synchronization and improve the synchronization processing efficiency.
[0132] In some embodiments, Figure 8 As shown, the transaction processing method also includes:
[0133] Step 802, in response to multiple transaction requests triggered concurrently for the same transaction account, obtaining the number of asset units in the transaction account;
[0134] Step 804: When the number of asset units is less than the number of transaction requests, at least a portion of the asset units of the transaction account are fragmented to obtain a plurality of asset units respectively used to process each transaction request.
[0135] Among them, transaction requests can be executed with high concurrency. For multiple transaction requests triggered concurrently, the main data center can process them through different asset units. When the number of asset units is less than the number of transaction requests, the existing asset units can be sharded to obtain a larger number of asset units, so that transaction requests can be executed separately through different asset units, thereby improving the concurrent processing volume of transaction requests.
[0136] For example, when the number of concurrently triggered transaction requests for transaction account A is 10, and the number of asset units currently divided into the transaction account that can participate in the transaction is 8, one of the asset units can be divided into 3 asset units that can participate in the transaction, so that the number of asset units that can participate in the transaction reaches 10, or two of the asset units can be divided into 2 asset units that can participate in the transaction, so that the number of asset units that can participate in the transaction reaches 10. Among them, the asset unit that can participate in the transaction can specifically be an asset unit whose asset volume is greater than the transaction asset volume.
[0137] In this embodiment, when processing multiple concurrent transaction requests, by sharding the asset units, the speed of the transaction account in processing the transaction requests can be further improved, the response time of the transaction requests can be reduced, and the user experience can be improved.
[0138] The present application also provides an application scenario, which applies the above-mentioned transaction processing method. Specifically, the application of the transaction processing method in the application scenario is as follows:
[0139] The application scenario of the present application can be a trading system that supports multi-data center multi-site active-active. The multi-site active-active system mainly follows the design principles of high throughput, high availability and easy scalability. It not only provides greater traffic processing capabilities and lower response latency, but also in the face of failures, the system can recover at the fastest speed to ensure that key services are always uninterrupted.
[0140] The trading system allocates a main data center (Base) to each account. Read and write requests are based on the data of the Base. If the Base fails, the Base of the account can be switched and trading services can continue to be provided to ensure the high availability of the account. At the same time, the system divides each account into several asset units (AU, Asset Unit). The total assets of the account are the sum of all asset units. According to the version number of the asset unit and the transaction information, the system can automatically repair the conflicting or missing data when each account switches the Base to ensure the consistency of the asset data. In addition, the system divides the data replication process into two layers. Each account uses a strong synchronization method between multiple copies in the same data center to prevent single point failures in the copies and ensure the availability and consistency of the account in a single data center. The data synchronization across data centers adopts an asynchronous method to prevent single point failures in the data center, ensure the efficiency of transaction execution and disaster recovery in multiple data centers. Combined with the above-mentioned data automatic repair function, the system can achieve a good balance between efficiency and disaster recovery.
[0141] By further splitting each account and dividing it into several asset units, each account can automatically repair conflicting or missing data when switching Base, thereby improving efficiency and ensuring the final consistency of asset data. In addition, each Base can serve multiple accounts and each account carries several asset units. Each asset unit can be traded, which improves the system's high throughput, high availability and scalability.
[0142] Specifically, the present application proposes a trading system that supports multi-data center multi-site active-active, which can be applicable to trading systems that require high throughput, remote disaster recovery and rapid automated recovery.
[0143] This application can be applied to disaster recovery scenarios in the same city or in different locations. The system assigns a Base to each account, and account-related transaction requests are connected to the corresponding Base. Each account has at least 3 copies in the Base. The 3 copies realize strong consistency data synchronization of single write and multiple reads. When a copy fails, the system will automatically complete the copy to the specified redundancy to ensure disaster recovery of data in a single data center. Due to the large network delay between different data centers, the data generated by the transaction will be synchronized to the other data centers in an asynchronous manner. Each account in the other data centers also has at least 3 copies. If the Base fails, the user's Base can be switched and transaction services can continue to be provided to ensure disaster recovery in different locations.
[0144] The present application can also be applied to the scenario of automatic repair of account data. The system divides each account into several asset units, which contain data such as version number and balance. When the base fails, all asset units of the account under the new base can continue to trade. When the original base is restored, the asset units with data conflicts in the account are checked, and the same root asset unit (RAU, Root AU) is found based on the version number and transaction information of the asset unit in the original base and the new base. Then, the difference data of the asset units is aligned. Since the asset unit granularity is smaller, the recovery is more accurate and faster, and no manual intervention is required, which can ensure the final consistency of the asset data.
[0145] In the specific implementation, the architecture of the trading system is as follows Figure 5 As shown, Figure 5The main data center of accounts A and B is Base1, and the main data center of account C is Base2. The accounts have 3 copies in each Base and execute a strong consistency protocol. The transaction information is transmitted asynchronously between Bases. At the same time, each account also has several asset units AU, where the core fields of the asset unit are: asset UID, account ID, balance Balance, version number Version, asset source ID (FID). The asset UID is its unique identifier. After each related transaction is executed, the AU balance is updated, the version number is updated, and the asset source ID is bound as the transaction ID. AUs under the same account can be sharded or merged, and the sharding or merging process can be understood as a special type of transaction. AU is the smallest unit of transaction, and the total assets of a user are the collection of all AUs under his account ID. AU can not only express the user's balance information, but also has the ability to trace back related transactions and version numbers. Each AU can be understood as a node on a chain structure, and each transaction related to AU can be understood as an edge of this structure, which continuously drives the update of AU.
[0146] In this system, accounts are distinguished by business. Account transactions of the same business are executed in the same base. Transactions can essentially be divided into recharges or transfers. A transaction is divided into an input asset set and an output asset set. The asset set contains several asset units. The input and output asset sets are bound to the transaction.
[0147] The process of transferring money from account A to account B is as follows:
[0148] Step (1) Account A selects an AU with sufficient balance a , transfer amount Amount, account B as the input of the transaction, and initiate the transaction.
[0149] Step (2) After the transaction is executed, two AUs will be generated: AU a 'With AU b , belonging to account A and account B respectively. AU a 'Deducted the balance and updated the asset source ID, AU b The newly generated AU belongs to account B, AU b The balance of AU a 'With AU b The version number is updated to the maximum value of Version in the transaction input AU set plus one.
[0150] Step (3) The transaction metadata (transaction ID, input set {AU a}、Output set {AU a ',AU b}) are saved in three copies of account A and account B respectively. After the three copies complete strong consistency synchronization, the transaction execution is completed and returned to the client.
[0151] Step (4) Base asynchronously synchronizes the transaction metadata to other data centers. After receiving the metadata, other data centers update the asset collection of internal accounts A and B.
[0152] The recharge process is similar to the transfer process, only adding new AU to an account.
[0153] The premise of disaster recovery in the same city is the above step (3), and the premise of disaster recovery in different regions is the above step (4). The following mainly analyzes disaster recovery in different regions. Assuming that Base1 of account A fails, the process of switching the service of account A to Base2 is as follows:
[0154] Step (4.1) When the upper-layer router finds that Base1 is unavailable, it switches the request traffic to Base2 and sets the main Base of account A to Base2. Account A continues to receive new transaction requests.
[0155] In step (4.2), the new transaction can immediately use all AUs of account A in Base2, and the AUs can be directly updated after the transaction is completed.
[0156] Because the data of account A in Base1 was previously backed up to the three copies of Base2 in an asynchronous manner, data inconsistency may occur when the Base is switched, which is manifested in abnormal situations such as insufficient account balance and expired AU version. The following mainly analyzes the automatic repair function of the system for data inconsistency. The premise for the activation of the automatic repair function is that the original Base is restored and the data can be read. If the original Base has been down or disconnected from the network, the difference data cannot be synchronized, and the data inconsistency will always exist. Another condition for automatic repair is that AU is not allowed to be merged before the recovery is completed. Now assume that the original Base1 is successfully restored at a certain time t in the future, and the automatic repair process is as follows:
[0157] Step (4.3) If the balance of account A is insufficient before time t (no AU has a balance greater than the transfer amount Amount), a special type of AU needs to be created for account A - virtual asset unit (VAU). The biggest difference between VAU and AU is that it will be marked as a negative asset by the system. When the system completes all data recovery, it will be forcibly merged with the normal AU. VAU still has the ability to backtrack, so account A can still continue to execute transactions. At this time, the input of this special transaction is account A (no AU is required), transfer amount Amount, account B; the output is {VAU a ,AU bAccount A is allowed to continue trading because Account A may have a recharge transaction in the original Base but it has not been synchronized.
[0158] Step (4.4): After time t, the original Base1 is restored successfully. Base2 will directly pull the latest version of AU data and transaction metadata of account A from Base1, and take the union of AUs with different asset UIDs; for AUs with the same asset UID, compare the AU version number Version and FID in turn, which are divided into the following situations:
[0159] (1) If Version1 = Version2 and FID1 = FID2, AU has no difference data and no processing is required.
[0160] (2) If the FIDs are equal, then the Versions must be equal. Therefore, there is no situation where Version1≠Version2 and FID1=FID2.
[0161] (3) If Version1 = Version2 and FID1≠FID2, AU1 and AU2 are traced back to the same RAU based on FID1 and FID2 respectively (i.e., Case 1). Fig. 9 As shown, each AU can find the specific transaction metadata through FID, and then find the previous version of AU, so AU1 and AU2 can continuously recurse to the same RAU. This solution can always trace back to the same RAU, because Base1 and Base2 have and only have difference data, and there must be a bifurcation point. After finding the bifurcation point, calculate the balance difference between AU1 and RAU of the original Base1. If the difference is greater than 0, create a new recharge transaction for account A to increase the balance of AU2. If the difference is less than 0, create a new liability transaction for account A. After the transaction is executed, a VAU will be created a , repair the difference asset data.
[0162] (4) If Version1≠Version2 and FID1≠FID2, roll back the AU with the larger Version until the Versions are equal, and then continue with 3).
[0163] After processing all AUs with the same asset UID in step (5), the system will merge the VAUs and AUs in the account. When AUs are merged, the balances are added, and when VAUs and AUs are merged, the balances are subtracted (the balance of AU must be greater than the balance of VAUs when merging). If there are VAUs that cannot be merged after the merger is completed, it means that the account is in arrears and subsequent transactions cannot be performed.
[0164] At this point, the account switching base and automated recovery process is complete. Step (3) of the automated recovery process allows the account to continue to provide trading services without being affected by the original base failure. At the same time, the recovery process of steps (4 and 5) is executed in the background without affecting normal trading. After step (5) is completed, the system will automatically determine whether the account can continue to trade.
[0165] The asset unit will be a smaller computable unit than the account. Since the asset unit is smaller, when data conflicts or missing occur in the account, it usually only occurs in a part of the asset units. The remaining asset units can be directly added or merged into the new Base. Therefore, the data to make up for the account difference can be directly restored from the granularity of the asset unit. There is no need to repeat the transaction during the recovery process, no manual intervention in the reconciliation, and no blocking of normal transactions. This recovery method can not only recover more accurately and faster, but also ensure the consistency of asset data. In addition, each Base can serve multiple accounts and each account carries several asset units. Each asset unit can be traded. In theory, it can improve the transaction throughput of each account and ensure the high availability and scalability of the system. The system adopts a combination of strong synchronization and asynchronous. Strong synchronization guarantees the data integrity of accounts in a single data center; asynchronous guarantees the availability of accounts when the Base is switched, and combines the automatic recovery function to ensure data consistency when the Base is switched.
[0166] It should be understood that, although the steps in the flowcharts involved in the above embodiments are displayed in sequence according to the indication of the arrows, these steps are not necessarily executed in sequence according to the order indicated by the arrows. Unless there is a clear explanation in this article, the execution of these steps is not strictly limited in order, and these steps can be executed in other orders. Moreover, at least a part of the steps in the flowcharts involved in the above embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily carried out in sequence, but can be executed in turn or alternately with other steps or at least a part of the steps or stages in other steps.
[0167] Based on the same inventive concept, the embodiment of the present application also provides a transaction processing device for implementing the transaction processing method involved above. The implementation solution provided by the device to solve the problem is similar to the implementation solution recorded in the above method, so the specific limitations in one or more transaction processing device embodiments provided below can refer to the limitations on the transaction processing method above, and will not be repeated here.
[0168] In one embodiment, Fig.10As shown, a transaction processing device 1000 is provided, comprising: a transaction account determination module 1002, a main data center determination module 1004, a transaction execution module 1006 and a data synchronization module 1008, wherein:
[0169] The transaction account determination module 1002 is used to determine the transaction account involved in the transaction in response to the transaction request, wherein the transaction account includes at least one asset unit, the asset unit carries a version identifier updated according to the transaction behavior, and the sum of the assets of each asset unit is used to represent the total asset amount of the transaction account;
[0170] A primary data center determination module 1004 is used to determine a primary data center for executing a transaction from among the data centers storing the asset units of the transaction account;
[0171] A transaction execution module 1006, configured to execute asset transactions according to the asset units in the primary data center to obtain transaction asset units with updated version identifiers;
[0172] The data synchronization module 1008 is used to synchronize the transaction asset unit to each of the data centers.
[0173] In some embodiments, when the transaction request is a transfer transaction request, the transaction account includes a transfer-in account and a transfer-out account; the transaction processing device 1000 further includes a target asset unit determination unit, which is used to determine a target asset unit participating in the transaction from the asset units of the transaction account based on the transaction asset amount requested by the transaction request; the asset amount of the target asset unit is greater than or equal to the transaction asset amount;
[0174] The transaction execution module 1006 is specifically used to execute asset transactions on the target asset unit according to the transaction asset amount, and generate an updated asset unit belonging to the transfer-out account and a newly added asset unit belonging to the transfer-in account; wherein the version identifier of the updated asset unit and the version identifier of the newly added asset unit are both associated with the version identifier of the target asset unit.
[0175] In some embodiments, the transaction processing device 1000 further includes a transaction metadata construction module, which is used to take the target asset unit involved in the transaction as a transaction input set, and take the updated asset unit and the newly added asset unit as a transaction output set; and construct transaction metadata including a transaction identifier representing the transaction behavior, the transaction input set, and the transaction output set;
[0176] The data synchronization module 1008 is specifically used to synchronize the transaction metadata to each of the data centers.
[0177] In some embodiments, when the transaction request is a recharge transaction request, the transaction account includes a transfer-in account; the transaction execution module 1006 is specifically used to execute asset transactions according to the transaction asset amount and generate a new asset unit belonging to the transfer-in account.
[0178] In some embodiments, each of the data centers includes multiple replicas; the transaction execution module 1006 is further used to determine, from the replicas of the primary data center, a primary replica for participating in the transaction and a secondary replica for synchronizing data; based on the target asset unit stored in the primary replica, execute the asset transaction to obtain a transaction asset unit with an updated version identifier;
[0179] The data synchronization module 1008 is further used to synchronize the transaction asset unit to each of the slave replicas.
[0180] In some of the embodiments, the primary data center determination module 1004 is specifically used to, when the transaction request is a transfer transaction request, use the data centers that match the transfer-in account and the transfer-out account as candidate data centers; and select the primary data center for executing the transaction from each of the candidate data centers.
[0181] In some of the embodiments, the primary data center determination module 1004 is specifically used to determine, from the data centers storing the asset units of the trading account, a first data center currently assigned to the trading account as the primary data center for executing transactions; to reallocate a second data center to the trading account when the primary data center is in an abnormal state; and to switch the primary data center for executing transactions to the second data center.
[0182] In some embodiments, the transaction processing device 1000 further includes a virtual asset unit creation module, which is used to create a virtual asset unit belonging to the transfer-out account in the second data center when the asset amount of each asset unit of the transfer-out account in the transaction account is less than the transaction asset amount;
[0183] The transaction execution module 1006 is specifically used to execute asset transactions according to the virtual asset units before the second data center completes the asset unit synchronization, and generate updated virtual asset units belonging to the transfer-in account and newly added asset units belonging to the transfer-in account; after the second data center completes the asset unit synchronization, the updated virtual asset units are merged with the synchronized asset units to generate updated asset units belonging to the transfer-out account.
[0184] In some of the embodiments, the transaction processing device 1000 also includes an asset unit synchronization module, which is used to receive a synchronous transaction asset unit sent by the first data center; when the first version identifier of the synchronous transaction asset unit is the same as the second version identifier of the actual transaction asset unit of the second data center, respectively obtain the first transaction identifier of the synchronous transaction asset unit and the second transaction identifier of the actual transaction asset unit; perform transaction backtracking based on the first transaction identifier and the second transaction identifier to obtain a root transaction asset unit with the same transaction identifier; and perform asset unit synchronization on the actual transaction asset unit based on the asset changes of the root transaction asset unit and the synchronous transaction asset unit.
[0185] In some of the embodiments, the asset unit synchronization module is also used to obtain a first version identifier of the synchronized transaction asset unit and a second version identifier of the actual transaction asset unit of the second data center; when the first version identifier is different from the second version identifier, determine the target asset unit with a larger number of updates between the first version identifier and the second version identifier; perform version rollback on the target asset unit to obtain a synchronized transaction asset unit and an actual transaction asset unit with the same version identifier.
[0186] In some of the embodiments, the transaction processing device 1000 also includes an asset unit sharding module, which is used to obtain the number of asset units in the transaction account in response to multiple transaction requests triggered concurrently for the same transaction account; when the number of asset units is less than the number of transaction requests, at least a part of the asset units of the transaction account are sharded to obtain multiple asset units used to process each of the transaction requests.
[0187] The above-mentioned transaction processing device, by dividing the transaction account into asset units, can directly process asset transactions at the granularity of the asset unit, which can effectively improve the concurrent processing volume of asset transaction processing. At the same time, the version identifier carried by the asset unit is updated according to the transaction behavior, and the transaction can be backtracked based on the version identifier between the synchronized transaction asset units in different data centers, so that the difference data of the account transaction can be directly restored from the granularity of the asset unit, which will not block the execution of other normal asset transactions, can improve the transaction throughput of each transaction account, ensure the high availability of the transaction process, and thus can effectively improve the transaction processing efficiency.
[0188] Each module in the above transaction processing device can be implemented in whole or in part by software, hardware or a combination thereof. Each module can be embedded in or independent of a processor in a computer device in the form of hardware, or can be stored in a memory in a computer device in the form of software, so that the processor can call and execute the operations corresponding to each module.
[0189] In one embodiment, a computer device is provided. The computer device may be a server, and its internal structure diagram may be as follows: Fig.11 As shown. The computer device includes a processor, a memory, an input / output interface (Input / Output, referred to as I / O) and a communication interface. The processor, the memory and the input / output interface are connected through a system bus, and the communication interface is connected to the system bus through the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system, a computer program and a database. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The database of the computer device is used to store data. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal through a network connection. When the computer program is executed by the processor, a transaction processing method is implemented.
[0190] In one embodiment, a computer device is provided. The computer device may be a terminal, and its internal structure diagram may be as follows: Fig.12 As shown. The computer device includes a processor, a memory, an input / output interface, a communication interface, a display unit and an input device. The processor, the memory and the input / output interface are connected via a system bus, and the communication interface, the display unit and the input device are connected to the system bus via the input / output interface. The processor of the computer device is used to provide computing and control capabilities. The memory of the computer device includes a non-volatile storage medium and an internal memory. The non-volatile storage medium stores an operating system and a computer program. The internal memory provides an environment for the operation of the operating system and the computer program in the non-volatile storage medium. The input / output interface of the computer device is used to exchange information between the processor and an external device. The communication interface of the computer device is used to communicate with an external terminal in a wired or wireless manner, and the wireless manner can be implemented through WIFI, a mobile cellular network, NFC (near field communication) or other technologies. When the computer program is executed by the processor, a transaction processing method is implemented. The display unit of the computer device is used to form a visually visible image, and can be a display screen, a projection device or a virtual reality imaging device. The display screen can be a liquid crystal display screen or an electronic ink display screen. The input device of the computer device can be a touch layer covered on the display screen, or a button, trackball or touchpad set on the computer device casing, or an external keyboard, touchpad or mouse, etc.
[0191] Those skilled in the art will understand that Fig.11The structure shown in or 12 is merely a block diagram of a partial structure related to the solution of the present application, and does not constitute a limitation on the computer device to which the solution of the present application is applied. The specific computer device may include more or fewer components than shown in the figure, or combine certain components, or have a different arrangement of components.
[0192] In one embodiment, a computer device is provided, including a memory and a processor, wherein a computer program is stored in the memory, and the processor implements the steps in the above-mentioned method embodiments when executing the computer program.
[0193] In one embodiment, a computer-readable storage medium is provided, on which a computer program is stored. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments are implemented.
[0194] In one embodiment, a computer program product is provided, including a computer program, which implements the steps in the above method embodiments when executed by a processor.
[0195] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in this application are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with relevant regulations.
[0196] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiment methods can be completed by instructing the relevant hardware through a computer program, and the computer program can be stored in a non-volatile computer-readable storage medium. When the computer program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, any reference to the memory, database or other medium used in the embodiments provided in the present application can include at least one of non-volatile and volatile memory. Non-volatile memory can include read-only memory (ROM), magnetic tape, floppy disk, flash memory, optical memory, high-density embedded non-volatile memory, resistive random access memory (ReRAM), magnetoresistive random access memory (MRAM), ferroelectric random access memory (FRAM), phase change memory (PCM), graphene memory, etc. Volatile memory can include random access memory (RAM) or external cache memory, etc. As an illustration and not limitation, RAM can be in various forms, such as static random access memory (SRAM) or dynamic random access memory (DRAM). The database involved in each embodiment provided in this application may include at least one of a relational database and a non-relational database. Non-relational databases may include distributed databases based on blockchains, etc., but are not limited to this. The processor involved in each embodiment provided in this application may be a general-purpose processor, a central processing unit, a graphics processor, a digital signal processor, a programmable logic device, a data processing logic device based on quantum computing, etc., but are not limited to this.
[0197] The technical features of the above embodiments may be arbitrarily combined. To make the description concise, not all possible combinations of the technical features in the above embodiments are described. However, as long as there is no contradiction in the combination of these technical features, they should be considered to be within the scope of this specification.
[0198] The above-described embodiments only express several implementation methods of the present application, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present application. It should be pointed out that, for a person of ordinary skill in the art, several variations and improvements can be made without departing from the concept of the present application, and these all belong to the protection scope of the present application. Therefore, the protection scope of the present application shall be subject to the attached claims.
Claims
1. A transaction processing method, characterized in that: The method comprises: In response to the transaction request, determining a transaction account participating in the transaction, wherein the transaction account includes at least one asset unit, the asset unit carries a version identifier updated according to the transaction behavior, and the sum of assets of each asset unit is used to represent the total asset amount of the transaction account; Determine a primary data center for executing the transaction from among the data centers storing the asset units of the transaction account; In the primary data center, executing asset transactions according to the asset units to obtain transaction asset units with updated version identifiers; The transaction asset unit is synchronized to each of the data centers.
2. The method according to claim 1, characterized in that In the case where the transaction request is a transfer transaction request, the transaction account includes a transfer-in account and a transfer-out account; and the method further includes: Based on the transaction asset amount requested by the transaction request, determine a target asset unit participating in the transaction from the asset units of the transaction account; the asset amount of the target asset unit is greater than or equal to the transaction asset amount; The performing of asset transactions according to the asset units to generate updated asset units with updated version identifiers includes: Performing asset transactions on the target asset units according to the transaction asset amount, generating updated asset units belonging to the transfer-out account and newly added asset units belonging to the transfer-in account; The version identifier of the updated asset unit and the version identifier of the newly added asset unit are both associated with the version identifier of the target asset unit.
3. The method according to claim 2, characterized in that The method further comprises: The target asset units involved in the transaction are used as a transaction input set, and the updated asset units and the newly added asset units are used as a transaction output set; Constructing transaction metadata including a transaction identifier characterizing the transaction behavior, the transaction input set, and the transaction output set; The step of synchronizing the transaction asset unit to each of the data centers includes: The transaction metadata is synchronized to each of the data centers.
4. The method according to claim 1, characterized in that: In the case where the transaction request is a recharge transaction request, the transaction account includes a transfer-in account; The performing of asset transactions according to the asset units to generate updated asset units with updated version identifiers includes: Execute asset transactions according to the transaction asset amount, and generate new asset units belonging to the transferred account.
5. The method according to claim 1, characterized in that Each of the data centers includes a plurality of replicas; The performing of asset transactions according to the asset units in the primary data center to obtain transaction asset units with updated version identifiers includes: Determine, from each replica of the primary data center, a primary replica for participating in the transaction and a secondary replica for synchronizing data; Based on the target asset unit stored in the master copy, execute asset transaction to obtain a transaction asset unit with an updated version identifier; After executing the asset transaction according to the asset unit in the primary data center to obtain the transaction asset unit with the updated version identifier, the method further includes: The transaction asset unit is synchronized to each of the slave replicas.
6. The method according to claim 1, characterized in that The determining, from among the data centers storing the asset units of the transaction account, a primary data center for executing the transaction, comprises: In the case where the transaction request is a transfer transaction request, the data centers that match the transfer-in account and the transfer-out account are used as candidate data centers; A primary data center for executing the transaction is selected from among the candidate data centers.
7. The method according to claim 1, characterized in that The determining, from among the data centers storing the asset units of the transaction account, a primary data center for executing the transaction, comprises: From among the data centers storing the asset units of the trading account, determine a first data center currently allocated to the trading account as a primary data center for executing the transaction; The method further comprises: When the primary data center is in an abnormal state, reassigning a second data center to the transaction account; The primary data center for executing the transaction is switched to the second data center.
8. The method according to claim 7, characterized in that The method further comprises: When the asset amount of each asset unit of the transfer-out account in the transaction account is less than the transaction asset amount, creating a virtual asset unit belonging to the transfer-out account in the second data center; The performing of asset transactions according to the asset units in the primary data center to obtain transaction asset units with updated version identifiers includes: Before the second data center completes the synchronization of the asset units, performing asset transactions according to the virtual asset units to generate updated virtual asset units belonging to the transfer-out account and newly added asset units belonging to the transfer-in account; After the second data center completes the synchronization of the asset units, the updated virtual asset unit is merged with the synchronized asset unit to generate an updated asset unit belonging to the transfer-out account.
9. The method according to claim 8, characterized in that The process of synchronizing the asset units of the second data center includes: Receiving a synchronous transaction asset unit sent by the first data center; When the first version identifier of the synchronous transaction asset unit is the same as the second version identifier of the actual transaction asset unit of the second data center, respectively acquiring the first transaction identifier of the synchronous transaction asset unit and the second transaction identifier of the actual transaction asset unit; Performing transaction backtracking based on the first transaction identifier and the second transaction identifier to obtain a root transaction asset unit with the same transaction identifier; Based on the asset changes of the root transaction asset unit and the synchronization transaction asset unit, the actual transaction asset unit is synchronized with the asset unit.
10. The method according to claim 9, characterized in that The method further comprises: Acquire a first version identifier of the synchronous transaction asset unit and a second version identifier of the actual transaction asset unit of the second data center; When the first version identifier is different from the second version identifier, determining a target asset unit having a larger number of updates between the first version identifier and the second version identifier; The target asset unit is version rolled back to obtain a synchronous transaction asset unit and an actual transaction asset unit with the same version identifier.
11. The method according to any one of claims 1 to 10, characterized in that The method further comprises: In response to multiple transaction requests triggered concurrently for the same transaction account, obtaining the number of asset units in the transaction account; In the case where the number of the asset units is less than the number of the transaction requests, at least a portion of the asset units of the transaction account are fragmented to obtain a plurality of asset units respectively used to process each of the transaction requests.
12. A transaction processing device, characterized in that: The device comprises: A transaction account determination module, configured to determine a transaction account participating in a transaction in response to a transaction request, wherein the transaction account includes at least one asset unit, the asset unit carries a version identifier updated according to the transaction behavior, and the sum of assets of each asset unit is used to represent the total asset amount of the transaction account; A primary data center determination module, used to determine a primary data center for executing transactions from data centers storing asset units of the transaction account; A transaction execution module, configured to execute asset transactions according to the asset units in the primary data center to obtain transaction asset units with updated version identifiers; A data synchronization module is used to synchronize the transaction asset unit to each of the data centers.
13. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method according to any one of claims 1 to 11 are implemented.
14. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.
15. A computer program product comprising a computer program, characterized in that When the computer program is executed by a processor, the steps of the method according to any one of claims 1 to 11 are implemented.
Citation Information
Cited By
Fund registration and transfer method and system based on distributed transaction mechanism
CN120258997A
Accounting request processing method and device of e-commerce platform consumer operation system, storage medium and computing equipment
CN121032487A