Distributed ledger data processing method and distributed ledger data processing system
By using distributed ledger data processing methods and the TCC framework, the scalability and performance limitations of a single Redis instance are solved, achieving account data consistency and efficient processing in high-concurrency scenarios, and improving the overall system performance and storage capacity.
Patent Information
- Application Number
- CN202210059196.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-01-19
- Publication Date
- 2026-01-09
- Estimated Expiration
- 2042-01-19
AI Technical Summary
In existing unified accounting systems, single Redis instances suffer from insufficient scalability and performance, as well as queuing issues caused by accounting blocking, especially under high concurrency conditions where there is a risk of request processing timeouts.
A distributed ledger data processing method is adopted, using the TCC (Try-Confirm-Cancel) framework to perform distributed ledger recording for multiple accounts in Redis. A successful accounting constraint and a locked amount mechanism are introduced for bidirectional balance growth scenarios. Account data is sharded and stored in different Redis instances using a hash algorithm to ensure the consistency of account data in high-concurrency scenarios.
It improved the system's processing power and storage capacity, increased the TPS of request processing, solved the distributed transaction problem, reduced the blocking of a single Redis instance, and ensured the consistency of account data.
Smart Images

Figure CN114841687B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of computer, in particular to a distributed accounting data processing method and a distributed accounting data processing system. BACKGROUND
[0002] In the existing unified accounting system, multiple accounts opened under the same account set exist in a single redis, where the unified account set is the same or similar business with correlation on business. The transactional single-thread processing of the single-deployed redis instance can maintain atomicity and data consistency, but at the same time, it also brings the following limitations:
[0003] (1) Poor scalability: since the data in a single account set is stored in the same redis instance, this sharding method makes redis horizontally unscalable for a single account set.
[0004] (2) Poor performance: limited by the performance and memory storage capacity bottleneck of a single redis instance, the system has an upper limit on TPS (Transactions Per Second) for a single account set, which is insufficient to meet the development of business. For account sets with large business volume, it will inevitably cause load imbalance among nodes in the redis cluster and insufficient resource utilization.
[0005] (3) Queuing caused by accounting blocking: based on business needs, there are accounting requests containing a large number of accounting details in practice. Since a single redis instance processes accounting requests in a single thread and serially, accounting requests with large number of details and long processing time cause blocking of redis, which will cause queuing of subsequent accounting requests when high concurrency occurs, and in severe cases, there is a risk of request processing timeout. SUMMARY
[0006] In view of the above problems, the present application aims to provide a distributed accounting data processing method and a distributed accounting data processing system with high scalability and high performance.
[0007] The distributed accounting data processing method of one aspect of the present application is characterized in that it is used for accounting for multiple distributed storage accounts, and comprises:
[0008] receiving an accounting request, the accounting request containing multiple accounting details corresponding to multiple accounts;
[0009] generating lock amount information on the account corresponding to the accounting detail when it is judged according to the pre-set first constraint rule that the accounting detail is successfully accounted for;
[0010] If all the accounting details corresponding to the accounting request are successfully accounted, make all the accounting details corresponding to the accounting request take effect on the corresponding account, and generate accounting result details corresponding to the accounting request;
[0011] If any of the accounting details corresponding to the accounting request is not successfully accounted, release the lock amount information of all the accounting details corresponding to the accounting request on the corresponding account.
[0012] Optionally, the generating of the lock amount information on the account corresponding to the accounting detail when it is judged that the accounting detail is successfully accounted according to the first constraint rule comprises:
[0013] judging whether the occurrence amount of the accounting detail is opposite to the balance information of the account corresponding to the accounting detail, if yes, accounting the accounting detail into the balance information, if no, the balance information remains unchanged;
[0014] when the balance information satisfies the first constraint rule, generating the lock amount information on the account corresponding to the accounting detail, and the accounting detail is successfully accounted.
[0015] Optionally, the balance information comprises: available balance, frozen amount, credit limit;
[0016] judging whether the occurrence amount of the accounting detail is opposite to the available limit of the account corresponding to the accounting detail, if yes, accounting the accounting detail into the available limit, if no, the available limit remains unchanged;
[0017] judging whether the occurrence amount of the accounting detail is opposite to the frozen amount of the account corresponding to the accounting detail, if yes, accounting the accounting detail into the frozen amount, if no, the frozen amount remains unchanged;
[0018] judging whether the occurrence amount of the accounting detail is opposite to the credit limit of the account corresponding to the accounting detail, if yes, accounting the accounting detail into the credit limit, if no, the credit limit remains unchanged;
[0019] Optionally, the first constraint rule comprises:
[0020] the available balance after accounting is not less than 0;
[0021] the frozen amount after accounting is not less than 0; and
[0022] the credit limit after accounting is not less than 0;
[0023] if the above conditions are satisfied at the same time, it is judged that the first constraint rule is satisfied.
[0024] Optionally, the making the all accounting details effective on the corresponding accounts comprises:
[0025] determining whether the occurrence amount of the accounting detail is opposite to the balance information of the account corresponding to the accounting detail, if the determination is no, then the accounting detail is accounted into the balance information, if the determination is yes, the balance information is unchanged; and
[0026] deleting the lock amount information of the accounting detail on the corresponding account.
[0027] Optionally, the making the all accounting details effective on the corresponding accounts comprises:
[0028] determining whether the occurrence amount of the accounting detail is opposite to the available balance of the account corresponding to the accounting detail, if the determination is no, then the accounting detail is accounted into the available balance, if the determination is yes, the available balance is unchanged;
[0029] determining whether the occurrence amount of the accounting detail is opposite to the frozen amount of the account corresponding to the accounting detail, if the determination is no, then the accounting detail is accounted into the frozen amount, if the determination is yes, the frozen amount is unchanged;
[0030] determining whether the occurrence amount of the accounting detail is opposite to the credit limit of the account corresponding to the accounting detail, if the determination is no, then the accounting detail is accounted into the credit limit, if the determination is yes, the credit limit is unchanged;
[0031] deleting the lock amount information of the accounting detail on the corresponding account.
[0032] Optionally, the releasing the lock amount information of all the accounting details corresponding to the accounting request on the corresponding accounts comprises:
[0033] determining whether the occurrence amount of the accounting detail is opposite to the balance information of the account corresponding to the accounting detail, if the determination is yes, then the negative value of the accounting detail is accounted into the balance information, if the determination is no, then the balance information is unchanged; and
[0034] deleting the lock amount information of the accounting detail on the corresponding account.
[0035] Optionally, the releasing the lock amount information of all the accounting details corresponding to the accounting request on the corresponding accounts comprises:
[0036] determining whether the occurrence amount of the accounting detail is opposite to the available balance of the account corresponding to the accounting detail, if the determination is yes, then the negative value of the accounting detail is accounted into the available balance, if the determination is no, then the available balance is unchanged; and
[0037] determining whether the occurrence amount of the accounting item is opposite to the frozen amount of the account corresponding to the accounting item, if the determination is yes, then the negative value of the accounting item is accounted into the frozen amount, if the determination is no, then the frozen amount remains unchanged; and
[0038] determining whether the occurrence amount of the accounting item is opposite to the credit limit of the account corresponding to the accounting item, if the determination is yes, then the negative value of the accounting item is accounted into the credit limit, if the determination is no, then the credit limit remains unchanged; and
[0039] deleting the lock amount information of the accounting item on the corresponding account.
[0040] Optionally, the distributed storage account is obtained by a hash algorithm to correspond to a block number, and the accounting data of the accounts corresponding to different block numbers are stored in different redis.
[0041] Optionally, the lock amount information on the account is a key-value pair stored in a lock amount hash table in the redis, and the key-value pair includes a sequence number of the accounting request, an available balance of the account, a lock frozen amount, a credit limit and time information.
[0042] The distributed accounting data processing device of one aspect of the present application is characterized in that the distributed accounting data processing device is used for accounting for a plurality of distributed storage accounts, comprising: a trial calculation module, a confirmation module and a release module,
[0043] The trial calculation module is used for receiving an accounting request, the accounting request includes a plurality of accounting items corresponding to a plurality of accounts, and the trial calculation module generates lock amount information on the account corresponding to the accounting item when the accounting item is successfully accounted according to the first constraint rule.
[0044] The confirmation module is used for making all accounting items corresponding to the accounting request effective on the corresponding account and generating an accounting result item corresponding to the accounting request when all accounting items corresponding to the accounting request are successfully accounted.
[0045] The release module is used for releasing the lock amount information of all accounting items corresponding to the accounting request on the corresponding account when any accounting item corresponding to the accounting request is not successfully accounted.
[0046] Optionally in the trial module, it is judged whether the occurrence amount of the accounting item is opposite to the balance information of the account corresponding to the accounting item, if yes, the accounting item is accounted into the balance information, if no, the balance information remains unchanged; when the balance information satisfies the first constraint rule, the locking amount information is generated on the account corresponding to the accounting item, and the accounting item is successfully accounted.
[0047] Optionally, the balance information comprises: available balance, frozen amount, credit limit;
[0048] In the trial module,
[0049] It is judged whether the occurrence amount of the accounting item is opposite to the available limit of the account corresponding to the accounting item, if yes, the accounting item is accounted into the available limit, if no, the available limit remains unchanged;
[0050] It is judged whether the occurrence amount of the accounting item is opposite to the frozen amount of the account corresponding to the accounting item, if yes, the accounting item is accounted into the frozen amount, if no, the frozen amount remains unchanged;
[0051] It is judged whether the occurrence amount of the accounting item is opposite to the credit limit of the account corresponding to the accounting item, if yes, the accounting item is accounted into the credit limit, if no, the credit limit remains unchanged;
[0052] Optionally, the first constraint rule comprises:
[0053] The available balance after accounting is not less than 0;
[0054] The frozen amount after accounting is not less than 0; and
[0055] The credit limit after accounting is not less than 0;
[0056] If the above conditions are simultaneously satisfied, it is determined that the first constraint rule is satisfied.
[0057] Optionally in the confirmation module, it is judged whether the occurrence amount of the accounting item is opposite to the balance information of the account corresponding to the accounting item, if no, the accounting item is accounted into the balance information, if yes, the balance information remains unchanged; and
[0058] The locking amount information of the accounting item on the corresponding account is deleted.
[0059] Optionally in the confirming module, it is judged whether the occurrence amount of the accounting item is opposite to the available balance of the account corresponding to the accounting item, if not, the accounting item is accounted into the available balance, if yes, the available balance remains unchanged;
[0060] It is judged whether the occurrence amount of the accounting item is opposite to the frozen amount of the account corresponding to the accounting item, if not, the accounting item is accounted into the frozen amount, if yes, the frozen amount remains unchanged;
[0061] It is judged whether the occurrence amount of the accounting item is opposite to the credit limit of the account corresponding to the accounting item, if not, the accounting item is accounted into the credit limit, if yes, the credit limit remains unchanged;
[0062] The locked amount information of the accounting item on the corresponding account is deleted.
[0063] Optionally in the releasing module, it is judged whether the occurrence amount of the accounting item is opposite to the balance information of the account corresponding to the accounting item, if yes, the negative value of the accounting item is accounted into the balance information, if not, the balance information remains unchanged; and the locked amount information of the accounting item on the corresponding account is deleted.
[0064] Optionally in the releasing module, it is judged whether the occurrence amount of the accounting item is opposite to the available balance of the account corresponding to the accounting item, if yes, the negative value of the accounting item is accounted into the available balance, if not, the available balance remains unchanged; it is judged whether the occurrence amount of the accounting item is opposite to the frozen amount of the account corresponding to the accounting item, if yes, the negative value of the accounting item is accounted into the frozen amount, if not, the frozen amount remains unchanged; it is judged whether the occurrence amount of the accounting item is opposite to the credit limit of the account corresponding to the accounting item, if yes, the negative value of the accounting item is accounted into the credit limit, if not, the credit limit remains unchanged; and the locked amount information of the accounting item on the corresponding account is deleted.
[0065] Optionally the distributed storage account obtains the corresponding block number through a hash algorithm, and the accounting data of the accounts corresponding to different block numbers are stored in different redis.
[0066] Optionally the locked amount information on the account is a key-value pair stored in a locked amount hash table in the redis, and the key-value pair includes the sequence number of the accounting request, the available balance, the frozen amount, the credit limit and time information of the account.
[0067] The computer readable medium of the present application, on which a computer program is stored, realizes the distributed accounting data processing method when the computer program is executed by a processor.
[0068] The computer equipment of the present application comprises a memory, a processor, and a computer program stored on the memory and executable on the processor, and the execution of the computer program enables the processor to realize the distributed accounting data processing method when the computer program is executed.
[0069] As described above, the distributed accounting data processing method of the present application adopts a distributed architecture, uses a TCC (Try-Confirm-Cancel) framework to replace the original single transaction accounting logic in a single redis, and uses a two-way growth balance scenario to introduce an accounting success constraint and a locked amount mechanism, which can ensure the consistency of account data in a high concurrency scenario, improve the system processing capacity, and solve the problem of distributed transactions caused by changes in data sharding rules. Therefore, the distributed accounting data processing method and device of the present application can improve the overall performance and storage capacity of the system, improve the TPS of various request processing, and significantly shorten the blocking of a single redis instance by accounting in multiple redis instances. BRIEF DESCRIPTION OF DRAWINGS
[0070] Figure 1 is the accounting logic diagram of the distributed accounting data system of the present application.
[0071] Figure 2 is the flowchart of the distributed accounting data processing method of the present application.
[0072] Figure 3 is the flowchart of the specific process of the Try phase.
[0073] Figure 4 is the flowchart of the specific process of the Confirm phase.
[0074] Figure 5 is the flowchart of the specific process of the Cancel phase.
[0075] Figure 6 is the structure block diagram of the distributed accounting data processing device of the present application. DETAILED DESCRIPTION
[0076] The following describes some of the multiple embodiments of the present application, which aims to provide a basic understanding of the present application. It is not intended to identify key or decisive elements or limit the scope of protection.
[0077] For the sake of brevity and clarity, the principles of the application are described herein primarily in reference to exemplary embodiments thereof. However, those skilled in the art will readily appreciate that the same principles apply equally to all types of distributed ledger data processing methods, and that these same principles can be implemented therein, and that any such variations do not depart from the true spirit and scope of the present patent application.
[0078] Moreover, in the following description, reference is made to the accompanying drawings which form a part hereof, and in which are shown, by way of illustration, specific embodiments. Changes in the electric, mechanical, logical, and structural details can be made to these embodiments without departing from the spirit and scope of the application. Additionally, although a feature can be disclosed in connection with only one embodiment / implementation, one or more of the features can be combined with other embodiments / implementations. Thus, the description below is not to be taken in a limiting sense, and the scope of the present application is defined by the appended claims and their equivalents.
[0079] The terms such as "have" and "include" mean that there are no other elements (modules and steps) in addition to the elements (modules and steps) directly or explicitly expressed in the specification and claims, and the technical solutions of the present application do not exclude the presence of other elements (modules and steps) not directly or explicitly expressed.
[0080] Before describing the distributed ledger data processing method of the present application, some technical terms in the art are described.
[0081] There are currently four balance domains in the unified accounting system account, namely, balance, frozen amount, credit limit, and available balance. Among them, the available balance is determined by the other three balances, that is, it can be expressed as: available balance = balance + credit limit - frozen amount. Correspondingly, three pairs of mutually opposite accounting operations are supported for the account, namely, credit occurrence / debit occurrence, freezing / thawing, and credit increase / credit decrease.
[0082] Among them, the effects of the accounting operation on the four balance domains are as follows:
[0083] Credit occurrence: if the account balance is credit, the balance will increase positively, so the available balance will increase positively; if the account balance is debit, the balance will decrease negatively, so the available balance will decrease negatively.
[0084] Debit occurrence: if the account balance is debit, the balance will increase positively, so the available balance will increase positively; if the account balance is credit, the balance will decrease negatively, so the available balance will decrease negatively.
[0085] Freezing: the frozen amount will increase positively, so the available balance will decrease negatively.
[0086] Unfreeze: make the frozen amount negative, so the available balance positive.
[0087] Credit increase: make the credit limit positive, so the available balance positive.
[0088] Credit decrease: make the credit limit negative, so the available balance negative.
[0089] The sufficiency of the balance determines whether the accounting of the account can be successful.
[0090] The distributed accounting data processing method of the present application adopts a distributed architecture and uses a TCC (Try-Confirm-Cancel) framework for distributed accounting of accounts in multiple redis, instead of the original single transaction accounting logic in a single redis. In addition, the distributed accounting data processing method of the present application also introduces an accounting success constraint and a locked amount mechanism in the context of bidirectional growth of the balance, to ensure the consistency of account data in a high-concurrency scenario, while improving the system processing capacity and solving the problem of distributed transactions caused by changes in data sharding rules.
[0091] The business logic of the existing unified accounting system requires transactionality of the processing results of all accounting details in a single accounting request, i.e., consistency of the accounting results of all accounts involved in the accounting request (all accounts are successfully accounted or all accounts fail to be accounted). In the existing technical architecture, since all data of the same account set are distributed in the same redis, the single-threaded execution of the accounting lua script by redis can ensure the atomicity of each accounting processing in multiple concurrent accounting, thereby ensuring the consistency of all accounting details and the accounting status of all accounts in the accounting request.
[0092] Figure 1 is the accounting logic diagram of the distributed accounting data system of the present application.
[0093] As shown in Figure 1 In the distributed accounting data processing method of the present application, the sharding of data in redis is based on the block number block_id in terms of technical meaning. In the distributed accounting data processing method of the present application, the block number block_id is calculated by a hash algorithm from the key of redis data.
[0094] In this way, in the present application, since the sharding basis is changed, each account under the same account set is distributed in different redis instances in the cluster. Since the complete accounting operation of the accounting request is no longer executed by the single thread of the same redis instance as in the existing technology described above, there is inevitably a problem of distributed transactions when multiple accounting requests are processed concurrently.
[0095] For such distributed transaction problems, the TCC (Try-Confirm-Cancel) mode is adopted in the distributed accounting data processing method of the present application, and at the same time, the accounting success constraint mechanism and the locking amount mechanism in the bidirectional growth scene of the available balance, the frozen amount, and the credit limit of three balance domains are introduced.
[0096] In the distributed accounting data processing method of the present application, the definition of the accounting success constraint mechanism is as follows:
[0097] After the trial accounting is completed, the balance of the account needs to meet the following conditions:
[0098] 1) The available balance after accounting is not less than 0;
[0099] 2) The frozen amount after accounting is not less than 0; and
[0100] 3) The credit limit after accounting is not less than 0;
[0101] If the above conditions are met at the same time, it is determined to pass, otherwise it is not passed.
[0102] Since there may be multiple accounting details for the same account in one accounting request, the determination of the accounting success constraint is based on the cumulative minimum value of each field in the sequential accounting process of the multiple accounting details of the account. For example: if the initial balance of a certain account in a certain balance domain before accounting is A, the accounting details of the account for this balance are +1, -2, and +3 in sequence, and the cumulative values of this balance during the accounting process are A+1, A-1, and A+2 in sequence, then the minimum value A-1 is used for trial calculation.
[0103] The mechanism of the locking amount is defined as follows:
[0104] The locking amount represents the amount of the corresponding balance occupied by the accounting during the processing process, and its value is equal to the change amount generated by the accounting on the corresponding balance domain. In redis, the locking amount exists in the form of the key-value pair of "accounting request ID->locking available balance: locking frozen amount: locking credit limit: timestamp" in the locking amount hash table of the account.
[0105] Figure 2 is the flowchart of the distributed accounting data processing method of the present application.
[0106] As Figure 2 shown, the distributed accounting data processing method of the present application adopts the TCC (Try-Confirm-Cancel) mode, which can be divided into three stages: the Try stage (trial stage) S100, the Confirm stage (confirmation stage) S200, and the Cancel stage (release stage) S300.
[0107] Specifically, as shown in Figure 2 The distributed accounting data processing method of the present application is used for accounting for a plurality of distributed stored accounts, and the method comprises:
[0108] Try stage (trial stage) S100: all accounts involved in the accounting request are traversed, and all accounting details of the account are tried according to the accounting success constraint to determine whether they can be successfully accounted, and if so, lock amount information is generated on the account corresponding to the accounting details, that is, the corresponding resources (balance) are occupied by using the lock amount. The success of this stage is marked by the generation of lock amount information;
[0109] Confirm stage (confirmation stage) S200: if all accounts involved in the accounting request are successful in the Try stage, the Confirm stage is executed, all accounting request details corresponding to the accounting request are made effective on the corresponding account, that is, all resource changes are made effective, and accounting result details corresponding to the accounting request are generated. This stage is marked by the generation of accounting result details; and
[0110] Cancel stage (release stage) S300: if any account involved in the accounting request fails in the Try stage, the Cancel stage is executed, and the lock amount information of all accounting details corresponding to the accounting request on the corresponding account is released, that is, the resources (balance) occupied on the corresponding account are released.
[0111] Next, the Try stage (trial stage), the Confirm stage (confirmation stage), and the Cancel stage (release stage) are described in detail.
[0112] Figure 3 is a flowchart showing the specific flow of the Try stage (trial stage).
[0113] In the Try stage of each account, if the accounting makes the available balance, the frozen amount, and the credit limit of the account grow in the direction of 0 (where "the available balance, the frozen amount, and the credit limit grow in the direction of 0" actually means "the available balance, the frozen amount, and the credit limit decrease") under the premise of meeting the accounting success constraint, the balance will be changed accordingly, otherwise the balance change is 0. Then the balance change of the request is recorded in the lock available balance, the lock frozen amount, and the lock credit limit corresponding to the account lock amount hash table.
[0114] As shown in Figure 3 The specific flow of the Try stage comprises:
[0115] S101: determine whether the occurrence amount of the accounting details of the account has been generated, if yes, go to step S111, if not, continue step S102;
[0116] S102: Determine whether the lock amount of the accounting request has been generated. If yes, go to step S111. If no, continue with step S103;
[0117] S103: Determine whether all accounting details processing is completed. If yes, go to step S110. If no, continue with step S104;
[0118] S104: Determine whether the occurrence and the balance of the accounting details are reversed. If yes, continue with step S105. If no, continue with step S106. Here, "reversed with the balance" refers to the direction of growth to 0;
[0119] S105: The balance change value is equal to the occurrence;
[0120] S106: The balance change value is equal to 0;
[0121] S107: Accumulate the change value into the balance;
[0122] S108: Determine whether the accumulated balance meets the accounting success constraint. If yes, return to step S103. If no, continue with step S109;
[0123] S109: Try fails;
[0124] S110: The balance change amount is written into the lock amount, that is, the lock amount information is generated;
[0125] S111: Try succeeds.
[0126] Figure 4 is a flowchart showing the specific flow of the Confirm phase (confirmation algorithm phase).
[0127] In the Confirm phase of each account, after confirming that the lock amount of the accounting in the account is recorded, the change of the balance includes:
[0128] Determine whether the occurrence of the accounting details is reversed with the available balance of the account corresponding to the accounting details. If the determination is no, the accounting details are accounted into the available balance. If the determination is yes, the available balance remains unchanged;
[0129] Determine whether the occurrence of the accounting details is reversed with the frozen amount of the account corresponding to the accounting details. If the determination is no, the accounting details are accounted into the frozen amount. If the determination is yes, the frozen amount remains unchanged;
[0130] Determine whether the occurrence of the accounting details is reversed with the credit limit of the account corresponding to the accounting details. If the determination is no, the accounting details are accounted into the credit limit. If the determination is yes, the credit limit remains unchanged;
[0131] deleting the locked amount information of the accounting details on the corresponding account.
[0132] As shown in FIG. 6, the specific process of the Confirm stage includes: Figure 4
[0133] S201: judging whether the occurrence of the accounting details of the account has been generated, if yes, jumping to step S210, if not, continuing step S202;
[0134] S202: judging whether the locked amount of the accounting request has been generated, if yes, continuing step S203, if not, jumping to step S211;
[0135] S203: judging whether all the accounting details have been processed, if yes, jumping to step S208, if not, continuing step S204;
[0136] S204: judging whether the occurrence and the balance of the accounting details are reversed, if yes, continuing step S205, if not, continuing step S206;
[0137] S205: the balance change value is equal to 0;
[0138] S206: the balance change value is equal to the occurrence;
[0139] S207: accumulating the change value into the balance;
[0140] S208: deleting the locked amount;
[0141] S209: making all the accounting details corresponding to the accounting request take effect on the corresponding account and generating the accounting result details corresponding to the accounting request;
[0142] S210: Confirm success;
[0143] S211: Confirm failure.
[0144] Figure 5 is a flowchart showing the specific process of the Cancel stage.
[0145] In the Cancel stage of each account, after confirming that the locked amount of the accounting is recorded in the account, the previous balance change is rolled back, including: judging whether the occurrence of the accounting details is reversed with the available balance of the account corresponding to the accounting details, if yes, accounting the negative value of the accounting details into the available balance, if not, the available balance remains unchanged;
[0146] Determine whether the amount of the transaction in the accounting details is opposite to the frozen amount of the account corresponding to the accounting details. If the determination is yes, then the negative value of the accounting details is recorded into the frozen amount. If the determination is no, then the frozen amount remains unchanged.
[0147] Determine whether the transaction amount of the accounting details is opposite to the credit limit of the account corresponding to the accounting details. If the determination is yes, then the negative value of the accounting details is recorded in the credit limit; if the determination is no, then the credit limit remains unchanged.
[0148] Delete the locked amount information of the aforementioned accounting details in the corresponding account.
[0149] like Figure 5 As shown, the specific process of the Cancel stage includes:
[0150] S301: Determine whether the lock amount requested by the account has been generated. If not, proceed to step S308. If yes, continue to step S302.
[0151] S302: Determine whether all accounting details have been processed. If yes, proceed to step S307; otherwise, continue to step S303.
[0152] S303: Determine whether the transaction amount and balance of the accounting details are reversed. If yes, continue to step S304; otherwise, continue to step S305.
[0153] S304: The change in balance equals the amount transacted;
[0154] S305: The change in balance is equal to 0;
[0155] S306: Accumulate the changes into the balance;
[0156] S307: Delete locked amount;
[0157] S308: Success.
[0158] The information, balance, locked amount, and accounting details related to a specific account are all stored in the same Redis instance according to the block number (block_id) obtained from the account hash. Therefore, Try, Confirm, and Cancel operations for a single account are executed by calling the Lua script loaded in Redis within the single Redis instance containing that account, thus ensuring the atomicity of account data operations and the consistency of the account balance before and after execution.
[0159] The three stages of Try, Confirm and Cancel of the account are guaranteed to be equal (the equal is to ensure that the user has only one result no matter whether the operation is repeated, so as to ensure that the required data is only responded to once) by judging whether the lock amount and the occurrence of the accounting details exist before execution, so as to prevent the wrong judgment and repeated accounting of the TCC logic on the accounting state of the account in the case of abnormal conditions such as redo after the request processing is interrupted.
[0160] The distributed accounting data processing method of the application adopts a distributed architecture, uses a TCC (Try-Confirm-Cancel) framework to perform distributed accounting of accounts in multiple redis, instead of the original single transaction accounting logic in a single redis. In the distributed accounting data processing method of the application, an accounting success constraint and a lock amount mechanism in a bidirectional growth balance scenario are introduced to ensure the consistency of account data in a high concurrency scenario, while improving the processing capacity of the system and solving the problem of distributed transactions caused by changes in data sharding rules.
[0161] The above describes the distributed accounting data processing method of the application, and then the distributed accounting data processing system of the application is described.
[0162] Figure 6 is a structure block diagram of the distributed accounting data processing device of the application.
[0163] As shown in Figure 6 , the distributed accounting data processing device of the application is used for accounting for a plurality of distributed storage accounts, and includes a trial module 100, a confirmation module 200 and a release module 300.
[0164] The trial module 100 is used for receiving an accounting request, the accounting request including a plurality of accounting details corresponding to a plurality of accounts, and the trial module 100 generates lock amount information on the accounts corresponding to the accounting details when the accounting details are determined to be successful according to a pre-set first constraint rule.
[0165] The confirmation module 200 is used for making all accounting details corresponding to the accounting request take effect on the corresponding accounts and generating accounting result details corresponding to the accounting request when all accounting details corresponding to the accounting request are successful.
[0166] The release module 300 is used for releasing the lock amount information of all accounting details corresponding to the accounting request on the corresponding accounts when any accounting detail corresponding to the accounting request is not successful.
[0167] The account data is divided into blocks and distributed to multiple redis for processing. The block number is calculated by a hash algorithm based on the key of the redis data. For the same account, the balance, locked amount, and accounting details are stored in the same redis according to the block number of the account number. The trial module 100, the confirmation module 200, and the release module 300 are executed in the single redis instance of the account by calling the lua script loaded in the redis.
[0168] The trial module 100 performs the following actions:
[0169] The trial module 100 performs the following actions:
[0170] The locked amount represents the amount of the corresponding balance occupied by the accounting during processing.
[0171] The balance information includes available balance, frozen amount, and credit limit.
[0172] In the trial module 100, the trial module 100 determines whether the occurrence of the accounting details is opposite to the available limit of the account corresponding to the accounting details. If the determination is yes, the accounting details are accounted into the available limit. If the determination is no, the available limit remains unchanged.
[0173] The trial module 100 determines whether the occurrence of the accounting details is opposite to the frozen amount of the account corresponding to the accounting details. If the determination is yes, the accounting details are accounted into the frozen amount. If the determination is no, the frozen amount remains unchanged.
[0174] The trial module 100 determines whether the occurrence of the accounting details is opposite to the credit limit of the account corresponding to the accounting details. If the determination is yes, the accounting details are accounted into the credit limit. If the determination is no, the credit limit remains unchanged.
[0175] Optionally, the first constraint rule includes:
[0176] The available balance after accounting is not less than 0.
[0177] The frozen amount after accounting is not less than 0.
[0178] The credit limit after accounting is not less than 0.
[0179] If the above conditions are met at the same time, it is determined that the first constraint rule is met.
[0180] In the redis, the locked amount corresponding to the account block number exists,
[0181] The locked amount includes a locked available balance, a locked frozen amount, and a locked credit limit.
[0182] In the confirmation module 200, it is determined whether the occurrence of the accounting details is opposite to the balance information of the account corresponding to the accounting details. If it is determined that no, the accounting details are accounted into the balance information, if it is determined that yes, the balance information is unchanged; and the locked amount information of the accounting details on the corresponding account is deleted.
[0183] In the confirmation module 200, it is determined whether the occurrence of the accounting details is opposite to the available balance of the account corresponding to the accounting details. If it is determined that no, the accounting details are accounted into the available balance, if it is determined that yes, the available balance is unchanged;
[0184] It is determined whether the occurrence of the accounting details is opposite to the frozen amount of the account corresponding to the accounting details. If it is determined that no, the accounting details are accounted into the frozen amount, if it is determined that yes, the frozen amount is unchanged;
[0185] It is determined whether the occurrence of the accounting details is opposite to the credit limit of the account corresponding to the accounting details. If it is determined that no, the accounting details are accounted into the credit limit, if it is determined that yes, the credit limit is unchanged;
[0186] The locked amount information of the accounting details on the corresponding account is deleted.
[0187] The release module 300 is set to perform the following actions:
[0188] It is determined whether the occurrence of the accounting details is opposite to the balance information of the account corresponding to the accounting details. If it is determined that yes, the negative value of the accounting details is accounted into the balance information, if it is determined that no, the balance information is unchanged; and the locked amount information of the accounting details on the corresponding account is deleted.
[0189] Optionally, in the release module 300, it is judged whether the occurrence amount of the accounting item is opposite to the available balance of the account corresponding to the accounting item, if yes, the negative value of the accounting item is accounted into the available balance, if no, the available balance remains unchanged; it is judged whether the occurrence amount of the accounting item is opposite to the frozen amount of the account corresponding to the accounting item, if yes, the negative value of the accounting item is accounted into the frozen amount, if no, the frozen amount remains unchanged; it is judged whether the occurrence amount of the accounting item is opposite to the credit limit of the account corresponding to the accounting item, if yes, the negative value of the accounting item is accounted into the credit limit, if no, the credit limit remains unchanged; and the lock amount information of the accounting item on the corresponding account is deleted.
[0190] Among them, the distributed storage account obtains the corresponding block number through a hash algorithm, and the accounting data of the accounts corresponding to different block numbers are stored in different redis.
[0191] And the lock amount information on the account is a key-value pair stored in the lock amount hash table in the redis, the key-value pair contains the sequence number of the accounting request, the available balance, the frozen amount, the credit limit and the time information of the account.
[0192] The distributed accounting data processing method and device of the application can achieve the following technical effects:
[0193] (1) High scalability:
[0194] The performance and memory storage capacity of a single redis instance can be broken through by horizontal expansion of the redis instance to limit any account set, improving the overall performance and storage capacity of the system. In theory, the overall performance and storage capacity of the system are linearly related to the number of redis instances in the system, and the horizontal expansion of the redis instance is not sensitive to the unified accounting system application and the external business system accessing the unified accounting system. Moreover, the system still retains the original ability to split data by account set: when necessary, the account set data can be independently split into an independent redis cluster to avoid the mutual influence of performance or capacity caused by sharing with other account sets.
[0195] (2) High performance:
[0196] In the application, the TPS of various request processing for any account set will be greatly improved compared with the prior art, the memory pressure of a single redis instance is eliminated, the load imbalance between redis instances is greatly alleviated, and the redis computing power and storage resources are more fully utilized.
[0197] (3) Fragmentation of accounting request processing:
[0198] In the present application, a large number of accounting requests are accounted in multiple redis instances, a single accounting request is fragmented, the blocking of a single redis instance is greatly shortened, multiple requests are executed in parallel in high concurrency, and the queuing of the requests is thus alleviated.
[0199] The above examples mainly illustrate the distributed accounting data processing method and device of the present application. Although only some specific embodiments of the present application are described, it should be understood by those skilled in the art that the present application can be implemented in many other forms without departing from the spirit and scope of the present application. Therefore, the examples and embodiments shown are considered illustrative rather than limiting, and the present application can encompass various modifications and alternatives without departing from the spirit and scope of the present application as defined by the appended claims.
Claims
1. A distributed ledger data processing method, characterized in that, This distributed ledger data processing method is used to perform ledger entries for multiple distributed storage accounts, including: The trial calculation step involves receiving a posting request, which includes multiple posting details corresponding to multiple accounts. When the accounting detail is successfully recorded according to the pre-set first constraint rule, a locked amount information is generated in the account corresponding to the accounting detail. In the confirmation step, if all accounting details corresponding to the accounting request are successfully recorded, all accounting details corresponding to the accounting request are made effective on the corresponding account, and accounting result details corresponding to the accounting request are generated. In the release step, if any accounting detail corresponding to the accounting request fails to be posted, the locked amount information of all accounting details corresponding to the accounting request in the corresponding account is released. Specifically, the accounting data for multiple accounts is divided into chunks using chunk numbers and then distributed to multiple Redis instances for processing. These chunk numbers are calculated from the Redis data keys using a hash algorithm. For the same account, the balance, locked amount, and detailed accounting results are stored in the same Redis instance according to the account's block number. For the same account, the trial calculation step, the confirmation step, and the release step are all executed by calling a Lua script loaded in Redis within the single Redis instance containing that account. Specifically, in the trial calculation step, when the accounting detail is successfully posted according to a pre-set first constraint rule, generating locked amount information on the account corresponding to the accounting detail includes: Determine whether the transaction amount of the accounting details is reversed with the balance information of the account corresponding to the accounting details. If the determination is yes, then the accounting details are recorded into the balance information. If the determination is no, then the balance information remains unchanged. When the balance information meets the first constraint rule, a locked amount is generated on the account corresponding to the accounting details, and the accounting details are successfully recorded.
2. The distributed ledger data processing method as described in claim 1, characterized in that, The balance information includes: available balance, frozen amount, and credit limit; Determine whether the transaction amount of the accounting details is opposite to the available credit limit of the account corresponding to the accounting details. If the determination is yes, then the accounting details are recorded into the available credit limit. If the determination is no, then the available credit limit remains unchanged. Determine whether the transaction amount of the accounting details is opposite to the frozen amount of the account corresponding to the accounting details. If the determination is yes, then the accounting details are recorded into the frozen amount. If the determination is no, then the frozen amount remains unchanged. Determine whether the transaction amount of the accounting details is opposite to the credit limit of the account corresponding to the accounting details. If the determination is yes, then the accounting details are recorded into the credit limit. If the determination is no, then the credit limit remains unchanged.
3. The distributed ledger data processing method as described in claim 2, characterized in that, The first constraint rule includes: The available balance after accounting is not less than 0; The amount frozen after accounting shall not be less than 0; and After accounting, the credit limit shall not be less than 0; If both conditions are met, then the first constraint rule is deemed to be satisfied.
4. The distributed ledger data processing method as described in claim 1, characterized in that, The step of making all the accounting details effective on the corresponding accounts includes: Determine whether the transaction amount of the accounting details is reversed compared to the balance information of the account corresponding to the accounting details. If the determination is no, then the accounting details are recorded into the balance information; if the determination is yes, the balance information remains unchanged. Delete the locked amount information of the aforementioned accounting details in the corresponding account.
5. The distributed ledger data processing method as described in claim 2, characterized in that, The step of making all the accounting details effective on the corresponding accounts includes: Determine whether the transaction amount of the accounting details is reversed with the available balance of the account corresponding to the accounting details. If the determination is no, then the accounting details are recorded into the available balance. If the determination is yes, the available balance remains unchanged. Determine whether the transaction amount of the accounting details is opposite to the frozen amount of the account corresponding to the accounting details. If the determination is no, then the accounting details are recorded into the frozen amount. If the determination is yes, the frozen amount remains unchanged. Determine whether the transaction amount of the accounting details is opposite to the credit limit of the account corresponding to the accounting details. If the determination is no, then the accounting details are recorded into the credit limit. If the determination is yes, the credit limit remains unchanged. Delete the locked amount information of the aforementioned accounting details in the corresponding account.
6. The distributed ledger data processing method as described in claim 1, characterized in that, The release of the locked amount information of all accounting details corresponding to the accounting request in the corresponding account includes: Determine whether the transaction amount of the accounting detail is reversed compared to the balance information of the account corresponding to the accounting detail. If the determination is yes, then the negative value of the accounting detail is recorded in the balance information; if the determination is no, then the balance information remains unchanged. Delete the locked amount information of the aforementioned accounting details in the corresponding account.
7. The distributed ledger data processing method as described in claim 3, characterized in that, The release of the locked amount information of all accounting details corresponding to the accounting request in the corresponding account includes: The system determines whether the transaction amount of the accounting detail is opposite to the available balance of the account corresponding to the accounting detail. If yes, the negative value of the accounting detail is recorded in the available balance; if no, the available balance remains unchanged. It also determines whether the transaction amount of the accounting detail is opposite to the frozen amount of the account corresponding to the accounting detail. If yes, the negative value of the accounting detail is recorded in the frozen amount; if no, the frozen amount remains unchanged. Finally, it determines whether the transaction amount of the accounting detail is opposite to the credit limit of the account corresponding to the accounting detail. If yes, the negative value of the accounting detail is recorded in the credit limit; if no, the credit limit remains unchanged. Delete the locked amount information of the aforementioned accounting details in the corresponding account.
8. The distributed ledger data processing method as described in claim 1, characterized in that, The distributed storage accounts obtain corresponding block numbers through a hash algorithm, and the accounting data of accounts corresponding to different block numbers are stored in different Redis instances.
9. The distributed ledger data processing method as described in claim 8, characterized in that, The locked amount information on the account is a key-value pair stored in the locked amount hash table in Redis. The key-value pair contains the sequence number of the accounting request, the available balance of the account, the locked amount, the credit limit, and the time information.
10. A distributed ledger data processing device, characterized in that, This distributed ledger data processing device is used to perform accounting for multiple distributed storage accounts, and includes: a trial calculation module, a confirmation module, and a release module. The trial calculation module is used to receive accounting requests, which include multiple accounting details corresponding to multiple accounts. When the trial calculation module determines that the accounting details have been successfully recorded according to a pre-set first constraint rule, it generates locked amount information on the account corresponding to the accounting details. The confirmation module is used to make all the accounting details corresponding to the accounting request effective on the corresponding accounts and generate accounting result details corresponding to the accounting request when all accounting details corresponding to the accounting request have been successfully recorded. The release module is used to release the locked amount information of all accounting details corresponding to the accounting request in the corresponding account when any accounting detail corresponding to the accounting request fails to be successfully recorded. Specifically, the accounting data for multiple accounts is divided into chunks using chunk numbers and then distributed to multiple Redis instances for processing. These chunk numbers are calculated from the Redis data keys using a hash algorithm. For the same account, the balance, locked amount, and detailed accounting results are stored in the same Redis instance according to the account's block number. The trial calculation module, confirmation module, and release module for the same account are all executed within a single Redis instance by calling Lua scripts loaded in Redis. In the trial calculation module, it is determined whether the transaction amount of the accounting details is reversed with the balance information of the account corresponding to the accounting details. If the determination is yes, the accounting details are recorded into the balance information. If the determination is no, the balance information remains unchanged. When the balance information meets the first constraint rule, a locked amount information is generated on the account corresponding to the accounting details, and the accounting details are successfully recorded.
11. The distributed ledger data processing apparatus as described in claim 10, characterized in that, The balance information includes: available balance, frozen amount, and credit limit; In the trial calculation module, Determine whether the transaction amount of the accounting details is opposite to the available credit limit of the account corresponding to the accounting details. If the determination is yes, then the accounting details are recorded into the available credit limit. If the determination is no, then the available credit limit remains unchanged. Determine whether the transaction amount of the accounting details is opposite to the frozen amount of the account corresponding to the accounting details. If the determination is yes, then the accounting details are recorded into the frozen amount. If the determination is no, then the frozen amount remains unchanged. Determine whether the transaction amount of the accounting details is opposite to the credit limit of the account corresponding to the accounting details. If the determination is yes, then the accounting details are recorded into the credit limit. If the determination is no, then the credit limit remains unchanged.
12. The distributed ledger data processing apparatus as described in claim 11, characterized in that, The first constraint rule includes: The available balance after accounting is not less than 0; The amount frozen after accounting shall not be less than 0; and After accounting, the credit limit shall not be less than 0; If both conditions are met, then the first constraint rule is deemed to be satisfied.
13. The distributed ledger data processing apparatus as described in claim 10, characterized in that, In the confirmation module, it is determined whether the transaction amount of the accounting detail is reversed with the balance information of the account corresponding to the accounting detail. If the determination is negative, the accounting detail is recorded into the balance information; if the determination is positive, the balance information remains unchanged. Delete the locked amount information of the aforementioned accounting details in the corresponding account.
14. The distributed ledger data processing apparatus as described in claim 11, characterized in that, In the confirmation module, it is determined whether the transaction amount of the accounting details is reversed with the available balance of the account corresponding to the accounting details. If the determination is no, the accounting details are recorded into the available balance. If the determination is yes, the available balance remains unchanged. Determine whether the transaction amount of the accounting details is opposite to the frozen amount of the account corresponding to the accounting details. If the determination is no, then the accounting details are recorded into the frozen amount. If the determination is yes, the frozen amount remains unchanged. Determine whether the transaction amount of the accounting details is opposite to the credit limit of the account corresponding to the accounting details. If the determination is no, then the accounting details are recorded into the credit limit. If the determination is yes, the credit limit remains unchanged. Delete the locked amount information of the aforementioned accounting details in the corresponding account.
15. The distributed ledger data processing apparatus as described in claim 10, characterized in that, In the release module, it is determined whether the transaction amount of the accounting details is reversed with the balance information of the account corresponding to the accounting details. If the determination is yes, the negative value of the accounting details is recorded into the balance information. If the determination is no, the balance information remains unchanged. The locked amount information of the accounting details in the corresponding account is also deleted.
16. The distributed ledger data processing apparatus as described in claim 12, characterized in that, In the release module, it is determined whether the transaction amount of the accounting details is opposite to the available balance of the account corresponding to the accounting details. If the determination is yes, the negative value of the accounting details is recorded into the available balance; if the determination is no, the available balance remains unchanged. It is also determined whether the transaction amount of the accounting details is opposite to the frozen amount of the account corresponding to the accounting details. If the determination is yes, the negative value of the accounting details is recorded into the frozen amount; if the determination is no, the frozen amount remains unchanged. Determine whether the transaction amount of the accounting details is opposite to the credit limit of the account corresponding to the accounting details. If the determination is yes, then the negative value of the accounting details is recorded in the credit limit. If the determination is no, then the credit limit remains unchanged. Also, delete the locked amount information of the accounting details in the corresponding account.
17. The distributed ledger data processing apparatus as described in claim 10, characterized in that, The distributed storage accounts obtain corresponding block numbers through a hash algorithm, and the accounting data of accounts corresponding to different block numbers are stored in different Redis instances.
18. The distributed ledger data processing apparatus as described in claim 17, characterized in that, The locked amount information on the account is a key-value pair stored in the locked amount hash table in Redis. The key-value pair contains the sequence number of the accounting request, the available balance of the account, the locked amount, the credit limit, and the time information.
19. A computer-readable medium having a computer program stored thereon, characterized in that, When executed by a processor, the computer program implements the distributed ledger data processing method according to any one of claims 1 to 9.
20. A computer device, comprising: Memory; processor; and a computer program stored on the memory and executable on the processor, characterized in that, The execution of the computer program causes the processor to implement the distributed ledger data processing method according to any one of claims 1 to 9 when executing the computer program.
Citation Information
Patent Citations
Method for performing redis lateral extension based on consistent Hash algorithm
CN106789175A
Distributed accounting method, device and system
CN109978540A
Data processing method and device
CN111813805A