Skip to content

Commit

Permalink
CQL3: move {max/min}_compaction_thresholds to compaction options
Browse files Browse the repository at this point in the history
patch by slebresne; reviewed by jbellis for CASSANDRA-4187
  • Loading branch information
Sylvain Lebresne committed May 3, 2012
1 parent 8dd6a34 commit f960f13
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 81 deletions.
2 changes: 2 additions & 0 deletions CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
* (cql3) Minor fixes (CASSANDRA-4185)
* (cql3) Fix prepared statement in BATCH (CASSANDRA-4202)
* (cql3) Reduce the list of reserved keywords (CASSANDRA-4186)
* (cql3) Move max/min compaction thresholds to compaction strategy options
(CASSANDRA-4187)
Merged from 1.0:
* Fix super columns bug where cache is not updated (CASSANDRA-4190)
* fix maxTimestamp to include row tombstones (CASSANDRA-4116)
Expand Down
4 changes: 2 additions & 2 deletions src/java/org/apache/cassandra/config/CFMetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,8 +254,6 @@ public CFMetaData(String keyspace, String name, ColumnFamilyType type, AbstractT
// System cfs have specific ids, and copies of old CFMDs need
// to copy over the old id.
cfId = id;
caching = DEFAULT_CACHING_STRATEGY;
bloomFilterFpChance = DEFAULT_BF_FP_CHANCE;

this.init();
}
Expand All @@ -279,6 +277,8 @@ private void init()
gcGraceSeconds = DEFAULT_GC_GRACE_SECONDS;
minCompactionThreshold = DEFAULT_MIN_COMPACTION_THRESHOLD;
maxCompactionThreshold = DEFAULT_MAX_COMPACTION_THRESHOLD;
caching = DEFAULT_CACHING_STRATEGY;
bloomFilterFpChance = DEFAULT_BF_FP_CHANCE;

// Defaults strange or simple enough to not need a DEFAULT_T for
defaultValidator = BytesType.instance;
Expand Down
73 changes: 35 additions & 38 deletions src/java/org/apache/cassandra/cql3/CFPropDefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ public class CFPropDefs
keywords.add(KW_READREPAIRCHANCE);
keywords.add(KW_DCLOCALREADREPAIRCHANCE);
keywords.add(KW_GCGRACESECONDS);
keywords.add(KW_MINCOMPACTIONTHRESHOLD);
keywords.add(KW_MAXCOMPACTIONTHRESHOLD);
keywords.add(KW_REPLICATEONWRITE);
keywords.add(KW_COMPACTION_STRATEGY_CLASS);
keywords.add(KW_CACHING);
Expand Down Expand Up @@ -120,41 +118,13 @@ public static AbstractType<?> parseType(String type) throws InvalidRequestExcept
* knows what they are doing (a custom comparator/validator for example), and pass it on as-is.
*/

public void validate() throws InvalidRequestException
public void validate() throws ConfigurationException
{
// Catch the case where someone passed a kwarg that is not recognized.
for (String bogus : Sets.difference(properties.keySet(), allowedKeywords))
throw new InvalidRequestException(bogus + " is not a valid keyword argument for CREATE COLUMNFAMILY");
throw new ConfigurationException(bogus + " is not a valid keyword argument for CREATE TABLE");
for (String obsolete : Sets.intersection(properties.keySet(), obsoleteKeywords))
logger.warn("Ignoring obsolete property {}", obsolete);

// Validate min/max compaction thresholds
Integer minCompaction = getInt(KW_MINCOMPACTIONTHRESHOLD, null);
Integer maxCompaction = getInt(KW_MAXCOMPACTIONTHRESHOLD, null);

if ((minCompaction != null) && (maxCompaction != null)) // Both min and max are set
{
if ((minCompaction > maxCompaction) && (maxCompaction != 0))
throw new InvalidRequestException(String.format("%s cannot be larger than %s",
KW_MINCOMPACTIONTHRESHOLD,
KW_MAXCOMPACTIONTHRESHOLD));
}
else if (minCompaction != null) // Only the min threshold is set
{
if (minCompaction > CFMetaData.DEFAULT_MAX_COMPACTION_THRESHOLD)
throw new InvalidRequestException(String.format("%s cannot be larger than %s, (default %s)",
KW_MINCOMPACTIONTHRESHOLD,
KW_MAXCOMPACTIONTHRESHOLD,
CFMetaData.DEFAULT_MAX_COMPACTION_THRESHOLD));
}
else if (maxCompaction != null) // Only the max threshold is set
{
if ((maxCompaction < CFMetaData.DEFAULT_MIN_COMPACTION_THRESHOLD) && (maxCompaction != 0))
throw new InvalidRequestException(String.format("%s cannot be smaller than %s, (default %s)",
KW_MAXCOMPACTIONTHRESHOLD,
KW_MINCOMPACTIONTHRESHOLD,
CFMetaData.DEFAULT_MIN_COMPACTION_THRESHOLD));
}
}

