Data writing method, device and electronic device

By selecting the target storage block based on the running status of the storage node in the distributed storage system, the write failure rate is reduced, the stability and availability of the distributed cluster are improved, and the write failure and throughput caused by slave node downtime are solved. Jitter problem.

CN114489464BActive Publication Date: 2024-10-25BEIJING KINGSOFT CLOUD NETWORK TECH CO LTD
View PDF 9 Cites 0 Cited by

Patent Information

Application Number
CN202011167636.7
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-10-27
Publication Date
2024-10-25
Estimated Expiration
2040-10-27

AI Technical Summary

Technical Problem

In a distributed storage system, if the slave node goes down or becomes unavailable, the master node will retry write requests indefinitely, causing write failures or throughput jitters, affecting the stability and availability of the cluster.

Method used

After receiving the data write request, the target storage block is determined based on the running status of the storage node, the primary copy is set on the local node, the slave copy is on other nodes, and in an abnormal state, the most recently written data is selected from the alternative storage block. Or the storage block with the largest remaining amount is used as the target storage block to reduce the probability of writing failure.

Benefits of technology

It reduces the write failure rate, improves the stability and availability of distributed clusters, and avoids the generation of invalid writes and garbage data.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114489464B_ABST
    Figure CN114489464B_ABST
Patent Text Reader

Abstract

The present invention provides a data writing method, device and electronic device, the method comprising: receiving a data writing request for target data; determining a target storage block for writing the target data based on the running state of a storage node, wherein the master copy of the target storage block is set at a local node, and the slave copy of the target storage block is set at a storage node other than the local node; and writing the target data into the master copy and the slave copy of the target storage block. This method refers to the running state of each storage node when determining the storage block for writing data, so the probability of writing the target data into the slave copy of a storage node set in an abnormal state can be reduced, thereby reducing the probability of write failure and improving the stability and availability of the entire distributed cluster.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the technical field of data storage, and in particular to a data writing method, device and electronic equipment. Background Art

[0002] In the related art, the strong consistency write process of the distributed storage system is usually that the client sends a write request to the master node, the master node receives the write request, writes the data carried in the write request locally, and then sends the write request to all slave nodes; after the slave node writes successfully, it sends a write success message to the master node. If the master node does not receive a write success message returned by the slave node within the specified time, the master node will send a write request to the slave node again until the slave node returns a write success message; when all slave nodes have written successfully, the master node sends a write success message to the client; when the write request reaches the preset time and no write success message is received from all slave nodes, a write failure message is sent to the client.

[0003] In the above write process, if a slave node goes down or is unavailable, the master node will retry indefinitely after sending the write request to the node until the slave node recovers and the write is successful. This can easily lead to write request timeouts, write failures or throughput jitters, thus affecting the stability and availability of the entire distributed cluster. Summary of the invention

[0004] The object of the present invention is to provide a data writing method, device and electronic device to reduce writing failures and throughput jitter and improve the stability and availability of the entire distributed cluster.

[0005] In a first aspect, an embodiment of the present invention provides a data writing method, the method comprising: receiving a data write request for target data; determining a target storage block for writing the target data based on the operating status of a storage node; wherein a master copy of the target storage block is set at a local node; a slave copy of the target storage block is set at a storage node other than the local node; and writing the target data into the master copy and the slave copy of the target storage block.

[0006] In an optional embodiment, the operating status of the above-mentioned storage node includes a normal state and an abnormal state; the node information of the storage node in the abnormal state is stored in a preset state storage unit; the above-mentioned step of determining the target storage block for writing the target data based on the operating status of the storage node includes: determining the storage node in the abnormal state based on the node information stored in the state storage unit; determining the slave copy of the storage node in the abnormal state as an abnormal copy; determining, from the multiple storage blocks corresponding to the local node, the storage blocks other than the storage blocks corresponding to the abnormal copy as alternative storage blocks; and determining the target storage block for writing the target data from the alternative storage blocks.

[0007] In an optional embodiment, the above-mentioned method of determining the target storage block for writing target data from the alternative storage blocks includes one of the following: determining the alternative storage block whose last data writing time is closest to the current time as the target storage block; determining the alternative storage block with the largest remaining storage space from the alternative storage blocks as the target storage block; randomly determining an alternative storage block from the alternative storage blocks as the target storage block.

[0008] In an optional embodiment, after the above step of writing the target data into the master copy and the slave copy of the target storage block, the above method further includes: if a write failure message returned from the storage node where the slave copy is located is received, the storage node where the slave copy is located is determined as a storage node in an abnormal state, and the node information carried by the write failure message is extracted; wherein the node information includes an IP address and a port number; the extracted node information is saved to a preset status storage unit; wherein the status storage unit stores the node information of the storage node in the abnormal state.

