Distributed storage system, data writing method, device, medium and program product

By introducing data streams and metadata streams into the distributed storage system, the problem of data write confirmation delay is solved, achieving efficient data writing and reading, and improving the stability and reliability of the system.

CN122633097APending Publication Date: 2026-08-25ALIBABA CLOUD COMPUTING CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510215730.1
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-25
Publication Date
2026-08-25

AI Technical Summary

Technical Problem

In existing distributed storage systems, data writing efficiency is low, and it is impossible to confirm in a timely manner whether the data has been successfully written, resulting in repeated disk read operations and affecting system performance.

Method used

In a distributed storage system, data streams and metadata streams are introduced. Data streams are used for data writing, while metadata streams are used to record the identifier and offset address of data blocks. When a write fails, the control node switches the data block until it succeeds, and only records the metadata of the successful data block in the metadata stream, reducing repeated reads.

Benefits of technology

It improves data writing efficiency, reduces the probability of data loss and missed writes, ensures that data is read only once, and improves the stability and reliability of the system.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122633097A_ABST
    Figure CN122633097A_ABST
Patent Text Reader

Abstract

Embodiments of the present application provide a kind of distributed storage system, data write method, equipment, medium and program product.In the management and control node of distributed storage system, data stream and metadata stream are additionally arranged, and data block is allocated for data stream and metadata stream.For target data to be written, the management and control node only needs to perceive that target data is written unsuccessfully, and then switches to another data block of data stream to write target data until it is perceived that target data is written successfully, without needing to confirm whether target data is truly written successfully by reading storage node, so as to improve data writing efficiency.Only the metadata of target data block in which target data is written successfully is written into metadata stream, and when reading data, only data from the data block with corresponding record in metadata stream is read.For the data block in which the management and control node perceives that writing is failed but actual writing data is successful, since there is no relevant record in metadata stream, data will not be read from the corresponding data block, so that it can be guaranteed that the same data is only read once.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of data storage technology, and in particular to a distributed storage system, data writing method, device, medium and program product. Background Technology

[0002] In recent years, with the development of information technology, more and more information has been digitized, and data has grown explosively. Distributed storage can improve the efficiency of data storage and management. For most distributed storage systems, metadata and data are usually separated, that is, the control flow and data flow are separated, thereby obtaining higher policy scalability and input / output (I / O) concurrency.

[0003] For data to be written in a data stream, it may have actually been written successfully, but the upper-layer system cannot receive confirmation. To ensure that the upper-layer system reads only one copy of the data when reading, it needs to re-read the disk to confirm whether the data was truly written successfully. Only after confirming that the data writing has actually failed will the data be rewritten. This data writing method is inefficient. Summary of the Invention

[0004] This application provides a distributed storage system, data storage method, device, medium, and program product to improve data writing efficiency.

[0005] This application provides a distributed storage system, including: a management node and multiple storage nodes; the management node is configured with a data stream and a metadata stream; the data stream is pre-allocated with multiple first data blocks; the metadata stream is pre-allocated with second data blocks; the first data blocks and the second data blocks are distributed among the multiple storage nodes;

[0006] The control node is configured to sequentially attempt to write the target data to be written into the plurality of first data blocks until the target data is successfully written; and to write the identifier of the target data block and the first offset address of the target data in the target data block into the second data block, so as to read the target data according to the identifier of the target data block and the first offset address recorded in the second data block; wherein, the target data block is the data block in which the target data is successfully written.

[0007] This application embodiment also provides a data writing method applicable to a control node in a distributed storage system, wherein the data stream is pre-allocated with multiple first data blocks; the metadata stream is pre-allocated with second data blocks; and the first data blocks and the second data blocks are distributed across multiple storage nodes in the distributed storage system.

[0008] The method includes:

[0009] The target data to be written is sequentially attempted to be written into the plurality of first data blocks until the target data is successfully written.

[0010] The identifier of the target data block and the first offset address of the target data in the target data block are written into the second data block, so as to read the target data according to the identifier of the target data block and the first offset address recorded in the second data block; wherein, the target data block is the data block in which the target data is successfully written.

[0011] This application also provides an electronic device, including: a memory and a processor; wherein the memory is used to store computer programs;

[0012] The processor is coupled to the memory and is used to execute the computer program to perform the steps in the above-described data writing method.

[0013] This application also provides a computer-readable storage medium storing computer instructions, which, when executed by one or more processors, cause the one or more processors to perform the steps in the above-described data writing method.

[0014] This application also provides a computer program product, including a computer program that, when executed by one or more processors, causes the one or more processors to perform the steps in the above-described data writing method.

[0015] In this embodiment, a data stream and a metadata stream are added to the control node of the distributed storage system, and data blocks are allocated to the data stream and metadata stream. For target data to be written, the control node switches to another data block in the data stream to write the target data as soon as it detects a write failure, continuing until it detects a successful write. This eliminates the need for the read storage node to confirm whether the target data has actually been written successfully, thus improving data writing efficiency. Only the metadata of the target data block that has been successfully written is written to the metadata stream. When reading data, only the data block with the corresponding record in the metadata stream is read. For data blocks where the control node detects a write failure but the data was actually written successfully, since there is no relevant record in the metadata stream, the corresponding data block will not be read, ensuring that only one copy of the same data is read. Attached Figure Description

[0016] The accompanying drawings, which are included to provide a further understanding of this application and form part of this application, illustrate exemplary embodiments and are used to explain this application, but do not constitute an undue limitation of this application. In the drawings:

[0017] Figure 1 and Figure 2This is a schematic diagram of the structure of a distributed storage system provided in an embodiment of this application;

[0018] Figure 3 A schematic diagram of the data writing process provided in this application embodiment;

[0019] Figure 4 A flowchart illustrating the data writing method provided in this application embodiment;

[0020] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0021] To make the objectives, technical solutions, and advantages of this application clearer, the technical solutions of this application will be clearly and completely described below in conjunction with specific embodiments and corresponding drawings. Obviously, the described embodiments are only a part of the embodiments of this application, and not all of them. Based on the embodiments in this application, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of this application.

[0022] It should be noted that, in the cases involving user information in the embodiments of this application, the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, displayed data, etc.) involved in the embodiments of this application are all information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use and processing of related data must comply with the relevant laws, regulations and standards of the relevant countries and regions, and corresponding operation entry points are provided for users to choose to authorize or refuse.

[0023] Raft is a distributed consensus algorithm for managing replicated logs. It aims to solve the problem of how multiple nodes in a distributed environment can reach a consensus on a certain value (such as configuration, state updates, etc.) while ensuring consistency even if some nodes fail or the network is unstable. Raft ensures consistency through three phases: leader election, log replication, and safety.

[0024] The log data generated by the Raft algorithm records the commands received by the replicated state machine. Through consensus protocols such as Raft, it can be determined which commands should be added to the log and their order. Therefore, the log data generated by the Raft algorithm needs to be persistently stored.

[0025] Typically, Raft implementations persist the log data generated by the Raft algorithm to the local disk of the physical machine where the Raft algorithm is deployed. However, the local disk can only store one copy of the Raft log data, resulting in insufficient reliability. This is partly because the probability of local disk failure is relatively high, and in the event of failure, the only solution is to use the Raft algorithm to replace members; and partly because using a local disk requires careful monitoring of whether data is actually written to the disk. For example, Linux (an operating system) typically writes to the page cache first, and then asynchronously writes the data to the local disk in the background. If the machine is powered off and restarted, data that has not yet been written from the page cache to the local disk will be lost. Therefore, Raft implementers, in addition to focusing on the algorithm itself, need to devote considerable effort to ensuring data reliability, significantly increasing the complexity of Raft implementation.

[0026] For data to be written in a data stream (such as Raft log data), it may have actually been written successfully, but the upper-layer system cannot receive confirmation. To ensure that the upper-layer system reads only one copy of the data when reading, it needs to re-read the disk to confirm whether the data was truly written successfully. Only after confirming that the data writing has actually failed will the data be rewritten. This data writing method is inefficient.

[0027] In some embodiments of this application, the data to be written in the data stream is stored in a distributed storage system to achieve redundant storage with multiple backups, thereby improving data security and reliability. In application scenarios where data is stored in a distributed storage system, a data stream and a metadata stream are added to the management node of the distributed storage system, and data blocks are allocated to these streams. For the target data to be written, the management node switches to another data block in the data stream to write the target data as soon as it detects a write failure, continuing until it detects a successful write. This eliminates the need for confirmation from the reading storage node, improving data writing efficiency. Only the metadata of the target data block where the target data was successfully written is written to the metadata stream. When reading data, only the data block with the corresponding record in the metadata stream is read. For data blocks where the management node detects a write failure but the data was actually successfully written, since there is no relevant record in the metadata stream, the corresponding data block will not be read, ensuring that only one copy of the same data is read.

[0028] The technical solutions provided by the various embodiments of this application are described in detail below with reference to the accompanying drawings.

[0029] It should be noted that the same reference numerals in the following figures and embodiments denote the same object or the same step. Therefore, once an object or step is defined in one figure or embodiment, it does not need to be discussed further in subsequent figures and embodiments.

[0030] Figure 1 and Figure 2 This is a schematic diagram of the structure of a distributed storage system provided in an embodiment of this application. Figure 1 and Figure 2 As shown, the distributed storage system may include: a control node 10 and multiple storage nodes 20. "Multiple" refers to two or more (including two).

