JBoss Cache SVN: r5359 - in core/trunk/src: test/java/org/jboss/cache/api and 1 other directory.
by jbosscache-commits@lists.jboss.org
Author: mircea.markus
Date: 2008-02-20 04:52:11 -0500 (Wed, 20 Feb 2008)
New Revision: 5359
Modified:
core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java
Log:
fixed following: if we remove a node twice in the same transaction, then second time a LockAcquisitionTimeout occured in PLI
Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-02-20 09:09:29 UTC (rev 5358)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/PessimisticLockInterceptor.java 2008-02-20 09:52:11 UTC (rev 5359)
@@ -192,7 +192,7 @@
Fqn childFqn = new Fqn(childName);
NodeSPI child_node = n.getChildDirect(childFqn);
if (child_node == null) child_node = n.addChildDirect(childFqn);
- manageReverseRemove(ctx.getGlobalTransaction(), child_node, true);
+ manageReverseRemove(ctx.getGlobalTransaction(), child_node, true, null);
n = child_node;
}
}
@@ -314,7 +314,7 @@
List<NodeSPI> createdNodes = new LinkedList<NodeSPI>();
// we need to mark new nodes created as deleted since they are only created to form a path to the node being removed, to
// create a lock.
- boolean created = acquireLocksWithTimeout(ctx, fqn, NodeLock.LockType.WRITE, true, false, true, false, createdNodes, true);
+ boolean created = acquireLocksWithTimeout(ctx, fqn, NodeLock.LockType.WRITE, true, false, true, true, createdNodes, true);
if (ctx.getGlobalTransaction() != null)
{
TransactionEntry entry = tx_table.get(ctx.getGlobalTransaction());
@@ -512,7 +512,7 @@
// actually acquire the lock we need. This method blocks.
acquireNodeLock(ctx, currentNode, owner, gtx, lockTypeRequired, timeout);
- manageReverseRemove(gtx, currentNode, reverseRemoveCheck);
+ manageReverseRemove(gtx, currentNode, reverseRemoveCheck, createdNodes);
// make sure the lock we acquired isn't on a deleted node/is an orphan!!
// look into invalidated nodes as well
NodeSPI repeek = peekNode(ctx, currentNodeFqn, true, true, true);
@@ -566,7 +566,6 @@
childName = fqn.get(currentIndex);
currentNode = currentNode.getChildDirect(childName);
- log.trace("Current node's identity is :" + System.identityHashCode(currentNode));
}
} while (true);
return created;
@@ -651,12 +650,16 @@
* Test if this node needs to be 'undeleted'
* reverse the "remove" if the node has been previously removed in the same tx, if this operation is a put()
*/
- private void manageReverseRemove(GlobalTransaction gtx, NodeSPI childNode, boolean reverseRemoveCheck)
+ private void manageReverseRemove(GlobalTransaction gtx, NodeSPI childNode, boolean reverseRemoveCheck, List createdNodes)
{
boolean needToReverseRemove = reverseRemoveCheck && childNode.isDeleted() && tx_table.isNodeRemovedInTx(gtx, childNode.getFqn());
if (gtx != null && needToReverseRemove)
{
childNode.markAsDeleted(false);
+ if (createdNodes != null)
+ {
+ createdNodes.add(childNode);
+ }
}
}
Modified: core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java 2008-02-20 09:09:29 UTC (rev 5358)
+++ core/trunk/src/test/java/org/jboss/cache/api/NodeAPITest.java 2008-02-20 09:52:11 UTC (rev 5359)
@@ -356,4 +356,29 @@
assertEquals(childrenNames, rootNode.getChildrenNames());
}
+ public void testDoubleRemovalOfData()
+ {
+ try
+ {
+ cache.put("/foo/1/2/3", "item", 1);
+ tm.begin();
+ assertEquals(cache.get("/foo/1/2/3", "item"), 1);
+ cache.removeNode("/foo/1");
+ assertNull(cache.get("/foo/1", "item"));
+ cache.removeNode("/foo/1/2/3");
+ assertNull(cache.get("/foo/1/2/3", "item"));
+ assertNull(cache.get("/foo/1", "item"));
+ tm.commit();
+ assertFalse(cache.exists("/foo/1"));
+ assertNull(cache.get("/foo/1/2/3", "item"));
+ assertNull(cache.get("/foo/1", "item"));
+ }
+ catch (Throwable t)
+ {
+ t.printStackTrace();
+ fail(t.toString());
+ }
+
+ }
+
}