cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r904675 - in /incubator/cassandra/branches/cassandra-0.5: src/java/org/apache/cassandra/io/ src/java/org/apache/cassandra/service/ test/system/ test/unit/org/apache/cassandra/db/
Date Fri, 29 Jan 2010 23:37:40 GMT
Author: jbellis
Date: Fri Jan 29 23:37:40 2010
New Revision: 904675

URL: http://svn.apache.org/viewvc?rev=904675&view=rev
Log:
revert last

Modified:
    incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/io/Streaming.java
    incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/service/CassandraServer.java
    incubator/cassandra/branches/cassandra-0.5/test/system/test_server.py
    incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/db/RemoveSuperColumnTest.java

Modified: incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/io/Streaming.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/io/Streaming.java?rev=904675&r1=904674&r2=904675&view=diff
==============================================================================
--- incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/io/Streaming.java
(original)
+++ incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/io/Streaming.java
Fri Jan 29 23:37:40 2010
@@ -173,12 +173,11 @@
                 StreamInitiateMessage biMsg = StreamInitiateMessage.serializer().deserialize(bufIn);
                 StreamContextManager.StreamContext[] streamContexts = biMsg.getStreamContext();
 
-                if (streamContexts.length == 0)
+                if (streamContexts.length == 0 && StorageService.instance().isBootstrapMode())
                 {
                     if (logger.isDebugEnabled())
                         logger.debug("no data needed from " + message.getFrom());
-                    if (StorageService.instance.isBootstrapMode())
-                        StorageService.instance.removeBootstrapSource(message.getFrom(),
new String(message.getHeader(Streaming.TABLE_NAME)));
+                    StorageService.instance().removeBootstrapSource(message.getFrom(), new
String(message.getHeader(Streaming.TABLE_NAME)));
                     return;
                 }
 

Modified: incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/service/CassandraServer.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/service/CassandraServer.java?rev=904675&r1=904674&r2=904675&view=diff
==============================================================================
--- incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/service/CassandraServer.java
(original)
+++ incubator/cassandra/branches/cassandra-0.5/src/java/org/apache/cassandra/service/CassandraServer.java
Fri Jan 29 23:37:40 2010
@@ -258,6 +258,41 @@
         return column;
     }
 
+    /** no values will be mapped to keys with no data */
+    private Map<String, Collection<IColumn>> multigetColumns(List<ReadCommand>
commands, int consistency_level)
+    throws InvalidRequestException, UnavailableException, TimedOutException
+    {
+        Map<String, ColumnFamily> cfamilies = readColumnFamily(commands, consistency_level);
+        Map<String, Collection<IColumn>> columnFamiliesMap = new HashMap<String,
Collection<IColumn>>();
+
+        for (ReadCommand command: commands)
+        {
+            ColumnFamily cfamily = cfamilies.get(command.key);
+            if (cfamily == null)
+                continue;
+
+            Collection<IColumn> columns = null;
+            if (command.queryPath.superColumnName != null)
+            {
+                IColumn column = cfamily.getColumn(command.queryPath.superColumnName);
+                if (column != null)
+                {
+                    columns = column.getSubColumns();
+                }
+            }
+            else
+            {
+                columns = cfamily.getSortedColumns();
+            }
+
+            if (columns != null && columns.size() != 0)
+            {
+                columnFamiliesMap.put(command.key, columns);
+            }
+        }
+        return columnFamiliesMap;
+    }
+
     /** always returns a ColumnOrSuperColumn for each key, even if there is no data for it
*/
     public Map<String, ColumnOrSuperColumn> multiget(String table, List<String>
keys, ColumnPath column_path, int consistency_level)
     throws InvalidRequestException, UnavailableException, TimedOutException
@@ -282,20 +317,36 @@
         }
 
         Map<String, ColumnOrSuperColumn> columnFamiliesMap = new HashMap<String,
