Search in sources :

Example 6 with NotServingRegionException

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

the class RSRpcServices method replicateToReplica.

/**
 * Replay the given changes on a secondary replica
 */
@Override
public ReplicateWALEntryResponse replicateToReplica(RpcController controller, ReplicateWALEntryRequest request) throws ServiceException {
    CellScanner cells = getAndReset(controller);
    try {
        checkOpen();
        List<WALEntry> entries = request.getEntryList();
        if (entries == null || entries.isEmpty()) {
            // empty input
            return ReplicateWALEntryResponse.newBuilder().build();
        }
        ByteString regionName = entries.get(0).getKey().getEncodedRegionName();
        HRegion region = server.getRegionByEncodedName(regionName.toStringUtf8());
        if (RegionReplicaUtil.isDefaultReplica(region.getRegionInfo())) {
            throw new DoNotRetryIOException("Should not replicate to primary replica " + region.getRegionInfo() + ", CODE BUG?");
        }
        for (WALEntry entry : entries) {
            if (!regionName.equals(entry.getKey().getEncodedRegionName())) {
                throw new NotServingRegionException("ReplicateToReplica request contains entries from multiple " + "regions. First region:" + regionName.toStringUtf8() + " , other region:" + entry.getKey().getEncodedRegionName());
            }
            region.replayWALEntry(entry, cells);
        }
        return ReplicateWALEntryResponse.newBuilder().build();
    } catch (IOException ie) {
        throw new ServiceException(ie);
    }
}
Also used : ServiceException(org.apache.hbase.thirdparty.com.google.protobuf.ServiceException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) ByteString(org.apache.hbase.thirdparty.com.google.protobuf.ByteString) WALEntry(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.WALEntry) IOException(java.io.IOException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) UncheckedIOException(java.io.UncheckedIOException) CellScanner(org.apache.hadoop.hbase.CellScanner)

Example 7 with NotServingRegionException

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

the class HRegionServer method getRegionByEncodedName.

private HRegion getRegionByEncodedName(byte[] regionName, String encodedRegionName) throws NotServingRegionException {
    HRegion region = this.onlineRegions.get(encodedRegionName);
    if (region == null) {
        MovedRegionInfo moveInfo = getMovedRegion(encodedRegionName);
        if (moveInfo != null) {
            throw new RegionMovedException(moveInfo.getServerName(), moveInfo.getSeqNum());
        }
        Boolean isOpening = this.regionsInTransitionInRS.get(Bytes.toBytes(encodedRegionName));
        String regionNameStr = regionName == null ? encodedRegionName : Bytes.toStringBinary(regionName);
        if (isOpening != null && isOpening) {
            throw new RegionOpeningException("Region " + regionNameStr + " is opening on " + this.serverName);
        }
        throw new NotServingRegionException("" + regionNameStr + " is not online on " + this.serverName);
    }
    return region;
}
Also used : RegionOpeningException(org.apache.hadoop.hbase.exceptions.RegionOpeningException) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) RegionMovedException(org.apache.hadoop.hbase.exceptions.RegionMovedException) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean)

Example 8 with NotServingRegionException

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

the class AsyncRpcRetryingCaller method onError.