[0009] In an optional embodiment, after the above-mentioned step of saving the extracted node information to a preset status storage unit, the method further includes: sending a data write request for the target data to the storage node that returns a write failure message; if the storage node that returns the write failure message returns a write success message, deleting the node information of the storage node from the status storage unit; if the storage node that returns the write failure message returns a write failure message, continuing to send a data write request for the target data to the storage node that returns the write failure message until the storage node returns a write success message.

[0010] In an optional implementation, the node information stored in the above-mentioned status storage unit is obtained in the following manner: detecting the operating status of the storage node through an active detector; if the storage node is detected to be in an abnormal state, saving the node information of the storage node to the status storage unit.

[0011] In an optional implementation, the node information stored in the above-mentioned status storage unit is obtained by: receiving node status information sent by a storage node; if the node status information indicates that the storage node is in an abnormal state, saving the node information of the storage node to the status storage unit.

[0012] In an optional embodiment, the step of determining the target storage block for writing the target data based on the operating status of the storage node includes: determining a slave copy set in a storage node in a normal state as a normal copy; determining the storage block corresponding to the normal copy as a candidate storage block from multiple storage blocks corresponding to the local node; and determining the target storage block for writing the target data from the candidate storage blocks.

[0013] In a second aspect, an embodiment of the present invention provides a data writing device, which includes: a request receiving module, used to receive a data writing request for target data; a storage block determination module, used to determine a target storage block for writing the target data based on the operating status of the storage node; wherein the master copy of the target storage block is set at a local node; the slave copy of the target storage block is set at a storage node other than the local node; and a data writing module, used to write the target data into the master copy and the slave copy of the target storage block.

[0014] In a third aspect, an embodiment of the present invention provides an electronic device, which includes a processor and a memory, wherein the memory stores machine executable instructions that can be executed by the processor, and the processor executes the machine executable instructions to implement the data writing method described in any of the aforementioned embodiments.

[0015] In a fourth aspect, an embodiment of the present invention provides a machine-readable storage medium, which stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the data writing method described in any one of the aforementioned implementations.

[0016] The embodiments of the present invention bring the following beneficial effects:

[0017] The present invention provides a data writing method, device and electronic device, which first receives a data writing request for target data; based on the operating status of a storage node, determines a target storage block for writing the target data, wherein the master copy of the target storage block is set at a local node, and the slave copy of the target storage block is set at a storage node other than the local node; and then writes the target data to the master copy and the slave copy of the target storage block. This method refers to the operating status of each storage node when determining the storage block to write data, so the probability of writing the target data to the slave copy of a storage node set in an abnormal state can be reduced, thereby reducing the probability of write failure and improving the stability and availability of the entire distributed cluster.

[0018] Other features and advantages of the present invention will be set forth in the following description, or some features and advantages may be inferred or unambiguously determined from the description, or may be learned by implementing the above-mentioned technology of the present invention.

[0019] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, preferred embodiments are specifically listed below and described in detail with reference to the attached drawings. BRIEF DESCRIPTION OF THE DRAWINGS

[0020] In order to more clearly illustrate the specific implementation methods of the present invention or the technical solutions in the prior art, the drawings required for use in the specific implementation methods or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are some implementation methods of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative work.

[0021] Figure 1 A flowchart of a data writing method provided by an embodiment of the present invention;

[0022] Figure 2 A flowchart of another data writing method provided by an embodiment of the present invention;

[0023] Figure 3 A flowchart of another data writing method provided by an embodiment of the present invention;

[0024] Figure 4 A schematic diagram of the structure of a data writing device provided by an embodiment of the present invention;

[0025] Figure 5 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION

[0026] In order to make the purpose, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below in conjunction with the drawings in the embodiments of the present invention. Obviously, the described embodiments are part of the embodiments of the present invention, not all of the embodiments. Generally, the components of the embodiments of the present invention described and shown in the drawings here can be arranged and designed in various different configurations.

[0027] Therefore, the following detailed description of the embodiments of the present invention provided in the accompanying drawings is not intended to limit the scope of the invention claimed for protection, but merely represents selected embodiments of the present invention. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0028] In the related art, the strong consistency write process of the distributed storage system is usually that the client sends a write request to the master node. When the master node receives the write request, it selects a target writable block from multiple saved writable blocks, and the writable block includes a master copy and two slave copies. The master copy is deployed on the master node, and the slave copies are deployed on two slave nodes respectively; after writing the data carried by the write request to the master copy of the target writable block, the write request is sent to the slave node where the slave copy of the target writable block is located; after the slave node receives the write request, it writes the data carried by the write request to the slave copy. After the write is successful, a write success message will be sent to the master node. If the write success message is not received from the slave node within the specified time, the master node will send a write request to the slave node again until the slave node returns a write success message; when all slave nodes are written successfully, the master node sends a write success message to the client; when the write request reaches a preset time and no write success message is received from all slave nodes, a write failure message is sent to the client; after receiving the write failure message, the client will retry the write process.

