make local copies of compaction thresholds so they can't be changed out from under us mid-method patch by jbellis for CASSANDRA-5214
Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/82de0ec7 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/82de0ec7 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/82de0ec7 Branch: refs/heads/cassandra-1.2 Commit: 82de0ec75689d84ee6a4fa2d9a960f3326e5387a Parents: b251e7a Author: Jonathan Ellis <jbel...@apache.org> Authored: Mon Feb 4 17:50:34 2013 +0100 Committer: Jonathan Ellis <jbel...@apache.org> Committed: Mon Feb 4 17:50:34 2013 +0100 ---------------------------------------------------------------------- .../compaction/SizeTieredCompactionStrategy.java | 10 +++++++--- 1 files changed, 7 insertions(+), 3 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/82de0ec7/src/java/org/apache/cassandra/db/compaction/SizeTieredCompactionStrategy.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/compaction/SizeTieredCompactionStrategy.java b/src/java/org/apache/cassandra/db/compaction/SizeTieredCompactionStrategy.java index 64ed744..5e01733 100644 --- a/src/java/org/apache/cassandra/db/compaction/SizeTieredCompactionStrategy.java +++ b/src/java/org/apache/cassandra/db/compaction/SizeTieredCompactionStrategy.java @@ -60,7 +60,10 @@ public class SizeTieredCompactionStrategy extends AbstractCompactionStrategy public synchronized AbstractCompactionTask getNextBackgroundTask(final int gcBefore) { - if (cfs.isCompactionDisabled()) + // make local copies so they can't be changed out from under us mid-method + int minThreshold = cfs.getMinimumCompactionThreshold(); + int maxThreshold = cfs.getMaximumCompactionThreshold(); + if (minThreshold == 0 || maxThreshold == 0) { logger.debug("Compaction is currently disabled."); return null; @@ -74,7 +77,7 @@ public class SizeTieredCompactionStrategy extends AbstractCompactionStrategy List<List<SSTableReader>> prunedBuckets = new ArrayList<List<SSTableReader>>(); for (List<SSTableReader> bucket : buckets) { - if (bucket.size() < cfs.getMinimumCompactionThreshold()) + if (bucket.size() < minThreshold) continue; Collections.sort(bucket, new Comparator<SSTableReader>() @@ -84,7 +87,8 @@ public class SizeTieredCompactionStrategy extends AbstractCompactionStrategy return o1.descriptor.generation - o2.descriptor.generation; } }); - prunedBuckets.add(bucket.subList(0, Math.min(bucket.size(), cfs.getMaximumCompactionThreshold()))); + List<SSTableReader> prunedBucket = bucket.subList(0, Math.min(bucket.size(), maxThreshold)); + prunedBuckets.add(prunedBucket); } if (prunedBuckets.isEmpty())