From b3c3393c19d09240588697b69dd7a9643983d357 Mon Sep 17 00:00:00 2001 From: Allan Yang Date: Thu, 18 Oct 2018 21:10:53 +0800 Subject: [PATCH] HBASE-21288 HostingServer in UnassignProcedure is not accurate Signed-off-by: Allan Yang --- .../org/apache/hadoop/hbase/master/HMaster.java | 15 +++++++++++++++ .../master/assignment/UnassignProcedure.java | 16 +++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) 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