Search in sources :

Example 46 with DoNotRetryIOException

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

the class RegionCoprocessorRpcChannelImpl method rpcCall.

private CompletableFuture<Message> rpcCall(MethodDescriptor method, Message request, Message responsePrototype, HBaseRpcController controller, HRegionLocation loc, ClientService.Interface stub) {
    CompletableFuture<Message> future = new CompletableFuture<>();
    if (region != null && !Bytes.equals(loc.getRegionInfo().getRegionName(), region.getRegionName())) {
        future.completeExceptionally(new DoNotRetryIOException("Region name is changed, expected " + region.getRegionNameAsString() + ", actual " + loc.getRegionInfo().getRegionNameAsString()));
        return future;
    }
    CoprocessorServiceRequest csr = CoprocessorRpcUtils.getCoprocessorServiceRequest(method, request, row, loc.getRegionInfo().getRegionName());
    stub.execService(controller, csr, new org.apache.hadoop.hbase.shaded.com.google.protobuf.RpcCallback<CoprocessorServiceResponse>() {

        @Override
        public void run(CoprocessorServiceResponse resp) {
            if (controller.failed()) {
                future.completeExceptionally(controller.getFailed());
            } else {
                try {
                    future.complete(CoprocessorRpcUtils.getResponse(resp, responsePrototype));
                } catch (IOException e) {
                    future.completeExceptionally(e);
                }
            }
        }
    });
    return future;
}
Also used : Message(com.google.protobuf.Message) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) IOException(java.io.IOException) CompletableFuture(java.util.concurrent.CompletableFuture) CoprocessorServiceRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceRequest) CoprocessorServiceResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.CoprocessorServiceResponse)

Example 47 with DoNotRetryIOException

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

the class MultiServerCallable method rpcCall.

@Override
protected MultiResponse rpcCall() throws Exception {
    int countOfActions = this.multiAction.size();
    if (countOfActions <= 0)
        throw new DoNotRetryIOException("No Actions");
    MultiRequest.Builder multiRequestBuilder = MultiRequest.newBuilder();
    RegionAction.Builder regionActionBuilder = RegionAction.newBuilder();
    ClientProtos.Action.Builder actionBuilder = ClientProtos.Action.newBuilder();
    MutationProto.Builder mutationBuilder = MutationProto.newBuilder();
    List<CellScannable> cells = null;
    // The multi object is a list of Actions by region.  Iterate by region.
    long nonceGroup = multiAction.getNonceGroup();
    if (nonceGroup != HConstants.NO_NONCE) {
        multiRequestBuilder.setNonceGroup(nonceGroup);
    }
    for (Map.Entry<byte[], List<Action>> e : this.multiAction.actions.entrySet()) {
        final byte[] regionName = e.getKey();
        final List<Action> actions = e.getValue();
        regionActionBuilder.clear();
        regionActionBuilder.setRegion(RequestConverter.buildRegionSpecifier(HBaseProtos.RegionSpecifier.RegionSpecifierType.REGION_NAME, regionName));
        if (this.cellBlock) {
            // Pre-size. Presume at least a KV per Action.  There are likely more.
            if (cells == null)
                cells = new ArrayList<>(countOfActions);
            // Send data in cellblocks. The call to buildNoDataMultiRequest will skip RowMutations.
            // They have already been handled above. Guess at count of cells
            regionActionBuilder = RequestConverter.buildNoDataRegionAction(regionName, actions, cells, regionActionBuilder, actionBuilder, mutationBuilder);
        } else {
            regionActionBuilder = RequestConverter.buildRegionAction(regionName, actions, regionActionBuilder, actionBuilder, mutationBuilder);
        }
        multiRequestBuilder.addRegionAction(regionActionBuilder.build());
    }
    if (cells != null) {
        setRpcControllerCellScanner(CellUtil.createCellScanner(cells));
    }
    ClientProtos.MultiRequest requestProto = multiRequestBuilder.build();
    ClientProtos.MultiResponse responseProto = getStub().multi(getRpcController(), requestProto);
    // Occurs on cancel
    if (responseProto == null)
        return null;
    return ResponseConverter.getResults(requestProto, responseProto, getRpcControllerCellScanner());
}
Also used : CellScannable(org.apache.hadoop.hbase.CellScannable) MultiRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MultiRequest) RegionAction(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionAction) MultiRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MultiRequest) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) ArrayList(java.util.ArrayList) RegionAction(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.RegionAction) MutationProto(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) ClientProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos)

Example 48 with DoNotRetryIOException

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

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

use of org.apache.hadoop.hbase.DoNotRetryIOException 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

DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)77 IOException (java.io.IOException)28 Cell (org.apache.hadoop.hbase.Cell)18 ArrayList (java.util.ArrayList)12 ServiceException (org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException)12 MutationType (org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos.MutationProto.MutationType)12 TableName (org.apache.hadoop.hbase.TableName)11 InterruptedIOException (java.io.InterruptedIOException)10 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)10 Delete (org.apache.hadoop.hbase.client.Delete)10 Put (org.apache.hadoop.hbase.client.Put)10 Test (org.junit.Test)10 AccessDeniedException (org.apache.hadoop.hbase.security.AccessDeniedException)9 User (org.apache.hadoop.hbase.security.User)8 Mutation (org.apache.hadoop.hbase.client.Mutation)7 ByteString (org.apache.hadoop.hbase.shaded.com.google.protobuf.ByteString)7 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)6 NameBytesPair (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameBytesPair)6 ByteBufferCell (org.apache.hadoop.hbase.ByteBufferCell)5 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)5