[jboss-cvs] JBossCache/src/org/jboss/cache/interceptors ...
Manik Surtani
msurtani at jboss.com
Tue Dec 5 12:25:45 EST 2006
User: msurtani
Date: 06/12/05 12:25:45
Modified: src/org/jboss/cache/interceptors Tag:
Branch_JBossCache_1_3_0
PessimisticLockInterceptor.java
Log:
Some fine-tunings
Revision Changes Path
No revision
No revision
1.14.2.9 +20 -4 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.8
retrieving revision 1.14.2.9
diff -u -b -r1.14.2.8 -r1.14.2.9
--- PessimisticLockInterceptor.java 1 Dec 2006 15:44:20 -0000 1.14.2.8
+++ PessimisticLockInterceptor.java 5 Dec 2006 17:25:45 -0000 1.14.2.9
@@ -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.8 2006/12/01 15:44:20 msurtani Exp $
+ * @version $Id: PessimisticLockInterceptor.java,v 1.14.2.9 2006/12/05 17:25:45 msurtani Exp $
*/
public class PessimisticLockInterceptor extends Interceptor {
TransactionTable tx_table=null;
@@ -145,7 +145,7 @@
do {
lock(fqn, ctx.getGlobalTransaction(), lock_type, recursive, lock_timeout, createIfNotExists, storeLockedNode);
}
- while(cache.peek(fqn) == null); // keep trying until we have the lock (fixes concurrent remove())
+ while(!cache.exists(fqn)); // keep trying until we have the lock (fixes concurrent remove())
// terminates successfully, or with (Timeout)Exception
}
else
@@ -243,6 +243,12 @@
currentLockType = DataNode.LOCK_TYPE_READ;
}
+ // reverse the "remove" if the node has been previously removed in the same tx, if this operation is a put()
+ if (needToReverseRemove(child_node, tx_table.get(gtx), lock_type, isRemoveNodeOperation))
+ {
+ reverseRemove(child_node);
+ }
+
// Try to acquire the lock; recording that we did if successful
acquireNodeLock(child_node, owner, gtx, currentLockType, lock_timeout);
@@ -269,6 +275,16 @@
if (isRemoveNodeOperation && gtx != null) cache.getTransactionTable().get(gtx).addRemovedNode(fqn);
}
+ private boolean needToReverseRemove(DataNode n, TransactionEntry te, int lockTypeRequested, boolean isRemoveOperation)
+ {
+ return !isRemoveOperation && lockTypeRequested == DataNode.LOCK_TYPE_WRITE && cache.isMarkedForRemoval(n) && te.getRemovedNodes().contains(n.getFqn());
+ }
+
+ private void reverseRemove(DataNode n)
+ {
+ cache.scrubRemoveMarker(n, false);
+ }
+
private boolean writeLockNeeded(int lock_type, int currentNodeIndex, int treeNodeSize, boolean isRemoveOperation, boolean createIfNotExists, Fqn targetFqn, Fqn currentFqn)
{
if (isRemoveOperation && currentNodeIndex == treeNodeSize - 2)
@@ -277,7 +293,7 @@
if (!isTargetNode(currentNodeIndex, treeNodeSize) && !cache.exists(new Fqn(currentFqn, targetFqn.get(currentNodeIndex + 1))))
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) && createIfNotExists; //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 || isRemoveOperation); //normal operation, write lock explicitly requested and this is the target to be written to.
}
private boolean isTargetNode(int nodePosition, int treeNodeSize)
More information about the jboss-cvs-commits
mailing list