Search in sources :

Example 1 with GroupedSSTableContainer

use of org.apache.cassandra.db.compaction.AbstractStrategyHolder.GroupedSSTableContainer 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)

Example 2 with GroupedSSTableContainer

use of org.apache.cassandra.db.compaction.AbstractStrategyHolder.GroupedSSTableContainer in project cassandra by apache.

the class CompactionStrategyManager method handleRepairStatusChangedNotification.

/**
 * Should only be called holding the readLock
 */
private void handleRepairStatusChangedNotification(Iterable<SSTableReader> sstables) {
    List<GroupedSSTableContainer> groups = groupSSTables(sstables);
    for (int i = 0; i < holders.size(); i++) {
        GroupedSSTableContainer group = groups.get(i);
        if (group.isEmpty())
            continue;
        AbstractStrategyHolder dstHolder = holders.get(i);
        for (AbstractStrategyHolder holder : holders) {
            if (holder != dstHolder)
                holder.removeSSTables(group);
        }
        // adding sstables into another strategy may change its level,
        // thus it won't be removed from original LCS. We have to remove sstables first
        dstHolder.addSSTables(group);
    }
}
Also used : GroupedSSTableContainer(org.apache.cassandra.db.compaction.AbstractStrategyHolder.GroupedSSTableContainer)

Example 3 with GroupedSSTableContainer

use of org.apache.cassandra.db.compaction.AbstractStrategyHolder.GroupedSSTableContainer in project cassandra by apache.

the class CompactionStrategyManager method maybeGetScanners.

/**
 * Create ISSTableScanners from the given sstables
 *
 * Delegates the call to the compaction strategies to allow LCS to create a scanner
 * @param sstables
 * @param ranges
 * @return
 */
@SuppressWarnings("resource")
public AbstractCompactionStrategy.ScannerList maybeGetScanners(Collection<SSTableReader> sstables, Collection<Range<Token>> ranges) {
    maybeReloadDiskBoundaries();
    List<ISSTableScanner> scanners = new ArrayList<>(sstables.size());
    readLock.lock();
    try {
        List<GroupedSSTableContainer> sstableGroups = groupSSTables(sstables);
        for (int i = 0; i < holders.size(); i++) {
            AbstractStrategyHolder holder = holders.get(i);
            GroupedSSTableContainer group = sstableGroups.get(i);
            scanners.addAll(holder.getScanners(group, ranges));
        }
    } catch (PendingRepairManager.IllegalSSTableArgumentException e) {
        ISSTableScanner.closeAllAndPropagate(scanners, new ConcurrentModificationException(e));
    } finally {
        readLock.unlock();
    }
    return new AbstractCompactionStrategy.ScannerList(scanners);
}
Also used : ISSTableScanner(org.apache.cassandra.io.sstable.ISSTableScanner) ConcurrentModificationException(java.util.ConcurrentModificationException) ArrayList(java.util.ArrayList) GroupedSSTableContainer(org.apache.cassandra.db.compaction.AbstractStrategyHolder.GroupedSSTableContainer)

Aggregations

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