fix nodetool's setcompactionthreshold command

patch by Aleksey Yeschenko; reviewed by Pavel Yaskevich for CASSANDRA-4455
This commit is contained in:
Pavel Yaskevich 2012-07-25 17:52:39 +03:00
parent f46232c0b0
commit cc0be1b400
6 changed files with 29 additions and 19 deletions

View File

@ -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)

View File

@ -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()

View File

@ -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
*/

View File

@ -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)

View File

@ -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)

View File

@ -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