From 814616687abd70d162e4e50286e1efe149e17662 Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Tue, 10 Apr 2012 18:29:31 +0000 Subject: [PATCH] HBASE-5755 Region sever looking for master forever with cached stale data git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1311910 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/hbase/regionserver/HRegionServer.java | 4 +++- .../hbase/zookeeper/MasterAddressTracker.java | 14 +++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) 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)); } /**