Search in sources :

Example 31 with HRegionLocation

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

the class MetaCache method clearCache.

/**
   * Deletes the cached location of the region if necessary, based on some error from source.
   * @param hri The region in question.
   */
public void clearCache(HRegionInfo hri) {
    ConcurrentMap<byte[], RegionLocations> tableLocations = getTableLocations(hri.getTable());
    RegionLocations regionLocations = tableLocations.get(hri.getStartKey());
    if (regionLocations != null) {
        HRegionLocation oldLocation = regionLocations.getRegionLocation(hri.getReplicaId());
        if (oldLocation == null)
            return;
        RegionLocations updatedLocations = regionLocations.remove(oldLocation);
        boolean removed;
        if (updatedLocations != regionLocations) {
            if (updatedLocations.isEmpty()) {
                removed = tableLocations.remove(hri.getStartKey(), regionLocations);
            } else {
                removed = tableLocations.replace(hri.getStartKey(), regionLocations, updatedLocations);
            }
            if (removed) {
                if (metrics != null) {
                    metrics.incrMetaCacheNumClearRegion();
                }
                if (LOG.isTraceEnabled()) {
                    LOG.trace("Removed " + oldLocation + " from cache");
                }
            }
        }
    }
}
Also used : RegionLocations(org.apache.hadoop.hbase.RegionLocations) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation)

Example 32 with HRegionLocation

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

the class MetaCache method cacheLocation.

/**
   * Put a newly discovered HRegionLocation into the cache.
   * @param tableName The table name.
   * @param source the source of the new location
   * @param location the new location
   */
public void cacheLocation(final TableName tableName, final ServerName source, final HRegionLocation location) {
    assert source != null;
    byte[] startKey = location.getRegionInfo().getStartKey();
    ConcurrentMap<byte[], RegionLocations> tableLocations = getTableLocations(tableName);
    RegionLocations locations = new RegionLocations(new HRegionLocation[] { location });
    RegionLocations oldLocations = tableLocations.putIfAbsent(startKey, locations);
    boolean isNewCacheEntry = (oldLocations == null);
    if (isNewCacheEntry) {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Cached location: " + location);
        }
        addToCachedServers(locations);
        return;
    }
    // If the server in cache sends us a redirect, assume it's always valid.
    HRegionLocation oldLocation = oldLocations.getRegionLocation(location.getRegionInfo().getReplicaId());
    boolean force = oldLocation != null && oldLocation.getServerName() != null && oldLocation.getServerName().equals(source);
    // For redirect if the number is equal to previous
    // record, the most common case is that first the region was closed with seqNum, and then
    // opened with the same seqNum; hence we will ignore the redirect.
    // There are so many corner cases with various combinations of opens and closes that
    // an additional counter on top of seqNum would be necessary to handle them all.
    RegionLocations updatedLocations = oldLocations.updateLocation(location, false, force);
    if (oldLocations != updatedLocations) {
        boolean replaced = tableLocations.replace(startKey, oldLocations, updatedLocations);
        if (replaced && LOG.isTraceEnabled()) {
            LOG.trace("Changed cached location to: " + location);
        }
        addToCachedServers(updatedLocations);
    }
}
Also used : RegionLocations(org.apache.hadoop.hbase.RegionLocations) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation)

Example 33 with HRegionLocation

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

the class RpcRetryingCallerWithReadReplicas method addCallsForReplica.

/**
   * Creates the calls and submit them
   *
   * @param cs  - the completion service to use for submitting
   * @param rl  - the region locations
   * @param min - the id of the first replica, inclusive
   * @param max - the id of the last replica, inclusive.
   */
private void addCallsForReplica(ResultBoundedCompletionService<Result> cs, RegionLocations rl, int min, int max) {
    for (int id = min; id <= max; id++) {
        HRegionLocation hrl = rl.getRegionLocation(id);
        ReplicaRegionServerCallable callOnReplica = new ReplicaRegionServerCallable(id, hrl);
        cs.submit(callOnReplica, operationTimeout, id);
    }
}
Also used : HRegionLocation(org.apache.hadoop.hbase.HRegionLocation)

Example 34 with HRegionLocation

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

the class ZooKeeperRegistry method getMetaRegionLocation.

@Override
public RegionLocations getMetaRegionLocation() throws IOException {
    ZooKeeperKeepAliveConnection zkw = hci.getKeepAliveZooKeeperWatcher();
    try {
        if (LOG.isTraceEnabled()) {
            LOG.trace("Looking up meta region location in ZK," + " connection=" + this);
        }
        List<ServerName> servers = new MetaTableLocator().blockUntilAvailable(zkw, hci.rpcTimeout, hci.getConfiguration());
        if (LOG.isTraceEnabled()) {
            if (servers == null) {
                LOG.trace("Looked up meta region location, connection=" + this + "; servers = null");
            } else {
                StringBuilder str = new StringBuilder();
                for (ServerName s : servers) {
                    str.append(s.toString());
                    str.append(" ");
                }
                LOG.trace("Looked up meta region location, connection=" + this + "; servers = " + str.toString());
            }
        }
        if (servers == null)
            return null;
        HRegionLocation[] locs = new HRegionLocation[servers.size()];
        int i = 0;
        for (ServerName server : servers) {
            HRegionInfo h = RegionReplicaUtil.getRegionInfoForReplica(HRegionInfo.FIRST_META_REGIONINFO, i);
            if (server == null)
                locs[i++] = null;
            else
                locs[i++] = new HRegionLocation(h, server, 0);
        }
        return new RegionLocations(locs);
    } catch (InterruptedException e) {
        Thread.currentThread().interrupt();
        return null;
    } finally {
        zkw.close();
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) RegionLocations(org.apache.hadoop.hbase.RegionLocations) MetaTableLocator(org.apache.hadoop.hbase.zookeeper.MetaTableLocator) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ServerName(org.apache.hadoop.hbase.ServerName)

Example 35 with HRegionLocation

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

the class MultiServerCallable method reset.

public void reset(ServerName location, MultiAction multiAction) {
    this.location = new HRegionLocation(null, location);
    this.multiAction = multiAction;
    this.cellBlock = isCellBlock();
}
Also used : HRegionLocation(org.apache.hadoop.hbase.HRegionLocation)

Aggregations

HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)213 Test (org.junit.Test)74 ServerName (org.apache.hadoop.hbase.ServerName)67 TableName (org.apache.hadoop.hbase.TableName)58 IOException (java.io.IOException)53 RegionLocations (org.apache.hadoop.hbase.RegionLocations)50 RegionLocator (org.apache.hadoop.hbase.client.RegionLocator)46 ArrayList (java.util.ArrayList)44 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)35 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)27 Table (org.apache.hadoop.hbase.client.Table)21 List (java.util.List)19 Map (java.util.Map)15 Connection (org.apache.hadoop.hbase.client.Connection)15 Configuration (org.apache.hadoop.conf.Configuration)14 HashMap (java.util.HashMap)13 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)13 MultiRowMutationEndpoint (org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint)13 CompletableFuture (java.util.concurrent.CompletableFuture)12 Admin (org.apache.hadoop.hbase.client.Admin)12