Accounting methods, accounting devices, computer-readable storage media and transaction systems
By establishing communication connections between the application server and the in-memory database and the business database, querying the update status of the business database, and using Lua scripts to ensure data consistency, the problem of account overdraft in hot account accounting is solved, improving transaction processing efficiency and database performance.
Patent Information
- Application Number
- CN202211718781.9
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-12-29
- Publication Date
- 2025-10-28
- Estimated Expiration
- 2042-12-29
AI Technical Summary
Existing technologies are prone to account overdraft issues when handling popular accounts. This is mainly due to inconsistencies in master-slave data caused by Redis cluster master-slave switching, and inconsistencies in dual-write data between the business database and the memory database caused by network issues, which leads to database performance degradation and account overdraft.
The application server communicates with the in-memory database and the business database to obtain the transaction data to be synchronized and query the update status of the business database within a predetermined time. It sends a rollback command to restore the data in the in-memory database to the state before execution. Lua scripts are used to ensure the atomicity of the operation, and data synchronization and account freezing are performed during master-slave switchover to ensure data consistency.
It effectively solves the problem of account overdraft in the accounting of hot accounts, improves transaction processing efficiency and database performance, and avoids data inconsistency caused by master-slave switching and network jitter.
Smart Images

Figure CN116205727B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of data processing technology, and more specifically, to an accounting method, an accounting device, a computer-readable storage medium, and a transaction system. Background Technology
[0002] With the development of internet technology, online transaction volume has surged, leading to situations where one party in a transaction uses a single account. Because transaction systems have high requirements for concurrent requests and response speed, when there are multiple inflows and outflows to the same account within a short period, to prevent database overdraft in concurrent scenarios, the account data is locked during the recording process. Only one transaction request can acquire the lock at a time, and the lock is released only after the transaction update is completed. Due to the lock contention mechanism, subsequent requests must wait for the lock to be released before acquiring it, resulting in excessively long response times. This frequent locking and unlocking process causes a sharp decline in database performance, creating a performance bottleneck. Requests that fail to acquire the lock will also fail due to timeout while waiting for the lock, thus creating the hot account problem.
[0003] When performing outgoing and incoming transactions for frequently accessed accounts in accounting systems, it is necessary to address the issues of ensuring transaction security for the data source itself during the buffered accounting process and ensuring consistency of accounting transaction data between heterogeneous data sources (business database and in-memory database).
[0004] A common solution for hot accounts is to buffer the accounting process in the business database. This involves caching the accounting data in the business database to a memory database, Redis, using memory I / O instead of disk I / O. Real-time accounting calculations are performed in memory, and the account data in the business database is updated asynchronously, thereby alleviating the pressure on the business database and improving transaction processing efficiency.
[0005] Current technologies using the in-memory database Redis for buffered accounting processing only consider reducing the frequency of operations on the business database by performing accounting calculations and recording transaction vouchers directly in the in-memory database, or shifting from synchronous to asynchronous accounting processes. They do not consider the inconsistency issues caused by master-slave failover in Redis clusters, or the inconsistencies between the business database and the in-memory Redis database due to network issues during accounting transactions. These problems can all lead to account overdrafts.
[0006] The information disclosed above in the background section is only intended to enhance the understanding of the background art of the art described herein. Therefore, the background art may contain certain information that does not constitute prior art known to those skilled in the art in this country. Summary of the Invention
[0007] The main objective of this application is to provide an accounting method, accounting device, computer-readable storage medium, and transaction system to solve the problem of account overdrafts that are prone to occur when recording transactions for frequently used accounts in the prior art.
[0008] According to one aspect of the present invention, an accounting method is provided, wherein an application server is communicatively connected to an in-memory database and a business database, the in-memory database being used to execute transactions of hot accounts, and the business database being used to execute transactions of the hot accounts and non-hot accounts, wherein a hot account is an account whose transaction concurrency exceeds a predetermined concurrency level. The method includes: the application server acquiring transaction data to be synchronized, the transaction data to be synchronized being transaction data of target transactions successfully executed by the in-memory database; the application server sending the transaction data to be synchronized to the business database, causing the business database to update the corresponding transaction data according to the transaction data to be synchronized; and the application server sending the transaction data to be synchronized to the business database within a predetermined time. In the case of the first deletion instruction, the application server queries the business database to see if the transaction data corresponding to the transaction data to be synchronized has been updated. The first deletion instruction is sent by the application server when it receives the update success information from the business database. The first deletion instruction is used to control the in-memory database to delete the transaction number of the target transaction, and the transaction number corresponds one-to-one with the transaction. If the transaction data corresponding to the transaction data to be synchronized in the business database has not been updated, the application server sends a rollback instruction to the in-memory database. The rollback instruction is used to control the in-memory database to restore the transaction data to be synchronized to its state before execution and delete the transaction number of the target transaction.
[0009] Optionally, after the application server queries whether the transaction data corresponding to the transaction data to be synchronized in the business database has been updated, the method further includes: if the transaction data corresponding to the transaction data to be synchronized in the business database has been updated, the application server sends a second deletion instruction to the memory database, the second deletion instruction being used to control the memory database to delete the transaction number of the target transaction.
[0010] Optionally, the in-memory database cluster includes multiple in-memory databases, one of which is the primary database and the others are backup databases. The primary database is used to execute transactions for hot accounts, and the backup databases are synchronized with the primary database. Before the application server obtains the transaction data to be synchronized, the method further includes: when the application server receives a primary / backup switchover message, setting all the hot accounts as non-hot accounts, where the primary / backup switchover message is a message generated when a backup database switches to the primary database; synchronizing the business database with the switched-off primary database; and setting accounts with transaction concurrency greater than the predetermined concurrency as hot accounts.
[0011] Optionally, the process of the in-memory database executing transactions of hot accounts includes: continuously executing multiple target transactions and modifying the transaction data corresponding to the target transactions sequentially through Lua scripts; if any of the target transactions fails to execute, restoring the transaction data corresponding to the successfully executed target transactions to the state before execution.
[0012] Optionally, the transaction data is a balance. Before the application server obtains the transaction data to be synchronized, the method further includes: if the target account is the hot account, the application server sends a freeze instruction to the business database to freeze the target account. The freeze instruction is used to deduct the balance of the hot account and add a frozen amount to the account freeze register. The frozen amount is the amount deducted from the balance of the hot account. Upon receiving the information of the frozen amount, the application server sends a registration instruction to the memory database. The registration instruction is at least used to control the memory database to register the frozen amount and obtain a cached amount. The cached amount is used to deduct when the memory database executes a transaction.
[0013] Optionally, after the application server sends a registration instruction to the memory database, the method further includes: if the hot account has no ongoing transactions and the cached amount of the hot account in the memory database is consistent with the frozen amount of the hot account in the account freeze register, clearing the frozen amount and the cached amount to zero, and increasing the balance of the hot account by the frozen amount to unfreeze the hot account; if the hot account has no ongoing transactions and the cached amount of the hot account in the memory database is consistent with the frozen amount of the hot account in the account freeze register, prohibiting the unfreezing of the hot account.
[0014] Optionally, the update process of the transaction data corresponding to the transaction data to be synchronized in the business database includes: storing multiple transaction data to be synchronized in a temporary register; updating the frozen amount of the hot account and the balance of the hot account in the account freeze register according to all the data of the hot account in the temporary register.
[0015] According to another aspect of the present invention, an accounting apparatus is also provided, wherein an application server is communicatively connected to a memory database and a business database, respectively. The memory database is used to execute transactions of hot accounts, and the business database is used to execute transactions of the hot accounts and non-hot accounts. The hot accounts are accounts whose transaction concurrency is greater than a predetermined concurrency. The apparatus includes: an acquisition unit, used to acquire transaction data to be synchronized, the transaction data to be synchronized being transaction data of target transactions successfully executed by the memory database; a first sending unit, used to send the transaction data to be synchronized to the business database, so that the business database updates the corresponding transaction data according to the transaction data to be synchronized; and a query unit, used to query the memory database at a predetermined time. If no first deletion instruction is received within the specified time, the application server queries the business database to check whether the transaction data corresponding to the transaction data to be synchronized has been updated. The first deletion instruction is sent by the application server when it receives the update success information from the business database. The first deletion instruction is used to control the memory database to delete the transaction number of the target transaction, and the transaction number corresponds one-to-one with the transaction. The second sending unit is used to send a rollback instruction to the memory database if the transaction data corresponding to the transaction data to be synchronized in the business database has not been updated. The rollback instruction is used to control the memory database to restore the transaction data to be synchronized to its state before execution and delete the transaction number of the target transaction.
[0016] According to another aspect of the present invention, a computer-readable storage medium is also provided, the computer-readable storage medium including a stored program, wherein when the program is executed by a processor, the processor performs any one of the methods described.
[0017] According to another aspect of the present invention, a transaction system is also provided, comprising: an application server, a memory database, a business database, one or more processors, a memory, and one or more programs, wherein the application server is communicatively connected to the memory database and the business database, the memory database is used to execute transactions of hot accounts, and the business database is used to execute transactions of the hot accounts and non-hot accounts, wherein the hot accounts are accounts with a transaction concurrency greater than a predetermined concurrency, and the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs including methods for executing any one of the methods described.
[0018] In this embodiment of the invention, in the above accounting method, firstly, the application server obtains transaction data to be synchronized, which is the transaction data of the target transaction successfully executed by the in-memory database; then, the application server sends the transaction data to be synchronized to the business database, causing the business database to update the corresponding transaction data according to the transaction data to be synchronized; subsequently, if the in-memory database does not receive a first deletion instruction within a predetermined time, the application server queries the business database to see if the transaction data corresponding to the transaction data to be synchronized has been updated, the first deletion instruction being an instruction sent by the application server when it receives the update success information from the business database, and the first deletion instruction is used to control the in-memory database to delete the transaction number of the target transaction, the transaction number corresponding one-to-one with the transaction; finally, if the transaction data corresponding to the transaction data to be synchronized has not been updated in the business database, the application server sends a rollback instruction to the in-memory database, the rollback instruction being used to control the in-memory database to restore the transaction data to be synchronized to its state before execution and delete the transaction number of the target transaction. This method sends the transaction data to be synchronized to the business database through the application server. After the data synchronization between the in-memory database and the business database is completed, if the in-memory database does not receive the first deletion instruction within the predetermined time, it indicates that there may be network jitter causing communication problems. Therefore, it queries whether the transaction data corresponding to the transaction data to be synchronized in the business database has been updated. If it has been updated, the data in the in-memory database and the business database are consistent. Otherwise, it sends a rollback instruction to control the in-memory database to restore the transaction data to be synchronized to the state before execution, so as to ensure data consistency. This solves the problem of account overdraft that is easy to occur when recording hot accounts in the existing technology. Attached Figure Description
[0019] The accompanying drawings, which form part of this application, are used to provide a further understanding of this application. The illustrative embodiments and descriptions of this application are used to explain this application and do not constitute an undue limitation of this application. In the drawings:
[0020] Figure 1 A flowchart of an accounting method according to an embodiment of this application is shown;
[0021] Figure 2 A flowchart of a hotspot account freezing process according to an embodiment of this application is shown;
[0022] Figure 3 A flowchart of a hotspot account accounting process according to an embodiment of this application is shown;
[0023] Figure 4 A flowchart illustrating a hotspot account unfreezing process according to an embodiment of this application is shown;
[0024] Figure 5 A timing diagram of a TCC mechanism according to one embodiment of this application is shown;
[0025] Figure 6 A schematic diagram of an accounting apparatus according to an embodiment of this application is shown. Detailed Implementation
[0026] It should be noted that the following detailed descriptions are illustrative and intended to provide further explanation of this application. Unless otherwise specified, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this application pertains.
[0027] It should be noted that the terminology used herein is for the purpose of describing particular embodiments only and is not intended to limit the exemplary embodiments according to this application. As used herein, the singular form is intended to include the plural form as well, unless the context clearly indicates otherwise. Furthermore, it should be understood that when the terms "comprising" and / or "including" are used in this specification, they indicate the presence of features, steps, operations, devices, components, and / or combinations thereof.
[0028] It should be understood that when an element (such as a layer, film, region, or substrate) is described as being "on" another element, the element may be directly on the other element, or there may be an intermediate element present. Furthermore, in the specification and claims, when an element is described as being "connected" to another element, the element may be "directly connected" to the other element, or "connected" to the other element via a third element.
[0029] For ease of description, the following explains some of the nouns or terms used in the embodiments of this application:
[0030] Hot accounts: Accounts that require frequent inbound and outbound operations at the same time in high-concurrency scenarios.
[0031] TCC: TCC is an abbreviation for Try-Confirm-Cancel, a relatively mature distributed transaction solution. The Try phase is responsible for checking and reserving resources, the Confirm phase executes the actual business logic, and the Cancel phase cancels the reserved resources if the Try phase fails.
[0032] Lua is a lightweight scripting language written in standard C and open-source. It provides flexible extension and customization capabilities for applications by being flexibly embedded into them.
[0033] As mentioned in the background section, existing technologies often lead to account overdrafts when recording transactions for frequently used accounts. To address this issue, this application provides a typical implementation of an accounting method, an accounting device, a computer-readable storage medium, and a transaction system.
[0034] According to an embodiment of this application, an accounting method is provided, wherein an application server is communicatively connected to an in-memory database and a business database, respectively. The in-memory database is used to execute transactions of hot accounts, and the business database is used to execute transactions of the hot accounts and non-hot accounts. The hot accounts are those with a transaction concurrency greater than a predetermined concurrency.
[0035] Figure 1 This is a flowchart of an accounting method according to an embodiment of this application. For example... Figure 1 As shown, the method includes the following steps:
[0036] Step S101: The application server obtains the transaction data to be synchronized, which is the transaction data of the target transaction that was successfully executed by the memory database.
[0037] The in-memory database cluster includes multiple in-memory databases, one of which is the primary database, and the others are backup databases. The primary database is used to execute transactions for frequently accessed accounts. To further ensure that account overdrafts are not prevented, in an optional implementation, the backup databases synchronize data with the primary database. Before the application server obtains the transaction data to be synchronized, the method further includes:
[0038] Step S201: When the application server receives the primary / standby switchover message, all the aforementioned hot accounts are set to the aforementioned non-hot accounts. The primary / standby switchover message is a message generated when the aforementioned standby database is switched to the aforementioned primary database.
[0039] Step S202: Synchronize the above-mentioned business database with the switched-over main database.
[0040] Step S203: Set the accounts with transaction concurrency exceeding the predetermined concurrency as the hot accounts.
[0041] In the above implementation, the system monitors whether there is a master-slave switchover issue in the Redis in-memory database cluster. If a master-slave switchover occurs, an alarm is issued for any detected real-time accounting anomalies. At the same time, the hot accounts service falling on that node is downgraded, that is, all the hot accounts are set to the non-hot accounts. Simultaneously, an accounting reconciliation is performed immediately. If no anomalies are found after reconciliation, or if anomalies are found, the data in the Redis in-memory database is calibrated using data from the Postgres business database. Then, the service degradation switch is turned off, and the hot account scheme continues to be implemented to avoid account overdrafts caused by master-slave data inconsistency during the master-slave switchover of the Redis in-memory database cluster.
[0042] It should be noted that the automatic account reconciliation mechanism is used to periodically reconcile transaction log records written to both the Postgres business database and the Redis in-memory database. Due to the strong consistency of row-level locking in relational databases, data in the Postgres business database can be used to calibrate the data in the Redis in-memory database. The trigger frequency of the scheduled task can be flexibly configured, and distributed locks are used to ensure that only one account reconciliation task can be executed for the same frequently accessed account at a time.
[0043] To prevent account overdrafts in the in-memory database, in one optional implementation, the process of the in-memory database executing transactions for frequently used accounts includes:
[0044] Step S301: Execute multiple target transactions consecutively, and modify the transaction data corresponding to the target transactions in sequence using Lua scripts;
[0045] Step S302: If any of the above target transactions fails to execute, restore the transaction data corresponding to the successfully executed target transactions to the state before execution.
[0046] In the above implementation, the Redis in-memory database uses Lua scripts to ensure the atomicity of operations. Since Lua scripts can package multiple Redis names into a single Redis name, network overhead can be effectively reduced. Furthermore, Lua scripts can reside in Redis memory and be reused directly during operation. Because Lua scripts require all keys to be distributed in the same slot within the Redis in-memory database cluster when operating on multiple keys, a customized hash tag scheme is used to generate cached keys. Specifically, Lua scripts sequentially modify the transaction data corresponding to the target transaction to generate cached keys. If any of the target transactions fails, the cached key is deleted, and the transaction data corresponding to the successfully executed target transaction is restored to its state before execution, ensuring that the Redis in-memory database does not experience account overdraft.
[0047] To improve transaction processing efficiency, in one optional implementation, the transaction data is a balance, and before the application server obtains the transaction data to be synchronized, the method further includes:
[0048] In step S401, if the target account is the aforementioned hot account, the application server sends a freeze instruction to the business database to freeze the target account. The freeze instruction is used to deduct the balance of the hot account and add the frozen amount to the account freeze register. The frozen amount is the amount deducted from the balance of the hot account.
[0049] In step S402, upon receiving the information about the frozen amount, the application server sends a registration instruction to the memory database. The registration instruction is at least used to control the memory database to register the frozen amount and obtain a cached amount. The cached amount is used to deduct when the memory database executes a transaction.
[0050] In the above embodiments, such as Figure 2 As shown, when performing a hot account freeze operation, the system first determines whether the account is a hot account. Non-hot accounts are not frozen. The Postgres business database deducts the available balance of the hot account according to the freeze command, keeping the balance unchanged and not affecting the user's balance query display. The frozen amount is then added to the account freeze register. The Redis in-memory database then records the frozen amount to obtain the cached amount. It can also record data such as transaction serial numbers to facilitate automatic account verification by the Redis in-memory database. Transactions can then be executed through the Redis in-memory database, reducing the transaction volume of the Postgres business database, alleviating the pressure on the business database, and improving transaction processing efficiency.
[0051] Specifically, such as Figure 3As shown, the steps for executing the target transaction in the Redis in-memory database include: receiving an accounting operation request, obtaining information such as the account number and transaction amount from the request parameters, reading the hot account register, determining whether it is an active hot account, using the hot account processing mechanism if it is a hot account, and following the non-hot account transaction process if it is not a hot account. If it is an inbound operation, it is directly recorded in the pending transaction register in the Postgres business database. If it is an outbound operation, it first determines whether the available frozen amount in the Redis database is sufficient. If the available frozen amount in the Redis in-memory database is insufficient for deduction, it returns an insufficient balance error and ends the transaction. If the available frozen amount is sufficient, it deducts the frozen amount in the Redis in-memory database. Transactions with successful outbound deductions in the Redis database are recorded in the Postgres business database's hot account pending transaction register. The transaction amounts in the pending transaction register are asynchronously summarized according to the inbound / outbound direction. The Postgres business database deducts the summarized transaction amount from the current frozen amount in the frozen register and simultaneously modifies the balance of the hot account.
[0052] To further ensure that account overdrafts are not detected, in an optional implementation, after the application server sends the registration instruction to the in-memory database, the method further includes:
[0053] Step S501: If there are no transactions being processed in the hot account and the cached amount of the hot account in the memory database is consistent with the frozen amount of the hot account in the account freeze register, the frozen amount and the cached amount are cleared to zero, and the balance of the hot account is increased by the frozen amount to unfreeze the hot account.
[0054] Step S502: If the hot account has no pending transactions and the cached amount of the hot account in the memory database is consistent with the frozen amount of the hot account in the account freeze register, the unfreezing of the hot account is prohibited.
[0055] In the above implementation, the hot account can be set to have an effective time. The hot account register in the business database is periodically polled. If the hot account has expired, a hot account unfreezing operation is initiated, unfreezing the frozen amount cached in the Redis in-memory database. Figure 4As shown, the system checks if the hot account has any pending transactions. If so, unfreezing is prohibited. The system compares the current frozen amount in the business database freeze register with the current cached amount in the Redis in-memory database. If the amounts match, the account can be unfrozen; otherwise, unfreezing is prohibited, and an automatic reconciliation process is initiated. This deducts the current frozen amount in the business database freeze register and the balance in the Redis in-memory database, increasing the available balance in the account table of the business database, thus preventing account overdrafts.
[0056] In step S102, the application server sends the transaction data to be synchronized to the business database, so that the business database updates the corresponding transaction data according to the transaction data to be synchronized.
[0057] To improve transaction processing efficiency, in one optional implementation, the update process of the transaction data corresponding to the transaction data to be synchronized in the above-mentioned business database includes:
[0058] Step S1021: Store the above-mentioned transaction data to be synchronized in a temporary register;
[0059] Step S1022: Update the frozen amount and balance of the hot account in the account freeze register according to all the data of the hot account in the temporary register.
[0060] In the above implementation, multiple transaction data to be synchronized are stored in a temporary register. The frozen amount and balance of the hot accounts in the account freeze register are updated periodically based on all the data in the temporary register, so as to further reduce the transaction volume of the Postgres business database, alleviate the pressure on the business database, and improve transaction processing efficiency.
[0061] In step S103, if the memory database does not receive the first deletion instruction within a predetermined time, the application server queries the business database to see if the transaction data corresponding to the transaction data to be synchronized has been updated. The first deletion instruction is an instruction sent by the application server when it receives the update success information from the business database. The first deletion instruction is used to control the memory database to delete the transaction number of the target transaction. The transaction number corresponds one-to-one with the transaction.
[0062] Specifically, such as Figure 5As shown, the Try phase of the TCC mechanism utilizes the atomicity of Lua scripts to deduct the available frozen amount in the Redis in-memory database. It registers a processing transaction record in the Redis in-memory database, returns the current Redis cluster timestamp, and divides the data into several Sets based on the timestamp when storing key-value pairs in the in-memory database. Simultaneously, it registers the processing transaction number in the Set set of the Redis in-memory database and finally registers it in the pending transaction register for hot accounts. After the Postgres database transaction is committed during the billing operation, the Conform phase is executed. The frozen amount is deducted in the Lua script, the aforementioned transaction record is marked as successful, and the processing transaction number is removed from the Set set. If the Try phase fails and the application service throws an exception, the Cancel phase is executed to recover the deduction of the available frozen amount in the Lua script, mark the transaction record as failed, and remove the processing transaction number from the Set set.
[0063] In step S104, if the transaction data corresponding to the transaction data to be synchronized in the business database has not been updated, the application server sends a rollback instruction to the memory database. The rollback instruction is used to control the memory database to restore the transaction data to be synchronized to the state before execution and delete the transaction number of the target transaction.
[0064] To prevent the Set collection from always containing undeleted serial numbers, in one optional implementation, after the application server queries the business database to see if the transaction data corresponding to the transaction data to be synchronized has been updated, the method further includes:
[0065] In step S105, if the transaction data corresponding to the transaction data to be synchronized in the business database has been updated, the application server sends a second deletion instruction to the memory database. The second deletion instruction is used to control the memory database to delete the transaction number of the target transaction.
[0066] In the above embodiments, such as Figure 5 As shown, if there are always undeleted serial numbers in the Set collection, the serial numbers in the Set collection are periodically polled. By checking the serial status in the Postgres database, if the transaction data corresponding to the transaction data to be synchronized in the business database has not been updated, the Confirm operation is executed, that is, the application server sends a rollback instruction to the Redis in-memory database. If the transaction data corresponding to the transaction data to be synchronized in the business database has been updated, the Cancel operation is executed, that is, the application server sends a second deletion instruction to the in-memory database, ensuring that the entire Set collection is processed.
[0067] In the above accounting method, firstly, the application server obtains transaction data to be synchronized, which is the transaction data of the target transaction successfully executed by the in-memory database; then, the application server sends the transaction data to be synchronized to the business database, causing the business database to update the corresponding transaction data according to the transaction data to be synchronized; subsequently, if the in-memory database does not receive a first deletion instruction within a predetermined time, the application server queries the business database to see if the transaction data corresponding to the transaction data to be synchronized has been updated. The first deletion instruction is sent by the application server when it receives the update success information from the business database, and the first deletion instruction is used to control the in-memory database to delete the transaction number of the target transaction, which corresponds one-to-one with the transaction; finally, if the transaction data corresponding to the transaction data to be synchronized has not been updated in the business database, the application server sends a rollback instruction to the in-memory database, which is used to control the in-memory database to restore the transaction data to be synchronized to its state before execution and delete the transaction number of the target transaction. This method sends the transaction data to be synchronized to the business database through the application server. After the data synchronization between the in-memory database and the business database is completed, if the in-memory database does not receive the first deletion instruction within the predetermined time, it indicates that there may be network jitter causing communication problems. Therefore, it queries whether the transaction data corresponding to the transaction data to be synchronized in the business database has been updated. If it has been updated, the data in the in-memory database and the business database are consistent. Otherwise, it sends a rollback instruction to control the in-memory database to restore the transaction data to be synchronized to the state before execution, so as to ensure data consistency. This solves the problem of account overdraft that is easy to occur when recording hot accounts in the existing technology.
[0068] This application also provides an accounting device. It should be noted that the accounting device of this application can be used to execute the accounting method provided in this application. The accounting device provided in this application is described below.
[0069] Figure 6 This is a schematic diagram of an accounting device according to an embodiment of this application. Figure 6 As shown, the device includes:
[0070] The acquisition unit 10 is used to acquire transaction data to be synchronized, which is the transaction data of the target transaction that was successfully executed by the memory database.
[0071] The in-memory database cluster includes multiple in-memory databases, one of which is the primary database and the others are backup databases. The primary database is used to execute transactions for frequently accessed accounts, and the backup databases are synchronized with the primary database. To further ensure that account overdrafts are not prevented, in an optional embodiment, the apparatus further includes:
[0072] The first processing unit is used to set all the hot accounts to non-hot accounts before the application server obtains the transaction data to be synchronized, and when the application server receives the master-slave switch message. The master-slave switch message is a message generated when the backup database is switched to the master database.
[0073] The synchronization unit is used to synchronize the aforementioned business database with the switched primary database.
[0074] The second processing unit is used to set accounts with transaction concurrency exceeding the predetermined concurrency as the aforementioned hot accounts.
[0075] In the above implementation, the system monitors whether there is a master-slave switchover issue in the Redis in-memory database cluster. If a master-slave switchover occurs, an alarm is issued for any detected real-time accounting anomalies. At the same time, the hot accounts service falling on that node is downgraded, that is, all the hot accounts are set to the non-hot accounts. Simultaneously, an accounting reconciliation is performed immediately. If no anomalies are found after reconciliation, or if anomalies are found, the data in the Redis in-memory database is calibrated using data from the Postgres business database. Then, the service degradation switch is turned off, and the hot account scheme continues to be implemented to avoid account overdrafts caused by master-slave data inconsistency during the master-slave switchover of the Redis in-memory database cluster.
[0076] To prevent account overdrafts in the in-memory database, in one optional implementation, the above-mentioned apparatus includes:
[0077] The third processing unit is used to continuously execute multiple target transactions and modify the transaction data corresponding to the target transactions in sequence through Lua scripts.
[0078] The reset unit is used to restore the transaction data corresponding to the successfully executed target transaction to its state before execution in the event that any of the aforementioned target transactions fails to execute.
[0079] In the above implementation, the Redis in-memory database uses Lua scripts to ensure the atomicity of operations. Since Lua scripts can package multiple Redis names into a single Redis name, network overhead can be effectively reduced. Furthermore, Lua scripts can reside in Redis memory and be reused directly during operation. Because Lua scripts require all keys to be distributed in the same slot within the Redis in-memory database cluster when operating on multiple keys, a customized hash tag scheme is used to generate cached keys. Specifically, Lua scripts sequentially modify the transaction data corresponding to the target transaction to generate cached keys. If any of the target transactions fails, the cached key is deleted, and the transaction data corresponding to the successfully executed target transaction is restored to its state before execution, ensuring that the Redis in-memory database does not experience account overdraft.
[0080] To improve transaction processing efficiency, in one optional embodiment, the transaction data is a balance, and the device further includes:
[0081] The fourth processing unit is used to send a freeze command to the business database before the application server obtains the transaction data to be synchronized, in the case that the target account is the hot account, so as to freeze the target account. The freeze command is used to deduct the balance of the hot account and add the frozen amount to the account freeze register. The frozen amount is the amount deducted from the balance of the hot account.
[0082] The third sending unit is used to send a registration instruction to the memory database when the application server receives the information about the frozen amount. The registration instruction is used to control the memory database to register the frozen amount and obtain a cached amount. The cached amount is used to deduct when the memory database executes a transaction.
[0083] In the above embodiments, such as Figure 2 As shown, when performing a hot account freeze operation, the system first determines whether the account is a hot account. Non-hot accounts are not frozen. The Postgres business database deducts the available balance of the hot account according to the freeze command, keeping the balance unchanged and not affecting the user's balance query display. The frozen amount is then added to the account freeze register. The Redis in-memory database then records the frozen amount to obtain the cached amount. It can also record data such as transaction serial numbers to facilitate automatic account verification by the Redis in-memory database. Transactions can then be executed through the Redis in-memory database, reducing the transaction volume of the Postgres business database, alleviating the pressure on the business database, and improving transaction processing efficiency.
[0084] Specifically, such as Figure 3As shown, the steps for executing the target transaction in the Redis in-memory database include: receiving an accounting operation request, obtaining information such as the account number and transaction amount from the request parameters, reading the hot account register, determining whether it is an active hot account, using the hot account processing mechanism if it is a hot account, and following the non-hot account transaction process if it is not a hot account. If it is an inbound operation, it is directly recorded in the pending transaction register in the Postgres business database. If it is an outbound operation, it first determines whether the available frozen amount in the Redis database is sufficient. If the available frozen amount in the Redis in-memory database is insufficient for deduction, it returns an insufficient balance error and ends the transaction. If the available frozen amount is sufficient, it deducts the frozen amount in the Redis in-memory database. Transactions with successful outbound deductions in the Redis database are recorded in the Postgres business database's hot account pending transaction register. The transaction amounts in the pending transaction register are asynchronously summarized according to the inbound / outbound direction. The Postgres business database deducts the summarized transaction amount from the current frozen amount in the frozen register and simultaneously modifies the balance of the hot account.
[0085] To further ensure that account overdrafts do not occur, in an optional implementation, the above-mentioned device further includes:
[0086] The fifth processing unit is configured to, after the application server sends a registration instruction to the memory database, if the hot account has no transactions in progress and the cached amount of the hot account in the memory database is consistent with the frozen amount of the hot account in the account freeze register, clear the frozen amount and the cached amount, and add the frozen amount to the balance of the hot account to unfreeze the hot account.
[0087] The sixth processing unit is configured to prohibit the unfreezing of the hot account when there is no transaction being processed for the hot account and the cached amount of the hot account in the memory database is consistent with the frozen amount of the hot account in the account freeze register.
[0088] In the above implementation, the hot account can be set to have an effective time. The hot account register in the business database is periodically polled. If the hot account has expired, a hot account unfreezing operation is initiated, unfreezing the frozen amount cached in the Redis in-memory database. Figure 4As shown, the system checks if the hot account has any pending transactions. If so, unfreezing is prohibited. The system compares the current frozen amount in the business database freeze register with the current cached amount in the Redis in-memory database. If the amounts match, the account can be unfrozen; otherwise, unfreezing is prohibited, and an automatic reconciliation process is initiated. This deducts the current frozen amount in the business database freeze register and the balance in the Redis in-memory database, increasing the available balance in the account table of the business database, thus preventing account overdrafts.
[0089] The first sending unit 20 is used to send the transaction data to be synchronized to the business database, so that the business database updates the corresponding transaction data according to the transaction data to be synchronized.
[0090] To improve transaction processing efficiency, in one optional embodiment, the above-mentioned apparatus includes:
[0091] Storage unit, used to store multiple of the above-mentioned transaction data to be synchronized into a temporary register;
[0092] The updating unit is used to update the frozen amount and balance of the hot account in the account freeze register based on all the data of the hot account in the temporary register.
[0093] In the above implementation, multiple transaction data to be synchronized are stored in a temporary register. The frozen amount and balance of the hot accounts in the account freeze register are updated periodically based on all the data in the temporary register, so as to further reduce the transaction volume of the Postgres business database, alleviate the pressure on the business database, and improve transaction processing efficiency.
[0094] The query unit 30 is used to query whether the transaction data corresponding to the transaction data to be synchronized in the business database has been updated if the memory database does not receive the first deletion instruction within a predetermined time. The first deletion instruction is an instruction sent by the application server when it receives the update success information from the business database. The first deletion instruction is used to control the memory database to delete the transaction number of the target transaction. The transaction number corresponds one-to-one with the transaction.
[0095] Specifically, such as Figure 5As shown, the Try phase of the TCC mechanism utilizes the atomicity of Lua scripts to deduct the available frozen amount in the Redis in-memory database. It registers a processing transaction record in the Redis in-memory database, returns the current Redis cluster timestamp, and divides the data into several Sets based on the timestamp when storing key-value pairs in the in-memory database. Simultaneously, it registers the processing transaction number in the Set set of the Redis in-memory database and finally registers it in the pending transaction register for hot accounts. After the Postgres database transaction is committed during the billing operation, the Conform phase is executed. The frozen amount is deducted in the Lua script, the aforementioned transaction record is marked as successful, and the processing transaction number is removed from the Set set. If the Try phase fails and the application service throws an exception, the Cancel phase is executed to recover the deduction of the available frozen amount in the Lua script, mark the transaction record as failed, and remove the processing transaction number from the Set set.
[0096] The second sending unit 40 is used to send a rollback instruction to the memory database when the transaction data corresponding to the transaction data to be synchronized in the business database has not been updated. The rollback instruction is used to control the memory database to restore the transaction data to be synchronized to the state before execution and delete the transaction number of the target transaction.
[0097] To prevent the Set collection from always containing undeleted serial numbers, in one optional implementation, the above-mentioned device further includes:
[0098] The fourth sending unit is used to send a second deletion instruction to the memory database after the application server queries whether the transaction data corresponding to the transaction data to be synchronized in the business database has been updated. If the transaction data corresponding to the transaction data to be synchronized in the business database has been updated, the application server sends the second deletion instruction to the memory database. The second deletion instruction is used to control the memory database to delete the transaction number of the target transaction.
[0099] In the above embodiments, such as Figure 5 As shown, if there are always undeleted serial numbers in the Set collection, the serial numbers in the Set collection are periodically polled. By checking the serial status in the Postgres database, if the transaction data corresponding to the transaction data to be synchronized in the business database has not been updated, the Confirm operation is executed, that is, the application server sends a rollback instruction to the Redis in-memory database. If the transaction data corresponding to the transaction data to be synchronized in the business database has been updated, the Cancel operation is executed, that is, the application server sends a second deletion instruction to the in-memory database, ensuring that the entire Set collection is processed.
[0100] In the aforementioned accounting device, the acquisition unit (application server) acquires transaction data to be synchronized, which is the transaction data of the target transaction successfully executed by the memory database; the first sending unit (application server) sends the transaction data to be synchronized to the business database, causing the business database to update the corresponding transaction data based on the transaction data to be synchronized; the query unit (application server) queries the business database to check whether the transaction data corresponding to the transaction data to be synchronized has been updated if the memory database does not receive a first deletion instruction within a predetermined time, the first deletion instruction being sent by the application server upon receiving a successful update message from the business database, and the first deletion instruction controlling the memory database to delete the transaction number of the target transaction, the transaction number corresponding one-to-one with the transaction; the second sending unit (application server) sends a rollback instruction to the memory database if the transaction data corresponding to the transaction data to be synchronized has not been updated in the business database, the rollback instruction controlling the memory database to restore the transaction data to be synchronized to its state before execution and delete the transaction number of the target transaction. The device sends the transaction data to be synchronized to the business database through the application server. After the data synchronization between the memory database and the business database is completed, if the memory database does not receive the first deletion instruction within the predetermined time, it indicates that there may be network jitter causing communication problems. Therefore, it queries whether the transaction data corresponding to the transaction data to be synchronized in the business database has been updated. If it has been updated, the data in the memory database and the business database are consistent. Otherwise, it sends a rollback instruction to control the memory database to restore the transaction data to be synchronized to the state before execution, so as to ensure data consistency and solve the problem of account overdraft that is easy to occur when recording hot accounts in the existing technology.
[0101] An embodiment of this application provides a transaction system, including: the aforementioned application server, the aforementioned in-memory database, the aforementioned business database, one or more processors, a memory, and one or more programs. The application server is communicatively connected to both the in-memory database and the aforementioned business database. The in-memory database is used to execute transactions for hot accounts, and the business database is used to execute transactions for both hot and non-hot accounts. Hot accounts are those with a transaction concurrency exceeding a predetermined concurrency level. The one or more programs are stored in the aforementioned memory and configured to be executed by the one or more processors. The one or more programs include methods for executing any of the aforementioned methods.
[0102] The aforementioned transaction system includes the aforementioned application server, the aforementioned in-memory database, and the aforementioned business database. The system sends transaction data to be synchronized to the business database via the application server. Data synchronization between the in-memory database and the business database has been completed. If the in-memory database does not receive the first deletion instruction within a predetermined time, it indicates that network jitter may be causing communication problems. Therefore, the system queries whether the transaction data corresponding to the transaction data to be synchronized in the business database has been updated. If it has been updated, the data in the in-memory database and the business database are consistent; otherwise, a rollback instruction is sent to control the in-memory database to restore the transaction data to be synchronized to its state before execution, ensuring data consistency. This solves the problem of account overdrafts that easily occur when recording transactions for popular accounts in existing technologies.
[0103] The aforementioned transaction device includes a processor and a memory. The aforementioned acquisition unit, first sending unit, query unit, and second sending unit are all stored in the memory as program units, and the processor executes the aforementioned program units stored in the memory to realize the corresponding functions.
[0104] The processor contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and adjusting kernel parameters can address the problem of overdrafts easily occurring in existing technologies when recording transactions for frequently accessed accounts.
[0105] The memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0106] This invention provides a computer-readable storage medium having a program stored thereon, which, when executed by a processor, implements the above-described method.
[0107] This invention provides a processor for running a program, wherein the program executes the method described above when it runs.
[0108] This invention provides a device including a processor, a memory, and a program stored in the memory and executable on the processor. When the processor executes the program, it performs at least the following steps:
[0109] Step S101: The application server obtains the transaction data to be synchronized, which is the transaction data of the target transaction that was successfully executed by the memory database.
[0110] In step S102, the application server sends the transaction data to be synchronized to the business database, so that the business database updates the corresponding transaction data according to the transaction data to be synchronized.
[0111] In step S103, if the memory database does not receive the first deletion instruction within a predetermined time, the application server queries the business database to see if the transaction data corresponding to the transaction data to be synchronized has been updated. The first deletion instruction is an instruction sent by the application server when it receives the update success information from the business database. The first deletion instruction is used to control the memory database to delete the transaction number of the target transaction. The transaction number corresponds one-to-one with the transaction.
[0112] In step S104, if the transaction data corresponding to the transaction data to be synchronized in the business database has not been updated, the application server sends a rollback instruction to the memory database. The rollback instruction is used to control the memory database to restore the transaction data to be synchronized to the state before execution and delete the transaction number of the target transaction.
[0113] The devices mentioned in this article can be servers, PCs, tablets, mobile phones, etc.
[0114] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program having at least the following method steps:
[0115] Step S101: The application server obtains the transaction data to be synchronized, which is the transaction data of the target transaction that was successfully executed by the memory database.
[0116] In step S102, the application server sends the transaction data to be synchronized to the business database, so that the business database updates the corresponding transaction data according to the transaction data to be synchronized.
[0117] In step S103, if the memory database does not receive the first deletion instruction within a predetermined time, the application server queries the business database to see if the transaction data corresponding to the transaction data to be synchronized has been updated. The first deletion instruction is an instruction sent by the application server when it receives the update success information from the business database. The first deletion instruction is used to control the memory database to delete the transaction number of the target transaction. The transaction number corresponds one-to-one with the transaction.
[0118] In step S104, if the transaction data corresponding to the transaction data to be synchronized in the business database has not been updated, the application server sends a rollback instruction to the memory database. The rollback instruction is used to control the memory database to restore the transaction data to be synchronized to the state before execution and delete the transaction number of the target transaction.
[0119] In the above embodiments of the present invention, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0120] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units described above can be a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.
[0121] The units described above as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0122] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0123] If the aforementioned integrated units are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a computer-readable storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned computer-readable storage medium includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0124] As can be seen from the above description, the embodiments of this application achieve the following technical effects:
[0125] 1) In the accounting method of this application, firstly, the application server obtains transaction data to be synchronized, which is the transaction data of the target transaction successfully executed by the in-memory database; then, the application server sends the transaction data to be synchronized to the business database, causing the business database to update the corresponding transaction data according to the transaction data to be synchronized; subsequently, if the in-memory database does not receive a first deletion instruction within a predetermined time, the application server queries the business database to see if the transaction data corresponding to the transaction data to be synchronized has been updated, the first deletion instruction is an instruction sent by the application server when it receives the update success information from the business database, and the first deletion instruction is used to control the in-memory database to delete the transaction number of the target transaction, the transaction number being one-to-one with the transaction; finally, if the transaction data corresponding to the transaction data to be synchronized has not been updated in the business database, the application server sends a rollback instruction to the in-memory database, the rollback instruction being used to control the in-memory database to restore the transaction data to be synchronized to its state before execution and delete the transaction number of the target transaction. This method sends the transaction data to be synchronized to the business database through the application server. After the data synchronization between the in-memory database and the business database is completed, if the in-memory database does not receive the first deletion instruction within the predetermined time, it indicates that there may be network jitter causing communication problems. Therefore, it queries whether the transaction data corresponding to the transaction data to be synchronized in the business database has been updated. If it has been updated, the data in the in-memory database and the business database are consistent. Otherwise, it sends a rollback instruction to control the in-memory database to restore the transaction data to be synchronized to the state before execution, so as to ensure data consistency. This solves the problem of account overdraft that is easy to occur when recording hot accounts in the existing technology.
[0126] 2) In the accounting device of this application, the acquisition unit, the application server, acquires transaction data to be synchronized, which is the transaction data of the target transaction successfully executed by the memory database; the first sending unit, the application server, sends the transaction data to be synchronized to the business database, so that the business database updates the corresponding transaction data according to the transaction data to be synchronized; if the memory database does not receive the first deletion instruction within a predetermined time, the query unit, the application server, queries the business database to see if the transaction data corresponding to the transaction data to be synchronized has been updated, the first deletion instruction is the instruction sent by the application server when it receives the update success information from the business database, and the first deletion instruction is used to control the memory database to delete the transaction number of the target transaction, the transaction number being one-to-one with the transaction; if the transaction data corresponding to the transaction data to be synchronized has not been updated in the business database, the application server sends a rollback instruction to the memory database, the rollback instruction is used to control the memory database to restore the transaction data to be synchronized to the state before execution and delete the transaction number of the target transaction. The device sends the transaction data to be synchronized to the business database through the application server. After the data synchronization between the memory database and the business database is completed, if the memory database does not receive the first deletion instruction within the predetermined time, it indicates that there may be network jitter causing communication problems. Therefore, it queries whether the transaction data corresponding to the transaction data to be synchronized in the business database has been updated. If it has been updated, the data in the memory database and the business database are consistent. Otherwise, it sends a rollback instruction to control the memory database to restore the transaction data to be synchronized to the state before execution, so as to ensure data consistency and solve the problem of account overdraft that is easy to occur when recording hot accounts in the existing technology.
[0127] 3) The transaction system of this application includes the aforementioned application server, the aforementioned in-memory database, and the aforementioned business database. The system sends the transaction data to be synchronized to the business database through the application server. The data synchronization between the in-memory database and the business database has been completed. If the in-memory database does not receive the first deletion instruction within a predetermined time, it indicates that there may be network jitter causing communication problems. Therefore, by querying whether the transaction data corresponding to the transaction data to be synchronized in the business database has been updated, if it has been updated, the data in the in-memory database and the business database are consistent. Otherwise, a rollback instruction is sent to control the in-memory database to restore the transaction data to be synchronized to the state before execution, so as to ensure data consistency and solve the problem of account overdraft that is easy to occur when recording hot accounts in the prior art.
[0128] The above description is merely a preferred embodiment of this application and is not intended to limit this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the protection scope of this application.
Claims
1. An accounting method, characterized in that, The application server communicates with both an in-memory database and a business database. The in-memory database is used to execute transactions for frequently accessed accounts, and the business database is used to execute transactions for both frequently accessed and non-frequently accessed accounts. Frequently accessed accounts are those with a transaction concurrency exceeding a predetermined concurrency level. The method includes: The application server obtains the transaction data to be synchronized, which is the transaction data of the target transaction that was successfully executed by the in-memory database; The application server sends the transaction data to be synchronized to the business database, so that the business database updates the corresponding transaction data according to the transaction data to be synchronized; If the memory database does not receive the first deletion instruction within a predetermined time, the application server queries the business database to see if the transaction data corresponding to the transaction data to be synchronized has been updated. The first deletion instruction is an instruction sent by the application server when it receives the update success information from the business database. The first deletion instruction is used to control the memory database to delete the transaction number of the target transaction. The transaction number corresponds one-to-one with the transaction. If the transaction data corresponding to the transaction data to be synchronized in the business database has not been updated, the application server sends a rollback instruction to the memory database. The rollback instruction is used to control the memory database to restore the transaction data to be synchronized to the state before execution and delete the transaction number of the target transaction. The transaction data is a balance. Before the application server obtains the transaction data to be synchronized, the method further includes: if the target account is the hot account, the application server sends a freeze instruction to the business database to freeze the target account. The freeze instruction is used to deduct the balance of the hot account and add the frozen amount to the account freeze register. The frozen amount is the amount deducted from the balance of the hot account. Upon receiving the information of the frozen amount, the application server sends a registration instruction to the memory database. The registration instruction is at least used to control the memory database to register the frozen amount and obtain a cached amount. The cached amount is used to deduct when the memory database executes a transaction.
2. The method according to claim 1, characterized in that, After the application server queries the business database to see if the transaction data corresponding to the transaction data to be synchronized has been updated, the method further includes: If the transaction data corresponding to the transaction data to be synchronized in the business database has been updated, the application server sends a second deletion instruction to the memory database. The second deletion instruction is used to control the memory database to delete the transaction number of the target transaction.
3. The method according to claim 1, characterized in that, The in-memory database cluster includes multiple in-memory databases, one of which is a primary database, and the others are backup databases. The primary database is used to execute transactions for frequently accessed accounts. The backup databases synchronize data with the primary database. Before the application server obtains the transaction data to be synchronized, the method further includes: When the application server receives the primary / standby switchover message, it sets all the hot accounts to the non-hot accounts. The primary / standby switchover message is a message generated when a standby database is switched to the primary database. Synchronize the business database with the switched master database; Accounts with transaction concurrency exceeding the predetermined concurrency level are designated as "hot accounts".
4. The method according to claim 1, characterized in that, The process of the in-memory database executing transactions for frequently used accounts includes: Execute multiple target transactions consecutively, and modify the transaction data corresponding to the target transactions sequentially using Lua scripts; If any of the target transactions fails to execute, the transaction data corresponding to the successfully executed target transaction will be restored to its state before execution.
5. The method according to claim 1, wherein After the application server sends a registration instruction to the memory database, the method further includes: If there is no transaction being processed in the hot account and the cached amount of the hot account in the memory database is consistent with the frozen amount of the hot account in the account freeze register, the frozen amount and the cached amount are cleared to zero, and the balance of the hot account is increased by the frozen amount to unfreeze the hot account; If the hot account has no pending transactions and the cached amount of the hot account in the memory database is inconsistent with the frozen amount of the hot account in the account freeze register, the hot account shall not be unfrozen.
6. The method according to claim 5, characterized in that, The update process for the transaction data corresponding to the transaction data to be synchronized in the business database includes: Store the data of the multiple transactions to be synchronized in a temporary register; Update the frozen amount and balance of the hot account in the account freeze register according to all data of the hot account in the temporary register.
7. An accounting device, characterized in that, The application server is communicatively connected to both an in-memory database and a business database. The in-memory database is used to execute transactions for frequently accessed accounts, and the business database is used to execute transactions for both frequently accessed and non-frequently accessed accounts. Frequently accessed accounts are those with a transaction concurrency exceeding a predetermined concurrency level. The device includes: The acquisition unit is used to acquire transaction data to be synchronized, wherein the transaction data to be synchronized is the transaction data of the target transaction that was successfully executed by the memory database; The first sending unit is configured to send the transaction data to be synchronized to the business database, so that the business database updates the corresponding transaction data according to the transaction data to be synchronized. The query unit is used to query whether the transaction data corresponding to the transaction data to be synchronized in the business database has been updated if the memory database does not receive the first deletion instruction within a predetermined time. The first deletion instruction is an instruction sent by the application server when it receives the update success information from the business database. The first deletion instruction is used to control the memory database to delete the transaction number of the target transaction. The transaction number corresponds one-to-one with the transaction. The second sending unit is used to send a rollback instruction to the memory database when the transaction data corresponding to the transaction data to be synchronized in the business database has not been updated. The rollback instruction is used to control the memory database to restore the transaction data to be synchronized to the state before execution and delete the transaction number of the target transaction. The transaction data is a balance. The device further includes: a fourth processing unit, configured to, before the application server obtains the transaction data to be synchronized, if the target account is the hot account, the application server sends a freeze instruction to the business database to freeze the target account. The freeze instruction is used to deduct the balance of the hot account and add a frozen amount to the account freeze register. The frozen amount is the amount deducted from the balance of the hot account. A third sending unit, configured to, upon receiving the information of the frozen amount, the application server sends a registration instruction to the memory database. The registration instruction is at least used to control the memory database to register the frozen amount and obtain a cached amount. The cached amount is used to deduct when the memory database executes a transaction.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored program, wherein when the program is executed by a processor, the processor performs the method according to any one of claims 1 to 6.
9. A trading system, characterized in that, include: The application server, the in-memory database, the business database, one or more processors, a memory, and one or more programs, wherein the application server is communicatively connected to the in-memory database and the business database, the in-memory database is used to execute transactions for hot accounts, and the business database is used to execute transactions for both hot and non-hot accounts, wherein a hot account is an account whose transaction concurrency exceeds a predetermined concurrency level, and the one or more programs are stored in the memory and configured to be executed by the one or more processors, the one or more programs comprising methods for performing any one of claims 1 to 6.
Citation Information
Patent Citations
Data consistency implementation method, device and equipment and computer storage medium
CN111488367A
Hotspot account service method and device, storage medium and electronic equipment
CN114328726A