Search in sources :

Example 1 with SourceSwitchingIterator

use of org.apache.accumulo.core.iterators.system.SourceSwitchingIterator in project accumulo by apache.

the class Scanner method read.

public ScanBatch read() throws IOException, TabletClosedException {
    ScanDataSource dataSource = null;
    Batch results = null;
    try {
        try {
            scannerSemaphore.acquire();
        } catch (InterruptedException e) {
            sawException = true;
        }
        // sawException may have occurred within close, so we cannot assume that an interrupted exception was its cause
        if (sawException)
            throw new IllegalStateException("Tried to use scanner after exception occurred.");
        if (scanClosed)
            throw new IllegalStateException("Tried to use scanner after it was closed.");
        if (options.isIsolated()) {
            if (isolatedDataSource == null)
                isolatedDataSource = new ScanDataSource(tablet, options);
            dataSource = isolatedDataSource;
        } else {
            dataSource = new ScanDataSource(tablet, options);
        }
        SortedKeyValueIterator<Key, Value> iter;
        if (options.isIsolated()) {
            if (isolatedIter == null)
                isolatedIter = new SourceSwitchingIterator(dataSource, true);
            else
                isolatedDataSource.reattachFileManager();
            iter = isolatedIter;
        } else {
            iter = new SourceSwitchingIterator(dataSource, false);
        }
        results = tablet.nextBatch(iter, range, options.getNum(), options.getColumnSet(), options.getBatchTimeOut(), options.isIsolated());
        if (results.getResults() == null) {
            range = null;
            return new ScanBatch(new ArrayList<>(), false);
        } else if (results.getContinueKey() == null) {
            return new ScanBatch(results.getResults(), false);
        } else {
            range = new Range(results.getContinueKey(), !results.isSkipContinueKey(), range.getEndKey(), range.isEndKeyInclusive());
            return new ScanBatch(results.getResults(), true);
        }
    } catch (IterationInterruptedException iie) {
        sawException = true;
        if (tablet.isClosed())
            throw new TabletClosedException(iie);
        else
            throw iie;
    } catch (IOException ioe) {
        if (tablet.shutdownInProgress()) {
            log.debug("IOException while shutdown in progress ", ioe);
            // assume IOException was caused by execution of HDFS shutdown hook
            throw new TabletClosedException(ioe);
        }
        sawException = true;
        dataSource.close(true);
        throw ioe;
    } catch (RuntimeException re) {
        sawException = true;
        throw re;
    } finally {
        // to return mapfiles, even when exception is thrown
        if (null != dataSource && !options.isIsolated()) {
            dataSource.close(false);
        } else if (null != dataSource) {
            dataSource.detachFileManager();
        }
        if (results != null && results.getResults() != null)
            tablet.updateQueryStats(results.getResults().size(), results.getNumBytes());
        scannerSemaphore.release();
    }
}
Also used : IOException(java.io.IOException) SourceSwitchingIterator(org.apache.accumulo.core.iterators.system.SourceSwitchingIterator) Range(org.apache.accumulo.core.data.Range) IterationInterruptedException(org.apache.accumulo.core.iterators.IterationInterruptedException) Value(org.apache.accumulo.core.data.Value) IterationInterruptedException(org.apache.accumulo.core.iterators.IterationInterruptedException) Key(org.apache.accumulo.core.data.Key)

Example 2 with SourceSwitchingIterator

use of org.apache.accumulo.core.iterators.system.SourceSwitchingIterator in project accumulo by apache.

the class Tablet method lookup.

public LookupResult lookup(List<Range> ranges, HashSet<Column> columns, Authorizations authorizations, List<KVEntry> results, long maxResultSize, List<IterInfo> ssiList, Map<String, Map<String, String>> ssio, AtomicBoolean interruptFlag, SamplerConfiguration samplerConfig, long batchTimeOut, String classLoaderContext) throws IOException {
    if (ranges.size() == 0) {
        return new LookupResult();
    }
    ranges = Range.mergeOverlapping(ranges);
    if (ranges.size() > 1) {
        Collections.sort(ranges);
    }
    Range tabletRange = extent.toDataRange();
    for (Range range : ranges) {
        // do a test to see if this range falls within the tablet, if it does not
        // then clip will throw an exception
        tabletRange.clip(range);
    }
    ScanDataSource dataSource = new ScanDataSource(this, authorizations, this.defaultSecurityLabel, columns, ssiList, ssio, interruptFlag, samplerConfig, batchTimeOut, classLoaderContext);
    LookupResult result = null;
    try {
        SortedKeyValueIterator<Key, Value> iter = new SourceSwitchingIterator(dataSource);
        result = lookup(iter, ranges, columns, results, maxResultSize, batchTimeOut);
        return result;
    } catch (IOException ioe) {
        dataSource.close(true);
        throw ioe;
    } finally {
        // code in finally block because always want
        // to return mapfiles, even when exception is thrown
        dataSource.close(false);
        synchronized (this) {
            queryCount += results.size();
            if (result != null)
                queryBytes += result.dataSize;
        }
    }
}
Also used : Value(org.apache.accumulo.core.data.Value) DataFileValue(org.apache.accumulo.core.metadata.schema.DataFileValue) IOException(java.io.IOException) Range(org.apache.accumulo.core.data.Range) SourceSwitchingIterator(org.apache.accumulo.core.iterators.system.SourceSwitchingIterator) Key(org.apache.accumulo.core.data.Key)

Example 3 with SourceSwitchingIterator

use of org.apache.accumulo.core.iterators.system.SourceSwitchingIterator in project accumulo by apache.

the class InMemoryMap method skvIterator.

public synchronized MemoryIterator skvIterator(SamplerConfigurationImpl iteratorSamplerConfig) {
    if (map == null)
        throw new NullPointerException();
    if (deleted)
        throw new IllegalStateException("Can not obtain iterator after map deleted");
    int mc = kvCount.get();
    MemoryDataSource mds = new MemoryDataSource(iteratorSamplerConfig);
    // TODO seems like a bug that two MemoryDataSources are created... may need to fix in older branches
    SourceSwitchingIterator ssi = new SourceSwitchingIterator(mds);
    MemoryIterator mi = new MemoryIterator(new PartialMutationSkippingIterator(ssi, mc));
    mi.setSSI(ssi);
    mi.setMDS(mds);
    activeIters.add(mi);
    return mi;
}
Also used : SourceSwitchingIterator(org.apache.accumulo.core.iterators.system.SourceSwitchingIterator)

Aggregations

SourceSwitchingIterator (org.apache.accumulo.core.iterators.system.SourceSwitchingIterator)3 IOException (java.io.IOException)2 Key (org.apache.accumulo.core.data.Key)2 Range (org.apache.accumulo.core.data.Range)2 Value (org.apache.accumulo.core.data.Value)2 IterationInterruptedException (org.apache.accumulo.core.iterators.IterationInterruptedException)1 DataFileValue (org.apache.accumulo.core.metadata.schema.DataFileValue)1