Permalink
Browse files

test and fix for CF clone bug during remove. patch by Jun Rao; review…

…ed by jbellis for #33
  • Loading branch information...
1 parent d0ad5f6 commit c646fcf5d2aea73a130bfb65acbad9eca87b9f67 Jonathan Ellis committed Apr 17, 2009
@@ -315,7 +315,7 @@ ColumnFamily getLocalCopy(String key, String columnFamilyColumn, IFilter filter)
IColumn column = cFamily.getColumn(values[1]); // super or normal column
if (column != null )
{
- columnFamily = new ColumnFamily(cfName_, cFamily.type());
+ columnFamily = cFamily.cloneMeShallow();
columnFamily.addColumn(column);
}
}
@@ -328,7 +328,7 @@ ColumnFamily getLocalCopy(String key, String columnFamilyColumn, IFilter filter)
IColumn subColumn = superColumn.getSubColumn(values[2]);
if (subColumn != null)
{
- columnFamily = new ColumnFamily(cfName_, cFamily.type());
+ columnFamily = cFamily.cloneMeShallow();
columnFamily.addColumn(values[1] + ":" + values[2], subColumn.value(), subColumn.timestamp(), subColumn.isMarkedForDelete());
}
}
@@ -272,6 +272,29 @@ public void testRemoveColumnFamily() throws IOException, ColumnFamilyNotDefinedE
ColumnFamilyStore store = table.getColumnFamilyStore("Standard1");
RowMutation rm;
+ // add data
+ rm = new RowMutation("Table1", "key1");
+ rm.add("Standard1:Column1", "asdf".getBytes(), 0);
+ rm.apply();
+
+ // remove
+ rm = new RowMutation("Table1", "key1");
+ rm.delete("Standard1", 1);
+ rm.apply();
+
+ ColumnFamily retrieved = store.getColumnFamily("key1", "Standard1:Column1", new IdentityFilter());
+ assert retrieved.isMarkedForDelete();
+ assertNull(retrieved.getColumn("Column1"));
+ assertNull(ColumnFamilyStore.removeDeleted(retrieved, Integer.MAX_VALUE));
+ }
+
+ @Test
+ public void testRemoveColumnFamilyWithFlush1() throws IOException, ColumnFamilyNotDefinedException, ExecutionException, InterruptedException
+ {
+ Table table = Table.open("Table1");
+ ColumnFamilyStore store = table.getColumnFamilyStore("Standard1");
+ RowMutation rm;
+
// add data
rm = new RowMutation("Table1", "key1");
rm.add("Standard1:Column1", "asdf".getBytes(), 0);
@@ -286,7 +309,30 @@ public void testRemoveColumnFamily() throws IOException, ColumnFamilyNotDefinedE
ColumnFamily retrieved = store.getColumnFamily("key1", "Standard1", new IdentityFilter());
assert retrieved.isMarkedForDelete();
- assertEquals(retrieved.getColumnCount(), 0);
+ assertNull(retrieved.getColumn("Column1"));
+ assertNull(ColumnFamilyStore.removeDeleted(retrieved, Integer.MAX_VALUE));
+ }
+
+ @Test
+ public void testRemoveColumnFamilyWithFlush2() throws IOException, ColumnFamilyNotDefinedException, ExecutionException, InterruptedException
+ {
+ Table table = Table.open("Table1");
+ ColumnFamilyStore store = table.getColumnFamilyStore("Standard1");
+ RowMutation rm;
+
+ // add data
+ rm = new RowMutation("Table1", "key1");
+ rm.add("Standard1:Column1", "asdf".getBytes(), 0);
+ rm.apply();
+ // remove
+ rm = new RowMutation("Table1", "key1");
+ rm.delete("Standard1", 1);
+ rm.apply();
+ store.forceBlockingFlush();
+
+ ColumnFamily retrieved = store.getColumnFamily("key1", "Standard1:Column1", new IdentityFilter());
+ assert retrieved.isMarkedForDelete();
+ assertNull(retrieved.getColumn("Column1"));
assertNull(ColumnFamilyStore.removeDeleted(retrieved, Integer.MAX_VALUE));
}

0 comments on commit c646fcf

Please sign in to comment.