[0031] Multiple storage nodes 20 form a storage cluster, enabling distributed data storage. The data can be file data, image data, or data tables, etc. The multiple storage nodes 20 can achieve distributed data storage based on a chunk storage service. Data in the multiple storage nodes 20 is distributed across different disks (e.g., disks D0-Dn) in the form of chunks. Therefore, storage nodes 20 can also be called chunk server (CS) nodes.

[0032] A data block (chunk) is a logical unit of data, either fixed-size or variable-size. It is the basic unit for data storage and management. A data block includes multiple data block replicas. "Multiple" means two or more (including two). These multiple data block replicas are distributed across different storage nodes 20. To ensure data security and reliability, the data in the multiple data block replicas can be stored using redundant storage methods. These redundant storage methods can include multi-replica storage or erasure coding storage, etc.

[0033] Control node 10 refers to the service node that provides storage services and manages storage services. There are generally multiple control nodes 10. These multiple control nodes act as master and slave nodes to provide storage services to each other. "Multiple" means two or more. To prevent split-brain scenarios among the control nodes, multiple control nodes 10 typically deploy a consensus protocol and use this protocol mechanism to compete for the master node. The master node then manages the storage services and resolves request conflicts. The master node has write permissions to the storage service node 20. In this embodiment, control node 10 primarily refers to the master node among the multiple control nodes.

[0034] Consensus protocols can include Two-Phase Commit Protocol (2PC), Three-Phase Commit Protocol (3PC), Paxos, and Raft, among others. Paxos is an algorithm used to achieve consensus in distributed systems. It aims to solve the problem of how multiple nodes in a distributed environment can reach a consensus on a certain value (such as configuration or state updates), ensuring consistency even if some nodes fail or the network is unstable. Paxos ensures consistency through two phases: the Prepare Phase and the Accept Phase.

[0035] In this embodiment, metadata and data are separated, that is, the control flow (i.e., metadata processing) and the data flow (data transmission written to the storage node) are separated, thereby achieving higher policy scalability and input / output (I / O) concurrency. Therefore, as Figure 1 As shown in the embodiments of this application, the distributed storage system may further include: a metadata service node 30.

[0036] The metadata service node manages the metadata of data blocks in storage node 20. Data block metadata refers to all descriptive information associated with that data block, used for managing and manipulating the data block itself. Metadata not only helps the system identify, locate, and manage data blocks, but also supports efficient data storage, retrieval, and protection. Data block metadata may include the data block's identity (ID), address information, and size.

[0037] For data to be written in the data stream, it may have actually been written successfully, but the upper-layer system (i.e., control node 10) cannot obtain confirmation and needs to reread the disk to confirm whether the data has actually been written successfully. This method of confirming whether the data has actually been written successfully is inefficient. In this embodiment, the data to be written in the data stream refers to the data to be written to storage node 20, which can be user data or consensus protocol log data. For the embodiment where the data to be written in the data stream is consensus protocol log data, compared to storing log data on the local disk of the control node, storing the consensus protocol log data in a distributed storage system and using redundant storage to store the log data in multiple data block replicas can improve the security of the log data.

[0038] In this application embodiment, the concept of a log stream is proposed. In this embodiment, the log stream (Journal Stream) 101 refers to a node or module used to provide data writing services. For example... Figure 1 and Figure 2 As shown, log stream 101 is set in management node 10 and can be implemented as a software module on management node 10.

[0039] Before using log stream 101, it needs to be initialized. Log stream 101 includes the concepts of data stream 10a and metadata stream 10b. Data stream 10a refers to the node or module that manages the data to be written to the storage node; metadata stream 10b refers to the node or module that manages the metadata of the data to be written to the storage node. Data stream 10a and metadata stream 10b are configured in the management node 10.

[0040] In this embodiment, log stream 101 needs to be initialized before use. The initialization process of log stream 101 includes: the control node 10 sending a first initialization request to the metadata service node 30. The first initialization request requests the metadata service node 30 to create file directories for data stream 10a and metadata stream 10b. The file directory for data stream 10a is used to record the metadata of data stream 10a; the file directory for metadata stream 10b is used to record the metadata of metadata stream 10b. In response to the initialization request from the control node 10, the metadata service node 30 can create file directories for data stream 10a and metadata stream 10b respectively, and return the IDs of the file directories for data stream 10a and metadata stream 10b to the control node 10.

[0041] Furthermore, the control node 10 can request the metadata service node 30 to initialize data stream 10a and metadata stream 10b. Specifically, the control node 10 can send a second initialization request to the metadata service node 30. The second initialization request includes the number M of data blocks requested to be allocated to the data stream, and the number N of data blocks requested to be allocated to the metadata stream. Both M and N are positive integers. Preferably, M ≥ 2 and N ≥ 2. With M ≥ 2, the metadata service node 30 can, when allocating data blocks to the data stream, try to control the distribution of the M data blocks across different storage nodes, achieving load balancing. On the other hand, if the metadata service node 30 malfunctions or the network between the control node 10 and the metadata service node 30 malfunctions before the M data blocks are fully consumed, the control node 10 can still use the unused storage space in the M data blocks to continue writing data, ensuring uninterrupted data storage services for a short period and improving service reliability to some extent. Similarly, N ≥ 2 also helps to achieve load balancing of storage nodes and ensure uninterrupted service for a short period. M and N can be equal or unequal.

[0042] Accordingly, in response to the second initialization request, the metadata service node 30 can allocate M data blocks for data stream 10a and N data blocks for metadata stream 10b. Specifically, the metadata service node 30 can return the identifiers of the M data blocks and the address information of the storage nodes where the M data blocks reside to the management node 10, thereby pre-allocating the M data blocks to data stream 10a. Similarly, the metadata service node 30 can also return the identifiers of the N data blocks and the address information of the storage nodes where the N data blocks reside to the management node 10, thereby pre-allocating the N data blocks to metadata stream 10b. Each data block may include multiple data block replicas. These replicas are distributed across different storage nodes, achieving redundant data storage and improving data security. The address information of the storage nodes can be Internet Protocol (IP) addresses. Once the data block allocation for data stream 10a and metadata stream 10b is completed, the initialization of data stream 10a and data stream 10b is finished.

[0043] The metadata service node 30 can also record the identifiers of the M data blocks allocated to data stream 10a and the address information of the storage nodes where the M data blocks are located in the file directory corresponding to data stream 10a; and record the identifiers of the N data blocks allocated to metadata stream 10b and the address information of the storage nodes where the N data blocks are located in the file directory corresponding to metadata stream 10b.

[0044] After data stream 10a and metadata stream 10b are initialized, data can be written to storage node 20 via data stream 10a. Data streams 10a and 10b are pre-allocated with data blocks. In this embodiment, for ease of description, the data to be written is defined as target data. Target data can be user data or log data of the consensus protocol running on management node 10. The data blocks pre-allocated to data streams 10a and 10b refer to the data blocks allocated to data streams 10a and 10b before the target data is successfully written. In this embodiment, for ease of description and distinction, the data blocks pre-allocated to data stream 10a are defined as first data blocks; and the data blocks pre-allocated to metadata stream 10b are defined as second data blocks. The number of first data blocks and second data blocks can be one or more. "Multiple" refers to two or more (including two). Figure 1 Data blocks 0 to M are the first data blocks pre-allocated to data stream 10a; data blocks 0 to N are the second data blocks pre-allocated to metadata stream 10b. Figure 2 Data blocks 0-M are the first data blocks pre-allocated to data stream 10a; data blocks 00-0N are the second data blocks pre-allocated to metadata stream 10b.

[0045] If the target data is the first data to be written after data stream 10a is initialized, then the first data block pre-allocated to data stream 10a is the M data blocks allocated after data stream 10a is created, i.e., the M data blocks allocated during data stream 10a initialization. Correspondingly, the second data block pre-allocated to metadata stream 10b is the N data blocks allocated after data stream 10a is created, i.e., the N data blocks allocated during metadata stream 10b initialization. If the target data is not the first data written after data stream 10a is initialized, the first data block pre-allocated to data stream 10a and the second data block pre-allocated to metadata stream 10b can also be data blocks allocated in other ways. This part will be described in the following embodiments and will not be repeated here.

[0046] For the first data block pre-allocated to data stream 10a, when the control node 10 performs the write operation of the target data, it can try to write the target data to multiple first data blocks in sequence until the target data is successfully written.

[0047] In some embodiments, the control node 10 may attempt to write the target data sequentially to multiple first data blocks according to the order of the first data blocks returned by the metadata service node 30, until the target data is successfully written. For example, the control node 10 may first select the first data block ranked first among the multiple first data blocks as the data block to be written, and attempt to write the target data to the data block to be written; if the target data writing fails, then the second-ranked first data block is selected as the data to be written, and the operation of attempting to write the target data to the data block to be written continues until the target data is successfully written.

[0048] Alternatively, each time, the control node 10 may randomly select a first data block from the first data block of the data stream 10a that has not yet attempted to write the target data as a data block to be written, and attempt to write the target data into the data block to be written until the target data is successfully written.

[0049] Furthermore, such as Figure 2 As shown, for a target data block that has been successfully written, the identifier of the target data block and the offset address of the target data in the target data block can be written to the second data block allocated to the metadata stream 10b. Figure 2 The target data block successfully written is designated as data block 0. Thus, when reading data, the target data is read directly based on the identifier and offset address of the target data block recorded in the second data block. Even if the control node detects a failed write to a data block, but the actual write to the target data is successful, since there is no relevant record in the metadata stream, it will not read data from the data block that the control node detected as having failed to write the target data but was actually successfully written to, ensuring that only one copy of the same data is read.

