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 74ce20e69ff..af210126b52 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 @@ -74,6 +74,7 @@ import org.apache.hadoop.hbase.MetaTableAccessor; import org.apache.hadoop.hbase.NamespaceDescriptor; import org.apache.hadoop.hbase.PleaseHoldException; import org.apache.hadoop.hbase.ReplicationPeerNotFoundException; +import org.apache.hadoop.hbase.ServerMetrics; import org.apache.hadoop.hbase.ServerName; import org.apache.hadoop.hbase.TableDescriptors; import org.apache.hadoop.hbase.TableName; @@ -1587,6 +1588,20 @@ public class HMaster extends HRegionServer implements MasterServices { this.serverManager.getDeadServers()); return false; } + Map onlineServers = serverManager.getOnlineServers(); + int regionNotOnOnlineServer = 0; + for (RegionState regionState : assignmentManager.getRegionStates().getRegionStates()) { + if (regionState.isOpened() && !onlineServers + .containsKey(regionState.getServerName())) { + LOG.warn("{} 's server is not in the online server list.", regionState); + regionNotOnOnlineServer++; + } + } + if (regionNotOnOnlineServer > 0) { + LOG.info("Not running balancer because {} regions found not on an online server", + regionNotOnOnlineServer); + return false; + } if (this.cpHost != null) { try { diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/UnassignProcedure.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/UnassignProcedure.java index 589b732d4f7..23b2de77604 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/UnassignProcedure.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/UnassignProcedure.java @@ -77,6 +77,8 @@ public class UnassignProcedure extends RegionTransitionProcedure { /** * Where to send the unassign RPC. + * this one may not accurate since another RTP may change this location for + * the region. The hostingServer will be updated in updateTransition */ protected volatile ServerName hostingServer; /** @@ -198,6 +200,13 @@ public class UnassignProcedure extends RegionTransitionProcedure { return false; } + if (regionNode.getRegionLocation() != null && !regionNode + .getRegionLocation().equals(hostingServer)) { + LOG.info("HostingServer changed from {} to {} for {}", hostingServer, + regionNode.getRegionLocation(), this); + this.hostingServer = regionNode.getRegionLocation(); + } + // Mark the region as CLOSING. env.getAssignmentManager().markRegionAsClosing(regionNode); @@ -357,7 +366,12 @@ public class UnassignProcedure extends RegionTransitionProcedure { @Override public ServerName getServer(final MasterProcedureEnv env) { - return this.hostingServer; + RegionStateNode node = + env.getAssignmentManager().getRegionStates().getRegionStateNode(this.getRegionInfo()); + if (node == null) { + return null; + } + return node.getRegionLocation(); } @Override