[0029] In the above writing process, if a slave node in the target writable block crashes or is unavailable, the master node will retry infinitely after sending the write request to the node until the slave node recovers and the writing is successful. Therefore, if a slave node crashes, it will affect the writing of the master node corresponding to all writable blocks contained in the slave node for a period of time. The synchronous retry of the master node will cause the client's write timeout, thereby causing write failure or throughput jitter; at the same time, it will also affect the stability and availability of the entire distributed cluster. Generally, the smaller the scale of the distributed cluster and the fewer the node devices, the greater the degree of impact, and the worse the availability and stability of the entire distributed cluster.

[0030] Based on the above problems, the embodiments of the present invention provide a data writing method, device and electronic device. The technology can be applied to various distributed storage systems, especially in the strong consistency writing scenario of distributed storage systems. To facilitate the understanding of this embodiment, a data writing method disclosed in the embodiment of the present invention is first described in detail. The method is applied to a node device in a distributed storage system, that is, a node device in a distributed cluster. The node device can be a server or other electronic device, for example, the master node mentioned above; Figure 1 As shown, the method comprises the following specific steps:

[0031] Step S102: receiving a data write request for target data.

[0032] The target data may be data that the user wants to write into the distributed storage system, and the data may be video data, audio data, image data, text data, etc. The data write request for the target data is usually sent by the user through a client, and the client may be a mobile phone, a tablet computer, a computer, etc.

[0033] Step S104, based on the running status of the storage node, determine the target storage block for writing the target data; wherein the primary copy of the target storage block is set in the local node; the secondary copy of the target storage block is set in the storage node other than the local node.

[0034] The local node is equivalent to the above-mentioned master node, and the master node can be provided with master copies of multiple storage blocks, that is, the master node can correspond to multiple storage blocks, each storage block includes a master copy and at least one slave copy (for example, it can be two slave copies or three slave copies, etc.), the master copy is set at the master node, and the slave copy is set at a storage node other than the master node, and the storage node can also be called a slave node. In the specific implementation, each slave copy in a storage block is set on a different storage node to achieve the purpose of distributed storage. Specifically, the above-mentioned storage block is equivalent to the writable block in the background technology, and the storage block can be understood as a data structure containing the correspondence between the master copy and the slave copy and the setting data.

[0035] The operation status of the storage node includes a normal state and an abnormal state; wherein the abnormal state may be an operation status when the storage node is down or unavailable. The master node that receives the data write request for the target data can sense the operation status of each storage node, and thus can determine the target storage block from the multiple storage blocks corresponding to the master node that is sensed and in a normal state from the storage node where the replica is located.

[0036] In some embodiments, the master node may also record the node information of a storage node in a normal state, or record the node information of a storage node in an abnormal state. When determining the target storage block, if the master node records the node information of a storage node in a normal state, the target storage block is determined to be the storage block where all the storage nodes recorded from the replica are in a normal state; if the master node records the node information of a storage node in an abnormal state, the target storage block is determined to be the storage block other than the storage block where the storage node recorded from the replica is in an abnormal state.

[0037] In the specific implementation, if multiple target storage blocks are determined, you can select any target storage block as the final target storage block, or you can select the target storage block with the largest remaining storage space as the final target storage block, or you can select the target storage block used for writing data last time as the final target storage block, etc.

[0038] Step S106, writing the target data into the primary copy and the secondary copy of the target storage block.

[0039] When the master node determines the target storage block, the target data is written to the master copy of the target storage block. After the write is successful, a data write request for the target data is sent to the storage node where the slave copy of the target storage block is located, so as to write the target data to the slave copy of the target storage block in the storage node, thereby realizing synchronous writing of the target data.

[0040] A data writing method provided by an embodiment of the present invention first receives a data writing request for target data; based on the operating status of a storage node, determines a target storage block for writing the target data, wherein the primary copy of the target storage block is set at a local node, and the secondary copy of the target storage block is set at a storage node other than the local node; and then writes the target data to the primary copy and the secondary copy of the target storage block. This method refers to the operating status of each storage node when determining the storage block to write data, so that the probability of writing the target data to the secondary copy of a storage node set in an abnormal state can be reduced, thereby reducing the probability of write failure and improving the stability and availability of the entire distributed cluster.