[0050] When the control node 10 writes the metadata of the target data block (i.e., the identifier of the target data block and the offset address of the target data in the target data block) into the second data block, it can try to write the identifier of the target data block and the offset address of the target data in the target data block into the second data block in turn until the identifier of the target data block and the offset address of the target data in the target data block are successfully written. This can reduce the possibility of data loss and the probability of data omission, and even ensure that the data is not lost, i.e., the data is not omitted.

[0051] In this embodiment, the control node switches to another data block in the data stream to write the target data as soon as it detects a write failure, continuing until it detects a successful write. It doesn't need to concern itself with whether the target data was actually written successfully, and therefore doesn't need to be confirmed by the read storage node. Thus, this data writing method improves data writing efficiency. Furthermore, only the metadata of the target data block where the target data was successfully written is written to the metadata stream. When reading data, only the data block with the corresponding record in the metadata stream is read. For data blocks where the control node detects a write failure but the data was actually written successfully, since there is no relevant record in the metadata stream, the corresponding data block will not be read, ensuring that only one copy of the same data is read.

[0052] For example, such as Figure 3 As shown, the address range of data block 0 is 0-110; the address range of data blocks 1 and 2 is 100-110; and the address range of data block 3 is 200-310. Assume that the length of the target data written each time is 10 bytes. When attempting to write target data 1 for the first time, the offset address is 0, and the length is 10 bytes. If writing data block 0 is successful, the identifier of data block 0 (i.e., ...) is written into the data block allocated to metadata stream 10b. Figure 3 The data block 0 in the target data 1 and the offset address of the target data 1 in the data block 0 (i.e., Figure 3 The offset address is 0 in the data block. During subsequent writes, assuming the target data 2 has an offset address of 100 and a length of 10 bytes, it is still written to data block 0. If the control node 10 detects that the write of target data 2 has failed, it switches to data block 1 as the data block to be written. If the control node 10 detects that the write of target data 2 to data block 1 has failed, it switches to data block 2 as the data block to be written and attempts to write target data 2 to data block 2. If the write of target data 2 to data block 2 is successful, the identifier of data block 2 (i.e., ...) is... Figure 3 Data block 2 in data block 2 and the offset address of target data 2 in data block 2 (i.e. Figure 3 The target data 2 is written to the data block allocated by metadata stream 10b at offset address 0, but not at offset address 100 of data block 1. Even if the target data 2 is successfully written to data block 0 and data block 1, the control node 10 will not be aware of it. When reading target data 2, it will not read data from data block 0 and data block 1, ensuring that the same data is read only once, thus achieving data non-duplication. When attempting to write target data 3 later, the offset address is 200 and the length is 10 bytes, and the target data 3 is attempted to be written to data block 3. If the target data 3 is successfully written to data block 3, the identifier of data block 3 (i.e., the target data 2) is written to the data block allocated by metadata stream 10b. Figure 3Data block 3 in the middle) and the offset address of target data 3 in data block 3 (i.e. Figure 3 Offset address 200 in the data.

[0053] In addition, when the target data fails to be written to a data block in the data stream, the control node can switch to another data block in the data stream to write the target data until it detects that the target data has been successfully written. This can reduce the possibility of data loss and the probability of data omission, and even ensure that no data is lost or no data is missed.

[0054] In some embodiments of this application, to facilitate the management of data blocks by the control node 10, the control node 10 may also set the state of the first data block. For example, Figure 1 As shown, for the first data block currently being attempted to be written (i.e., the data block to be written), the state of the data block to be written can be set to the "Writing" state, which indicates that the data block is being written. Figure 1 The data block currently being written to is data block 2. For the first data block where the target data write failed, its state can be set to read-only, such as a sealed state. A sealed state, also known as a read-only state, indicates that the data block only supports reading data and not writing data. Setting the first data block to read-only prevents subsequent write operations from attempting to write to that data block again, thus avoiding potential data overwriting or further corruption. On the other hand, even if the target data write to that data block fails, the data already written to that data block may still be valid. By setting it to read-only, this data can be protected from accidental modification or corruption. Figure 1 Data blocks 0 and 1 are in read-only state. For other first data blocks that have not yet been written to, their state can be set to Check In. Data blocks in Check In state support data writing and can be identified as pending write blocks at any time, changing their state to Writing. Figure 1 The data blocks that are in a state of waiting to be written are data blocks M or N, etc.

[0055] Similarly, for the second data block of metadata stream 10b, the control node 10 can also manage the status of the second data block. For the second data block currently being attempted to be written (i.e., the data block to be written), the status of the second data block can be set to the Writing state. For the second data block whose data writing has failed, its status can be set to the Read-only state. For other second data blocks that have not yet attempted to be written, their status can be set to the Check-In state.

[0056] In this embodiment, the data blocks in the check-in state are pre-allocated. To further improve the stability of the distributed storage system, the control node 10 can continuously and asynchronously request the metadata service node 20 to allocate data blocks for data stream 10a and metadata stream 10b, ensuring that data stream 10a and metadata stream 10b have sufficient prepared data blocks to support data writing. Thus, even if the metadata service node malfunctions or the network between the metadata service node and the control node fails, the control node 10 can still use unconsumed data blocks in the data stream and metadata stream to continue writing data, ensuring uninterrupted data storage service for a short period and improving the reliability of the distributed storage service to a certain extent.

[0057] The following is an exemplary description of how the control node 10 continuously and asynchronously requests the metadata service node 20 to pre-allocate data blocks for data stream 10a and metadata stream 10b.

[0058] In some embodiments, the control node 10 may request the metadata service node 30 to allocate a first number (P) of data blocks for the data stream and a second number (Q) of data blocks for the metadata stream before the target data is successfully written.

[0059] In response to a request from the management node, the metadata service node 30 can pre-allocate a first number (P) of third data blocks for data stream 10a and a second number (Q) of fourth data blocks for metadata stream 10b. Here, P and Q are positive integers. In some embodiments, P ≥ 2, Q ≥ 2, and P and Q are less than the total number of data blocks in a single storage node. P ≥ 2 ensures that when the metadata service node allocates data blocks for the data streams, it can control the distribution of the P third data blocks across different storage nodes, achieving load balancing among the storage nodes. Similarly, Q ≥ 2 also helps to achieve load balancing among the storage nodes. P and Q can be equal or unequal.

[0060] Specifically, in response to a request from the control node, the metadata service node 30 predetermines P third data blocks for data stream 10a and returns the identifiers of the P third data blocks and the address information of the storage nodes where the P third data blocks are located to data stream 10a, thereby pre-allocating the P third data blocks to data stream 10a. Similarly, in response to a request from the control node, the metadata service node 30 can also predetermine Q fourth data blocks for metadata stream 10b and return the identifiers of the Q fourth data blocks and the address information of the storage nodes where the Q fourth data blocks are located to the metadata stream, thereby pre-allocating the fourth data blocks to the metadata stream.

[0061] Before the target data is successfully written, data blocks are continuously requested and pre-allocated for the data stream and metadata stream. This ensures that there are enough data blocks to store the target data, as well as enough data blocks to store the metadata of the target data block that has been successfully written. This reduces the probability of data loss and can even guarantee that no data is lost.

[0062] Before the target data is successfully written, the metadata service node is requested to allocate data blocks for the data stream and metadata stream respectively. After the data stream and metadata stream are created, when the control node requests the metadata service node to initialize the data stream and metadata stream, it does so by sending an initialization request (i.e., the aforementioned second initialization request) to the metadata service node. For details on the implementation method, please refer to the relevant content on the initialization of the data stream and metadata stream, which will not be repeated here. In this implementation method, the control node 10 can determine that P third data blocks are the first data blocks and Q fourth data blocks are the second data blocks.

[0063] In addition to pre-allocating data blocks for the data stream and metadata stream during initialization, as mentioned above, the control node 10 can also continuously request data blocks for the data stream and metadata stream before the target data is successfully written, so as to ensure that there are enough data blocks to support data writing.

[0064] In some embodiments, since each switch of the data block to be written indicates that one data block has been marked as read-only, meaning that data writing is no longer supported, it means that the number of data blocks currently supported for writing in the data stream or metadata stream has decreased. Therefore, in order to ensure that there are sufficient data blocks to support data writing, it is necessary to allocate data blocks to the data stream or metadata stream in a timely manner. Accordingly, the management node 10 can monitor the switching event of the data block to be written in the data stream (defined as the first switching event), and upon detecting the occurrence of the first switching event in the data stream, pre-request the metadata service node 30 to allocate a first number (P) data blocks for the data stream.

[0065] In this application embodiment, the specific implementation of the first switching event for the data block to be written in the monitored data stream is not limited. In some embodiments, for any data block A currently attempting to write target data, if the writing of target data to data block A fails, a first switching event is determined to have occurred. Accordingly, the state of data block A can be set to read-only. For subsequent processes attempting to write target data, data block A no longer belongs to the first data block.

[0066] Alternatively, the control node 10 can also monitor the write latency of data block A. If the write latency of data block A is greater than or equal to a set first latency threshold, a first switching event is determined to have occurred. Specifically, if the write latency of data block A is greater than or equal to the set first latency threshold, it indicates that data block A may be malfunctioning. To improve the reliability of data writing, the system can switch to another data block to write the target data, thus triggering the first switching event. Correspondingly, the state of data block A can be set to read-only. For subsequent attempts to write the target data, data block A is no longer considered the first data block.

[0067] Alternatively, the control node 10 can also count the amount of data stored in data block A. If the amount of data stored in data block A is greater than or equal to a set first data volume threshold, it indicates that the storage space of data block A is insufficient. Continuing to write data may lead to data overflow. Therefore, it can switch to another data block to write the target data. The first data volume threshold can be set according to the size of the data block. For example, the first data volume threshold can be equal to the size of the data block. Based on this, if the amount of data in data block A is greater than or equal to the set first data volume threshold, it is determined that a first data flow switching event has occurred. Accordingly, the state of data block A can be set to read-only. For subsequent processes attempting to write the target data, data block A no longer belongs to the first data block.

[0068] Alternatively, the control node 10 can monitor whether the target data is successfully written to data block A and monitor the write latency of data block A; if the target data fails to be written to data block A, and / or the write latency of data block A is greater than or equal to the set first latency threshold, then it is determined that a first switching event has occurred.

[0069] Alternatively, the control node 10 can monitor whether the target data has been successfully written to data block A and count the amount of data stored in data block A; if the target data fails to be written to data block A, and / or the amount of data stored in data block A is greater than or equal to the set first data amount threshold, then it is determined that a first switching event has occurred.

[0070] Alternatively, the control node 10 can monitor the write latency of data block A and the amount of data stored in data block A; if the write latency of data block A is greater than or equal to the set first latency threshold, and / or the amount of data stored in data block A is greater than or equal to the set first data amount threshold, then it is determined that a first switching event has occurred.

[0071] Alternatively, the control node 10 can monitor whether the target data is successfully written to data block A, monitor the write latency of data block A, and count the amount of data stored in data block A; if the target data fails to be written to data block A, and / or the write latency of data block A is greater than or equal to the set first latency threshold, and / or the amount of data stored in data block A is greater than or equal to the set first data amount threshold, then it is determined that a first switching event has occurred.

[0072] Furthermore, in response to a first switching event of the target data's pending data block, the control node 10 may pre-request the metadata service node 30 to allocate a first number (P) data blocks for the data stream. The metadata service node 30 may, in response to this request, pre-allocate P third data blocks for the data stream. For a detailed implementation of the metadata service node 30 pre-allocating P third data blocks for the data stream, please refer to the relevant content of the foregoing embodiments, which will not be repeated here. Accordingly, the control node 10 may determine the P third data blocks and the data blocks that the data stream supports writing at the time of the first switching event as the first data block.

[0073] Similarly, the control node 10 can monitor the switching event of the data block to be written in the metadata stream (defined as the second switching event), and when the second switching event is detected in the metadata stream, it can request the metadata service node 30 to allocate a second number (Q) data blocks for the metadata stream in advance.

[0074] In this application embodiment, the specific implementation of the second switching event for the data block to be written in the monitoring metadata stream is not limited. In some embodiments, for any data block B currently attempting to write metadata (i.e., the identifier of the target data block and the offset address of the target data) to the target data block, if the writing of the target data to data block B fails, it is determined that a second switching event has occurred in the metadata stream. Accordingly, the state of data block B can be set to read-only. For subsequent attempts to write metadata to the target data block, data block B no longer belongs to the second data block.

[0075] Alternatively, the control node 10 can also monitor the write latency of data block B. If the write latency of data block B is greater than or equal to a set second latency threshold, a second switching event is determined to have occurred. Specifically, if the write latency of data block B is greater than or equal to the set second latency threshold, it indicates that data block B may be malfunctioning. To improve the reliability of data writing, the system can switch to another data block to write the metadata of the target data block, thus triggering the second switching event. Correspondingly, the state of data block B can be set to read-only. For subsequent attempts to write the metadata of the target data block, data block B no longer belongs to the second data block.

[0076] Alternatively, the control node 10 can also count the amount of data stored in data block B. If the amount of data stored in data block B is greater than or equal to a set second data volume threshold, it indicates that the storage space of data block B is insufficient. Continuing to write data may lead to data overflow. Therefore, it can switch to another data block to write the metadata of the target data block. The second data volume threshold can be set according to the size of the data block. For example, the second data volume threshold can be equal to the size of the data block. Based on this, if the amount of data in data block B is greater than or equal to the set second data volume threshold, it is determined that a second switching event has occurred in the metadata stream. Accordingly, the state of data block B can be set to read-only. For subsequent attempts to write the metadata of the target data block, data block B no longer belongs to the second data block.

[0077] Alternatively, the control node 10 can monitor whether the metadata of the target data block (i.e., the identifier of the target data block and the offset address of the target data) is successfully written to data block B, and monitor the write latency of data block B; if the metadata of the target data block fails to be written to data block B, and / or the write latency of data block B is greater than or equal to the set second latency threshold, then it is determined that a second switching event has occurred.

[0078] Alternatively, the control node 10 can monitor whether the metadata of the target data block (i.e., the identifier of the target data block and the offset address of the target data) is successfully written to data block B, and count the amount of data stored in data block B; if the metadata of the target data block fails to be written to data block B, and / or the amount of data stored in data block B is greater than or equal to the set second data volume threshold, then it is determined that a second switching event has occurred.

[0079] Alternatively, the control node 10 can monitor the write latency of data block B and the amount of data stored in data block B; if the write latency of data block B is greater than or equal to the set second latency threshold, and / or the amount of data stored in data block B is greater than or equal to the set second data amount threshold, then it is determined that a second switching event has occurred.

[0080] Alternatively, the control node 10 can monitor whether the metadata of the target data block (i.e., the identifier of the target data block and the offset address of the target data) is successfully written to data block B, and monitor the write latency of data block B, as well as the amount of data stored in data block B; if the metadata of the target data block fails to be written to data block B, and / or the write latency of data block B is greater than or equal to the set second latency threshold, and / or the amount of data stored in data block B is greater than or equal to the set second data amount threshold, then it is determined that a second switching event has occurred.

[0081] Accordingly, in response to a second switching event of the data blocks to be written in the metadata stream, the control node 10 may pre-request the metadata service node to allocate a second number (Q) data blocks for the data stream. The metadata service node 30 may, in response to this request, pre-allocate Q fourth data blocks for the metadata stream. For a specific implementation of the metadata service node 30 pre-allocating Q fourth data blocks for the metadata stream, please refer to the relevant content of the foregoing embodiments, which will not be repeated here. Accordingly, the control node 10 may determine the Q fourth data blocks and the data blocks that the metadata stream supports writing at the time of the second switching event as the second data blocks.

[0082] In other embodiments, when the number of data blocks supporting data writing (i.e., data blocks in a waiting-to-be-written state) in the data stream or metadata stream is small, it indicates that the data stream or metadata stream needs to be supplemented with new data blocks in a timely manner. Based on this, for the data stream, the control node 10 can monitor the number R of data blocks currently supporting writing in the data stream; if the number R is less than or equal to a set first quantity threshold, it indicates that the number of data blocks supporting data writing in the data stream is insufficient, and new data blocks need to be allocated in a timely manner. The first quantity threshold is greater than or equal to 1 and less than P. Accordingly, when the number R is less than or equal to the set first quantity threshold, the control node 10 can pre-request the metadata service node 30 to allocate P data blocks for the data stream. The metadata service node 30 can respond to this request and pre-allocate P third data blocks for the data stream. For a detailed implementation of the metadata service node 30 pre-allocating P third data blocks for the data stream, please refer to the relevant content of the foregoing embodiments, which will not be repeated here. Accordingly, the control node 10 can determine the P third data blocks and the data blocks that the data stream supports writing when R is less than or equal to the first quantity threshold as the first data blocks.

[0083] Similarly, for the metadata stream, the control node 10 can monitor the number S of data blocks currently supported for writing in the metadata stream. If the number S is less than or equal to a set second threshold, it indicates that the number of data blocks supporting data writing in the metadata stream is insufficient, and new data blocks need to be allocated in a timely manner. The second threshold is greater than or equal to 1 and less than Q. Accordingly, when the number S is less than or equal to the set second threshold, the control node 10 can pre-request the metadata service node 30 to allocate Q data blocks for the metadata stream. The metadata service node 30 can respond to this request and pre-allocate Q fourth data blocks for the metadata stream. For a detailed implementation of the metadata service node 30 pre-allocating Q fourth data blocks for the data stream, please refer to the relevant content of the foregoing embodiments, which will not be repeated here. Accordingly, the control node 10 can determine the Q fourth data blocks and the data blocks supported for writing in the metadata stream when S is less than or equal to the second threshold as the second data blocks.

[0084] For the first data block pre-allocated to data stream 10a, when the control node 10 performs a write operation on the target data, it can sequentially attempt to write the target data into multiple first data blocks until the target data is successfully written. For specific writing methods, please refer to the relevant content in the foregoing embodiments, which will not be repeated here.

[0085] Furthermore, for a successfully written target data block, the control node 10 can write the target data block's identifier and the target data's offset address within the target data block to the second data block allocated to the metadata stream 10b. In this way, when reading data, the target data is read directly based on the target data block's identifier and offset address recorded in the second data block. Even if the control node detects a failed write to a data block, but the target data was actually written successfully, since there is no relevant record in the metadata stream's data blocks, it will not read data from the data block where the control node detected a failed write but the data was actually written successfully, ensuring that only one copy of the same data is read.

[0086] It should be noted that in the various embodiments of this application, the target data can be any data to be written. In some embodiments, the target data is the data first written to the target data block. For the data first written to the target data block (i.e., the target data), the identifier of the target data block and the offset address of the target data in the target data block can be written to the data block of the metadata stream. For subsequent data to be written, writing to the target data block can be attempted directly; if the data to be written to the target data block is successful, the identifier of the target data block and the offset address of the data to be written in the target data block do not need to be written to the data block of the metadata stream. This is mainly because when a data block is written for the first time, it is usually written in the order of logical blocks. This means that if the offset address of the first write to the data block is known, the offset addresses of other data written to the data block can be calculated based on this offset address of the first write to the data block. Therefore, only writing the offset address of the first successfully written data in the data block of the data stream to the data block of the metadata stream can save the storage resources of the data block of the metadata stream.

[0087] It is worth noting that the data to be written in the data stream (such as the aforementioned target data) can be user data or logs generated by the consensus protocol running in the control node. In the embodiment where the logs generated by the consensus protocol are stored in the storage nodes of a distributed storage system, the log system no longer depends on the local disk of the control node. Therefore, there are no special requirements for the type of control node; a computer-type server can be used as the control node, which helps improve the flexibility of control node deployment.

[0088] The consensus protocol generates logs that record the commands to be executed by the state machine in the management node. These commands determine the final state of the state machine, which provides read and write services. Therefore, if the management node restarts, it is necessary to restore the management node's state, specifically the logs generated by the management node's consensus protocol.

[0089] In this context, the state machine is a Deterministic Finite State Machine (DFSM) running on each management node. This means that for a given input, the state machine always produces the same output and state transitions. The goal is to ensure that these state machines reach a consistent state so that, from the outside, it appears as if only one state machine is operating. If it can be ensured that all state machines receive the exact same sequence of commands and execute them in the same order, then these state machines will eventually reach the same final state. This means that regardless of which state machine replica a client connects to, it will get the same result. Because each state machine runs the same logic independently, the system can tolerate the failure of some state machines without affecting the overall quality of service.

[0090] If the control node restarts after logs have been successfully written to the data stream, the successfully written logs must be recovered. For ease of description and distinction, the logs that have been successfully written to the data stream when the control node restarts are defined as the target logs. The target logs may or may not include the target data, depending on the timing of the control node restart and the successful writing of the target data. If the target data has been successfully written before the control node restarts, the target logs include the target data. If the target data has not yet been successfully written when the control node restarts, the target logs do not include the target data. Generally, the control node is the master node among multiple control nodes.

[0091] To recover the logs generated by the consensus protocol of the control node, the control node can obtain the identifier of the data block (defined as the fifth data block) where the target log was successfully written and its offset address within the fifth data block from the data blocks allocated in the metadata stream 10b. Then, based on the identifier of the fifth data block and its offset address, it can read the target log. Afterward, the logs generated by the consensus protocol in the control node can be recovered based on the target log. Specifically, the target log can be used as the logs generated by the consensus protocol in the restarted control node, thereby recovering the logs generated by the consensus protocol in the control node. Since the data blocks in the metadata stream only store logs of successfully written data, recovering the consensus protocol generated by the control node based on the target log ensures that all successfully written logs are correctly recovered, maintaining the state consistency of the control node.

[0092] In addition to the aforementioned distributed storage system, this application embodiment also provides a data writing method, which will be described exemplarily below.

[0093] Figure 4 This is a flowchart illustrating the data writing method provided in an embodiment of this application. In this data writing method, a control node in a distributed storage system pre-allocates multiple first data blocks for the data stream; a second data block is pre-allocated for the metadata stream; and the first and second data blocks are stored on multiple storage nodes in the distributed storage system. Figure 4 As shown, this data writing method mainly includes the following steps:

[0094] 401. The target data to be written is sequentially attempted to be written to multiple first data blocks until the target data is successfully written.

[0095] 402. Write the identifier of the target data block and the first offset address of the target data in the target data block into the second data block, so as to read the target data according to the identifier of the target data block and the first offset address recorded in the second data block; wherein, the target data block is the data block in which the target data is successfully written.

[0096] In this embodiment, the data to be written in the data stream refers to the data to be written to the storage node, which can be user data or consensus protocol log data. For embodiments where the data to be written in the data stream is consensus protocol log data, compared to storing log data on the local disk of the control node, storing the consensus protocol log data in a distributed storage system and using redundant storage across multiple data block replicas can improve the security of the log data.

[0097] In this application embodiment, the concept of a journal stream is proposed. In this embodiment, a journal stream refers to a node or module used to provide data writing services. The journal stream includes a data stream and a metadata stream. For explanations of the data stream and metadata stream, please refer to the relevant content in the foregoing system embodiments, which will not be repeated here.

[0098] In this embodiment, the log stream needs to be initialized before use. The initialization process includes: the control node sending a first initialization request to the metadata service node. This first initialization request requests the metadata service node to create file directories for the data stream and the metadata stream. The file directory for the data stream records its metadata; the file directory for the metadata stream records its metadata. In response to the control node's initialization request, the metadata service node creates file directories for both the data stream and the metadata stream, and returns the IDs of both file directories to the control node.

[0099] Furthermore, the control node can request the metadata service node to initialize the data stream and metadata stream. Specifically, the control node can send a second initialization request to the metadata service node. The second initialization request includes the number M of data blocks requested to be allocated to the data stream, and the number N of data blocks requested to be allocated to the metadata stream. Both M and N are positive integers. Preferably, M ≥ 2, and N ≥ 2. With M ≥ 2, the metadata service node can, as far as possible, control the distribution of the M data blocks across different storage nodes when allocating data blocks to the data stream, achieving load balancing. On the other hand, if the metadata service node malfunctions or the network between the control node and the metadata service node malfunctions before the M data blocks are fully consumed, the control node can still use the unused storage space in the M data blocks to continue writing data, ensuring uninterrupted data storage services for a short period and improving service reliability to some extent. Similarly, N ≥ 2 also helps to achieve load balancing of storage nodes and ensure uninterrupted service for a short period. M and N can be equal or unequal.

[0100] Accordingly, in response to the second initialization request, the metadata service node can allocate M data blocks to the data stream and N data blocks to the metadata stream. Specifically, the metadata service node can return the identifiers of the M data blocks and the address information of the storage nodes where the M data blocks reside to the control node, thereby pre-allocating the M data blocks to the data stream. Similarly, the metadata service node can also return the identifiers of the N data blocks and the address information of the storage nodes where the N data blocks reside to the control node, thereby pre-allocating the N data blocks to the metadata stream. Each data block can include multiple data block replicas. These replicas are distributed across different storage nodes, achieving redundant data storage and improving data security. Once the data block allocation for the data stream and metadata stream is complete, the initialization of the data stream and metadata stream is finished.

[0101] The metadata service node can record the identifiers of the M data blocks allocated to the data stream and the address information of the storage nodes where the M data blocks are located in the file directory corresponding to the data stream; and record the identifiers of the N data blocks allocated to the metadata stream and the address information of the storage nodes where the N data blocks are located in the file directory corresponding to the metadata stream.

[0102] After the data stream and metadata stream are initialized, data can be written to the storage node via the data stream. Data blocks are pre-allocated to both the data stream and metadata stream. In this embodiment, for ease of description, the data to be written is defined as target data. Target data can be user data or log data of the consensus protocol running on the management node. The data blocks pre-allocated to the aforementioned data stream and metadata stream refer to the data blocks allocated to the data stream and metadata stream before the target data is successfully written. In this embodiment, for ease of description and distinction, the data block pre-allocated to the data stream is defined as the first data block; and the data block pre-allocated to the metadata stream is defined as the second data block. The number of second data blocks for the first data block can be one or more. "Multiple" means two or more (including two).

[0103] If the target data is the first data to be written after the data stream initialization is complete, the first data block pre-allocated to the data stream is the M data blocks allocated after the data stream creation is completed, i.e., the M data blocks allocated during data stream initialization. Correspondingly, the second data block pre-allocated to the metadata stream is the N data blocks allocated after the data stream creation is complete, i.e., the N data blocks allocated during metadata stream initialization. If the target data is not the first data to be written after the data stream initialization is complete, the first data block pre-allocated to the data stream and the second data block pre-allocated to the metadata stream can also be data blocks allocated in other ways. This part will be described in the following embodiments and will not be repeated here.

[0104] For the first data block pre-allocated to the data stream, in step 401, when performing the write operation of the target data, the target data can be attempted to be written to multiple first data blocks in sequence until the target data is successfully written.

[0105] Furthermore, for the target data block that was successfully written, in step 402, the identifier of the target data block and the offset address of the target data within the target data block can be written to the second data block allocated to the metadata stream. In this way, when reading data, the target data can be read directly based on the identifier and offset address of the target data block recorded in the second data block. Even if the control node detects a failed write to a data block, but the target data was actually successfully written, since there is no relevant record in the data block of the metadata stream, it will not read data from the data block that the control node detected as having failed to write the target data but was actually successfully written, ensuring that only one copy of the same data is read.

[0106] Specifically, when writing the metadata of the target data block (i.e., the identifier of the target data block and the offset address of the target data in the target data block) into the second data block, the identifier of the target data block and the offset address of the target data in the target data block can be tried to be written into the second data block in turn until the identifier of the target data block and the offset address of the target data in the target data block are successfully written. This can reduce the possibility of data loss and the probability of data omission, and even ensure that no data is lost, i.e., no data is omitted.

[0107] In this embodiment, the control node switches to another data block in the data stream to write the target data as soon as it detects a failure to write the target data, and continues writing until it detects a successful write. It doesn't need to concern itself with whether the target data was actually written successfully, and therefore doesn't need to verify this through the read storage node. Thus, this data writing method improves data writing efficiency. Furthermore, only the identifier and offset address of the target data block that was successfully written are written to the data block in the metadata stream. Even if the control node detects a failed write to a data block, but the target data was actually written successfully, since there is no related record in the metadata stream's data block, it will not read data from the data block where the control node detected a failed write but the target data was actually written successfully. This ensures that only one copy of the same data is read.

[0108] In addition, when the target data fails to be written to a data block in the data stream, the control node can switch to another data block in the data stream to write the target data until it detects that the target data has been successfully written. This can reduce the possibility of data loss and the probability of data omission, and even ensure that no data is lost or no data is missed.

[0109] In some embodiments of this application, for the purpose of managing the state of data blocks, the state of the first data block currently being attempted to be written (i.e., the data block to be written) can be set to a "Writing" state, which indicates that the data block is being written. For the first data block whose target data writing failed, its state can be set to a read-only state. Setting the state of the first data block to read-only prevents subsequent write operations from attempting to write to the data block again, thereby avoiding potential data overwriting or further corruption. On the other hand, even if the target data writing to the data block fails, the data already written to the data block may still be valid. By setting it to read-only, this data can be protected from accidental modification or destruction. For other first data blocks that have not yet been attempted to be written, their state can be set to a "Check In" state. Data blocks in the "Check In" state support data writing and can be identified as data blocks to be written at any time, changing to a "Writing" state.

[0110] Similarly, the second data block of the metadata stream can also be managed in terms of state. For the second data block currently being attempted to be written (i.e., the data block to be written), its state can be set to the "Writing" state. For the second data block where data writing has failed, its state can be set to the "Read-only" state. For other second data blocks that have not yet been attempted to be written, their state can be set to the "Check In" state.

[0111] In this embodiment, the data blocks in the check-in state are pre-allocated. To further improve the stability of the distributed storage system, the control node can continuously and asynchronously request the metadata service node to allocate data blocks for the data stream and metadata, ensuring that the data stream and metadata stream have sufficient prepared data blocks to support data writing. Thus, even if the metadata service node malfunctions or the network between the metadata service node and the control node fails, the control node can still use unconsumed data blocks in the data stream and metadata stream to continue writing data, ensuring uninterrupted data storage services for a short period and improving the reliability of the distributed storage service to a certain extent.

[0112] The following example illustrates how the control node continuously and asynchronously requests data blocks from the metadata service node for data streams and metadata streams.

[0113] In some embodiments, before the target data is successfully written, the metadata service node may be requested in advance to allocate a first number (P) of data blocks to the data stream, and a second number (Q) of data blocks may be requested in advance to allocate to the metadata stream.

[0114] In response to a request from the management node, the metadata service node can pre-allocate a first number (P) of third data blocks to the data stream and a second number (Q) of fourth data blocks to the metadata stream. Here, P and Q are positive integers. In some embodiments, P ≥ 2, Q ≥ 2, and P and Q are less than the total number of data blocks in a single storage node. P ≥ 2 ensures that when the metadata service node allocates data blocks to the data stream, it can control the distribution of the P third data blocks across different storage nodes, achieving load balancing among the storage nodes. Similarly, Q ≥ 2 also helps to achieve load balancing among the storage nodes. P and Q can be equal or unequal.

[0115] Before the target data is successfully written, data blocks are continuously requested and pre-allocated for the data stream and metadata stream. This ensures that there are enough data blocks to store the target data, as well as enough data blocks to store the metadata of the target data block that has been successfully written. This reduces the probability of data loss and can even guarantee that no data is lost.

[0116] Before the target data is successfully written, the metadata service node is requested to allocate data blocks for the data stream and metadata stream respectively. After the data stream and metadata stream are created, when the control node requests the metadata service node to initialize the data stream and metadata stream, it does so by sending an initialization request (i.e., the aforementioned second initialization request) to the metadata service node. For details on the implementation, please refer to the aforementioned content on initializing the data stream and metadata stream, which will not be repeated here. In this implementation, P third data blocks can be determined as the first data block, and Q fourth data blocks can be determined as the second data block.

[0117] In addition to pre-allocating data blocks for the data stream and metadata stream during initialization, as mentioned above, data blocks can be continuously requested for the data stream and metadata stream before the target data is successfully written, to ensure that there are sufficient data blocks to support data writing.

[0118] In some embodiments, since each switch of the data block to be written indicates that a data block has been marked as read-only, meaning it no longer supports data writing, it means that the number of data blocks currently supported for writing in the data stream or metadata stream has decreased. Therefore, in order to ensure that there are sufficient data blocks to support data writing, it is necessary to allocate data blocks to the data stream or metadata stream in a timely manner. Accordingly, the switching event of the data block to be written in the data stream (defined as the first switching event) can be monitored, and if the first switching event is detected in the data stream, the metadata service node can be requested in advance to allocate a first number (P) data blocks to the data stream.

[0119] In this application embodiment, the specific implementation of the first switching event for the data block to be written in the monitored data stream is not limited. In some embodiments, for any data block A currently attempting to write target data, if the writing of target data to data block A fails, a first switching event is determined to have occurred. Accordingly, the state of data block A can be set to read-only. For subsequent processes attempting to write target data, data block A no longer belongs to the first data block.

[0120] Alternatively, the write latency of data block A can be monitored. If the write latency of data block A is greater than or equal to a set first latency threshold, a first switching event is determined to have occurred. Accordingly, the state of data block A can be set to read-only. For subsequent attempts to write target data, data block A no longer belongs to the first data block.

[0121] Alternatively, the amount of data stored in data block A can be analyzed. If the amount of data stored in data block A is greater than or equal to a set first data volume threshold, a first data stream switching event is determined. Accordingly, the state of data block A can be set to read-only. For subsequent attempts to write target data, data block A no longer belongs to the first data block.

[0122] Alternatively, it can monitor whether the target data is successfully written to data block A and monitor the write latency of data block A; if the target data fails to be written to data block A, and / or the write latency of data block A is greater than or equal to the set first latency threshold, then it is determined that a first switching event has occurred.

[0123] Alternatively, it can monitor whether the target data is successfully written to data block A and count the amount of data stored in data block A; if the target data fails to be written to data block A, and / or the amount of data stored in data block A is greater than or equal to a set first data volume threshold, then it is determined that a first switching event has occurred.

[0124] Alternatively, the write latency of data block A can be monitored, and the amount of data stored in data block A can be counted; if the write latency of data block A is greater than or equal to a set first latency threshold, and / or the amount of data stored in data block A is greater than or equal to a set first data amount threshold, then a first switching event is determined to have occurred.

[0125] Alternatively, it can monitor whether the target data is successfully written to data block A, monitor the write latency of data block A, and count the amount of data stored in data block A; if the target data fails to be written to data block A, and / or the write latency of data block A is greater than or equal to the set first latency threshold, and / or the amount of data stored in data block A is greater than or equal to the set first data amount threshold, then it is determined that a first switching event has occurred.

[0126] Furthermore, in response to a first switching event of the target data's pending data block, a metadata service node can be requested in advance to allocate a first number (P) data blocks for the data stream. The metadata service node can then respond to this request by pre-allocating P third data blocks for the data stream. For a specific implementation of the metadata service node pre-allocating P third data blocks for the data stream, please refer to the relevant content in the foregoing embodiments, which will not be repeated here. Accordingly, the P third data blocks and the data blocks that the data stream supports writing at the time of the first switching event can be determined as the first data blocks.

[0127] Similarly, the switching event of the data block to be written in the metadata stream can be monitored (defined as the second switching event), and if the second switching event of the metadata stream is detected, the metadata service node can be requested in advance to allocate a second number (Q) data blocks for the metadata stream.

[0128] In this application embodiment, the specific implementation of the second switching event for the data block to be written in the monitoring metadata stream is not limited. In some embodiments, for any data block B currently attempting to write metadata (i.e., the identifier of the target data block and the offset address of the target data) to the target data block, if the writing of the target data to data block B fails, it is determined that a second switching event has occurred in the metadata stream. Accordingly, the state of data block B can be set to read-only. For subsequent attempts to write metadata to the target data block, data block B no longer belongs to the second data block.

[0129] Alternatively, the write latency of data block B can be monitored. If the write latency of data block B is greater than or equal to a set second latency threshold, a second switching event is determined to have occurred. Accordingly, the state of data block B can be set to read-only. For subsequent attempts to write metadata to the target data block, data block B no longer belongs to the second data block.

[0130] Alternatively, the amount of data stored in data block B can be analyzed. If the amount of data stored in data block B is greater than or equal to a set second data volume threshold, a second switching event is determined to have occurred in the metadata stream. Accordingly, the state of data block B can be set to read-only. For subsequent attempts to write metadata to the target data block, data block B no longer belongs to the second data block.

[0131] Alternatively, it can monitor whether the metadata of the target data block (i.e., the identifier of the target data block and the offset address of the target data) is successfully written to data block B, and monitor the write latency of data block B; if the metadata of the target data block fails to be written to data block B, and / or the write latency of data block B is greater than or equal to the set second latency threshold, then it is determined that a second switching event has occurred.

[0132] Alternatively, it can monitor whether the metadata of the target data block (i.e., the identifier of the target data block and the offset address of the target data) is successfully written to data block B, and count the amount of data stored in data block B; if the metadata of the target data block fails to be written to data block B, and / or the amount of data stored in data block B is greater than or equal to the set second data amount threshold, then it is determined that a second switching event has occurred.

[0133] Alternatively, the write latency of data block B can be monitored, and the amount of data stored in data block B can be counted; if the write latency of data block B is greater than or equal to the set second latency threshold, and / or the amount of data stored in data block B is greater than or equal to the set second data amount threshold, then a second switching event is determined to have occurred.

[0134] Alternatively, it can monitor whether the metadata of the target data block (i.e., the identifier of the target data block and the offset address of the target data) is successfully written to data block B, and monitor the write latency of data block B, as well as the amount of data stored in data block B; if the metadata of the target data block fails to be written to data block B, and / or the write latency of data block B is greater than or equal to the set second latency threshold, and / or the amount of data stored in data block B is greater than or equal to the set second data amount threshold, then it is determined that a second switching event has occurred.

[0135] Accordingly, in response to a second switching event of the data blocks to be written in the metadata stream, the metadata service node may be requested in advance to allocate a second number (Q) data blocks for the data stream. The metadata service node may, in response to this request, pre-allocate Q fourth data blocks for the metadata stream. For a specific implementation of the metadata service node pre-allocating Q fourth data blocks for the metadata stream, please refer to the relevant content of the foregoing embodiments, which will not be repeated here. Accordingly, the Q fourth data blocks and the data blocks that the metadata stream supports writing when the second switching event occurs can be determined as the second data blocks.

[0136] In other embodiments, when the number of data blocks supporting data writing (i.e., data blocks in a waiting-to-be-written state) in the data stream or metadata stream is small, it indicates that the data stream or metadata stream needs to be replenished with new data blocks in a timely manner. Based on this, for the data stream, the number R of data blocks currently supporting writing can be monitored; if the number R is less than or equal to a set first quantity threshold, it indicates that the number of data blocks supporting data writing in the data stream is insufficient, and new data blocks need to be allocated in a timely manner. The first quantity threshold is greater than or equal to 1 and less than P. Accordingly, when the number R is less than or equal to the set first quantity threshold, a metadata service node can be requested in advance to allocate P data blocks for the data stream. The metadata service node can respond to this request by pre-allocating P third data blocks for the data stream. For a detailed implementation of the metadata service node pre-allocating P third data blocks for the data stream, please refer to the relevant content of the foregoing embodiments, which will not be repeated here. Accordingly, the P third data blocks and the data blocks that the data stream supports writing when R is less than or equal to the first quantity threshold can be determined as the first data blocks.

[0137] Similarly, for the metadata stream, the number S of data blocks currently supported for writing can be monitored. If the number S is less than or equal to a set second threshold, it indicates that the number of data blocks supporting data writing in the metadata stream is insufficient, and new data blocks need to be allocated in a timely manner. The second threshold is greater than or equal to 1 and less than Q. Accordingly, when the number S is less than or equal to the set second threshold, a request can be made to the metadata service node to allocate Q data blocks for the metadata stream in advance. The metadata service node can respond to this request by pre-allocating Q fourth data blocks for the metadata stream. For a detailed implementation of the metadata service node pre-allocating Q fourth data blocks for the data stream, please refer to the relevant content of the foregoing embodiments, which will not be repeated here. Accordingly, the Q fourth data blocks and the data blocks supported for writing in the metadata stream when S is less than or equal to the second threshold can be determined as the second data blocks.

[0138] For the first data block pre-allocated to the data stream, when performing a write operation on the target data, the target data can be sequentially attempted to be written to multiple first data blocks until the target data is successfully written. Specific writing methods can be found in the relevant content of the foregoing embodiments, and will not be repeated here.

[0139] Furthermore, for a successfully written target data block, the controller can write the target data block's identifier and the target data's offset address within the target data block to the second data block allocated to the metadata stream. This way, when reading data, the target data is read directly based on the target data block's identifier and offset address recorded in the second data block. Even if the control node detects a failed write to a data block, but the target data was actually written successfully, since there is no relevant record in the metadata stream's data blocks, it will not attempt to read data from the data block that the control node detected as having failed to write the target data but which was actually successfully written, ensuring that only one copy of the same data is read.

[0140] It should be noted that in the various embodiments of this application, the target data can be any data to be written. In some embodiments, the target data is the data first written to the target data block. For the data first written to the target data block (i.e., the target data), the identifier of the target data block and the offset address of the target data in the target data block can be written to the data block of the metadata stream. For subsequent data to be written, writing to the target data block can be attempted directly; if the data to be written to the target data block is successful, the identifier of the target data block and the offset address of the data to be written in the target data block do not need to be written to the data block of the metadata stream. This is mainly because when a data block is written for the first time, it is usually written in the order of logical blocks. This means that if the offset address of the first write to the data block is known, the offset addresses of other data written to the data block can be calculated based on this offset address of the first write to the data block. Therefore, only writing the offset address of the first successfully written data in the data block of the data stream to the data block of the metadata stream can save the storage resources of the data block of the metadata stream.

[0141] It is worth noting that the data to be written in the data stream (such as the aforementioned target data) can be user data or logs generated by the consensus protocol running in the control node. In the embodiment where the logs generated by the consensus protocol are stored in the storage nodes of a distributed storage system, the log system no longer depends on the local disk of the control node. Therefore, there are no special requirements for the type of control node; a computer-type server can be used as the control node, which helps improve the flexibility of control node deployment.

[0142] The consensus protocol generates logs that record the commands to be executed by the state machine in the management node. These commands determine the final state of the state machine, which provides read and write services. Therefore, if the management node restarts, it is necessary to restore the management node's state, specifically the logs generated by the management node's consensus protocol.

[0143] If the control node restarts after logs have been successfully written to the data stream, the successfully written logs must be recovered. For ease of description and distinction, the logs that have been successfully written to the data stream when the control node restarts are defined as the target logs. The target logs may or may not include the target data, depending on the timing of the control node restart and the successful writing of the target data. If the target data has been successfully written before the control node restarts, the target logs include the target data. If the target data has not yet been successfully written when the control node restarts, the target logs do not include the target data. Generally, the control node is the master node among multiple control nodes.

[0144] To recover the logs generated by the consensus protocol of the management node, the identifier of the data block where the target log was successfully written (defined as the fifth data block) and the offset address of the target log within the fifth data block can be obtained from the data blocks allocated to the metadata stream. Then, the target log is read based on the identifier of the fifth data block and the offset address of the target log within the fifth data block. Afterwards, the logs generated by the consensus protocol in the management node can be recovered based on the target log. Specifically, the target log can be used as the logs generated by the consensus protocol in the restarted management node, thereby recovering the logs generated by the consensus protocol in the management node. Since the data blocks of the metadata stream only store logs of successfully written data, recovering the consensus protocol generated by the management node based on the target log ensures that all successfully written logs are correctly recovered, maintaining the state consistency of the management node.

[0145] It should be noted that the execution subject of each step of the method provided in the above embodiments can be the same device, or the method can be executed by different devices. For example, the execution subject of steps 401 and 402 can be device A; or the execution subject of step 401 can be device A, and the execution subject of step 402 can be device B; and so on.

[0146] Furthermore, some processes described in the above embodiments and accompanying drawings include multiple operations that appear in a specific order. However, it should be clearly understood that these operations may not be executed in the order they appear herein, or they may be executed in parallel. The operation numbers, such as 401, 402, etc., are merely used to distinguish different operations and do not represent any execution order. In addition, these processes may include more or fewer operations, and these operations may be executed sequentially or in parallel.

[0147] Accordingly, embodiments of this application also provide a computer-readable storage medium storing computer instructions, which, when executed by one or more processors, cause one or more processors to perform the steps in the data writing methods provided in the foregoing embodiments.

[0148] Computer-readable storage media include volatile or non-volatile or a combination thereof, and may be removable or non-removable. Examples of computer-readable storage media include, but are not limited to, phase-change random access memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), flash memory or other memory technologies, compact disc read-only memory (CD-ROM), digital video disc (DVD) or other optical storage, magnetic tape, disk storage or other magnetic storage devices, or any other non-transfer medium.

[0149] This application also provides a computer program product, including a computer program that, when executed by one or more processors, causes the one or more processors to perform the steps in the data writing methods provided in the foregoing embodiments.

[0150] In the embodiments of this application, the specific implementation form of the computer program product is not limited. In some embodiments, the computer program product may be implemented as an application (APP), a mini-program, a computer-side client, a program module, a plug-in, an installation package, a software development kit (SDK), an image file of an optical disc (such as an ISO file), a plug-in, or software in the form of Software as a Service (SaaS), etc., but is not limited to these.

[0151] The computer program product should understand that each or a combination of the above-described method flow can be implemented by a computer program or instructions. Furthermore, these computer programs or instructions can be applied to the processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing device, enabling the processor of the general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing device to function as an apparatus for implementing the corresponding functions in the above-described method embodiments.

[0152] Figure 5 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 5 As shown, the electronic device includes a memory 50a and a processor 50b. The memory 50a is used to store computer programs and can be configured to store various other data to support operation on a computing platform. Examples of this data include instructions for any application or method operating on the electronic device, data structures, contact data, phone book data, messages, pictures, videos, etc.

[0153] Processor 50b is coupled to memory 50a and is used to execute computer programs to perform the steps in the data writing methods provided in the foregoing embodiments. Specific implementation details of each step can be found in the relevant descriptions of the foregoing embodiments, and will not be repeated here.

[0154] In some alternative implementations, such as Figure 5 As shown, the electronic device may also include optional components such as a communication component 50c, a power supply component 50d, a display component 50e, and an audio component 50f. Figure 5 The diagram only shows some components and does not mean that the electronic device must contain them. Figure 5 The inclusion of all components does not imply that an electronic device can only include... Figure 5 The components shown.

[0155] in addition, Figure 5 The components within the dashed box are optional, not mandatory, and their specific requirements depend on the form factor of the electronic device. The electronic device in this embodiment can be a desktop computer, laptop computer, mobile phone, or IoT device; it can also be a traditional server, cloud server, or server cluster, or other server equipment.

[0156] In this embodiment, the memory is used to store computer programs and can be configured to store various other data to support operation on its host device. The processor can execute the computer programs stored in the memory to implement corresponding control logic. The memory can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), electrically erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.

