cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From slebre...@apache.org
Subject svn commit: r1211486 - in /cassandra/branches/cassandra-0.8: CHANGES.txt src/java/org/apache/cassandra/config/CFMetaData.java src/java/org/apache/cassandra/cql/CreateColumnFamilyStatement.java
Date Wed, 07 Dec 2011 16:00:25 GMT
Author: slebresne
Date: Wed Dec  7 16:00:25 2011
New Revision: 1211486

URL: http://svn.apache.org/viewvc?rev=1211486&view=rev
Log:
Detect misuses of CounterColumnType
patch by slebresne; reviewed by jbellis for CASSANDRA-3422

Modified:
    cassandra/branches/cassandra-0.8/CHANGES.txt
    cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/config/CFMetaData.java
    cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/cql/CreateColumnFamilyStatement.java

Modified: cassandra/branches/cassandra-0.8/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/CHANGES.txt?rev=1211486&r1=1211485&r2=1211486&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.8/CHANGES.txt Wed Dec  7 16:00:25 2011
@@ -2,6 +2,7 @@
  * use cannonical host for local node in nodetool info (CASSANDRA-3556)
  * remove nonlocal DC write optimization since it only worked with
    CL.ONE or CL.LOCAL_QUORUM (CASSANDRA-3577)
+ * detect misuses of CounterColumnType (CASSANDRA-3422)
 
 
 0.8.8

Modified: cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/config/CFMetaData.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/config/CFMetaData.java?rev=1211486&r1=1211485&r2=1211486&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/config/CFMetaData.java
(original)
+++ cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/config/CFMetaData.java
Wed Dec  7 16:00:25 2011
@@ -677,7 +677,8 @@ public final class CFMetaData
                       .replicateOnWrite(cf_def.replicate_on_write)
                       .defaultValidator(TypeParser.parse(cf_def.default_validation_class))
                       .keyValidator(TypeParser.parse(cf_def.key_validation_class))
-                      .columnMetadata(ColumnDefinition.fromColumnDef(cf_def.column_metadata));
+                      .columnMetadata(ColumnDefinition.fromColumnDef(cf_def.column_metadata))
+                      .validate();
     }
 
     // merges some final fields from this CFM with modifiable fields from CfDef into a new
CFMetaData.
@@ -990,6 +991,32 @@ public final class CFMetaData
         return (cfName + "_" + comparator.getString(columnName) + "_idx").replaceAll("\\W",
"");
     }
 
+    public CFMetaData validate() throws ConfigurationException
+    {
+        if (comparator instanceof CounterColumnType)
+            throw new ConfigurationException("CounterColumnType is not a valid comparator");
+        if (subcolumnComparator instanceof CounterColumnType)
+            throw new ConfigurationException("CounterColumnType is not a valid sub-column
comparator");
+        if (keyValidator instanceof CounterColumnType)
+            throw new ConfigurationException("CounterColumnType is not a valid key validator");
+
+        // Mixing counter with non counter columns is not supported (#2614)
+        if (defaultValidator instanceof CounterColumnType)
+        {
+            for (ColumnDefinition def : column_metadata.values())
+                if (!(def.getValidator() instanceof CounterColumnType))
+                    throw new ConfigurationException("Cannot add a non counter column ("
+ comparator.getString(def.name) + ") in a counter column family");
+        }
+        else
+        {
+            for (ColumnDefinition def : column_metadata.values())
+                if (def.getValidator() instanceof CounterColumnType)
+                    throw new ConfigurationException("Cannot add a counter column (" + comparator.getString(def.name)
+ ") in a non counter column family");
+        }
+
+        return this;
+    }
+
     @Override
     public String toString()
     {

Modified: cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/cql/CreateColumnFamilyStatement.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/cql/CreateColumnFamilyStatement.java?rev=1211486&r1=1211485&r2=1211486&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/cql/CreateColumnFamilyStatement.java
(original)
+++ cassandra/branches/cassandra-0.8/src/java/org/apache/cassandra/cql/CreateColumnFamilyStatement.java
Wed Dec  7 16:00:25 2011
@@ -313,7 +313,8 @@ public class CreateColumnFamilyStatement
                    .columnMetadata(getColumns(comparator))
                    .keyValidator(TypeParser.parse(comparators.get(getKeyType())))
                    .rowCacheProvider(FBUtilities.newCacheProvider(getPropertyString(KW_ROW_CACHE_PROVIDER,
CFMetaData.DEFAULT_ROW_CACHE_PROVIDER)))
-                   .keyAlias(keyAlias);
+                   .keyAlias(keyAlias)
+                   .validate();
         }
         catch (ConfigurationException e)
         {



Mime
View raw message