Search in sources :

Example 1 with IColumnIterator

use of org.apache.cassandra.db.columniterator.IColumnIterator in project eiger by wlloyd.

the class ColumnFamilyStore method filterColumnFamily.

/**
 *  Filter a cached row, which will not be modified by the filter, but may be modified by throwing out
 *  tombstones that are no longer relevant.
 *  The returned column family won't be thread safe.
 */
ColumnFamily filterColumnFamily(ColumnFamily cached, QueryFilter filter, int gcBefore) {
    ColumnFamily cf = cached.cloneMeShallow(ArrayBackedSortedColumns.factory(), filter.filter.isReversed());
    IColumnIterator ci = filter.getMemtableColumnIterator(cached, null);
    filter.collateColumns(cf, Collections.singletonList(ci), gcBefore);
    // their subcolumns for relevance, so we need to do a second prune post facto here.
    return cf.isSuper() ? removeDeleted(cf, gcBefore) : removeDeletedCF(cf, gcBefore);
}
Also used : IColumnIterator(org.apache.cassandra.db.columniterator.IColumnIterator)

Example 2 with IColumnIterator

use of org.apache.cassandra.db.columniterator.IColumnIterator in project eiger by wlloyd.

the class CollationController method collectAllData.

/**
 * Collects data the brute-force way: gets an iterator for the filter in question
 * from every memtable and sstable, then merges them together.
 */
