Search in sources :

Example 1 with TooManyFilesException

use of org.apache.accumulo.server.fs.TooManyFilesException 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)

Example 2 with TooManyFilesException

use of org.apache.accumulo.server.fs.TooManyFilesException in project accumulo by apache.

the class Tablet method lookup.

private LookupResult lookup(SortedKeyValueIterator<Key, Value> mmfi, List<Range> ranges, List<KVEntry> results, ScanParameters scanParams, long maxResultsSize) throws IOException {
    LookupResult lookupResult = new LookupResult();
    boolean exceededMemoryUsage = false;
    boolean tabletClosed = false;
    Set<ByteSequence> cfset = null;
    if (!scanParams.getColumnSet().isEmpty()) {
        cfset = LocalityGroupUtil.families(scanParams.getColumnSet());
    }
    long batchTimeOut = scanParams.getBatchTimeOut();
    long timeToRun = TimeUnit.MILLISECONDS.toNanos(batchTimeOut);
    long startNanos = System.nanoTime();
    if (batchTimeOut <= 0 || batchTimeOut == Long.MAX_VALUE) {
        batchTimeOut = 0;
    }
    // determine if the iterator supported yielding
    YieldCallback<Key> yield = new YieldCallback<>();
    mmfi.enableYielding(yield);
    boolean yielded = false;
    for (Range range : ranges) {
        boolean timesUp = batchTimeOut > 0 && (System.nanoTime() - startNanos) > timeToRun;
        if (exceededMemoryUsage || tabletClosed || timesUp || yielded) {
            lookupResult.unfinishedRanges.add(range);
            continue;
        }
        int entriesAdded = 0;
        try {
            if (cfset != null) {
                mmfi.seek(range, cfset, true);
            } else {
                mmfi.seek(range, Set.of(), false);
            }
            while (mmfi.hasTop()) {
                if (yield.hasYielded()) {
                    throw new IOException("Coding error: hasTop returned true but has yielded at " + yield.getPositionAndReset());
                }
                Key key = mmfi.getTopKey();
                KVEntry kve = new KVEntry(key, mmfi.getTopValue());
                results.add(kve);
                entriesAdded++;
                lookupResult.bytesAdded += kve.estimateMemoryUsed();
                lookupResult.dataSize += kve.numBytes();
                exceededMemoryUsage = lookupResult.bytesAdded > maxResultsSize;
                timesUp = batchTimeOut > 0 && (System.nanoTime() - startNanos) > timeToRun;
                if (exceededMemoryUsage || timesUp) {
                    addUnfinishedRange(lookupResult, range, key);
                    break;
                }
                mmfi.next();
            }
            if (yield.hasYielded()) {
                yielded = true;
                Key yieldPosition = yield.getPositionAndReset();
                if (!range.contains(yieldPosition)) {
                    throw new IOException("Underlying iterator yielded to a position outside of its range: " + yieldPosition + " not in " + range);
                }
                if (!results.isEmpty() && yieldPosition.compareTo(results.get(results.size() - 1).getKey()) <= 0) {
                    throw new IOException("Underlying iterator yielded to a position" + " that does not follow the last key returned: " + yieldPosition + " <= " + results.get(results.size() - 1).getKey());
                }
                addUnfinishedRange(lookupResult, range, yieldPosition);
                log.debug("Scan yield detected at position " + yieldPosition);
                getTabletServer().getScanMetrics().addYield(1);
            }
        } catch (TooManyFilesException tmfe) {
            // treat this as a closed tablet, and let the client retry
            log.warn("Tablet {} has too many files, batch lookup can not run", getExtent());
            handleTabletClosedDuringScan(results, lookupResult, exceededMemoryUsage, range, entriesAdded);
            tabletClosed = true;
        } catch (IOException ioe) {
            if (ShutdownUtil.isShutdownInProgress()) {
                // assume HDFS shutdown hook caused this exception
                log.debug("IOException while shutdown in progress", ioe);
                handleTabletClosedDuringScan(results, lookupResult, exceededMemoryUsage, range, entriesAdded);
                tabletClosed = true;
            } else {
                throw ioe;
            }
        } catch (IterationInterruptedException iie) {
            if (isClosed()) {
                handleTabletClosedDuringScan(results, lookupResult, exceededMemoryUsage, range, entriesAdded);
                tabletClosed = true;
            } else {
                throw iie;
            }
        } catch (TabletClosedException tce) {
            handleTabletClosedDuringScan(results, lookupResult, exceededMemoryUsage, range, entriesAdded);
            tabletClosed = true;
        }
    }
    return lookupResult;
}
Also used : YieldCallback(org.apache.accumulo.core.iterators.YieldCallback) TooManyFilesException(org.apache.accumulo.server.fs.TooManyFilesException) IOException(java.io.IOException) Range(org.apache.accumulo.core.data.Range) IterationInterruptedException(org.apache.accumulo.core.iteratorsImpl.system.IterationInterruptedException) ByteSequence(org.apache.accumulo.core.data.ByteSequence) Key(org.apache.accumulo.core.data.Key)

Example 3 with TooManyFilesException

use of org.apache.accumulo.server.fs.TooManyFilesException in project accumulo by apache.

the class ThriftClientHandler method checkConditions.

