use explicit dirty flag instead of trying to cheat and use executor taskcount, which is race-prone. patch by jbellis; reviewed by Eric Evans for CASSANDRA-134

git-svn-id: https://svn.apache.org/repos/asf/incubator/cassandra/trunk@772680 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jonathan Ellis 2009-05-07 15:30:53 +00:00
parent 4a2ba89fe3
commit 3395efdb30
1 changed files with 5 additions and 1 deletions

View File

@ -57,6 +57,7 @@ public class Memtable implements Comparable<Memtable>
private MemtableThreadPoolExecutor executor_;
private volatile boolean isFrozen_;
private volatile boolean isDirty_;
private volatile boolean isFlushed_; // for tests, in particular forceBlockingFlush asserts this
private int threshold_ = DatabaseDescriptor.getMemtableSize()*1024*1024;
@ -195,6 +196,7 @@ public class Memtable implements Comparable<Memtable>
*/
void put(String key, ColumnFamily columnFamily, CommitLog.CommitLogContext cLogCtx) throws IOException
{
isDirty_ = true;
executor_.submit(new Putter(key, columnFamily));
if (isThresholdViolated())
{
@ -411,6 +413,8 @@ public class Memtable implements Comparable<Memtable>
public boolean isClean()
{
return columnFamilies_.isEmpty() && executor_.getPendingTasks() == 0;
// executor taskcount is inadequate for our needs here -- it can return zero under certain
// race conditions even though a task has been processed.
return !isDirty_;
}
}