Search in sources :

Example 1 with MajorLeveledCompactionWriter

use of org.apache.cassandra.db.compaction.writers.MajorLeveledCompactionWriter in project cassandra by apache.

the class CompactionAwareWriterTest method testMajorLeveledCompactionWriter.

@Test
public void testMajorLeveledCompactionWriter() throws Throwable {
    ColumnFamilyStore cfs = getColumnFamilyStore();
    cfs.disableAutoCompaction();
    int rowCount = 20000;
    int targetSSTableCount = 50;
    populate(rowCount);
    LifecycleTransaction txn = cfs.getTracker().tryModify(cfs.getLiveSSTables(), OperationType.COMPACTION);
    long beforeSize = txn.originals().iterator().next().onDiskLength();
    int sstableSize = (int) beforeSize / targetSSTableCount;
    CompactionAwareWriter writer = new MajorLeveledCompactionWriter(cfs, cfs.getDirectories(), txn, txn.originals(), sstableSize);
    int rows = compact(cfs, txn, writer);
    assertEquals(targetSSTableCount, cfs.getLiveSSTables().size());
    int[] levelCounts = new int[5];
    assertEquals(rowCount, rows);
    for (SSTableReader sstable : cfs.getLiveSSTables()) {
        levelCounts[sstable.getSSTableLevel()]++;
    }
    assertEquals(0, levelCounts[0]);
    assertEquals(10, levelCounts[1]);
    // note that if we want more levels, fix this
    assertEquals(targetSSTableCount - 10, levelCounts[2]);
    for (int i = 3; i < levelCounts.length; i++) assertEquals(0, levelCounts[i]);
    validateData(cfs, rowCount);
    cfs.truncateBlocking();
}
Also used : CompactionAwareWriter(org.apache.cassandra.db.compaction.writers.CompactionAwareWriter) SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) LifecycleTransaction(org.apache.cassandra.db.lifecycle.LifecycleTransaction) MajorLeveledCompactionWriter(org.apache.cassandra.db.compaction.writers.MajorLeveledCompactionWriter)

Aggregations

CompactionAwareWriter (org.apache.cassandra.db.compaction.writers.CompactionAwareWriter)1 MajorLeveledCompactionWriter (org.apache.cassandra.db.compaction.writers.MajorLeveledCompactionWriter)1 LifecycleTransaction (org.apache.cassandra.db.lifecycle.LifecycleTransaction)1 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)1