Search in sources :

Example 36 with ServerName

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();
    }
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) Admin(org.apache.hadoop.hbase.client.Admin) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus)

Example 37 with ServerName

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);
    }
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName)

Example 38 with ServerName

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://&lt;name node&gt;/hbase/.logs/&lt;server name&gt;-splitting/...</li>
   * <li>hdfs://&lt;name node&gt;/hbase/.logs/&lt;server name&gt;/...</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;
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName)

Example 39 with 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();
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) RegionOpenInfo(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.OpenRegionRequest.RegionOpenInfo)

Example 40 with ServerName

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;
}
Also used : Stat(org.apache.zookeeper.data.Stat) ServerName(org.apache.hadoop.hbase.ServerName) KeeperException(org.apache.zookeeper.KeeperException) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException)

Aggregations

ServerName (org.apache.hadoop.hbase.ServerName)426 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)202 Test (org.junit.Test)163 ArrayList (java.util.ArrayList)97 TableName (org.apache.hadoop.hbase.TableName)89 IOException (java.io.IOException)87 HashMap (java.util.HashMap)81 List (java.util.List)72 Map (java.util.Map)54 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)45 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)34 Table (org.apache.hadoop.hbase.client.Table)33 HashSet (java.util.HashSet)32 TreeMap (java.util.TreeMap)31 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)29 Configuration (org.apache.hadoop.conf.Configuration)26 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)26 Pair (org.apache.hadoop.hbase.util.Pair)24 KeeperException (org.apache.zookeeper.KeeperException)23 InterruptedIOException (java.io.InterruptedIOException)22