diff --git a/src/java/org/apache/cassandra/db/compaction/CompactionManager.java b/src/java/org/apache/cassandra/db/compaction/CompactionManager.java index dcf86a831c..5207f49811 100644 --- a/src/java/org/apache/cassandra/db/compaction/CompactionManager.java +++ b/src/java/org/apache/cassandra/db/compaction/CompactionManager.java @@ -460,12 +460,18 @@ public class CompactionManager implements CompactionManagerMBean Iterator sstableIterator = sstables.iterator(); try { + List> normalizedRanges = Range.normalize(ranges); + while (sstableIterator.hasNext()) { SSTableReader sstable = sstableIterator.next(); - for (Range r : Range.normalize(ranges)) + + Range sstableRange = new Range<>(sstable.first.getToken(), sstable.last.getToken()); + + boolean shouldAnticompact = false; + + for (Range r : normalizedRanges) { - Range sstableRange = new Range<>(sstable.first.getToken(), sstable.last.getToken()); if (r.contains(sstableRange)) { logger.info("SSTable {} fully contained in range {}, mutating repairedAt instead of anticompacting", sstable, r); @@ -473,20 +479,22 @@ public class CompactionManager implements CompactionManagerMBean sstable.reloadSSTableMetadata(); mutatedRepairStatuses.add(sstable); sstableIterator.remove(); + shouldAnticompact = true; break; } - else if (!sstableRange.intersects(r)) - { - logger.info("SSTable {} ({}) does not intersect repaired range {}, not touching repairedAt.", sstable, sstableRange, r); - nonAnticompacting.add(sstable); - sstableIterator.remove(); - break; - } - else + else if (sstableRange.intersects(r)) { logger.info("SSTable {} ({}) will be anticompacted on range {}", sstable, sstableRange, r); + shouldAnticompact = true; } } + + if (!shouldAnticompact) + { + logger.info("SSTable {} ({}) does not intersect repaired ranges {}, not touching repairedAt.", sstable, sstableRange, normalizedRanges); + nonAnticompacting.add(sstable); + sstableIterator.remove(); + } } cfs.getTracker().notifySSTableRepairedStatusChanged(mutatedRepairStatuses); txn.cancel(Sets.union(nonAnticompacting, mutatedRepairStatuses)); diff --git a/test/unit/org/apache/cassandra/db/compaction/AntiCompactionTest.java b/test/unit/org/apache/cassandra/db/compaction/AntiCompactionTest.java index a3167f9aa2..cd82b19342 100644 --- a/test/unit/org/apache/cassandra/db/compaction/AntiCompactionTest.java +++ b/test/unit/org/apache/cassandra/db/compaction/AntiCompactionTest.java @@ -302,14 +302,14 @@ public class AntiCompactionTest Collection sstables = getUnrepairedSSTables(store); assertEquals(store.getLiveSSTables().size(), sstables.size()); - Range range = new Range(new BytesToken("-10".getBytes()), new BytesToken("-1".getBytes())); + Range range = new Range(new BytesToken("-1".getBytes()), new BytesToken("-10".getBytes())); List> ranges = Arrays.asList(range); try (LifecycleTransaction txn = store.getTracker().tryModify(sstables, OperationType.ANTICOMPACTION); Refs refs = Refs.ref(sstables)) { - CompactionManager.instance.performAnticompaction(store, ranges, refs, txn, 0); + CompactionManager.instance.performAnticompaction(store, ranges, refs, txn, 1); } assertThat(store.getLiveSSTables().size(), is(10));