[0041] The embodiment of the present invention also provides another data writing method, which is implemented on the basis of the above embodiment method; the method focuses on describing the specific process of determining the target storage block for writing the target data based on the operating status of the storage node (implemented by the following steps S204-S210); Figure 2 As shown, the method comprises the following steps:

[0042] Step S202: receiving a data write request for target data.

[0043] Step S204, determining a storage node in an abnormal state based on the node information stored in a preset state storage unit; wherein the state storage unit stores the node information of the storage node in an abnormal state.

[0044] The operation status of the above storage node includes a normal state and an abnormal state. A state storage unit is set in the master node that receives the data write request of the target data. The state storage unit is used to save the node information of the storage node in the abnormal state. The function of the state storage unit is equivalent to a blacklist. The abnormal state of the storage node is usually caused by the downtime or unavailability of the storage node. The node information of the storage node includes an IP (Internet Protocol) address and a port number; wherein the IP address is usually a unified address format provided by the IP protocol, which assigns a logical address to each network and each host on the Internet to shield the difference in physical addresses; the role of the above port number is similar to the house number. The client can find the corresponding server (for example, storage node) through the IP address, but the server has many ports, and each application corresponds to a port number. Through the port number similar to the house number, the client can really access the server. In order to distinguish the ports, each port is numbered to form a port number.

[0045] Step S206: determine the slave replica set on the storage node in the abnormal state as an abnormal replica.

[0046] Step S208: From the multiple storage blocks corresponding to the local node, determine the storage blocks other than the storage blocks corresponding to the abnormal copy as candidate storage blocks.

[0047] The above-mentioned local node is equivalent to the master node that receives the data write request for the target data. The local node can be provided with multiple master copies of storage blocks, that is, the local node corresponds to multiple storage blocks. The local node can determine the storage nodes in an abnormal state based on the node information stored in the state storage unit; then the slave copies set in these storage nodes in an abnormal state are determined as abnormal slave copies, and then, among the multiple storage blocks corresponding to the local node, the storage blocks other than the storage blocks corresponding to these abnormal copies are determined as candidate storage blocks. It can also be understood that when determining the target storage block to write the target data, it is first necessary to check whether the node information of the storage node where the slave copy of the storage block to be selected is located is stored in the state storage unit. If it is stored in the state storage unit, the storage block to be selected is ignored.

[0048] Step S210: determining a target storage block for writing target data from candidate storage blocks.

[0049] In specific implementation, the target storage block may be determined from the candidate storage blocks by any one of the following methods 1 to 3:

[0050] Method 1: among the candidate storage blocks, the candidate storage block whose last data writing time is closest to the current time is determined as the target storage block.

[0051] Method 2: From the candidate storage blocks, the candidate storage block with the largest remaining storage space is determined as the target storage block. The candidate storage block with the largest remaining storage space can be understood as the candidate storage block with the largest remaining storage space of the primary copy or the candidate storage block with the largest remaining storage space of the secondary copy.

[0052] Method three: randomly determine a candidate storage block from the candidate storage blocks as the target storage block.

[0053] Step S212, writing the target data into the primary copy and the secondary copy of the target storage block.

[0054] In the specific implementation, the target data is written to the master copy of the determined target storage block. After the writing is successful, a data write request for the target data is sent to the storage node where the slave copy of the target storage block is located, so as to write the target data to the slave copy of the target data block in the storage node. In the process of the storage node writing the target data to the slave copy, the write may fail because the storage node is currently in an abnormal state, and the node information of the storage node in the abnormal state is not saved in the state storage unit. Therefore, the node information of the storage node in the abnormal state can be saved to the state storage unit through the following steps 10-11:

[0055] Step 10: If a write failure message returned from the storage node where the replica is located is received, the storage node where the replica is located is determined as a storage node in an abnormal state, and the node information carried by the write failure message is extracted.

[0056] When the storage node that receives the data write request for the target data is in an abnormal state (the storage node is down or unavailable), the storage node returns a write failure message to the local node that sent the data write request, and the write failure message carries the node information of the storage node. In a specific implementation, the write failure message can be a recognizable RPC (Remote Procedure Call) error code.

[0057] Step 11: Save the extracted node information to a preset state storage unit.

[0058] In a specific implementation, if the storage node corresponding to the node information stored in the state storage unit is restored to a normal state, the node information of the storage node restored to a normal state can be deleted from the state storage unit. The specific process is implemented by the following steps 20-23:

[0059] Step 20: If a write failure message returned from the storage node where the replica is located is received, the node information of the storage node where the replica is located and carried in the write failure message is saved to the state storage unit.

