Search in sources :

Example 1 with DiskBoundaries

use of org.apache.cassandra.db.DiskBoundaries in project cassandra by apache.

the class CompactionStrategyManagerTest method groupSSTables.

/**
 * Test that csm.groupSSTables correctly groups sstables by repaired status and directory
 */
@Test
public void groupSSTables() throws Exception {
    final int numDir = 4;
    ColumnFamilyStore cfs = createJBODMockCFS(numDir);
    Keyspace.open(cfs.keyspace.getName()).getColumnFamilyStore(cfs.name).disableAutoCompaction();
    assertTrue(cfs.getLiveSSTables().isEmpty());
    List<SSTableReader> transientRepairs = new ArrayList<>();
    List<SSTableReader> pendingRepair = new ArrayList<>();
    List<SSTableReader> unrepaired = new ArrayList<>();
    List<SSTableReader> repaired = new ArrayList<>();
    for (int i = 0; i < numDir; i++) {
        int key = 100 * i;
        transientRepairs.add(createSSTableWithKey(cfs.keyspace.getName(), cfs.name, key++));
        pendingRepair.add(createSSTableWithKey(cfs.keyspace.getName(), cfs.name, key++));
        unrepaired.add(createSSTableWithKey(cfs.keyspace.getName(), cfs.name, key++));
        repaired.add(createSSTableWithKey(cfs.keyspace.getName(), cfs.name, key++));
    }
    cfs.getCompactionStrategyManager().mutateRepaired(transientRepairs, 0, UUID.randomUUID(), true);
    cfs.getCompactionStrategyManager().mutateRepaired(pendingRepair, 0, UUID.randomUUID(), false);
    cfs.getCompactionStrategyManager().mutateRepaired(repaired, 1000, null, false);
    DiskBoundaries boundaries = new DiskBoundaries(cfs, cfs.getDirectories().getWriteableLocations(), Lists.newArrayList(forKey(100), forKey(200), forKey(300)), 10, 10);
    CompactionStrategyManager csm = new CompactionStrategyManager(cfs, () -> boundaries, true);
    List<GroupedSSTableContainer> grouped = csm.groupSSTables(Iterables.concat(transientRepairs, pendingRepair, repaired, unrepaired));
    for (int x = 0; x < grouped.size(); x++) {
        GroupedSSTableContainer group = grouped.get(x);
        AbstractStrategyHolder holder = csm.getHolders().get(x);
        for (int y = 0; y < numDir; y++) {
            SSTableReader sstable = Iterables.getOnlyElement(group.getGroup(y));
            assertTrue(holder.managesSSTable(sstable));
            SSTableReader expected;
            if (sstable.isRepaired())
                expected = repaired.get(y);
            else if (sstable.isPendingRepair()) {
                if (sstable.isTransient()) {
                    expected = transientRepairs.get(y);
                } else {
                    expected = pendingRepair.get(y);
                }
            } else
                expected = unrepaired.get(y);
            assertSame(expected, sstable);
        }
    }
}
Also used : SSTableReader(org.apache.cassandra.io.sstable.format.SSTableReader) ColumnFamilyStore(org.apache.cassandra.db.ColumnFamilyStore) ArrayList(java.util.ArrayList) DiskBoundaries(org.apache.cassandra.db.DiskBoundaries) GroupedSSTableContainer(org.apache.cassandra.db.compaction.AbstractStrategyHolder.GroupedSSTableContainer) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 ColumnFamilyStore (org.apache.cassandra.db.ColumnFamilyStore)1 DiskBoundaries (org.apache.cassandra.db.DiskBoundaries)1 GroupedSSTableContainer (org.apache.cassandra.db.compaction.AbstractStrategyHolder.GroupedSSTableContainer)1 SSTableReader (org.apache.cassandra.io.sstable.format.SSTableReader)1 Test (org.junit.Test)1