A data caching method and a data caching system

By optimizing the data caching and flushing process of the caching system through remote data access and data block sequence number mechanism of master-slave nodes, the problems of low performance and long fault recovery time of the caching system are solved, and efficient data synchronization and consistency management are achieved.

CN122261496BActive Publication Date: 2026-08-04LANGCHAO ELECTRONIC INFORMATION IND CO LTD
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202610737946.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2026-05-27
Publication Date
2026-08-04
Estimated Expiration
2046-05-27

AI Technical Summary

Technical Problem

Caching systems consume a lot of protocol communication and CPU resources when managing multiple replicas, leading to performance degradation and increased latency, especially in data synchronization and refresh tasks where efficiency is low.

Method used

A data caching method using master and slave nodes is adopted. Through a remote data access mechanism, the written data is directly cached in the slave node's memory and merged and flushed to the storage device when the master data block is full. This reduces protocol communication and CPU resource consumption. Data block sequence number and write sequence number are used to ensure data consistency and fault recovery.

Benefits of technology

It effectively reduces the communication volume and CPU resource consumption of the caching system, improves processing efficiency and data synchronization speed, simplifies the flushing task, shortens the fault recovery time, and improves system performance and reliability.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122261496B_ABST
    Figure CN122261496B_ABST
Patent Text Reader

Abstract

The application provides a data caching method and a data caching system, and relates to the field of storage. The method is applied to a caching system, the caching system comprises a master node and a slave node, and the method comprises the following steps: when receiving a write request, the master node caches write data in the write request to a master data block in the master node memory, and marks a dirty data state for the master data block; wherein the master data block is used for caching at least two write requests; the master node initiates remote data access to the slave node memory, caches the write data to a slave data block mapped with the master data block in the slave node memory, and marks a dirty data state for the slave data block; when determining that the master data block is full, the master node stores the write data in the master data block to a storage device, marks the master data block as an idle state, initiates remote data access to the slave node memory, and synchronizes the idle state to the slave data block; the method can reduce the protocol communication processing involved in the data caching of the caching system and improve the processing efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of storage, and in particular to a data caching method and a data caching system. Background Technology

[0002] As the link between front-end devices and back-end storage devices, the caching system plays a decisive role in the performance of the storage system.

[0003] In related technologies, caching systems typically manage data using a multi-replica approach across multiple cache nodes. However, to ensure data redundancy requirements, extensive protocol communication and data synchronization are involved between cache nodes, posing a significant challenge to the performance of the caching system. Summary of the Invention

[0004] The purpose of this invention is to provide a data caching method and a data caching system that can reduce the protocol communication processing involved in data caching and improve processing efficiency.

[0005] To address the aforementioned technical problems, this invention provides a data caching method applied to a caching system, which includes a master node and slave nodes. The method includes: When the master node receives a write request, it caches the write data in the write request into the master node's main data block and marks the main data block as dirty data; the main data block is used to cache at least two write requests. The master node initiates remote data access to the slave node's memory, caches the written data in the slave node's memory to the slave data block mapped to the master data block, and marks the slave data block as dirty data. When the master node determines that the master data block is full, it stores the written data in the master data block to the storage device and marks the master data block as idle. At the same time, it initiates remote data access to the slave node's memory to synchronize the idle state to the slave data block.

[0006] The present invention also provides a caching system, which includes a master node and a slave node, wherein the master node includes master node memory and the slave node includes slave node memory; The master node, upon receiving a write request, caches the write data in the write request to the master data block in its memory and marks the master data block as dirty. The master data block is used to cache at least two write requests. It initiates a remote data access to the slave node's memory, caches the write data to the slave data block mapped to the master data block in the slave node's memory, and marks the slave data block as dirty. When it determines that the master data block is full, it stores the write data in the master data block to the storage device, marks the master data block as idle, and simultaneously initiates a remote data access to the slave node's memory to synchronize the idle state to the slave data block.

[0007] This invention provides a data caching method applied to a data caching system, the data caching system comprising a master node and slave nodes. The method includes: when the master node receives a write request, it caches the write data in the write request to a master data block in the master node's memory and marks the master data block as dirty data; wherein, the master data block is used to cache at least two write requests; the master node initiates a remote data access to the slave node's memory, caches the write data to a slave data block in the slave node's memory mapped to the master data block, and marks the slave data block as dirty data; when the master node determines that the master data block is full, it stores the write data in the master data block to a storage device, marks the master data block as idle, and simultaneously initiates a remote data access to the slave node's memory to synchronize the idle state to the slave data block.

[0008] The beneficial effects of this invention are as follows: When the master node receives a write request, it can first cache the write data in the write request to the master data block in the master node's memory and mark the master data block as dirty data; wherein, the master data block is used to cache at least two write requests. Subsequently, the master node can initiate remote data access to the slave node's memory, cache the write data to the slave data block mapped to the master data block in the slave node's memory, and mark the slave data block as dirty data. That is, when caching write requests, the write data can be directly written to the slave node's memory through remote data access without the involvement of the slave node processor, which can reduce protocol communication processing and improve processing efficiency. In addition, when the master node determines that the master data block is full, it can store the written data in the master data block to the storage device and mark the master data block as idle. At the same time, it can initiate remote data access to the slave node's memory to synchronize the idle state to the slave data block. That is, during the data flushing process, the master node can merge and flush the master data block with multiple write requests to the storage device, and merge and synchronize the flushing results of multiple write requests to the master data block and the slave data block. This can reduce the amount of communication and further improve processing efficiency.

