Transaction processing method for memory data operations
By adding a memory cache between the business layer and the database, and defining transaction functions and log lists to capture error rollback operations, the problem of memory data integrity and consistency in low-latency data access is solved, achieving the correctness of memory data and simplifying code management.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- XIAMEN FEIYOU INFORMATION TECH CO LTD
- Filing Date
- 2022-07-06
- Publication Date
- 2026-07-31
AI Technical Summary
In low-latency data access applications, existing technologies cannot effectively guarantee the integrity and consistency of memory data, and code management is chaotic.
A memory cache is added between the business layer and the database, transaction functions and log lists are defined, errors are caught through an exception mechanism, and operations are rolled back when errors occur, so as to achieve the integrity and consistency of in-memory data and support nested transaction processing.
It ensures the integrity and consistency of in-memory data, simplifies code management, improves development efficiency, and supports nested transaction processing.
Smart Images

Figure CN115185648B_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of memory data operation technology, and specifically relates to a transaction processing method for memory data operations. Background Technology
[0002] Database transactions play a crucial role in data access, ensuring that one or more database operations form a logical whole. Within this whole, all database operations either succeed successfully or fail entirely, thus guaranteeing data integrity. For example, in bank transfers, it's unacceptable for money to be deducted from one account while the other party doesn't receive it; database transactions ensure data integrity after such operations. However, in applications with low-latency data access requirements, such as online games, caching techniques are often used to store data in high-performance memory. Ensuring that this in-memory data also forms a coherent whole is a challenge that needs to be addressed.
[0003] The current approach typically involves writing error handling methods and data processing logic in each business logic instance, based on different requirements each time. This method leads to chaotic code management and cannot effectively guarantee the correctness of in-memory data. Summary of the Invention
[0004] To address the shortcomings of existing technologies, this invention provides a transaction processing method for memory data operations, which can effectively solve the above-mentioned problems.
[0005] The technical solution adopted in this invention is as follows:
[0006] This invention provides a transaction processing method for memory data operations, comprising the following steps:
[0007] Step 1: Add memory as a cache between the business layer and the database; when the business layer starts a new user process pro_user, load the user data corresponding to the user process pro_user stored in the database into memory;
[0008] Step 2: When the user process pro_user sends n operation instructions to the user data in memory, where n is a natural number and the n operation instructions have an execution logic relationship, a transaction function tran(A) corresponding to the current operation instruction is defined according to the execution logic relationship of the n operation instructions, and the n operation instructions are put into the transaction function tran(A);
[0009] Step 3: Create the do transaction execution function corresponding to this operation instruction; the do transaction execution function creates the tran_log log list in the inner layer and sets the tran_log log list to an empty list at its initial state;
[0010] The transaction function tran(A) is passed as a parameter to the do transaction execution function, which then executes n memory operation instructions according to the execution logic. During the execution of these n instructions, the memory operation process is added to the tran_log log list in real time. Simultaneously, an exception mechanism is used to catch errors in the operation process. If an error is caught, step 4 is executed. If no error is caught, it indicates that the n memory operation instructions have been successfully executed. The transaction function tran(A), the tran_log log list, and the do transaction execution function are then unregistered. The execution of these n instructions is complete, and then step 5 is executed.
[0011] Step 4: Traverse the tran_log log list in reverse order. Based on the memory operation process recorded in the tran_log log list, roll back the executed operation process to restore the memory user data to the initial state before the execution of the current n operation instructions. Then, cancel the transaction function tran(A), the tran_log log list, and the do transaction execution function, and stop executing the current n operation instructions, thus ending the current processing flow.
[0012] Step 5: Send the memory operation process recorded in the tran_log log list to the data persistence process. The data persistence process will convert the memory operation process into SQL statements and send them asynchronously to the persistence file process and the persistence database process.
[0013] The file persistence process writes SQL statements into a file and saves it on the local machine for backup; the database persistence process connects to the MySQL database via a socket, sends SQL statements to the database, completes the database operations, realizes the synchronization between the database and memory, and completes the data persistence.
[0014] Preferably, the do transaction execution function created in step 3 is a multi-level do transaction execution function with a nested relationship, including an outer do transaction execution function and an inner do transaction execution function;
[0015] When the transaction function tran(A) is passed to the do transaction execution function, according to the execution logic of the n operation instructions contained in the transaction function tran(A), some operation instructions are placed into the inner do transaction execution function, some operation instructions are placed into the outer do transaction execution function, and some are not located in the inner do transaction execution function.
[0016] Preferably, for multi-level do transaction execution functions with nested relationships, they share the same tran_log log list.
[0017] Preferably, memory operation instructions include three categories: insertion operations, update operations, and deletion operations;
[0018] If it is an insert operation, the key of the newly inserted data will be recorded in the tran_log log list;
[0019] If it is an update operation, the old data to be updated will be recorded in the tran_log log list;
[0020] If it is a deletion operation, the old data to be deleted will be recorded in the tran_log log list;
[0021] During rollback, perform the following restore operations:
[0022] If it is an insert operation, the key of the new data is read from the tran_log log list, and the new data is deleted from memory;
[0023] If it is an update operation, the old data is read from the tran_log log list and the old data is used to update the corresponding new data;
[0024] If it is a deletion operation, the old data to be deleted is read from the tran_log log list and then the old data is re-inserted into the corresponding memory location.
[0025] The transaction processing method for memory data operations provided by this invention has the following advantages:
[0026] In this invention, a custom set of memory transactions is defined to handle memory operations performed by the business layer. When operating on memory data, the memory transaction processing mechanism ensures the integrity and correctness of the memory data and supports nesting, making it usable on both the server and client sides. Attached Figure Description
[0027] Figure 1 A detailed flowchart illustrating the transaction processing method for memory data operations provided by this invention;
[0028] Figure 2 A simplified flowchart illustrating the transaction processing method for memory data operations provided by this invention;
[0029] Figure 3 The schematic diagram of the multi-level do transaction execution function with nested relationship provided by the present invention. Detailed Implementation
[0030] To make the technical problems solved, the technical solutions, and the beneficial effects of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and are not intended to limit the invention.
[0031] This invention provides a transaction processing method for memory data operations, referencing... Figure 1 and Figure 2 This includes the following steps:
[0032] Step 1: Add memory as a cache between the business layer and the database; when the business layer starts a new user process pro_user, load the user data corresponding to the user process pro_user stored in the database into memory;
[0033] This invention is applicable to application scenarios that require low latency for data access. Therefore, a memory layer is added between the business layer and the database as a cache, loading user data stored in the database into memory. In subsequent processes, operations are performed directly on the user data stored in memory, thereby improving the data access speed.
[0034] Step 2: When the user process pro_user sends n operation instructions to the user data in memory, where n is a natural number and the n operation instructions have an execution logic relationship, a transaction function tran(A) corresponding to the current operation instruction is defined according to the execution logic relationship of the n operation instructions, and the n operation instructions are put into the transaction function tran(A);
[0035] In this invention, by defining a transaction function, all operation instructions that need to be included in a transaction are placed in the transaction function, which is used to determine the execution scope of the subsequent do transaction execution function.
[0036] Step 3: Create the do transaction execution function corresponding to this operation instruction; the do transaction execution function creates the tran_log log list in the inner layer and sets the tran_log log list to an empty list at its initial state;
[0037] The transaction function tran(A) is passed as a parameter to the do transaction execution function, which then executes n memory operation instructions according to the execution logic. During the execution of these n instructions, the memory operation process is added to the tran_log log list in real time. Simultaneously, an exception mechanism is used to catch errors in the operation process. If an error is caught, it indicates that an operation has failed within the transaction. To ensure the integrity of the memory data, the already executed operations need to be rolled back, i.e., step 4 is executed. If no error is caught, it indicates that the n memory operation instructions have been successfully executed. The transaction function tran(A), the tran_log log list, and the do transaction execution function are then unregistered. The execution of these n operation instructions is complete, and then step 5 is executed.
[0038] In this step, based on the execution logic of the n operation instructions, the created do transaction execution function can be a multi-level do transaction execution function with a nested relationship, including an outer do transaction execution function and an inner do transaction execution function. When the transaction function tran(A) is passed to the do transaction execution function, according to the execution logic of the n operation instructions contained in the transaction function tran(A), some operation instructions are placed into the inner do transaction execution function, and some operation instructions are placed into the outer do transaction execution function, but not within the inner do transaction execution function. For example... Figure 3 The diagram shows the principle of a nested multi-level do transaction execution function. These nested multi-level do transaction execution functions share the same tran_log log list.
[0039] exist Figure 3 There are two layers of DO transaction execution functions: the outer DO transaction execution function and the inner DO transaction execution function. Their execution process is as follows:
[0040] First, the outer DO transaction execution function is started. It checks if the `tran_log` log list has already been created; since it hasn't, it creates the `tran_log` log list and then executes operations 1 and 2. Next, the inner DO transaction execution function is started. It checks if the `tran_log` log list has already been created; since it has, it doesn't create a new `tran_log` log list and executes operations 3 and 4. Then, the outer DO transaction execution function is started again, executing operations 5 and 6, thus completing the execution of operations 1-6. Throughout this process, the outer and inner DO transaction execution functions share the same `tran_log` log list.
[0041] Step 4: Traverse the tran_log log list in reverse order. Based on the memory operation process recorded in the tran_log log list, roll back the executed operation process to restore the memory user data to the initial state before the execution of the current n operation instructions. Then, cancel the transaction function tran(A), the tran_log log list, and the do transaction execution function, and stop executing the current n operation instructions, thus ending the current processing flow.
[0042] Specifically, memory operation instructions fall into three categories: insertion operations, update operations, and deletion operations.
[0043] If it is an insert operation, the key of the newly inserted data will be recorded in the tran_log log list;
[0044] If it is an update operation, the old data to be updated will be recorded in the tran_log log list;
[0045] If it is a deletion operation, the old data to be deleted will be recorded in the tran_log log list;
[0046] During rollback, perform the following restore operations:
[0047] If it is an insert operation, the key of the new data is read from the tran_log log list, and the new data is deleted from memory;
[0048] If it is an update operation, the old data is read from the tran_log log list and the old data is used to update the corresponding new data;
[0049] If it is a deletion operation, the old data to be deleted is read from the tran_log log list and then the old data is re-inserted into the corresponding memory location.
[0050] Step 5: Send the memory operation process recorded in the tran_log log list to the data persistence process. The data persistence process will convert the memory operation process into SQL statements and send them asynchronously to the persistence file process and the persistence database process.
[0051] The file persistence process writes SQL statements into a file and saves it on the local machine for backup; the database persistence process connects to the MySQL database via a socket, sends SQL statements to the database, completes the database operations, realizes the synchronization between the database and memory, and completes the data persistence.
[0052] In this invention, because a memory layer is added as a cache between the business layer and the database, database transactions cannot be directly reflected back to the business layer. Therefore, this invention defines a custom set of memory transactions to handle business layer operations on memory. When operating on memory data, the memory transaction processing mechanism ensures the integrity and correctness of the memory data and supports nesting, making it usable on both the server and client sides.
[0053] The present invention has the following advantages:
[0054] 1) When operating on memory data, the integrity of the memory data is ensured through a memory transaction processing mechanism;
[0055] 2) It provides a unified user interface, making code management simpler, improving development efficiency, and eliminating the risk of errors caused by rewriting transaction logic code every time.
[0056] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A transaction processing method for memory data operations, characterized in that, Includes the following steps: Step 1: Add memory as a cache between the business layer and the database; when the business layer starts a new user process pro_user, load the user data corresponding to the user process pro_user stored in the database into memory; Step 2: When the user process pro_user sends n operation instructions to the user data in memory, where n is a natural number and the n operation instructions have an execution logic relationship, a transaction function tran(A) corresponding to the current operation instruction is defined according to the execution logic relationship of the n operation instructions, and the n operation instructions are put into the transaction function tran(A); Step 3: Create the do transaction execution function corresponding to this operation instruction; the do transaction execution function creates the tran_log log list in the inner layer and sets the tran_log log list to an empty list at its initial state; The transaction function tran(A) is passed as a parameter to the do transaction execution function, which then executes n memory operation instructions according to the execution logic. During the execution of these n instructions, the memory operation process is added to the tran_log log list in real time. Simultaneously, an exception mechanism is used to catch errors in the operation process. If an error is caught, step 4 is executed. If no error is caught, it indicates that the n memory operation instructions have been successfully executed. The transaction function tran(A), the tran_log log list, and the do transaction execution function are then unregistered. The execution of these n instructions is complete, and then step 5 is executed. Step 4: Traverse the tran_log log list in reverse order. Based on the memory operation process recorded in the tran_log log list, roll back the executed operation process to restore the memory user data to the initial state before the execution of the current n operation instructions. Then, cancel the transaction function tran(A), the tran_log log list, and the do transaction execution function, and stop executing the current n operation instructions, thus ending the current processing flow. Step 5: Send the memory operation process recorded in the tran_log log list to the data persistence process. The data persistence process will convert the memory operation process into SQL statements and send them asynchronously to the persistence file process and the persistence database process. The file persistence process writes SQL statements into a file and saves it on the local machine for backup; the database persistence process connects to the MySQL database via a socket, sends SQL statements to the database, completes the database operations, realizes the synchronization between the database and memory, and completes the data persistence.
2. The transaction processing method for memory data operations according to claim 1, characterized in that, The do transaction execution function created in step 3 is a multi-level do transaction execution function with a nested relationship, including an outer do transaction execution function and an inner do transaction execution function; When the transaction function tran(A) is passed to the do transaction execution function, according to the execution logic of the n operation instructions contained in the transaction function tran(A), some operation instructions are placed into the inner do transaction execution function, some operation instructions are placed into the outer do transaction execution function, and some are not located in the inner do transaction execution function.
3. The transaction processing method for memory data operations according to claim 2, characterized in that, For multi-level do transaction execution functions with nested relationships, they share the same tran_log log list.
4. The transaction processing method for memory data operations according to claim 1, characterized in that, Memory operation instructions fall into three categories: insertion operations, update operations, and deletion operations. If it is an insert operation, the key of the newly inserted data will be recorded in the tran_log log list; If it is an update operation, the old data to be updated will be recorded in the tran_log log list; If it is a deletion operation, the old data to be deleted will be recorded in the tran_log log list; During rollback, perform the following restore operations: If it is an insert operation, the key of the new data is read from the tran_log log list, and the new data is deleted from memory; If it is an update operation, the old data is read from the tran_log log list and the old data is used to update the corresponding new data; If it is a deletion operation, the old data to be deleted is read from the tran_log log list and then the old data is re-inserted into the corresponding memory location.