Operation log replication method and system for distributed transactions based on non-volatile memory
By using non-volatile memory to parallelly copy operation logs in a distributed transaction system, the problem of distributed transaction submission delay is solved, more efficient log replication and recovery is achieved, and the reliability and throughput of the system are improved.
Patent Information
- Application Number
- CN202111101120.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-09-18
- Publication Date
- 2024-10-18
- Estimated Expiration
- 2041-09-18
AI Technical Summary
The existing distributed transaction system based on RDMA high-speed network needs to wait for log replication and persistence before transaction submission, resulting in large submission delay and affecting the reliability and high availability of the system.
A distributed transaction operation log copy method based on non-volatile memory is adopted. The coordinator obtains the read set on the main server and generates the write set. The log is copied to the backup server in parallel to reduce waiting time and upload data under optimistic concurrency control. Lock and verify operations are performed in parallel with log replication.
It greatly reduces the waiting time before distributed transaction submission, reduces the submission delay, improves the system throughput, and reduces the overhead of replaying the operation log during crash recovery.
Smart Images

Figure CN113868336B_ABST
Abstract
Description
Technical Field
[0001] The present invention belongs to the field of computer data storage, and more specifically, relates to an operation log replication method and system for distributed transactions based on non-volatile memory. Background Art
[0002] In recent years, RDMA high-speed networks have emerged in data centers. RDMA networks with low latency, high bandwidth and low CPU overhead have greatly improved the performance of distributed transactions. RDMA networks allow direct access to the memory of remote machines without the participation of the kernels of both parties, and support copy-free data transmission. Therefore, most existing distributed transaction systems are implemented based on RDMA networks. RDMA networks provide two types of primitives: unilateral RDMA primitives and bilateral RDMA primitives. Among them, unilateral RDMA primitives include read, write and atomic (READ, WRITE, ATOMIC) operations; bilateral RDMA primitives include send and receive (SEND, RECEIVE) operations. In distributed transaction systems, hardware, software and network errors are frequent. In order to provide reliability and high availability, data logs need to be copied and persisted to remote servers.
[0003] However, in the existing distributed transaction system based on RDMA high-speed network, before the distributed transaction is committed, it is necessary to wait for the data log to be replicated and persisted to the remote server. The data log replication operation needs to wait for the locking operation and verification operation to be completed before it can be performed, which makes the log replication and persistence overhead on the critical path of transaction submission relatively large. Summary of the invention
[0004] In view of the above defects or improvement needs of the prior art, the present invention provides an operation log replication method and system based on non-volatile memory distributed transactions, the purpose of which is to significantly reduce the waiting time for the log replication process before the submission of distributed transactions and reduce the submission delay of distributed transactions while ensuring the reliability and high availability of the distributed transaction processing system.
[0005] In order to achieve the above object, in a first aspect, the present invention provides an operation log replication method for distributed transactions based on non-volatile memory, comprising the following steps:
[0006] S1. Enable the coordinator of the distributed transaction to obtain the read set of the distributed transaction from the non-volatile memory on the primary server, execute the distributed transaction locally, generate the corresponding operation log and cache the write set of the distributed transaction;
[0007] S2. At the same time as the coordinator sends a lock request to the primary server containing the write set, it starts to copy the operation log to the non-volatile memory on the backup server, so that this operation is executed in parallel with the lock operation and subsequent verification operations;
[0008] The above-mentioned distributed transaction is a distributed transaction using optimistic concurrency control.
[0009] Further preferably, a unilateral RDMA write operation is used to copy the operation log to the backup server.
[0010] Further preferably, the above operation log includes: transaction ID, transaction type and transaction parameters; wherein the transaction type indicates the type of logical transactions included in the OLTP application; and the transaction parameters indicate input parameters of the logical transactions.
[0011] Further preferably, the operation log replication method of non-volatile memory distributed transactions also includes: when recovering after a machine failure, the coordinator replays the operation logs in the non-volatile memory on the backup server in sequence according to the order in which the distributed transactions are committed, so that the distributed transaction system is restored to the state before the failure; wherein the distributed transaction commit operation is executed after the operation of copying the operation logs to the non-volatile memory on the backup server is completed; when the distributed transaction is committed, the coordinator sends the ID of the distributed transaction to the primary server and the backup server, and records the submission order of the distributed transaction.
[0012] Further preferably, the coordinator analyzes data dependencies between transactions according to transaction types and input parameters in the operation logs, and replays operation logs without data dependencies in parallel to reduce recovery delays caused by replaying the operation logs.
[0013] Further preferably, the logic of the distributed transaction is stored in the non-volatile memory on all servers in advance; when the operation log is replayed, the corresponding transaction logic is found in the non-volatile memory according to the transaction type recorded in the operation log, and the transaction parameters in the operation log are used as input to execute the transaction logic.
[0014] In a second aspect, the present invention provides an operation log replication system for non-volatile memory distributed transactions, comprising:
[0015] An operation log generation module is used to enable the coordinator of the distributed transaction to obtain the read set of the distributed transaction from the non-volatile memory on the master server, execute the distributed transaction locally, generate the corresponding operation log and cache the write set of the distributed transaction;
[0016] The operation log parallel replication module is used to start the operation of copying the operation log to the non-volatile memory on the backup server at the same time as the coordinator sends a lock request to the primary server containing the write set, so that this operation is executed in parallel with the locking operation and the subsequent verification operation;
[0017] The above-mentioned distributed transaction is a distributed transaction using optimistic concurrency control.
[0018] Further preferably, the above-mentioned operation log replication system also includes an operation log replay module, which is used to enable the coordinator to replay the operation logs in the non-volatile memory on the backup server in sequence according to the order of distributed transaction submission when recovering after a machine failure, so as to restore the distributed transaction system to the state before the failure; wherein the distributed transaction submission operation is executed after the operation of copying the operation log to the non-volatile memory on the backup server is completed; when the distributed transaction is committed, the coordinator sends the ID of the distributed transaction to the primary server and the backup server, and records the submission order of the distributed transaction.
[0019] In a third aspect, the present invention further provides a machine-readable storage medium, which stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the operation log replication method for distributed transactions based on non-volatile memory provided in the first aspect of the present invention.
[0020] In general, the above technical solutions conceived by the present invention can achieve the following beneficial effects:
[0021] 1. The present invention provides an operation log replication method for distributed transactions based on non-volatile memory, which replicates the operation log to the replica server in parallel during the locking stage and the verification stage of the optimistic concurrency control of the distributed transaction, thereby reducing the time waiting for the log replication to be completed. Under the premise of ensuring the reliability and high availability of the distributed transaction processing system, the waiting time for the log replication process before the distributed transaction is submitted is greatly reduced, thereby reducing the submission delay of the distributed transaction.
[0022] 2. The operation log replication method provided by the present invention adopts an operation log, which only needs to record the transaction ID, transaction type and transaction parameters, and does not need to record the output results of the transaction execution, thereby greatly reducing the size of the log, thereby reducing the amount of data written to the NVM during the log replication process, reducing the persistence overhead, and improving the throughput of the distributed transaction processing system.
[0023] 3. The operation log replication method provided by the present invention selectively replays the operation logs in parallel during crash recovery, and replays the operation logs without data dependencies in parallel by analyzing the data correlation between the transactions corresponding to the operation logs. For the operation logs without data dependencies, the replay results are independent of the replay order, so the results of parallel replay of these operation logs are consistent with the serial replay, and parallel replay greatly reduces the system recovery delay and reduces the recovery overhead of replaying the operation logs after a machine failure. BRIEF DESCRIPTION OF THE DRAWINGS
[0024] Figure 1A flow chart of an operation log replication method for distributed transactions based on non-volatile memory provided in Example 1 of the present invention;
[0025] Figure 2 A schematic diagram comparing the parallel replication process and the serial replication process of the operation log provided in Example 1 of the present invention;
[0026] Figure 3 A schematic diagram of the physical storage structure of the operation log provided in Example 1 of the present invention;
[0027] Figure 4 A schematic diagram of a flow chart of an operation log replication method under an optional implementation mode provided in Example 1 of the present invention;
[0028] Figure 5 A flowchart of an operation log replay method under an optional implementation mode provided in Example 1 of the present invention;
[0029] Figure 6 A flowchart of a method for selectively replaying operation logs in parallel under an optional implementation mode provided in Example 1 of the present invention. DETAILED DESCRIPTION
[0030] In order to make the purpose, technical solutions and advantages of the present invention more clearly understood, the present invention is further described in detail below in conjunction with the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present invention and are not intended to limit the present invention. In addition, the technical features involved in the various embodiments of the present invention described below can be combined with each other as long as they do not conflict with each other.
[0031] Embodiment 1,
[0032] An operation log replication method for distributed transactions based on non-volatile memory, such as Figure 1 As shown, the following steps are included:
[0033] S1. Enable the coordinator of the distributed transaction to obtain the read set of the distributed transaction from the non-volatile memory on the primary server, execute the distributed transaction locally, generate the corresponding operation log and cache the write set of the distributed transaction; wherein, the distributed transaction is a distributed transaction using optimistic concurrency control; optimistic concurrency control requires the execution of locking and subsequent verification operations, at which time log replication can be executed in parallel; in addition, optimistic concurrency control is suitable for distributed transaction systems with fewer conflicts, so that fewer operation logs are marked as invalid in the backup server.
[0034] The log used in the present invention is an operation log. The operation log does not record the value of the modified data, but only records the transaction type and input parameters. Compared with the output results of transaction execution recorded in the data log, the operation log greatly reduces the size of the log, thereby reducing the amount of data persisted in the log replication process, reducing the persistence overhead, and improving the throughput of the distributed transaction processing system.
[0035] S2. At the same time as the coordinator sends a lock request to the primary server containing the write set, it starts to copy the operation log to the non-volatile memory on the backup server, so that this operation is executed in parallel with the lock operation and subsequent verification operations;
[0036] Specifically, Figure 2 The diagram shows a comparison of the parallel operation log replication process and the serial operation log replication process. It can be seen from the figure that, compared with the serial method, the parallel operation log replication method provided by the present invention advances the operation log replication process and starts at the same time as the locking process; the operation log replication is parallel to the locking and verification stage, which saves the time of operation log replication. It should be noted that regardless of whether the locking and verification stage is successful, the operation log will be copied to the non-volatile memory on the backup server. There are two situations when entering the transaction commit stage. If the locking and verification are successful, and the coordinator receives a response that the operation log is successfully copied, the transaction commit stage is directly entered; if the locking and verification are successful, but the coordinator does not receive a response that the operation log is successfully copied, wait for the operation log to be successfully copied, and then enter the transaction commit stage; because the operation log replication is executed in parallel with the locking and verification stage, the waiting for the log replication process before the distributed transaction is committed is greatly reduced, so the above two situations can reduce the distributed transaction commit delay.
[0037] It should be noted that the present invention is an operation log replication method for distributed transactions based on non-volatile memory, and non-volatile memory (NVM) has extremely low persistence overhead. By connecting NVM to the memory bus, the application can directly access the persistent data in NVM through the load and store instructions of the CPU, which has read and write delays similar to DRAM, byte addressability and non-volatility, blurring the boundary between memory and storage. Commonly used non-volatile memories include 3D-XPoint, phase change memory (PCM), resistive random access memory (ReRAM) and spin torque memory (STT-RAM). Compared with DRAM, NVM has a much larger storage capacity; however, the write bandwidth of NVM is only 1 / 3 to 1 / 8 of the write bandwidth of DRAM; therefore, although NVM provides an opportunity for low-overhead distributed transaction log replication, due to the low write bandwidth of NVM, the log replication process becomes a system bottleneck, hindering the improvement of the throughput of the distributed transaction processing system. The present invention reduces the amount of data written to the NVM during the log replication process by performing parallel replication of the operation log, reduces the write bandwidth pressure on the NVM, reduces the persistence overhead, and improves the throughput of the distributed transaction processing system.
[0038] Furthermore, the RDMA network provides two types of primitives: unilateral RDMA primitives and bilateral RDMA primitives; wherein, unilateral RDMA primitives include read, write and atomic (READ, WRITE, ATOMIC) operations; bilateral RDMA primitives include send and receive (SEND, RECEIVE) operations. By using bilateral RDMA primitives, users can bypass the kernel of the remote machine to exchange RPC information, but the CPU of the remote machine needs to be occupied; and by using unilateral RDMA primitives, users can bypass the CPU and kernel of the remote machine and directly access the memory of the remote machine, so preferably, the present invention adopts unilateral RDMA write operations to copy the operation log to the backup server.
[0039] It should be noted that if Figure 3 The figure shows a schematic diagram of the physical storage structure of the operation log. In this embodiment, the operation log stores three items of data, namely, transaction ID, transaction type and transaction parameters; wherein the transaction type represents the logical transaction type contained in the OLTP application (such as transaction types such as create order and order payment in the order management application); the transaction parameter represents the input parameter of the logical transaction (such as the input parameters for create order include warehouse ID, customer ID and product quantity, etc.).
[0040] Furthermore, in an optional implementation, the above-mentioned non-volatile memory distributed transaction operation log replication method also includes: when recovering after a machine failure, the coordinator replays the operation logs in the non-volatile memory on the backup server in sequence according to the order in which the distributed transactions are committed, so that the distributed transaction system is restored to the state before the failure; wherein the distributed transaction commit operation is executed after the operation of copying the operation log to the non-volatile memory on the backup server is completed; when the distributed transaction is committed, the coordinator sends the ID of the distributed transaction to the primary server and the backup server, and records the submission order of the distributed transaction.
[0041] Specifically, the logic of distributed transactions is stored in the non-volatile memory of all servers in advance; when the operation log is replayed, the corresponding transaction logic is found in the non-volatile memory according to the transaction type recorded in the operation log, and the transaction parameters in the operation log are used as input to execute the transaction logic.
[0042] like Figure 4 The figure shows a flow chart of an operation log replication method under an optional implementation mode; first, the coordinator obtains the read set of the transaction from the non-volatile memory on the primary server, executes the transaction locally, generates the corresponding operation log and caches the write set of the transaction. After that, when the coordinator sends a lock request to the primary server containing the write set, the coordinator starts to use the unilateral RDMA write operation in parallel to copy the operation log to the non-volatile memory on the backup server; the operation log replication is parallel to the locking and verification phase, and the operation log will be copied to the non-volatile memory on the backup server regardless of whether the locking and verification phases are successful. In the commit phase of the distributed transaction, the coordinator sends the transaction ID to the primary server and the backup server, and records the commit order of the distributed transaction. When recovering after a machine failure, the coordinator replays the operation logs in the backup server in the order in which the transactions were committed.
[0043] Specifically, Figure 5 The figure is a flow chart of an operation log replay method under an optional implementation mode. In this implementation mode, after executing distributed transactions T1, T2, T3, T4, and T5, the main server fails. When the committed transactions are restored through the backup server, the operation log is replayed. The specific operations are as follows:
[0044] Obtain the committed transaction set (T1, T2, T4, T5), the aborted transaction set (T3), and the transaction commit sequence (T1, T2, T4, T5) from the log records of the backup server, scan all operation logs from the beginning of the operation log area, delete the operation logs of the aborted transactions, and replay the operation logs of the committed transactions in the order of transaction commit. When replaying the operation log, map the transaction type recorded in the operation log to the transaction logic stored in the backup server, and use the transaction parameters in the operation log as the input data of the transaction to execute the transaction logic.
[0045] Preferably, in order to further reduce the recovery delay caused by replaying the operation log, the coordinator can selectively replay the operation log in parallel according to the transaction type recorded in the operation log and the input parameters of the transaction. Figure 6 The figure shows a flow chart of a method for selectively replaying operation logs in parallel under an optional implementation mode. Under this implementation mode, after executing distributed transactions T1, T2, T3, T4, and T5, the main server fails. When the committed transactions are restored through the backup server, the operation logs are selectively replayed, and the operation logs without data dependency are specifically selected for parallel replay to reduce the recovery delay of the replayed operation logs. The specific operations are as follows:
[0046] Scan all operation logs starting from the starting position of the operation log area, ignoring the operation logs of aborted transactions; analyze the read set and write set of the transaction according to the transaction type and transaction parameters of the operation log; generate a transaction data dependency graph based on the correlation between the read set and write set between transactions and the order of transaction submission, and obtain a transaction set (T1, T2) without data dependency; and replay all transactions in the transaction set without data dependency in parallel to reduce recovery delay.
[0047] Under the premise of ensuring the reliability and high availability of the distributed transaction processing system, the present invention greatly reduces the waiting time for the log replication process before the distributed transaction is submitted, thereby reducing the submission delay of the distributed transaction; in addition, the present invention reduces the amount of data written to the NVM during the log replication process, reduces the persistence overhead, and further improves the throughput of the distributed transaction processing system; it also reduces the recovery overhead of replaying the operation log after a machine failure.
[0048] Embodiment 2,
[0049] An operation log replication system for non-volatile memory distributed transactions, comprising:
[0050] An operation log generation module is used to enable the coordinator of the distributed transaction to obtain the read set of the distributed transaction from the non-volatile memory on the master server, execute the distributed transaction locally, generate the corresponding operation log and cache the write set of the distributed transaction;
[0051] The operation log parallel replication module is used to start the operation of copying the operation log to the non-volatile memory on the backup server at the same time as the coordinator sends a lock request to the primary server containing the write set, so that this operation is executed in parallel with the locking operation and the subsequent verification operation;
[0052] The above-mentioned distributed transaction is a distributed transaction using optimistic concurrency control.
[0053] Furthermore, in an optional implementation, the above-mentioned operation log replication system also includes an operation log replay module, which is used to enable the coordinator to replay the operation logs in the non-volatile memory on the backup server in sequence according to the order of distributed transaction submission when recovering after a machine failure, so as to restore the distributed transaction system to the state before the failure; wherein the distributed transaction submission operation is executed after the operation of copying the operation log to the non-volatile memory on the backup server is completed; when the distributed transaction is committed, the coordinator sends the ID of the distributed transaction to the primary server and the backup server, and records the submission order of the distributed transaction.
[0054] The relevant technical solution is the same as that in Example 1 and will not be described in detail here.
[0055] Embodiment 3,
[0056] A machine-readable storage medium stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the operation log replication method of non-volatile memory distributed transactions provided in Example 1.
[0057] The relevant technical solution is the same as that in Example 1 and will not be described in detail here.
[0058] It will be easily understood by those skilled in the art that the above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions and improvements made within the spirit and principles of the present invention should be included in the protection scope of the present invention.
Claims
1. A method for replicating operation logs of distributed transactions based on non-volatile memory, characterized in that: The following steps are involved: S1. Enable the coordinator of the distributed transaction to obtain the read set of the distributed transaction from the non-volatile memory on the primary server, execute the distributed transaction locally, generate the corresponding operation log and cache the write set of the distributed transaction; S2, while the coordinator sends a lock request to the primary server containing the write set, starts to execute the operation of copying the operation log to the non-volatile memory on the backup server, so that the operation is executed in parallel with the locking operation and the subsequent verification operation; Wherein, the distributed transaction is a distributed transaction using optimistic concurrency control; The operation log replication method further includes: when recovering after a machine failure, causing the coordinator to sequentially replay the operation logs in the non-volatile memory on the backup server in the order in which the distributed transaction is committed, so that the distributed transaction system is restored to the state before the failure; wherein the distributed transaction commit operation is performed after the operation of copying the operation log to the non-volatile memory on the backup server is completed; when the distributed transaction is committed, causing the coordinator to send the ID of the distributed transaction to the primary server and the backup server, and record the submission order of the distributed transaction; The logic of distributed transactions is stored in the non-volatile memory of all servers in advance. When replaying the operation log, the corresponding transaction logic is found in the non-volatile memory according to the transaction type recorded in the operation log, and the transaction parameters in the operation log are used as input to execute the transaction logic.
2. The operation log replication method according to claim 1, characterized in that: The coordinator analyzes data dependencies between transactions according to transaction types and input parameters in the operation log, and replays operation logs without data dependencies in parallel, so as to reduce recovery delay caused by replaying the operation logs.
3. The operation log replication method according to any one of claims 1 to 2, characterized in that: In step S2, the operation log is copied to the backup server using a unilateral RDMA write operation.
4. The operation log replication method according to any one of claims 1 to 2, characterized in that: The operation log includes: a transaction ID, a transaction type and a transaction parameter; wherein the transaction type indicates a logical transaction type included in the OLTP application; and the transaction parameter indicates an input parameter of the logical transaction.
5. An operation log replication system for non-volatile memory distributed transactions, characterized in that: include: An operation log generation module, used to enable the coordinator of the distributed transaction to obtain the read set of the distributed transaction from the non-volatile memory on the master server, and execute the distributed transaction locally, generate the corresponding operation log and cache the write set of the distributed transaction; the distributed transaction is a distributed transaction using optimistic concurrency control; An operation log parallel replication module, configured to start executing an operation of replicating the operation log to a non-volatile memory on a backup server while the coordinator sends a lock request to the primary server containing the write set, so that the operation is executed in parallel with the lock operation and the subsequent verification operation; The operation log replay module is used to enable the coordinator to replay the operation logs in the non-volatile memory on the backup server in sequence according to the order of distributed transaction submission when recovering from a machine failure, so as to restore the distributed transaction system to the state before the failure; wherein the distributed transaction submission operation is performed after the operation of copying the operation log to the non-volatile memory on the backup server is completed; when the distributed transaction is submitted, the coordinator sends the ID of the distributed transaction to the primary server and the backup server, and records the submission order of the distributed transaction; The logic of the distributed transaction is stored in the non-volatile memory on all servers in advance; when the operation log is replayed, the corresponding transaction logic is found in the non-volatile memory according to the transaction type recorded in the operation log, and the transaction parameters in the operation log are used as input to execute the transaction logic.
6. A machine-readable storage medium storing machine-executable instructions, wherein when the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the operation log replication method according to any one of claims 1 to 4.
Citation Information
Patent Citations
Distributed transaction security method for memory data grid
CN103473318A
Distributed data retracement method and device and computer readable storage medium
CN110309227A
