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();
}
};
}
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);
}
}
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);
}
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);
}
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);
}
Aggregations