[0060] Step 21: Send a data write request for the target data again to the storage node that returns the write failure message.

[0061] Step 22: If the storage node that returns the write failure message returns a write success message, the node information of the storage node is deleted from the state storage unit.

[0062] Step 23: If the storage node that returns the write failure message returns the write failure message, continue to send the data write request of the target data to the storage node that returns the write failure message until the storage node returns the write success message.

[0063] Based on the above steps 10-23, the local node can quickly identify the storage node that failed to synchronize after a synchronization task fails (that is, the local node sends a data write request for the target data to the storage node where the slave copy of the target storage block is located, and if the storage node returns a write failure message), and record the node information of the storage node and save it to the state storage unit; in the subsequent write process (that is, the local node retries to send a data write request to the storage node), the node information of the storage node can be deleted from the state storage unit after the storage node is restored, thereby reducing the impact of a single storage node or process downtime in a small-scale distributed cluster on the write failure rate of the entire distributed cluster. At the same time, the local node can effectively avoid invalid writes to the storage node that has already been down, and to a certain extent, it can also reduce the garbage data of the distributed cluster.

[0064] In some embodiments, the node information stored in the state storage unit may also be obtained through the following steps 30-31:

[0065] Step 30: Detect the operating status of the storage node through an active detector.

[0066] The above-mentioned active detector is deployed on a local node. The active detector may be a node operation status monitoring system. The active detector may actively detect the operation status of each storage node.

[0067] Step 31: If it is detected that the storage node is in an abnormal state, the node information of the storage node is saved to a state storage unit.

[0068] When the active detector detects that a storage node is in an abnormal state (the abnormal state may be the running state of a storage node that is down or has a down process), the node information of the storage node is saved in the state storage unit. If the active detector detects that the storage node corresponding to the node information saved in the state storage unit is restored, that is, in a normal state, the node information of the storage node is deleted from the state storage unit to ensure that the state storage unit only stores the node information of the storage node in the abnormal state.

[0069] In some embodiments, the node information stored in the state storage unit may also be obtained through the following steps 40-41:

[0070] Step 40: Receive node status information sent by the storage node.

[0071] A heartbeat sending process and a heartbeat receiving process are deployed on each master node and storage node in the distributed cluster to enable each node to perceive each other's operating status. For example, the storage node can send node status information (equivalent to heartbeat information) to the master node through the heartbeat sending process, and the master node receives the node status information through the heartbeat receiving process, and determines the operating status of the storage node through the node status information.

[0072] Step 41: If the node status information indicates that the storage node is in an abnormal state, the node information of the storage node is saved to a status storage unit.

[0073] If the storage node corresponding to the node information stored in the status storage unit is restored, that is, the node status information indicates that the storage node is in a normal state, the node information of the storage node is deleted from the status storage unit.

[0074] The above data writing method first receives a data writing request for target data; then determines the storage node in abnormal state based on the node information of the storage node in abnormal state stored in the state storage unit; then determines the slave replica set in the storage node in abnormal state as an abnormal replica; then determines the storage blocks other than the storage blocks corresponding to the abnormal replica from the multiple storage blocks corresponding to the local node as candidate storage blocks; determines the target storage block for writing the target data from the candidate storage blocks; then writes the target data to the master replica and the slave replica of the target storage block. In this method, a state storage unit is added to the local node to record the node information of the storage node in abnormal state, so that when the local node determines the target storage block for writing data, the storage block recorded in the state storage unit of the storage node where the slave replica is located is excluded, thereby improving the success rate of the data writing process; at the same time, it also reduces the invalid writing of the master node, and reduces the unavailable data of the distributed cluster to a certain extent.

[0075] The embodiment of the present invention also provides another data writing method, which is implemented on the basis of the above embodiment method; the method focuses on describing the specific process of determining the target storage block for writing the target data based on the operating status of the storage node (implemented by the following steps S304-S308); Figure 3 As shown, the method comprises the following steps:

[0076] Step S302: receiving a data write request for target data.

[0077] Step S304: determine the slave replica set on the storage node in a normal state as a normal replica.

[0078] Step S306: From the multiple storage blocks corresponding to the local node, determine the storage block corresponding to the normal copy as the storage block to be selected.

[0079] Step S308: determining a target storage block for writing target data from the storage blocks to be selected.

[0080] The local node mentioned above corresponds to multiple storage blocks, the master copy of each storage block is set in the local node, and the slave copies are set in storage nodes other than the local node. A whitelist can be set in the local node to save the node information of the storage nodes in a normal state. When determining the target storage block, the storage block in which all the slave copies are set in the storage node corresponding to the node information saved in the whitelist can be selected as the target storage block, thereby ensuring that the storage nodes where the slave copies of the target storage block are located are all in a normal state.