[0157] In the embodiments of this application, the processor can be any hardware processing device capable of executing the above-described method logic. Optionally, the processor can be a central processing unit (CPU), a graphics processing unit (GPU), or a microcontroller unit (MCU); it can also be a field-programmable gate array (FPGA), a programmable array logic (PAL), a general array logic (GAL), a complex programmable logic device (CPLD), or other programmable devices; or it can be an advanced RISC machine (ARM) or a system on chip (SoC), etc., but is not limited thereto.

[0158] In this embodiment, the communication component is configured to facilitate wired or wireless communication between its host device and other devices. The device hosting the communication component can access wireless networks based on communication standards, such as 2G or 3G, 4G, 5G, or combinations thereof. In one exemplary embodiment, the communication component receives broadcast signals or broadcast-related information from an external broadcast management system via a broadcast channel.

[0159] In embodiments of this application, the display component may include a liquid crystal display (LCD) and a touch panel (TP). If the display component includes a touch panel, the display component can be implemented as a touchscreen to receive input signals from a user. The touch panel includes one or more touch sensors to sense touches, swipes, and gestures on the touch panel. The touch sensors can sense not only the boundaries of touch or swipe actions but also the duration and pressure associated with the touch or swipe operation.

[0160] In this embodiment, a power supply component is configured to provide power to various components of the device in which it resides. The power supply component may include a power management system, one or more power supplies, and other components associated with generating, managing, and distributing power to the device in which the power supply component resides.

