[jbosscache-commits] JBoss Cache SVN: r5746 - in core/trunk/src: main/java/org/jboss/cache/commands/write and 2 other directories.

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Tue Apr 29 08:54:33 EDT 2008


Author: manik.surtani at jboss.com
Date: 2008-04-29 08:54:33 -0400 (Tue, 29 Apr 2008)
New Revision: 5746

Modified:
   core/trunk/src/main/java/org/jboss/cache/DataContainer.java
   core/trunk/src/main/java/org/jboss/cache/commands/write/MoveCommand.java
   core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
   core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
   core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java
   core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java
Log:
Fixed recursive evicts with passivation

Modified: core/trunk/src/main/java/org/jboss/cache/DataContainer.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DataContainer.java	2008-04-29 11:35:15 UTC (rev 5745)
+++ core/trunk/src/main/java/org/jboss/cache/DataContainer.java	2008-04-29 12:54:33 UTC (rev 5746)
@@ -280,7 +280,7 @@
       buildNodesForEviction(node, result);
    }
 
-   private void buildNodesForEviction(Node node, List<Fqn> nodes)
+   private void buildNodesForEviction(NodeSPI node, List<Fqn> nodes)
    {
       if (node == null || node.isResident())
       {
@@ -289,7 +289,7 @@
       Fqn fqn = node.getFqn();
       if (fqn.isRoot())
       {
-         for (Object childName : node.getChildrenNames())
+         for (Object childName : node.getChildrenNamesDirect())
          {
             if (!node.isResident()) nodes.add(Fqn.fromRelativeElements(fqn, childName));
          }

Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/MoveCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/MoveCommand.java	2008-04-29 11:35:15 UTC (rev 5745)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/MoveCommand.java	2008-04-29 12:54:33 UTC (rev 5746)
@@ -1,5 +1,7 @@
 package org.jboss.cache.commands.write;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.jboss.cache.Fqn;
 import org.jboss.cache.InvocationContext;
 import org.jboss.cache.NodeNotExistsException;
@@ -17,9 +19,12 @@
  * @author Mircea.Markus at jboss.com
  * @since 2.2
  */
+// TODO: 2.2.0: Make sure this is properly intercepted, i.e., locked and loaded!!
 public class MoveCommand extends AbstractDataCommand implements ReversibleCommand
 {
    public static final int METHOD_ID = 36;
+   private static final Log log = LogFactory.getLog(MoveCommand.class);
+   private static boolean trace;
 
    /* params */
    private Fqn to;
@@ -30,6 +35,7 @@
    public void injectNotifier(Notifier notifier)
    {
       this.notifier = notifier;
+      trace = log.isTraceEnabled();
    }
 
    public MoveCommand()
@@ -92,6 +98,8 @@
          throw new NodeNotExistsException("Node " + nodeToMoveFqn + " does not exist when attempting to move node!!");
       }
 
+      if (trace) log.trace("Moving " + fqn + " to sit under " + to);
+
       NodeSPI oldParent = node.getParent();
       Object nodeName = nodeToMoveFqn.getLastElement();
 
@@ -162,7 +170,7 @@
    {
       return "MoveCommand{" +
             "fqn=" + fqn +
-            "to=" + to +
+            ", to=" + to +
             '}';
    }
 }

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java	2008-04-29 11:35:15 UTC (rev 5745)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/ActivationInterceptor.java	2008-04-29 12:54:33 UTC (rev 5746)
@@ -11,6 +11,7 @@
 import org.jboss.cache.commands.read.GetNodeCommand;
 import org.jboss.cache.commands.tx.OptimisticPrepareCommand;
 import org.jboss.cache.commands.tx.PrepareCommand;
+import org.jboss.cache.commands.write.MoveCommand;
 import org.jboss.cache.commands.write.PutDataMapCommand;
 import org.jboss.cache.commands.write.PutKeyValueCommand;
 import org.jboss.cache.commands.write.RemoveDataCommand;
@@ -146,6 +147,19 @@
       return returnValue;
    }
 
+   @Override
+   public Object visitMoveCommand(InvocationContext ctx, MoveCommand command) throws Throwable
+   {
+      Object returnValue = super.visitMoveCommand(ctx, command);
+      if (trace)
+         log.trace("This is a move operation; removing the FROM node from the loader, no activation processing needed.");
+      loader.remove(command.getFqn());
+      removeNodeFromCacheLoader(ctx, command.getFqn().getParent());
+      removeNodeFromCacheLoader(ctx, command.getTo());
+      return returnValue;
+   }
+
+
    /**
     * Remove the node from the cache loader if it exists in memory,
     * its attributes have been initialized, its children have been loaded,

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java	2008-04-29 11:35:15 UTC (rev 5745)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CacheLoaderInterceptor.java	2008-04-29 12:54:33 UTC (rev 5746)
@@ -240,7 +240,7 @@
    {
       NodeSPI n = dataContainer.peek(fqn, true, true);
 
-      boolean mustLoad = mustLoad(n, key, allKeys);
+      boolean mustLoad = mustLoad(n, key, allKeys || isMove);
       if (trace)
       {
          log.trace("load element " + fqn + " mustLoad=" + mustLoad);

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java	2008-04-29 11:35:15 UTC (rev 5745)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/PassivationInterceptor.java	2008-04-29 12:54:33 UTC (rev 5746)
@@ -14,6 +14,7 @@
 
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import java.util.concurrent.atomic.AtomicLong;
 
@@ -49,9 +50,29 @@
     * store using the CacheLoader.
     */
    @Override
-   public Object visitEvictFqnCommand(InvocationContext ctx, EvictCommand evictFqnCommand) throws Throwable
+   public Object visitEvictFqnCommand(InvocationContext ctx, EvictCommand command) throws Throwable
    {
-      Fqn fqn = evictFqnCommand.getFqn();
+      if (command.isRecursive())
+      {
+         List<Fqn> fqnsToEvict = dataContainer.getNodesForEviction(command.getFqn(), true);
+         if (fqnsToEvict != null)
+         {
+            for (Fqn f : fqnsToEvict)
+            {
+               passivate(ctx, f);
+            }
+         }
+      }
+      else
+      {
+         passivate(ctx, command.getFqn());
+      }
+
+      return invokeNextInterceptor(ctx, command);
+   }
+
+   private void passivate(InvocationContext ctx, Fqn fqn) throws Throwable
+   {
       try
       {
          // evict method local doesn't hold attributes therefore we have
@@ -59,6 +80,7 @@
          Map attributes = getNodeAttributes(ctx, fqn);
          // notify listeners that this node is about to be passivated
          notifier.notifyNodePassivated(fqn, true, attributes, ctx);
+         if (trace) log.trace("Passivating " + fqn);
          loader.put(fqn, attributes);
          notifier.notifyNodePassivated(fqn, false, Collections.emptyMap(), ctx);
          if (getStatisticsEnabled() && configuration.getExposeManagementStatistics())
@@ -73,10 +95,8 @@
             log.trace("Node " + fqn + " not loaded in memory; passivation skipped");
          }
       }
-      return invokeNextInterceptor(ctx, evictFqnCommand);
    }
 