[0081] In specific implementation, the node information in the above whitelist can be obtained by one or more of the following methods:

[0082] Method 1: If a write success message is received from the storage node where the replica is located, the storage node where the replica is located is determined to be a storage node in a normal state, and the node information carried by the write success message is extracted; the node information is written into the whitelist.

[0083] Method 2: Use an active detector to detect the operating status of the storage node; if the storage node is detected to be in a normal state, save the node information of the storage node to a whitelist.

[0084] Method three, receiving the node status information sent by the storage node; if the node status information indicates that the storage node is in a normal state, saving the node information of the storage node to the whitelist.

[0085] In a specific implementation, the target storage block for writing the target data may be determined from the candidate storage blocks by any one of the following methods 1 to 3:

[0086] Method 1: among the candidate storage blocks, the candidate storage block whose last data writing time is closest to the current time is determined as the target storage block.

[0087] Method 2: From the candidate storage blocks, the candidate storage block with the largest remaining storage space is determined as the target storage block. The candidate storage block with the largest remaining storage space can be understood as the candidate storage block with the largest remaining storage space of the primary copy or the candidate storage block with the largest remaining storage space of the secondary copy.

[0088] Method three: randomly determine a candidate storage block from the candidate storage blocks as the target storage block.

[0089] Step S310, writing the target data into the primary copy and the secondary copy of the target storage block.

[0090] The above data writing method can determine the target storage block for writing the target data according to the operating status of the storage node where the slave copy of the storage block is located, ensuring that the target data is written to the storage node set in a normal state, thereby reducing the phenomenon of write failures and improving the stability and availability of the entire distributed cluster.

[0091] Corresponding to the above method embodiment, the embodiment of the present invention provides a data writing device, such as Figure 4 As shown, the device comprises:

[0092] The request receiving module 40 is used to receive a data writing request for target data.

[0093] The storage block determination module 41 is used to determine the target storage block for writing target data based on the operating status of the storage node; wherein the primary copy of the target storage block is set in the local node; and the secondary copy of the target storage block is set in the storage node other than the local node.

[0094] The data writing module 42 is used to write the target data into the primary copy and the secondary copy of the target storage block.

[0095] The above-mentioned data writing device first receives a data writing request for target data; based on the operating status of the storage node, determines the target storage block for writing the target data, the master copy of the target storage block is set in the local node, and the slave copy of the target storage block is set in the storage node other than the local node; then writes the target data to the master copy and the slave copy of the target storage block. This method refers to the operating status of each storage node when determining the storage block to write data, so it can reduce the probability of writing the target data to the slave copy of the storage node set in an abnormal state, thereby reducing the probability of write failure and improving the stability and availability of the entire distributed cluster.

[0096] Specifically, the operating status of the above-mentioned storage node includes a normal state and an abnormal state; the node information of the storage node in the abnormal state is stored in a preset state storage unit; the above-mentioned storage block determination module 41 is used to: determine the storage node in the abnormal state based on the node information stored in the state storage unit; determine the slave copy set in the storage node in the abnormal state as an abnormal copy; from the multiple storage blocks corresponding to the local node, determine the storage blocks other than the storage blocks corresponding to the abnormal copy as alternative storage blocks; from the alternative storage blocks, determine the target storage block for writing the target data.

[0097] In a specific implementation, the storage block determination module 41 determines the target storage block for writing target data from the candidate storage blocks, including one of the following: determining the candidate storage block whose last data writing time is closest to the current time as the target storage block; or, from the candidate storage blocks, determining the candidate storage block with the largest remaining storage space as the target storage block; or, randomly determining an alternative storage block from the alternative storage blocks as the target storage block.

[0098] Furthermore, the above-mentioned device also includes a first information saving module, which is used to: after writing the target data into the master copy and the slave copy of the target storage block, if a write failure message is received from the storage node where the slave copy is located, the storage node where the slave copy is located is determined as a storage node in an abnormal state, and the node information carried by the write failure message is extracted; wherein the node information includes an IP address and a port number; the extracted node information is saved to a preset status storage unit; wherein the status storage unit stores the node information of the storage node in the abnormal state.

[0099] Furthermore, the above-mentioned device also includes a node information deletion module, which is used to: after saving the extracted node information to a preset status storage unit, send a data write request for the target data to the storage node that returns a write failure message; if the storage node that returns the write failure message returns a write success message, delete the node information of the storage node from the status storage unit; if the storage node that returns the write failure message returns a write failure message, continue to execute the data write request for the target data to the storage node that returns the write failure message until the storage node returns a write success message.

