From 8417db8fa9b75ed27dcfa1e56263d92ab97c80f0 Mon Sep 17 00:00:00 2001 From: Jonathan Ellis Date: Tue, 8 Dec 2009 06:19:30 +0000 Subject: [PATCH] compute major-ness of compaction in the compaction method, rather than relying on caller to do it correctly (as some tests were not). patch by jbellis git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@888279 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/cassandra/db/ColumnFamilyStore.java | 17 +++++++++++------ .../apache/cassandra/db/CompactionsTest.java | 4 ++-- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java index b60bf97416..03169deaf4 100644 --- a/src/java/org/apache/cassandra/db/ColumnFamilyStore.java +++ b/src/java/org/apache/cassandra/db/ColumnFamilyStore.java @@ -660,7 +660,7 @@ public final class ColumnFamilyStore implements ColumnFamilyStoreMBean // re-compacting files we just created. Collections.sort(sstables); boolean major = sstables.size() == ssTables_.size(); - filesCompacted += doFileCompaction(sstables.subList(0, Math.min(sstables.size(), maxThreshold)), major); + filesCompacted += doFileCompaction(sstables.subList(0, Math.min(sstables.size(), maxThreshold))); } logger_.debug(filesCompacted + " files compacted"); } @@ -702,7 +702,7 @@ public final class ColumnFamilyStore implements ColumnFamilyStoreMBean sstables = ssTables_.getSSTables(); } - doFileCompaction(sstables, major); + doFileCompaction(sstables); } /* @@ -858,9 +858,9 @@ public final class ColumnFamilyStore implements ColumnFamilyStoreMBean return results; } - private int doFileCompaction(Collection sstables, boolean major) throws IOException + private int doFileCompaction(Collection sstables) throws IOException { - return doFileCompaction(sstables, getDefaultGCBefore(), major); + return doFileCompaction(sstables, getDefaultGCBefore()); } /* @@ -876,7 +876,7 @@ public final class ColumnFamilyStore implements ColumnFamilyStoreMBean * The collection of sstables passed may be empty (but not null); even if * it is not empty, it may compact down to nothing if all rows are deleted. */ - int doFileCompaction(Collection sstables, int gcBefore, boolean major) throws IOException + int doFileCompaction(Collection sstables, int gcBefore) throws IOException { if (DatabaseDescriptor.isSnapshotBeforeCompaction()) Table.open(table_).snapshot("compact-" + columnFamily_); @@ -889,9 +889,14 @@ public final class ColumnFamilyStore implements ColumnFamilyStoreMBean SSTableReader maxFile = getMaxSizeFile(sstables); List smallerSSTables = new ArrayList(sstables); smallerSSTables.remove(maxFile); - return doFileCompaction(smallerSSTables, gcBefore, false); + return doFileCompaction(smallerSSTables, gcBefore); } + // new sstables from flush can be added during a compaction, but only the compaction can remove them, + // so in our single-threaded compaction world this is a valid way of determining if we're compacting + // all the sstables (that existed when we started) + boolean major = sstables.size() == ssTables_.size(); + long startTime = System.currentTimeMillis(); long totalkeysWritten = 0; diff --git a/test/unit/org/apache/cassandra/db/CompactionsTest.java b/test/unit/org/apache/cassandra/db/CompactionsTest.java index d65f8d55cd..01994e7cdb 100644 --- a/test/unit/org/apache/cassandra/db/CompactionsTest.java +++ b/test/unit/org/apache/cassandra/db/CompactionsTest.java @@ -112,7 +112,7 @@ public class CompactionsTest extends CleanupHelper store.forceBlockingFlush(); // compact and test that all columns but the resurrected one is completely gone - store.doFileCompaction(store.getSSTables(), Integer.MAX_VALUE, false); + store.doFileCompaction(store.getSSTables(), Integer.MAX_VALUE); ColumnFamily cf = table.getColumnFamilyStore(cfName).getColumnFamily(new IdentityQueryFilter(key, new QueryPath(cfName))); assert cf.getColumnCount() == 1; assert cf.getColumn(String.valueOf(5).getBytes()) != null; @@ -150,7 +150,7 @@ public class CompactionsTest extends CleanupHelper assert store.getSSTables().size() == 1 : store.getSSTables(); // inserts & deletes were in the same memtable -> only deletes in sstable // compact and test that the row is completely gone - store.doFileCompaction(store.getSSTables(), Integer.MAX_VALUE, false); + store.doFileCompaction(store.getSSTables(), Integer.MAX_VALUE); assert store.getSSTables().isEmpty(); ColumnFamily cf = table.getColumnFamilyStore(cfName).getColumnFamily(new IdentityQueryFilter(key, new QueryPath(cfName))); assert cf == null : cf;