Search in sources :

Example 1 with ISSTableScanner

use of org.apache.cassandra.io.sstable.ISSTableScanner in project cassandra by apache.

the class GcCompactionTest method count.

int count(SSTableReader reader, Function<Unfiltered, Integer> predicate, Function<UnfilteredRowIterator, Integer> partitionPredicate) {
    int instances = 0;
    try (ISSTableScanner partitions = reader.getScanner()) {
        while (partitions.hasNext()) {
            try (UnfilteredRowIterator iter = partitions.next()) {
                instances += partitionPredicate.apply(iter);
                while (iter.hasNext()) {
                    Unfiltered atom = iter.next();
                    instances += predicate.apply(atom);
                }
            }
        }
    }
    return instances;
}
Also used : ISSTableScanner(org.apache.cassandra.io.sstable.ISSTableScanner)

Example 2 with ISSTableScanner

use of org.apache.cassandra.io.sstable.ISSTableScanner in project cassandra by apache.

the class CompactionIteratorTest method iterate.

private void iterate(Unfiltered... unfiltereds) {
    ColumnFamilyStore cfs = getCurrentColumnFamilyStore();
    DecoratedKey key = cfs.getPartitioner().decorateKey(ByteBufferUtil.bytes("key"));
    try (CompactionController controller = new CompactionController(cfs, Integer.MAX_VALUE);
        UnfilteredRowIterator rows = rows(cfs.metadata(), key, false, unfiltereds);
        ISSTableScanner scanner = new Scanner(Collections.singletonList(rows));
        CompactionIterator iter = new CompactionIterator(OperationType.COMPACTION, Collections.singletonList(scanner), controller, FBUtilities.nowInSeconds(), null)) {
        while (iter.hasNext()) {
            try (UnfilteredRowIterator partition = iter.next()) {
                partition.forEachRemaining(u -> {
                });
            }
        }
    }
}
Also used : ISSTableScanner(org.apache.cassandra.io.sstable.ISSTableScanner) ISSTableScanner(org.apache.cassandra.io.sstable.ISSTableScanner) DecoratedKey(org.apache.cassandra.db.DecoratedKey) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore)

Example 3 with ISSTableScanner

use of org.apache.cassandra.io.sstable.ISSTableScanner in project cassandra by apache.

the class CompactionsCQLTest method assertTombstones.

private void assertTombstones(SSTableReader sstable, boolean expectTS) {
    boolean foundTombstone = false;
    try (ISSTableScanner scanner = sstable.getScanner()) {
        while (scanner.hasNext()) {
            try (UnfilteredRowIterator iter = scanner.next()) {
                if (!iter.partitionLevelDeletion().isLive())
                    foundTombstone = true;
                while (iter.hasNext()) {
                    Unfiltered unfiltered = iter.next();
                    assertTrue(unfiltered instanceof Row);
                    for (Cell<?> c : ((Row) unfiltered).cells()) {
                        if (c.isTombstone())
                            foundTombstone = true;
                    }
                }
            }
        }
    }
    assertEquals(expectTS, foundTombstone);
}
Also used : ISSTableScanner(org.apache.cassandra.io.sstable.ISSTableScanner) UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) Row(org.apache.cassandra.db.rows.Row) Unfiltered(org.apache.cassandra.db.rows.Unfiltered)

Example 4 with ISSTableScanner

use of org.apache.cassandra.io.sstable.ISSTableScanner in project cassandra by apache.

the class CompactionStrategyManager method maybeGetScanners.

/**
 * Create ISSTableScanners from the given sstables
 *
 * Delegates the call to the compaction strategies to allow LCS to create a scanner
 * @param sstables
 * @param ranges
 * @return
 */
@SuppressWarnings("resource")
public AbstractCompactionStrategy.ScannerList maybeGetScanners(Collection<SSTableReader> sstables, Collection<Range<Token>> ranges) {
    maybeReloadDiskBoundaries();
    List<ISSTableScanner> scanners = new ArrayList<>(sstables.size());
    readLock.lock();
    try {
        List<GroupedSSTableContainer> sstableGroups = groupSSTables(sstables);
        for (int i = 0; i < holders.size(); i++) {
            AbstractStrategyHolder holder = holders.get(i);
            GroupedSSTableContainer group = sstableGroups.get(i);
            scanners.addAll(holder.getScanners(group, ranges));
        }
    } catch (PendingRepairManager.IllegalSSTableArgumentException e) {
        ISSTableScanner.closeAllAndPropagate(scanners, new ConcurrentModificationException(e));
    } finally {
        readLock.unlock();
    }
    return new AbstractCompactionStrategy.ScannerList(scanners);
}
Also used : ISSTableScanner(org.apache.cassandra.io.sstable.ISSTableScanner) ConcurrentModificationException(java.util.ConcurrentModificationException) ArrayList(java.util.ArrayList) GroupedSSTableContainer(org.apache.cassandra.db.compaction.AbstractStrategyHolder.GroupedSSTableContainer)

Example 5 with ISSTableScanner

use of org.apache.cassandra.io.sstable.ISSTableScanner in project cassandra by apache.

the class GcCompactionTest method count.

int count(SSTableReader reader, ToIntFunction<Unfiltered> predicate, ToIntFunction<UnfilteredRowIterator> partitionPredicate) {
    int instances = 0;
    try (ISSTableScanner partitions = reader.getScanner()) {
        while (partitions.hasNext()) {
            try (UnfilteredRowIterator iter = partitions.next()) {
                instances += partitionPredicate.applyAsInt(iter);
                while (iter.hasNext()) {
                    Unfiltered atom = iter.next();
                    instances += predicate.applyAsInt(atom);
                }
            }
        }
    }
    return instances;
}
Also used : ISSTableScanner(org.apache.cassandra.io.sstable.ISSTableScanner)

Aggregations

ISSTableScanner (org.apache.cassandra.io.sstable.ISSTableScanner)24 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)18 UnfilteredRowIterator (org.apache.cassandra.db.rows.UnfilteredRowIterator)10 Test (org.junit.Test)9 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)6 Row (org.apache.cassandra.db.rows.Row)5 ArrayList (java.util.ArrayList)4 LifecycleTransaction (org.apache.cassandra.db.lifecycle.LifecycleTransaction)4 Unfiltered (org.apache.cassandra.db.rows.Unfiltered)4 TableMetadata (org.apache.cassandra.schema.TableMetadata)4 ByteBuffer (java.nio.ByteBuffer)3 UUID (java.util.UUID)3 DecoratedKey (org.apache.cassandra.db.DecoratedKey)3 File (org.apache.cassandra.io.util.File)3 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)2 Collections (java.util.Collections)2 HashSet (java.util.HashSet)2 List (java.util.List)2 ExecutorService (java.util.concurrent.ExecutorService)2 Collectors (java.util.stream.Collectors)2