From 211ae1d1504c9302e319c0c916a03d2430aef04c Mon Sep 17 00:00:00 2001 From: jxiang Date: Tue, 1 Apr 2014 19:53:55 +0000 Subject: [PATCH] HBASE-10851 Wait for regionservers to join the cluster git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1583769 13f79535-47bb-0310-9956-ffa450edef68 --- .../hadoop/hbase/master/AssignmentManager.java | 9 +++------ .../org/apache/hadoop/hbase/master/HMaster.java | 6 +++++- .../hadoop/hbase/master/HMasterCommandLine.java | 1 + .../hadoop/hbase/master/ServerManager.java | 17 +++++++++++++---- .../hbase/master/balancer/BaseLoadBalancer.java | 4 ++++ 5 files changed, 26 insertions(+), 11 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java index a3d21b42c6c..c25f712a637 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java @@ -64,7 +64,6 @@ import org.apache.hadoop.hbase.executor.EventType; import org.apache.hadoop.hbase.executor.ExecutorService; import org.apache.hadoop.hbase.ipc.RpcClient; import org.apache.hadoop.hbase.ipc.RpcClient.FailedServerException; -import org.apache.hadoop.hbase.ipc.RpcClient.FailedServerException; import org.apache.hadoop.hbase.ipc.ServerNotRunningYetException; import org.apache.hadoop.hbase.master.RegionState.State; import org.apache.hadoop.hbase.master.balancer.FavoredNodeAssignmentHelper; @@ -2211,11 +2210,9 @@ public class AssignmentManager extends ZooKeeperListener { } LOG.debug("No previous transition plan found (or ignoring " + "an existing plan) for " + region.getRegionNameAsString() + - "; generated random plan=" + randomPlan + "; " + - serverManager.countOfRegionServers() + - " (online=" + serverManager.getOnlineServers().size() + - ", available=" + destServers.size() + ") available servers" + - ", forceNewPlan=" + forceNewPlan); + "; generated random plan=" + randomPlan + "; " + destServers.size() + + " (online=" + serverManager.getOnlineServers().size() + + ") available servers, forceNewPlan=" + forceNewPlan); return randomPlan; } LOG.debug("Using pre-existing plan for " + 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 82bae87ce9f..95cb26f406e 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 @@ -532,7 +532,7 @@ public class HMaster extends HRegionServer implements MasterServices, Server { this.initializationBeforeMetaAssignment = true; // Wait for regionserver to finish initialization. - while (!isOnline()) { + while (!isStopped() && !isOnline()) { synchronized (online) { online.wait(100); } @@ -543,6 +543,10 @@ public class HMaster extends HRegionServer implements MasterServices, Server { this.balancer.setMasterServices(this); this.balancer.initialize(); + // Check if master is shutting down because of some issue + // in initializing the regionserver or the balancer. + if(isStopped()) return; + // Make sure meta assigned before proceeding. status.setStatus("Assigning Meta Region"); assignMeta(status, previouslyFailedMetaRSs); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java index 55aaa7cf17e..431f4c138f2 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMasterCommandLine.java @@ -151,6 +151,7 @@ public class HMasterCommandLine extends ServerCommandLine { // and regionserver both in the one JVM. if (LocalHBaseCluster.isLocal(conf)) { DefaultMetricsSystem.setMiniClusterMode(true); + conf.setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, 1); final MiniZooKeeperCluster zooKeeperCluster = new MiniZooKeeperCluster(conf); File zkDataPath = new File(conf.get(HConstants.ZOOKEEPER_DATA_DIR)); int zkClientPort = conf.getInt(HConstants.ZOOKEEPER_CLIENT_PORT, 0); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java index 391e0b84237..4c7ffdd38a0 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java @@ -436,10 +436,19 @@ public class ServerManager { return averageLoad; } - /** @return the count of active regionservers */ - int countOfRegionServers() { + /** + * Get the count of active regionservers that are not backup + * masters. This count may not be accurate depending on timing. + * @return the count of active regionservers + */ + private int countOfRegionServers() { // Presumes onlineServers is a concurrent map - return this.onlineServers.size(); + int count = this.onlineServers.size(); + if (balancer != null) { + count -= balancer.getExcludedServers().size(); + if (count < 0) count = 0; + } + return count; } /** @@ -849,7 +858,7 @@ public class ServerManager { final long timeout = this.master.getConfiguration(). getLong(WAIT_ON_REGIONSERVERS_TIMEOUT, 4500); int minToStart = this.master.getConfiguration(). - getInt(WAIT_ON_REGIONSERVERS_MINTOSTART, 1); + getInt(WAIT_ON_REGIONSERVERS_MINTOSTART, 2); if (minToStart < 1) { LOG.warn(String.format( "The value of '%s' (%d) can not be less than 1, ignoring.", diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java index e7002c39745..2e53f2e846d 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java @@ -496,6 +496,10 @@ public abstract class BaseLoadBalancer implements LoadBalancer { if (!usingBackupMasters) excludedServers.add(serverName); } + public Set getExcludedServers() { + return excludedServers; + } + @Override public Configuration getConf() { return this.config;