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);
}
}
}
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);
}
}
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);
}
Aggregations