Search in sources :

Example 1 with UnfilteredPartitionIterator

use of org.apache.cassandra.db.partitions.UnfilteredPartitionIterator in project cassandra by apache.

the class KeysSearcher method queryDataFromIndex.

protected UnfilteredPartitionIterator queryDataFromIndex(final DecoratedKey indexKey, final RowIterator indexHits, final ReadCommand command, final ReadExecutionController executionController) {
    assert indexHits.staticRow() == Rows.EMPTY_STATIC_ROW;
    return new UnfilteredPartitionIterator() {

        private UnfilteredRowIterator next;

        public TableMetadata metadata() {
            return command.metadata();
        }

        public boolean hasNext() {
            return prepareNext();
        }

        public UnfilteredRowIterator next() {
            if (next == null)
                prepareNext();
            UnfilteredRowIterator toReturn = next;
            next = null;
            return toReturn;
        }

        private boolean prepareNext() {
            while (next == null && indexHits.hasNext()) {
                Row hit = indexHits.next();
                DecoratedKey key = index.baseCfs.decorateKey(hit.clustering().get(0));
                if (!command.selectsKey(key))
                    continue;
                ColumnFilter extendedFilter = getExtendedFilter(command.columnFilter());
                SinglePartitionReadCommand dataCmd = SinglePartitionReadCommand.create(index.baseCfs.metadata(), command.nowInSec(), extendedFilter, command.rowFilter(), DataLimits.NONE, key, command.clusteringIndexFilter(key));
                // filterIfStale closes it's iterator if either it materialize it or if it returns null.
                @SuppressWarnings("resource") UnfilteredRowIterator // by the next caller of next, or through closing this iterator is this come before.
                dataIter = filterIfStale(dataCmd.queryMemtableAndDisk(index.baseCfs, executionController), hit, indexKey.getKey(), executionController.writeOpOrderGroup(), command.nowInSec());
                if (dataIter != null) {
                    if (dataIter.isEmpty())
                        dataIter.close();
                    else
                        next = dataIter;
                }
            }
            return next != null;
        }

        public void remove() {
            throw new UnsupportedOperationException();
        }

        public void close() {
            indexHits.close();
            if (next != null)
                next.close();
        }
    };
}
Also used : UnfilteredPartitionIterator(org.apache.cassandra.db.partitions.UnfilteredPartitionIterator) ColumnFilter(org.apache.cassandra.db.filter.ColumnFilter)

Example 2 with UnfilteredPartitionIterator

use of org.apache.cassandra.db.partitions.UnfilteredPartitionIterator in project cassandra by apache.

the class SinglePartitionSliceCommandTest method staticColumnsAreReturned.

