[jboss-cvs] JBossCache/src/org/jboss/cache/interceptors ...

Manik Surtani msurtani at jboss.com
Tue Dec 5 12:16:35 EST 2006


  User: msurtani
  Date: 06/12/05 12:16:35

  Modified:    src/org/jboss/cache/interceptors  Tag:
                        Branch_JBossCache_1_4_0
                        PessimisticLockInterceptor.java
  Log:
  Ported stuff from 1.3.0.SP4
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.20.2.3  +20 -3     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.20.2.2
  retrieving revision 1.20.2.3
  diff -u -b -r1.20.2.2 -r1.20.2.3
  --- PessimisticLockInterceptor.java	5 Dec 2006 00:01:52 -0000	1.20.2.2
  +++ PessimisticLockInterceptor.java	5 Dec 2006 17:16:35 -0000	1.20.2.3
  @@ -36,7 +36,7 @@
    * current method and unlock when the method returns.
    *
    * @author Bela Ban
  - * @version $Id: PessimisticLockInterceptor.java,v 1.20.2.2 2006/12/05 00:01:52 msurtani Exp $
  + * @version $Id: PessimisticLockInterceptor.java,v 1.20.2.3 2006/12/05 17:16:35 msurtani Exp $
    */
   public class PessimisticLockInterceptor extends Interceptor
   {
  @@ -171,7 +171,7 @@
               {
                  lock(fqn, ctx.getGlobalTransaction(), lock_type, recursive, zeroLockTimeout ? 0 : lock_timeout, createIfNotExists, storeLockedNode);
               }
  -            while (!cache.exists(fqn)); // 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
  @@ -274,6 +274,13 @@
               }
            }
   
  +         // 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);
   
  @@ -302,6 +309,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)
  @@ -310,7 +327,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