HDFS-15223. FSCK fails if one namenode is not available. Contributed by Ayush Saxena.

This commit is contained in:
Ayush Saxena 2020-03-19 21:23:13 +05:30
parent f2d3ac2a3f
commit bb41ddaf1e
2 changed files with 18 additions and 4 deletions

View File

@ -57,10 +57,14 @@
import com.google.common.base.Joiner;
import com.google.common.base.Preconditions;
import com.google.common.collect.Lists;
import org.slf4j.LoggerFactory;
@InterfaceAudience.Private
public class HAUtil {
public static final org.slf4j.Logger LOG =
LoggerFactory.getLogger(HAUtil.class.getName());
private static final String[] HA_SPECIAL_INDEPENDENT_KEYS = new String[]{
DFS_NAMENODE_RPC_ADDRESS_KEY,
DFS_NAMENODE_RPC_BIND_HOST_KEY,
@ -273,9 +277,14 @@ public static InetSocketAddress getAddressOfActive(FileSystem fs)
List<ClientProtocol> namenodes =
getProxiesForAllNameNodesInNameservice(dfsConf, nsId);
for (ClientProtocol proxy : namenodes) {
try {
if (proxy.getHAServiceState().equals(HAServiceState.ACTIVE)) {
inAddr = RPC.getServerAddress(proxy);
}
} catch (Exception e) {
//Ignore the exception while connecting to a namenode.
LOG.debug("Error while connecting to namenode", e);
}
}
} else {
DFSClient dfsClient = dfs.getClient();

View File

@ -76,6 +76,11 @@ public void testHaFsck() throws Exception {
cluster.transitionToStandby(0);
cluster.transitionToActive(1);
runFsck(conf);
// Stop one standby namenode, FSCK should still be successful, since there
// is one Active namenode available
cluster.getNameNode(0).stop();
runFsck(conf);
} finally {
if (fs != null) {