cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eev...@apache.org
Subject svn commit: r943189 - in /cassandra/trunk: interface/cassandra.avpr src/java/org/apache/cassandra/avro/AvroValidation.java src/java/org/apache/cassandra/avro/CassandraServer.java
Date Tue, 11 May 2010 17:20:44 GMT
Author: eevans
Date: Tue May 11 17:20:44 2010
New Revision: 943189

URL: http://svn.apache.org/viewvc?rev=943189&view=rev
Log:
bring insert() up to date w/ thrift in trunk

 * no more keyspace arg
 * key is byte[]
 * ColumnParent+Column instead of ColumnPath+value

Patch by eevans

Modified:
    cassandra/trunk/interface/cassandra.avpr
    cassandra/trunk/src/java/org/apache/cassandra/avro/AvroValidation.java
    cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java

Modified: cassandra/trunk/interface/cassandra.avpr
URL: http://svn.apache.org/viewvc/cassandra/trunk/interface/cassandra.avpr?rev=943189&r1=943188&r2=943189&view=diff
==============================================================================
--- cassandra/trunk/interface/cassandra.avpr (original)
+++ cassandra/trunk/interface/cassandra.avpr Tue May 11 17:20:44 2010
@@ -26,7 +26,7 @@
             {"name": "name", "type": "bytes"},
             {"name": "value", "type": "bytes"},
             {"name": "timestamp", "type": "long"},
-            {"name": "ttl", "type": "int"}
+            {"name": "ttl", "type": ["int", "null"]}
         ]
       },
       {"name": "SuperColumn", "type": "record",
@@ -111,11 +111,9 @@
     },
     "insert": {
         "request": [
-            {"name": "keyspace", "type": "string"},
-            {"name": "key", "type": "string"},
-            {"name": "column_path", "type": "ColumnPath"},
-            {"name": "value", "type": "bytes"},
-            {"name": "timestamp", "type": "long"},
+            {"name": "key", "type": "bytes"},
+            {"name": "column_parent", "type": "ColumnParent"},
+            {"name": "column", "type": "Column"},
             {"name": "consistency_level", "type": "ConsistencyLevel"}
         ],
         "response": "null",

Modified: cassandra/trunk/src/java/org/apache/cassandra/avro/AvroValidation.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/avro/AvroValidation.java?rev=943189&r1=943188&r2=943189&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/avro/AvroValidation.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/avro/AvroValidation.java Tue May 11 17:20:44
2010
@@ -110,6 +110,19 @@ public class AvroValidation {
             validateColumns(keyspace, column_family, null, Arrays.asList(cp.super_column));
     }
     
+    static void validateColumnParent(String keyspace, ColumnParent parent) throws InvalidRequestException
+    {
+        validateKeyspace(keyspace);
+        String cfName = parent.column_family.toString();
+        String cfType = validateColumnFamily(keyspace, cfName);
+        
+        if (cfType.equals("Standard"))
+            if (parent.super_column != null)
+                throw newInvalidRequestException("super column specified for standard column
family");
+        if (parent.super_column != null)
+            validateColumns(keyspace, cfName, null, Arrays.asList(parent.super_column));
+    }
+    
     // FIXME: could use method in ThriftValidation
     static void validateColumns(String keyspace, String cfName, byte[] superColumnName, Iterable<ByteBuffer>
columnNames)
     throws InvalidRequestException
@@ -144,6 +157,22 @@ public class AvroValidation {
             }
         }
     }
+    
+    static void validateColumns(String keyspace, ColumnParent parent, Iterable<ByteBuffer>
columnNames)
+    throws InvalidRequestException
+    {
+        validateColumns(keyspace,
+                        parent.column_family.toString(),
+                        parent.super_column == null ? null : parent.super_column.array(),
+                        columnNames);
+    }
+    
+    static void validateColumn(String keyspace, ColumnParent parent, Column column)
+    throws InvalidRequestException
+    {
+        validateTtl(column);
+        validateColumns(keyspace, parent, Arrays.asList(column.name));
+    }
 
     static void validateColumnOrSuperColumn(String keyspace, String cfName, ColumnOrSuperColumn
cosc)
     throws InvalidRequestException
@@ -232,4 +261,10 @@ public class AvroValidation {
             throw newInvalidRequestException("Mutation must have one ColumnOrSuperColumn,
or one Deletion");
         }
     }
+    
+    static void validateTtl(Column column) throws InvalidRequestException
+    {
+        if (column.ttl != null && column.ttl < 0)
+            throw newInvalidRequestException("ttl must be a positive value");
+    }
 }

Modified: cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java
URL: http://svn.apache.org/viewvc/cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java?rev=943189&r1=943188&r2=943189&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java Tue May 11 17:20:44
2010
@@ -233,26 +233,26 @@ public class CassandraServer implements 
             return avronateColumns(cf.getSortedColumns(), reverseOrder);
     }
 
-    public Void insert(Utf8 keyspace, Utf8 key, ColumnPath cp, ByteBuffer value, long timestamp,
ConsistencyLevel consistencyLevel)
+    @Override
+    public Void insert(ByteBuffer key, ColumnParent parent, Column column, ConsistencyLevel
consistencyLevel)
     throws AvroRemoteException, InvalidRequestException, UnavailableException, TimedOutException
     {
         if (logger.isDebugEnabled())
             logger.debug("insert");
 
-        // FIXME: This is repetitive.
-        byte[] column, super_column;
-        column = cp.column == null ? null : cp.column.array();
-        super_column = cp.super_column == null ? null : cp.super_column.array();
-        String column_family = cp.column_family.toString();
-        String keyspace_string = keyspace.toString();
-
-        AvroValidation.validateKey(keyspace_string);
-        AvroValidation.validateColumnPath(keyspace_string, cp);
+        AvroValidation.validateKey(key.array());
+        AvroValidation.validateColumnParent(curKeyspace.get(), parent);
+        AvroValidation.validateColumn(curKeyspace.get(), parent, column);
 
-        RowMutation rm = new RowMutation(keyspace_string, key.getBytes());
+        RowMutation rm = new RowMutation(curKeyspace.get(), key.array());
         try
         {
-            rm.add(new QueryPath(column_family, super_column, column), value.array(), timestamp);
+            rm.add(new QueryPath(parent.column_family.toString(),
+                   parent.super_column == null ? null : parent.super_column.array(),
+                   column.name.array()),
+                   column.value.array(),
+                   column.timestamp,
+                   column.ttl);
         }
         catch (MarshalException e)
         {



Mime
View raw message