diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java index 4e6952a..164849c 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -40,6 +40,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; @@ -693,6 +694,7 @@ public class HMaster extends HRegionServer implements MasterServices { // publish cluster ID status.setStatus("Publishing Cluster ID in ZooKeeper"); ZKClusterId.setClusterId(this.zooKeeper, fileSystemManager.getClusterId()); + this.initLatch.countDown(); this.serverManager = createServerManager(this); @@ -1660,6 +1662,7 @@ public class HMaster extends HRegionServer implements MasterServices { } private void startActiveMasterManager(int infoPort) throws KeeperException { + setInitLatch(new CountDownLatch(1)); String backupZNode = ZKUtil.joinZNode( zooKeeper.backupMasterAddressesZNode, serverName.toString()); /* diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index e03993f..a075f67 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -55,6 +55,8 @@ import java.util.TreeSet; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentSkipListMap; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.locks.ReentrantReadWriteLock; @@ -233,6 +235,7 @@ public class HRegionServer extends HasThread implements protected MemStoreFlusher cacheFlusher; protected HeapMemoryManager hMemManager; + protected CountDownLatch initLatch = null; /** * Cluster connection to be shared by services. @@ -655,6 +658,10 @@ public class HRegionServer extends HasThread implements this.fs, this.rootDir, !canUpdateTableDescriptor(), false); } + protected void setInitLatch(CountDownLatch latch) { + this.initLatch = latch; + } + /* * Returns true if configured hostname should be used */ @@ -809,6 +816,9 @@ public class HRegionServer extends HasThread implements // when ready. blockAndCheckIfStopped(this.clusterStatusTracker); + if (this.initLatch != null) { + this.initLatch.await(50, TimeUnit.SECONDS); + } // Retrieve clusterId // Since cluster status is now up // ID should have already been set by HMaster