[0009] The present invention also provides a data caching system, which has the above-mentioned beneficial effects. Attached Figure Description

[0010] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0011] Figure 1 This is a structural block diagram of a first caching system provided in an embodiment of the present invention; Figure 2This is a structural diagram of a second caching system provided in an embodiment of the present invention; Figure 3 This is a schematic diagram of the data structure of a data block provided in an embodiment of the present invention; Figure 4 A flowchart of a data caching method provided in an embodiment of the present invention; Figure 5 A flowchart of another data caching method provided in an embodiment of the present invention. Detailed Implementation

[0012] To make the objectives, technical solutions, and advantages of the embodiments of the present invention clearer, the technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0013] In related technologies, caching systems typically manage data using a multi-replica approach across multiple cache nodes. However, to ensure data redundancy requirements, extensive protocol communication and data synchronization are involved between cache nodes, posing a significant challenge to the performance of the caching system.

[0014] For example, in a caching system, the nodes that process data can be divided into master nodes and slave nodes. The master node for caching the current data can be determined using a hash algorithm based on the address or content of the data accessed.

[0015] To ensure data redundancy and consistency, for write requests (write IO, Input / Output) issued by the host, the master node first receives the data from the write request and distributes it to each slave node through the underlying communication module according to redundancy requirements. The slave nodes retrieve the data from the communication module, write it to their cache, set a dirty flag, and respond. After receiving responses from all slave nodes, the master node writes the data to its local cache, returns a successful write response to the host for the current write request, and sets a dirty flag to await flushing.

[0016] For the write-down task, the master node writes the data corresponding to each write request to the backend storage device in sequence according to the dirty data flag. After the backend storage device has finished writing, the master node calls the communication module to notify all slave nodes to clear the dirty data flag corresponding to each write request data. After receiving the responses from all slave nodes, the master node clears its local dirty data flag.

[0017] The relevant technologies have the following shortcomings in handling write requests and refresh tasks: 1. There is a large amount of data communication between nodes. The first type of message communication involves data content synchronization messages from the master node to the slave node, and acknowledgment messages from the slave node to the master node. The second type of message communication involves dirty data flag synchronization messages from the master node to the slave node, and acknowledgment messages from the slave node to the master node. Processing a single write request involves four inter-node communication messages, which not only consumes the communication bandwidth of the caching system but also consumes significant CPU resources for sending and receiving these messages.

[0018] 2. Cache nodes involve significant CPU computation. To ensure data redundancy and consistency across nodes, before responding to a write request to the host, it must not only be processed by the master node but also wait for all slave nodes to complete their synchronous processing. Write request processing consumes not only the master node's CPU resources but also an equal amount of CPU resources from the slave nodes. This not only introduces substantial latency to write requests but also results in long task queuing times on slave nodes, limiting the maximum bandwidth of the entire system.

[0019] 3. The flushing task has high complexity. When flushing data to the backend storage device, related technologies usually perform flushing on a per-write-request basis. That is, the master node needs to flush each write request one by one. This not only reduces flushing efficiency, but also significantly increases the amount of message communication between the master node and the slave node, ultimately resulting in low execution efficiency of the flushing task.

[0020] In view of this, in order to address the technical problem of how to reduce the protocol communication processing involved in data caching and improve processing efficiency, the present invention can provide a data caching method that can reduce the amount of communication and CPU resource consumption required for data caching by optimizing the data caching mechanism, while reducing the complexity of data flushing tasks.

[0021] For ease of understanding, the system architecture of the caching system to which this invention applies will be described below. Please refer to... Figure 1 , Figure 1 This is a structural block diagram of a first type of caching system provided in an embodiment of the present invention. Figure 1In this system, the caching system consists of master nodes and slave nodes, with one or more slave nodes. The master node has its own master node memory. The master node memory contains at least a master data block resource pool (Master_block resource pool), which is composed of master data blocks (Master_block). A master data block is a contiguous memory region that can be divided into multiple data pages. This embodiment does not limit the size of the master data block or the size of the data pages; for example, a master data block can be 16MB of memory, which can be divided into 4096 4KB data pages. Slave nodes have their own slave node memory, which contains at least a slave data block resource pool (Slave_block resource pool), composed of slave data blocks (Slave_block). The size and structure of slave data blocks are completely identical to those of master data blocks. Furthermore, a remote data access connection is established between the master node and slave nodes. This connection enables direct data exchange between the master node memory and slave node memory without CPU processing.

[0022] Additionally, please refer to Figure 2 , Figure 2 This is a structural diagram of a second caching system provided in an embodiment of the present invention. Figure 1 The difference is that, in Figure 2 In this system, both the master node and the slave node have their own master data block resource pool and slave data block resource pool in their memory. That is, the master node and the slave node have the same structure, which makes it easy to switch between master nodes and slave nodes in various cache nodes.

[0023] It should be noted that this embodiment does not limit the underlying implementation form of the remote data access connection. For example, it can be implemented using the underlying network card in the form of RDMA (remote direct memory access) or NTB (Non-Transparent Bridge).

[0024] In this embodiment, to address the issues of numerous data synchronization messages and lengthy write processes in related technologies when performing data caching, a master data block and slave data blocks are provided. Each cache node maintains a master data block resource pool and a slave data block resource pool. The master and slave data blocks have the same defined structure, each consisting of a contiguous 16MB memory block divided into 4094 4KB data pages, capable of caching multiple IO data entries. Furthermore, the master and slave data blocks are mapped one-to-one, meaning that the corresponding slave data block can be uniquely found through the master data block.

