cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eev...@apache.org
Subject svn commit: r955050 - in /cassandra/trunk: interface/cassandra.avpr interface/cassandra.genavro src/java/org/apache/cassandra/avro/AvroValidation.java src/java/org/apache/cassandra/avro/CassandraServer.java test/system/test_avro_server.py
Date Tue, 15 Jun 2010 20:57:23 GMT
Author: eevans
Date: Tue Jun 15 20:57:22 2010
New Revision: 955050

URL: http://svn.apache.org/viewvc?rev=955050&view=rev
Log:
added remove() implementation to avro-based server

Patch by eevans

Modified:
    cassandra/trunk/interface/cassandra.avpr
    cassandra/trunk/interface/cassandra.genavro
    cassandra/trunk/src/java/org/apache/cassandra/avro/AvroValidation.java
    cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java
    cassandra/trunk/test/system/test_avro_server.py

Modified: cassandra/trunk/interface/cassandra.avpr
URL: http://svn.apache.org/viewvc/cassandra/trunk/interface/cassandra.avpr?rev=955050&r1=955049&r2=955050&view=diff
==============================================================================
--- cassandra/trunk/interface/cassandra.avpr (original)
+++ cassandra/trunk/interface/cassandra.avpr Tue Jun 15 20:57:22 2010
@@ -148,6 +148,17 @@
         "errors": ["InvalidRequestException", "UnavailableException",
             "TimedOutException"]
     },
+    "remove": {
+        "request": [
+            {"name": "key", "type": "bytes"},
+            {"name": "column_path", "type": "ColumnPath"},
+            {"name": "clock", "type": "Clock"},
+            {"name": "consistency_level", "type": "ConsistencyLevel"}
+        ],
+        "response": "null",
+        "errors": ["InvalidRequestException", "UnavailableException",
+            "TimedOutException"]
+    },
     "batch_mutate": {
         "request": [
             {"name": "keyspace", "type": "string"},

Modified: cassandra/trunk/interface/cassandra.genavro
URL: http://svn.apache.org/viewvc/cassandra/trunk/interface/cassandra.genavro?rev=955050&r1=955049&r2=955050&view=diff
==============================================================================
--- cassandra/trunk/interface/cassandra.genavro (original)
+++ cassandra/trunk/interface/cassandra.genavro Tue Jun 15 20:57:22 2010
@@ -115,6 +115,12 @@ protocol Cassandra {
                 Column column,
                 ConsistencyLevel consistency_level)
     throws InvalidRequestException, UnavailableException, TimedOutException;
+    
+    void remove(bytes key,
+                ColumnPath column_path,
+                Clock clock,
+                ConsistencyLevel consistency_level)
+    throws InvalidRequestException, UnavailableException, TimedOutException;
 
     void batch_mutate(string keyspace,
                       map<map<array<Mutation>>> mutation_map,

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=955050&r1=955049&r2=955050&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/avro/AvroValidation.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/avro/AvroValidation.java Tue Jun 15 20:57:22
2010
@@ -28,8 +28,10 @@ import java.util.Comparator;
 import org.apache.avro.util.Utf8;
 import org.apache.cassandra.config.DatabaseDescriptor;
 import org.apache.cassandra.db.ColumnFamily;
+import org.apache.cassandra.db.IClock;
 import org.apache.cassandra.db.IColumn;
 import org.apache.cassandra.db.ColumnFamilyType;
+import org.apache.cassandra.db.TimestampClock;
 import org.apache.cassandra.db.marshal.AbstractType;
 import org.apache.cassandra.db.marshal.MarshalException;
 import org.apache.cassandra.utils.FBUtilities;
@@ -267,4 +269,12 @@ public class AvroValidation {
         if (column.ttl != null && column.ttl < 0)
             throw newInvalidRequestException("ttl must be a positive value");
     }
+    
+    static IClock validateClock(Clock clock) throws InvalidRequestException
+    {
+        if (clock.timestamp >= 0)
+            return new TimestampClock(clock.timestamp);
+        
+        throw newInvalidRequestException("Clock must have a timestamp set");
+    }
 }

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=955050&r1=955049&r2=955050&view=diff
==============================================================================
--- cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java (original)
+++ cassandra/trunk/src/java/org/apache/cassandra/avro/CassandraServer.java Tue Jun 15 20:57:22
2010
@@ -282,6 +282,26 @@ public class CassandraServer implements 
 
         return null;
     }
+    
+    @Override
+    public Void remove(ByteBuffer key, ColumnPath columnPath, Clock clock, ConsistencyLevel
consistencyLevel)
+    throws AvroRemoteException, InvalidRequestException, UnavailableException, TimedOutException
+    {
+        if (logger.isDebugEnabled())
+            logger.debug("remove");
+        
+        AvroValidation.validateKey(key.array());
+        AvroValidation.validateColumnPath(curKeyspace.get(), columnPath);
+        IClock dbClock = AvroValidation.validateClock(clock);
+        
+        RowMutation rm = new RowMutation(curKeyspace.get(), key.array());
+        byte[] superName = columnPath.super_column == null ? null : columnPath.super_column.array();
+        rm.delete(new QueryPath(columnPath.column_family.toString(), superName), dbClock);
+        
+        doInsert(consistencyLevel, rm);
+        
+        return null;
+    }
 
     private void doInsert(ConsistencyLevel consistency, RowMutation rm) throws UnavailableException,
TimedOutException
     {

Modified: cassandra/trunk/test/system/test_avro_server.py
URL: http://svn.apache.org/viewvc/cassandra/trunk/test/system/test_avro_server.py?rev=955050&r1=955049&r2=955050&view=diff
==============================================================================
--- cassandra/trunk/test/system/test_avro_server.py (original)
+++ cassandra/trunk/test/system/test_avro_server.py Tue Jun 15 20:57:22 2010
@@ -91,6 +91,40 @@ class TestRpcOperations(AvroTester):
         assert_cosc(cosc)
         assert_columns_match(cosc['column'], params['column'])
 
+    def test_remove_simple(self):
+        "removing a simple column"
+        self.client.request('set_keyspace', {'keyspace': 'Keyspace1'})
+
+        params = dict()
+        params['key'] = 'key1'
+        params['column_parent'] = {'column_family': 'Standard1'}
+        params['column'] = dict()
+        params['column']['name'] = 'c1'
+        params['column']['value'] = 'v1'
+        params['column']['clock'] = { 'timestamp' : 0 }
+        params['consistency_level'] = 'ONE'
+        self.client.request('insert', params)
+
+        read_params = dict()
+        read_params['key'] = params['key']
+        read_params['column_path'] = dict()
+        read_params['column_path']['column_family'] = 'Standard1'
+        read_params['column_path']['column'] = params['column']['name']
+        read_params['consistency_level'] = 'ONE'
+
+        cosc = self.client.request('get', read_params)
+
+        assert_cosc(cosc)
+
+        remove_params = read_params
+        remove_params['clock'] = {'timestamp': 1}
+
+        self.client.request('remove', remove_params)
+
+        try: cosc = self.client.request('get', read_params)
+        except AvroRemoteException, err: pass
+        else: assert False, "Expected exception, returned %s instead" % cosc
+
     def test_describe_keyspaces(self):
         "retrieving a list of all keyspaces"
         keyspaces = self.client.request('describe_keyspaces', {})



Mime
View raw message