cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject [36/50] [abbrv] git commit: Detect misuses of CounterColumnType patch by slebresne; reviewed by jbellis for CASSANDRA-3422
Date Thu, 05 Jan 2012 20:00:30 GMT
Detect misuses of CounterColumnType
patch by slebresne; reviewed by jbellis for CASSANDRA-3422


git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.8@1211486 13f79535-47bb-0310-9956-ffa450edef68


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

Branch: refs/heads/cassandra-1.0
Commit: 1f996108310009e6c384ed4eae0de80dc47747c4
Parents: 2ffe87e
Author: Sylvain Lebresne <slebresne@apache.org>
Authored: Wed Dec 7 16:00:25 2011 +0000
Committer: Sylvain Lebresne <slebresne@apache.org>
Committed: Wed Dec 7 16:00:25 2011 +0000

----------------------------------------------------------------------
 CHANGES.txt                                        |    1 +
 .../org/apache/cassandra/config/CFMetaData.java    |   29 ++++++++++++++-
 .../cassandra/cql/CreateColumnFamilyStatement.java |    3 +-
 3 files changed, 31 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cassandra/blob/1f996108/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index c93a6de..82311a8 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -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

http://git-wip-us.apache.org/repos/asf/cassandra/blob/1f996108/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 d10e2fd..35bbb8d 100644
--- a/src/java/org/apache/cassandra/config/CFMetaData.java
+++ b/src/java/org/apache/cassandra/config/CFMetaData.java
@@ -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()
     {

http://git-wip-us.apache.org/repos/asf/cassandra/blob/1f996108/src/java/org/apache/cassandra/cql/CreateColumnFamilyStatement.java
----------------------------------------------------------------------
diff --git a/src/java/org/apache/cassandra/cql/CreateColumnFamilyStatement.java b/src/java/org/apache/cassandra/cql/CreateColumnFamilyStatement.java
index ac4c6ec..2e451a1 100644
--- a/src/java/org/apache/cassandra/cql/CreateColumnFamilyStatement.java
+++ b/src/java/org/apache/cassandra/cql/CreateColumnFamilyStatement.java
@@ -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