[0161] In embodiments of this application, the audio component can be configured to output and / or input audio signals. For example, the audio component includes a microphone (MIC), which is configured to receive external audio signals when the device containing the audio component is in an operating mode, such as call mode, recording mode, and voice recognition mode. The received audio signals can be further stored in memory or transmitted via a communication component. In some embodiments, the audio component also includes a speaker for outputting audio signals. For example, in devices with voice interaction capabilities, voice interaction with the user can be achieved through the audio component.

[0162] It should be noted that the terms "first" and "second" in this article are used to distinguish different messages, devices, modules, etc., and do not represent a chronological order, nor do they limit "first" and "second" to different types.

[0163] It should also be noted that the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus. Unless otherwise specified, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes the aforementioned element.

[0164] The above description is merely an embodiment of this application and is not intended to limit the scope of this application. Various modifications and variations can be made to this application by those skilled in the art. Any modifications, equivalent substitutions, improvements, etc., made within the spirit and principles of this application should be included within the scope of the claims of this application.

Claims

1. A distributed storage system, characterized in that, include: Control node and multiple storage nodes; The control node is equipped with a data stream and a metadata stream; the data stream is pre-allocated with multiple first data blocks; the metadata stream is pre-allocated with second data blocks; the first data blocks and the second data blocks are distributed across the multiple storage nodes; The control node is used to sequentially attempt to write the target data to be written into the plurality of first data blocks until the target data is successfully written. In addition, the identifier of the target data block and the first offset address of the target data in the target data block are written into the second data block, so as to read the target data according to the identifier of the target data block and the first offset address recorded in the second data block; wherein, the target data block is the data block in which the target data is successfully written.