[0025] Please refer to Figure 3 , Figure 3This is a schematic diagram of the data structure of a data block provided in an embodiment of the present invention. In this embodiment, both the master data block and the slave data block include a data block header (block_head), a data block metadata header (block_meta_head), and a data block data area (block_data).

[0026] The data block header contains the data block's attribute information, which may include the data block identifier (block_id), data block sequence number (block_seq), data block status (dirty), write start index (start_index), and usage (using). The data block identifier is a unique identifier for the data block in memory; the primary and secondary data blocks that are mapped to each other have the same data block identifier. The data block sequence number is the allocation sequence number of the data block, used to indicate the order in which the data blocks were allocated. The data block status can include a dirty status (dirty) and a clean status (clean). The dirty status indicates that the written data in the data block has not been flushed to the backend storage device, while the clean status indicates that the written data in the data block has been flushed to the backend storage device. The write start index indicates the current write start position within the data block; the maximum value of the write start index should not exceed the total number of data pages contained in the data block. Usage indicates the amount of data used within the data block.

[0027] The data block metadata header contains write information for each write request, which may include the data address (address), data length (length), and write sequence number (io_sequence) for each data page. The data block data area contains the data segment (data) within each data page. The data address is the storage address of the written data in the data page on the backend storage device. The data length is the length of the written data in the data page. The write sequence number indicates the order in which write requests are sent, distinguishing the latest written data when multiple writes are performed to the same data address.

[0028] The data block data area contains the written data in each data page.

[0029] In addition, both the master node memory and the slave node memory can be NVRAM (Non-Volatile Random Access Memory), which is not lost when power is off.

[0030] During write request processing, when the master node receives a write request, it can split the write data into 4KB segments and copy them sequentially to the current index position of the master data block. It also marks the master data block's state as dirty. Simultaneously, it writes the data block state and the write data directly to the corresponding memory location of the slave data block on the slave node via remote data access. After the underlying physical link returns a successful write response, the write data is added to the cache. Unlike related technologies, the data synchronization process only requires the underlying network card to directly move the data; no slave node operation (adding synchronized data to the cache and responding) is needed. This not only saves the slave node's CPU resources but also reduces data synchronization latency.

[0031] When the master data block space is exhausted, the master node can flush the entire master data block to the backend storage device. After the backend storage device successfully writes the data, the master node can mark the master data block status as clean and write the status directly to the corresponding memory location of the slave data block on the slave node via remote data access. Compared with related technologies, the status synchronization message is based on the master data block, not the write request. Only one synchronization message is sent for each master data block, which reduces the number of synchronization messages from multiple write requests to one. This significantly reduces the number of messages, reduces the bandwidth pressure on the underlying link, and thus improves IO latency.

[0032] Based on the above system architecture description, the data caching method provided in this embodiment will be described below. Please refer to... Figure 4 , Figure 4 The flowchart illustrates a data caching method provided in an embodiment of the present invention. This method is applied to a caching system, which may include a master node and slave nodes. The method may include: S10. When the master node receives a write request, it caches the write data in the write request into the master data block in the master node's memory and marks the master data block as dirty data; wherein, the master data block is used to cache at least two write requests.

[0033] In this embodiment, the write data to be cached in the write request may include data content, data address, and data length. When the master node receives a write request, it can query the currently used master data block. If it is determined that a currently used master data block exists and that the master data block is not full, the master node can cache the aforementioned write data into that master data block. If it is determined that no currently used master data block exists, or that a currently used master data block exists but is full, the master node can request a free master data block from the master data block resource pool and cache the aforementioned write data into that master data block.

[0034] It is important to note that since the front-end device may repeatedly write data to the same address, in order to distinguish the latest written data, this embodiment, in addition to caching the written data, also needs to set the write sequence number of the written data in the main data block. The initial value of this write sequence number can be 0, and it can be incremented sequentially according to the order in which write requests are sent. This allows the write order of the data to be determined by comparing the order of the write sequence numbers. Furthermore, the write sequence number is globally consistent across all cache nodes, ensuring the unique determination of the written data and its write order.

[0035] In addition, since the front-end device can repeatedly write data to the same data address, when the master node receives multiple write requests for the same data address, it can add only the write data with the largest write sequence number to the master data block.

[0036] Additionally, master data blocks in the master data block resource pool can be reclaimed. In this case, the order in which master data blocks are requested helps identify the location of the most recently requested master data block and the most recently written data. Therefore, after requesting a free master data block from the master data block resource pool, the master node can set the block sequence number and dirty data status in the master data block's attributes. The block sequence number indicates the request order of the master data block, and the dirty data status indicates that the written data in the master data block has not been flushed to the backend storage device. Similarly, the block sequence number is globally unified across all cache nodes, uniquely determining the request order of data blocks within each cache node.

[0037] Based on this, the write data in the write request is cached in the main data block in the master node's memory, and the main data block is marked as dirty data. This can include: S11. The master node determines whether the currently used master data block is full.

[0038] S12. If the currently used main data block is not full, the write data in the write request is cached in the main data block, and the write sequence number of the write data is set in the main data block; wherein, the write sequence number is incremented sequentially according to the order in which the write requests are issued.

[0039] S13. If the currently used master data block is full, request an idle master data block from the master data block resource pool, set the data block sequence number and dirty data status in the master data block's attributes, cache the write data in the write request to the master data block, and set the write sequence number of the write data in the master data block; wherein, the data block sequence number increases sequentially according to the request order of the master data block.

