Search in sources :

Example 21 with RegionLocations

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

the class TestAsyncProcess method createHConnection.

private static ClusterConnection createHConnection() throws IOException {
    ClusterConnection hc = createHConnectionCommon();
    setMockLocation(hc, DUMMY_BYTES_1, new RegionLocations(loc1));
    setMockLocation(hc, DUMMY_BYTES_2, new RegionLocations(loc2));
    setMockLocation(hc, DUMMY_BYTES_3, new RegionLocations(loc3));
    Mockito.when(hc.locateRegions(Mockito.eq(DUMMY_TABLE), Mockito.anyBoolean(), Mockito.anyBoolean())).thenReturn(Arrays.asList(loc1, loc2, loc3));
    setMockLocation(hc, FAILS, new RegionLocations(loc2));
    return hc;
}
Also used : RegionLocations(org.apache.hadoop.hbase.RegionLocations)

Example 22 with RegionLocations

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

the class ZKAsyncRegistry method getMetaRegionLocation.

@Override
public CompletableFuture<RegionLocations> getMetaRegionLocation() {
    CompletableFuture<RegionLocations> future = new CompletableFuture<>();
    HRegionLocation[] locs = new HRegionLocation[znodePaths.metaReplicaZNodes.size()];
    MutableInt remaining = new MutableInt(locs.length);
    znodePaths.metaReplicaZNodes.forEach((replicaId, path) -> {
        if (replicaId == DEFAULT_REPLICA_ID) {
            exec(zk.getData(), path, ZKAsyncRegistry::getMetaProto).whenComplete((proto, error) -> {
                if (error != null) {
                    future.completeExceptionally(error);
                    return;
                }
                if (proto == null) {
                    future.completeExceptionally(new IOException("Meta znode is null"));
                    return;
                }
                Pair<RegionState.State, ServerName> stateAndServerName = getStateAndServerName(proto);
                if (stateAndServerName.getFirst() != RegionState.State.OPEN) {
                    future.completeExceptionally(new IOException("Meta region is in state " + stateAndServerName.getFirst()));
                    return;
                }
                locs[DEFAULT_REPLICA_ID] = new HRegionLocation(getRegionInfoForDefaultReplica(FIRST_META_REGIONINFO), stateAndServerName.getSecond());
                tryComplete(remaining, locs, future);
            });
        } else {
            exec(zk.getData(), path, ZKAsyncRegistry::getMetaProto).whenComplete((proto, error) -> {
                if (future.isDone()) {
                    return;
                }
                if (error != null) {
                    LOG.warn("Failed to fetch " + path, error);
                    locs[replicaId] = null;
                } else if (proto == null) {
                    LOG.warn("Meta znode for replica " + replicaId + " is null");
                    locs[replicaId] = null;
                } else {
                    Pair<RegionState.State, ServerName> stateAndServerName = getStateAndServerName(proto);
                    if (stateAndServerName.getFirst() != RegionState.State.OPEN) {
                        LOG.warn("Meta region for replica " + replicaId + " is in state " + stateAndServerName.getFirst());
                        locs[replicaId] = null;
                    } else {
                        locs[replicaId] = new HRegionLocation(getRegionInfoForReplica(FIRST_META_REGIONINFO, replicaId), stateAndServerName.getSecond());
                    }
                }
                tryComplete(remaining, locs, future);
            });
        }
    });
    return future;
}
Also used : RegionLocations(org.apache.hadoop.hbase.RegionLocations) CompletableFuture(java.util.concurrent.CompletableFuture) RegionState(org.apache.hadoop.hbase.master.RegionState) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) RegionState(org.apache.hadoop.hbase.master.RegionState) MutableInt(org.apache.commons.lang.mutable.MutableInt) ServerName(org.apache.hadoop.hbase.ServerName) IOException(java.io.IOException) Pair(org.apache.hadoop.hbase.util.Pair)

Example 23 with RegionLocations

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

the class RegionAdminServiceCallable method getLocation.

