From f7116c91b237d920249e5bcae653b47631f206c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Hegerfors?= Date: Tue, 31 Mar 2015 12:41:27 +0200 Subject: [PATCH] Don't wait for min_threshold sstables in the same window in DTCS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Patch by Björn Hegerfors; reviewed by marcuse for CASSANDRA-8360 --- CHANGES.txt | 1 + .../DateTieredCompactionStrategy.java | 18 ++++++++++++++---- .../DateTieredCompactionStrategyTest.java | 7 +++++-- 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index ed40a784ff..0bcc5cbc42 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,4 +1,5 @@ 2.0.14: + * Do more aggressive compaction in old time windows in DTCS (CASSANDRA-8360) * java.lang.AssertionError when reading saved cache (CASSANDRA-8740) * "disk full" when running cleanup (CASSANDRA-9036) * Make PasswordAuthenticator number of hashing rounds configurable (CASSANDRA-8085) diff --git a/src/java/org/apache/cassandra/db/compaction/DateTieredCompactionStrategy.java b/src/java/org/apache/cassandra/db/compaction/DateTieredCompactionStrategy.java index 9c708db73c..6b3e800633 100644 --- a/src/java/org/apache/cassandra/db/compaction/DateTieredCompactionStrategy.java +++ b/src/java/org/apache/cassandra/db/compaction/DateTieredCompactionStrategy.java @@ -103,7 +103,11 @@ public class DateTieredCompactionStrategy extends AbstractCompactionStrategy List> buckets = getBuckets(createSSTableAndMinTimestampPairs(candidates), options.baseTime, base, now); logger.debug("Compaction buckets are {}", buckets); updateEstimatedCompactionsByTasks(buckets); - List mostInteresting = newestBucket(buckets, cfs.getMinimumCompactionThreshold(), cfs.getMaximumCompactionThreshold()); + List mostInteresting = newestBucket(buckets, + cfs.getMinimumCompactionThreshold(), + cfs.getMaximumCompactionThreshold(), + options.baseTime, + now); if (!mostInteresting.isEmpty()) return mostInteresting; return null; @@ -298,12 +302,18 @@ public class DateTieredCompactionStrategy extends AbstractCompactionStrategy * @return a bucket (list) of sstables to compact. */ @VisibleForTesting - static List newestBucket(List> buckets, int minThreshold, int maxThreshold) + static List newestBucket(List> buckets, int minThreshold, int maxThreshold, long now, long baseTime) { - // Skip buckets containing less than minThreshold sstables, and limit other buckets to maxThreshold sstables. + // If the "incoming window" has at least minThreshold SSTables, choose that one. + // For any other bucket, at least 2 SSTables is enough. + // In any case, limit to maxThreshold SSTables. + Target incomingWindow = getInitialTarget(now, baseTime); for (List bucket : buckets) - if (bucket.size() >= minThreshold) + { + if (bucket.size() >= minThreshold || + (bucket.size() >= 2 && !incomingWindow.onTarget(bucket.get(0).getMinTimestamp()))) return trimToThreshold(bucket, maxThreshold); + } return Collections.emptyList(); } diff --git a/test/unit/org/apache/cassandra/db/compaction/DateTieredCompactionStrategyTest.java b/test/unit/org/apache/cassandra/db/compaction/DateTieredCompactionStrategyTest.java index 7d4857506d..f98e372a23 100644 --- a/test/unit/org/apache/cassandra/db/compaction/DateTieredCompactionStrategyTest.java +++ b/test/unit/org/apache/cassandra/db/compaction/DateTieredCompactionStrategyTest.java @@ -213,8 +213,11 @@ public class DateTieredCompactionStrategyTest extends SchemaLoader List sstrs = new ArrayList<>(cfs.getSSTables()); - List newBucket = newestBucket(Collections.singletonList(sstrs.subList(0, 2)), 4, 32); - assertTrue("nothing should be returned when all buckets are below the min threshold", newBucket.isEmpty()); + List newBucket = newestBucket(Collections.singletonList(sstrs.subList(0, 2)), 4, 32, 9, 10); + assertTrue("incoming bucket should not be accepted when it has below the min threshold SSTables", newBucket.isEmpty()); + + newBucket = newestBucket(Collections.singletonList(sstrs.subList(0, 2)), 4, 32, 10, 10); + assertFalse("non-incoming bucket should be accepted when it has at least 2 SSTables", newBucket.isEmpty()); assertEquals("an sstable with a single value should have equal min/max timestamps", sstrs.get(0).getMinTimestamp(), sstrs.get(0).getMaxTimestamp()); assertEquals("an sstable with a single value should have equal min/max timestamps", sstrs.get(1).getMinTimestamp(), sstrs.get(1).getMaxTimestamp());