Author: manik.surtani(a)jboss.com
Date: 2007-11-08 21:00:46 -0500 (Thu, 08 Nov 2007)
New Revision: 4741
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
core/trunk/src/test/java/org/jboss/cache/lock/pessimistic/ConcurrentPutRemoveTest.java
Log:
Fixed return value for removeNode operations and reduced test iterations
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
---
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2007-11-08
15:40:14 UTC (rev 4740)
+++
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2007-11-09
02:00:46 UTC (rev 4741)
@@ -177,6 +177,7 @@
// If no TX: add each acquired lock to the list of locks for this method (locks)
// If TX: [merge code from TransactionInterceptor]: register with TxManager, on
commit/rollback,
// release the locks for the given TX
+ boolean created = false;
if (fqn != null)
{
if (!locksAlreadyObtained)
@@ -189,7 +190,7 @@
{
// this is an additional check to make sure we don't try for too
long.
if (!firstTry && System.currentTimeMillis() > cutoffTime) throw
new TimeoutException("Unable to acquire lock on Fqn " + fqn + " after
" + timeout + " millis");
- lock(ctx, fqn, lock_type, recursive, createIfNotExists, timeout,
isDeleteOperation, isEvictOperation, isRemoveDataOperation);
+ created = lock(ctx, fqn, lock_type, recursive, createIfNotExists, timeout,
isDeleteOperation, isEvictOperation, isRemoveDataOperation);
firstTry = false;
}
while (createIfNotExists && cache.peek(fqn, false) == null);// keep
trying until we have the lock (fixes concurrent remove())
@@ -229,7 +230,8 @@
{
cleanup(ctx.getGlobalTransaction());
}
- return o;
+ // if this is a delete op and we had to create the node, return a FALSE as nothing
*really* was deleted!
+ return isDeleteOperation && created ? false : o;
}
private long getLockAcquisitionTimeout(InvocationContext ctx)
@@ -267,8 +269,9 @@
* @param fqn
* @param lock_type DataNode.LOCK_TYPE_READ, DataNode.LOCK_TYPE_WRITE or
DataNode.LOCK_TYPE_NONE
* @param recursive Lock children recursively
+ * @return true if the node had to be created
*/
- private void lock(InvocationContext ctx, Fqn fqn, NodeLock.LockType lock_type, boolean
recursive, boolean createIfNotExists, long timeout, boolean isDeleteOperation, boolean
isEvictionOperation, boolean isRemoveDataOperation)
+ private boolean lock(InvocationContext ctx, Fqn fqn, NodeLock.LockType lock_type,
boolean recursive, boolean createIfNotExists, long timeout, boolean isDeleteOperation,
boolean isEvictionOperation, boolean isRemoveDataOperation)
throws TimeoutException, LockingException, InterruptedException
{
NodeSPI n;
@@ -276,6 +279,7 @@
Object child_name;
Thread currentThread = Thread.currentThread();
GlobalTransaction gtx = ctx.getGlobalTransaction();
+ boolean created = false;
// if the tx associated with the current thread is rolling back, barf! JBCACHE-923
if (gtx != null)
{
@@ -290,7 +294,7 @@
if (fqn == null)
{
log.error("fqn is null - this should not be the case");
- return;
+ return false;
}
if (configuration.getIsolationLevel() == IsolationLevel.NONE)
@@ -314,7 +318,6 @@
child_node = n.getChildDirect(child_name);
}
- boolean created = false;
if (log.isTraceEnabled()) log.trace("Directly got child node " +
child_name);
if (child_node == null && createIfNotExists)
{
@@ -329,7 +332,7 @@
{
log.trace("failed to find or create child " + child_name +
" of node " + n);
}
- return;
+ return false;
}
NodeLock.LockType lockTypeRequired;
@@ -394,6 +397,8 @@
// Add the Fqn to be removed to the transaction entry so we can clean up after
ourselves during commit/rollback
if (isDeleteOperation && gtx != null)
cache.getTransactionTable().get(gtx).addRemovedNode(fqn);
+
+ return created;
}
private boolean needToReverseRemove(NodeSPI n, TransactionEntry te, NodeLock.LockType
lockTypeRequested, boolean isRemoveOperation, boolean createIfNotExists)
Modified:
core/trunk/src/test/java/org/jboss/cache/lock/pessimistic/ConcurrentPutRemoveTest.java
===================================================================
---
core/trunk/src/test/java/org/jboss/cache/lock/pessimistic/ConcurrentPutRemoveTest.java 2007-11-08
15:40:14 UTC (rev 4740)
+++
core/trunk/src/test/java/org/jboss/cache/lock/pessimistic/ConcurrentPutRemoveTest.java 2007-11-09
02:00:46 UTC (rev 4741)
@@ -51,7 +51,7 @@
}
}
- @Test (invocationCount = 50)
+ @Test
public void testLock() throws Exception {
for (int x = 0; x < 2; x++) {
SeparateThread t = new SeparateThread(x);