[0040] Furthermore, the master node can determine whether the master data block is full based on the write start sequence number in the master data block. The master data block can be divided into multiple data pages, and during write data caching, the data must be written sequentially to each data page. Therefore, the master data block's attributes can maintain a write start sequence number. After each data caching cycle, the write start sequence number can be updated based on the sequence number of the last data page written in that round, indicating the start position for the next caching cycle. It's understood that the write start sequence number should be less than the total number of data pages contained in the data block. Therefore, the master node obtains the write start sequence number from the currently used master data block and determines whether it is less than the total number of data pages. If it is less, the currently used master data block is considered not full. If it is not less, the currently used master data block is considered full.

[0041] Based on this, the master data block contains at least two data pages; the master node determines whether the currently used master data block is full by including: S111. The master node obtains the write start sequence number from the currently used master data block and determines whether the write start sequence number is less than the total number of data pages. S112. If it is less than, then it is determined that the currently used main data block is not full; S113. If it is not less than, then the currently used main data block is determined to be full.

[0042] Furthermore, during data caching, the master node can divide the data to be written into data segments based on the page size of the data page. Subsequently, the master node can start writing each data segment sequentially to the data page corresponding to the write start number, and set a write sequence number for each data segment.

[0043] Based on this, the write data in the write request is cached in the main data block, and the write sequence number of the write data is set in the main data block, including: S121. Divide the data to be written into data segments according to the page size of the data page; S122. Starting from the data page corresponding to the write start number, write each data segment to the data page in order, and set the write sequence number for each data segment.

[0044] S20. The master node initiates remote data access to the slave node's memory, caches the written data in the slave node's memory to the slave data block mapped to the master data block, and marks the slave data block as dirty data.

[0045] In this embodiment, after caching the written data to the master data block, the master node can initiate remote data access to the slave node's memory through an underlying communication module (such as a network interface card), caching the written data to the slave data block mapped to the master data block in the slave node's memory, and simultaneously marking the slave data block as dirty data. Since the master node writes data directly to the slave node's memory without going through the slave node's CPU, it can avoid consuming the slave node's CPU, and at the same time simplify the data synchronization process and improve data synchronization efficiency.

[0046] Specifically, master and slave data blocks are mapped to each other using data block identifiers. Therefore, the master node can synchronize the written data and its sequence number to the slave data blocks based on the master data block's identifier. Additionally, if the master data block is a newly requested master data block from the master data block resource pool, the master node can also synchronize the data block sequence number and dirty data status to the corresponding slave data block. If the master data block is not a newly requested master data block from the master data block resource pool, the corresponding slave data block already records the data block sequence number and dirty data status. Therefore, to save bandwidth, the master node only needs to synchronize the written data and its sequence number to the slave data block.

[0047] Based on this, the master node initiates remote data access to the slave node's memory, caches the written data in the slave node's memory to the slave data block mapped to the master's data block, and marks the slave data block as dirty, including: S211. The master node extracts the data block identifier from the attributes of the master data block and determines whether the currently used master data block is a newly requested master data block. S212. If so, initiate remote data access to the slave node memory and synchronize the data block sequence number, dirty data status, written data, and write sequence number to the slave data block corresponding to the data block identifier. S213. If not, initiate remote data access to the slave node's memory and synchronize the written data and write sequence number to the slave data block corresponding to the data block identifier.

[0048] Furthermore, since master and slave nodes rely on remote data access for data synchronization, and this remote data access is generally implemented over a network, the transmission quality of which directly affects the data consistency of each cache node. Therefore, when synchronizing written data, the master node can add a checksum bit to the written data based on its master node network card. When the slave node's network card receives the written data, it can use this checksum bit to perform integrity verification. If the verification passes, the data is written to the slave node's memory; otherwise, an error message is sent to the master node's network card to guide the master node to resend the written data, thereby effectively ensuring data consistency among the cache nodes.

[0049] Based on this, the master node initiates remote data access to the slave node's memory, caching the written data in the slave node's memory to the slave data block mapped to the master data block. This can include: S221. The master node encapsulates the written data into a data frame through the master node network card, sets a check bit for the data frame according to the written data, and sends the data frame to the slave node network card. S222. When the slave node network card receives a data frame, it uses the check bit to perform integrity verification on the written data. If it determines that the written data has passed the verification, it writes the written data into the slave data block in the slave node's memory. If the written data fails the verification, it sends an error message to the master node network card.

[0050] S30. When the master node determines that the master data block is full, it stores the written data in the master data block to the storage device and marks the master data block as idle. At the same time, it initiates remote data access to the slave node's memory to synchronize the idle state to the slave data block.

[0051] In this embodiment, when the master data block is full, the master node not only needs to request a free master data block from the master node resource pool, but also needs to promptly flush the written data in the full master data block to the backend storage device. It is worth noting that since a master data block can store the write data of at least two write requests, the master node can merge multiple write data requests and flush them to the backend storage device. Furthermore, after completing the data flushing, the master node can mark the master data block as idle and simultaneously initiate remote data access to the slave node's memory to synchronize the idle state to the slave data block. This allows for state synchronization based on data block granularity, rather than write request granularity, thus achieving the effect of merging multiple write requests for state synchronization, further reducing data communication volume and improving processing efficiency.

