use of org.apache.hadoop.hbase.ServerName in project hbase by apache.
the class RegionSplitter method getRegionServerCount.
/**
* Alternative getCurrentNrHRS which is no longer available.
* @param connection
* @return Rough count of regionservers out on cluster.
* @throws IOException
*/
private static int getRegionServerCount(final Connection connection) throws IOException {
try (Admin admin = connection.getAdmin()) {
ClusterStatus status = admin.getClusterStatus();
Collection<ServerName> servers = status.getServers();
return servers == null || servers.isEmpty() ? 0 : servers.size();
}
}
use of org.apache.hadoop.hbase.ServerName in project hbase by apache.
the class RegionServerTracker method nodeDeleted.
@Override
public void nodeDeleted(String path) {
if (path.startsWith(watcher.znodePaths.rsZNode)) {
String serverName = ZKUtil.getNodeName(path);
LOG.info("RegionServer ephemeral node deleted, processing expiration [" + serverName + "]");
ServerName sn = ServerName.parseServerName(serverName);
if (!serverManager.isServerOnline(sn)) {
LOG.warn(serverName.toString() + " is not online or isn't known to the master." + "The latter could be caused by a DNS misconfiguration.");
return;
}
remove(sn);
this.serverManager.expireServer(sn);
}
}
use of org.apache.hadoop.hbase.ServerName in project hbase by apache.
the class AbstractFSWALProvider method getServerNameFromWALDirectoryName.
/**
* This function returns region server name from a log file name which is in one of the following
* formats:
* <ul>
* <li>hdfs://<name node>/hbase/.logs/<server name>-splitting/...</li>
* <li>hdfs://<name node>/hbase/.logs/<server name>/...</li>
* </ul>
* @return null if the passed in logFile isn't a valid WAL file path
*/
public static ServerName getServerNameFromWALDirectoryName(Path logFile) {
String logDirName = logFile.getParent().getName();
// We were passed the directory and not a file in it.
if (logDirName.equals(HConstants.HREGION_LOGDIR_NAME)) {
logDirName = logFile.getName();
}
ServerName serverName = null;
if (logDirName.endsWith(SPLITTING_EXT)) {
logDirName = logDirName.substring(0, logDirName.length() - SPLITTING_EXT.length());
}
try {
serverName = ServerName.parseServerName(logDirName);
} catch (IllegalArgumentException | IllegalStateException ex) {
serverName = null;
LOG.warn("Cannot parse a server name from path=" + logFile + "; " + ex.getMessage());
}
if (serverName != null && serverName.getStartcode() < 0) {
LOG.warn("Invalid log file path=" + logFile);
serverName = null;
}
return serverName;
}
use of org.apache.hadoop.hbase.ServerName in project hbase by apache.
the class RequestConverter method buildRegionOpenInfo.
/**
* Create a RegionOpenInfo based on given region info and version of offline node
*/
private static RegionOpenInfo buildRegionOpenInfo(final HRegionInfo region, final List<ServerName> favoredNodes, Boolean openForReplay) {
RegionOpenInfo.Builder builder = RegionOpenInfo.newBuilder();
builder.setRegion(HRegionInfo.convert(region));
if (favoredNodes != null) {
for (ServerName server : favoredNodes) {
builder.addFavoredNodes(ProtobufUtil.toServerName(server));
}
}
if (openForReplay != null) {
builder.setOpenForDistributedLogReplay(openForReplay);
}
return builder.build();
}
use of org.apache.hadoop.hbase.ServerName in project hbase by apache.
the class MasterAddressTracker method deleteIfEquals.
/**
* delete the master znode if its content is same as the parameter
* @param zkw must not be null
* @param content must not be null
*/
public static boolean deleteIfEquals(ZooKeeperWatcher zkw, final String content) {
if (content == null) {
throw new IllegalArgumentException("Content must not be null");
}
try {
Stat stat = new Stat();
byte[] data = ZKUtil.getDataNoWatch(zkw, zkw.znodePaths.masterAddressZNode, stat);
ServerName sn = ProtobufUtil.parseServerNameFrom(data);
if (sn != null && content.equals(sn.toString())) {
return (ZKUtil.deleteNode(zkw, zkw.znodePaths.masterAddressZNode, stat.getVersion()));
}
} catch (KeeperException e) {
LOG.warn("Can't get or delete the master znode", e);
} catch (DeserializationException e) {
LOG.warn("Can't get or delete the master znode", e);
}
return false;
}
Aggregations