Updated Branches: refs/heads/cassandra-1.1 f46232c0b -> cc0be1b40
fix nodetool's setcompactionthreshold command patch by Aleksey Yeschenko; reviewed by Pavel Yaskevich for CASSANDRA-4455 Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/cc0be1b4 Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/cc0be1b4 Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/cc0be1b4 Branch: refs/heads/cassandra-1.1 Commit: cc0be1b40007ef4b653e4ad6bc4dbe0438b97785 Parents: f46232c Author: Pavel Yaskevich <xe...@apache.org> Authored: Wed Jul 25 17:52:39 2012 +0300 Committer: Pavel Yaskevich <xe...@apache.org> Committed: Wed Jul 25 21:59:38 2012 +0300 ---------------------------------------------------------------------- CHANGES.txt | 1 + .../org/apache/cassandra/db/ColumnFamilyStore.java | 33 +++++++++------ .../cassandra/db/ColumnFamilyStoreMBean.java | 5 ++ .../compaction/SizeTieredCompactionStrategy.java | 3 +- src/java/org/apache/cassandra/tools/NodeProbe.java | 3 +- .../cassandra/db/compaction/CompactionsTest.java | 3 +- 6 files changed, 29 insertions(+), 19 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc0be1b4/CHANGES.txt ---------------------------------------------------------------------- diff --git a/CHANGES.txt b/CHANGES.txt index c160d69..169f66d 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) http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc0be1b4/src/java/org/apache/cassandra/db/ColumnFamilyStore.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java index 0b66020..b93adc1 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() http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc0be1b4/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java b/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java index 68448c9..1d9959e 100644 --- a/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java +++ b/src/java/org/apache/cassandra/db/ColumnFamilyStoreMBean.java @@ -183,6 +183,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 */ public void setMaximumCompactionThreshold(int threshold); http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc0be1b4/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 63ec442..3ee4d01 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) http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc0be1b4/src/java/org/apache/cassandra/tools/NodeProbe.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/cassandra/tools/NodeProbe.java b/src/java/org/apache/cassandra/tools/NodeProbe.java index 5c04eff..5488d75 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) http://git-wip-us.apache.org/repos/asf/cassandra/blob/cc0be1b4/test/unit/org/apache/cassandra/db/compaction/CompactionsTest.java ---------------------------------------------------------------------- diff --git a/test/unit/org/apache/cassandra/db/compaction/CompactionsTest.java b/test/unit/org/apache/cassandra/db/compaction/CompactionsTest.java index 6339224..55616a2 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