diff --git a/CHANGES.txt b/CHANGES.txt index c160d69f0b..169f66dcc4 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -18,6 +18,7 @@ * Fix LCS bug with sstable containing only 1 row (CASSANDRA-4411) * fix "Can't Modify Index Name" problem on CF update (CASSANDRA-4439) * Fix assertion error in getOverlappingSSTables during repair (CASSANDRA-4456) + * fix nodetool's setcompactionthreshold command (CASSANDRA-4455) Merged from 1.0: * allow dropping columns shadowed by not-yet-expired supercolumn or row tombstones in PrecompactedRow (CASSANDRA-4396) diff --git a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java index 0b66020ec4..b93adc19e4 100644 --- a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java +++ b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java @@ -1845,6 +1845,18 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean return compactionStrategy; } + public void setCompactionThresholds(int minThreshold, int maxThreshold) + { + validateCompactionThresholds(minThreshold, maxThreshold); + + minCompactionThreshold.set(minThreshold); + maxCompactionThreshold.set(maxThreshold); + + // this is called as part of CompactionStrategy constructor; avoid circular dependency by checking for null + if (compactionStrategy != null) + CompactionManager.instance.submitBackground(this); + } + public int getMinimumCompactionThreshold() { return minCompactionThreshold.value(); @@ -1852,14 +1864,8 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean public void setMinimumCompactionThreshold(int minCompactionThreshold) { - if ((minCompactionThreshold > this.maxCompactionThreshold.value()) && this.maxCompactionThreshold.value() != 0) - throw new RuntimeException("The min_compaction_threshold cannot be larger than the max."); - + validateCompactionThresholds(minCompactionThreshold, maxCompactionThreshold.value()); this.minCompactionThreshold.set(minCompactionThreshold); - - // this is called as part of CompactionStrategy constructor; avoid circular dependency by checking for null - if (compactionStrategy != null) - CompactionManager.instance.submitBackground(this); } public int getMaximumCompactionThreshold() @@ -1869,14 +1875,15 @@ public class ColumnFamilyStore implements ColumnFamilyStoreMBean public void setMaximumCompactionThreshold(int maxCompactionThreshold) { - if (maxCompactionThreshold > 0 && maxCompactionThreshold < this.minCompactionThreshold.value()) - throw new RuntimeException("The max_compaction_threshold cannot be smaller than the min."); - + validateCompactionThresholds(minCompactionThreshold.value(), maxCompactionThreshold); this.maxCompactionThreshold.set(maxCompactionThreshold); + } - // this is called as part of CompactionStrategy constructor; avoid circular dependency by checking for null - if (compactionStrategy != null) - CompactionManager.instance.submitBackground(this); + private void validateCompactionThresholds(int minThreshold, int maxThreshold) + { + if (minThreshold > maxThreshold && maxThreshold != 0) + throw new RuntimeException(String.format("The min_compaction_threshold cannot be larger than the max_compaction_threshold. " + + "Min is '%d', Max is '%d'.", minThreshold, maxThreshold)); } public boolean isCompactionDisabled() diff --git a/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java b/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java index 68448c97e9..1d9959e258 100644 --- a/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java +++ b/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java @@ -182,6 +182,11 @@ public interface ColumnFamilyStoreMBean */ public int getMaximumCompactionThreshold(); + /** + * Sets the maximum and maximum number of SSTables in queue before compaction kicks off + */ + public void setCompactionThresholds(int minThreshold, int maxThreshold); + /** * Sets the maximum number of sstables in queue before compaction kicks off */ diff --git a/src/java/org/apache/cassandra/db/compaction/SizeTieredCompactionStrategy.java b/src/java/org/apache/cassandra/db/compaction/SizeTieredCompactionStrategy.java index 63ec442487..3ee4d01dea 100644 --- a/src/java/org/apache/cassandra/db/compaction/SizeTieredCompactionStrategy.java +++ b/src/java/org/apache/cassandra/db/compaction/SizeTieredCompactionStrategy.java @@ -43,8 +43,7 @@ public class SizeTieredCompactionStrategy extends AbstractCompactionStrategy this.estimatedRemainingTasks = 0; String optionValue = options.get(MIN_SSTABLE_SIZE_KEY); minSSTableSize = (null != optionValue) ? Long.parseLong(optionValue) : DEFAULT_MIN_SSTABLE_SIZE; - cfs.setMaximumCompactionThreshold(cfs.metadata.getMaxCompactionThreshold()); - cfs.setMinimumCompactionThreshold(cfs.metadata.getMinCompactionThreshold()); + cfs.setCompactionThresholds(cfs.metadata.getMinCompactionThreshold(), cfs.metadata.getMaxCompactionThreshold()); } public AbstractCompactionTask getNextBackgroundTask(final int gcBefore) diff --git a/src/java/org/apache/cassandra/tools/NodeProbe.java b/src/java/org/apache/cassandra/tools/NodeProbe.java index 5c04eff805..5488d7513c 100644 --- a/src/java/org/apache/cassandra/tools/NodeProbe.java +++ b/src/java/org/apache/cassandra/tools/NodeProbe.java @@ -440,8 +440,7 @@ public class NodeProbe public void setCompactionThreshold(String ks, String cf, int minimumCompactionThreshold, int maximumCompactionThreshold) { ColumnFamilyStoreMBean cfsProxy = getCfsProxy(ks, cf); - cfsProxy.setMinimumCompactionThreshold(minimumCompactionThreshold); - cfsProxy.setMaximumCompactionThreshold(maximumCompactionThreshold); + cfsProxy.setCompactionThresholds(minimumCompactionThreshold, maximumCompactionThreshold); } public void setCacheCapacities(String tableName, String cfName, int keyCacheCapacity, int rowCacheCapacity) diff --git a/test/unit/org/apache/cassandra/db/compaction/CompactionsTest.java b/test/unit/org/apache/cassandra/db/compaction/CompactionsTest.java index 6339224150..55616a23b5 100644 --- a/test/unit/org/apache/cassandra/db/compaction/CompactionsTest.java +++ b/test/unit/org/apache/cassandra/db/compaction/CompactionsTest.java @@ -194,8 +194,7 @@ public class CompactionsTest extends SchemaLoader private void forceCompactions(ColumnFamilyStore cfs) throws ExecutionException, InterruptedException { // re-enable compaction with thresholds low enough to force a few rounds - cfs.setMinimumCompactionThreshold(2); - cfs.setMaximumCompactionThreshold(4); + cfs.setCompactionThresholds(2, 4); // loop submitting parallel compactions until they all return 0 do