use of org.apache.cassandra.io.sstable.SSTableScanner in project eiger by wlloyd.
the class RowIteratorFactory method getIterator.
/**
* Get a row iterator over the provided memtables and sstables, between the provided keys
* and filtered by the queryfilter.
* @param memtables Memtables pending flush.
* @param sstables SStables to scan through.
* @param startWith Start at this key
* @param stopAt Stop and this key
* @param filter Used to decide which columns to pull out
* @param cfs
* @return A row iterator following all the given restrictions
*/
public static CloseableIterator<Row> getIterator(final Iterable<Memtable> memtables, final Collection<SSTableReader> sstables, final RowPosition startWith, final RowPosition stopAt, final QueryFilter filter, final ColumnFamilyStore cfs) {
// fetch data from current memtable, historical memtables, and SSTables in the correct order.
final List<CloseableIterator<IColumnIterator>> iterators = new ArrayList<CloseableIterator<IColumnIterator>>();
// memtables
for (Memtable memtable : memtables) {
iterators.add(new ConvertToColumnIterator(filter, memtable.getEntryIterator(startWith, stopAt)));
}
for (SSTableReader sstable : sstables) {
final SSTableScanner scanner = sstable.getScanner(filter);
scanner.seekTo(startWith);
// otherwise we leak FDs
assert scanner instanceof Closeable;
iterators.add(scanner);
}
// reduce rows from all sources into a single row
return MergeIterator.get(iterators, COMPARE_BY_KEY, new MergeIterator.Reducer<IColumnIterator, Row>() {
private final int gcBefore = (int) (System.currentTimeMillis() / 1000) - cfs.metadata.getGcGraceSeconds();
private final List<IColumnIterator> colIters = new ArrayList<IColumnIterator>();
private DecoratedKey key;
private ColumnFamily returnCF;
@Override
protected void onKeyChange() {
this.returnCF = ColumnFamily.create(cfs.metadata);
}
public void reduce(IColumnIterator current) {
this.colIters.add(current);
this.key = current.getKey();
this.returnCF.delete(current.getColumnFamily());
}
protected Row getReduced() {
// First check if this row is in the rowCache. If it is we can skip the rest
ColumnFamily cached = cfs.getRawCachedRow(key);
if (cached == null)
// not cached: collate
filter.collateColumns(returnCF, colIters, gcBefore);
else {
QueryFilter keyFilter = new QueryFilter(key, filter.path, filter.filter);
returnCF = cfs.filterColumnFamily(cached, keyFilter, gcBefore);
}
Row rv = new Row(key, returnCF);
colIters.clear();
key = null;
return rv;
}
});
}
Aggregations