private void checkConditions(Map<KeyExtent, List<ServerConditionalMutation>> updates, ArrayList<TCMResult> results, ConditionalSession cs, List<String> symbols) throws IOException {
    Iterator<Entry<KeyExtent, List<ServerConditionalMutation>>> iter = updates.entrySet().iterator();
    final CompressedIterators compressedIters = new CompressedIterators(symbols);
    ConditionCheckerContext checkerContext = new ConditionCheckerContext(server.getContext(), compressedIters, context.getTableConfiguration(cs.tableId));
    while (iter.hasNext()) {
        final Entry<KeyExtent, List<ServerConditionalMutation>> entry = iter.next();
        final Tablet tablet = server.getOnlineTablet(entry.getKey());
        if (tablet == null || tablet.isClosed()) {
            for (ServerConditionalMutation scm : entry.getValue()) {
                results.add(new TCMResult(scm.getID(), TCMStatus.IGNORED));
            }
            iter.remove();
        } else {
            final List<ServerConditionalMutation> okMutations = new ArrayList<>(entry.getValue().size());
            final List<TCMResult> resultsSubList = results.subList(results.size(), results.size());
            ConditionChecker checker = checkerContext.newChecker(entry.getValue(), okMutations, resultsSubList);
            try {
                tablet.checkConditions(checker, cs.auths, cs.interruptFlag);
                if (okMutations.isEmpty()) {
                    iter.remove();
                } else {
                    entry.setValue(okMutations);
                }
            } catch (TabletClosedException | IterationInterruptedException | TooManyFilesException e) {
                // clear anything added while checking conditions.
                resultsSubList.clear();
                for (ServerConditionalMutation scm : entry.getValue()) {
                    results.add(new TCMResult(scm.getID(), TCMStatus.IGNORED));
                }
                iter.remove();
            }
        }
    }
}
Also used : ServerConditionalMutation(org.apache.accumulo.tserver.data.ServerConditionalMutation) TooManyFilesException(org.apache.accumulo.server.fs.TooManyFilesException) ArrayList(java.util.ArrayList) TKeyExtent(org.apache.accumulo.core.dataImpl.thrift.TKeyExtent) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) TCMResult(org.apache.accumulo.core.dataImpl.thrift.TCMResult) TabletClosedException(org.apache.accumulo.tserver.tablet.TabletClosedException) KVEntry(org.apache.accumulo.tserver.tablet.KVEntry) Entry(java.util.Map.Entry) ConditionChecker(org.apache.accumulo.tserver.ConditionCheckerContext.ConditionChecker) IterationInterruptedException(org.apache.accumulo.core.iteratorsImpl.system.IterationInterruptedException) CompressedIterators(org.apache.accumulo.core.clientImpl.CompressedIterators) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) Tablet(org.apache.accumulo.tserver.tablet.Tablet)

Example 4 with TooManyFilesException

use of org.apache.accumulo.server.fs.TooManyFilesException in project accumulo by apache.

the class NextBatchTask method run.

@Override
public void run() {
    final SingleScanSession scanSession = (SingleScanSession) server.getSession(scanID);
    String oldThreadName = Thread.currentThread().getName();
    try {
        if (isCancelled() || scanSession == null)
            return;
        runState.set(ScanRunState.RUNNING);
        Thread.currentThread().setName("User: " + scanSession.getUser() + " Start: " + scanSession.startTime + " Client: " + scanSession.client + " Tablet: " + scanSession.extent);
        Tablet tablet = server.getOnlineTablet(scanSession.extent);
        if (tablet == null) {
            addResult(new org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException(scanSession.extent.toThrift()));
            return;
        }
        ScanBatch batch = scanSession.scanner.read();
        // there should only be one thing on the queue at a time, so
        // it should be ok to call add()
        // instead of put()... if add() fails because queue is at
        // capacity it means there is code
        // problem somewhere
        addResult(batch);
    } catch (TabletClosedException e) {
        addResult(new org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException(scanSession.extent.toThrift()));
    } catch (IterationInterruptedException iie) {
        if (!isCancelled()) {
            log.warn("Iteration interrupted, when scan not cancelled", iie);
            addResult(iie);
        }
    } catch (TooManyFilesException | SampleNotPresentException e) {
        addResult(e);
    } catch (IOException | RuntimeException e) {
        log.warn("exception while scanning tablet {} for {}", scanSession.extent, scanSession.client, e);
        addResult(e);
    } finally {
        runState.set(ScanRunState.FINISHED);
        Thread.currentThread().setName(oldThreadName);
    }
}
Also used : TooManyFilesException(org.apache.accumulo.server.fs.TooManyFilesException) IOException(java.io.IOException) TabletClosedException(org.apache.accumulo.tserver.tablet.TabletClosedException) SampleNotPresentException(org.apache.accumulo.core.client.SampleNotPresentException) ScanBatch(org.apache.accumulo.tserver.tablet.ScanBatch) IterationInterruptedException(org.apache.accumulo.core.iteratorsImpl.system.IterationInterruptedException) Tablet(org.apache.accumulo.tserver.tablet.Tablet) SingleScanSession(org.apache.accumulo.tserver.session.SingleScanSession)

Aggregations

IterationInterruptedException (org.apache.accumulo.core.iteratorsImpl.system.IterationInterruptedException)4 TooManyFilesException (org.apache.accumulo.server.fs.TooManyFilesException)4 IOException (java.io.IOException)3 Tablet (org.apache.accumulo.tserver.tablet.Tablet)3 TabletClosedException (org.apache.accumulo.tserver.tablet.TabletClosedException)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Collectors.toList (java.util.stream.Collectors.toList)2 SampleNotPresentException (org.apache.accumulo.core.client.SampleNotPresentException)2 KVEntry (org.apache.accumulo.tserver.tablet.KVEntry)2 ScanBatch (org.apache.accumulo.tserver.tablet.ScanBatch)2 Entry (java.util.Map.Entry)1 CancellationException (java.util.concurrent.CancellationException)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)1 CompressedIterators (org.apache.accumulo.core.clientImpl.CompressedIterators)1 ThriftSecurityException (org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException)1 ThriftTableOperationException (org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException)1