HDFS high availability helps keep your data safe and accessible even if one part of the system fails. It stops your system from going offline.
HDFS high availability in Hadoop
1. Set up two NameNodes: one active and one standby. 2. Configure a shared storage called JournalNode for edit logs. 3. Use ZooKeeper to manage automatic failover between NameNodes. 4. Update hdfs-site.xml with HA settings including dfs.nameservices, dfs.ha.namenodes, dfs.namenode.rpc-address, dfs.namenode.http-address, dfs.namenode.shared.edits.dir, and dfs.client.failover.proxy.provider. 5. Start JournalNodes, ZooKeeper, and both NameNodes. 6. Use hdfs commands to check the status and switch active NameNode if needed.
This setup requires careful configuration of multiple components.
ZooKeeper helps decide which NameNode is active to avoid conflicts.
# Example hdfs-site.xml snippet for HA <configuration> <property> <name>dfs.nameservices</name> <value>mycluster</value> </property> <property> <name>dfs.ha.namenodes.mycluster</name> <value>nn1,nn2</value> </property> <property> <name>dfs.namenode.rpc-address.mycluster.nn1</name> <value>host1:8020</value> </property> <property> <name>dfs.namenode.rpc-address.mycluster.nn2</name> <value>host2:8020</value> </property> <property> <name>dfs.namenode.http-address.mycluster.nn1</name> <value>host1:50070</value> </property> <property> <name>dfs.namenode.http-address.mycluster.nn2</name> <value>host2:50070</value> </property> <property> <name>dfs.namenode.shared.edits.dir</name> <value>qjournal://host1:8485;host2:8485;host3:8485/mycluster</value> </property> <property> <name>dfs.client.failover.proxy.provider.mycluster</name> <value>org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider</value> </property> </configuration>
# Edge case: Only one NameNode configured (no HA)
<configuration>
<property>
<name>dfs.nameservices</name>
<value>mycluster</value>
</property>
<property>
<name>dfs.ha.namenodes.mycluster</name>
<value>nn1</value>
</property>
</configuration># Edge case: Standby NameNode is down # The active NameNode continues serving data. # Failover can be manual or automatic if ZooKeeper is configured.
This script shows how to check which NameNode is active or standby and how to switch active NameNode manually.
# This is a shell script example to check HDFS HA status # Check the status of NameNodes hdfs haadmin -getServiceState nn1 hdfs haadmin -getServiceState nn2 # Manually failover from nn1 to nn2 hdfs haadmin -failover nn1 nn2 # Check status again hdfs haadmin -getServiceState nn1 hdfs haadmin -getServiceState nn2
Time complexity: HA setup adds some overhead but keeps system responsive.
Space complexity: Requires extra storage for shared edits and standby NameNode.
Common mistake: Not configuring ZooKeeper correctly can cause failover to fail.
Use HA when you need zero downtime. For small clusters, simple single NameNode may be enough.
HDFS high availability uses two NameNodes to avoid downtime.
Shared storage and ZooKeeper help manage failover automatically.
Proper configuration is key to keep data safe and accessible.
Practice
Solution
Step 1: Understand HDFS HA concept
HDFS HA uses two NameNodes to ensure one is always available if the other fails.Step 2: Identify the main goal
The goal is to avoid downtime, not to increase storage or speed processing.Final Answer:
To avoid downtime by using two active NameNodes -> Option BQuick Check:
HDFS HA = Avoid downtime [OK]
- Confusing HA with storage scaling
- Thinking HA speeds up processing
- Assuming HA encrypts data
Solution
Step 1: Identify failover mechanism in HDFS HA
ZooKeeper coordinates and manages automatic failover between NameNodes.Step 2: Exclude unrelated components
DataNode stores data, ResourceManager manages resources, JobTracker is for MapReduce jobs, none handle failover.Final Answer:
ZooKeeper -> Option AQuick Check:
Failover = ZooKeeper [OK]
- Choosing DataNode as failover manager
- Confusing YARN with failover
- Selecting MapReduce components
dfs.nameservices?
dfs.nameservices=cluster1
Solution
Step 1: Understand dfs.nameservices meaning
It defines a logical name for the HDFS cluster, grouping NameNodes under one namespace.Step 2: Eliminate other options
It does not specify IPs, DataNodes, or replication factors.Final Answer:
Defines the logical name for the HDFS cluster used by clients -> Option CQuick Check:
dfs.nameservices = cluster name [OK]
- Thinking it sets IP addresses
- Confusing with DataNode list
- Mixing with replication settings
Solution
Step 1: Identify failover configuration
Automatic failover requiresdfs.ha.automatic-failover.enabledset to true.Step 2: Exclude unrelated settings
Replication factor, DataNodes count, and checkpoint settings do not control failover.Final Answer:
Setting dfs.ha.automatic-failover.enabled to true -> Option AQuick Check:
Auto failover enabled = true [OK]
- Changing replication factor to fix failover
- Adding DataNodes expecting failover fix
- Disabling checkpoint thinking it helps failover
cluster1?Solution
Step 1: Understand failover proxy provider setting
This property tells the client how to switch between NameNodes during failover.Step 2: Check correctness of options
dfs.client.failover.proxy.provider.cluster1=org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider
correctly sets the proxy provider for cluster1.dfs.nameservices=nn1,nn2
wrongly lists NameNodes as nameservices.dfs.ha.automatic-failover.enabled=false
disables failover.dfs.replication=3
sets replication, unrelated to failover.Final Answer:
dfs.client.failover.proxy.provider.cluster1=org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider -> Option DQuick Check:
Failover proxy provider =dfs.client.failover.proxy.provider.cluster1=org.apache.hadoop.hdfs.server.namenode.ha.ConfiguredFailoverProxyProvider
[OK]
- Confusing nameservices with NameNodes list
- Disabling automatic failover by mistake
- Mixing replication with failover settings
Ready to prove it?
Pass the test and this pattern moves unknown
