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

Manik Surtani msurtani at jboss.com
Thu Jan 4 00:35:40 EST 2007


  User: msurtani
  Date: 07/01/04 00:35:40

  Modified:    src/org/jboss/cache/lock   IdentityLock.java LockUtil.java
  Log:
  Major changes around nodes, and the way they interact with the interceptor stack.
  Also removed redundant methods in NodeSPI and removed the need for casting to NodeSPI in most cases.
  
  Revision  Changes    Path
  1.19      +34 -15    JBossCache/src/org/jboss/cache/lock/IdentityLock.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: IdentityLock.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/lock/IdentityLock.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -b -r1.18 -r1.19
  --- IdentityLock.java	31 Dec 2006 02:08:40 -0000	1.18
  +++ IdentityLock.java	4 Jan 2007 05:35:40 -0000	1.19
  @@ -10,6 +10,7 @@
   import org.apache.commons.logging.LogFactory;
   import org.jboss.cache.Fqn;
   import org.jboss.cache.Node;
  +import org.jboss.cache.NodeSPI;
   
   import java.util.ArrayList;
   import java.util.Collection;
  @@ -58,7 +59,7 @@
    *
    * @author <a href="mailto:bela at jboss.org">Bela Ban</a> Apr 11, 2003
    * @author Ben Wang July 2003
  - * @version $Revision: 1.18 $
  + * @version $Revision: 1.19 $
    */
   public class IdentityLock implements NodeLock
   {
  @@ -73,12 +74,12 @@
      private final LockStrategy lock_;
      private final LockMap map_;
      private final boolean mustReacquireRead_;
  -   private Node node;
  +   private NodeSPI node;
   
      /**
       * Creates a new Identity lock based on the lock level set in the {@link LockStrategyFactory}
       */
  -   public IdentityLock(Node node)
  +   public IdentityLock(NodeSPI node)
      {
         this(LockStrategyFactory.getLockStrategy(), node);
         log.trace("Using default lock level");
  @@ -89,12 +90,12 @@
       *
       * @param level
       */
  -   public IdentityLock(IsolationLevel level, Node node)
  +   public IdentityLock(IsolationLevel level, NodeSPI node)
      {
         this(LockStrategyFactory.getLockStrategy(level), node);
      }
   
  -   private IdentityLock(LockStrategy strategy, Node node)
  +   private IdentityLock(LockStrategy strategy, NodeSPI node)
      {
         lock_ = strategy;
         mustReacquireRead_ = strategy instanceof LockStrategyReadCommitted;
  @@ -116,7 +117,9 @@
      public Fqn getFqn()
      {
         if (node == null)
  +      {
            return null;
  +      }
         return node.getFqn();
      }
   
  @@ -179,8 +182,10 @@
         if (map_.isOwner(caller, LockMap.OWNER_WRITE))
         {
            if (trace)
  +         {
               log.trace("acquireWriteLock(): caller already owns lock for " + getFqn() + " (caller=" + caller + ')');
  -         return false; // owner already has the lock
  +         }
  +         return false;// owner already has the lock
         }
   
         // Check first if we need to upgrade
  @@ -191,7 +196,9 @@
            try
            {
               if (trace)
  +            {
                  log.trace("upgrading RL to WL for " + caller + ", timeout=" + timeout + ", locks: " + map_.printInfo());
  +            }
               wLock = lock_.upgradeLockAttempt(timeout);
            }
            catch (UpgradeException ue)
  @@ -202,7 +209,7 @@
            }
            if (wLock == null)
            {
  -            release(caller);   // bug fix: remember to release the read lock before throwing the exception
  +            release(caller);// bug fix: remember to release the read lock before throwing the exception
               map_.removeReader(caller);
               String errStr = "upgrade lock for " + getFqn() + " could not be acquired after " + timeout + " ms." +
                       " Lock map ownership " + map_.printInfo() + " (caller=" + caller + ')';
  @@ -212,7 +219,9 @@
            try
            {
               if (trace)
  +            {
                  log.trace("upgrading lock for " + getFqn());
  +            }
               map_.upgrade(caller);
            }
            catch (OwnerNotExistedException ex)
  @@ -279,8 +288,10 @@
         {
            hasRequired = map_.isOwner(caller, LockMap.OWNER_WRITE);
            if (!hasRequired)
  +         {
               hasRead = map_.isOwner(caller, LockMap.OWNER_READ);
         }
  +      }
         else if (map_.isOwner(caller, LockMap.OWNER_ANY))
         {
            hasRequired = true;
  @@ -294,7 +305,7 @@
               sb.append("acquireReadLock(): caller ").append(caller).append(" already owns lock for ").append(getFqn());
               log.trace(sb.toString());
            }
  -         return false; // owner already has the lock
  +         return false;// owner already has the lock
         }
   
         rc = lock_.readLock().tryLock(timeout, TimeUnit.MILLISECONDS);
  @@ -312,7 +323,9 @@
   
         // Only add to the map if we didn't already have the lock
         if (!hasRead)
  -         map_.addReader(caller); // this is synchronized internally, we don't need to synchronize here
  +      {
  +         map_.addReader(caller);// this is synchronized internally, we don't need to synchronize here
  +      }
         return true;
      }
   
  @@ -434,19 +447,25 @@
            Iterator iter = read_owners.iterator();
            read_owners = new ArrayList(read_owners.size());
            while (iter.hasNext())
  +         {
               read_owners.add(iter.next());
  +         }
   
            sb.append("read owners=").append(read_owners);
            printed_read_owners = true;
         }
         else
  +      {
            read_owners = null;
  +      }
   
         Object write_owner = lock_ != null ? getWriterOwner() : null;
         if (write_owner != null)
         {
            if (printed_read_owners)
  +         {
               sb.append(", ");
  +         }
            sb.append("write owner=").append(write_owner);
         }
         if (read_owners == null && write_owner == null)
  @@ -524,18 +543,18 @@
            retval.add(this);
         }
   
  -      for (Node n : node.getChildren())
  +      for (NodeSPI n : node.getChildrenDirect())
         {
  -         retval.addAll(n.getNodeSPI().getLock().acquireAll(caller, timeout, lock_type));
  +         retval.addAll(n.getLock().acquireAll(caller, timeout, lock_type));
         }
         return retval;
      }
   
      public void releaseAll(Object owner)
      {
  -      for (Node n : node.getChildren())
  +      for (NodeSPI n : node.getChildrenDirect())
         {
  -         n.getNodeSPI().getLock().releaseAll(owner);
  +         n.getLock().releaseAll(owner);
         }
         release(owner);
      }
  @@ -564,10 +583,10 @@
            sb.append(")");
         }
   
  -      for (Node n : node.getChildren())
  +      for (NodeSPI n : node.getChildrenDirect())
         {
            sb.append("\n");
  -         n.getNodeSPI().getLock().printLockInfo(sb, indent + 4);
  +         n.getLock().printLockInfo(sb, indent + 4);
         }
      }
   
  
  
  
  1.7       +27 -4     JBossCache/src/org/jboss/cache/lock/LockUtil.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: LockUtil.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/lock/LockUtil.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- LockUtil.java	30 Dec 2006 17:49:58 -0000	1.6
  +++ LockUtil.java	4 Jan 2007 05:35:40 -0000	1.7
  @@ -5,6 +5,7 @@
   import org.jboss.cache.CacheImpl;
   import org.jboss.cache.GlobalTransaction;
   import org.jboss.cache.Node;
  +import org.jboss.cache.NodeSPI;
   import org.jboss.cache.TransactionTable;
   import org.jboss.cache.statetransfer.StateTransferManager;
   
  @@ -38,9 +39,13 @@
         {
            int status = breakTransactionLock(gtx, lock, tx_table, tm, localTx, lastStatus, tryCount);
            if (status == TransactionLockStatus.STATUS_BROKEN)
  +         {
               broken = true;
  +         }
            else if (status != lastStatus)
  +         {
               tryCount = 0;
  +         }
            lastStatus = status;
   
            tryCount++;
  @@ -60,17 +65,19 @@
       * @param lockChildren <code>true</code> if this method should be recursively
       *                     applied to <code>node</code>'s children.
       */
  -   public static void forceAcquireLock(Node node,
  +   public static void forceAcquireLock(NodeSPI node,
                                          Object newOwner,
                                          CacheImpl cache,
                                          boolean lockChildren)
      {
   
  -      NodeLock lock = node.getNodeSPI().getLock();
  +      NodeLock lock = node.getLock();
         boolean acquired = lock.isOwner(newOwner);
   
         if (!acquired && log.isDebugEnabled())
  +      {
            log.debug("Force acquiring lock on node " + node.getFqn());
  +      }
   
         TransactionTable tx_table = cache.getTransactionTable();
         TransactionManager tm = cache.getTransactionManager();
  @@ -123,7 +130,7 @@
         // Recursively unlock children
         if (lockChildren)
         {
  -         for (Node n : node.getChildren())
  +         for (NodeSPI n : node.getChildrenDirect())
            {
               forceAcquireLock(n, newOwner, cache, true);
            }
  @@ -149,8 +156,10 @@
                                                  Object localAddress)
      {
         if (log.isTraceEnabled())
  +      {
            log.trace("Attempting to acquire lock for node " + node.getFqn() +
                    " from owner " + curOwner);
  +      }
   
         boolean acquired = false;
         boolean broken = false;
  @@ -165,9 +174,13 @@
               boolean local = gtx.getAddress().equals(localAddress);
               int status = breakTransactionLock(gtx, lock, tx_table, tm, local, lastStatus, tryCount);
               if (status == TransactionLockStatus.STATUS_BROKEN)
  +            {
                  broken = true;
  +            }
               else if (status != lastStatus)
  +            {
                  tryCount = 0;
  +            }
               lastStatus = status;
            }
            else if (tryCount > 0)
  @@ -177,8 +190,10 @@
            }
   
            if (broken && log.isTraceEnabled())
  +         {
               log.trace("Broke lock for node " + node.getFqn() +
                       " held by owner " + curOwner);
  +         }
   
            try
            {
  @@ -236,7 +251,9 @@
               status = tx.getStatus();
   
               if (status != lastStatus)
  +            {
                  tryCount = 0;
  +            }
   
               switch (status)
               {
  @@ -247,8 +264,10 @@
                     if (tryCount == 0)
                     {
                        if (log.isTraceEnabled())
  +                     {
                           log.trace("Attempting to break transaction lock held " +
                                   " by " + gtx + " by rolling back local tx");
  +                     }
                        // This thread has to join the tx
                        tm.resume(tx);
                        try
  @@ -274,7 +293,9 @@
                  case Status.STATUS_ROLLING_BACK:
                     // We'll try up to 10 times before just releasing
                     if (tryCount < 10)
  -                     break; // let it finish
  +                  {
  +                     break;// let it finish
  +                  }
                     // fall through and release
   
                  case Status.STATUS_COMMITTED:
  @@ -292,9 +313,11 @@
                     {
                        // We can still abort the commit
                        if (log.isTraceEnabled())
  +                     {
                           log.trace("Attempting to break transaction lock held " +
                                   "by " + gtx + " by marking local tx as " +
                                   "rollback-only");
  +                     }
                        tx.setRollbackOnly();
                        break;
                     }
  
  
  



More information about the jboss-cvs-commits mailing list