jcs-dev@jakarta.apache.org
[Top] [All Lists]

cvs commit: jakarta-turbine-jcs/src/java/org/apache/jcs/engine/memory Ab

Subject: cvs commit: jakarta-turbine-jcs/src/java/org/apache/jcs/engine/memory AbstractMemoryCache.java
From:
Date: 11 Jun 2005 00:35:27 -0000
asmuts      2005/06/10 17:35:27

  Modified:    src/java/org/apache/jcs/auxiliary/disk
                        AbstractDiskCacheAttributes.java
                        AbstractDiskCache.java
               src/java/org/apache/jcs/engine/behavior
                        ICacheEventQueue.java
               src/java/org/apache/jcs/auxiliary/disk/behavior
                        IDiskCacheAttributes.java
               src/java/org/apache/jcs/auxiliary/disk/indexed
                        IndexedDiskCacheAttributes.java
               src/java/org/apache/jcs/engine/control CompositeCache.java
               src/java/org/apache/jcs/auxiliary/disk/jisp
                        JISPCacheAttributes.java
               src/java/org/apache/jcs/engine/memory
                        AbstractMemoryCache.java
  Log:
  Working on disk cache shutdown bug.  Items in memory were not making it to 
disk.
  The disk cache was killing the event queue and then optimizing the file and 
storing the keys.
  
  I changed it so the disk cache will wait a configuratble number of seconds 
for the event queue to
  empty out before shutting down.  (we still need a way to make the event queue 
stop accepting input during this process.)
  There is a new disk cache config param
  jcs.auxiliary.DC.attributes.ShutdownSpoolTimeLimit=60
  The default is 60 seconds.  This is a per region setting.  It will wait this 
long for each region if it takes that long.
  
   . . .I want to add a setting for disk duplication of memory, so that all 
memory items will be backed on disk.
  
  Revision  Changes    Path
  1.4       +21 -0     
jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCacheAttributes.java
  
  Index: AbstractDiskCacheAttributes.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCacheAttributes.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- AbstractDiskCacheAttributes.java  4 Jun 2005 02:01:56 -0000       1.3
  +++ AbstractDiskCacheAttributes.java  11 Jun 2005 00:35:27 -0000      1.4
  @@ -37,6 +37,11 @@
       /** default to 5000 */
       protected int maxPurgatorySize = MAX_PURGATORY_SIZE_DEFUALT;
   
  +    private static final int DEFAULT_shutdownSpoolTimeLimit = 60;
  +    
  +    protected int shutdownSpoolTimeLimit = DEFAULT_shutdownSpoolTimeLimit;
  +        
  +    
       /*
        * (non-Javadoc)
        * 
  @@ -77,6 +82,22 @@
           this.maxPurgatorySize = maxPurgatorySize;
       }
   
  +    /* (non-Javadoc)
  +     * @see 
org.apache.jcs.auxiliary.disk.behavior.IDiskCacheAttributes#getShutdownSpoolTimeLimit()
  +     */
  +    public int getShutdownSpoolTimeLimit()
  +    {
  +        return this.shutdownSpoolTimeLimit;
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.jcs.auxiliary.disk.behavior.IDiskCacheAttributes#setShutdownSpoolTimeLimit(int)
  +     */
  +    public void setShutdownSpoolTimeLimit( int shutdownSpoolTimeLimit )
  +    {
  +        this.shutdownSpoolTimeLimit = shutdownSpoolTimeLimit;
  +    }     
  +    
       /**
        * Description of the Method
        * 
  
  
  
  1.32      +52 -2     
jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java
  
  Index: AbstractDiskCache.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/AbstractDiskCache.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- AbstractDiskCache.java    4 Jun 2005 02:01:56 -0000       1.31
  +++ AbstractDiskCache.java    11 Jun 2005 00:35:27 -0000      1.32
  @@ -328,14 +328,64 @@
   
       /**
        * Adds a dispose request to the disk cache.
  +     * <p>
  +     * Disposal proceeds in several steps. 
  +     * <ul>
  +     * <li> 1.  Prior to this call the Composite cache dumped the memory
  +     * into the disk cache.  If it is large then we need to wait for
  +     * the event queue to finish.
  +     * <li> 2.  Wait until the event queue is empty of until the configured 
ShutdownSpoolTimeLimit
  +     * is reached.
  +     * <li> 3.  Call doDispose on the concrete impl.   
  +     * </ul>
  +     * 
        */
       public final void dispose()
       {
   
  +        Runnable disR = new Runnable()
  +        {
  +            public void run()
  +            {
  +                boolean keepGoing = true;
  +                long total = 0;
  +                long interval = 100;
  +                while ( keepGoing )
  +                {
  +                    keepGoing = !cacheEventQueue.isEmpty();
  +                    try
  +                    {
  +                        Thread.sleep( interval );
  +                        total += interval;                        
  +                        //log.info( "total = " + total );
  +                    }
  +                    catch ( InterruptedException e )
  +                    {
  +                        break;
  +                    }
  +                }
  +                log.info( "No longer waiting for event queue to finish: " + 
cacheEventQueue.getStatistics() );
  +            }
  +        };
  +        Thread t = new Thread( disR );
  +        t.start();
  +        // wait up to 60 seconds for dispose and then quit if not done.
  +        try
  +        {
  +            t.join( this.dcattr.getShutdownSpoolTimeLimit() * 1000 );
  +        }
  +        catch ( InterruptedException ex )
  +        {
  +            log.error( ex );
  +        }
  +        
  +        log.info( "In dispose, destroying event queue." );
           // This stops the processor thread.
           cacheEventQueue.destroy();
  -
  +        
  +        
           // Invoke any implementation specific disposal code
  +        // need to handle the disposal first.
           doDispose();
   
           alive = false;
  
  
  
  1.10      +7 -0      
jakarta-turbine-jcs/src/java/org/apache/jcs/engine/behavior/ICacheEventQueue.java
  
  Index: ICacheEventQueue.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/engine/behavior/ICacheEventQueue.java,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- ICacheEventQueue.java     4 Jun 2005 02:01:56 -0000       1.9
  +++ ICacheEventQueue.java     11 Jun 2005 00:35:27 -0000      1.10
  @@ -106,6 +106,13 @@
       public boolean isWorking();
   
       /**
  +     * Are there elements in the queue.
  +     * 
  +     * @return true if there are stil elements.
  +     */
  +    public boolean isEmpty();
  +    
  +    /**
        * Returns the historical and statistical data for an event queue cache.
        * 
        * @return
  
  
  
  1.3       +20 -0     
jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/behavior/IDiskCacheAttributes.java
  
  Index: IDiskCacheAttributes.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/behavior/IDiskCacheAttributes.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- IDiskCacheAttributes.java 4 Jun 2005 02:01:57 -0000       1.2
  +++ IDiskCacheAttributes.java 11 Jun 2005 00:35:27 -0000      1.3
  @@ -58,5 +58,25 @@
        */
       public void setMaxPurgatorySize( int maxPurgatorySize );
   
  +    /**
  +     * Get the amount of time in seconds we will wait for elements to
  +     * move to disk during shutdown for a particular region.
  +     *  
  +     * @return the time in seconds.
  +     */
  +    public int getShutdownSpoolTimeLimit();
  +    
  +    /**
  +     * Sets the amount of time in seconds we will wait for elements to
  +     * move to disk during shutdown for a particular region.
  +     * <p>
  +     * This is how long we give the event queue to empty.
  +     * <p>
  +     * The default is 60 seconds.
  +     * 
  +     * @param shutdownSpoolTimeLimit the time in seconds
  +     */
  +    public void setShutdownSpoolTimeLimit( int shutdownSpoolTimeLimit ); 
  +    
   }
   //   end interface
  
  
  
  1.16      +9 -7      
jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheAttributes.java
  
  Index: IndexedDiskCacheAttributes.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/indexed/IndexedDiskCacheAttributes.java,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- IndexedDiskCacheAttributes.java   4 Jun 2005 02:01:55 -0000       1.15
  +++ IndexedDiskCacheAttributes.java   11 Jun 2005 00:35:27 -0000      1.16
  @@ -29,11 +29,12 @@
   
       private static final int DEFAULT_maxKeySize = 5000;
   
  -    private static final int DEFAULT_maxRecycleBinSize = 5000;
  -
  -    /** -1 mean no limit. */
  +    /** -1 means no limit. */
       private int maxKeySize = DEFAULT_maxKeySize;
  +    
   
  +    private static final int DEFAULT_maxRecycleBinSize = 5000;
  +    
       /**
        * Cannot be larger than the max size. If max is less than 0, this will 
be
        * 5000
  @@ -42,7 +43,7 @@
   
       // default to -1, i.e., don't optimize until shutdown
       private int optimizeAtRemoveCount = -1;
  -
  +   
       /**
        * Constructor for the DiskCacheAttributes object
        */
  @@ -120,9 +121,9 @@
       {
           return maxRecycleBinSize;
       }
  -
  +   
       /**
  -     * Description of the Method
  +     * Returns a copy of the attributes.
        * 
        * @return AuxiliaryCacheAttributes
        */
  @@ -137,7 +138,7 @@
           }
           return this;
       }
  -
  +    
       /**
        * Description of the Method
        * 
  @@ -152,6 +153,7 @@
           str.append( "\n maxKeySize  = " + maxKeySize );
           str.append( "\n maxRecycleBinSize  = " + maxRecycleBinSize );
           str.append( "\n optimizeAtRemoveCount  = " + optimizeAtRemoveCount );
  +        str.append( "\n shutdownSpoolTimeLimit  = " + shutdownSpoolTimeLimit 
);
           return str.toString();
       }
   
  
  
  
  1.26      +19 -11    
jakarta-turbine-jcs/src/java/org/apache/jcs/engine/control/CompositeCache.java
  
  Index: CompositeCache.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/engine/control/CompositeCache.java,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- CompositeCache.java       4 Jun 2005 02:01:58 -0000       1.25
  +++ CompositeCache.java       11 Jun 2005 00:35:27 -0000      1.26
  @@ -877,8 +877,12 @@
                   {
                       Iterator itr = memCache.getIterator();
   
  +                    log.info( "In dispose, " + this.cacheName + " 
memCache.size = " + memCache.getSize() );
  +                    
  +                    int cnt = 0;
                       while ( itr.hasNext() )
                       {
  +                        cnt++;
                           Map.Entry entry = (Map.Entry) itr.next();
   
                           ICacheElement ce = (ICacheElement) entry.getValue();
  @@ -896,8 +900,11 @@
                               log.error( e );
                           }
                       }
  -                }
   
  +                    log.info( "In dispose, " + this.cacheName + " put " + 
cnt + " into auxiliary " + aux );
  +
  +                }
  +                               
                   // Dispose of the auxiliary
   
                   aux.dispose();
  @@ -907,17 +914,18 @@
                   log.error( "Failure disposing of aux", ex );
               }
   
  -            try
  -            {
  -                memCache.dispose();
  -            }
  -            catch ( IOException ex )
  -            {
  -                log.error( "Failure disposing of memCache", ex );
  -            }
  -
           }
   
  +        log.info( "In dispose, " + this.cacheName + " disposing of memory 
cache." );
  +        try
  +        {
  +            memCache.dispose();
  +        }
  +        catch ( IOException ex )
  +        {
  +            log.error( "Failure disposing of memCache", ex );
  +        }
  +               
           log.warn( "Called close for " + cacheName );
   
       }
  
  
  
  1.9       +16 -0     
jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/jisp/JISPCacheAttributes.java
  
  Index: JISPCacheAttributes.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/disk/jisp/JISPCacheAttributes.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- JISPCacheAttributes.java  4 Jun 2005 02:01:56 -0000       1.8
  +++ JISPCacheAttributes.java  11 Jun 2005 00:35:27 -0000      1.9
  @@ -58,6 +58,22 @@
           return clearOnStart;
       }
   
  +    /* (non-Javadoc)
  +     * @see 
org.apache.jcs.auxiliary.disk.behavior.IDiskCacheAttributes#getShutdownSpoolTimeLimit()
  +     */
  +    public int getShutdownSpoolTimeLimit()
  +    {
  +        return this.shutdownSpoolTimeLimit;
  +    }
  +
  +    /* (non-Javadoc)
  +     * @see 
org.apache.jcs.auxiliary.disk.behavior.IDiskCacheAttributes#setShutdownSpoolTimeLimit(int)
  +     */
  +    public void setShutdownSpoolTimeLimit( int shutdownSpoolTimeLimit )
  +    {
  +        this.shutdownSpoolTimeLimit = shutdownSpoolTimeLimit;
  +    }     
  +    
       /** Description of the Method */
       public AuxiliaryCacheAttributes copy()
       {
  
  
  
  1.13      +2 -1      
jakarta-turbine-jcs/src/java/org/apache/jcs/engine/memory/AbstractMemoryCache.java
  
  Index: AbstractMemoryCache.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/engine/memory/AbstractMemoryCache.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- AbstractMemoryCache.java  4 Jun 2005 02:01:56 -0000       1.12
  +++ AbstractMemoryCache.java  11 Jun 2005 00:35:27 -0000      1.13
  @@ -183,6 +183,7 @@
       public void dispose()
           throws IOException
       {
  +        log.info( "Memory Cache dispose called.  Shutting down shrinker 
thread if it is running." );
           if ( shrinkerDaemon != null )
           {
               shrinkerDaemon.shutDown();
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: jcs-dev-unsubscribe@xxxxxxxxxxxxxxxxxx
For additional commands, e-mail: jcs-dev-help@xxxxxxxxxxxxxxxxxx

<Prev in Thread] Current Thread [Next in Thread>
  • cvs commit: jakarta-turbine-jcs/src/java/org/apache/jcs/engine/memory AbstractMemoryCache.java, asmuts <=