[jboss-user] [JBossCache] - Re: ExpirationAlgorithm (2.0.0.CR1) doesn't work with expiry

genman do-not-reply at jboss.com
Wed May 9 04:05:26 EDT 2007


The most elegant solution I could come up with is to never delete the ExpirationEntry, but double-check the node's current expiration value before eviction. The solution looks like this:


  | Index: src/org/jboss/cache/eviction/ExpirationAlgorithm.java
  | ===================================================================
  | RCS file: /cvsroot/jboss/JBossCache/src/org/jboss/cache/eviction/ExpirationAlgorithm.java,v
  | retrieving revision 1.9
  | diff -u -r1.9 ExpirationAlgorithm.java
  | --- src/org/jboss/cache/eviction/ExpirationAlgorithm.java	7 Feb 2007 22:06:56 -0000	1.9
  | +++ src/org/jboss/cache/eviction/ExpirationAlgorithm.java	9 May 2007 08:04:08 -0000
  | @@ -92,21 +92,19 @@
  |  
  |     private void setExpiration(Fqn fqn, Long l)
  |     {
  | -      boolean found = set.remove(new ExpirationEntry(fqn));
  | -      if (found && log.isTraceEnabled())
  | -         log.trace("removed old expiration for " + fqn);
  |        ExpirationEntry ee = new ExpirationEntry(fqn, l);
  |        if (log.isTraceEnabled())
  |           log.trace("adding eviction entry: " + ee);
  |        set.add(ee);
  |     }
  |  
  | +   @SuppressWarnings("unchecked")
  |     private Long getExpiration(Fqn fqn)
  |     {
  | -      NodeSPI n = policy.getCache().peek(fqn, false);
  | +      NodeSPI<String, Long> n = policy.getCache().peek(fqn, false);
  |        if (n == null)
  |           return null;
  | -      return (Long)n.getDirect(config.getExpirationKeyName());
  | +      return n.getDirect(config.getExpirationKeyName());
  |     }
  |  
  |     @Override
  | @@ -126,7 +124,8 @@
  |              case REMOVE_ELEMENT_EVENT:
  |              case REMOVE_NODE_EVENT:
  |              case UNMARK_USE_EVENT:
  | -               removeEvictionEntry(node);
  | +               // Removals will be noticed when double-checking expiry time
  | +               // removeEvictionEntry(node);
  |                 break;
  |              case VISIT_NODE_EVENT:
  |                 // unused
  | @@ -161,6 +160,13 @@
  |        for (Iterator<ExpirationEntry> i = set.iterator(); i.hasNext();)
  |        {
  |           ExpirationEntry ee = i.next();
  | +         Long ce = getExpiration(ee.getFqn());
  | +         if (ce == null || ce > ee.getExpiration())
  | +         {
  | +        	 // Expiration now older
  | +        	 i.remove();
  | +        	 continue;
  | +         }
  |           if (ee.getExpiration() < now || (max != 0 && set.size() > max))
  |           {
  |              i.remove();
  | @@ -177,13 +183,6 @@
  |                   "Set expiration for nodes in this region");
  |     }
  |  
  | -   private void removeEvictionEntry(EvictedEventNode node)
  | -   {
  | -      Fqn fqn = node.getFqn();
  | -      if (getExpiration(fqn) == null)
  | -         set.remove(new ExpirationEntry(fqn));
  | -   }
  | -
  |     @Override
  |     public void resetEvictionQueue(Region region)
  |     {
  | @@ -230,12 +229,10 @@
  |        }
  |  
  |        /**
  | -       * Returns true if the FQN are the same, else compares expiration, then FQN order.
  | +       * Compares expiration, then FQN order.
  |         */
  |        public int compareTo(ExpirationEntry ee)
  |        {
  | -         if (fqn.equals(ee.fqn))
  | -            return 0;
  |           long n = expiration - ee.expiration;
  |           if (n < 0)
  |              return -1;
  | @@ -265,12 +262,12 @@
  |           if (!(o instanceof ExpirationEntry))
  |              return false;
  |           ExpirationEntry ee = (ExpirationEntry) o;
  | -         return fqn.equals(ee.fqn);
  | +         return expiration == ee.expiration && fqn.equals(ee.fqn);
  |        }
  |  
  |        public int hashCode()
  |        {
  | -         return fqn.hashCode();
  | +         return (int)expiration ^ fqn.hashCode();
  |        }
  |  
  |        public String toString()
  | 
  | 

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4044182#4044182

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=4044182



More information about the jboss-user mailing list