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

Manik Surtani msurtani at jboss.com
Mon Nov 13 09:20:32 EST 2006


  User: msurtani
  Date: 06/11/13 09:20:32

  Modified:    src/org/jboss/cache/interceptors      TxInterceptor.java
                        CacheStoreInterceptor.java
                        OptimisticValidatorInterceptor.java
                        OptimisticReplicationInterceptor.java
                        OptimisticNodeInterceptor.java
  Log:
  Fixed test suite failures
  
  Revision  Changes    Path
  1.65      +46 -19    JBossCache/src/org/jboss/cache/interceptors/TxInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: TxInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/TxInterceptor.java,v
  retrieving revision 1.64
  retrieving revision 1.65
  diff -u -b -r1.64 -r1.65
  --- TxInterceptor.java	11 Nov 2006 19:55:19 -0000	1.64
  +++ TxInterceptor.java	13 Nov 2006 14:20:32 -0000	1.65
  @@ -97,8 +97,10 @@
                        result = handleRemotePrepare(m, ctx.getGlobalTransaction());
                        scrubTxsOnExit = true;
                        if (configuration.getExposeManagementStatistics() && getStatisticsEnabled())
  +                     {
                           m_prepares++;
                     }
  +                  }
                     else
                     {
                        if (log.isTraceEnabled()) log.trace("received my own message (discarding it)");
  @@ -192,7 +194,7 @@
            if (ltx == null)
            {
               if (currentTx != null) txManager.suspend();
  -            ltx = createLocalTxForGlobalTx(gtx); // creates new LTX and associates it with a GTX
  +            ltx = createLocalTxForGlobalTx(gtx);// creates new LTX and associates it with a GTX
               if (log.isDebugEnabled())
               {
                  log.debug("(" + cache.getLocalAddress() + "): started new local TX as result of remote PREPARE: local TX=" + ltx + ", global TX=" + gtx);
  @@ -235,13 +237,17 @@
            registerHandler(ltx, new RemoteSynchronizationHandler(gtx, ltx, cache));
   
            if (configuration.isNodeLockingOptimistic())
  +         {
               retval = handleOptimisticPrepare(m, gtx, modifications, onePhase, ltx);
  +         }
            else
  +         {
               retval = handlePessimisticPrepare(m, gtx, modifications, onePhase, ltx);
         }
  +      }
         finally
         {
  -         txManager.suspend(); // suspends ltx - could be null
  +         txManager.suspend();// suspends ltx - could be null
            // resume whatever else we had going.
            if (currentTx != null) txManager.resume(currentTx);
            if (log.isDebugEnabled()) log.debug("Finished remote prepare " + gtx);
  @@ -315,7 +321,9 @@
      private MethodCall attachGlobalTransaction(Transaction tx, MethodCall m) throws Exception
      {
         if (log.isDebugEnabled())
  +      {
            log.debug(" local transaction exists - registering global tx if not present for " + Thread.currentThread());
  +      }
         if (log.isTraceEnabled())
         {
            GlobalTransaction tempGtx = txTable.get(tx);
  @@ -418,9 +426,15 @@
            {
               try
               {
  -//                    invokeOnePhaseCommitMethod(gtx, modifications.size() > 0, success);
  -               if (success) ltx.commit();
  -               else ltx.rollback();
  +               //                    invokeOnePhaseCommitMethod(gtx, modifications.size() > 0, success);
  +               if (success)
  +               {
  +                  ltx.commit();
  +               }
  +               else
  +               {
  +                  ltx.rollback();
  +               }
               }
               catch (Throwable t)
               {
  @@ -442,8 +456,8 @@
               }
               finally
               {
  -               transactions.remove(ltx);        // JBAS-298
  -               remoteTransactions.remove(gtx); // JBAS-308
  +               transactions.remove(ltx);// JBAS-298
  +               remoteTransactions.remove(gtx);// JBAS-308
               }
            }
         }
  @@ -460,10 +474,12 @@
            {
               try
               {
  -               if (injectDataVersions)
  +               if (injectDataVersions && !MethodDeclarations.isDataGravitationMethod(modification.getMethodId()))
                  {
                     Object[] origArgs = modification.getArgs();
  -                  injectDataVersion((DataVersion) origArgs[origArgs.length - 1]);
  +                  // there may be instances (e.g., data gravitation calls) where a data version is not passed in or not even relevant.
  +                  // make sure we are aware of this.
  +                  injectDataVersion(origArgs[origArgs.length - 1]);
                     // modify the call to the non-dataversioned counterpart since we've popped out the data version
                     Object[] args = new Object[origArgs.length - 1];
                     System.arraycopy(origArgs, 0, args, 0, args.length);
  @@ -499,12 +515,19 @@
         return retval;
      }
   
  -   public void injectDataVersion(DataVersion v)
  +   public void injectDataVersion(Object obj)
  +   {
  +      if (obj instanceof DataVersion)
      {
         Option o = new Option();
  -      o.setDataVersion(v);
  +         o.setDataVersion((DataVersion) obj);
         cache.getInvocationContext().setOptionOverrides(o);
      }
  +      else
  +      {
  +         log.debug("Object " + obj + " is not a DataVersion, not applying to this mod.");
  +      }
  +   }
   
      /**
       * Handles a commit or a rollback for a remote gtx.  Called by invoke().
  @@ -555,15 +578,19 @@
            {
               txManager.commit();
               if (configuration.getExposeManagementStatistics() && getStatisticsEnabled())
  +            {
                  m_commits++;
            }
  +         }
            else
            {
               txManager.rollback();
               if (configuration.getExposeManagementStatistics() && getStatisticsEnabled())
  +            {
                  m_rollbacks++;
            }
         }
  +      }
         finally
         {
            //resume the old transaction if we suspended it
  @@ -624,7 +651,7 @@
         // callled before
         //Transaction ltx = getLocalTxForGlobalTx(gtx);
   
  -//        Transaction currentTx = txManager.getTransaction();
  +      //        Transaction currentTx = txManager.getTransaction();
   
         //if (!ltx.equals(currentTx)) throw new IllegalStateException(" local transaction " + ltx + " transaction does not match running tx " + currentTx);
   
  @@ -708,7 +735,7 @@
         {
            cache.getInvocationContext().setTxHasMods(modifications != null && modifications.size() > 0);
            // JBCACHE-457
  -//            MethodCall rollbackMethod = MethodCall(TreeCache.rollbackMethod, new Object[]{gtx, hasMods ? true : false});
  +         //            MethodCall rollbackMethod = MethodCall(TreeCache.rollbackMethod, new Object[]{gtx, hasMods ? true : false});
            MethodCall rollbackMethod = MethodCallFactory.create(MethodDeclarations.rollbackMethod, gtx);
            if (log.isTraceEnabled()) {log.trace(" running rollback for " + gtx);}
   
  @@ -741,8 +768,8 @@
         // TODO: Manik: one phase commit for opt locking too if using repl-async?
         // build the method call
         MethodCall prepareMethod;
  -//        if (cache.getCacheModeInternal() != TreeCache.REPL_ASYNC)
  -//        {
  +      //        if (cache.getCacheModeInternal() != TreeCache.REPL_ASYNC)
  +      //        {
         // running a 2-phase commit.
         if (configuration.isNodeLockingOptimistic())
         {
  @@ -752,7 +779,7 @@
         {
            prepareMethod = MethodCallFactory.create(MethodDeclarations.prepareMethod,
                    gtx, modifications, (Address) cache.getLocalAddress(),
  -                 false); // don't commit or rollback - wait for call
  +                 false);// don't commit or rollback - wait for call
         }
         //}
         else
  @@ -838,7 +865,7 @@
   
         if (log.isTraceEnabled()) log.trace("registering for TX completion: SynchronizationHandler(" + handler + ")");
   
  -      orderedHandler.registerAtHead(handler); // needs to be invoked first on TX commit
  +      orderedHandler.registerAtHead(handler);// needs to be invoked first on TX commit
      }
   
      /**
  
  
  
  1.37      +21 -21    JBossCache/src/org/jboss/cache/interceptors/CacheStoreInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: CacheStoreInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/CacheStoreInterceptor.java,v
  retrieving revision 1.36
  retrieving revision 1.37
  diff -u -b -r1.36 -r1.37
  --- CacheStoreInterceptor.java	10 Nov 2006 02:48:46 -0000	1.36
  +++ CacheStoreInterceptor.java	13 Nov 2006 14:20:32 -0000	1.37
  @@ -26,7 +26,7 @@
    * through the CacheLoader, either after each method call (no TXs), or at TX commit.
    *
    * @author Bela Ban
  - * @version $Id: CacheStoreInterceptor.java,v 1.36 2006/11/10 02:48:46 bstansberry Exp $
  + * @version $Id: CacheStoreInterceptor.java,v 1.37 2006/11/13 14:20:32 msurtani Exp $
    */
   public class CacheStoreInterceptor extends BaseCacheLoaderInterceptor implements CacheStoreInterceptorMBean
   {
  @@ -150,7 +150,7 @@
   
         // remove() methods need to be applied to the CacheLoader before passing up the call: a listener might
         // access an element just removed, causing the CacheLoader to *load* the element before *removing* it.
  -//      synchronized(this) {
  +      //      synchronized(this) {
         switch (m.getMethodId())
         {
            case MethodDeclarations.removeNodeMethodLocal_id:
  @@ -192,12 +192,12 @@
               }
               break;
         }
  -//      }
  +      //      }
   
         retval = super.invoke(m);
   
         // put() methods need to be applied *after* the call
  -//      synchronized(this) {
  +      //      synchronized(this) {
         switch (m.getMethodId())
         {
            case MethodDeclarations.moveMethodLocal_id:
  @@ -242,7 +242,7 @@
               }
               break;
         }
  -//      }
  +      //      }
   
         if (use_tmp_retval)
         {
  @@ -259,7 +259,7 @@
         Fqn newNodeFqn = new Fqn(parent, node.getLast());
         //NodeImpl n = (NodeImpl) ((TreeCacheProxyImpl) cache).peek(newNodeFqn);
         //recursiveMove(n);
  -//      throw new RuntimeException("Implement me!");
  +      //      throw new RuntimeException("Implement me!");
   
         recursiveMove(node, newNodeFqn);
         try
  @@ -395,36 +395,36 @@
            case MethodDeclarations.putDataMethodLocal_id:
               mod = new Modification(Modification.ModificationType.PUT_DATA,
                       (Fqn) args[1],      // fqn
  -                    (Map) args[2]);     // data
  +                    (Map) args[2]);// data
               break;
            case MethodDeclarations.putDataEraseMethodLocal_id:
               mod = new Modification(Modification.ModificationType.PUT_DATA_ERASE,
                       (Fqn) args[1],      // fqn
  -                    (Map) args[2]);     // data
  +                    (Map) args[2]);// data
               break;
            case MethodDeclarations.putKeyValMethodLocal_id:
               mod = new Modification(Modification.ModificationType.PUT_KEY_VALUE,
                       (Fqn) args[1],      // fqn
                       args[2],           // key
  -                    args[3]);          // value
  +                    args[3]);// value
               break;
            case MethodDeclarations.removeNodeMethodLocal_id:
               mod = new Modification(Modification.ModificationType.REMOVE_NODE,
  -                    (Fqn) args[1]);     // fqn
  +                    (Fqn) args[1]);// fqn
               break;
            case MethodDeclarations.removeKeyMethodLocal_id:
               mod = new Modification(Modification.ModificationType.REMOVE_KEY_VALUE,
                       (Fqn) args[1],      // fqn
  -                    args[2]);          // key
  +                    args[2]);// key
               break;
            case MethodDeclarations.removeDataMethodLocal_id:
               mod = new Modification(Modification.ModificationType.REMOVE_DATA,
  -                    (Fqn) args[1]);     // fqn
  +                    (Fqn) args[1]);// fqn
               break;
            case MethodDeclarations.moveMethodLocal_id:
               mod = new Modification(Modification.ModificationType.MOVE, (Fqn) args[0], (Fqn) args[1]);
               break;
  -         default :
  +         default:
               throw new CacheException("method call " + method.getName() + " cannot be converted to a modification");
         }
   
  
  
  
  1.39      +9 -2      JBossCache/src/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: OptimisticValidatorInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/OptimisticValidatorInterceptor.java,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -b -r1.38 -r1.39
  --- OptimisticValidatorInterceptor.java	11 Nov 2006 19:55:19 -0000	1.38
  +++ OptimisticValidatorInterceptor.java	13 Nov 2006 14:20:32 -0000	1.39
  @@ -105,7 +105,7 @@
      }
   
      private void simpleValidate(Collection nodes)
  -           throws CacheException
  +           throws DataVersioningException
      {
         WorkspaceNode workspaceNode;
   
  @@ -131,7 +131,12 @@
            // if not, we have a problem...
            if (realNode == null && !workspaceNode.isCreated())
            {
  -            throw new CacheException("Real node for " + fqn + " is null, and this wasn't newly created in this tx!");
  +            throw new DataVersioningException("Real node for " + fqn + " is null, and this wasn't newly created in this tx!");
  +         }
  +
  +         if (realNode != null && workspaceNode.isCreated())
  +         {
  +            throw new DataVersioningException("Tx attempted to create " + fqn + " anew.  It has already been created since this tx started by another (possibly remote) tx.");
            }
   
            if (!workspaceNode.isCreated())
  @@ -259,8 +264,10 @@
         if (map2 == null)
         {
            if (map1.isEmpty())
  +         {
               return true;
         }
  +      }
         return map1.equals(map2);
      }
   
  
  
  
  1.29      +35 -21    JBossCache/src/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: OptimisticReplicationInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/OptimisticReplicationInterceptor.java,v
  retrieving revision 1.28
  retrieving revision 1.29
  diff -u -b -r1.28 -r1.29
  --- OptimisticReplicationInterceptor.java	11 Nov 2006 19:55:19 -0000	1.28
  +++ OptimisticReplicationInterceptor.java	13 Nov 2006 14:20:32 -0000	1.29
  @@ -166,18 +166,24 @@
   
            //record the things we have possibly sent
            broadcastTxs.put(gtx, gtx);
  -         if (log.isDebugEnabled()) log.debug("(" + cache.getLocalAddress()
  +         if (log.isDebugEnabled())
  +         {
  +            log.debug("(" + cache.getLocalAddress()
                    + "): broadcasting prepare for " + gtx
                    + " (" + num_mods + " modifications");
  +         }
   
            replicateCall(toBroadcast, remoteCallSync);
         }
         else
         {
            //no members, ignoring
  -         if (log.isDebugEnabled()) log.debug("(" + cache.getLocalAddress()
  +         if (log.isDebugEnabled())
  +         {
  +            log.debug("(" + cache.getLocalAddress()
                    + "):not broadcasting prepare as members are " + cache.getMembers());
         }
  +      }
         return null;
      }
   
  @@ -253,6 +259,13 @@
         while (origCalls.hasNext())
         {
            MethodCall origCall = (MethodCall) origCalls.next();
  +         if (MethodDeclarations.isDataGravitationMethod(origCall.getMethodId()))
  +         {
  +            // no need to translate data gravitation calls.
  +            newList.add(origCall);
  +         }
  +         else
  +         {
            Object[] origArgs = origCall.getArgs();
            // get the data version associated with this orig call.
   
  @@ -273,6 +286,7 @@
            // and add it to the new list.
            newList.add(newCall);
         }
  +      }
         return newList;
      }
   
  
  
  
  1.32      +10 -7     JBossCache/src/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: OptimisticNodeInterceptor.java
  ===================================================================
  RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/interceptors/OptimisticNodeInterceptor.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -b -r1.31 -r1.32
  --- OptimisticNodeInterceptor.java	10 Nov 2006 20:32:51 -0000	1.31
  +++ OptimisticNodeInterceptor.java	13 Nov 2006 14:20:32 -0000	1.32
  @@ -91,13 +91,16 @@
               workspace.setVersioningImplicit(false);
               DataVersion version = ctx.getOptionOverrides().getDataVersion();
               // "fail-more-silently" patch thanks to Owen Taylor - JBCACHE-767
  +
  +            // also, if this is a "remove", do we care if the node didn't exist?
  +
               if (workspaceNode != null)
               {
                  workspaceNode.setVersion(version);
               }
               else
               {
  -               if (ctx.getOptionOverrides() == null || !ctx.getOptionOverrides().isFailSilently())
  +               if ((ctx.getOptionOverrides() == null || !ctx.getOptionOverrides().isFailSilently()) && MethodDeclarations.isPutMethod(m.getMethodId()))
                  {
                     throw new CacheException("Unable to set node version for " + getFqn(args) + ", node is null.");
                  }
  @@ -183,8 +186,8 @@
         // now that we have the parent and target nodes:
         // first correct the pointers at the pruning point
         oldParent.removeChild(nodeName);
  -//      parent.addChild(nodeName, node);
  -//      parent.createChild(nodeName, nodeFqn, parent.getNode(), ((TreeCacheProxyImpl)cache).treeCache, null);
  +      //      parent.addChild(nodeName, node);
  +      //      parent.createChild(nodeName, nodeFqn, parent.getNode(), ((TreeCacheProxyImpl)cache).treeCache, null);
   
         // parent pointer is calculated on the fly using Fqns.
   
  @@ -210,7 +213,7 @@
         // process children
         for (Object n : node.getChildrenNames())
         {
  -//         movedNode.createChild(n, new Fqn(node.getFqn(), n), movedNode.getNode(), ((TreeCacheProxyImpl)cache).treeCache, null);
  +         //         movedNode.createChild(n, new Fqn(node.getFqn(), n), movedNode.getNode(), ((TreeCacheProxyImpl)cache).treeCache, null);
            WorkspaceNode child = getOrCreateWorkspaceNode(new Fqn(node.getFqn(), n), ws);
            moveFqns(child, newFqn, ws);
            //movedNode.addChild(n, child);
  @@ -308,7 +311,7 @@
         Fqn nodeFqn = workspaceNode.getFqn();
   
         // Mark this node and all children as deleted
  -      workspace.addNode(workspaceNode); // deleted below
  +      workspace.addNode(workspaceNode);// deleted below
         SortedMap tailMap = workspace.getNodesAfter(workspaceNode.getFqn());
   
         for (Iterator it = tailMap.entrySet().iterator(); it.hasNext();)
  @@ -321,7 +324,7 @@
            }
            else
            {
  -            break; // no more children, we came to the end
  +            break;// no more children, we came to the end
            }
         }
      }
  @@ -433,7 +436,7 @@
            DataNode node = ((TreeCacheProxyImpl) cache).peek(fqn);
            if (node == null)
            {
  -            return null; // seems to happen quite a bit
  +            return null;// seems to happen quite a bit
            }
            workspaceNode = NodeFactory.getInstance().createWorkspaceNode(node, workspace);
            workspace.addNode(workspaceNode);
  
  
  



More information about the jboss-cvs-commits mailing list