diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/NamenodeHeartbeatService.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/NamenodeHeartbeatService.java index 936db80a59..ce6db5ce05 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/NamenodeHeartbeatService.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/NamenodeHeartbeatService.java @@ -79,6 +79,8 @@ public class NamenodeHeartbeatService extends PeriodicService { /** Namenode HA target. */ private NNHAServiceTarget localTarget; + /** Cache HA protocol. */ + private HAServiceProtocol localTargetHAProtocol; /** RPC address for the namenode. */ private String rpcAddress; /** Service RPC address for the namenode. */ @@ -293,8 +295,10 @@ protected NamenodeStatusReport getNamenodeStatusReport() { try { // Determine if NN is active // TODO: dynamic timeout - HAServiceProtocol haProtocol = localTarget.getProxy(conf, 30*1000); - HAServiceStatus status = haProtocol.getServiceStatus(); + if (localTargetHAProtocol == null) { + localTargetHAProtocol = localTarget.getProxy(conf, 30*1000); + } + HAServiceStatus status = localTargetHAProtocol.getServiceStatus(); report.setHAServiceState(status.getState()); } catch (Throwable e) { if (e.getMessage().startsWith("HA for namenode is not enabled")) { @@ -305,6 +309,7 @@ protected NamenodeStatusReport getNamenodeStatusReport() { LOG.error("Cannot fetch HA status for {}: {}", getNamenodeDesc(), e.getMessage(), e); } + localTargetHAProtocol = null; } } } catch(IOException e) {