[infinispan-dev] race condition in AsyncStore
Mircea Markus
mircea.markus at jboss.com
Wed Oct 28 12:51:11 EDT 2009
Hi Galder,
This is following an email sent this morning on an infinit loop in
AsyncTest. I've found what was[1] causing the infinite loop. Here it
is (see comments in the code):
Let's say we do put(k1, v1) and put(k1, v2) in this order
void run0() throws InterruptedException {
if (trace) log.trace("Checking for modifications");
boolean unlock = false;
try {
acquireLock(write);
unlock = true;
swap = state;
state = newStateMap();
} finally {
if (unlock) write.unlock();
}
//thread ONE comes here and is processing (k1, v1); it releases the
write lock. Immediately, thread TWO acquires write lock, and takes
(k1,v2) from the store into its swap.
// the race condition happens when thread TWO executes (i.e. persists)
before thread one, and as a result in the store the final value
persisted is v1 (not v2).
// This is known to be an async (i.e. best effort store), so this
situation might be considered as normal behavior. Still, I think this
induces unwanted errors/behavior.
// A possible solution is to only release the WL after put(swap).
if (trace) log.trace("About to insert the swap: " + swap);
int size = swap.size();
if (size == 0)
awaitNotEmpty();
else
decrementAndGet(size);
if (trace) log.trace("Calling put(List) with {0}
modifications", size);
put(swap);
}
Cheers,
Mircea
[1] I say 'was' because I modified the test to fail (intermittently)
rather than hang
More information about the infinispan-dev
mailing list