Troubleshooting HDFS: Common Errors, Causes and Fixes
A Repeatable Diagnosis Flow
- What exactly fails? Copy the full error message and time
- Scope: one user, one node, one path, or everything?
- Recent changes: config, patch, upgrade, network, new job?
- Check health:
hdfs dfsadmin -report,hdfs fsck /, NameNode UI - Read logs of the NameNode and the affected DataNode around that time
- Fix the cause, not the symptom, and write down what you did
Quick Commands
bash
hdfs dfsadmin -report | head -25
hdfs dfsadmin -safemode get
hdfs haadmin -getAllServiceState
hdfs fsck / | tail -20
hdfs fsck /path -files -blocks -locations
hdfs getconf -confKey dfs.replication
tail -200 /var/log/hadoop/hadoop-hdfs-namenode-$(hostname).log | grep -E "ERROR|WARN|Exception"
Problem 1: NameNode Will Not Start
| Log message | Cause | Fix |
|---|---|---|
java.net.BindException: Address already in use | Old process or other service on the port | ss -ltnp | grep 8020, stop the process |
Directory /data/nn1 is in an inconsistent state: storage directory does not exist or is not accessible | Mount missing or wrong owner | Mount the disk, chown hdfs, check permissions |
File system image contains an old layout version / Upgrade required | Binary version newer than metadata | Start with the proper upgrade options |
Java heap space / OutOfMemoryError | Heap too small for namespace | Increase -Xmx, check block count growth |
Edit log corruption / Encountered exception loading fsimage | Corrupt metadata | Copy the directory, use the other name.dir or the standby, else -recover |
Cannot lock storage ... The directory is already locked | A previous NameNode process is still running | Kill it or remove in_use.lock only if no process exists |
Problem 2: Stuck in Safe Mode
bash
hdfs dfsadmin -safemode get
grep -i "safe mode" /var/log/hadoop/hadoop-hdfs-namenode-*.log | tail -5
# "The reported blocks 8200 needs additional 800 blocks to reach the threshold 0.9990"
hdfs dfsadmin -report | grep -E "Live datanodes|Dead datanodes"
- Start missing DataNodes, check their logs and networking
- If many blocks are truly lost, list them with
fsck -list-corruptfileblocksbefore deciding - Only after you accept the loss:
hdfs dfsadmin -safemode leave, then clean up withfsck -deleteor restore from backup
Problem 3: DataNode Does Not Register or Dies
| Log message | Cause | Fix |
|---|---|---|
Incompatible clusterIDs | DataNode directories from another (or reformatted) cluster | If the node was reused: clear the data dir after confirming data is not needed, or fix the NameNode ID mismatch |
DiskErrorException: Too many failed volumes | More failed disks than failed.volumes.tolerated | Replace the disks, reconfigure |
java.io.IOException: Too many open files | ulimit too low | Raise nofile, restart |
Cannot connect to NameNode / Connection refused | Firewall, wrong fs.defaultFS, NameNode down | Test with nc -vz nn1 8020, fix configs |
Datanode denied communication with namenode because hostname cannot be resolved | Reverse DNS missing | Fix DNS or dfs.namenode.datanode.registration.ip-hostname-check=false (temporary) |
Unable to get SASL... / Kerberos error | Principal or keytab problem | See Kerberos lesson |
Problem 4: Missing and Corrupt Blocks
bash
hdfs fsck / -list-corruptfileblocks
hdfs fsck /data/sales/orders/part-0001 -files -blocks -locations
# find the DataNodes that should have the block and check their logs and disks
hdfs debug verifyMeta -meta /data/d1/dn/current/BP-.../current/finalized/subdir0/blk_1073741825_1001.meta -block .../blk_1073741825
# options when no good replica exists
hdfs dfs -rm /path/file # delete if it can be reloaded from source
hdfs fsck /path -move # move to /lost+found
hdfs fsck /path -delete
Recover first: A block may be 'missing' only because the DataNode that has it is down. Bring nodes and disks back before declaring data lost.
Problem 5: Cannot Close File / Lease Issues
A writer crashed and the file stays open for write. Readers may see Cannot obtain block length and MapReduce jobs fail.
bash
hdfs fsck /path -openforwrite
hdfs debug recoverLease -path /path/to/file -retries 5
Problem 6: Slow Writes and Reads
| Check | Command / metric |
|---|---|
| One slow DataNode in the pipeline | DataNode log Slow BlockReceiver write packet to mirror |
| Disk latency | iostat -x 5 (await, %util) |
| Network errors | ip -s link, sar -n EDEV 5 3 |
| NameNode overloaded | RpcQueueTimeAvgTime, GC pause |
| Too many xceivers | dfs.datanode.max.transfer.threads reached |
| Under-replicated storm | Replication backlog slowing everything |
Problem 7: Disk Full
bash
hdfs dfsadmin -report | grep -E "DFS Used%|DFS Remaining%"
hdfs dfs -du -h -s /user/* | sort -rh | head # who uses the space
hdfs dfs -du -h /tmp /app-logs /spark-history /user/*/.Trash | sort -rh | head
hdfs dfs -expunge # clear trash
hdfs dfs -rm -r -skipTrash /tmp/old_dir
hdfs balancer -threshold 5
Problem 8: Permission and Quota Errors
| Error | Meaning and fix |
|---|---|
Permission denied: user=alice, access=WRITE, inode=/data:hdfs:hdfs:drwxr-xr-x | Check owner and mode or ACL, group mapping with hdfs groups alice |
The DiskSpace quota of /user/alice is exceeded | Remove files or raise the space quota |
The NameSpace quota (directories and files) is exceeded | Too many files, compact them, raise name quota |
org.apache.hadoop.ipc.StandbyException | Client hit standby, failover proxy provider missing in config |
Failed to replace a bad datanode on the existing pipeline | Too few DataNodes for replication during a write, check live nodes and dfs.client.block.write.replace-datanode-on-failure.policy |
Keep an incident notebook: Write the symptom, cause and fix of every incident in a shared wiki. The same error returns months later, usually when a different person is on call.
Conclusion
Use a fixed flow, check health commands, then match the error to its cause: bad mounts, metadata, ulimits, DNS, clusterID, missing DataNodes, leases, slow disks, quotas or permissions. Fix the root cause carefully.
Quick Summary: flow: scope -> changes -> health -> logs -> fix cause.