ColumnOrSuperColumn>();
-        Map<String, ColumnFamily> cfamilies = readColumnFamily(commands, consistency_level);
+        Map<String, Collection<IColumn>> columnsMap = multigetColumns(commands,
consistency_level);
 
         for (ReadCommand command: commands)
         {
-            ColumnFamily cf = cfamilies.get(command.key);
-            if (cf == null)
+            ColumnOrSuperColumn columnorsupercolumn;
+
+            Collection<IColumn> columns = columnsMap.get(command.key);
+            if (columns == null)
             {
-                columnFamiliesMap.put(command.key, new ColumnOrSuperColumn());
+               columnorsupercolumn = new ColumnOrSuperColumn();
             }
             else
             {
-                List<ColumnOrSuperColumn> tcolumns = thriftifyColumnFamily(cf, command.queryPath.superColumnName
!= null, false);
-                columnFamiliesMap.put(command.key, tcolumns.size() > 0 ? tcolumns.iterator().next()
: new ColumnOrSuperColumn());
+                assert columns.size() == 1;
+                IColumn column = columns.iterator().next();
+
+
+                if (column.isMarkedForDelete())
+                {
+                    columnorsupercolumn = new ColumnOrSuperColumn();
+                }
+                else
+                {
+                    columnorsupercolumn = column instanceof org.apache.cassandra.db.Column
+                                          ? new ColumnOrSuperColumn(new Column(column.name(),
column.value(), column.timestamp()), null)
+                                          : new ColumnOrSuperColumn(null, new SuperColumn(column.name(),
thriftifySubColumns(column.getSubColumns())));
+                }
+
             }
+            columnFamiliesMap.put(command.key, columnorsupercolumn);
         }
 
         return columnFamiliesMap;
@@ -306,10 +357,44 @@
     {
         if (logger.isDebugEnabled())
             logger.debug("get_count");
+        return multigetCountInternal(table, Arrays.asList(key), column_parent, consistency_level).get(key);
+    }
+
+    private Map<String, Integer> multigetCountInternal(String table, List<String>
keys, ColumnParent column_parent, int consistency_level)
+    throws InvalidRequestException, UnavailableException, TimedOutException
+    {
+        // validateColumnParent assumes we require simple columns; g_c_c is the only
+        // one of the columnParent-taking apis that can also work at the SC level.
+        // so we roll a one-off validator here.
+        String cfType = ThriftValidation.validateColumnFamily(table, column_parent.column_family);
+        if (cfType.equals("Standard") && column_parent.super_column != null)
+        {
+            throw new InvalidRequestException("columnfamily alone is required for standard
CF " + column_parent.column_family);
+        }
+
+        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));
+        }
+
+        Map<String, Integer> columnFamiliesMap = new HashMap<String, Integer>();
+        Map<String, Collection<IColumn>> columnsMap = multigetColumns(commands,
consistency_level);
 
-        SliceRange range = new SliceRange(ArrayUtils.EMPTY_BYTE_ARRAY, ArrayUtils.EMPTY_BYTE_ARRAY,
false, Integer.MAX_VALUE);
-        SlicePredicate predicate = new SlicePredicate().setSlice_range(range);
-        return get_slice(table, key, column_parent, predicate, consistency_level).size();
+        for (ReadCommand command: commands)
+        {
+            Collection<IColumn> columns = columnsMap.get(command.key);
+            if(columns == null)
+            {
+               columnFamiliesMap.put(command.key, 0);
+            }
+            else
+            {
+               columnFamiliesMap.put(command.key, columns.size());
+            }
+        }
+        return columnFamiliesMap;
     }
 
     public void insert(String table, String key, ColumnPath column_path, byte[] value, long
timestamp, int consistency_level)

Modified: incubator/cassandra/branches/cassandra-0.5/test/system/test_server.py
URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.5/test/system/test_server.py?rev=904675&r1=904674&r2=904675&view=diff
==============================================================================
--- incubator/cassandra/branches/cassandra-0.5/test/system/test_server.py (original)
+++ incubator/cassandra/branches/cassandra-0.5/test/system/test_server.py Fri Jan 29 23:37:40
2010
@@ -472,18 +472,6 @@
         assert columns == [Column(_i64(5), 'value5', 6)], columns
 
 
