CQL3: move {max/min}_compaction_thresholds to compaction options

patch by slebresne; reviewed by jbellis for CASSANDRA-4187


Project: http://git-wip-us.apache.org/repos/asf/cassandra/repo
Commit: http://git-wip-us.apache.org/repos/asf/cassandra/commit/f960f13a
Tree: http://git-wip-us.apache.org/repos/asf/cassandra/tree/f960f13a
Diff: http://git-wip-us.apache.org/repos/asf/cassandra/diff/f960f13a

Branch: refs/heads/trunk
Commit: f960f13a5405addb861bcf5dc6512efa7b18226d
Parents: 8dd6a34
Author: Sylvain Lebresne <sylv...@datastax.com>
Authored: Thu May 3 17:29:02 2012 +0200
Committer: Sylvain Lebresne <sylv...@datastax.com>
Committed: Thu May 3 17:30:40 2012 +0200

----------------------------------------------------------------------
 CHANGES.txt                                        |    2 +
 .../org/apache/cassandra/config/CFMetaData.java    |    4 +-
 src/java/org/apache/cassandra/cql3/CFPropDefs.java |   73 +++++++--------
 .../cql3/statements/AlterTableStatement.java       |   29 +------
 .../statements/CreateColumnFamilyStatement.java    |   17 +---
 5 files changed, 44 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/f960f13a/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index 8097485..3f3ff72 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -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)

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f960f13a/src/java/org/apache/cassandra/config/CFMetaData.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/config/CFMetaData.java 
b/src/java/org/apache/cassandra/config/CFMetaData.java
index 14b964f..e903bd7 100644
--- a/src/java/org/apache/cassandra/config/CFMetaData.java
+++ b/src/java/org/apache/cassandra/config/CFMetaData.java
@@ -254,8 +254,6 @@ public final class CFMetaData
         // 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();
     }
@@ -279,6 +277,8 @@ public final class CFMetaData
         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;

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f960f13a/src/java/org/apache/cassandra/cql3/CFPropDefs.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql3/CFPropDefs.java 
b/src/java/org/apache/cassandra/cql3/CFPropDefs.java
index 8196c4e..7072176 100644
--- a/src/java/org/apache/cassandra/cql3/CFPropDefs.java
+++ b/src/java/org/apache/cassandra/cql3/CFPropDefs.java
@@ -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);
@@ -120,41 +118,13 @@ public class CFPropDefs
      * 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 */
@@ -188,6 +158,27 @@ public class CFPropDefs
         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);
@@ -200,14 +191,14 @@ public class CFPropDefs
     }
 
     // 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);
@@ -222,17 +213,22 @@ public class CFPropDefs
             }
             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;
@@ -244,12 +240,13 @@ public class CFPropDefs
             }
             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)",

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f960f13a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java 
b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
index b1291fe..67b7dd7 100644
--- a/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
+++ b/src/java/org/apache/cassandra/cql3/statements/AlterTableStatement.java
@@ -138,40 +138,13 @@ public class AlterTableStatement extends 
SchemaAlteringStatement
                     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)",

http://git-wip-us.apache.org/repos/asf/cassandra/blob/f960f13a/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
----------------------------------------------------------------------
diff --git 
a/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
 
b/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
index c2dca2e..8c0806f 100644
--- 
a/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
+++ 
b/src/java/org/apache/cassandra/cql3/statements/CreateColumnFamilyStatement.java
@@ -101,23 +101,14 @@ public class CreateColumnFamilyStatement extends 
SchemaAlteringStatement
                                      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)
         {

Reply via email to