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

jbosscache-commits at lists.jboss.org jbosscache-commits at lists.jboss.org
Mon Apr 28 11:41:52 EDT 2008


Author: mircea.markus
Date: 2008-04-28 11:41:51 -0400 (Mon, 28 Apr 2008)
New Revision: 5726

Modified:
   core/trunk/src/main/java/org/jboss/cache/DataContainer.java
   core/trunk/src/main/java/org/jboss/cache/commands/write/EvictCommand.java
   core/trunk/src/main/java/org/jboss/cache/eviction/EvictionTimerTask.java
   core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java
   core/trunk/src/main/java/org/jboss/cache/interceptors/CallInterceptor.java
   core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java
   core/trunk/src/test/resources/log4j.xml
Log:
JBCACHE-1222 - fixed eviction

Modified: core/trunk/src/main/java/org/jboss/cache/DataContainer.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/DataContainer.java	2008-04-28 15:02:26 UTC (rev 5725)
+++ core/trunk/src/main/java/org/jboss/cache/DataContainer.java	2008-04-28 15:41:51 UTC (rev 5726)
@@ -455,18 +455,24 @@
       }
    }
 
+   /**
+    * @return true if the FQN is leaf and was removed; false if is an intermediate FQN and only contained data
+    * is droped.
+    */
    public boolean evict(Fqn fqn)
    {
       if (peek(fqn, false, true) == null) return true;
-      if (log.isTraceEnabled())
-         log.trace("evict(" + fqn + ")");
       if (hasChild(fqn))
       {
+         if (log.isTraceEnabled())
+            log.trace("removing DATA as node has children: evict(" + fqn + ")");
          removeData(fqn);
          return false;
       }
       else
       {
+         if (log.isTraceEnabled())
+            log.trace("removing NODE as it is a leaf: evict(" + fqn + ")");
          removeNode(fqn);
          return true;
       }

Modified: core/trunk/src/main/java/org/jboss/cache/commands/write/EvictCommand.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/commands/write/EvictCommand.java	2008-04-28 15:02:26 UTC (rev 5725)
+++ core/trunk/src/main/java/org/jboss/cache/commands/write/EvictCommand.java	2008-04-28 15:41:51 UTC (rev 5726)
@@ -2,6 +2,7 @@
 
 import org.jboss.cache.Fqn;
 import org.jboss.cache.InvocationContext;
+import org.jboss.cache.NodeSPI;
 import org.jboss.cache.commands.Visitor;
 
 import java.util.List;
@@ -24,8 +25,18 @@
       this.fqn = fqn;
    }
 
+   /**
+    * Returns false if the node still exists; i.e. was only data removed because it still has children.
+    * @see org.jboss.cache.interceptors.EvictionInterceptor#handleEvictFqnCommand(org.jboss.cache.InvocationContext, EvictCommand)
+    * there is wehere this attribute is used
+   */
    public Object perform(InvocationContext ctx)
    {
+      NodeSPI node = dataContainer.peek(fqn, false);
+      if (node != null && node.isResident())
+      {
+         return true;
+      }
       if (recursive)
       {
 
@@ -35,19 +46,24 @@
          {
             evictNode(aFqn, ctx);
          }
+         return null;
       }
       else
       {
-         evictNode(fqn, ctx);
+         return evictNode(fqn, ctx);
       }
-      return null;
    }
 
-   void evictNode(Fqn fqn, InvocationContext ctx)
+   boolean evictNode(Fqn fqn, InvocationContext ctx)
    {
       notifier.notifyNodeEvicted(fqn, true, ctx);
-      dataContainer.evict(fqn);
-      notifier.notifyNodeEvicted(fqn, false, ctx);
+      try
+      {
+         return dataContainer.evict(fqn);
+      } finally
+      {
+         notifier.notifyNodeEvicted(fqn, false, ctx);
+      }
    }
 
    public Object acceptVisitor(InvocationContext ctx, Visitor visitor) throws Throwable