-    def test_super_cf_resurrect_subcolumn(self):
-        key = 'vijay'
-        client.insert('Keyspace1', key, ColumnPath('Super1', 'sc1', _i64(4)), 'value4', 0,
ConsistencyLevel.ONE)
-
-        client.remove('Keyspace1', key, ColumnPath('Super1', 'sc1'), 1, ConsistencyLevel.ONE)
-
-        client.insert('Keyspace1', key, ColumnPath('Super1', 'sc1', _i64(4)), 'value4', 2,
ConsistencyLevel.ONE)
-
-        result = client.get('Keyspace1', key, ColumnPath('Super1', 'sc1'), ConsistencyLevel.ONE)
-        assert result.super_column.columns is not None, result.super_column
-
-
     def test_empty_range(self):
         assert client.get_key_range('Keyspace1', 'Standard1', '', '', 1000, ConsistencyLevel.ONE)
== []
         _insert_simple()
@@ -666,14 +654,3 @@
         ks1 = client.describe_keyspace("Keyspace1")
         assert set(ks1.keys()) == set(['Super1', 'Standard1', 'Standard2', 'StandardLong1',
'StandardLong2', 'Super3', 'Super2', 'Super4'])
         sysks = client.describe_keyspace("system")
-
-    def test_vijay(self):
-        key = 'vijay'
-        client.insert('Keyspace1', key, ColumnPath('Super1', 'sc1', _i64(4)), 'value4', 0,
ConsistencyLevel.ONE)
-
-        client.remove('Keyspace1', 'key1', ColumnPath('Super1', 'sc1'), 1, ConsistencyLevel.ONE)
-
-        client.insert('Keyspace1', key, ColumnPath('Super1', 'sc1', _i64(4)), 'value4', 0,
ConsistencyLevel.ONE)
-
-        result = client.get('Keyspace1', key, ColumnPath('Super1', 'sc1'), ConsistencyLevel.ONE)
-        assert result.super_column.columns != None

Modified: incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/db/RemoveSuperColumnTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/db/RemoveSuperColumnTest.java?rev=904675&r1=904674&r2=904675&view=diff
==============================================================================
--- incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/db/RemoveSuperColumnTest.java
(original)
+++ incubator/cassandra/branches/cassandra-0.5/test/unit/org/apache/cassandra/db/RemoveSuperColumnTest.java
Fri Jan 29 23:37:40 2010
@@ -159,33 +159,4 @@
         assert subColumns.iterator().next().timestamp() == 2;
     }
 
-    @Test
-    public void testRemoveSuperColumnResurrection() throws IOException, ExecutionException,
InterruptedException
-    {
-        ColumnFamilyStore store = Table.open("Keyspace1").getColumnFamilyStore("Super2");
-        RowMutation rm;
-        String key = "keyC";
-
-        // add data
-        rm = new RowMutation("Keyspace1", key);
-        addMutation(rm, "Super2", "SC1", 1, "val1", 0);
-        rm.apply();
-
-        // remove
-        rm = new RowMutation("Keyspace1", key);
-        rm.delete(new QueryPath("Super2", "SC1".getBytes()), 1);
-        rm.apply();
-        assertNull(store.getColumnFamily(new NamesQueryFilter(key, new QueryPath("Super2"),
"SC1".getBytes()), Integer.MAX_VALUE));
-
-        // resurrect
-        rm = new RowMutation("Keyspace1", key);
-        addMutation(rm, "Super2", "SC1", 1, "val2", 2);
-        rm.apply();
-
-        // validate
-        ColumnFamily resolved = store.getColumnFamily(new NamesQueryFilter(key, new QueryPath("Super2"),
"SC1".getBytes()), Integer.MAX_VALUE);
-        Collection<IColumn> subColumns = resolved.getSortedColumns().iterator().next().getSubColumns();
-        assert subColumns.size() == 1;
-        assert subColumns.iterator().next().timestamp() == 2;
-    }
 }



Mime
View raw message