Search in sources :

Example 1 with NextBatchTask

use of org.apache.accumulo.tserver.scan.NextBatchTask in project accumulo by apache.

the class ThriftClientHandler method continueScan.

private ScanResult continueScan(TInfo tinfo, long scanID, SingleScanSession scanSession) throws NoSuchScanIDException, NotServingTabletException, org.apache.accumulo.core.tabletserver.thrift.TooManyFilesException, TSampleNotPresentException {
    if (scanSession.nextBatchTask == null) {
        scanSession.nextBatchTask = new NextBatchTask(server, scanID, scanSession.interruptFlag);
        server.resourceManager.executeReadAhead(scanSession.extent, getScanDispatcher(scanSession.extent), scanSession, scanSession.nextBatchTask);
    }
    ScanBatch bresult;
    try {
        bresult = scanSession.nextBatchTask.get(MAX_TIME_TO_WAIT_FOR_SCAN_RESULT_MILLIS, TimeUnit.MILLISECONDS);
        scanSession.nextBatchTask = null;
    } catch (ExecutionException e) {
        server.sessionManager.removeSession(scanID);
        if (e.getCause() instanceof NotServingTabletException) {
            throw (NotServingTabletException) e.getCause();
        } else if (e.getCause() instanceof TooManyFilesException) {
            throw new org.apache.accumulo.core.tabletserver.thrift.TooManyFilesException(scanSession.extent.toThrift());
        } else if (e.getCause() instanceof SampleNotPresentException) {
            throw new TSampleNotPresentException(scanSession.extent.toThrift());
        } else if (e.getCause() instanceof IOException) {
            sleepUninterruptibly(MAX_TIME_TO_WAIT_FOR_SCAN_RESULT_MILLIS, TimeUnit.MILLISECONDS);
            List<KVEntry> empty = Collections.emptyList();
            bresult = new ScanBatch(empty, true);
            scanSession.nextBatchTask = null;
        } else {
            throw new RuntimeException(e);
        }
    } catch (CancellationException ce) {
        server.sessionManager.removeSession(scanID);
        Tablet tablet = server.getOnlineTablet(scanSession.extent);
        if (tablet == null || tablet.isClosed()) {
            throw new NotServingTabletException(scanSession.extent.toThrift());
        } else {
            throw new NoSuchScanIDException();
        }
    } catch (TimeoutException e) {
        List<TKeyValue> param = Collections.emptyList();
        long timeout = server.getConfiguration().getTimeInMillis(Property.TSERV_CLIENT_TIMEOUT);
        server.sessionManager.removeIfNotAccessed(scanID, timeout);
        return new ScanResult(param, true);
    } catch (Exception t) {
        server.sessionManager.removeSession(scanID);
        log.warn("Failed to get next batch", t);
        throw new RuntimeException(t);
    }
    ScanResult scanResult = new ScanResult(Key.compress(bresult.getResults()), bresult.isMore());
    scanSession.entriesReturned += scanResult.results.size();
    scanSession.batchCount++;
    if (scanResult.more && scanSession.batchCount > scanSession.readaheadThreshold) {
        // start reading next batch while current batch is transmitted
        // to client
        scanSession.nextBatchTask = new NextBatchTask(server, scanID, scanSession.interruptFlag);
        server.resourceManager.executeReadAhead(scanSession.extent, getScanDispatcher(scanSession.extent), scanSession, scanSession.nextBatchTask);
    }
    if (!scanResult.more) {
        closeScan(tinfo, scanID);
    }
    return scanResult;
}
Also used : ScanResult(org.apache.accumulo.core.dataImpl.thrift.ScanResult) MultiScanResult(org.apache.accumulo.core.dataImpl.thrift.MultiScanResult) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) TooManyFilesException(org.apache.accumulo.server.fs.TooManyFilesException) IOException(java.io.IOException) NoSuchScanIDException(org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException) TooManyFilesException(org.apache.accumulo.server.fs.TooManyFilesException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NoSuchScanIDException(org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException) CancellationException(java.util.concurrent.CancellationException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TSampleNotPresentException(org.apache.accumulo.core.tabletserver.thrift.TSampleNotPresentException) ConstraintViolationException(org.apache.accumulo.core.tabletserver.thrift.ConstraintViolationException) TException(org.apache.thrift.TException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) TimeoutException(java.util.concurrent.TimeoutException) TabletClosedException(org.apache.accumulo.tserver.tablet.TabletClosedException) IterationInterruptedException(org.apache.accumulo.core.iteratorsImpl.system.IterationInterruptedException) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) SampleNotPresentException(org.apache.accumulo.core.client.SampleNotPresentException) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) TSampleNotPresentException(org.apache.accumulo.core.tabletserver.thrift.TSampleNotPresentException) SampleNotPresentException(org.apache.accumulo.core.client.SampleNotPresentException) KVEntry(org.apache.accumulo.tserver.tablet.KVEntry) CancellationException(java.util.concurrent.CancellationException) TSampleNotPresentException(org.apache.accumulo.core.tabletserver.thrift.TSampleNotPresentException) ScanBatch(org.apache.accumulo.tserver.tablet.ScanBatch) Tablet(org.apache.accumulo.tserver.tablet.Tablet) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) NextBatchTask(org.apache.accumulo.tserver.scan.NextBatchTask) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Aggregations

IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Collectors.toList (java.util.stream.Collectors.toList)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 SampleNotPresentException (org.apache.accumulo.core.client.SampleNotPresentException)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 ThriftSecurityException (org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException)1 ThriftTableOperationException (org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException)1 MultiScanResult (org.apache.accumulo.core.dataImpl.thrift.MultiScanResult)1 ScanResult (org.apache.accumulo.core.dataImpl.thrift.ScanResult)1 IterationInterruptedException (org.apache.accumulo.core.iteratorsImpl.system.IterationInterruptedException)1 ConstraintViolationException (org.apache.accumulo.core.tabletserver.thrift.ConstraintViolationException)1 NoSuchScanIDException (org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException)1 NotServingTabletException (org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException)1 TSampleNotPresentException (org.apache.accumulo.core.tabletserver.thrift.TSampleNotPresentException)1 TooManyFilesException (org.apache.accumulo.server.fs.TooManyFilesException)1