Author: jbellis Date: Tue Sep 21 13:23:26 2010 New Revision: 999400 URL: http://svn.apache.org/viewvc?rev=999400&view=rev Log: fix replaying the last mutation in a commitlog unnecessarily. patch by jbellis; reviewed by gdusbabek for CASSANDRA-1512
Modified: cassandra/branches/cassandra-0.6/CHANGES.txt cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/commitlog/CommitLog.java cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/db/RecoveryManager2Test.java Modified: cassandra/branches/cassandra-0.6/CHANGES.txt URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/CHANGES.txt?rev=999400&r1=999399&r2=999400&view=diff ============================================================================== --- cassandra/branches/cassandra-0.6/CHANGES.txt (original) +++ cassandra/branches/cassandra-0.6/CHANGES.txt Tue Sep 21 13:23:26 2010 @@ -24,6 +24,7 @@ * make IndexInterval configurable (CASSANDRA-1488) * remove tombstones during non-major compactions when bloom filter verifies that row does not exist in other sstables (CASSANDRA-1074) + * fix replaying the last mutation in a commitlog unnecessarily (CASSANDRA-1512) 0.6.5 Modified: cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/commitlog/CommitLog.java URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/commitlog/CommitLog.java?rev=999400&r1=999399&r2=999400&view=diff ============================================================================== --- cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/commitlog/CommitLog.java (original) +++ cassandra/branches/cassandra-0.6/src/java/org/apache/cassandra/db/commitlog/CommitLog.java Tue Sep 21 13:23:26 2010 @@ -256,7 +256,7 @@ public class CommitLog for (ColumnFamily columnFamily : columnFamilies) { int id = table.getColumnFamilyId(columnFamily.name()); - if (!clHeader.isDirty(id) || entryLocation < clHeader.getPosition(id)) + if (!clHeader.isDirty(id) || entryLocation <= clHeader.getPosition(id)) { rm.removeColumnFamily(columnFamily); } @@ -291,7 +291,6 @@ public class CommitLog for (Table table : tablesRecovered) futures.addAll(table.flush()); FBUtilities.waitOnFutures(futures); - logger.info("Recovery complete"); } private CommitLogSegment currentSegment() Modified: cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/db/RecoveryManager2Test.java URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/db/RecoveryManager2Test.java?rev=999400&r1=999399&r2=999400&view=diff ============================================================================== --- cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/db/RecoveryManager2Test.java (original) +++ cassandra/branches/cassandra-0.6/test/unit/org/apache/cassandra/db/RecoveryManager2Test.java Tue Sep 21 13:23:26 2010 @@ -22,7 +22,8 @@ package org.apache.cassandra.db; import java.io.IOException; -import java.util.concurrent.ExecutionException; + +import org.apache.log4j.Logger; import org.apache.cassandra.Util; @@ -35,31 +36,44 @@ import static org.apache.cassandra.Util. public class RecoveryManager2Test extends CleanupHelper { + private static Logger logger = Logger.getLogger(RecoveryManager2Test.class); + @Test - public void testWithFlush() throws IOException, ExecutionException, InterruptedException + /* test that commit logs do not replay flushed data */ + public void testWithFlush() throws Exception { CompactionManager.instance.disableAutoCompaction(); + // add a row to another CF so we test skipping mutations within a not-entirely-flushed CF + insertRow("Standard2", "key"); + for (int i = 0; i < 100; i++) { String key = "key" + i; - insertRow(key); + insertRow("Standard1", key); } Table table1 = Table.open("Keyspace1"); ColumnFamilyStore cfs = table1.getColumnFamilyStore("Standard1"); + logger.debug("forcing flush"); cfs.forceBlockingFlush(); + // remove Standard1 SSTable/MemTables cfs.clearUnsafe(); - CommitLog.recover(); // this is a no-op. is testing this useful? + logger.debug("begin manual replay"); + // replay the commit log (nothing should be replayed since everything was flushed) + CommitLog.recover(); + + // since everything that was flushed was removed (i.e. clearUnsafe) + // and the commit shouldn't have replayed anything, there should be no data assert Util.getRangeSlice(cfs).rows.isEmpty(); } - private void insertRow(String key) throws IOException + private void insertRow(String cfname, String key) throws IOException { RowMutation rm = new RowMutation("Keyspace1", key); - ColumnFamily cf = ColumnFamily.create("Keyspace1", "Standard1"); + ColumnFamily cf = ColumnFamily.create("Keyspace1", cfname); cf.addColumn(column("col1", "val1", 1L)); rm.add(cf); rm.apply();