protected final void onError(Throwable t, Supplier<String> errMsg, Consumer<Throwable> updateCachedLocation) {
    if (future.isDone()) {
        // Give up if the future is already done, this is possible if user has already canceled the
        // future. And for timeline consistent read, we will also cancel some requests if we have
        // already get one of the responses.
        LOG.debug("The future is already done, canceled={}, give up retrying", future.isCancelled());
        return;
    }
    Throwable error = preProcessError(translateException(t));
    // exactly trying to open a new scanner, so we should retry on ScannerResetException.
    if (error instanceof DoNotRetryIOException && !(error instanceof ScannerResetException)) {
        future.completeExceptionally(error);
        return;
    }
    if (tries > startLogErrorsCnt) {
        LOG.warn(errMsg.get() + ", tries = " + tries + ", maxAttempts = " + maxAttempts + ", timeout = " + TimeUnit.NANOSECONDS.toMillis(operationTimeoutNs) + " ms, time elapsed = " + elapsedMs() + " ms", error);
    }
    updateCachedLocation.accept(error);
    RetriesExhaustedException.ThrowableWithExtraContext qt = new RetriesExhaustedException.ThrowableWithExtraContext(error, EnvironmentEdgeManager.currentTime(), "");
    exceptions.add(qt);
    if (tries >= maxAttempts) {
        completeExceptionally();
        return;
    }
    // meta, so here we only check for disabled for some specific exception types.
    if (error instanceof NotServingRegionException || error instanceof RegionOfflineException) {
        Optional<TableName> tableName = getTableName();
        if (tableName.isPresent()) {
            FutureUtils.addListener(conn.getAdmin().isTableDisabled(tableName.get()), (disabled, e) -> {
                if (e != null) {
                    if (e instanceof TableNotFoundException) {
                        future.completeExceptionally(e);
                    } else {
                        // failed to test whether the table is disabled, not a big deal, continue retrying
                        tryScheduleRetry(error);
                    }
                    return;
                }
                if (disabled) {
                    future.completeExceptionally(new TableNotEnabledException(tableName.get()));
                } else {
                    tryScheduleRetry(error);
                }
            });
        } else {
            tryScheduleRetry(error);
        }
    } else {
        tryScheduleRetry(error);
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) DoNotRetryIOException(org.apache.hadoop.hbase.DoNotRetryIOException) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) ScannerResetException(org.apache.hadoop.hbase.exceptions.ScannerResetException) TableNotEnabledException(org.apache.hadoop.hbase.TableNotEnabledException)

Example 9 with NotServingRegionException

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

the class ServerManager method closeRegionSilentlyAndWait.

/**
   * Contacts a region server and waits up to timeout ms
   * to close the region.  This bypasses the active hmaster.
   */
public static void closeRegionSilentlyAndWait(ClusterConnection connection, ServerName server, HRegionInfo region, long timeout) throws IOException, InterruptedException {
    AdminService.BlockingInterface rs = connection.getAdmin(server);
    HBaseRpcController controller = connection.getRpcControllerFactory().newController();
    try {
        ProtobufUtil.closeRegion(controller, rs, server, region.getRegionName());
    } catch (IOException e) {
        LOG.warn("Exception when closing region: " + region.getRegionNameAsString(), e);
    }
    long expiration = timeout + System.currentTimeMillis();
    while (System.currentTimeMillis() < expiration) {
        controller.reset();
        try {
            HRegionInfo rsRegion = ProtobufUtil.getRegionInfo(controller, rs, region.getRegionName());
            if (rsRegion == null)
                return;
        } catch (IOException ioe) {
            if (// no need to retry again
            ioe instanceof NotServingRegionException)
                return;
            LOG.warn("Exception when retrieving regioninfo from: " + region.getRegionNameAsString(), ioe);
        }
        Thread.sleep(1000);
    }
    throw new IOException("Region " + region + " failed to close within" + " timeout " + timeout);
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) AdminService(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) IOException(java.io.IOException)

Example 10 with NotServingRegionException

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

the class HBaseAdmin method getCompactionState.

/**
   * {@inheritDoc}
   */
