Intro
Understanding HDFS architecture is essential for anyone managing large-scale data storage in the Hadoop ecosystem. This guide is written for developers, DevOps engineers, and startup teams who need to move beyond conceptual diagrams and into practical, verifiable operations. We will walk through the core components—NameNode, DataNodes, and the mechanisms that keep data safe and available—using concrete commands, expected outputs, and recovery procedures.
The goal of this article is operational safety. We follow a pattern: observe the current state with read-only commands, define the expected result before changing anything, limit the blast radius of any intervention, and always know how to verify success or roll back. All examples use placeholders like </path/to/directory> and </namenode/hostname>; never use real credentials or production identifiers in your own scripts.
Version and Environment Inventory
Before you can reason about HDFS architecture, you must know exactly what you are running. The first step is to inventory the installed version, deployment topology, and key configuration values. This information determines which commands are valid, which failure signals matter, and how to plan changes safely.
Start by checking the Hadoop version. This command works on any node in the cluster:
hadoop version
Expected output on a typical Apache Hadoop 3.3.6 installation:
Hadoop 3.3.6
Source code repository https://github.com/apache/hadoop.git -r 1be78238728da9266a4f88195058f08fd012bf9c
Compiled by ubuntu on 2023-06-18T15:43Z
Compiled with protoc 3.7.1
From source with checksum 3b6a6f8279cd9e6d4a40a4e2b1b1b7
This command was run using /opt/hadoop/share/hadoop/common/hadoop-common-3.3.6.jar
Note the version at the top. Many operational procedures differ between major versions (for example, the transition from Hadoop 2.x to 3.x introduced erasure coding and changed default ports). If you are using a vendor-specific distribution such as Cloudera or Hortonworks, the command may be wrapped by a management tool, but the underlying Hadoop version is still critical.
Next, identify the deployment topology. HDFS has two main roles:
- NameNode: manages the filesystem namespace and regulates client access.
- DataNode: stores the actual data blocks on local disks.
In production, you often have a high-availability (HA) setup with two NameNodes (active and standby) and a set of JournalNodes for edit log synchronization. To find the NameNode addresses, inspect hdfs-site.xml on a configuration node:
grep -A 1 'dfs.namenode.rpc-address' /etc/hadoop/conf/hdfs-site.xml
Expected output (for a simple HA cluster with nameservice mycluster):
<property>
<name>dfs.namenode.rpc-address.mycluster.nn1</name>
<value>namenode1.example.com:8020</value>
</property>
<property>
<name>dfs.namenode.rpc-address.mycluster.nn2</name>
<value>namenode2.example.com:8020</value>
</property>
If the output is empty, you may be looking at a non-HA setup or the wrong configuration directory. In that case, check the default location /etc/hadoop/conf or the value of HADOOP_CONF_DIR.
To see all DataNodes currently reporting to the NameNode, use the hdfs dfsadmin command:
hdfs dfsadmin -report
Look for the section starting with Live datanodes. A healthy cluster with three DataNodes shows:
Live datanodes (3):
Name: 10.0.0.11:9866 (datanode1.example.com)
Hostname: datanode1.example.com
Decommission Status : Normal
Configured Capacity: 1099511627776 (1 TB)
DFS Used: 219902325555 (200 GB)
Non DFS Used: 10995116277 (10 GB)
DFS Remaining: 867583393944 (790 GB)
...
The report also gives block pool usage, version, and other useful metrics. If a DataNode is missing, the count will be lower than expected, and that is an immediate red flag.
Now that you have the version and topology, you can define your expected outcomes and failure signals for any change. For example, if you plan to add a new DataNode, the success signal is that hdfs dfsadmin -report shows the new node in the Live datanodes list with the expected capacity. Failure might be a timeout or the node appearing under Dead datanodes.
So, the version and environment inventory gives you the foundation. Without it, every other procedure in this article is guesswork.
Safe Configuration Path
HDFS configuration is governed by hdfs-site.xml and core-site.xml. Many settings affect architecture directly, such as dfs.replication, dfs.blocksize, and rack awareness. Making changes without understanding the blast radius can lead to data unavailability or performance degradation. This section walks through a structured approach to configuration changes, using a concrete example.
Suppose you want to lower the replication factor from 3 to 2 to save space. This is a common but risky change. Here is the safe path:
- Prerequisites: Identify all files with the current replication factor. The change only affects files written after the configuration change unless you explicitly set replication on existing files. New writes will use the default from
dfs.replication. Existing files keep their replication factor until a re-replication or manual command is issued.
- Read-only observation: Before changing anything, capture the current setting and the replication distribution of a sample directory.
Check the current default replication factor in the configuration:
hdfs getconf -confKey dfs.replication
Expected output: 3
Check replication on a specific directory, say /user/hive/warehouse:
hdfs dfs -ls /user/hive/warehouse | head -n 5
The second column in ls output is the replication factor for each file. For example:
-rw-r--r-- 3 hdfs supergroup 123456789 2024-01-05 12:34 /user/hive/warehouse/table1
Here, the 3 after the permissions is the replication factor.
- Smallest justified change: Instead of changing the global default immediately, change the replication factor on a specific test directory using a runtime command. This avoids altering the configuration file for the whole cluster.
hdfs dfs -setrep -R 2 /user/testdir
Expected output: Waiting for /user/testdir to replicate... followed by confirmation. You can verify with hdfs dfs -ls /user/testdir that the replication factor column now shows 2.
- Verification: After setting, check the actual replication status on a file within that directory.
hdfs fsck /user/testdir -files -blocks -replicaDetails | grep -A 3 'Replication'
The output will show expected vs. actual replication. A healthy file with replication factor 2 shows something like:
Status: HEALTHY
Total blocks: 1
Replication factor: 2
Average block replication: 2.0
- Permanent configuration change (if needed): Once you have validated that the lower replication is acceptable, modify
hdfs-site.xmlon all NameNodes and DataNodes (or push via configuration management). Set:
<property>
<name>dfs.replication</name>
<value>2</value>
</property>
Then restart the HDFS services or run hdfs dfsadmin -refreshNodes if only node list changed. However, dfs.replication requires restart of NameNode to take effect for new files. Be aware of the rolling restart process.
- Recovery path: If you see that files are under-replicated after the change (e.g., due to capacity constraints), you can revert by setting the replication factor back to 3 either with
hdfs dfs -setrep 3on affected files or by restoring the configuration and restarting services.
A blast radius note: Changing dfs.replication does not delete excess replicas immediately; the NameNode will schedule deletion of over-replicated blocks over time. Lowering replication reduces redundancy; if a DataNode fails during this period, some blocks may become unavailable because the target replication factor is not yet met. So, monitor hdfs dfsadmin -report for under-replicated blocks.
Another common configuration change is enabling rack awareness. This affects block placement and can improve fault tolerance. The safe path involves defining a topology script and setting net.topology.script.file.name in core-site.xml. The script maps IP addresses or hostnames to rack IDs. For example:
#!/bin/bash
# topology.sh
HOSTNAME=$1
if [[ $HOSTNAME == datanode1* ]]; then
echo "/rack1"
elif [[ $HOSTNAME == datanode2* ]]; then
echo "/rack2"
else
echo "/default-rack"
fi
Set net.topology.script.file.name to the script path, and test with hdfs dfsadmin -printTopology to see the rack assignment. The verification signal is a topology tree that correctly groups DataNodes into racks.
Remember, never modify configuration files without first understanding the scope and testing on a canary node or directory.
Verification and Diagnostics
After any change or during regular operations, you need to verify the health and correctness of HDFS components. This section provides a set of diagnostic commands with their expected outputs and failure signals.
1. Filesystem Health Check
hdfs fsck is the primary tool for checking filesystem consistency. Run it on the root directory to get a summary:
hdfs fsck /
Healthy output includes:
Status: HEALTHY
Total size: 1234567890123 B
Total dirs: 450
Total files: 12000
Total blocks (validated): 36000 (avg. block size 134217728 B)
Minimally replicated blocks: 36000 (100.0 %)
Over-replicated blocks: 0 (0.0 %)
Under-replicated blocks: 0 (0.0 %)
Mis-replicated blocks: 0 (0.0 %)
Default replication factor: 3
Average block replication: 3.0
Corrupt blocks: 0
Missing replicas: 0
Number of data-nodes: 3
Number of racks: 2
Failure signals to watch for:
Status: CORRUPTindicates corrupt blocks. Runhdfs fsck / -list-corruptfileblocksto list them.Under-replicated blocks> 0 means some blocks have fewer replicas than desired. This could be transient during rebalancing or persistent due to DataNode failures.Missing replicas> 0 indicates that replicas expected on specific nodes are not found. Investigate the DataNodes.
2. DataNode Health
Use hdfs dfsadmin -report to see live and dead DataNodes. Already described, but look for:
Live datanodescount matches expected.Dead datanodeslist is empty or contains only nodes intentionally decommissioned.
If a DataNode is dead, check logs on that node: /var/log/hadoop-hdfs/hadoop-hdfs-datanode-*.log. Look for ERROR or FATAL messages, especially related to disk failures or network issues.
3. NameNode UI and JMX
The NameNode web UI (default port 9870 on Hadoop 3.x) provides a dashboard with cluster summary, DataNode status, and block health. For programmatic verification, query JMX:
curl -s http://namenode1.example.com:9870/jmx | jq '.beans[] | select(.name=="Hadoop:service=NameNode,name=NameNodeStatus")'
Expected output includes "State":"active" or "standby" for HA. This is crucial for diagnosing failover issues.
4. Log Analysis
Centralized log monitoring is essential. Typical failure patterns in NameNode logs:
java.io.IOException: Cannot lock storageusually means another NameNode is running or the storage directory is corrupted.FATAL org.apache.hadoop.hdfs.server.namenode.NameNode: Failed to start namenodeoften points to a configuration error or missing metadata.
Use grep on recent logs:
grep -i "fatal\|error\|exception" /var/log/hadoop-hdfs/hadoop-hdfs-namenode-namenode1.example.com.log | tail -n 20
5. Block Verification
To verify a specific file's block locations, use hdfs fsck <path> -files -blocks -locations. This shows which DataNodes hold each replica, helping you assess rack diversity. For example:
hdfs fsck /user/test/file.txt -files -blocks -locations
Output snippet:
0. BP-123456789-10.0.0.1-1616500000000:blk_1073741825_1001 len=134217728 Live_repl=3
[DatanodeInfoWithStorage[10.0.0.11:9866,DS-xxx,DISK],
DatanodeInfoWithStorage[10.0.0.12:9866,DS-yyy,DISK],
DatanodeInfoWithStorage[10.0.0.13:9866,DS-zzz,DISK]]
If the three DataNodes are all on the same rack, that's a problem for fault tolerance. Rack awareness should place at least one replica on a different rack.
With these diagnostics, you can pinpoint most operational issues before they cause downtime.
Failure Modes and Recovery
HDFS is designed to handle failures, but you must know how to respond. This section covers common failure scenarios and step-by-step recovery procedures.
Scenario 1: DataNode Failure
Failure mode: A DataNode crashes or becomes unavailable. The NameNode will detect this after a timeout (default 10 minutes + 30 seconds) and mark the node as dead. Blocks on that node become under-replicated, and the NameNode begins re-replication to other nodes if capacity allows.
Recovery steps:
- Verify the node is dead:
hdfs dfsadmin -report | grep -A 5 'Dead datanodes'
If the node appears there, proceed.
- Check the node's network connectivity and disk health. If the node can be restored, restart the DataNode service:
systemctl restart hadoop-hdfs-datanode
- Wait for the node to rejoin. Monitor
hdfs dfsadmin -reportuntil it appears underLive datanodes. - The NameNode will automatically reduce replication on the restored node if it had been over-replicated due to re-replication. You can force a rebalance if needed.
- If the node is permanently lost, follow decommissioning procedures to remove it from the cluster.
Verification: After recovery, check that the file system is healthy:
hdfs fsck / | grep 'Under-replicated blocks'
Expect Under-replicated blocks: 0 after replication settles.
Scenario 2: NameNode Metadata Corruption
Failure mode: The NameNode's metadata (fsimage or edit logs) becomes corrupted, often from a disk failure or abrupt shutdown. The NameNode fails to start, throwing exceptions.
Recovery steps (for non-HA):
- Identify corrupted storage directories by checking the
dfs.namenode.name.dirproperty (typically/hadoop/hdfs/namenode). - Stop the NameNode.
- Choose a backup of the fsimage and edit logs from a known good point. If you have a secondary NameNode, it may have checkpoints.
- Restore the best available fsimage into the active name directory and delete the stale edit logs; the checkpoint includes everything up to that point.
- Restart NameNode and accept that data written after the checkpoint may be lost.
- Run
hdfs fsck /to ensure filesystem consistency.
Verification: The NameNode starts and the fsck status is not CORRUPT. There may be missing files; identify them via hdfs fsck / -files -blocks and restore from backups if needed.
For HA clusters, failover to the standby NameNode is the primary recovery. The standby has been keeping up with edit logs and can be promoted quickly.
Scenario 3: Rack Awareness Misconfiguration
Failure mode: If the rack topology script is wrong or not set, block replicas may all end up on the same rack, defeating fault tolerance. A rack failure could cause data unavailability.
Recovery steps:
- Check current topology:
hdfs dfsadmin -printTopology
If all DataNodes show the same rack or default rack, investigate.
- Fix the topology script and set
net.topology.script.file.name. - Restart NameNode to reload the script.
- Rebalance the cluster if needed:
hdfs balancer -threshold 10moves blocks to satisfy policy and improve distribution. - Verify that file block locations now include racks as desired using
hdfs fsckwith-locations.
Verification: hdfs dfsadmin -printTopology shows correct rack grouping, and hdfs fsck on critical files shows replicas on different racks.
Scenario 4: Capacity Exhaustion
Failure mode: The cluster runs out of disk space, causing writes to fail with DiskOutOfSpaceException and DataNodes to report full volumes.
Recovery steps:
- Identify full DataNodes with
hdfs dfsadmin -reportand look forDFS Remainingnear zero. - Add more storage to DataNodes or add new DataNodes.
- If space is temporarily critical, you can set a low-limit on some directories or delete unnecessary data after coordinating with users.
- Run the balancer after adding nodes to redistribute data:
hdfs balancer -threshold 5. - Monitor until
hdfs dfsadmin -reportshows healthy remaining capacity.
Verification: Writes succeed and no DataNode remains above 90% utilization.
Always have a tested recovery plan before a failure. Simulate failure drills in a staging environment to ensure your team knows what to do.
Operations Checklist
Use this checklist for daily, weekly, and monthly operational tasks to keep your HDFS architecture healthy and anticipated failures under control.
Daily Checks
- [ ] Run
hdfs dfsadmin -reportand confirm all expected DataNodes are live and capacity is within normal range. Look for any node withDFS Remainingless than 10% of total. - [ ] Check NameNode status:
curl -s http://namenode1:9870/jmx | jq '.beans[] | select(.name=="Hadoop:service=NameNode,name=NameNodeStatus") | .State'should returnactiveorstandbyas expected. - [ ] View
hdfs fsck /summary for under-replicated or corrupt blocks. Act immediately if any. - [ ] Inspect logs for errors:
grep -i "error\|fatal" /var/log/hadoop-hdfs/hadoop-hdfs-namenode-*.log | tail -n 5. - [ ] Monitor disk utilization on DataNodes with
df -hon each node, ensuring no volume is over 80% full.
Weekly Checks
- [ ] Review block replication distribution with
hdfs fsck / -files -blocks -locations | grep 'Live_repl' | awk '{print $3}' | sort | uniq -cto spot files with replication != 3. - [ ] Validate rack awareness script output: run the script manually for each DataNode hostname and confirm rack IDs.
- [ ] Check the HDFS audit log for unusual activity:
/var/log/hadoop-hdfs/hdfs-audit.log(or configured location). Look for unexpected deletions or permission changes. - [ ] Run
hdfs dfsadmin -refreshNodesafter any planned node changes.
Monthly Checks
- [ ] Perform a rolling upgrade of configuration files if changes are pending; ensure all nodes have consistent
hdfs-site.xmlandcore-site.xml. - [ ] Test failure recovery in a staging environment: simulate DataNode failure and ensure NameNode re-replicates correctly.
- [ ] Review capacity planning trends: use
hdfs dfsadmin -reportto track usage over time and plan for storage additions before hitting 80%. - [ ] Run a full
hdfs fsck / -files -blocks -locations > fsck-report.txtand archive for compliance. - [ ] Verify backup strategy: check that snapshots or distcp to a secondary cluster are working, and test restoring a small set of files.
Each item should have an owner and a defined remediation path. For example, if under-replicated blocks are found, the on-call engineer should first check DataNode status, then consider adding nodes or adjusting replication.
Conclusion
HDFS architecture is robust, but its operational health depends on deliberate, verifiable practices. This guide has covered inventorying your environment, making configuration changes safely, diagnosing problems, and recovering from failures—all with concrete commands and expected outputs.
The key takeaway is to never make a change without first observing the current state and defining the success signal. Use read-only commands liberally; restrict modifications to the smallest scope possible; and always have a rollback plan.
Start with a low-risk verification: run hdfs dfsadmin -report and hdfs fsck / on your cluster, record the outputs, and compare them with the healthy examples shown here. From there, gradually adopt the safe configuration path and the operations checklist. Remember, a reliable workflow makes failures visible, protects sensitive data, and ensures that recovery is a controlled process rather than an emergency scramble.