diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index a8fc64f7d38..9b34e61de45 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -1774,8 +1774,9 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler, ServerName masterServerName = null; long previousLogTime = 0; HMasterRegionInterface master = null; + boolean refresh = false; // for the first time, use cached data while (keepLooping() && master == null) { - masterServerName = this.masterAddressManager.getMasterAddress(); + masterServerName = this.masterAddressManager.getMasterAddress(refresh); if (masterServerName == null) { if (!keepLooping()) { // give up with no connection. @@ -1784,6 +1785,7 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler, } LOG.debug("No master found; retry"); previousLogTime = System.currentTimeMillis(); + refresh = true; // let's try pull it from ZK directly sleeper.sleep(); continue; diff --git a/src/main/java/org/apache/hadoop/hbase/zookeeper/MasterAddressTracker.java b/src/main/java/org/apache/hadoop/hbase/zookeeper/MasterAddressTracker.java index 21d6aef18f8..f9575af41fb 100644 --- a/src/main/java/org/apache/hadoop/hbase/zookeeper/MasterAddressTracker.java +++ b/src/main/java/org/apache/hadoop/hbase/zookeeper/MasterAddressTracker.java @@ -68,7 +68,19 @@ public class MasterAddressTracker extends ZooKeeperNodeTracker { * @return Server name or null if timed out. */ public ServerName getMasterAddress() { - return ZKUtil.znodeContentToServerName(super.getData(false)); + return getMasterAddress(false); + } + + /** + * Get the address of the current master if one is available. Returns null + * if no current master. If refresh is set, try to load the data from ZK again, + * otherwise, cached data will be used. + * + * @param refresh whether to refresh the data by calling ZK directly. + * @return Server name or null if timed out. + */ + public ServerName getMasterAddress(final boolean refresh) { + return ZKUtil.znodeContentToServerName(super.getData(refresh)); } /**