2. A data writing method, applicable to the control node in a distributed storage system, characterized in that, The control node is equipped with a data stream and a metadata stream; the data stream is pre-allocated with multiple first data blocks; the metadata stream is pre-allocated with second data blocks; The first data block and the second data block are distributed across multiple storage nodes in the distributed storage system; The method includes: The target data to be written is sequentially attempted to be written into the plurality of first data blocks until the target data is successfully written. The identifier of the target data block and the first offset address of the target data in the target data block are written into the second data block, so as to read the target data according to the identifier of the target data block and the first offset address recorded in the second data block; wherein, the target data block is the data block in which the target data is successfully written.

3. The method according to claim 2, characterized in that, The distributed storage system includes a metadata service node; the method further includes: Before the target data is successfully written, the metadata service node is requested in advance to allocate a first number of data blocks for the data stream, and the metadata service node is requested in advance to allocate a second number of data blocks for the metadata stream; Based on a first number of third data blocks, determine the first data block; and based on a second number of fourth data blocks, determine the second data block; Wherein, the first number of third data blocks are data blocks allocated by the metadata service node to the data stream in response to the request of the management node; the second number of fourth data blocks are data blocks allocated by the metadata service node to the metadata stream in response to the request of the management node.

4. The method according to claim 3, characterized in that, The step of requesting the metadata service node to allocate a first number of data blocks for the data stream before the target data is successfully written, and requesting the metadata service node to allocate a second number of data blocks for the metadata stream, includes: After the data stream and the metadata stream are successfully created, an initialization request is sent to the metadata service node to initialize the data stream and the metadata stream. The initialization request requests the metadata service node in advance to allocate the first number of data blocks to the data stream and the second number of data blocks to the metadata stream. The step of determining the first data block based on a first number of third data blocks and determining the second data block based on a second number of fourth data blocks includes: The first number of third data blocks are determined as the first data block, and the second number of fourth data blocks are determined as the second data block.