[0052] Based on the above embodiments, in this invention, when the master node receives a write request, it can first cache the write data in the write request to the master data block in the master node's memory and mark the master data block as dirty data. The master data block is used to cache at least two write requests. Subsequently, the master node can initiate remote data access to the slave node's memory, cache the write data to the slave data block mapped to the master data block in the slave node's memory, and mark the slave data block as dirty data. That is, when caching write requests, the write data can be directly written to the slave node's memory via remote data access without the slave node processor's involvement, reducing protocol communication processing and improving processing efficiency. Furthermore, when the master node determines that the master data block is full, it can store the write data in the master data block to a storage device and mark the master data block as idle. Simultaneously, it can initiate remote data access to the slave node's memory to synchronize the idle state to the slave data block. That is, during the data flushing process, the master node can merge and flush the master data block containing multiple write requests to the storage device, and merge and synchronize the flushing results of multiple write requests to both the master and slave data blocks, reducing communication volume and further improving processing efficiency.

[0053] Based on the above embodiments, this embodiment, by setting up the aforementioned master data block and slave data block, and establishing a data synchronization mechanism between data blocks, can effectively improve the fault recovery efficiency of the slave node when the master node encounters a failure. The specific fault recovery process is described below. Therefore, both the master node and the slave node have master data blocks and slave data blocks; This method may also include: S31. When a slave node detects a failure in the master node, it sorts the slave data blocks in the slave node's memory according to the data block sequence number and reads the data block status of each slave data block in sequence.

[0054] In this embodiment, when a slave node determines that the master node has failed, it first sorts the slave data blocks in its memory according to their sequence numbers from smallest to largest to clarify the allocation and caching order of the slave data blocks. Then, the slave node sequentially reads the data block status of each slave data block. If a slave data block is determined to be in an idle state, it means that the written data in that slave data block has been flushed to the backend storage device. If a slave data block is determined to be in a dirty data state, it means that the written data in that slave data block is dirty data and has not yet been flushed to the backend storage device. The slave node needs to use this method to filter out the dirty data and re-add it to the master data block in the slave node.

[0055] S32. If the data block is idle, read the status of the next data block.

[0056] S33. If the data block is in a dirty data state, filter the dirty data according to the write sequence number of each written data in the data block, and synchronize the data block sequence number, data block state, dirty data, and write sequence number of the dirty data of the data block to the master data block in the slave node memory.

[0057] In this embodiment, both the primary and secondary data blocks are reused. Specifically, secondary data blocks may store not only recently cached write data but also previously cached historical write data, all of which has been flushed to the backend storage device. This embodiment assigns a write sequence number to each write data entry to indicate its writing order. Therefore, when a secondary node filters out secondary data blocks in a dirty state, it can do so based on the write sequence numbers of the write data within those blocks.

[0058] Specifically, the slave node can read the write sequence number of each written data in the order of the data pages. If the write sequence number is found to be gradually increasing, the corresponding written data is all dirty data. If the target write sequence number read now is much smaller than the previous write sequence number, it can be determined that the target data page containing the target write sequence number is the starting position for storing historical write data. The target data page and all subsequent target data pages contain historical write data, and this historical write data has been flushed to the backend storage device. Therefore, the write data between the starting write sequence number in the data block (the write sequence number in the first data page of the data block) and the previous write sequence number of the target write sequence number can be determined as dirty data.

[0059] Based on this, dirty data is filtered according to the write sequence number of each piece of data written from the data block, including: S331. Read the write sequence number of each written data in sequence from the data block; S332. If the current target write sequence number is greater than the previous write sequence number, then continue reading the next write sequence number; S333. If the target write sequence number of the current read is less than the previous write sequence number, the written data between the starting write sequence number in the data block and the previous write sequence number of the target write sequence number is determined to be dirty data, and the read operation is terminated.

[0060] Furthermore, after filtering the complete dirty data, the slave node can synchronize the data block sequence number, data block status, dirty data, and dirty data write sequence number of the slave data block to the master data block in the slave node's memory, and restore the master node's services based on the master data block.

[0061] S34. Upon completion of data synchronization, the slave node takes over the caching services of the master node.

[0062] As can be seen, when a slave node is performing fault service recovery, it can orderly and quickly filter slave data blocks in a dirty data state according to the data block sequence number and data block status recorded in the data block, and quickly filter dirty data according to the write sequence number in the slave data block, so as to only add dirty data back into memory, which can improve the efficiency of service recovery.

[0063] Furthermore, when the original master node resumes operations, to ensure the consistency and continuity of data block sequence numbers and write sequence numbers, the slave node needs to synchronize the maximum data block sequence number and maximum write sequence number corresponding to the master data block in the slave node's memory to the master node. The master node then sets the data block sequence number for newly requested master data blocks starting with the maximum data block sequence number, and sets the write sequence number for newly received write requests starting with the maximum write sequence number.

[0064] Based on this, the method may also include: S41. When the slave node detects that the master node has recovered, it will synchronize the maximum data block sequence number and the maximum write sequence number corresponding to the master data block in the slave node's memory to the master node. S42. The master node sets the data block sequence number for newly requested master data blocks, starting with the maximum data block sequence number, and sets the write sequence number for newly received write requests, starting with the maximum write sequence number.

