本文整理汇总了Java中org.apache.cassandra.utils.CloseableIterator类的典型用法代码示例。如果您正苦于以下问题:Java CloseableIterator类的具体用法?Java CloseableIterator怎么用?Java CloseableIterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
CloseableIterator类属于org.apache.cassandra.utils包,在下文中一共展示了CloseableIterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: resolve
import org.apache.cassandra.utils.CloseableIterator; //导入依赖的package包/类
public Iterable<Row> resolve()
{
ArrayList<RowIterator> iters = new ArrayList<RowIterator>(responses.size());
int n = 0;
for (MessageIn<RangeSliceReply> response : responses)
{
RangeSliceReply reply = response.payload;
n = Math.max(n, reply.rows.size());
iters.add(new RowIterator(reply.rows.iterator(), response.from));
}
// for each row, compute the combination of all different versions seen, and repair incomplete versions
// TODO do we need to call close?
CloseableIterator<Row> iter = MergeIterator.get(iters, pairComparator, new Reducer());
List<Row> resolvedRows = new ArrayList<Row>(n);
while (iter.hasNext())
resolvedRows.add(iter.next());
return resolvedRows;
}
示例2: merge
import org.apache.cassandra.utils.CloseableIterator; //导入依赖的package包/类
public static void merge(final ColumnFamily returnCF, List<CloseableIterator<Column>> data, final SecondaryIndexManager.Updater indexer)
{
IDiskAtomFilter filter = new IdentityQueryFilter();
Comparator<Column> fcomp = filter.getColumnComparator(returnCF.getComparator());
MergeIterator.Reducer<Column, Column> reducer = new MergeIterator.Reducer<Column, Column>()
{
ColumnFamily container = returnCF.cloneMeShallow();
public void reduce(Column column)
{
container.addColumn(column);
// skip the index-update checks if there is no indexing needed since they are a bit expensive
if (indexer == SecondaryIndexManager.nullUpdater)
return;
// notify the index that the column has been overwritten if the value being reduced has been
// superceded by another directly, or indirectly by a range tombstone
if ((!column.isMarkedForDelete(System.currentTimeMillis()) && !container.getColumn(column.name()).equals(column))
|| returnCF.deletionInfo().isDeleted(column.name(), CompactionManager.NO_GC))
{
indexer.remove(column);
}
}
protected Column getReduced()
{
Column c = container.iterator().next();
container.clear();
return c;
}
};
Iterator<Column> reduced = MergeIterator.get(data, fcomp, reducer);
filter.collectReducedColumns(returnCF, reduced, CompactionManager.NO_GC, System.currentTimeMillis());
}
示例3: merge
import org.apache.cassandra.utils.CloseableIterator; //导入依赖的package包/类
public static void merge(final ColumnFamily returnCF, List<CloseableIterator<IColumn>> data, final SecondaryIndexManager.Updater indexer)
{
IDiskAtomFilter filter = new IdentityQueryFilter();
Comparator<IColumn> fcomp = filter.getColumnComparator(returnCF.getComparator());
MergeIterator.Reducer<IColumn, IColumn> reducer = new MergeIterator.Reducer<IColumn, IColumn>()
{
ColumnFamily container = returnCF.cloneMeShallow();
public void reduce(IColumn column)
{
container.addColumn(column);
if (indexer != SecondaryIndexManager.nullUpdater
&& !column.isMarkedForDelete()
&& !container.getColumn(column.name()).equals(column))
{
indexer.remove(column);
}
}
protected IColumn getReduced()
{
IColumn c = container.iterator().next();
container.clear();
return c;
}
};
Iterator<IColumn> reduced = MergeIterator.get(data, fcomp, reducer);
filter.collectReducedColumns(returnCF, reduced, CompactionManager.NO_GC);
}
示例4: collateOnDiskAtom
import org.apache.cassandra.utils.CloseableIterator; //导入依赖的package包/类
public void collateOnDiskAtom(final ColumnFamily returnCF, List<? extends CloseableIterator<OnDiskAtom>> toCollate, final int gcBefore)
{
List<CloseableIterator<IColumn>> filteredIterators = new ArrayList<CloseableIterator<IColumn>>(toCollate.size());
for (CloseableIterator<OnDiskAtom> iter : toCollate)
filteredIterators.add(gatherTombstones(returnCF, iter));
collateColumns(returnCF, filteredIterators, gcBefore);
}
示例5: close
import org.apache.cassandra.utils.CloseableIterator; //导入依赖的package包/类
public void close() throws IOException
{
for (Object o : mi.iterators())
{
((CloseableIterator)o).close();
}
}
示例6: getRowIterator
import org.apache.cassandra.utils.CloseableIterator; //导入依赖的package包/类
private CloseableIterator<Row> getRowIterator(RowPosition start) throws IOException {
releaseReferences();
// loop round until we get a successful read
List<CloseableIterator<OnDiskAtomIterator>> iterators = null;
while (iterators == null)
iterators = getSSTableIterators(start);
return makeRowIterator(iterators);
}
示例7: makeRowIterator
import org.apache.cassandra.utils.CloseableIterator; //导入依赖的package包/类
private CloseableIterator<Row> makeRowIterator(List<CloseableIterator<OnDiskAtomIterator>> iterators) {
// reduce rows from all sources into a single row
return MergeIterator.get(iterators, COMPARE_BY_KEY, new MergeIterator.Reducer<OnDiskAtomIterator, Row>() {
private final List<OnDiskAtomIterator> colIters = new ArrayList<OnDiskAtomIterator>();
private DecoratedKey key;
private ColumnFamily returnCF;
private final QueryFilter filter = QueryFilter.getIdentityFilter(null, new QueryPath(metadata.getColumnFamily()));
@Override
protected void onKeyChange() {
this.returnCF = ColumnFamily.create(cfMetadata);
}
@Override
public void reduce(OnDiskAtomIterator current) {
this.colIters.add(current);
this.key = current.getKey();
this.returnCF.delete(current.getColumnFamily());
}
@Override
protected Row getReduced() {
filter.collateOnDiskAtom(returnCF, colIters, Integer.MAX_VALUE);
Row rv = new Row(key, returnCF);
colIters.clear();
key = null;
return rv;
}
});
}
示例8: getIterator
import org.apache.cassandra.utils.CloseableIterator; //导入依赖的package包/类
/**
* 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 range The data range to fetch
* @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 DataRange range,
final ColumnFamilyStore cfs,
final long now)
{
// fetch data from current memtable, historical memtables, and SSTables in the correct order.
final List<CloseableIterator<OnDiskAtomIterator>> iterators = new ArrayList<>(Iterables.size(memtables) + sstables.size());
for (Memtable memtable : memtables)
iterators.add(new ConvertToColumnIterator(range, memtable.getEntryIterator(range.startKey(), range.stopKey())));
for (SSTableReader sstable : sstables)
iterators.add(sstable.getScanner(range));
// reduce rows from all sources into a single row
return MergeIterator.get(iterators, COMPARE_BY_KEY, new MergeIterator.Reducer<OnDiskAtomIterator, Row>()
{
private final int gcBefore = cfs.gcBefore(now);
private final List<OnDiskAtomIterator> colIters = new ArrayList<>();
private DecoratedKey key;
private ColumnFamily returnCF;
@Override
protected void onKeyChange()
{
this.returnCF = ArrayBackedSortedColumns.factory.create(cfs.metadata, range.columnFilter.isReversed());
}
public void reduce(OnDiskAtomIterator 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 and it covers our filter, we can skip the rest
ColumnFamily cached = cfs.getRawCachedRow(key);
IDiskAtomFilter filter = range.columnFilter(key.getKey());
if (cached == null || !cfs.isFilterFullyCoveredBy(filter, cached, now))
{
// not cached: collate
QueryFilter.collateOnDiskAtom(returnCF, colIters, filter, gcBefore, now);
}
else
{
QueryFilter keyFilter = new QueryFilter(key, cfs.name, filter, now);
returnCF = cfs.filterColumnFamily(cached, keyFilter);
}
Row rv = new Row(key, returnCF);
colIters.clear();
key = null;
return rv;
}
});
}
示例9: iterator
import org.apache.cassandra.utils.CloseableIterator; //导入依赖的package包/类
public CloseableIterator<AbstractCompactedRow> iterator()
{
return MergeIterator.get(scanners, comparator, new Reducer());
}
示例10: getIterator
import org.apache.cassandra.utils.CloseableIterator; //导入依赖的package包/类
/**
* 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 range The data range to fetch
* @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 DataRange range,
final ColumnFamilyStore cfs,
final long now)
{
// fetch data from current memtable, historical memtables, and SSTables in the correct order.
final List<CloseableIterator<OnDiskAtomIterator>> iterators = new ArrayList<CloseableIterator<OnDiskAtomIterator>>();
// memtables
for (Memtable memtable : memtables)
{
iterators.add(new ConvertToColumnIterator<AtomicSortedColumns>(range, memtable.getEntryIterator(range.startKey(), range.stopKey())));
}
for (SSTableReader sstable : sstables)
{
final SSTableScanner scanner = sstable.getScanner(range);
iterators.add(scanner);
}
// reduce rows from all sources into a single row
return MergeIterator.get(iterators, COMPARE_BY_KEY, new MergeIterator.Reducer<OnDiskAtomIterator, Row>()
{
private final int gcBefore = cfs.gcBefore(now);
private final List<OnDiskAtomIterator> colIters = new ArrayList<OnDiskAtomIterator>();
private DecoratedKey key;
private ColumnFamily returnCF;
@Override
protected void onKeyChange()
{
this.returnCF = TreeMapBackedSortedColumns.factory.create(cfs.metadata);
}
public void reduce(OnDiskAtomIterator 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
QueryFilter.collateOnDiskAtom(returnCF, colIters, range.columnFilter(key.key), gcBefore, now);
}
else
{
QueryFilter keyFilter = new QueryFilter(key, cfs.name, range.columnFilter(key.key), now);
returnCF = cfs.filterColumnFamily(cached, keyFilter);
}
Row rv = new Row(key, returnCF);
colIters.clear();
key = null;
return rv;
}
});
}
示例11: getIterator
import org.apache.cassandra.utils.CloseableIterator; //导入依赖的package包/类
/**
* 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<OnDiskAtomIterator>> iterators = new ArrayList<CloseableIterator<OnDiskAtomIterator>>();
// 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);
iterators.add(scanner);
}
// reduce rows from all sources into a single row
return MergeIterator.get(iterators, COMPARE_BY_KEY, new MergeIterator.Reducer<OnDiskAtomIterator, Row>()
{
private final int gcBefore = (int) (System.currentTimeMillis() / 1000) - cfs.metadata.getGcGraceSeconds();
private final List<OnDiskAtomIterator> colIters = new ArrayList<OnDiskAtomIterator>();
private DecoratedKey key;
private ColumnFamily returnCF;
@Override
protected void onKeyChange()
{
this.returnCF = ColumnFamily.create(cfs.metadata);
}
public void reduce(OnDiskAtomIterator 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.collateOnDiskAtom(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;
}
});
}
示例12: collateColumns
import org.apache.cassandra.utils.CloseableIterator; //导入依赖的package包/类
public void collateColumns(final ColumnFamily returnCF, List<? extends CloseableIterator<IColumn>> toCollate, final int gcBefore)
{
IDiskAtomFilter topLevelFilter = (superFilter == null ? filter : superFilter);
Comparator<IColumn> fcomp = topLevelFilter.getColumnComparator(returnCF.getComparator());
// define a 'reduced' iterator that merges columns w/ the same name, which
// greatly simplifies computing liveColumns in the presence of tombstones.
MergeIterator.Reducer<IColumn, IColumn> reducer = new MergeIterator.Reducer<IColumn, IColumn>()
{
ColumnFamily curCF = returnCF.cloneMeShallow();
public void reduce(IColumn current)
{
if (curCF.isSuper() && curCF.isEmpty())
{
// If it is the first super column we add, we must clone it since other super column may modify
// it otherwise and it could be aliased in a memtable somewhere. We'll also don't have to care about what
// consumers make of the result (for instance CFS.getColumnFamily() call removeDeleted() on the
// result which removes column; which shouldn't be done on the original super column).
assert current instanceof SuperColumn;
curCF.addColumn(((SuperColumn) current).cloneMe());
}
else
{
curCF.addColumn(current);
}
}
protected IColumn getReduced()
{
IColumn c = curCF.iterator().next();
if (superFilter != null)
{
// filterSuperColumn only looks at immediate parent (the supercolumn) when determining if a subcolumn
// is still live, i.e., not shadowed by the parent's tombstone. so, bump it up temporarily to the tombstone
// time of the cf, if that is greater.
DeletionInfo delInfo = ((SuperColumn) c).deletionInfo();
((SuperColumn) c).delete(returnCF.deletionInfo());
c = filter.filterSuperColumn((SuperColumn) c, gcBefore);
((SuperColumn) c).setDeletionInfo(delInfo); // reset sc tombstone time to what it should be
}
curCF.clear();
return c;
}
};
Iterator<IColumn> reduced = MergeIterator.get(toCollate, fcomp, reducer);
topLevelFilter.collectReducedColumns(returnCF, reduced, gcBefore);
}
示例13: gatherTombstones
import org.apache.cassandra.utils.CloseableIterator; //导入依赖的package包/类
/**
* Given an iterator of on disk atom, returns an iterator that filters the tombstone range
* markers adding them to {@code returnCF} and returns the normal column.
*/
public static CloseableIterator<IColumn> gatherTombstones(final ColumnFamily returnCF, final CloseableIterator<OnDiskAtom> iter)
{
return new CloseableIterator<IColumn>()
{
private IColumn next;
public boolean hasNext()
{
if (next != null)
return true;
getNext();
return next != null;
}
public IColumn next()
{
if (next == null)
getNext();
assert next != null;
IColumn toReturn = next;
next = null;
return toReturn;
}
private void getNext()
{
while (iter.hasNext())
{
OnDiskAtom atom = iter.next();
if (atom instanceof IColumn)
{
next = (IColumn)atom;
break;
}
else
{
returnCF.addAtom(atom);
}
}
}
public void remove()
{
throw new UnsupportedOperationException();
}
public void close() throws IOException
{
iter.close();
}
};
}
示例14: getIterator
import org.apache.cassandra.utils.CloseableIterator; //导入依赖的package包/类
/**
* 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 range The data range to fetch
* @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 DataRange range,
final ColumnFamilyStore cfs,
final long now)
{
// fetch data from current memtable, historical memtables, and SSTables in the correct order.
final List<CloseableIterator<OnDiskAtomIterator>> iterators = new ArrayList<CloseableIterator<OnDiskAtomIterator>>();
// memtables
for (Memtable memtable : memtables)
{
iterators.add(new ConvertToColumnIterator<>(range, memtable.getEntryIterator(range.startKey(), range.stopKey())));
}
for (SSTableReader sstable : sstables)
{
final SSTableScanner scanner = sstable.getScanner(range);
iterators.add(scanner);
}
// reduce rows from all sources into a single row
return MergeIterator.get(iterators, COMPARE_BY_KEY, new MergeIterator.Reducer<OnDiskAtomIterator, Row>()
{
private final int gcBefore = cfs.gcBefore(now);
private final List<OnDiskAtomIterator> colIters = new ArrayList<OnDiskAtomIterator>();
private DecoratedKey key;
private ColumnFamily returnCF;
@Override
protected void onKeyChange()
{
this.returnCF = TreeMapBackedSortedColumns.factory.create(cfs.metadata);
}
public void reduce(OnDiskAtomIterator 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
QueryFilter.collateOnDiskAtom(returnCF, colIters, range.columnFilter(key.key), gcBefore, now);
}
else
{
QueryFilter keyFilter = new QueryFilter(key, cfs.name, range.columnFilter(key.key), now);
returnCF = cfs.filterColumnFamily(cached, keyFilter);
}
Row rv = new Row(key, returnCF);
colIters.clear();
key = null;
return rv;
}
});
}
示例15: getIterator
import org.apache.cassandra.utils.CloseableIterator; //导入依赖的package包/类
/**
* 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 range The data range to fetch
* @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 DataRange range,
final ColumnFamilyStore cfs,
final long now)
{
// fetch data from current memtable, historical memtables, and SSTables in the correct order.
final List<CloseableIterator<OnDiskAtomIterator>> iterators = new ArrayList<CloseableIterator<OnDiskAtomIterator>>();
// memtables
for (Memtable memtable : memtables)
{
iterators.add(new ConvertToColumnIterator(range, memtable.getEntryIterator(range.startKey(), range.stopKey())));
}
for (SSTableReader sstable : sstables)
{
final SSTableScanner scanner = sstable.getScanner(range);
iterators.add(scanner);
}
// reduce rows from all sources into a single row
return MergeIterator.get(iterators, COMPARE_BY_KEY, new MergeIterator.Reducer<OnDiskAtomIterator, Row>()
{
private final int gcBefore = cfs.gcBefore(now);
private final List<OnDiskAtomIterator> colIters = new ArrayList<OnDiskAtomIterator>();
private DecoratedKey key;
private ColumnFamily returnCF;
@Override
protected void onKeyChange()
{
this.returnCF = ArrayBackedSortedColumns.factory.create(cfs.metadata);
}
public void reduce(OnDiskAtomIterator 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 and it covers our filter, we can skip the rest
ColumnFamily cached = cfs.getRawCachedRow(key);
IDiskAtomFilter filter = range.columnFilter(key.key);
if (cached == null || !cfs.isFilterFullyCoveredBy(filter, cached, now))
{
// not cached: collate
QueryFilter.collateOnDiskAtom(returnCF, colIters, filter, gcBefore, now);
}
else
{
QueryFilter keyFilter = new QueryFilter(key, cfs.name, filter, now);
returnCF = cfs.filterColumnFamily(cached, keyFilter);
}
Row rv = new Row(key, returnCF);
colIters.clear();
key = null;
return rv;
}
});
}