5. The method according to claim 3, characterized in that, Before the target data is successfully written, the metadata service node is requested to allocate a first number of data blocks to the data stream, including: In response to a first switching event of the target data block to be written, the metadata service node is requested in advance to allocate the first number of data blocks to the data stream; the first number of third data blocks and the data blocks that the data stream can write when the first switching event occurs are determined as the first data blocks; or, Monitor the third number of data blocks that the data stream currently supports writing; if the third number is less than or equal to a set first number threshold, request the metadata service node in advance to allocate the first number of data blocks to the data stream; determine the first number of third data blocks and the data blocks that the data stream supports writing when the third number is less than or equal to the first number threshold as the first data blocks.

6. The method according to claim 5, characterized in that, Also includes: If the writing of the target data to any data block currently being attempted to be written fails, then it is determined that the first switching event has occurred. And / or, If the write latency of any data block is greater than or equal to the set first latency threshold, then the first switching event is determined to have occurred. And / or, If the amount of data stored in any of the data blocks is greater than or equal to a set first data volume threshold, then the first switching event is determined to have occurred.

7. The method according to claim 3, characterized in that, Before the target data is successfully written, the metadata service node is requested in advance to allocate a second number of data blocks for the metadata stream, including: In response to a second switching event of the data block to be written in the metadata stream, the metadata service node is requested in advance to allocate a second number of data blocks for the data stream; the second number of data blocks and the data blocks that the metadata stream supports writing when the second switching event occurs are determined as the second data blocks; or, Monitor the fourth number of data blocks that the metadata stream currently supports writing; if the fourth number is less than or equal to a set second number threshold, request the metadata service node in advance to allocate a second number of data blocks for the metadata stream; determine the second number of fourth data blocks and the data blocks that the data stream supports writing when the fourth number is less than or equal to the second number threshold as the second data blocks.