/** Map a keyword to the corresponding value */
Expand Down Expand Up @@ -188,6 +158,27 @@ public Boolean hasProperty(String name)
return properties.containsKey(name);
}

public void applyToCFMetadata(CFMetaData cfm) throws ConfigurationException
{
if (hasProperty(KW_COMMENT))
cfm.comment(get(KW_COMMENT));

cfm.readRepairChance(getDouble(KW_READREPAIRCHANCE, cfm.getReadRepairChance()));
cfm.dcLocalReadRepairChance(getDouble(KW_DCLOCALREADREPAIRCHANCE, cfm.getDcLocalReadRepair()));
cfm.gcGraceSeconds(getInt(KW_GCGRACESECONDS, cfm.getGcGraceSeconds()));
cfm.replicateOnWrite(getBoolean(KW_REPLICATEONWRITE, cfm.getReplicateOnWrite()));
cfm.minCompactionThreshold(toInt(KW_MINCOMPACTIONTHRESHOLD, compactionStrategyOptions.get(KW_MINCOMPACTIONTHRESHOLD), cfm.getMinCompactionThreshold()));
cfm.maxCompactionThreshold(toInt(KW_MAXCOMPACTIONTHRESHOLD, compactionStrategyOptions.get(KW_MAXCOMPACTIONTHRESHOLD), cfm.getMaxCompactionThreshold()));
cfm.caching(CFMetaData.Caching.fromString(getString(KW_CACHING, cfm.getCaching().toString())));
cfm.bloomFilterFpChance(getDouble(KW_BF_FP_CHANCE, cfm.getBloomFilterFpChance()));

if (!compactionStrategyOptions.isEmpty())
cfm.compactionStrategyOptions(new HashMap<String, String>(compactionStrategyOptions));

if (!compressionParameters.isEmpty())
cfm.compressionParameters(CompressionParameters.create(compressionParameters));
}

public String get(String name)
{
return properties.get(name);
Expand All @@ -200,14 +191,14 @@ public String getString(String key, String defaultValue)
}

// Return a property value, typed as a Boolean
public Boolean getBoolean(String key, Boolean defaultValue) throws InvalidRequestException
public Boolean getBoolean(String key, Boolean defaultValue)
{
String value = properties.get(key);
return (value == null) ? defaultValue : value.toLowerCase().matches("(1|true|yes)");
}

// Return a property value, typed as a Double
public Double getDouble(String key, Double defaultValue) throws InvalidRequestException
public Double getDouble(String key, Double defaultValue) throws ConfigurationException
{
Double result;
String value = properties.get(key);
Expand All @@ -222,17 +213,22 @@ public Double getDouble(String key, Double defaultValue) throws InvalidRequestEx
}
catch (NumberFormatException e)
{
throw new InvalidRequestException(String.format("%s not valid for \"%s\"", value, key));
throw new ConfigurationException(String.format("%s not valid for \"%s\"", value, key));
}
}
return result;
}

// Return a property value, typed as an Integer
public Integer getInt(String key, Integer defaultValue) throws InvalidRequestException
public Integer getInt(String key, Integer defaultValue) throws ConfigurationException
{
Integer result;
String value = properties.get(key);
return toInt(key, value, defaultValue);
}

public static Integer toInt(String key, String value, Integer defaultValue) throws ConfigurationException
{
Integer result;

if (value == null)
result = defaultValue;
Expand All @@ -244,12 +240,13 @@ public Integer getInt(String key, Integer defaultValue) throws InvalidRequestExc
}
catch (NumberFormatException e)
{
throw new InvalidRequestException(String.format("%s not valid for \"%s\"", value, key));
throw new ConfigurationException(String.format("%s not valid for \"%s\"", value, key));
}
}
return result;
}


public String toString()
{
return String.format("CFPropDefs(%s, compaction: %s, compression: %s)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,40 +138,13 @@ public void announceMigration() throws InvalidRequestException, ConfigurationExc
throw new InvalidRequestException(String.format("ALTER COLUMNFAMILY WITH invoked, but no parameters found"));

cfProps.validate();
applyPropertiesToCFMetadata(cfm, cfProps);
cfProps.applyToCFMetadata(cfm);
break;
}

MigrationManager.announceColumnFamilyUpdate(cfm);
}

