Sample HDFS HA Client

In any HDP cluster with a HA setup with quorum there are two NameNodes configured with one working as the active and the other as the standby instance. As the standby node does not accept any write requests, for a client try to write to HDFS it is fairly important to know which one of the two NameNodes it the active one at any given time. The discovery process for that is configured through the hdfs-site.xml.

For any custom implementation it’s becomes relevant to set and understand the correct parameters if a current hdfs-site.xml configuration of the cluster is not given. This post gives a sample Java implementation of a HA HDFS client.

The failover mechanism of a client is a plug-able implementation configurable by the  dfs.client.failover.proxy.provider.{{serviceId}} property. This is set for each service identify, so be using hdfs://serviceId the client will lookup the appropriate fail-over implementation for that service.

A service id should therefor also not contain the port 8020 as it would in a non HA setup.

Typically the ConfiguredFailoverProxyProvider (link) is being used, which expects in the the hdfs-site.xml a proper configuration to access both NameNodes as illustrated in the picture below. The fail-over typically happens based on a trial and error approach, where the first NN’s state is being validated before the second.

hdfs-ha-design-2

Programmatically using a HA HDFS file system in Java is to configure the defaultFS property with the service id of the clsuter:

The client needs to know it is supposed to use the fail-over mechanism by setting the proxy provider:

For the HA fail-over proxy to work we also need to configure the whole HA setup into the client:

The configuration design in an overview:

hdfs-ha-design

With this configuration we can now use the FS to list all files under the user directory:

Here is the complete Java implementation:

The complete configuration in hdfs-site.xml for a sample HA setup:

Further Reading

 

Leave a Reply

Your email address will not be published. Required fields are marked *