Search in sources :

Example 41 with ServerName

use of org.apache.hadoop.hbase.ServerName in project hbase by apache.

the class MetaTableLocator method getMetaRegionState.

/**
   * Load the meta region state from the meta server ZNode.
   * @param zkw
   * @param replicaId
   * @return regionstate
   * @throws KeeperException
   */
public static RegionState getMetaRegionState(ZooKeeperWatcher zkw, int replicaId) throws KeeperException {
    RegionState.State state = RegionState.State.OPEN;
    ServerName serverName = null;
    try {
        byte[] data = ZKUtil.getData(zkw, zkw.znodePaths.getZNodeForReplica(replicaId));
        if (data != null && data.length > 0 && ProtobufUtil.isPBMagicPrefix(data)) {
            try {
                int prefixLen = ProtobufUtil.lengthOfPBMagic();
                ZooKeeperProtos.MetaRegionServer rl = ZooKeeperProtos.MetaRegionServer.PARSER.parseFrom(data, prefixLen, data.length - prefixLen);
                if (rl.hasState()) {
                    state = RegionState.State.convert(rl.getState());
                }
                HBaseProtos.ServerName sn = rl.getServer();
                serverName = ServerName.valueOf(sn.getHostName(), sn.getPort(), sn.getStartCode());
            } catch (InvalidProtocolBufferException e) {
                throw new DeserializationException("Unable to parse meta region location");
            }
        } else {
            // old style of meta region location?
            serverName = ProtobufUtil.parseServerNameFrom(data);
        }
    } catch (DeserializationException e) {
        throw ZKUtil.convert(e);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
    }
    if (serverName == null) {
        state = RegionState.State.OFFLINE;
    }
    return new RegionState(RegionReplicaUtil.getRegionInfoForReplica(HRegionInfo.FIRST_META_REGIONINFO, replicaId), state, serverName);
}
Also used : MetaRegionServer(org.apache.hadoop.hbase.shaded.protobuf.generated.ZooKeeperProtos.MetaRegionServer) RegionState(org.apache.hadoop.hbase.master.RegionState) ServerName(org.apache.hadoop.hbase.ServerName) InvalidProtocolBufferException(org.apache.hadoop.hbase.shaded.com.google.protobuf.InvalidProtocolBufferException) ZooKeeperProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ZooKeeperProtos) HBaseProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos) DeserializationException(org.apache.hadoop.hbase.exceptions.DeserializationException)

Example 42 with ServerName

use of org.apache.hadoop.hbase.ServerName in project hbase by apache.

the class MetaTableLocator method blockUntilAvailable.

/**
   * Wait until the primary meta region is available. Get the secondary
   * locations as well but don't block for those.
   * @param zkw
   * @param timeout
   * @param conf
   * @return ServerName or null if we timed out.
   * @throws InterruptedException
   */
public List<ServerName> blockUntilAvailable(final ZooKeeperWatcher zkw, final long timeout, Configuration conf) throws InterruptedException {
    int numReplicasConfigured = 1;
    List<ServerName> servers = new ArrayList<>();
    // Make the blocking call first so that we do the wait to know
    // the znodes are all in place or timeout.
    ServerName server = blockUntilAvailable(zkw, timeout);
    if (server == null)
        return null;
    servers.add(server);
    try {
        List<String> metaReplicaNodes = zkw.getMetaReplicaNodes();
        numReplicasConfigured = metaReplicaNodes.size();
    } catch (KeeperException e) {
        LOG.warn("Got ZK exception " + e);
    }
    for (int replicaId = 1; replicaId < numReplicasConfigured; replicaId++) {
        // return all replica locations for the meta
        servers.add(getMetaRegionLocation(zkw, replicaId));
    }
    return servers;
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) KeeperException(org.apache.zookeeper.KeeperException)

Example 43 with ServerName

use of org.apache.hadoop.hbase.ServerName in project hbase by apache.

the class MetaTableLocator method getMetaRegionsAndLocations.

/**
   *
   * @param zkw
   * @param replicaId
   * @return meta table regions and their locations.
   */
public List<Pair<HRegionInfo, ServerName>> getMetaRegionsAndLocations(ZooKeeperWatcher zkw, int replicaId) {
    ServerName serverName = getMetaRegionLocation(zkw, replicaId);
    List<Pair<HRegionInfo, ServerName>> list = new ArrayList<>(1);
    list.add(new Pair<>(RegionReplicaUtil.getRegionInfoForReplica(HRegionInfo.FIRST_META_REGIONINFO, replicaId), serverName));
    return list;
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) Pair(org.apache.hadoop.hbase.util.Pair)

Example 44 with ServerName

use of org.apache.hadoop.hbase.ServerName in project hbase by apache.

the class MetaTableLocator method blockUntilAvailable.

/**
   * Wait until the meta region is available and is not in transition.
   * @param zkw
   * @param replicaId
   * @param timeout
   * @return ServerName or null if we timed out.
   * @throws InterruptedException
   */
public ServerName blockUntilAvailable(final ZooKeeperWatcher zkw, int replicaId, final long timeout) throws InterruptedException {
    if (timeout < 0)
        throw new IllegalArgumentException();
    if (zkw == null)
        throw new IllegalArgumentException();
    long startTime = System.currentTimeMillis();
    ServerName sn = null;
    while (true) {
        sn = getMetaRegionLocation(zkw, replicaId);
        if (sn != null || (System.currentTimeMillis() - startTime) > timeout - HConstants.SOCKET_RETRY_WAIT_MS) {
            break;
        }
        Thread.sleep(HConstants.SOCKET_RETRY_WAIT_MS);
    }
    return sn;
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName)

Example 45 with ServerName

use of org.apache.hadoop.hbase.ServerName in project hbase by apache.

the class UnbalanceKillAndRebalanceAction method perform.

@Override
public void perform() throws Exception {
    ClusterStatus status = this.cluster.getClusterStatus();
    List<ServerName> victimServers = new LinkedList<>(status.getServers());
    Set<ServerName> killedServers = new HashSet<>();
    int liveCount = (int) Math.ceil(FRC_SERVERS_THAT_HOARD_AND_LIVE * victimServers.size());
    int deadCount = (int) Math.ceil(FRC_SERVERS_THAT_HOARD_AND_DIE * victimServers.size());
    Assert.assertTrue((liveCount + deadCount) < victimServers.size());
    List<ServerName> targetServers = new ArrayList<>(liveCount);
    for (int i = 0; i < liveCount + deadCount; ++i) {
        int victimIx = RandomUtils.nextInt(victimServers.size());
        targetServers.add(victimServers.remove(victimIx));
    }
    unbalanceRegions(status, victimServers, targetServers, HOARD_FRC_OF_REGIONS);
    Thread.sleep(waitForUnbalanceMilliSec);
    for (int i = 0; i < liveCount; ++i) {
        // trying to stop the monkey.
        if (context.isStopping()) {
            break;
        }
        killRs(targetServers.get(i));
        killedServers.add(targetServers.get(i));
    }
    Thread.sleep(waitForKillsMilliSec);
    forceBalancer();
    Thread.sleep(waitAfterBalanceMilliSec);
    for (ServerName server : killedServers) {
        startRs(server);
    }
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) ClusterStatus(org.apache.hadoop.hbase.ClusterStatus) LinkedList(java.util.LinkedList) HashSet(java.util.HashSet)

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