public HRegionLocation getLocation(boolean useCache) throws IOException {
    RegionLocations rl = getRegionLocations(connection, tableName, row, useCache, replicaId);
    if (rl == null) {
        throw new HBaseIOException(getExceptionMessage());
    }
    HRegionLocation location = rl.getRegionLocation(replicaId);
    if (location == null) {
        throw new HBaseIOException(getExceptionMessage());
    }
    return location;
}
Also used : RegionLocations(org.apache.hadoop.hbase.RegionLocations) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException)

Example 24 with RegionLocations

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

the class MetaCache method getCachedLocation.

/**
   * Search the cache for a location that fits our table and row key.
   * Return null if no suitable region is located.
   *
   * @return Null or region location found in cache.
   */
public RegionLocations getCachedLocation(final TableName tableName, final byte[] row) {
    ConcurrentNavigableMap<byte[], RegionLocations> tableLocations = getTableLocations(tableName);
    Entry<byte[], RegionLocations> e = tableLocations.floorEntry(row);
    if (e == null) {
        if (metrics != null)
            metrics.incrMetaCacheMiss();
        return null;
    }
    RegionLocations possibleRegion = e.getValue();
    // make sure that the end key is greater than the row we're looking
    // for, otherwise the row actually belongs in the next region, not
    // this one. the exception case is when the endkey is
    // HConstants.EMPTY_END_ROW, signifying that the region we're
    // checking is actually the last region in the table.
    byte[] endKey = possibleRegion.getRegionLocation().getRegionInfo().getEndKey();
    // HConstants.EMPTY_END_ROW) check itself will pass.
    if (Bytes.equals(endKey, HConstants.EMPTY_END_ROW) || Bytes.compareTo(endKey, 0, endKey.length, row, 0, row.length) > 0) {
        if (metrics != null)
            metrics.incrMetaCacheHit();
        return possibleRegion;
    }
    // Passed all the way through, so we got nothing - complete cache miss
    if (metrics != null)
        metrics.incrMetaCacheMiss();
    return null;
}
Also used : RegionLocations(org.apache.hadoop.hbase.RegionLocations)

Example 25 with RegionLocations

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

the class ScannerCallable method prepare.

/**
   * @param reload force reload of server location
   * @throws IOException
   */
@Override
public void prepare(boolean reload) throws IOException {
    if (Thread.interrupted()) {
        throw new InterruptedIOException();
    }
    RegionLocations rl = RpcRetryingCallerWithReadReplicas.getRegionLocations(!reload, id, getConnection(), getTableName(), getRow());
    location = id < rl.size() ? rl.getRegionLocation(id) : null;
    if (location == null || location.getServerName() == null) {
        //  when the table is created or after a split.
        throw new HBaseIOException("There is no location for replica id #" + id);
    }
    ServerName dest = location.getServerName();
    setStub(super.getConnection().getClient(dest));
    if (!instantiated || reload) {
        checkIfRegionServerIsRemote();
        instantiated = true;
    }
    // check how often we retry.
    if (reload && this.scanMetrics != null) {
        this.scanMetrics.countOfRPCRetries.incrementAndGet();
        if (isRegionServerRemote) {
            this.scanMetrics.countOfRemoteRPCRetries.incrementAndGet();
        }
    }
}
Also used : InterruptedIOException(java.io.InterruptedIOException) RegionLocations(org.apache.hadoop.hbase.RegionLocations) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) ServerName(org.apache.hadoop.hbase.ServerName)

Aggregations

RegionLocations (org.apache.hadoop.hbase.RegionLocations)47 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)28 ServerName (org.apache.hadoop.hbase.ServerName)18 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)13 Test (org.junit.Test)9 IOException (java.io.IOException)8 InterruptedIOException (java.io.InterruptedIOException)7 ArrayList (java.util.ArrayList)6 Result (org.apache.hadoop.hbase.client.Result)6 TableName (org.apache.hadoop.hbase.TableName)5 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)4 MetaTableAccessor (org.apache.hadoop.hbase.MetaTableAccessor)4 Pair (org.apache.hadoop.hbase.util.Pair)4 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)2 CancellationException (java.util.concurrent.CancellationException)2 ExecutionException (java.util.concurrent.ExecutionException)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)2 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)2