All Products
Search
Document Center

E-MapReduce:File close exception when writing to HDFS

Last Updated:Mar 26, 2026

When writing data to Hadoop Distributed File System (HDFS), you may encounter a file-close failure caused by DataNode overload. This topic explains how to diagnose the root cause and resolve it.

Error message

java.io.IOException: Unable to close file because the last block xxx:xxx does not have enough number of replicas.

Cause

Heavy write load on a DataNode prevents data blocks from being reported in time. When HDFS cannot confirm that a block has enough replicas, it fails to close the file.

Diagnose and resolve

Work through the following checks in order. Stop when you find the cause.

Step 1: Adjust the retry parameter

Check the value of dfs.client.block.write.locateFollowingBlock.retries on the hdfs-site.xml tab. This parameter controls how many times the client retries closing a file after writing data blocks.

Setting Value
Default 5 retries (within 30 seconds)
Recommended 8 retries (within 2 minutes)

Set this parameter to 8 for clusters under moderate load. For clusters with consistently high load, increase it further.

Increasing this value extends the wait time before the system closes a file when a node is busy. Data writing is not affected.

Step 2: Check the DataNode-to-task-node ratio

If your cluster has only a small number of DataNodes and a large number of task nodes, and a large number of jobs are submitted concurrently, a large number of JAR files need to be uploaded, which may cause heavy load on the DataNodes.

To resolve this:

  • Increase the value of dfs.client.block.write.locateFollowingBlock.retries.

  • Add more core nodes (DataNodes) to distribute the write load.

Step 3: Check for jobs that generate many small files

Certain workloads create a disproportionate number of small files on HDFS. Flink checkpoints are a common example—each checkpoint creates and deletes a large number of small files, which places heavy load on DataNodes.

If this is the cause, use one of the following approaches:

  • Run Flink on an independent cluster with its own HDFS, so checkpoint activity does not affect the shared cluster.

  • Use Object Storage Service (OSS) or OSS-HDFS Connector for Flink checkpoints instead of HDFS.