[0065] Based on the above embodiments, the data caching method described above will be fully described below with specific examples and diagrams. Please refer to... Figure 5 , Figure 5 A flowchart of another data caching method provided in an embodiment of the present invention. The data caching process is as follows: 1) Upon receiving an I / O request, the master node first checks if the current_block (the currently used master data block) exists. If it does not exist, it requests one from the master data block resource pool and assigns a data block sequence number to the current_block. The data block sequence number is globally unique and increments, marking the data block sequence number and distinguishing the order in which blocks are generated. If the current_block exists, it checks if its space is exhausted. If the write start sequence number is less than 4096, the current_block can continue to be used; otherwise, the current_block begins flushing data to the backend media.

[0066] 2) If there is free space in the current_block, the IO data is split into 4K page sizes. The data address (the address where the IO is written) and data length (the length of the IO write, which may not be less than 4K) corresponding to each 4K page are sequentially written to the memory space corresponding to the [write start sequence number] in the data block's metadata header. Each data block's metadata header maintains a write sequence number (incrementing according to the order of IO processing) to distinguish multiple IO writes to the same address. If the same address is written multiple times, the data with the largest write sequence number is added to the cache. Simultaneously, the content corresponding to each 4K page is sequentially copied to the memory space corresponding to the [write start sequence number] in the data block's data. If current_block is the first write, a dirty data flag needs to be set.

[0067] 3) Each block's memory space is unique, identified by a data block identifier, and there is a one-to-one correspondence between master and slave data blocks. After the data status and content are written to the current_block, the underlying communication module synchronizes the data to the corresponding memory location of the slave data block on the slave node. The synchronized data includes the following: data block header, data block metadata header [write start sequence number], and data block data [write start sequence number]. To reduce communication bandwidth, the data block header is only synchronized when the current_block receives the first IO (at this time, the data block sequence number / dirty data flag has been set and will not be changed in subsequent IOs). Subsequent IOs received by the current_block do not require synchronization of the data block header.

[0068] After the underlying communication module returns a successful transmission, it adds the data to the buffer. It also writes the starting sequence number plus the number of 4KB data pages in the current I / O, indicating how much space the current_block has already used.

[0069] 4) When the write start sequence number of current_block is greater than 4096, it indicates that the current_block space has been used up, and the write process begins to flush the data to the backend storage medium. After the write process is complete, the dirty data flag in the header of the data block in current_block is cleared.

[0070] 5) Synchronize the header content of the data block in current_block to the corresponding slave data block (the physical memory spaces of the master data block and the slave data block correspond one-to-one, and the corresponding slave data block of the peer node can be found through the data block identifier in the header of the current data block), indicating that the current data block has been flushed.

[0071] The fault recovery process is as follows: 1) When the master node fails, before the slave node takes over the service, it needs to re-add the data previously synchronized from the master node that has not yet been flushed to the cache to prevent data inconsistency between the two ends. First, all data blocks in the data block resource pool are sorted in ascending order of data block number to ensure that data is processed in the order it is received. If the current data block does not have a dirty data flag, it means that the data block has already been written to the backend medium and does not need to be processed. If the current data block has a dirty data flag, dirty data is first filtered out from the data blocks. The filtering algorithm is as follows: traverse the data block's metadata header. If the write sequence number keeps increasing, it means that the corresponding data is dirty data; if the write sequence number suddenly decreases, it means that the corresponding data was written previously and has been flushed (data blocks are reused, and this data was written when the data block was last used, which can be distinguished by the increasing write sequence number). Then, the filtered data is added to the master data block and simultaneously added to the cache.

[0072] 2) When the master node recovers from a failure and takes over the business again, the slave nodes need to synchronize the sequence number of the largest data block and the write sequence number of the current data block with the master node. This is because these two parameters can be used to identify the age of data and the order of reception and processing, and are globally unique throughout the entire system. When processing new I / O, the master node uses the latest data block sequence number and write sequence number synchronized by the slave node as a starting point to incrementally allocate indexes for each master data block and each I / O.

[0073] The beneficial effects of this invention are as follows: To address the performance inefficiencies and long fault recovery times of multi-replica caching systems in related technologies, this invention proposes a high-performance, high-reliability caching system. This system optimizes write I / O processing on slave nodes through a remote data access mechanism, reducing CPU resource usage and significantly lowering data synchronization latency. By aggregating small I / O blocks into master data blocks, it reduces synchronization messages between cache nodes, thereby improving I / O latency and increasing system bandwidth. Simultaneously, converting small data blocks into larger blocks improves the flushing efficiency of the backend storage medium, thus improving fault recovery time. Furthermore, by introducing a global data block sequence number and write sequence number mechanism, the system achieves data recovery without loss in fault scenarios, ensuring data security and consistency within the caching system.

[0074] The caching system, computer-readable storage medium, and computer program product provided in the embodiments of the present invention are described below. The caching system, computer-readable storage medium, and computer program product described below can be referred to in correspondence with the data caching method described above.

[0075] Please refer to Figure 1 , Figure 1This is a structural block diagram of a first type of caching system provided in an embodiment of the present invention. The caching system includes a master node and a slave node. The master node includes master node memory, and the slave node includes slave node memory. The master node, upon receiving a write request, caches the write data in the write request to the master data block in its memory and marks the master data block as dirty. The master data block is used to cache at least two write requests. It initiates a remote data access to the slave node's memory, caches the write data to the slave data block mapped to the master data block in the slave node's memory, and marks the slave data block as dirty. When it determines that the master data block is full, it stores the write data in the master data block to the storage device, marks the master data block as idle, and simultaneously initiates a remote data access to the slave node's memory to synchronize the idle state to the slave data block.