@Test
public void staticColumnsAreReturned() throws IOException {
    DecoratedKey key = metadata.partitioner.decorateKey(ByteBufferUtil.bytes("k1"));
    QueryProcessor.executeInternal("INSERT INTO ks.tbl (k, s) VALUES ('k1', 's')");
    Assert.assertFalse(QueryProcessor.executeInternal("SELECT s FROM ks.tbl WHERE k='k1'").isEmpty());
    ColumnFilter columnFilter = ColumnFilter.selection(RegularAndStaticColumns.of(s));
    ClusteringIndexSliceFilter sliceFilter = new ClusteringIndexSliceFilter(Slices.NONE, false);
    ReadCommand cmd = new SinglePartitionReadCommand(false, MessagingService.VERSION_30, metadata, FBUtilities.nowInSeconds(), columnFilter, RowFilter.NONE, DataLimits.NONE, key, sliceFilter);
    // check raw iterator for static cell
    try (ReadExecutionController executionController = cmd.executionController();
        UnfilteredPartitionIterator pi = cmd.executeLocally(executionController)) {
        checkForS(pi);
    }
    ReadResponse response;
    DataOutputBuffer out;
    DataInputPlus in;
    ReadResponse dst;
    // check (de)serialized iterator for memtable static cell
    try (ReadExecutionController executionController = cmd.executionController();
        UnfilteredPartitionIterator pi = cmd.executeLocally(executionController)) {
        response = ReadResponse.createDataResponse(pi, cmd);
    }
    out = new DataOutputBuffer((int) ReadResponse.serializer.serializedSize(response, MessagingService.VERSION_30));
    ReadResponse.serializer.serialize(response, out, MessagingService.VERSION_30);
    in = new DataInputBuffer(out.buffer(), true);
    dst = ReadResponse.serializer.deserialize(in, MessagingService.VERSION_30);
    try (UnfilteredPartitionIterator pi = dst.makeIterator(cmd)) {
        checkForS(pi);
    }
    // check (de)serialized iterator for sstable static cell
    Schema.instance.getColumnFamilyStoreInstance(metadata.id).forceBlockingFlush();
    try (ReadExecutionController executionController = cmd.executionController();
        UnfilteredPartitionIterator pi = cmd.executeLocally(executionController)) {
        response = ReadResponse.createDataResponse(pi, cmd);
    }
    out = new DataOutputBuffer((int) ReadResponse.serializer.serializedSize(response, MessagingService.VERSION_30));
    ReadResponse.serializer.serialize(response, out, MessagingService.VERSION_30);
    in = new DataInputBuffer(out.buffer(), true);
    dst = ReadResponse.serializer.deserialize(in, MessagingService.VERSION_30);
    try (UnfilteredPartitionIterator pi = dst.makeIterator(cmd)) {
        checkForS(pi);
    }
}
Also used : ClusteringIndexSliceFilter(org.apache.cassandra.db.filter.ClusteringIndexSliceFilter) DataInputBuffer(org.apache.cassandra.io.util.DataInputBuffer) DataOutputBuffer(org.apache.cassandra.io.util.DataOutputBuffer) UnfilteredPartitionIterator(org.apache.cassandra.db.partitions.UnfilteredPartitionIterator) DataInputPlus(org.apache.cassandra.io.util.DataInputPlus) ColumnFilter(org.apache.cassandra.db.filter.ColumnFilter) Test(org.junit.Test)

Example 3 with UnfilteredPartitionIterator

use of org.apache.cassandra.db.partitions.UnfilteredPartitionIterator in project cassandra by apache.

the class RepairedDataTombstonesTest method readTestPartitionTombstones.

@Test
public void readTestPartitionTombstones() throws Throwable {
    createTable("create table %s (id int, id2 int, t text, t2 text, primary key (id, id2)) with gc_grace_seconds=0 and compaction = {'class':'SizeTieredCompactionStrategy', 'only_purge_repaired_tombstones':true}");
    for (int i = 0; i < 10; i++) {
        execute("delete from %s where id=?", i);
    }
    flush();
    SSTableReader repairedSSTable = getCurrentColumnFamilyStore().getSSTables(SSTableSet.LIVE).iterator().next();
    repair(getCurrentColumnFamilyStore(), repairedSSTable);
    Thread.sleep(2000);
    for (int i = 10; i < 20; i++) {
        execute("delete from %s where id=?", i);
    }
    flush();
    Thread.sleep(1000);
    ReadCommand cmd = Util.cmd(getCurrentColumnFamilyStore()).build();
    int partitionsFound = 0;
    try (ReadExecutionController executionController = cmd.executionController();
        UnfilteredPartitionIterator iterator = cmd.executeLocally(executionController)) {
        while (iterator.hasNext()) {
            partitionsFound++;
            try (UnfilteredRowIterator rowIter = iterator.next()) {
                int val = ByteBufferUtil.toInt(rowIter.partitionKey().getKey());
                assertTrue("val=" + val, val >= 10 && val < 20);
            }
        }
    }
    assertEquals(10, partitionsFound);
}
Also used : UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) UnfilteredPartitionIterator(org.apache.cassandra.db.partitions.UnfilteredPartitionIterator) Test(org.junit.Test)

Example 4 with UnfilteredPartitionIterator

use of org.apache.cassandra.db.partitions.UnfilteredPartitionIterator in project cassandra by apache.

the class RepairedDataTombstonesTest method verify2.

