HBASE-21704 The implementation of DistributedHBaseCluster.getServerHoldingRegion is incorrect

This commit is contained in:
Duo Zhang 2019-01-11 17:45:12 +08:00 committed by zhangduo
parent 2b5b190882
commit 3d2580cd6d
2 changed files with 21 additions and 31 deletions

View File

@ -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) {

View File

@ -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