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

Elias Ross genman at noderunner.net
Mon Nov 20 02:33:13 EST 2006


  User: genman  
  Date: 06/11/20 02:33:13

  Modified:    src/org/jboss/cache   RegionManager.java TreeCache.java
  Log:
  JBCACHE-867 -- Fix some data copying issues of Node.getData()
  
  Revision  Changes    Path
  1.14      +18 -14    JBossCache/src/org/jboss/cache/RegionManager.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: RegionManager.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/RegionManager.java,v
  retrieving revision 1.13
  retrieving revision 1.14
  diff -u -b -r1.13 -r1.14
  --- RegionManager.java	20 Nov 2006 03:53:54 -0000	1.13
  +++ RegionManager.java	20 Nov 2006 07:33:13 -0000	1.14
  @@ -436,16 +436,18 @@
      public void inactivateRegion(String subtreeFqn) throws CacheException
      {
         Fqn fqn = Fqn.fromString(subtreeFqn);
  -      DataNode parent = null;
  -      DataNode subtreeRoot = null;
  -      boolean parentLocked = false;
  -      boolean subtreeLocked = false;
  -
         if (isActivatingDeactivating(fqn))
         {
  -         throw new CacheException("Region " + subtreeRoot.getFqn() + " is already being activated/deactivated");
  +         throw new CacheException("Region " + subtreeFqn + " is already being activated/deactivated");
         }
   
  +      Node parent = null;
  +      Node subtreeRoot = null;
  +      boolean parentLocked = false;
  +      boolean subtreeLocked = false;
  +      NodeLock parentLock = null;
  +      NodeLock subtreeLock = null;      
  +
         try
         {
            // Record that this fqn is in status change, so can't provide state
  @@ -486,14 +488,16 @@
               {
                  // Acquire locks
                  Object owner = treeCache.getOwnerForLock();
  -               subtreeRoot.getNodeSPI().getLock().acquireAll(owner, stateFetchTimeout, NodeLock.LockType.WRITE);
  +               subtreeLock = subtreeRoot.getNodeSPI().getLock();
  +               subtreeLock.acquireAll(owner, stateFetchTimeout, NodeLock.LockType.WRITE);
                  subtreeLocked = true;
   
                  // Lock the parent, as we're about to write to it
  -               parent = (DataNode) subtreeRoot.getParent();
  +               parent = subtreeRoot.getParent();
                  if (parent != null)
                  {
  -                  parent.getNodeSPI().getLock().acquire(owner, stateFetchTimeout, NodeLock.LockType.WRITE);
  +                  parentLock = parent.getNodeSPI().getLock(); 
  +                  parentLock.acquire(owner, stateFetchTimeout, NodeLock.LockType.WRITE);
                     parentLocked = true;
                  }
   
  @@ -504,13 +508,13 @@
                  if (parent != null)
                  {
                     log.debug("forcing release of locks in parent");
  -                  parent.releaseAllForce();
  +                  parentLock.releaseAll();
                  }
   
                  parentLocked = false;
   
                  log.debug("forcing release of all locks in subtree");
  -               subtreeRoot.releaseAllForce();
  +               subtreeLock.releaseAll();
                  subtreeLocked = false;
               }
            }
  @@ -532,7 +536,7 @@
               log.debug("forcing release of locks in parent");
               try
               {
  -               parent.releaseAllForce();
  +               parentLock.releaseAll();
               }
               catch (Throwable t)
               {
  @@ -544,7 +548,7 @@
               log.debug("forcing release of all locks in subtree");
               try
               {
  -               subtreeRoot.releaseAllForce();
  +               subtreeLock.releaseAll();
               }
               catch (Throwable t)
               {
  @@ -766,7 +770,7 @@
    * @author Ben Wang 02-2004
    * @author Daniel Huang (dhuang at jboss.org)
    * @author Brian Stansberry
  - * @version $Id: RegionManager.java,v 1.13 2006/11/20 03:53:54 genman Exp $
  + * @version $Id: RegionManager.java,v 1.14 2006/11/20 07:33:13 genman Exp $
    */
   /*public class ERegionManager
   {
  
  
  
  1.281     +17 -25    JBossCache/src/org/jboss/cache/TreeCache.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TreeCache.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/TreeCache.java,v
  retrieving revision 1.280
  retrieving revision 1.281
  diff -u -b -r1.280 -r1.281
  --- TreeCache.java	20 Nov 2006 05:09:15 -0000	1.280
  +++ TreeCache.java	20 Nov 2006 07:33:13 -0000	1.281
  @@ -40,6 +40,7 @@
   import org.jboss.cache.notifications.Notifier;
   import org.jboss.cache.optimistic.DataVersion;
   import org.jboss.cache.statetransfer.StateTransferManager;
  +import org.jboss.cache.util.MapCopy;
   import org.jboss.util.stream.MarshalledValueInputStream;
   import org.jboss.util.stream.MarshalledValueOutputStream;
   import org.jgroups.Address;
  @@ -95,7 +96,7 @@
    * @author <a href="mailto:manik at jboss.org">Manik Surtani (manik at jboss.org)</a>
    * @author Brian Stansberry
    * @author Daniel Huang (dhuang at jboss.org)
  - * @version $Id: TreeCache.java,v 1.280 2006/11/20 05:09:15 genman Exp $
  + * @version $Id: TreeCache.java,v 1.281 2006/11/20 07:33:13 genman Exp $
    *          <p/>
    * @see <a href="http://labs.jboss.com/portal/jbosscache/docs">JBossCache doc</a>
    */
  @@ -2225,10 +2226,6 @@
      public void _put(GlobalTransaction tx, Fqn fqn, Map data, boolean create_undo_ops, boolean erase_contents)
              throws CacheException
      {
  -      DataNode n;
  -      MethodCall undo_op = null;
  -      Map old_data;
  -
         if (log.isTraceEnabled())
         {
            log.trace(new StringBuffer("_put(").append(tx).append(", \"").append(fqn).append("\", ").append(data).append(")"));
  @@ -2236,7 +2233,7 @@
   
         // Find the node. This will lock it (if <tt>locking</tt> is true) and
         // add the temporarily created parent nodes to the TX's node list if tx != null)
  -      n = findNode(fqn);
  +      Node n = findNode(fqn);
         if (n == null)
         {
            String errStr = "node " + fqn + " not found (gtx=" + tx + ", caller=" + Thread.currentThread() + ")";
  @@ -2246,37 +2243,31 @@
            }
            throw new NodeNotExistsException(errStr);
         }
  -      notifier.notifyNodeModified(fqn, true, n.getNodeSPI().getRawData());;
  +      Map rawData = n.getNodeSPI().getRawData();
  +      notifier.notifyNodeModified(fqn, true, rawData);
  +
  +      MethodCall undo_op = null;
   
         // TODO: move creation of undo-operations to separate Interceptor
         // create a compensating method call (reverting the effect of
         // this modification) and put it into the TX's undo list.
         if (tx != null && create_undo_ops)
         {
  -         // TODO even if n is brand new, getData can have empty value instead. Need to fix.
  -         if ((old_data = n.getData()) == null)
  -         {
  -            undo_op = MethodCallFactory.create(MethodDeclarations.removeDataMethodLocal, tx, fqn, false);
  -         }
  -         else
  -         {
  -            undo_op = MethodCallFactory.create(MethodDeclarations.putDataEraseMethodLocal,
  -                    tx, fqn,
  -                    new HashMap(old_data),
  -                    false,
  -                    true); // erase previous hashmap contents
  -         }
  +         // erase previous hashmap contents
  +         undo_op = MethodCallFactory.create(MethodDeclarations.putDataEraseMethodLocal, tx, fqn,
  +               new MapCopy(rawData),
  +               false, true);
         }
   
         n.put(data, erase_contents);
   
  -      if (tx != null && create_undo_ops)
  +      if (undo_op != null)
         {
            // 1. put undo-op in TX' undo-operations list (needed to rollback TX)
            tx_table.addUndoOperation(tx, undo_op);
         }
   
  -      notifier.notifyNodeModified(fqn, false, n.getData() == null ? Collections.emptyMap() : Collections.unmodifiableMap(n.getData()));
  +      notifier.notifyNodeModified(fqn, false, rawData);
      }
   
      /**
  @@ -2448,7 +2439,7 @@
         }
         else
         {
  -         notifier.notifyNodeRemoved(fqn, true, n.getData() == null ? Collections.emptyMap() : Collections.unmodifiableMap(n.getData()));
  +         notifier.notifyNodeRemoved(fqn, true, n.getNodeSPI().getRawData());
         }
   
         parent_node = n.getParent();
  @@ -2604,9 +2595,10 @@
   
         // create a compensating method call (reverting the effect of
         // this modification) and put it into the TX's undo list.
  -      if (tx != null && create_undo_ops && (old_data = n.getData()) != null && !eviction)
  +      if (tx != null && create_undo_ops && !n.getData().isEmpty() && !eviction)
         {
  -         undo_op = MethodCallFactory.create(MethodDeclarations.putDataMethodLocal, tx, fqn, new HashMap(old_data), false);
  +         undo_op = MethodCallFactory.create(MethodDeclarations.putDataMethodLocal, 
  +               tx, fqn, new MapCopy(old_data), false);
         }
   
         if (eviction)
  
  
  



More information about the jboss-cvs-commits mailing list