[0076] Optionally, the master node is also used for: Determine if the currently used main data block is full; If the currently used main data block is not full, the write data in the write request will be cached in the main data block, and the write sequence number of the write data will be set in the main data block; the write sequence number will increment sequentially according to the order in which the write requests are sent. If the currently used master data block is full, request an idle master data block from the master data block resource pool, set the data block sequence number and dirty data status in the master data block's attributes, cache the write data in the write request to the master data block, and set the write sequence number of the write data in the master data block; wherein, the data block sequence number increases sequentially according to the request order of the master data block.

[0077] Optionally, the master data block contains at least two data pages; the master node is also used for: Obtain the write start sequence number from the currently used master data block, and determine whether the write start sequence number is less than the total number of data pages; If it is less than, then it is determined that the currently used main data block is not full; If it is not less than, then the currently used main data block is considered full.

[0078] Optionally, the master node is also used for: The data to be written is divided into data segments based on the page size of the data page; Starting from the data page corresponding to the write start number, write each data segment to the data page in order, and set a write sequence number for each data segment.

[0079] Optionally, the master node is also used for: Extract the data block identifier from the attributes of the master data block and determine whether the currently used master data block is a newly requested master data block; If so, initiate a remote data access to the slave node's memory, and synchronize the data block sequence number, dirty data status, written data, and write sequence number to the slave data block corresponding to the data block identifier; If not, a remote data access is initiated to the slave node's memory, and the written data and write sequence number are synchronized to the slave data block corresponding to the data block identifier.

[0080] Optionally, both the master data block and the slave data block include a data block header, a data block metadata header, and a data block data area. The data block header includes a data block identifier, a data block sequence number, a data block status, a write start sequence number, and usage. The data block metadata header includes the data address, data length, and write sequence number corresponding to each data page. The data block data area includes the data segments in each data page.

[0081] Optionally, both the master node and the slave node have master data blocks and slave data blocks; The node is used for: When a master node failure is detected, the slave data blocks in the slave node's memory are sorted according to the data block sequence number, and the data block status of each slave data block is read sequentially. If the data block is idle, then read the status of the next data block. If the data block is in a dirty state, the dirty data is filtered according to the write sequence number of each data written in the data block, and the data block sequence number, data block state, dirty data, and write sequence number of the dirty data of the data block are synchronized to the master data block in the slave node's memory. Upon completion of data synchronization, the slave node takes over the caching functions of the master node.

[0082] Optionally, the node is also used for: Read the write sequence number of each written data in sequence from the data block; If the current target write sequence number is greater than the previous write sequence number, then continue reading the next write sequence number; If the target write sequence number being read is less than the previous write sequence number, then the data written between the starting write sequence number in the data block and the previous write sequence number of the target write sequence number is considered dirty data, and the read operation is terminated.

[0083] Optionally, the node is also used for: When the master node is detected to have recovered, the maximum data block sequence number and the maximum write sequence number corresponding to the master data block in the slave node's memory will be synchronized to the master node. The master node is also used for: Set the data block sequence number for newly requested primary data blocks, starting with the maximum data block sequence number, and set the write sequence number for newly received write requests, starting with the maximum write sequence number.

[0084] Optionally, the master node also includes a master node network interface card (NIC), and the slave node also includes a slave node NIC. The master node is also used for: The master node encapsulates the written data into a data frame using its network interface card (NIC), sets a checksum for the data frame based on the written data, and then sends the data frame to the slave node's NIC. The network interface card on the slave node is used for: When a data frame is received, the integrity of the written data is checked using the check bit. If the written data passes the check, it is written to the slave data block in the slave node's memory. If the written data fails the check, an error message is sent to the master node's network card.

[0085] This invention also provides a computer program product, including a computer program / instruction, which, when executed by a processor, implements the data caching method described in the above embodiments.

[0086] Since the embodiments of the computer program product portion correspond to the embodiments of the data caching method portion, please refer to the description of the embodiments of the data caching method portion for the embodiments of the computer program product portion, and will not be repeated here.

[0087] This invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the data caching method described in the above embodiments.

[0088] Since the embodiments of the computer-readable storage medium portion correspond to the embodiments of the data caching method portion, the embodiments of the storage medium portion are described in the description of the embodiments of the data caching method portion, and will not be repeated here.

[0089] The various embodiments in this specification are described in a progressive manner, with each embodiment focusing on its differences from other embodiments. Similar or identical parts between embodiments can be referred to interchangeably. For the apparatus disclosed in the embodiments, since it corresponds to the method disclosed in the embodiments, the description is relatively simple; relevant parts can be referred to the method section.

[0090] Those skilled in the art will further recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, computer software, or a combination of both. To clearly illustrate the interchangeability of hardware and software, the components and steps of the various examples have been generally described in terms of functionality in the foregoing description. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.

[0091] The steps of the methods or algorithms described in conjunction with the embodiments disclosed herein can be implemented directly by hardware, a software module executed by a processor, or a combination of both. The software module can be located in random access memory (RAM), main memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, removable disk, CD-ROM, or any other form of storage medium known in the art.

[0092] The data caching method and system provided by this invention have been described in detail above. Specific examples have been used to illustrate the principles and implementation methods of this invention. The descriptions of the embodiments above are only for the purpose of helping to understand the method and core ideas of this invention. It should be noted that those skilled in the art can make several improvements and modifications to this invention without departing from the principles of this invention, and these improvements and modifications also fall within the protection scope of this invention.

Claims