[0100] Furthermore, the above device also includes a second information storage module, which is used to: detect the operating status of the storage node through an active detector; if the storage node is detected to be in an abnormal state, save the node information of the storage node to the state storage unit.

[0101] Furthermore, the above-mentioned device also includes a third information saving module, which is used to: receive node status information sent by the storage node; if the node status information indicates that the storage node is in an abnormal state, save the node information of the storage node to the state storage unit.

[0102] In a specific implementation, the above-mentioned storage block determination module 41 is also used to: determine the slave copy set in the storage node in a normal state as a normal copy; determine the storage block corresponding to the normal copy as the storage block to be selected from the multiple storage blocks corresponding to the local node; and determine the target storage block for writing the target data from the storage blocks to be selected.

[0103] The data writing device provided in the embodiment of the present invention has the same implementation principle and technical effects as those of the aforementioned method embodiment. For the sake of brief description, for matters not mentioned in the device embodiment, reference may be made to the corresponding contents in the aforementioned method embodiment.

[0104] The embodiment of the present invention further provides an electronic device, see Figure 5 As shown, the electronic device includes a processor 101 and a memory 100. The memory 100 stores machine executable instructions that can be executed by the processor 101. The processor 101 executes the machine executable instructions to implement the above data writing method.

[0105] Further, Figure 5 The electronic device shown further includes a bus 102 and a communication interface 103 , and the processor 101 , the communication interface 103 and the memory 100 are connected via the bus 102 .

[0106] The memory 100 may include a high-speed random access memory (RAM), and may also include a non-volatile memory, such as at least one disk storage. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 103 (which may be wired or wireless), and the Internet, wide area network, local area network, metropolitan area network, etc. may be used. The bus 102 may be an ISA bus, a PCI bus, or an EISA bus, etc. The bus may be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 5 Only one bidirectional arrow is used in the diagram, but this does not mean that there is only one bus or only one type of bus.

[0107] The processor 101 may be an integrated circuit chip with signal processing capabilities. In the implementation process, each step of the above method can be completed by the hardware integrated logic circuit or software instructions in the processor 101. The above processor 101 can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. The methods, steps and logic block diagrams disclosed in the embodiments of the present invention can be implemented or executed. The general processor can be a microprocessor or the processor can also be any conventional processor, etc. The steps of the method disclosed in conjunction with the embodiments of the present invention can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module may be located in a storage medium mature in the art, such as a random access memory, a flash memory, a read-only memory, a programmable read-only memory, or an electrically erasable programmable memory, a register, etc. The storage medium is located in the memory 100, and the processor 101 reads the information in the memory 100 and completes the steps of the method of the above embodiment in combination with its hardware.

[0108] An embodiment of the present invention also provides a machine-readable storage medium, which stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the above-mentioned data writing method. The specific implementation can be found in the method embodiment, which will not be repeated here.

[0109] The computer program product of the data writing method, device and electronic device provided in the embodiments of the present invention includes a computer-readable storage medium storing program code, and the instructions included in the program code can be used to execute the method described in the previous method embodiment. The specific implementation can be referred to the method embodiment, which will not be repeated here. If the function is implemented in the form of a software function unit and sold or used as an independent product, it can be stored in a computer-readable storage medium.

[0110] Based on this understanding, the technical solution of the present invention, or the part that contributes to the prior art, or the part of the technical solution, can be embodied in the form of a software product, which is stored in a storage medium and includes several instructions for enabling a computer device (which can be a personal computer, electronic device, or network device, etc.) to perform all or part of the steps of the method described in each embodiment of the present invention. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, Read-Only Memory), random access memory (RAM, Random Access Memory), disk or optical disk, etc., various media that can store program codes.

[0111] Finally, it should be noted that the above-described embodiments are only specific implementations of the present invention, which are used to illustrate the technical solutions of the present invention, rather than to limit them. The protection scope of the present invention is not limited thereto. Although the present invention is described in detail with reference to the above-described embodiments, ordinary technicians in the field should understand that any technician familiar with the technical field can still modify the technical solutions recorded in the above-described embodiments within the technical scope disclosed by the present invention, or can easily think of changes, or make equivalent replacements for some of the technical features therein; and these modifications, changes or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should be included in the protection scope of the present invention. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.

Claims

