cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r824815 - in /incubator/cassandra/branches/cassandra-0.4: src/java/org/apache/cassandra/service/CassandraServer.java test/system/test_server.py
Date Tue, 13 Oct 2009 15:47:43 GMT
Author: jbellis
Date: Tue Oct 13 15:47:43 2009
New Revision: 824815

URL: http://svn.apache.org/viewvc?rev=824815&view=rev
Log:
Add missing validateKey calls for inserts, and move get key validation where it's more visible.
Also remove inconsistent trim-ing of keys.  patch by jbellis; tested by Eric Lubow for CASSANDRA-486

Modified:
    incubator/cassandra/branches/cassandra-0.4/src/java/org/apache/cassandra/service/CassandraServer.java
    incubator/cassandra/branches/cassandra-0.4/test/system/test_server.py

Modified: incubator/cassandra/branches/cassandra-0.4/src/java/org/apache/cassandra/service/CassandraServer.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.4/src/java/org/apache/cassandra/service/CassandraServer.java?rev=824815&r1=824814&r2=824815&view=diff
==============================================================================
--- incubator/cassandra/branches/cassandra-0.4/src/java/org/apache/cassandra/service/CassandraServer.java
(original)
+++ incubator/cassandra/branches/cassandra-0.4/src/java/org/apache/cassandra/service/CassandraServer.java
Tue Oct 13 15:47:43 2009
@@ -80,11 +80,6 @@
 
         Map<String, ColumnFamily> columnFamilyKeyMap = new HashMap<String,ColumnFamily>();
 
-        for (ReadCommand command: commands)
-        {
-            ThriftValidation.validateKey(command.key);
-        }
-
         if (consistency_level == ConsistencyLevel.ZERO)
         {
             throw new InvalidRequestException("Consistency level zero may not be applied
to read operations");
@@ -238,13 +233,19 @@
         if (predicate.column_names != null)
         {
             for (String key: keys)
+            {
+                ThriftValidation.validateKey(key);
                 commands.add(new SliceByNamesReadCommand(keyspace, key, column_parent, predicate.column_names));
+            }
             ThriftValidation.validateColumns(keyspace, column_parent, predicate.column_names);
         }
         else
         {
             for (String key: keys)
+            {
+                ThriftValidation.validateKey(key);
                 commands.add(new SliceFromReadCommand(keyspace, key, column_parent, range.start,
range.finish, range.reversed, range.count));
+            }
             ThriftValidation.validateRange(keyspace, column_parent, range);
         }
 
@@ -318,6 +319,7 @@
         List<ReadCommand> commands = new ArrayList<ReadCommand>();
         for (String key: keys)
         {
+            ThriftValidation.validateKey(key);
             commands.add(new SliceByNamesReadCommand(table, key, path, nameAsList));
         }
 
@@ -380,6 +382,7 @@
         List<ReadCommand> commands = new ArrayList<ReadCommand>();
         for (String key: keys)
         {
+            ThriftValidation.validateKey(key);
             commands.add(new SliceFromReadCommand(table, key, column_parent, ArrayUtils.EMPTY_BYTE_ARRAY,
ArrayUtils.EMPTY_BYTE_ARRAY, true, Integer.MAX_VALUE));
         }
 
@@ -409,7 +412,7 @@
         ThriftValidation.validateKey(key);
         ThriftValidation.validateColumnPath(table, column_path);
 
-        RowMutation rm = new RowMutation(table, key.trim());
+        RowMutation rm = new RowMutation(table, key);
         try
         {
             rm.add(new QueryPath(column_path), value, timestamp);
@@ -426,6 +429,7 @@
     {
         if (logger.isDebugEnabled())
             logger.debug("batch_insert");
+        ThriftValidation.validateKey(key);
 
         for (String cfName : cfmap.keySet())
         {
@@ -453,9 +457,10 @@
     {
         if (logger.isDebugEnabled())
             logger.debug("remove");
+        ThriftValidation.validateKey(key);
         ThriftValidation.validateColumnPathOrParent(table, column_path);
         
-        RowMutation rm = new RowMutation(table, key.trim());
+        RowMutation rm = new RowMutation(table, key);
         rm.delete(new QueryPath(column_path), timestamp);
 
         doInsert(consistency_level, rm);

Modified: incubator/cassandra/branches/cassandra-0.4/test/system/test_server.py
URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.4/test/system/test_server.py?rev=824815&r1=824814&r2=824815&view=diff
==============================================================================
--- incubator/cassandra/branches/cassandra-0.4/test/system/test_server.py (original)
+++ incubator/cassandra/branches/cassandra-0.4/test/system/test_server.py Tue Oct 13 15:47:43
2009
@@ -289,6 +289,11 @@
     def test_bad_calls(self):
         # supercolumn in a non-super CF
         _expect_exception(lambda: client.insert('Keyspace1', 'key1', ColumnPath('Standard1',
'x', 'y'), 'value', 0, ConsistencyLevel.ONE), InvalidRequestException)
+        # empty key
+        _expect_exception(lambda: client.get('Keyspace1', '', ColumnPath('Standard1', column='c1'),
ConsistencyLevel.ONE), InvalidRequestException)
+        cfmap = {'Super1': [ColumnOrSuperColumn(super_column=c) for c in _SUPER_COLUMNS],
+                 'Super2': [ColumnOrSuperColumn(super_column=c) for c in _SUPER_COLUMNS]}
+        _expect_exception(lambda: client.batch_insert('Keyspace1', '', cfmap, ConsistencyLevel.ONE),
InvalidRequestException)
         # get doesn't specify column name
         _expect_exception(lambda: client.get('Keyspace1', 'key1', ColumnPath('Standard1'),
ConsistencyLevel.ONE), InvalidRequestException)
         # supercolumn in a non-super CF



Mime
View raw message