This is an automated email from the ASF dual-hosted git repository. zhangduo pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/hbase.git
The following commit(s) were added to refs/heads/master by this push: new 3d2580c HBASE-21704 The implementation of DistributedHBaseCluster.getServerHoldingRegion is incorrect 3d2580c is described below commit 3d2580cd6dbe32497543207ae616a9559de94739 Author: Duo Zhang <zhang...@apache.org> AuthorDate: Fri Jan 11 17:45:12 2019 +0800 HBASE-21704 The implementation of DistributedHBaseCluster.getServerHoldingRegion is incorrect --- .../hadoop/hbase/DistributedHBaseCluster.java | 47 +++++++++------------- .../java/org/apache/hadoop/hbase/HBaseCluster.java | 5 ++- 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/hbase-it/src/test/java/org/apache/hadoop/hbase/DistributedHBaseCluster.java b/hbase-it/src/test/java/org/apache/hadoop/hbase/DistributedHBaseCluster.java index 5ec9e25..30a3db9 100644 --- a/hbase-it/src/test/java/org/apache/hadoop/hbase/DistributedHBaseCluster.java +++ b/hbase-it/src/test/java/org/apache/hadoop/hbase/DistributedHBaseCluster.java @@ -25,20 +25,19 @@ import java.util.List; import java.util.Objects; import java.util.Set; import java.util.TreeSet; - import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.hbase.ClusterManager.ServiceType; import org.apache.hadoop.hbase.client.Admin; import org.apache.hadoop.hbase.client.ClusterConnection; import org.apache.hadoop.hbase.client.Connection; import org.apache.hadoop.hbase.client.ConnectionFactory; +import org.apache.hadoop.hbase.client.RegionInfo; import org.apache.hadoop.hbase.client.RegionLocator; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.Threads; import org.apache.yetus.audience.InterfaceAudience; -import org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil; + import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos; -import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.ServerInfo; import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos; import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MasterService; @@ -312,20 +311,16 @@ public class DistributedHBaseCluster extends HBaseCluster { @Override public ServerName getServerHoldingRegion(TableName tn, byte[] regionName) throws IOException { + byte[] startKey = RegionInfo.getStartKey(regionName); HRegionLocation regionLoc = null; try (RegionLocator locator = connection.getRegionLocator(tn)) { - regionLoc = locator.getRegionLocation(regionName, true); + regionLoc = locator.getRegionLocation(startKey, true); } if (regionLoc == null) { - LOG.warn("Cannot find region server holding region " + Bytes.toString(regionName) + - ", start key [" + Bytes.toString(HRegionInfo.getStartKey(regionName)) + "]"); + LOG.warn("Cannot find region server holding region " + Bytes.toStringBinary(regionName)); return null; } - - AdminProtos.AdminService.BlockingInterface client = - ((ClusterConnection)this.connection).getAdmin(regionLoc.getServerName()); - ServerInfo info = ProtobufUtil.getServerInfo(null, client); - return ProtobufUtil.toServerName(info.getServerName()); + return regionLoc.getServerName(); } @Override @@ -366,17 +361,15 @@ public class DistributedHBaseCluster extends HBaseCluster { //check whether current master has changed final ServerName initMaster = initial.getMasterName(); if (!ServerName.isSameAddress(initMaster, current.getMasterName())) { - LOG.info("Restoring cluster - Initial active master : " - + initMaster.getHostAndPort() - + " has changed to : " - + current.getMasterName().getHostAndPort()); + LOG.info("Restoring cluster - Initial active master : " + initMaster.getAddress() + + " has changed to : " + current.getMasterName().getAddress()); // If initial master is stopped, start it, before restoring the state. // It will come up as a backup master, if there is already an active master. try { if (!clusterManager.isRunning(ServiceType.HBASE_MASTER, initMaster.getHostname(), initMaster.getPort())) { LOG.info("Restoring cluster - starting initial active master at:" - + initMaster.getHostAndPort()); + + initMaster.getAddress()); startMaster(initMaster.getHostname(), initMaster.getPort()); } @@ -407,7 +400,7 @@ public class DistributedHBaseCluster extends HBaseCluster { backup.getHostname(), backup.getPort())) { LOG.info("Restoring cluster - starting initial backup master: " - + backup.getHostAndPort()); + + backup.getAddress()); startMaster(backup.getHostname(), backup.getPort()); } } catch (IOException ex) { @@ -431,7 +424,7 @@ public class DistributedHBaseCluster extends HBaseCluster { for (ServerName sn:toStart) { try { if(!clusterManager.isRunning(ServiceType.HBASE_MASTER, sn.getHostname(), sn.getPort())) { - LOG.info("Restoring cluster - starting initial backup master: " + sn.getHostAndPort()); + LOG.info("Restoring cluster - starting initial backup master: " + sn.getAddress()); startMaster(sn.getHostname(), sn.getPort()); } } catch (IOException ex) { @@ -442,7 +435,7 @@ public class DistributedHBaseCluster extends HBaseCluster { for (ServerName sn:toKill) { try { if(clusterManager.isRunning(ServiceType.HBASE_MASTER, sn.getHostname(), sn.getPort())) { - LOG.info("Restoring cluster - stopping backup master: " + sn.getHostAndPort()); + LOG.info("Restoring cluster - stopping backup master: " + sn.getAddress()); stopMaster(sn); } } catch (IOException ex) { @@ -492,11 +485,9 @@ public class DistributedHBaseCluster extends HBaseCluster { for(ServerName sn:toStart) { try { - if (!clusterManager.isRunning(ServiceType.HBASE_REGIONSERVER, - sn.getHostname(), - sn.getPort()) - && master.getPort() != sn.getPort()) { - LOG.info("Restoring cluster - starting initial region server: " + sn.getHostAndPort()); + if (!clusterManager.isRunning(ServiceType.HBASE_REGIONSERVER, sn.getHostname(), + sn.getPort()) && master.getPort() != sn.getPort()) { + LOG.info("Restoring cluster - starting initial region server: " + sn.getAddress()); startRegionServer(sn.getHostname(), sn.getPort()); } } catch (IOException ex) { @@ -506,11 +497,9 @@ public class DistributedHBaseCluster extends HBaseCluster { for(ServerName sn:toKill) { try { - if (clusterManager.isRunning(ServiceType.HBASE_REGIONSERVER, - sn.getHostname(), - sn.getPort()) - && master.getPort() != sn.getPort()){ - LOG.info("Restoring cluster - stopping initial region server: " + sn.getHostAndPort()); + if (clusterManager.isRunning(ServiceType.HBASE_REGIONSERVER, sn.getHostname(), + sn.getPort()) && master.getPort() != sn.getPort()) { + LOG.info("Restoring cluster - stopping initial region server: " + sn.getAddress()); stopRegionServer(sn); } } catch (IOException ex) { diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseCluster.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseCluster.java index a1b474d..d760a7d 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseCluster.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/HBaseCluster.java @@ -22,6 +22,7 @@ import java.io.IOException; import org.apache.hadoop.conf.Configurable; import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.client.RegionInfoBuilder; import org.apache.hadoop.hbase.util.Threads; import org.apache.yetus.audience.InterfaceAudience; import org.slf4j.Logger; @@ -373,7 +374,7 @@ public abstract class HBaseCluster implements Closeable, Configurable { */ public ServerName getServerHoldingMeta() throws IOException { return getServerHoldingRegion(TableName.META_TABLE_NAME, - HRegionInfo.FIRST_META_REGIONINFO.getRegionName()); + RegionInfoBuilder.FIRST_META_REGIONINFO.getRegionName()); } /** @@ -383,7 +384,7 @@ public abstract class HBaseCluster implements Closeable, Configurable { * @return ServerName that hosts the region or null */ public abstract ServerName getServerHoldingRegion(final TableName tn, byte[] regionName) - throws IOException; + throws IOException; /** * @return whether we are interacting with a distributed cluster as opposed to an