Search in sources :

Example 11 with ImmutableBTreePartition

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());
}
Also used : ImmutableBTreePartition(org.apache.cassandra.db.partitions.ImmutableBTreePartition) Test(org.junit.Test)

Example 12 with ImmutableBTreePartition

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());
}
Also used : ImmutableBTreePartition(org.apache.cassandra.db.partitions.ImmutableBTreePartition) Test(org.junit.Test)

Example 13 with ImmutableBTreePartition

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());
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ImmutableBTreePartition(org.apache.cassandra.db.partitions.ImmutableBTreePartition) Test(org.junit.Test)

Aggregations

ImmutableBTreePartition (org.apache.cassandra.db.partitions.ImmutableBTreePartition)13 Test (org.junit.Test)11 Row (org.apache.cassandra.db.rows.Row)5 ByteBuffer (java.nio.ByteBuffer)4 ColumnMetadata (org.apache.cassandra.schema.ColumnMetadata)3 DecoratedKey (org.apache.cassandra.db.DecoratedKey)2 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)2 File (java.io.File)1 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)1 Mutation (org.apache.cassandra.db.Mutation)1 RowUpdateBuilder (org.apache.cassandra.db.RowUpdateBuilder)1 UnfilteredSerializer (org.apache.cassandra.db.rows.UnfilteredSerializer)1 IndexInfo (org.apache.cassandra.io.sstable.IndexInfo)1 TableMetadata (org.apache.cassandra.schema.TableMetadata)1 LongSerializer (org.apache.cassandra.serializers.LongSerializer)1