// remove new sstables from compactions that didn't complete, and compute
// set of ancestors that shouldn't exist anymore
Set<Integer> completedAncestors = new HashSet<>();
for (Map.Entry<Descriptor, Set<Component>> sstableFiles : directories.sstableLister().skipTemporary(true).list().entrySet())
{
Descriptor desc = sstableFiles.getKey();
Set<Integer> ancestors;
try
{
CompactionMetadata compactionMetadata = (CompactionMetadata) desc.getMetadataSerializer().deserialize(desc, MetadataType.COMPACTION);
ancestors = compactionMetadata.ancestors;
}
catch (IOException e)
{
throw new FSReadError(e, desc.filenameFor(Component.STATS));
}
if (!ancestors.isEmpty()
&& unfinishedGenerations.containsAll(ancestors)
&& allGenerations.containsAll(ancestors))
{
// any of the ancestors would work, so we'll just lookup the compaction task ID with the first one
UUID compactionTaskID = unfinishedCompactions.get(ancestors.iterator().next());
assert compactionTaskID != null;
logger.debug("Going to delete unfinished compaction product {}", desc);
SSTable.delete(desc, sstableFiles.getValue());
SystemKeyspace.finishCompaction(compactionTaskID);
}
else
{
completedAncestors.addAll(ancestors);
}
}
// remove old sstables from compactions that did complete
for (Map.Entry<Descriptor, Set<Component>> sstableFiles : directories.sstableLister().list().entrySet())
{
Descriptor desc = sstableFiles.getKey();
if (completedAncestors.contains(desc.generation))
{
// if any of the ancestors were participating in a compaction, finish that compaction
logger.debug("Going to delete leftover compaction ancestor {}", desc);
SSTable.delete(desc, sstableFiles.getValue());