private void verify2(int key, int expectedRows, int minVal, int maxVal, boolean includePurgeable) {
    ReadCommand cmd = Util.cmd(getCurrentColumnFamilyStore(), Util.dk(ByteBufferUtil.bytes(key))).build();
    int foundRows = 0;
    try (ReadExecutionController executionController = cmd.executionController();
        UnfilteredPartitionIterator iterator = includePurgeable ? cmd.queryStorage(getCurrentColumnFamilyStore(), executionController) : cmd.executeLocally(executionController)) {
        while (iterator.hasNext()) {
            try (UnfilteredRowIterator rowIter = iterator.next()) {
                while (rowIter.hasNext()) {
                    AbstractRow row = (AbstractRow) rowIter.next();
                    for (int i = 0; i < row.clustering().size(); i++) {
                        foundRows++;
                        int val = ByteBufferUtil.toInt(row.clustering().get(i));
                        assertTrue("val=" + val, val >= minVal && val < maxVal);
                    }
                }
            }
        }
    }
    assertEquals(expectedRows, foundRows);
}
Also used : UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) AbstractRow(org.apache.cassandra.db.rows.AbstractRow) UnfilteredPartitionIterator(org.apache.cassandra.db.partitions.UnfilteredPartitionIterator)

Example 5 with UnfilteredPartitionIterator

use of org.apache.cassandra.db.partitions.UnfilteredPartitionIterator in project cassandra by apache.

the class RepairedDataTombstonesTest method verify.

private void verify(int expectedRows, int minVal, int maxVal, boolean includePurgeable) {
    ReadCommand cmd = Util.cmd(getCurrentColumnFamilyStore()).build();
    int foundRows = 0;
    try (ReadExecutionController executionController = cmd.executionController();
        UnfilteredPartitionIterator iterator = includePurgeable ? cmd.queryStorage(getCurrentColumnFamilyStore(), executionController) : cmd.executeLocally(executionController)) {
        while (iterator.hasNext()) {
            try (UnfilteredRowIterator rowIter = iterator.next()) {
                if (// partition key 999 is 'live' and used to avoid sstables from being dropped
                !rowIter.partitionKey().equals(Util.dk(ByteBufferUtil.bytes(999)))) {
                    while (rowIter.hasNext()) {
                        AbstractRow row = (AbstractRow) rowIter.next();
                        for (int i = 0; i < row.clustering().size(); i++) {
                            foundRows++;
                            int val = ByteBufferUtil.toInt(row.clustering().get(i));
                            assertTrue("val=" + val, val >= minVal && val < maxVal);
                        }
                    }
                }
            }
        }
    }
    assertEquals(expectedRows, foundRows);
}
Also used : UnfilteredRowIterator(org.apache.cassandra.db.rows.UnfilteredRowIterator) AbstractRow(org.apache.cassandra.db.rows.AbstractRow) UnfilteredPartitionIterator(org.apache.cassandra.db.partitions.UnfilteredPartitionIterator)

Aggregations

UnfilteredPartitionIterator (org.apache.cassandra.db.partitions.UnfilteredPartitionIterator)10 UnfilteredRowIterator (org.apache.cassandra.db.rows.UnfilteredRowIterator)4 Test (org.junit.Test)4 ClusteringIndexSliceFilter (org.apache.cassandra.db.filter.ClusteringIndexSliceFilter)3 ColumnFilter (org.apache.cassandra.db.filter.ColumnFilter)3 ArrayList (java.util.ArrayList)2 AbstractRow (org.apache.cassandra.db.rows.AbstractRow)2 DataInputBuffer (org.apache.cassandra.io.util.DataInputBuffer)2 DataOutputBuffer (org.apache.cassandra.io.util.DataOutputBuffer)2 ByteBuffer (java.nio.ByteBuffer)1 ClusteringIndexNamesFilter (org.apache.cassandra.db.filter.ClusteringIndexNamesFilter)1 RowFilter (org.apache.cassandra.db.filter.RowFilter)1 PartitionIterator (org.apache.cassandra.db.partitions.PartitionIterator)1 UnfilteredPartitionIterators (org.apache.cassandra.db.partitions.UnfilteredPartitionIterators)1 Row (org.apache.cassandra.db.rows.Row)1 RowIterator (org.apache.cassandra.db.rows.RowIterator)1 IndexEntry (org.apache.cassandra.index.internal.IndexEntry)1 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)1 DataInputPlus (org.apache.cassandra.io.util.DataInputPlus)1 MessageOut (org.apache.cassandra.net.MessageOut)1