[jboss-cvs] JBossCache/src/org/jboss/cache/interceptors ...
Manik Surtani
msurtani at jboss.com
Tue Nov 28 22:20:53 EST 2006
User: msurtani
Date: 06/11/28 22:20:53
Modified: src/org/jboss/cache/interceptors Tag:
Branch_JBossCache_1_3_0
PessimisticLockInterceptor.java
Log:
fixed more bugs
Revision Changes Path
No revision
No revision
1.14.2.5 +19 -48 JBossCache/src/org/jboss/cache/interceptors/PessimisticLockInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PessimisticLockInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/PessimisticLockInterceptor.java,v
retrieving revision 1.14.2.4
retrieving revision 1.14.2.5
diff -u -b -r1.14.2.4 -r1.14.2.5
--- PessimisticLockInterceptor.java 26 Nov 2006 12:25:43 -0000 1.14.2.4
+++ PessimisticLockInterceptor.java 29 Nov 2006 03:20:53 -0000 1.14.2.5
@@ -34,7 +34,7 @@
* scope of the TX. When no TX is present, we keep track of the locks acquired during the current method and unlock
* when the method returns
* @author Bela Ban
- * @version $Id: PessimisticLockInterceptor.java,v 1.14.2.4 2006/11/26 12:25:43 msurtani Exp $
+ * @version $Id: PessimisticLockInterceptor.java,v 1.14.2.5 2006/11/29 03:20:53 msurtani Exp $
*/
public class PessimisticLockInterceptor extends Interceptor {
TransactionTable tx_table=null;
@@ -43,7 +43,6 @@
Map lock_table;
private long lock_acquisition_timeout;
-
public void setCache(TreeCache cache) {
super.setCache(cache);
tx_table=cache.getTransactionTable();
@@ -146,7 +145,7 @@
do {
lock(fqn, ctx.getGlobalTransaction(), lock_type, recursive, lock_timeout, createIfNotExists, storeLockedNode);
}
- while(!cache.exists(fqn)); // keep trying until we have the lock (fixes concurrent remove())
+ while(cache.peek(fqn) == null); // keep trying until we have the lock (fixes concurrent remove())
// terminates successfully, or with (Timeout)Exception
}
else
@@ -164,7 +163,8 @@
// to add the removedNodes map to TreeCache
if (storeLockedNode && ctx.getGlobalTransaction() == null)
{
- cache.getRemovedNodesMap().remove(fqn);
+ //cache.getRemovedNodesMap().remove(fqn);
+ cache.peek(fqn);
}
return retval;
@@ -216,28 +216,7 @@
else
{
child_name = fqn.get(i);
- child_node = (DataNode) n.getChild(child_name);
- }
- if (child_node == null)
- {
- if (lock_type != DataNode.LOCK_TYPE_NONE)
- {
- // JBCACHE-871 -- If this is a node removed by another incomplete
- // invocation or an uncommitted transaction, we won't be able to find
- // the node in the cache; so first check for it in the removedNodes map
- DataNode removed = (DataNode) cache.getRemovedNodesMap().get(fqn.getFqnChild(i +1));
- if (removed != null)
- {
- acquireNodeLock(removed, owner, gtx, lock_type, lock_timeout);
- }
-// else
-// {
-// // JBCACHE-875 - this is a create operation. So make sure we have a WL on the PARENT.
-// if (log.isTraceEnabled()) log.trace("Trying to get a hold of WL on Node " + n.getFqn());
-// acquireNodeLock(n, owner, gtx, DataNode.LOCK_TYPE_WRITE, lock_timeout);
-// }
- }
child_node = (DataNode) n.getOrCreateChild(child_name, gtx, createIfNotExists);
}
@@ -253,14 +232,7 @@
continue;
}
-// if (isRemoveNodeOperation && isTargetNode(i, treeNodeSize))
-// {
-// // JBCACHE-875 - this is a node removal operation. So make sure we have a WL on the PARENT.
-// acquireNodeLock(n, owner, gtx, DataNode.LOCK_TYPE_WRITE, lock_timeout);
-// }
-
-
- if (writeLockNeeded(lock_type, i, treeNodeSize, isRemoveNodeOperation, fqn, child_node.getFqn()))
+ if (writeLockNeeded(lock_type, i, treeNodeSize, isRemoveNodeOperation, createIfNotExists, fqn, child_node.getFqn()))
{
currentLockType = DataNode.LOCK_TYPE_WRITE;
}
@@ -291,22 +263,19 @@
n=child_node;
}
- if (isRemoveNodeOperation && n != null)
- {
- cache.getRemovedNodesMap().put(fqn, n);
- if (gtx != null) cache.getTransactionTable().get(gtx).addRemovedNode(fqn);
- }
+ // Add the Fqn to be removed to the transaction entry so we can clean up after ourselves during commit/rollback
+ if (isRemoveNodeOperation && gtx != null) cache.getTransactionTable().get(gtx).addRemovedNode(fqn);
}
- private boolean writeLockNeeded(int lock_type, int currentNodeIndex, int treeNodeSize, boolean isRemoveOperation, Fqn targetFqn, Fqn currentFqn)
+ private boolean writeLockNeeded(int lock_type, int currentNodeIndex, int treeNodeSize, boolean isRemoveOperation, boolean createIfNotExists, Fqn targetFqn, Fqn currentFqn)
{
if (isRemoveOperation && currentNodeIndex == treeNodeSize - 2)
return true; // we're doing a remove and we've reached the PARENT node of the target to be removed.
if (!isTargetNode(currentNodeIndex, treeNodeSize) && !cache.exists(new Fqn(currentFqn, targetFqn.get(currentNodeIndex + 1))))
- return true; // we're at a node in the tree, not yet at the target node, and we need to create the next node. So we need a WL here.
+ return createIfNotExists; // we're at a node in the tree, not yet at the target node, and we need to create the next node. So we need a WL here.
- return lock_type == DataNode.LOCK_TYPE_WRITE && isTargetNode(currentNodeIndex, treeNodeSize); //normal operation, write lock explicitly requested and this is the target to be written to.
+ return lock_type == DataNode.LOCK_TYPE_WRITE && isTargetNode(currentNodeIndex, treeNodeSize) && createIfNotExists; //normal operation, write lock explicitly requested and this is the target to be written to.
}
private boolean isTargetNode(int nodePosition, int treeNodeSize)
@@ -390,7 +359,7 @@
while (removedNodes.hasNext())
{
Fqn f = (Fqn) removedNodes.next();
- cache.getRemovedNodesMap().remove(f);
+ cache.realRemove(f, false);
}
}
@@ -420,6 +389,14 @@
return;
}
+ Iterator removedNodes = entry.getRemovedNodes().iterator();
+ while (removedNodes.hasNext())
+ {
+ Fqn f = (Fqn) removedNodes.next();
+ cache.realRemove(f, false);
+
+ }
+
// 1. Revert the modifications by running the undo-op list in reverse. This *cannot* throw any exceptions !
undo_ops=new LinkedList(entry.getUndoOperations());
for(ListIterator it=undo_ops.listIterator(undo_ops.size()); it.hasPrevious();) {
@@ -470,12 +447,6 @@
tx_table.remove(ltx);
tx_table.remove(tx);
- Iterator removedNodes = entry.getRemovedNodes().iterator();
- while (removedNodes.hasNext())
- {
- Fqn f = (Fqn) removedNodes.next();
- cache.getRemovedNodesMap().remove(f);
- }
}
}
More information about the jboss-cvs-commits
mailing list