cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r1041932 - in /cassandra/branches/cassandra-0.7: CHANGES.txt src/java/org/apache/cassandra/config/ColumnDefinition.java src/java/org/apache/cassandra/db/ColumnFamilyType.java src/java/org/apache/cassandra/thrift/ThriftValidation.java
Date Fri, 03 Dec 2010 17:52:46 GMT
Author: jbellis
Date: Fri Dec  3 17:52:46 2010
New Revision: 1041932

URL: http://svn.apache.org/viewvc?rev=1041932&view=rev
Log:
improved validation of column_metadata
patch by jbellis; reviewed by gdusbabek for CASSANDRA-1813

Modified:
    cassandra/branches/cassandra-0.7/CHANGES.txt
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/config/ColumnDefinition.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnFamilyType.java
    cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/thrift/ThriftValidation.java

Modified: cassandra/branches/cassandra-0.7/CHANGES.txt
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/CHANGES.txt?rev=1041932&r1=1041931&r2=1041932&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/CHANGES.txt (original)
+++ cassandra/branches/cassandra-0.7/CHANGES.txt Fri Dec  3 17:52:46 2010
@@ -26,6 +26,7 @@ dev
  * fix consistencylevel calculations for NetworkTopologyStrategy
    (CASSANDRA-1804)
  * cli support index type enum names (CASSANDRA-1810)
+ * improved validation of column_metadata (CASSANDRA-1813)
 
 
 0.7.0-rc1

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/config/ColumnDefinition.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/config/ColumnDefinition.java?rev=1041932&r1=1041931&r2=1041932&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/config/ColumnDefinition.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/config/ColumnDefinition.java
Fri Dec  3 17:52:46 2010
@@ -103,7 +103,6 @@ public class ColumnDefinition {
 
     public static ColumnDefinition fromColumnDef(ColumnDef thriftColumnDef) throws ConfigurationException
     {
-        validateIndexType(thriftColumnDef);
         return new ColumnDefinition(thriftColumnDef.name, thriftColumnDef.validation_class,
thriftColumnDef.index_type, thriftColumnDef.index_name);
     }
     
@@ -123,10 +122,7 @@ public class ColumnDefinition {
 
         Map<ByteBuffer, ColumnDefinition> cds = new TreeMap<ByteBuffer, ColumnDefinition>();
         for (ColumnDef thriftColumnDef : thriftDefs)
-        {
-            validateIndexType(thriftColumnDef);
             cds.put(thriftColumnDef.name, fromColumnDef(thriftColumnDef));
-        }
 
         return Collections.unmodifiableMap(cds);
     }
@@ -146,12 +142,6 @@ public class ColumnDefinition {
         return Collections.unmodifiableMap(cds);
     }
 
-    public static void validateIndexType(org.apache.cassandra.thrift.ColumnDef thriftColumnDef)
throws ConfigurationException
-    {
-        if ((thriftColumnDef.index_name != null) && (thriftColumnDef.index_type ==
null))
-            throw new ConfigurationException("index_name cannot be set if index_type is not
also set");
-    }
-
     public static void validateIndexType(org.apache.cassandra.avro.ColumnDef avroColumnDef)
throws ConfigurationException
     {
         if ((avroColumnDef.index_name != null) && (avroColumnDef.index_type == null))

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnFamilyType.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnFamilyType.java?rev=1041932&r1=1041931&r2=1041932&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnFamilyType.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/db/ColumnFamilyType.java
Fri Dec  3 17:52:46 2010
@@ -25,11 +25,12 @@ public enum ColumnFamilyType
     Standard,
     Super;
 
-    public final static ColumnFamilyType create(String name)
+    public static ColumnFamilyType create(String name)
     {
         try
         {
-            return name == null ? null : ColumnFamilyType.valueOf(name);
+            // TODO thrift optional parameter in CfDef is leaking down here which it shouldn't
+            return name == null ? ColumnFamilyType.Standard : ColumnFamilyType.valueOf(name);
         }
         catch (IllegalArgumentException e)
         {

Modified: cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/thrift/ThriftValidation.java
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/thrift/ThriftValidation.java?rev=1041932&r1=1041931&r2=1041932&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/thrift/ThriftValidation.java
(original)
+++ cassandra/branches/cassandra-0.7/src/java/org/apache/cassandra/thrift/ThriftValidation.java
Fri Dec  3 17:52:46 2010
@@ -383,14 +383,20 @@ public class ThriftValidation
     {
         try
         {
+            ColumnFamilyType cfType = ColumnFamilyType.create(cf_def.column_type);
+            if (cfType == null)
+                throw new InvalidRequestException("invalid column type " + cf_def.column_type);
+
             DatabaseDescriptor.getComparator(cf_def.comparator_type);
             DatabaseDescriptor.getComparator(cf_def.subcomparator_type);
             DatabaseDescriptor.getComparator(cf_def.default_validation_class);
+            if (cfType != ColumnFamilyType.Super && cf_def.subcomparator_type !=
null)
+                throw new InvalidRequestException("subcomparator_type is invalid for standard
columns");
 
             if (cf_def.column_metadata == null)
                 return;
 
-            AbstractType comparator = cf_def.subcomparator_type == null
+            AbstractType comparator = cfType == ColumnFamilyType.Standard
                                     ? DatabaseDescriptor.getComparator(cf_def.comparator_type)
                                     : DatabaseDescriptor.getComparator(cf_def.subcomparator_type);
             for (ColumnDef c : cf_def.column_metadata)
@@ -406,6 +412,12 @@ public class ThriftValidation
                     throw new InvalidRequestException(String.format("Column name %s is not
valid for comparator %s",
                                                                     FBUtilities.bytesToHex(c.name),
cf_def.comparator_type));
                 }
+
+                if ((c.index_name != null) && (c.index_type == null))
+                    throw new ConfigurationException("index_name cannot be set without index_type");
+
+                if (cfType == ColumnFamilyType.Super && c.index_type != null)
+                    throw new InvalidRequestException("Secondary indexes are not supported
on supercolumns");
             }
         }
         catch (ConfigurationException e)



Mime
View raw message