cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jbel...@apache.org
Subject svn commit: r788511 - in /incubator/cassandra/trunk: src/java/org/apache/cassandra/db/SuperColumn.java src/java/org/apache/cassandra/io/SequenceFile.java test/unit/org/apache/cassandra/db/RemoveSuperColumnTest.java
Date Thu, 25 Jun 2009 21:07:47 GMT
Author: jbellis
Date: Thu Jun 25 21:07:45 2009
New Revision: 788511

URL: http://svn.apache.org/viewvc?rev=788511&view=rev
Log:
add tests for supercolumnfamily removal; fix bugs.
(both the assert removal and the "if" removal are bug fixes.)

patch by jbellis; reviewed by Sandeep Tata for CASSANDRA-255

Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/SuperColumn.java
    incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java
    incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/RemoveSuperColumnTest.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/SuperColumn.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/SuperColumn.java?rev=788511&r1=788510&r2=788511&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/SuperColumn.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/SuperColumn.java Thu Jun 25
21:07:45 2009
@@ -442,24 +442,22 @@
         }
 
         SuperColumn superColumn = defreezeSuperColumn(dis);
-        if ( !superColumn.isMarkedForDelete() )
+        int size = dis.readInt();
+        /* skip the size of the columns */
+        dis.readInt();
+        if ( size > 0 )
         {
-            int size = dis.readInt();
-            /* skip the size of the columns */
-            dis.readInt();
-            if ( size > 0 )
+            for ( int i = 0; i < size; ++i )
             {
-                for ( int i = 0; i < size; ++i )
+                IColumn subColumn = Column.serializer().deserialize(dis, names[1], filter);
+                if ( subColumn != null )
                 {
-                    IColumn subColumn = Column.serializer().deserialize(dis, names[1], filter);
-                    if ( subColumn != null )
-                    {
-                        superColumn.addColumn(subColumn);
-                        break;
-                    }
+                    superColumn.addColumn(subColumn);
+                    break;
                 }
             }
         }
+
         return superColumn;
     }
 }

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java?rev=788511&r1=788510&r2=788511&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/io/SequenceFile.java Thu Jun 25
21:07:45 2009
@@ -493,7 +493,6 @@
          */
         public long next(String key, DataOutputBuffer bufOut, String columnFamilyName, List<String>
columnNames, IndexHelper.TimeRange timeRange, long position) throws IOException
         {
-            assert !columnFamilyName.contains(":");
             assert timeRange == null || columnNames == null; // at most one may be non-null
 
             long bytesRead = -1L;

Modified: incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/RemoveSuperColumnTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/RemoveSuperColumnTest.java?rev=788511&r1=788510&r2=788511&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/RemoveSuperColumnTest.java
(original)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/RemoveSuperColumnTest.java
Thu Jun 25 21:07:45 2009
@@ -20,20 +20,22 @@
 
 import java.io.IOException;
 import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
 import java.util.List;
 import java.util.Collection;
+import java.util.Arrays;
 
 import org.apache.commons.lang.StringUtils;
 import org.junit.Test;
 import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertEquals;
 
 public class RemoveSuperColumnTest
 {
     @Test
     public void testRemoveSuperColumn() throws IOException, ExecutionException, InterruptedException
     {
-        Table table = Table.open("Table1");
-        ColumnFamilyStore store = table.getColumnFamilyStore("Super1");
+        ColumnFamilyStore store = Table.open("Table1").getColumnFamilyStore("Super1");
         RowMutation rm;
 
         // add data
@@ -47,6 +49,20 @@
         rm.delete("Super1:SC1", 1);
         rm.apply();
 
+        validateRemoveTwoSources();
+
+        store.forceBlockingFlush();
+        validateRemoveTwoSources();
+
+        Future<Integer> ft = MinorCompactionManager.instance().submit(store, 2);
+        ft.get();
+        assertEquals(1, store.getSSTables().size());
+        validateRemoveCompacted();
+    }
+
+    private void validateRemoveTwoSources() throws IOException
+    {
+        ColumnFamilyStore store = Table.open("Table1").getColumnFamilyStore("Super1");
         List<ColumnFamily> families = store.getColumnFamilies("key1", "Super1", new
IdentityFilter());
         assert families.size() == 2 : StringUtils.join(families, ", ");
         assert families.get(0).getAllColumns().first().getMarkedForDeleteAt() == 1; // delete
marker, just added
@@ -58,4 +74,69 @@
         assert subColumns.iterator().next().timestamp() == 0;
         assertNull(ColumnFamilyStore.removeDeleted(resolved, Integer.MAX_VALUE));
     }
+
+    private void validateRemoveCompacted() throws IOException
+    {
+        ColumnFamilyStore store = Table.open("Table1").getColumnFamilyStore("Super1");
+        List<ColumnFamily> families = store.getColumnFamilies("key1", "Super1", new
IdentityFilter());
+        assert families.size() == 1 : StringUtils.join(families, ", ");
+        ColumnFamily resolved = families.get(0);
+        assert resolved.getAllColumns().first().getMarkedForDeleteAt() == 1;
+        Collection<IColumn> subColumns = resolved.getAllColumns().first().getSubColumns();
+        assert subColumns.size() == 0;
+    }
+
+    @Test
+    public void testRemoveSuperColumnWithNewData() throws IOException, ExecutionException,
InterruptedException
+    {
+        ColumnFamilyStore store = Table.open("Table1").getColumnFamilyStore("Super2");
+        RowMutation rm;
+
+        // add data
+        rm = new RowMutation("Table1", "key1");
+        rm.add("Super2:SC1:Column1", "asdf".getBytes(), 0);
+        rm.apply();
+        store.forceBlockingFlush();
+
+        // remove
+        rm = new RowMutation("Table1", "key1");
+        rm.delete("Super2:SC1", 1);
+        rm.apply();
+
+        // new data
+        rm = new RowMutation("Table1", "key1");
+        rm.add("Super2:SC1:Column2", "asdf".getBytes(), 2);
+        rm.apply();
+
+        validateRemoveWithNewData();
+
+        store.forceBlockingFlush();
+        validateRemoveWithNewData();
+
+        Future<Integer> ft = MinorCompactionManager.instance().submit(store, 2);
+        ft.get();
+        assertEquals(1, store.getSSTables().size());
+        validateRemoveWithNewData();
+    }
+
+    private void validateRemoveWithNewData() throws IOException
+    {
+        ColumnFamilyStore store = Table.open("Table1").getColumnFamilyStore("Super2");
+        List<ColumnFamily> families;
+        ColumnFamily resolved;
+
+        families = store.getColumnFamilies("key1", "Super2:SC1", new NamesFilter(Arrays.asList("Column2")));
+        resolved = ColumnFamilyStore.removeDeleted(ColumnFamily.resolve(families));
+        validateNewDataFamily(resolved);
+
+        resolved = store.getColumnFamily("key1", "Super2:SC1:Column2", new IdentityFilter());
+        validateNewDataFamily(resolved);
+    }
+
+    private void validateNewDataFamily(ColumnFamily resolved)
+    {
+        Collection<IColumn> subColumns = resolved.getAllColumns().first().getSubColumns();
+        assert subColumns.size() == 1;
+        assert subColumns.iterator().next().timestamp() == 2;
+    }
 }



Mime
View raw message