Search in sources :

Example 11 with NotServingRegionException

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

the class HBaseAdmin method compact.

/**
   * Compact a table.
   * Asynchronous operation.
   *
   * @param tableName table or region to compact
   * @param columnFamily column family within a table or region
   * @param major True if we are to do a major compaction.
   * @param compactType {@link org.apache.hadoop.hbase.client.CompactType}
   * @throws IOException if a remote or network exception occurs
   */
private void compact(final TableName tableName, final byte[] columnFamily, final boolean major, CompactType compactType) throws IOException {
    switch(compactType) {
        case MOB:
            ServerName master = getMasterAddress();
            compact(master, getMobRegionInfo(tableName), major, columnFamily);
            break;
        case NORMAL:
        default:
            ZooKeeperWatcher zookeeper = null;
            try {
                checkTableExists(tableName);
                zookeeper = new ZooKeeperWatcher(conf, ZK_IDENTIFIER_PREFIX + connection.toString(), new ThrowableAbortable());
                List<Pair<HRegionInfo, ServerName>> pairs;
                if (TableName.META_TABLE_NAME.equals(tableName)) {
                    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;
                    try {
                        compact(pair.getSecond(), pair.getFirst(), major, columnFamily);
                    } catch (NotServingRegionException e) {
                        if (LOG.isDebugEnabled()) {
                            LOG.debug("Trying to" + (major ? " major" : "") + " compact " + pair.getFirst() + ": " + StringUtils.stringifyException(e));
                        }
                    }
                }
            } finally {
                if (zookeeper != null) {
                    zookeeper.close();
                }
            }
            break;
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) MetaTableLocator(org.apache.hadoop.hbase.zookeeper.MetaTableLocator) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) ServerName(org.apache.hadoop.hbase.ServerName) Pair(org.apache.hadoop.hbase.util.Pair) NameStringPair(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameStringPair)

Example 12 with NotServingRegionException

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

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

the class UpsertSelectOverlappingBatchesIT method testSplitDuringUpsertSelect.

/**
 * Tests that splitting a region is not blocked indefinitely by UPSERT SELECT load
 */
@Test
public void testSplitDuringUpsertSelect() throws Exception {
    int numUpsertSelectRunners = 4;
    ExecutorService exec = Executors.newFixedThreadPool(numUpsertSelectRunners);
    try (Connection conn = driver.connect(url, props)) {
        final UpsertSelectRunner upsertSelectRunner = new UpsertSelectRunner(dataTable, 0, 105, 1);
        // keep running slow upsert selects
        SlowBatchRegionObserver.SLOW_MUTATE = true;
        for (int i = 0; i < numUpsertSelectRunners; i++) {
            exec.submit(new UpsertSelectLooper(upsertSelectRunner));
            Thread.sleep(300);
        }
        // keep trying to split the region
        final HBaseTestingUtility utility = getUtility();
        final HBaseAdmin admin = utility.getHBaseAdmin();
        final TableName dataTN = TableName.valueOf(dataTable);
        assertEquals(1, utility.getHBaseCluster().getRegions(dataTN).size());
        utility.waitFor(60000L, 1000, new Waiter.Predicate<Exception>() {

            @Override
            public boolean evaluate() throws Exception {
                try {
                    List<HRegionInfo> regions = admin.getTableRegions(dataTN);
                    if (regions.size() > 1) {
                        logger.info("Found region was split");
                        return true;
                    }
                    if (regions.size() == 0) {
                        // This happens when region in transition or closed
                        logger.info("No region returned");
                        return false;
                    }
                    ;
                    HRegionInfo hRegion = regions.get(0);
                    logger.info("Attempting to split region");
                    admin.splitRegion(hRegion.getRegionName(), Bytes.toBytes(2));
                    return false;
                } catch (NotServingRegionException nsre) {
                    // during split
                    return false;
                }
            }
        });
    } finally {
        SlowBatchRegionObserver.SLOW_MUTATE = false;
        exec.shutdownNow();
        exec.awaitTermination(60, TimeUnit.SECONDS);
    }
}
Also used : NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) Connection(java.sql.Connection) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) HBaseIOException(org.apache.hadoop.hbase.HBaseIOException) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HBaseAdmin(org.apache.hadoop.hbase.client.HBaseAdmin) TableName(org.apache.hadoop.hbase.TableName) HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) ExecutorService(java.util.concurrent.ExecutorService) List(java.util.List) Waiter(org.apache.hadoop.hbase.Waiter) Test(org.junit.Test)

Example 14 with NotServingRegionException

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

the class TestTableInputFormat method createDNRIOEScannerTable.

/**
 * Create a table that throws a NotServingRegionException on first scanner
 * next call
 *
 * @throws IOException
 */
static Table createDNRIOEScannerTable(byte[] name, final int failCnt) throws IOException {
    // build up a mock scanner stuff to fail the first time
    Answer<ResultScanner> a = new Answer<ResultScanner>() {

        int cnt = 0;

        @Override
        public ResultScanner answer(InvocationOnMock invocation) throws Throwable {
            // first invocation return the busted mock scanner
            if (cnt++ < failCnt) {
                // create mock ResultScanner that always fails.
                Scan scan = mock(Scan.class);
                // avoid npe
                doReturn(Bytes.toBytes("bogus")).when(scan).getStartRow();
                ResultScanner scanner = mock(ResultScanner.class);
                // simulate NotServingRegionException
                invocation.callRealMethod();
                doThrow(new NotServingRegionException("Injected simulated TimeoutException")).when(scanner).next();
                return scanner;
            }
            // otherwise return the real scanner.
            return (ResultScanner) invocation.callRealMethod();
        }
    };
    Table htable = spy(createTable(name));
    doAnswer(a).when(htable).getScanner((Scan) anyObject());
    return htable;
}
Also used : Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Table(org.apache.hadoop.hbase.client.Table) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Scan(org.apache.hadoop.hbase.client.Scan)

Example 15 with NotServingRegionException

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

the class TestTableInputFormat method createDNRIOEScannerTable.

/**
 * Create a table that throws a DoNoRetryIOException on first scanner next
 * call
 *
 * @throws IOException
 */
static Table createDNRIOEScannerTable(byte[] name, final int failCnt) throws IOException {
    // build up a mock scanner stuff to fail the first time
    Answer<ResultScanner> a = new Answer<ResultScanner>() {

        int cnt = 0;

        @Override
        public ResultScanner answer(InvocationOnMock invocation) throws Throwable {
            // first invocation return the busted mock scanner
            if (cnt++ < failCnt) {
                // create mock ResultScanner that always fails.
                Scan scan = mock(Scan.class);
                // avoid npe
                doReturn(Bytes.toBytes("bogus")).when(scan).getStartRow();
                ResultScanner scanner = mock(ResultScanner.class);
                // simulate NotServingRegionException
                invocation.callRealMethod();
                doThrow(new NotServingRegionException("Injected simulated TimeoutException")).when(scanner).next();
                return scanner;
            }
            // otherwise return the real scanner.
            return (ResultScanner) invocation.callRealMethod();
        }
    };
    Table htable = spy(createTable(name));
    doAnswer(a).when(htable).getScanner((Scan) anyObject());
    return htable;
}
Also used : Mockito.doAnswer(org.mockito.Mockito.doAnswer) Answer(org.mockito.stubbing.Answer) ResultScanner(org.apache.hadoop.hbase.client.ResultScanner) Table(org.apache.hadoop.hbase.client.Table) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Scan(org.apache.hadoop.hbase.client.Scan)

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