-
    public long getPassivations()
    {
       return passivations.get();

Modified: core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java	2008-04-29 11:35:15 UTC (rev 5745)
+++ core/trunk/src/test/java/org/jboss/cache/api/NodeMoveAPITest.java	2008-04-29 12:54:33 UTC (rev 5746)
@@ -312,12 +312,7 @@
       nodeD.put(k, vD);
       nodeE = nodeD.addChild(E);
       nodeE.put(k, vE);
-      cache.evict(Fqn.ROOT);
-      cache.evict(A);
-      cache.evict(B);
-      cache.evict(C);
-      cache.evict(D);
-      cache.evict(E);
+      cache.evict(Fqn.ROOT, true);
 
       // move
       if (useTx) tm.begin();
@@ -352,15 +347,7 @@
       assertEquals(nodeD, nodeE.getParent());
 
 
-      if (pasv)
-      {
-         cache.evict(Fqn.ROOT);
-         cache.evict(nodeA.getFqn());
-         cache.evict(nodeB.getFqn());
-         cache.evict(nodeC.getFqn());
-         cache.evict(nodeD.getFqn());
-         cache.evict(nodeE.getFqn());
-      }
+      if (pasv) cache.evict(Fqn.ROOT, true);
 
       //now inspect the loader.
       assertEquals(vA, loader.get(nodeA.getFqn()).get(k));




More information about the jbosscache-commits mailing list