use of org.apache.cassandra.db.partitions.FilteredPartition in project cassandra by apache.
the class CleanupTransientTest method testCleanup.
@Test
public void testCleanup() throws Exception {
Keyspace keyspace = Keyspace.open(KEYSPACE1);
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(CF_STANDARD1);
// insert data and verify we get it back w/ range query
fillCF(cfs, "val", LOOPS);
// record max timestamps of the sstables pre-cleanup
List<Long> expectedMaxTimestamps = getMaxTimestampList(cfs);
assertEquals(LOOPS, Util.getAll(Util.cmd(cfs).build()).size());
// with two tokens RF=2/1 and the sstable not repaired this should do nothing
CompactionManager.instance.performCleanup(cfs, 2);
// ensure max timestamp of the sstables are retained post-cleanup
assert expectedMaxTimestamps.equals(getMaxTimestampList(cfs));
// check data is still there
assertEquals(LOOPS, Util.getAll(Util.cmd(cfs).build()).size());
// Get an exact count of how many partitions are in the fully replicated range and should
// be retained
int fullCount = 0;
RangesAtEndpoint localRanges = StorageService.instance.getLocalReplicas(keyspace.getName()).filter(Replica::isFull);
for (FilteredPartition partition : Util.getAll(Util.cmd(cfs).build())) {
Token token = partition.partitionKey().getToken();
for (Replica r : localRanges) {
if (r.range().contains(token))
fullCount++;
}
}
SSTableReader sstable = cfs.getLiveSSTables().iterator().next();
sstable.descriptor.getMetadataSerializer().mutateRepairMetadata(sstable.descriptor, 1, null, false);
sstable.reloadSSTableMetadata();
// This should remove approximately 50% of the data, specifically whatever was transiently replicated
CompactionManager.instance.performCleanup(cfs, 2);
// ensure max timestamp of the sstables are retained post-cleanup
assert expectedMaxTimestamps.equals(getMaxTimestampList(cfs));
// check less data is there, all transient data should be gone since the table was repaired
assertEquals(fullCount, Util.getAll(Util.cmd(cfs).build()).size());
}
use of org.apache.cassandra.db.partitions.FilteredPartition in project cassandra by apache.
the class QueryPagerTest method rangeNamesQueryTest.
public void rangeNamesQueryTest(boolean testPagingState, ProtocolVersion protocolVersion) {
ReadCommand command = rangeNamesQuery("k0", "k5", 100, "c1", "c4", "c8");
QueryPager pager = command.getPager(null, protocolVersion);
assertFalse(pager.isExhausted());
List<FilteredPartition> partitions = query(pager, 3 * 3);
for (int i = 1; i <= 3; i++) assertRow(partitions.get(i - 1), "k" + i, "c1", "c4", "c8");
assertFalse(pager.isExhausted());
pager = maybeRecreate(pager, command, testPagingState, protocolVersion);
assertFalse(pager.isExhausted());
partitions = query(pager, 3 * 3, 2 * 3);
for (int i = 4; i <= 5; i++) assertRow(partitions.get(i - 4), "k" + i, "c1", "c4", "c8");
assertTrue(pager.isExhausted());
}
use of org.apache.cassandra.db.partitions.FilteredPartition in project cassandra by apache.
the class QueryPagerTest method multiQueryTest.
public void multiQueryTest(boolean testPagingState, ProtocolVersion protocolVersion) {
ReadQuery command = SinglePartitionReadCommand.Group.create(new ArrayList<SinglePartitionReadCommand>() {
{
add(sliceQuery("k1", "c2", "c6", 10));
add(sliceQuery("k4", "c3", "c5", 10));
}
}, DataLimits.NONE);
QueryPager pager = command.getPager(null, protocolVersion);
assertFalse(pager.isExhausted());
List<FilteredPartition> partition = query(pager, 3);
assertRow(partition.get(0), "k1", "c2", "c3", "c4");
assertFalse(pager.isExhausted());
pager = maybeRecreate(pager, command, testPagingState, protocolVersion);
assertFalse(pager.isExhausted());
partition = query(pager, 4);
assertRow(partition.get(0), "k1", "c5", "c6");
assertRow(partition.get(1), "k4", "c3", "c4");
assertFalse(pager.isExhausted());
pager = maybeRecreate(pager, command, testPagingState, protocolVersion);
assertFalse(pager.isExhausted());
partition = query(pager, 3, 1);
assertRow(partition.get(0), "k4", "c5");
assertTrue(pager.isExhausted());
}
use of org.apache.cassandra.db.partitions.FilteredPartition in project cassandra by apache.
the class QueryPagerTest method query.
private static List<FilteredPartition> query(QueryPager pager, int toQuery, int expectedSize) {
StringBuilder sb = new StringBuilder();
List<FilteredPartition> partitionList = new ArrayList<>();
int rows = 0;
try (ReadExecutionController executionController = pager.executionController();
PartitionIterator iterator = pager.fetchPageInternal(toQuery, executionController)) {
while (iterator.hasNext()) {
try (RowIterator rowIter = iterator.next()) {
FilteredPartition partition = FilteredPartition.create(rowIter);
sb.append(partition);
partitionList.add(partition);
rows += partition.rowCount();
}
}
}
assertEquals(sb.toString(), expectedSize, rows);
return partitionList;
}
use of org.apache.cassandra.db.partitions.FilteredPartition in project cassandra by apache.
the class QueryPagerTest method reversedSliceQueryTest.
public void reversedSliceQueryTest(boolean testPagingState, ProtocolVersion protocolVersion) {
ReadCommand command = sliceQuery("k0", "c1", "c8", true, 10);
QueryPager pager = command.getPager(null, protocolVersion);
assertFalse(pager.isExhausted());
List<FilteredPartition> partition = query(pager, 3);
assertRow(partition.get(0), "k0", "c6", "c7", "c8");
assertFalse(pager.isExhausted());
pager = maybeRecreate(pager, command, testPagingState, protocolVersion);
assertFalse(pager.isExhausted());
partition = query(pager, 3);
assertRow(partition.get(0), "k0", "c3", "c4", "c5");
assertFalse(pager.isExhausted());
pager = maybeRecreate(pager, command, testPagingState, protocolVersion);
assertFalse(pager.isExhausted());
partition = query(pager, 3, 2);
assertRow(partition.get(0), "k0", "c1", "c2");
assertTrue(pager.isExhausted());
}
Aggregations