Hadoop FAQ
HDFS Related Issues
What to Do When HDFS Storage Space is Insufficient
Insufficient HDFS storage space is a common problem that can have multiple causes. First, check DataNode disk usage:
hdfs dfsadmin -report
If space is indeed insufficient, take these measures: delete unnecessary historical data; use hdfs balancer to balance data distribution and free some nodes; add new DataNode nodes to expand cluster storage capacity; reduce replication factor to decrease storage overhead (need to weigh data security).
# Delete files
hdfs dfs -rm -r /user/olddata
# Balance data
hdfs balancer -threshold 10
How to Handle NameNode Memory Insufficiency
NameNode stores all metadata in memory; if there are too many files, memory may become insufficient. Mitigate by: increasing NameNode memory configuration in hadoop-env.sh by setting the -Xmx parameter in HADOOP_NAMENODE_OPTS; enabling NameNode snapshot functionality to regularly create read-only backups of important data; upgrading to Hadoop 2.x or higher, which has better metadata management optimization.
# Set in hadoop-env.sh
export HADOOP_NAMENODE_OPTS="-Xmx4g -Xms4g"
What to Do When DataNode Fails to Start
DataNode startup failure can have multiple causes. First check DataNode logs:
cat $HADOOP_HOME/logs/hadoop-datanode-*.log
Common causes and solutions: insufficient disk space—clean disks or add new disks; permission issues—ensure Hadoop user has read/write access to data directories; inconsistent cluster ID—if adding a new DataNode, run hdfs namenode -upgrade on the DataNode or delete the storage directory and reformat.
# Check DataNode directory permissions
ls -la /usr/local/hadoop/data/
# Delete DataNode storage directory and restart
rm -rf /usr/local/hadoop/data/datanode/*
systemctl restart hadoop-datanode
How to Recover Accidentally Deleted Files
HDFS provides trash functionality to recover deleted files. First confirm trash is enabled:
hdfs dfs -ls /user/username/.Trash/Current/
If you discover accidental deletion, restore from trash:
# Restore file
hdfs dfs -mv /user/username/.Trash/Current/filepath /user/username/
If trash has been emptied or the retention period has passed, data cannot be recovered. Therefore, in daily operations: keep trash enabled (enabled by default); back up important data; confirm carefully before deletion.
How to Handle Corrupted HDFS Blocks
Data blocks may become corrupted due to disk failures or network issues. HDFS has built-in data integrity detection—when corrupted blocks are found, it automatically replicates data from other replicas for recovery. Manual check and repair:
# Check file system integrity
hdfs fsck / -files -blocks -locations
# Delete corrupted block files
hdfs fsck / -delete
MapReduce Related Issues
What to Do When Jobs Run Slowly
Slow MapReduce jobs can be caused by multiple factors. First, check job history logs and analyze time spent in each phase:
# View job details
yarn logs -applicationId application_xxx -logFiles *
# View in JobHistory Server
mapred job -history job_history_file
Common optimization directions: increase Reduce task count to improve parallelism; adjust JVM heap size to avoid OOM; enable Combiner to reduce network transmission volume; optimize data skew using custom partitioners to balance load; choose appropriate file formats (Parquet, ORC, etc.).
How to Handle Data Skew
Data skew means data is unevenly distributed during the Reduce phase, causing some Reduce tasks to run much longer than others. Solutions include: use custom partitioners to redistribute data based on business logic; add random prefix to let data first scatter to multiple Reduces, then aggregate secondarily; use key salting—remove prefix after aggregation.
// Custom partitioner example
public class SaltedPartitioner extends Partitioner<Text, Text> {
@Override
public int getPartition(Text key, Text value, int numPartitions) {
// Redistribute based on business logic
int hash = key.hashCode() % numPartitions;
return Math.abs(hash);
}
}
How to Troubleshoot Failing MapReduce Jobs
When jobs fail, first check error logs to determine the cause of failure:
# View job status
yarn application -status application_xxx
# View task failure reasons
mapred job -status job_id
Common failure causes: Java OutOfMemory (OOM)—increase mapreduce.map.memory.mb and mapreduce.reduce.memory.mb; input data format error—check if data matches expected format; custom code exception—check code logic and exception messages; network timeout—increase mapreduce.task.timeout parameter.
YARN Related Issues
What to Do When ResourceManager Fails to Start
ResourceManager startup failure is usually caused by configuration errors or port conflicts. Check logs:
cat $HADOOP_HOME/logs/yarn-resourcemanager-*.log
Common problems and solutions: port already in use—modify ResourceManager port in yarn-site.xml; ZooKeeper configuration error (if using HA)—check zkfc related configuration; insufficient memory—ensure machine has enough physical memory; configuration file error—carefully check yarn-site.xml and capacity-scheduler.xml.
# Check port usage
netstat -tlnp | grep 8032
How to Handle Low Cluster Resource Utilization
Low cluster resource utilization may be caused by: unreasonable job submission patterns—jobs too small cause scheduling overhead to exceed computation time; improper scheduler configuration—queue resource allocation unreasonable; poor data locality—input data and compute nodes not in the same location.
Optimization suggestions: batch submit small jobs; reasonably configure queue capacity and priorities; optimize data layout to improve data locality; use appropriate scheduler (Capacity Scheduler or Fair Scheduler).
How to Limit User Resource Usage
Use YARN queues and access control to limit user resource usage:
<property>
<name>yarn.scheduler.capacity.root.<queue-name>.user-limit-factor</name>
<value>1</value> <!-- Maximum multiple of queue resources for single user -->
</property>
<property>
<name>yarn.scheduler.capacity.root.<queue-name>.maximum-applications</name>
<value>100</value> <!-- Maximum running jobs in queue -->
</property>
Cluster Operations Issues
How to Monitor Hadoop Cluster
Hadoop provides multiple monitoring methods: Web UI (NameNode port 9870, ResourceManager port 8088); JMX (Java Management Extensions) monitoring; External monitoring systems like Ganglia, Prometheus; Command-line tools (hdfs dfsadmin, yarn node, etc.).
Using Prometheus + Grafana to build a complete monitoring platform is recommended—collect Hadoop's JMX metrics and visualize them.
How to Perform Cluster Upgrade
Hadoop cluster upgrade requires careful operation. Recommended steps: first verify new version compatibility in test environment; backup NameNode metadata and HDFS data; upgrade DataNode nodes one by one, then upgrade NameNode; use rolling upgrade to reduce downtime.
# Rolling upgrade DataNode
$HADOOP_HOME/bin/hdfs --daemon stop datanode
# Upgrade Hadoop
tar -xzf hadoop-new.tar.gz -C /usr/local/
# Start DataNode
$HADOOP_HOME/bin/hdfs --daemon start datanode
How to Configure NameNode High Availability
NameNode HA avoids NameNode single point of failure. Configuration steps: configure two NameNodes in hdfs-site.xml; configure shared edit directory (usually using ZooKeeper or NFS); start ZooKeeper Failover Controller (ZKFC).
<property>
<name>dfs.ha.automatic-failover.enabled</name>
<value>true</value>
</property>
<property>
<name>ha.zookeeper.quorum</name>
<value>zk1:2181,zk2:2181,zk3:2181</value>
</property>
After configuration, initialize ZKFC:
hdfs zkfc -formatZK
How to Handle Node Decommissioning
Node decommissioning requires careful handling to ensure no data loss. Use decommission functionality to safely take nodes offline:
# Add node to exclude file in workers file
echo "slave3" >> $HADOOP_HOME/etc/hadoop/workers.exclude
# Refresh node list
hdfs dfsadmin -refreshNodes
yarn rmadmin -refreshNodes
Wait for data replication to complete—node will automatically enter decommissioned state. Confirm data has been replicated to other nodes before shutting down the node.
Development Related Issues
How to Debug MapReduce Programs
MapReduce program debugging is difficult. Recommended methods: first test logic in local mode; use Counters to record key metrics; add log output—print key variable values in Map or Reduce methods; use MRUnit for unit testing.
// Using Counter
context.getCounter("MyCounters", "InvalidRecord").increment(1);
How to Choose InputFormat and OutputFormat
InputFormat determines how to read input data: TextInputFormat (default, reads by line); KeyValueTextInputFormat (splits by tab); SequenceFileInputFormat (binary format); DBInputFormat (reads from database).
OutputFormat determines how to output results: TextOutputFormat (default, text format); SequenceFileOutputFormat (binary format); NullOutputFormat (no file output); DBOutputFormat (outputs to database).
How to Handle Small File Problem
Large numbers of small files increase NameNode memory pressure and reduce processing efficiency. Solutions: use Hadoop Archives (HAR) to package small files; use SequenceFile to merge small files; use HBase to store large numbers of small files; adjust block size to reduce small file count.
