use of org.apache.cassandra.db.partitions.ImmutableBTreePartition in project cassandra by apache.
the class CompactionsPurgeTest method testMajorCompactionPurge.
@Test
public void testMajorCompactionPurge() {
CompactionManager.instance.disableAutoCompaction();
Keyspace keyspace = Keyspace.open(KEYSPACE1);
String cfName = "Standard1";
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfName);
String key = "key1";
// inserts
for (int i = 0; i < 10; i++) {
RowUpdateBuilder builder = new RowUpdateBuilder(cfs.metadata(), 0, key);
builder.clustering(String.valueOf(i)).add("val", ByteBufferUtil.EMPTY_BYTE_BUFFER).build().applyUnsafe();
}
cfs.forceBlockingFlush();
// deletes
for (int i = 0; i < 10; i++) {
RowUpdateBuilder.deleteRow(cfs.metadata(), 1, key, String.valueOf(i)).applyUnsafe();
}
cfs.forceBlockingFlush();
// resurrect one column
RowUpdateBuilder builder = new RowUpdateBuilder(cfs.metadata(), 2, key);
builder.clustering(String.valueOf(5)).add("val", ByteBufferUtil.EMPTY_BYTE_BUFFER).build().applyUnsafe();
cfs.forceBlockingFlush();
// major compact and test that all columns but the resurrected one is completely gone
FBUtilities.waitOnFutures(CompactionManager.instance.submitMaximal(cfs, Integer.MAX_VALUE, false));
cfs.invalidateCachedPartition(dk(key));
ImmutableBTreePartition partition = Util.getOnlyPartitionUnfiltered(Util.cmd(cfs, key).build());
assertEquals(1, partition.rowCount());
}
use of org.apache.cassandra.db.partitions.ImmutableBTreePartition in project cassandra by apache.
the class CompactionsPurgeTest method testMajorCompactionPurgeRangeTombstoneWithMaxTimestamp.
@Test
public void testMajorCompactionPurgeRangeTombstoneWithMaxTimestamp() {
CompactionManager.instance.disableAutoCompaction();
Keyspace keyspace = Keyspace.open(KEYSPACE1);
String cfName = "Standard1";
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfName);
String key = "key1";
// inserts
for (int i = 0; i < 10; i++) {
RowUpdateBuilder builder = new RowUpdateBuilder(cfs.metadata(), 0, key);
builder.clustering(String.valueOf(i)).add("val", ByteBufferUtil.EMPTY_BYTE_BUFFER).build().applyUnsafe();
}
cfs.forceBlockingFlush();
new RowUpdateBuilder(cfs.metadata(), Long.MAX_VALUE, dk(key)).addRangeTombstone(String.valueOf(0), String.valueOf(9)).build().applyUnsafe();
cfs.forceBlockingFlush();
// major compact - tombstones should be purged
FBUtilities.waitOnFutures(CompactionManager.instance.submitMaximal(cfs, Integer.MAX_VALUE, false));
// resurrect one column
RowUpdateBuilder builder = new RowUpdateBuilder(cfs.metadata(), 2, key);
builder.clustering(String.valueOf(5)).add("val", ByteBufferUtil.EMPTY_BYTE_BUFFER).build().applyUnsafe();
cfs.forceBlockingFlush();
cfs.invalidateCachedPartition(dk(key));
ImmutableBTreePartition partition = Util.getOnlyPartitionUnfiltered(Util.cmd(cfs, key).build());
assertEquals(1, partition.rowCount());
}
use of org.apache.cassandra.db.partitions.ImmutableBTreePartition in project cassandra by apache.
the class CompactionsPurgeTest method testMinorCompactionPurge.
@Test
public void testMinorCompactionPurge() {
CompactionManager.instance.disableAutoCompaction();
Keyspace keyspace = Keyspace.open(KEYSPACE2);
String cfName = "Standard1";
ColumnFamilyStore cfs = keyspace.getColumnFamilyStore(cfName);
for (int k = 1; k <= 2; ++k) {
String key = "key" + k;
// inserts
for (int i = 0; i < 10; i++) {
RowUpdateBuilder builder = new RowUpdateBuilder(cfs.metadata(), 0, key);
builder.clustering(String.valueOf(i)).add("val", ByteBufferUtil.EMPTY_BYTE_BUFFER).build().applyUnsafe();
}
cfs.forceBlockingFlush();
// deletes
for (int i = 0; i < 10; i++) {
RowUpdateBuilder.deleteRow(cfs.metadata(), 1, key, String.valueOf(i)).applyUnsafe();
}
cfs.forceBlockingFlush();
}
DecoratedKey key1 = Util.dk("key1");
DecoratedKey key2 = Util.dk("key2");
// flush, remember the current sstable and then resurrect one column
// for first key. Then submit minor compaction on remembered sstables.
cfs.forceBlockingFlush();
Collection<SSTableReader> sstablesIncomplete = cfs.getLiveSSTables();
RowUpdateBuilder builder = new RowUpdateBuilder(cfs.metadata(), 2, "key1");
builder.clustering(String.valueOf(5)).add("val", ByteBufferUtil.EMPTY_BYTE_BUFFER).build().applyUnsafe();
cfs.forceBlockingFlush();
List<AbstractCompactionTask> tasks = cfs.getCompactionStrategyManager().getUserDefinedTasks(sstablesIncomplete, Integer.MAX_VALUE);
assertEquals(1, tasks.size());
tasks.get(0).execute(null);
// verify that minor compaction does GC when key is provably not
// present in a non-compacted sstable
Util.assertEmpty(Util.cmd(cfs, key2).build());
// verify that minor compaction still GC when key is present
// in a non-compacted sstable but the timestamp ensures we won't miss anything
ImmutableBTreePartition partition = Util.getOnlyPartitionUnfiltered(Util.cmd(cfs, key1).build());
assertEquals(1, partition.rowCount());
}
Aggregations