You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cassandra.apache.org by jb...@apache.org on 2010/01/22 02:14:02 UTC

svn commit: r901956 - in /incubator/cassandra/trunk: src/java/org/apache/cassandra/db/ColumnFamilyStore.java test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java

Author: jbellis
Date: Fri Jan 22 01:14:02 2010
New Revision: 901956

URL: http://svn.apache.org/viewvc?rev=901956&view=rev
Log:
invalidate cache after compaction so we read what's in the new sstable instead of the cache
patch by jbellis; reviewed by goffinet for CASSANDRA-719

Modified:
    incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
    incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java

Modified: incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java?rev=901956&r1=901955&r2=901956&view=diff
==============================================================================
--- incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java (original)
+++ incubator/cassandra/trunk/src/java/org/apache/cassandra/db/ColumnFamilyStore.java Fri Jan 22 01:14:02 2010
@@ -1140,6 +1140,12 @@
         return rowCache == null ? null : rowCache.get(key);
     }
 
+    void invalidateCachedRow(String key)
+    {
+        if (rowCache != null)
+            rowCache.remove(key);
+    }
+
     /**
      * for testing.  no effort is made to clear historical memtables.
      */

Modified: incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java
URL: http://svn.apache.org/viewvc/incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java?rev=901956&r1=901955&r2=901956&view=diff
==============================================================================
--- incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java (original)
+++ incubator/cassandra/trunk/test/unit/org/apache/cassandra/db/CompactionsPurgeTest.java Fri Jan 22 01:14:02 2010
@@ -36,6 +36,7 @@
 import org.apache.cassandra.utils.FBUtilities;
 
 import static junit.framework.Assert.assertEquals;
+import static org.apache.cassandra.db.TableTest.assertColumns;
 
 public class CompactionsPurgeTest extends CleanupHelper
 {
@@ -48,7 +49,7 @@
 
         Table table = Table.open(TABLE1);
         String cfName = "Standard1";
-        ColumnFamilyStore store = table.getColumnFamilyStore(cfName);
+        ColumnFamilyStore cfs = table.getColumnFamilyStore(cfName);
 
         String key = "key1";
         RowMutation rm;
@@ -60,7 +61,7 @@
             rm.add(new QueryPath(cfName, null, String.valueOf(i).getBytes()), new byte[0], 0);
         }
         rm.apply();
-        store.forceBlockingFlush();
+        cfs.forceBlockingFlush();
 
         // deletes
         for (int i = 0; i < 10; i++)
@@ -69,28 +70,29 @@
             rm.delete(new QueryPath(cfName, null, String.valueOf(i).getBytes()), 1);
             rm.apply();
         }
-        store.forceBlockingFlush();
+        cfs.forceBlockingFlush();
 
         // resurrect one column
         rm = new RowMutation(TABLE1, key);
         rm.add(new QueryPath(cfName, null, String.valueOf(5).getBytes()), new byte[0], 2);
         rm.apply();
-        store.forceBlockingFlush();
+        cfs.forceBlockingFlush();
 
         // verify that non-major compaction does no GC to ensure correctness (see CASSANDRA-604)
-        Collection<SSTableReader> sstablesIncomplete = store.getSSTables();
+        Collection<SSTableReader> sstablesIncomplete = cfs.getSSTables();
         rm = new RowMutation(TABLE1, key + "x");
         rm.add(new QueryPath(cfName, null, "0".getBytes()), new byte[0], 0);
         rm.apply();
-        store.forceBlockingFlush();
-        CompactionManager.instance.doCompaction(store, sstablesIncomplete, CompactionManager.getDefaultGCBefore());
-        ColumnFamily cf = table.getColumnFamilyStore(cfName).getColumnFamily(new IdentityQueryFilter(key, new QueryPath(cfName)));
+        cfs.forceBlockingFlush();
+        CompactionManager.instance.doCompaction(cfs, sstablesIncomplete, CompactionManager.getDefaultGCBefore());
+        ColumnFamily cf = cfs.getColumnFamily(new IdentityQueryFilter(key, new QueryPath(cfName)));
         assert cf.getColumnCount() == 10;
 
         // major compact and test that all columns but the resurrected one is completely gone
-        CompactionManager.instance.submitMajor(store, 0, Integer.MAX_VALUE).get();
-        cf = table.getColumnFamilyStore(cfName).getColumnFamily(new IdentityQueryFilter(key, new QueryPath(cfName)));
-        assert cf.getColumnCount() == 1;
+        CompactionManager.instance.submitMajor(cfs, 0, Integer.MAX_VALUE).get();
+        cfs.invalidateCachedRow(key);
+        cf = cfs.getColumnFamily(new IdentityQueryFilter(key, new QueryPath(cfName)));
+        assertColumns(cf, "5");
         assert cf.getColumn(String.valueOf(5).getBytes()) != null;
     }