1. A data caching method, characterized in that, Applied to a data caching system, the data caching system comprising master nodes and slave nodes, the method includes: When the master node receives a write request, it caches the write data in the write request into the master node's main data block and marks the main data block as dirty data; wherein, the main data block is used to cache at least two write requests; The master node determines the slave data blocks in the slave node memory that are mapped one-to-one with the master data blocks based on the data block identifier of the master data block, and initiates remote data access to the slave node memory through the underlying communication module, so that the written data can be directly written to the slave data blocks without the participation of the slave node's processor, and marks the slave data blocks as dirty data. When the master node determines that the master data block is full, it stores the written data in the master data block to the storage device and marks the master data block as idle. At the same time, it initiates remote data access to the slave node's memory through the underlying communication module to synchronize the idle state to the slave data block. The idle state is used to indicate that the written data in the corresponding data block has been stored in the storage device.

2. The data caching method according to claim 1, characterized in that, The write data in the write request is cached in the main data block in the master node's memory, and the main data block is marked as dirty data, including: The master node determines whether the currently used master data block is full. If the currently used main data block is not full, the write data in the write request is cached in the main data block, and the write sequence number of the write data is set in the main data block; wherein, the write sequence number is incremented sequentially according to the order in which the write requests are issued; If the currently used main data block is full, an idle main data block is requested from the main data block resource pool. The data block sequence number and the dirty data status are set in the attributes of the main data block. The write data in the write request is cached in the main data block, and the write sequence number of the write data is set in the main data block. The data block sequence number is incremented sequentially according to the request order of the main data blocks.

3. The data caching method according to claim 2, characterized in that, The main data block contains at least two data pages; The master node determines whether the currently used master data block is full, including: The master node obtains the write start sequence number from the currently used master data block and determines whether the write start sequence number is less than the total number of data pages; If it is less than, then it is determined that the currently used main data block is not full; If it is not less than, then the currently used main data block is considered full.

4. The data caching method according to claim 3, characterized in that, The write data in the write request is cached in the main data block, and the write sequence number of the write data is set in the main data block, including: The written data is divided into data segments according to the page size of the data page; Starting from the data page corresponding to the write start number, each data segment is written to the data page in an orderly manner, and a write sequence number is set for each data segment.

5. The data caching method according to claim 3, characterized in that, The master node initiates remote data access to the slave node's memory, caches the written data in the slave node's memory to a slave data block mapped to the master data block, and marks the slave data block as dirty data, including: The master node extracts the data block identifier from the attributes of the master data block and determines whether the currently used master data block is a newly requested master data block; If so, a remote data access is initiated to the slave node memory to synchronize the data block sequence number, the dirty data status, the written data, and the write sequence number to the slave data block corresponding to the data block identifier; If not, a remote data access is initiated to the slave node's memory to synchronize the written data and the write sequence number to the slave data block corresponding to the data block identifier.

6. The data caching method according to claim 5, characterized in that, Both the master data block and the slave data block include a data block header, a data block metadata header, and a data block data area. The data block header includes a data block identifier, a data block sequence number, a data block status, a write start sequence number, and usage. The data block metadata header includes the data address, data length, and write sequence number corresponding to each data page. The data block data area includes the data segments in each data page.

7. The data caching method according to claim 2, characterized in that, Both the master node and the slave node have the master data block and the slave data block; The method further includes: When the slave node detects a failure in the master node, it sorts the slave data blocks in its memory according to the data block sequence number and sequentially reads the data block status of each slave data block. If the data block is idle, then read the status of the next data block; If the data block is in a dirty data state, the dirty data is filtered according to the write sequence number of each written data in the data block, and the data block sequence number, data block state, dirty data, and write sequence number of the dirty data of the data block are synchronized to the master data block in the slave node memory. Upon completion of data synchronization, the slave node takes over the caching services of the master node.

8. The data caching method according to claim 7, characterized in that, Filtering dirty data based on the write sequence number of each piece of data written from the data block includes: The write sequence number of each written data is read sequentially from the data block; If the current target write sequence number is greater than the previous write sequence number, then continue reading the next write sequence number; If the target write sequence number being read is less than the previous write sequence number, then the data written between the starting write sequence number and the previous write sequence number of the target write sequence number in the data block is determined to be dirty data, and the reading process is terminated.

9. The data caching method according to claim 7, characterized in that, Also includes: When the slave node detects that the master node has recovered, it will synchronize the maximum data block sequence number and the maximum write sequence number corresponding to the master data block in the slave node's memory to the master node. The master node sets the data block sequence number for newly requested master data blocks, starting with the maximum data block sequence number, and sets the write sequence number for newly received write requests, starting with the maximum write sequence number.

10. A data caching system, characterized in that, The data caching system includes a master node and slave nodes. The master node contains master node memory, and the slave node contains slave node memory. The master node, upon receiving a write request, caches the write data in the write request into a master data block in its memory and marks the master data block as dirty. The master data block caches at least two write requests. Based on the data block identifier of the master data block, it determines the slave data block in the slave node's memory that maps one-to-one with the master data block, and initiates remote data access to the slave node's memory via the underlying communication module. This allows the write data to be directly written to the slave data block without the slave node's processor involvement, and the slave data block is marked as dirty. When the master data block is determined to be full, it stores the write data in the master data block into a storage device and marks the master data block as idle. Simultaneously, it initiates remote data access to the slave node's memory via the underlying communication module to synchronize the idle state to the slave data block. The idle state indicates that the write data in the corresponding data block has been stored in the storage device.