Search in sources :

Example 76 with HRegionLocation

use of org.apache.hadoop.hbase.HRegionLocation 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 77 with HRegionLocation

use of org.apache.hadoop.hbase.HRegionLocation 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 78 with HRegionLocation

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

the class ScannerCallable method next.

private ScanResponse next() throws IOException {
    // Reset the heartbeat flag prior to each RPC in case an exception is thrown by the server
    setHeartbeatMessage(false);
    incRPCcallsMetrics();
    ScanRequest request = RequestConverter.buildScanRequest(scannerId, caching, false, nextCallSeq, this.scanMetrics != null, renew, scan.getLimit());
    try {
        ScanResponse response = getStub().scan(getRpcController(), request);
        nextCallSeq++;
        return response;
    } catch (Exception e) {
        IOException ioe = ProtobufUtil.handleRemoteException(e);
        if (logScannerActivity) {
            LOG.info("Got exception making request " + ProtobufUtil.toText(request) + " to " + getLocation(), e);
        }
        if (logScannerActivity) {
            if (ioe instanceof UnknownScannerException) {
                try {
                    HRegionLocation location = getConnection().relocateRegion(getTableName(), scan.getStartRow());
                    LOG.info("Scanner=" + scannerId + " expired, current region location is " + location.toString());
                } catch (Throwable t) {
                    LOG.info("Failed to relocate region", t);
                }
            } else if (ioe instanceof ScannerResetException) {
                LOG.info("Scanner=" + scannerId + " has received an exception, and the server " + "asked us to reset the scanner state.", ioe);
            }
        }
        // yeah and hard to follow and in need of a refactor).
        if (ioe instanceof NotServingRegionException) {
            // Attach NSRE to signal client that it needs to re-setup scanner.
            if (this.scanMetrics != null) {
                this.scanMetrics.countOfNSRE.incrementAndGet();
            }
            throw new DoNotRetryIOException("Resetting the scanner -- see exception cause", ioe);
        } else if (ioe instanceof RegionServerStoppedException) {
            // open scanner against new location.
            throw new DoNotRetryIOException("Resetting the scanner -- see exception cause", ioe);
        } else {
            // The outer layers will retry
            throw ioe;
        }
    }
}
Also used : ScanRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanRequest) RegionServerStoppedException(org.apache.hadoop.hbase.regionserver.RegionServerStoppedException) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) ScannerResetException(org.apache.hadoop.hbase.exceptions.ScannerResetException) ScanResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.ScanResponse) InterruptedIOException(java.io.InterruptedIOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) InterruptedIOException(java.io.InterruptedIOException) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) RegionServerStoppedException(org.apache.hadoop.hbase.regionserver.RegionServerStoppedException) UnknownScannerException(org.apache.hadoop.hbase.UnknownScannerException) ScannerResetException(org.apache.hadoop.hbase.exceptions.ScannerResetException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) UnknownScannerException(org.apache.hadoop.hbase.UnknownScannerException)

Example 79 with HRegionLocation

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

the class ReversedScannerCallable 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();
    }
    if (!instantiated || reload) {
        // 2. the start row is empty which means we need to locate to the last region.
        if (scan.includeStartRow() && !isEmptyStartRow(getRow())) {
            // Just locate the region with the row
            RegionLocations rl = RpcRetryingCallerWithReadReplicas.getRegionLocations(reload, id, getConnection(), getTableName(), getRow());
            this.location = id < rl.size() ? rl.getRegionLocation(id) : null;
            if (location == null || location.getServerName() == null) {
                throw new IOException("Failed to find location, tableName=" + getTableName() + ", row=" + Bytes.toStringBinary(getRow()) + ", reload=" + reload);
            }
        } else {
            // Need to locate the regions with the range, and the target location is
            // the last one which is the previous region of last region scanner
            byte[] locateStartRow = createCloseRowBefore(getRow());
            List<HRegionLocation> locatedRegions = locateRegionsInRange(locateStartRow, getRow(), reload);
            if (locatedRegions.isEmpty()) {
                throw new DoNotRetryIOException("Does hbase:meta exist hole? Couldn't get regions for the range from " + Bytes.toStringBinary(locateStartRow) + " to " + Bytes.toStringBinary(getRow()));
            }
            this.location = locatedRegions.get(locatedRegions.size() - 1);
        }
        setStub(getConnection().getClient(getLocation().getServerName()));
        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) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) InterruptedIOException(java.io.InterruptedIOException)

Example 80 with HRegionLocation

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

the class ReversedScannerCallable method locateRegionsInRange.

/**
   * Get the corresponding regions for an arbitrary range of keys.
   * @param startKey Starting row in range, inclusive
   * @param endKey Ending row in range, exclusive
   * @param reload force reload of server location
   * @return A list of HRegionLocation corresponding to the regions that contain
   *         the specified range
   * @throws IOException
   */
private List<HRegionLocation> locateRegionsInRange(byte[] startKey, byte[] endKey, boolean reload) throws IOException {
    final boolean endKeyIsEndOfTable = Bytes.equals(endKey, HConstants.EMPTY_END_ROW);
    if ((Bytes.compareTo(startKey, endKey) > 0) && !endKeyIsEndOfTable) {
        throw new IllegalArgumentException("Invalid range: " + Bytes.toStringBinary(startKey) + " > " + Bytes.toStringBinary(endKey));
    }
    List<HRegionLocation> regionList = new ArrayList<>();
    byte[] currentKey = startKey;
    do {
        RegionLocations rl = RpcRetryingCallerWithReadReplicas.getRegionLocations(reload, id, getConnection(), getTableName(), currentKey);
        HRegionLocation regionLocation = id < rl.size() ? rl.getRegionLocation(id) : null;
        if (regionLocation != null && regionLocation.getRegionInfo().containsRow(currentKey)) {
            regionList.add(regionLocation);
        } else {
            throw new DoNotRetryIOException("Does hbase:meta exist hole? Locating row " + Bytes.toStringBinary(currentKey) + " returns incorrect region " + (regionLocation == null ? null : regionLocation.getRegionInfo()));
        }
        currentKey = regionLocation.getRegionInfo().getEndKey();
    } while (!Bytes.equals(currentKey, HConstants.EMPTY_END_ROW) && (endKeyIsEndOfTable || Bytes.compareTo(currentKey, endKey) < 0));
    return regionList;
}
Also used : RegionLocations(org.apache.hadoop.hbase.RegionLocations) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) ArrayList(java.util.ArrayList)

Aggregations

HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)132 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)52 Test (org.junit.Test)50 ServerName (org.apache.hadoop.hbase.ServerName)44 TableName (org.apache.hadoop.hbase.TableName)39 IOException (java.io.IOException)31 RegionLocator (org.apache.hadoop.hbase.client.RegionLocator)30 RegionLocations (org.apache.hadoop.hbase.RegionLocations)29 ArrayList (java.util.ArrayList)25 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)18 Table (org.apache.hadoop.hbase.client.Table)18 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)16 List (java.util.List)12 HashMap (java.util.HashMap)11 Map (java.util.Map)11 Result (org.apache.hadoop.hbase.client.Result)10 MultiRowMutationEndpoint (org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint)10 Connection (org.apache.hadoop.hbase.client.Connection)9 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)9 Admin (org.apache.hadoop.hbase.client.Admin)8