[jboss-cvs] JBossCache/src/org/jboss/cache/interceptors ...
Manik Surtani
msurtani at jboss.com
Sun Nov 26 07:25:43 EST 2006
User: msurtani
Date: 06/11/26 07:25:43
Modified: src/org/jboss/cache/interceptors Tag:
Branch_JBossCache_1_3_0
PessimisticLockInterceptor.java
Log:
Alternate algorithm for deciding when to acquire WLs
Revision Changes Path
No revision
No revision
1.14.2.4 +25 -13 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.3
retrieving revision 1.14.2.4
diff -u -b -r1.14.2.3 -r1.14.2.4
--- PessimisticLockInterceptor.java 26 Nov 2006 11:52:06 -0000 1.14.2.3
+++ PessimisticLockInterceptor.java 26 Nov 2006 12:25:43 -0000 1.14.2.4
@@ -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.3 2006/11/26 11:52:06 msurtani Exp $
+ * @version $Id: PessimisticLockInterceptor.java,v 1.14.2.4 2006/11/26 12:25:43 msurtani Exp $
*/
public class PessimisticLockInterceptor extends Interceptor {
TransactionTable tx_table=null;
@@ -231,12 +231,12 @@
{
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);
- }
+// 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,13 +253,14 @@
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 (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 (lock_type == DataNode.LOCK_TYPE_WRITE && isTargetNode(i, treeNodeSize))
+
+ if (writeLockNeeded(lock_type, i, treeNodeSize, isRemoveNodeOperation, fqn, child_node.getFqn()))
{
currentLockType = DataNode.LOCK_TYPE_WRITE;
}
@@ -297,6 +298,17 @@
}
}
+ private boolean writeLockNeeded(int lock_type, int currentNodeIndex, int treeNodeSize, boolean isRemoveOperation, 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 lock_type == DataNode.LOCK_TYPE_WRITE && isTargetNode(currentNodeIndex, treeNodeSize); //normal operation, write lock explicitly requested and this is the target to be written to.
+ }
+
private boolean isTargetNode(int nodePosition, int treeNodeSize)
{
return nodePosition == (treeNodeSize - 1);
More information about the jboss-cvs-commits
mailing list