When we upgraded our hadoop cluster from hadoop 2.6.0 to hadoop 3.2.2, we got failed volume on a lot of datanodes, which cause some missing blocks at that time. Although later on we recovered all the missing blocks by symlinking the path (dfs/dn/current) on the failed volume to a new directory and copying all the data to the new directory, we missed our SLA and it delayed our upgrading process on our production cluster for several hours.
When this issue happened, we saw a lot of this exceptions happened before the volumed failed on the datanode:
[DataXceiver for client at /XX.XX.XX.XX:XXX [Receiving block BP-XXXXXX-XX.XX.XX.XX-XXXXXX:blk_XXXXX_XXXXXXX]] datanode.DataNode (BlockReceiver.java:<init>(289)) - IOException in BlockReceiver constructor :Possible disk error: Failed to create /XXXXXXX/dfs/dn/current/BP-XXXXXX-XX.XX.XX.XX-XXXXXXXXX/tmp/blk_XXXXXX. Cause is
java.io.IOException: No space left on device
at java.io.UnixFileSystem.createFileExclusively(Native Method)
We found this issue happened due to the following two reasons:
First the upgrade process added some extra disk storage on the each disk volume of the data node:
BlockPoolSliceStorage.doUpgrade (https://github.com/apache/hadoop/blob/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/BlockPoolSliceStorage.java#L445) is the main upgrade function in the datanode, it will add some extra storage. The extra storage added is all new directories created in /current/<bpid>/current, although all block data file and block meta data file are hard-linked with /current/<bpid>/previous after upgrade. Since there will be a lot of new directories created, this will use some disk space on each disk volume.
Second there is a potential bug when picking a disk volume to write a new block file(replica). By default, Hadoop uses RoundRobinVolumeChoosingPolicy, The code to select a disk will check whether the available space on the selected disk is more than the size bytes of block file to store (https://github.com/apache/hadoop/blob/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/RoundRobinVolumeChoosingPolicy.java#L86) But when creating a new block, there will be two files created: one is the block file blk_XXXX, the other is block metadata file blk_XXXX_XXXX.meta, this is the code when finalizing a block, both block file size and meta data file size will be updated: https://github.com/apache/hadoop/blob/trunk/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/fsdataset/impl/BlockPoolSlice.java#L391 the current code only considers the size of block file and doesn't consider the size of block metadata file, when choosing a disk in RoundRobinVolumeChoosingPolicy. There can be a lot of on-going blocks received at the same time, the default maximum number of DataXceiver threads is 4096. This will underestimate the total size needed to write a block, which will potentially cause the above disk full error(No space left on device).
Since the size of the block metadata file is not fixed, I suggest to add a configuration(
) to safeguard the disk space when choosing a volume to write a new block data in RoundRobinVolumeChoosingPolicy.