1. A data writing method, characterized in that: The method comprises: receiving a data write request for target data; Based on the running state of the storage node, determine the target storage block for writing the target data; wherein the master copy of the target storage block is set in the local node; the slave copy of the target storage block is set in the storage node other than the local node; the target storage block is a data structure including the correspondence between the master copy and the slave copy and setting data; Writing the target data into the master copy and the slave copy of the target storage block; The operating status of the storage node includes a normal status and an abnormal status; the node information of the storage node in the abnormal status is stored in a preset status storage unit; the step of determining the target storage block for writing the target data based on the operating status of the storage node includes: determining the storage node in the abnormal status based on the node information stored in the status storage unit; determining the slave copy of the storage node in the abnormal status as an abnormal copy; determining, from the multiple storage blocks corresponding to the local node, storage blocks other than the storage blocks corresponding to the abnormal copy as alternative storage blocks; and determining, from the alternative storage blocks, the target storage block for writing the target data.

2. The method according to claim 1, characterized in that The method of determining the target storage block for writing the target data from the candidate storage blocks includes one of the following: Determine, among the candidate storage blocks, a candidate storage block whose last data writing time is closest to the current time as the target storage block; From the candidate storage blocks, determining the candidate storage block with the largest remaining storage space as the target storage block; From the candidate storage blocks, a candidate storage block is randomly determined as the target storage block.

3. The method according to claim 1, characterized in that: After the step of writing the target data into the master copy and the slave copy of the target storage block, the method further comprises: If a write failure message returned by the storage node where the slave replica is located is received, the storage node where the slave replica is located is determined as a storage node in an abnormal state, and the node information carried by the write failure message is extracted; wherein the node information includes an IP address and a port number; The extracted node information is saved in a preset state storage unit; wherein the state storage unit stores the node information of the storage node in an abnormal state.

4. The method according to claim 3, characterized in that After the step of saving the extracted node information to a preset state storage unit, the method further includes: Sending a data write request for the target data to the storage node that returns a write failure message; If the storage node that returns the write failure message returns a write success message, deleting the node information of the storage node from the state storage unit; If the storage node that returns the write failure message returns the write failure message, continue to execute the data write request for the target data to the storage node that returns the write failure message until the storage node returns the write success message.

5. The method according to claim 1, characterized in that The node information stored in the state storage unit is obtained in the following manner: Detecting the operating status of the storage node through an active detector; If it is detected that the storage node is in an abnormal state, the node information of the storage node is saved to the state storage unit.

6. The method according to claim 1, characterized in that The node information stored in the state storage unit is obtained in the following manner: Receiving node status information sent by the storage node; If the node status information indicates that the storage node is in an abnormal state, the node information of the storage node is saved to the status storage unit.

7. The method according to claim 1, characterized in that The operation state of the storage node includes a normal state and an abnormal state; the step of determining the target storage block for writing the target data based on the operation state of the storage node includes: Determine the slave replica set on the storage node in the normal state as a normal replica; Determine, from the multiple storage blocks corresponding to the local node, a storage block corresponding to the normal copy as a storage block to be selected; A target storage block for writing the target data is determined from the candidate storage blocks.

8. A data writing device, characterized in that: The device comprises: A request receiving module, used for receiving a data writing request for target data; A storage block determination module, used to determine a target storage block for writing the target data based on the running state of the storage node; wherein the master copy of the target storage block is set in a local node; the slave copy of the target storage block is set in a storage node other than the local node; the target storage block is a data structure including a correspondence between the master copy and the slave copy and setting data; A data writing module, used for writing the target data into the master copy and the slave copy of the target storage block; The operating status of the storage node includes a normal state and an abnormal state; the node information of the storage node in the abnormal state is stored in a preset state storage unit; the storage block determination module is also used to: determine the storage node in the abnormal state based on the node information stored in the state storage unit; determine the slave copy of the storage node in the abnormal state as an abnormal copy; from the multiple storage blocks corresponding to the local node, determine the storage blocks other than the storage blocks corresponding to the abnormal copy as alternative storage blocks; and determine the target storage block for writing the target data from the alternative storage blocks.

9. An electronic device, characterized in that: The electronic device includes a processor and a memory, the memory stores machine executable instructions that can be executed by the processor, and the processor executes the machine executable instructions to implement the data writing method according to any one of claims 1 to 7.

10. A machine-readable storage medium, characterized in that: The machine-readable storage medium stores machine-executable instructions. When the machine-executable instructions are called and executed by a processor, the machine-executable instructions prompt the processor to implement the data writing method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Detection of slow node in distributed storage system

    CN106878388A

  • Data writing and data restoration method and device, electronic device and storage medium

    CN108572793A

  • Data storage method and device

    CN110337633A

  • Multi-region data processing method and device of distributed storage system and electronic equipment

    CN111104069A

  • Data reading method and device, storage equipment and machine readable storage medium

    CN111124740A