8. The method according to claim 7, characterized in that, Also includes: For any data block whose identifier and first offset address are currently being attempted to be written to, if the writing of the identifier and first offset address of the target data block to any data block fails, then it is determined that the second switching event has occurred. And / or, If the write latency of any data block is greater than or equal to the set second latency threshold, then the second switching event is determined to have occurred; And / or, If the amount of data stored in any of the data blocks is greater than or equal to the set second data amount threshold, then the second switching event is determined to have occurred.

9. The method according to any one of claims 2-8, characterized in that, The control node is the master node among multiple control nodes in the distributed storage system; the multiple control nodes run a consensus protocol; the target data is the log generated by the consensus protocol.

10. The method according to claim 9, characterized in that, Also includes: If the master node restarts while the target log is successfully written to the data stream, the identifier of the fifth data block in which the target log was successfully written and the second offset address of the target log in the fifth data block are obtained from the data blocks allocated to the metadata stream. The target log is read based on the identifier of the fifth data block and the second offset address; Based on the target log, recover the log generated by the consensus protocol.

11. The method according to any one of claims 2-8, characterized in that, Also includes: If the writing of the target data to any first data block fails, the state of the first data block is set to read-only.

12. The method according to any one of claims 2-8, characterized in that, The step of writing the identifier of the target data block and the offset address of the target data in the target data block into the second data block includes: The identifier of the target data block and the first offset address are sequentially attempted to be written into the second data block until the identifier of the target data block and the offset address are successfully written; and, Set the identifier of the target data block and the status of the second data block that failed to write the first offset address to read-only.

13. The method according to any one of claims 2-8, characterized in that, The target data is the data written to the target data block for the first time.

14. An electronic device, characterized in that, include: A memory and a processor; wherein the memory is used to store computer programs; The processor is coupled to the memory for executing the computer program to perform the steps of the method according to any one of claims 2-13.

15. A computer-readable storage medium storing computer instructions, characterized in that, When the computer instructions are executed by one or more processors, the one or more processors are caused to perform the steps of the method according to any one of claims 2-13.

16. A computer program product, characterized in that, Includes a computer program that, when executed by one or more processors, causes the one or more processors to perform the steps of the method according to any one of claims 2-13.