Modified: core/trunk/src/main/java/org/jboss/cache/eviction/EvictionTimerTask.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/EvictionTimerTask.java	2008-04-28 15:02:26 UTC (rev 5725)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/EvictionTimerTask.java	2008-04-28 15:41:51 UTC (rev 5726)
@@ -96,11 +96,11 @@
           * This thread will synchronize the set of regions and iterate through every MarshRegion registered w/ the
           * Eviction thread. It also synchronizes on each individual region as it is being processed.
           */
-         @Override
          public void run()
          {
             synchronized (processedRegions)
             {
+               log.trace("***** eviction kicks in");
                for (Region region : processedRegions)
                {
                   final EvictionPolicy policy = region.getEvictionPolicy();
@@ -117,7 +117,7 @@
                      catch (EvictionException e)
                      {
                         log.error("run(): error processing eviction with exception: " + e.toString()
-                              + " will reset the eviction queue list.");
+                                + " will reset the eviction queue list.");
                         region.resetEvictionQueues();
                         log.debug("trace", e);
                      }

Modified: core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java	2008-04-28 15:02:26 UTC (rev 5725)
+++ core/trunk/src/main/java/org/jboss/cache/eviction/LRUAlgorithm.java	2008-04-28 15:41:51 UTC (rev 5726)
@@ -54,6 +54,8 @@
             if (log.isTraceEnabled())
             {
                log.trace("Node " + entry.getFqn() + " should be evicted because of idle time");
+               log.trace("Time to live in millies is: " + (config.getTimeToLiveSeconds() * 1000));
+               log.trace("Config instance is: " + System.identityHashCode(config));
             }
             return true;
          }

Modified: core/trunk/src/main/java/org/jboss/cache/interceptors/CallInterceptor.java
===================================================================
--- core/trunk/src/main/java/org/jboss/cache/interceptors/CallInterceptor.java	2008-04-28 15:02:26 UTC (rev 5725)
+++ core/trunk/src/main/java/org/jboss/cache/interceptors/CallInterceptor.java	2008-04-28 15:41:51 UTC (rev 5726)
@@ -90,7 +90,7 @@
    @Override
    public Object handleDefault(InvocationContext ctx, VisitableCommand command) throws Throwable
    {
-      if (trace) log.trace("Executing command: " + command.getClass().getSimpleName() + ".");
+      if (trace) log.trace("Executing command: " + command + ".");
       return invokeCommand(ctx, command);
    }
 

Modified: core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java
===================================================================
--- core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java	2008-04-28 15:02:26 UTC (rev 5725)
+++ core/trunk/src/test/java/org/jboss/cache/api/ResidentNodesTest.java	2008-04-28 15:41:51 UTC (rev 5726)
@@ -107,6 +107,19 @@
 
    }
 
+   public void simpleTest() throws Exception
+   {
+      cache.put(getSubFqn("/a"), "k_a", "v_a");
+      cache.put(getSubFqn("/b"), "k_b", "v_b");
+      cache.put(getSubFqn("/c"), "k_c", "v_c");
+      cache.put(getSubFqn("/d"), "k_d", "v_d");
+      Thread.sleep(3000);//so that eviction is activated
+      assertFalse(cache.exists(getSubFqn("/a")));
+      assertTrue(cache.exists(getSubFqn("/b")));
+      assertTrue(cache.exists(getSubFqn("/c")));
+      assertTrue(cache.exists(getSubFqn("/d")));
+   }
+
    /**
     * If a node is marked as resident, and a get is made on that given node then an VISITED event would normally be
     * added to the eviction queue. In a LRU scenario, this will cause another node to be evicted given that the size of

Modified: core/trunk/src/test/resources/log4j.xml
===================================================================
--- core/trunk/src/test/resources/log4j.xml	2008-04-28 15:02:26 UTC (rev 5725)
+++ core/trunk/src/test/resources/log4j.xml	2008-04-28 15:41:51 UTC (rev 5726)
@@ -22,7 +22,7 @@
 
    <!-- A time/date based rolling appender -->
    <appender name="FILE" class="org.apache.log4j.DailyRollingFileAppender">
-      <param name="File" value="jbosscache.log"/>
+      <param name="File" value="../za_trunk_jbosscache.log"/>
       <param name="Append" value="false"/>
 
       <!-- Rollover at midnight each day -->




More information about the jbosscache-commits mailing list