@Override
public CompactionState getCompactionState(final TableName tableName, CompactType compactType) throws IOException {
    AdminProtos.GetRegionInfoResponse.CompactionState state = AdminProtos.GetRegionInfoResponse.CompactionState.NONE;
    checkTableExists(tableName);
    // TODO: There is no timeout on this controller. Set one!
    final HBaseRpcController rpcController = rpcControllerFactory.newController();
    switch(compactType) {
        case MOB:
            final AdminProtos.AdminService.BlockingInterface masterAdmin = this.connection.getAdmin(getMasterAddress());
            Callable<AdminProtos.GetRegionInfoResponse.CompactionState> callable = new Callable<AdminProtos.GetRegionInfoResponse.CompactionState>() {

                @Override
                public AdminProtos.GetRegionInfoResponse.CompactionState call() throws Exception {
                    HRegionInfo info = getMobRegionInfo(tableName);
                    GetRegionInfoRequest request = RequestConverter.buildGetRegionInfoRequest(info.getRegionName(), true);
                    GetRegionInfoResponse response = masterAdmin.getRegionInfo(rpcController, request);
                    return response.getCompactionState();
                }
            };
            state = ProtobufUtil.call(callable);
            break;
        case NORMAL:
        default:
            ZooKeeperWatcher zookeeper = null;
            try {
                List<Pair<HRegionInfo, ServerName>> pairs;
                if (TableName.META_TABLE_NAME.equals(tableName)) {
                    zookeeper = new ZooKeeperWatcher(conf, ZK_IDENTIFIER_PREFIX + connection.toString(), new ThrowableAbortable());
                    pairs = new MetaTableLocator().getMetaRegionsAndLocations(zookeeper);
                } else {
                    pairs = MetaTableAccessor.getTableRegionsAndLocations(connection, tableName);
                }
                for (Pair<HRegionInfo, ServerName> pair : pairs) {
                    if (pair.getFirst().isOffline())
                        continue;
                    if (pair.getSecond() == null)
                        continue;
                    final ServerName sn = pair.getSecond();
                    final byte[] regionName = pair.getFirst().getRegionName();
                    final AdminService.BlockingInterface snAdmin = this.connection.getAdmin(sn);
                    try {
                        Callable<GetRegionInfoResponse> regionInfoCallable = new Callable<GetRegionInfoResponse>() {

                            @Override
                            public GetRegionInfoResponse call() throws Exception {
                                GetRegionInfoRequest request = RequestConverter.buildGetRegionInfoRequest(regionName, true);
                                return snAdmin.getRegionInfo(rpcController, request);
                            }
                        };
                        GetRegionInfoResponse response = ProtobufUtil.call(regionInfoCallable);
                        switch(response.getCompactionState()) {
                            case MAJOR_AND_MINOR:
                                return CompactionState.MAJOR_AND_MINOR;
                            case MAJOR:
                                if (state == AdminProtos.GetRegionInfoResponse.CompactionState.MINOR) {
                                    return CompactionState.MAJOR_AND_MINOR;
                                }
                                state = AdminProtos.GetRegionInfoResponse.CompactionState.MAJOR;
                                break;
                            case MINOR:
                                if (state == AdminProtos.GetRegionInfoResponse.CompactionState.MAJOR) {
                                    return CompactionState.MAJOR_AND_MINOR;
                                }
                                state = AdminProtos.GetRegionInfoResponse.CompactionState.MINOR;
                                break;
                            case NONE:
                            // nothing, continue
                            default:
                        }
                    } catch (NotServingRegionException e) {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("Trying to get compaction state of " + pair.getFirst() + ": " + StringUtils.stringifyException(e));
                        }
                    } catch (RemoteException e) {
                        if (e.getMessage().indexOf(NotServingRegionException.class.getName()) >= 0) {
                            if (LOG.isDebugEnabled()) {
                                LOG.debug("Trying to get compaction state of " + pair.getFirst() + ": " + StringUtils.stringifyException(e));
                            }
                        } else {
                            throw e;
                        }
                    }
                }
            } finally {
                if (zookeeper != null) {
                    zookeeper.close();
                }
            }
            break;
    }
    if (state != null) {
        return ProtobufUtil.createCompactionState(state);
    }
    return null;
}
Also used : AdminService(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.AdminService) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) Callable(java.util.concurrent.Callable) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HBaseRpcController(org.apache.hadoop.hbase.ipc.HBaseRpcController) MetaTableLocator(org.apache.hadoop.hbase.zookeeper.MetaTableLocator) GetRegionInfoRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoRequest) GetRegionInfoResponse(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.GetRegionInfoResponse) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) AdminProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos) ServerName(org.apache.hadoop.hbase.ServerName) RemoteException(org.apache.hadoop.ipc.RemoteException) Pair(org.apache.hadoop.hbase.util.Pair) NameStringPair(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameStringPair)

Aggregations

NotServingRegionException (org.apache.hadoop.hbase.NotServingRegionException)22 IOException (java.io.IOException)11 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)7 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)5 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)5 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)4 ServerName (org.apache.hadoop.hbase.ServerName)4 Test (org.junit.Test)4 InterruptedIOException (java.io.InterruptedIOException)3 UncheckedIOException (java.io.UncheckedIOException)3 TableName (org.apache.hadoop.hbase.TableName)3 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)3 Pair (org.apache.hadoop.hbase.util.Pair)3 ByteString (org.apache.hbase.thirdparty.com.google.protobuf.ByteString)3 FileNotFoundException (java.io.FileNotFoundException)2 List (java.util.List)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 ExecutionException (java.util.concurrent.ExecutionException)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 CellScanner (org.apache.hadoop.hbase.CellScanner)2