public static void applyPropertiesToCFMetadata(CFMetaData cfm, CFPropDefs cfProps) throws InvalidRequestException, ConfigurationException
{
if (cfProps.hasProperty(CFPropDefs.KW_COMMENT))
{
cfm.comment(cfProps.get(CFPropDefs.KW_COMMENT));
}

cfm.readRepairChance(cfProps.getDouble(CFPropDefs.KW_READREPAIRCHANCE, cfm.getReadRepairChance()));
cfm.dcLocalReadRepairChance(cfProps.getDouble(CFPropDefs.KW_DCLOCALREADREPAIRCHANCE, cfm.getDcLocalReadRepair()));
cfm.gcGraceSeconds(cfProps.getInt(CFPropDefs.KW_GCGRACESECONDS, cfm.getGcGraceSeconds()));
cfm.replicateOnWrite(cfProps.getBoolean(CFPropDefs.KW_REPLICATEONWRITE, cfm.getReplicateOnWrite()));
cfm.minCompactionThreshold(cfProps.getInt(CFPropDefs.KW_MINCOMPACTIONTHRESHOLD, cfm.getMinCompactionThreshold()));
cfm.maxCompactionThreshold(cfProps.getInt(CFPropDefs.KW_MAXCOMPACTIONTHRESHOLD, cfm.getMaxCompactionThreshold()));
cfm.caching(CFMetaData.Caching.fromString(cfProps.getString(CFPropDefs.KW_CACHING, cfm.getCaching().toString())));
cfm.bloomFilterFpChance(cfProps.getDouble(CFPropDefs.KW_BF_FP_CHANCE, cfm.getBloomFilterFpChance()));

if (!cfProps.compactionStrategyOptions.isEmpty())
{
cfm.compactionStrategyOptions(new HashMap<String, String>(cfProps.compactionStrategyOptions));
}

if (!cfProps.compressionParameters.isEmpty())
{
cfm.compressionParameters(CompressionParameters.create(cfProps.compressionParameters));
}
}

public String toString()
{
return String.format("AlterTableStatement(name=%s, type=%s, column=%s, validator=%s)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,23 +101,14 @@ public CFMetaData getCFMetaData() throws InvalidRequestException
comparator,
null);

newCFMD.comment(properties.get(CFPropDefs.KW_COMMENT))
.readRepairChance(properties.getDouble(CFPropDefs.KW_READREPAIRCHANCE, CFMetaData.DEFAULT_READ_REPAIR_CHANCE))
.dcLocalReadRepairChance(properties.getDouble(CFPropDefs.KW_DCLOCALREADREPAIRCHANCE, CFMetaData.DEFAULT_DCLOCAL_READ_REPAIR_CHANCE))
.replicateOnWrite(properties.getBoolean(CFPropDefs.KW_REPLICATEONWRITE, CFMetaData.DEFAULT_REPLICATE_ON_WRITE))
.gcGraceSeconds(properties.getInt(CFPropDefs.KW_GCGRACESECONDS, CFMetaData.DEFAULT_GC_GRACE_SECONDS))
.defaultValidator(defaultValidator)
.minCompactionThreshold(properties.getInt(CFPropDefs.KW_MINCOMPACTIONTHRESHOLD, CFMetaData.DEFAULT_MIN_COMPACTION_THRESHOLD))
.maxCompactionThreshold(properties.getInt(CFPropDefs.KW_MAXCOMPACTIONTHRESHOLD, CFMetaData.DEFAULT_MAX_COMPACTION_THRESHOLD))
newCFMD.defaultValidator(defaultValidator)
.columnMetadata(getColumns())
.keyValidator(keyValidator)
.keyAlias(keyAlias)
.columnAliases(columnAliases)
.valueAlias(valueAlias)
.compactionStrategyOptions(properties.compactionStrategyOptions)
.compressionParameters(CompressionParameters.create(properties.compressionParameters))
.caching(CFMetaData.Caching.fromString(properties.getString(CFPropDefs.KW_CACHING, CFMetaData.DEFAULT_CACHING_STRATEGY.toString())))
.bloomFilterFpChance(properties.getDouble(CFPropDefs.KW_BF_FP_CHANCE, CFMetaData.DEFAULT_BF_FP_CHANCE));
.valueAlias(valueAlias);

properties.applyToCFMetadata(newCFMD);
}
catch (ConfigurationException e)
{
Expand Down

0 comments on commit f960f13

Please sign in to comment.