private ColumnFamily collectAllData() {
    logger.debug("collectAllData");
    ISortedColumns.Factory factory = mutableColumns ? AtomicSortedColumns.factory() : ArrayBackedSortedColumns.factory();
    List<IColumnIterator> iterators = new ArrayList<IColumnIterator>();
    ColumnFamily returnCF = ColumnFamily.create(cfs.metadata, factory, filter.filter.isReversed());
    ColumnFamilyStore.ViewFragment view = cfs.markReferenced(filter.key);
    try {
        for (Memtable memtable : view.memtables) {
            IColumnIterator iter = filter.getMemtableColumnIterator(memtable);
            if (iter != null) {
                returnCF.delete(iter.getColumnFamily());
                iterators.add(iter);
            }
        }
        for (SSTableReader sstable : view.sstables) {
            IColumnIterator iter = filter.getSSTableColumnIterator(sstable);
            iterators.add(iter);
            if (iter.getColumnFamily() != null) {
                returnCF.delete(iter.getColumnFamily());
                sstablesIterated++;
            }
        }
        // and "there used to be data, but it's gone now" (we should cache the empty CF so we don't need to rebuild that slower)
        if (iterators.isEmpty())
            return null;
        filter.collateColumns(returnCF, iterators, gcBefore);
        // Caller is responsible for final removeDeletedCF.  This is important for cacheRow to work correctly:
        return returnCF;
    } finally {
        for (IColumnIterator iter : iterators) FileUtils.closeQuietly(iter);
        SSTableReader.releaseReferences(view.sstables);
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) IColumnIterator(org.apache.cassandra.db.columniterator.IColumnIterator)

Example 3 with IColumnIterator

use of org.apache.cassandra.db.columniterator.IColumnIterator in project eiger by wlloyd.

the class SSTableImportTest method testImportSimpleCf.

@Test
public void testImportSimpleCf() throws IOException, URISyntaxException {
    // Import JSON to temp SSTable file
    String jsonUrl = resourcePath("SimpleCF.json");
    File tempSS = tempSSTableFile("Keyspace1", "Standard1");
    SSTableImport.importJson(jsonUrl, "Keyspace1", "Standard1", tempSS.getPath());
    // Verify results
    SSTableReader reader = SSTableReader.open(Descriptor.fromFilename(tempSS.getPath()));
    QueryFilter qf = QueryFilter.getIdentityFilter(Util.dk("rowA"), new QueryPath("Standard1"));
    IColumnIterator iter = qf.getSSTableColumnIterator(reader);
    ColumnFamily cf = iter.getColumnFamily();
    while (iter.hasNext()) cf.addColumn(iter.next());
    assert cf.getColumn(ByteBufferUtil.bytes("colAA")).value().equals(hexToBytes("76616c4141"));
    assert !(cf.getColumn(ByteBufferUtil.bytes("colAA")) instanceof DeletedColumn);
    IColumn expCol = cf.getColumn(ByteBufferUtil.bytes("colAC"));
    assert expCol.value().equals(hexToBytes("76616c4143"));
    assert expCol instanceof ExpiringColumn;
    assert ((ExpiringColumn) expCol).getTimeToLive() == 42 && expCol.getLocalDeletionTime() == 2000000000;
}
Also used : QueryPath(org.apache.cassandra.db.filter.QueryPath) SSTableReader(org.apache.cassandra.io.sstable.SSTableReader) QueryFilter(org.apache.cassandra.db.filter.QueryFilter) IColumn(org.apache.cassandra.db.IColumn) ExpiringColumn(org.apache.cassandra.db.ExpiringColumn) IColumnIterator(org.apache.cassandra.db.columniterator.IColumnIterator) DeletedColumn(org.apache.cassandra.db.DeletedColumn) File(java.io.File) SSTableUtils.tempSSTableFile(org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile) ColumnFamily(org.apache.cassandra.db.ColumnFamily) Test(org.junit.Test)

Example 4 with IColumnIterator

use of org.apache.cassandra.db.columniterator.IColumnIterator in project eiger by wlloyd.

the class SSTableUtils method assertContentEquals.

public static void assertContentEquals(SSTableReader lhs, SSTableReader rhs) throws IOException {
    SSTableScanner slhs = lhs.getDirectScanner();
    SSTableScanner srhs = rhs.getDirectScanner();
    while (slhs.hasNext()) {
        IColumnIterator ilhs = slhs.next();
        assert srhs.hasNext() : "LHS contained more rows than RHS";
        IColumnIterator irhs = srhs.next();
        assertContentEquals(ilhs, irhs);
    }
    assert !srhs.hasNext() : "RHS contained more rows than LHS";
}
Also used : IColumnIterator(org.apache.cassandra.db.columniterator.IColumnIterator)

Example 5 with IColumnIterator

use of org.apache.cassandra.db.columniterator.IColumnIterator in project eiger by wlloyd.

the class Memtable method getNamesIterator.

public static IColumnIterator getNamesIterator(final DecoratedKey key, final ColumnFamily cf, final NamesQueryFilter filter) {
    assert cf != null;
    final boolean isStandard = !cf.isSuper();
    return new SimpleAbstractColumnIterator() {

        private Iterator<ByteBuffer> iter = filter.columns.iterator();

        public ColumnFamily getColumnFamily() {
            return cf;
        }

        public DecoratedKey getKey() {
            return key;
        }

        protected IColumn computeNext() {
            while (iter.hasNext()) {
                ByteBuffer current = iter.next();
                IColumn column = cf.getColumn(current);
                if (column != null)
                    // clone supercolumns so caller can freely removeDeleted or otherwise mutate it
                    return isStandard ? column : ((SuperColumn) column).cloneMe();
            }
            return endOfData();
        }
    };
}
Also used : PeekingIterator(com.google.common.collect.PeekingIterator) SimpleAbstractColumnIterator(org.apache.cassandra.db.columniterator.SimpleAbstractColumnIterator) AbstractColumnIterator(org.apache.cassandra.db.filter.AbstractColumnIterator) IColumnIterator(org.apache.cassandra.db.columniterator.IColumnIterator) SimpleAbstractColumnIterator(org.apache.cassandra.db.columniterator.SimpleAbstractColumnIterator) ByteBuffer(java.nio.ByteBuffer)

Aggregations

IColumnIterator (org.apache.cassandra.db.columniterator.IColumnIterator)9 SSTableReader (org.apache.cassandra.io.sstable.SSTableReader)6 QueryFilter (org.apache.cassandra.db.filter.QueryFilter)5 File (java.io.File)3 ColumnFamily (org.apache.cassandra.db.ColumnFamily)3 IColumn (org.apache.cassandra.db.IColumn)3 QueryPath (org.apache.cassandra.db.filter.QueryPath)3 SSTableUtils.tempSSTableFile (org.apache.cassandra.io.sstable.SSTableUtils.tempSSTableFile)3 Test (org.junit.Test)3 ByteBuffer (java.nio.ByteBuffer)2 DeletedColumn (org.apache.cassandra.db.DeletedColumn)2 ExpiringColumn (org.apache.cassandra.db.ExpiringColumn)2 SimpleAbstractColumnIterator (org.apache.cassandra.db.columniterator.SimpleAbstractColumnIterator)2 CloseableIterator (org.apache.cassandra.utils.CloseableIterator)2 PeekingIterator (com.google.common.collect.PeekingIterator)1 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 CounterColumn (org.apache.cassandra.db.CounterColumn)1 SizeTieredCompactionStrategy (org.apache.cassandra.db.compaction.SizeTieredCompactionStrategy)1 AbstractColumnIterator (org.apache.cassandra.db.filter.AbstractColumnIterator)1