You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jcs-dev@jakarta.apache.org by as...@apache.org on 2005/01/14 02:34:03 UTC

cvs commit: jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/remote/server RemoteCacheServer.java

asmuts      2005/01/13 17:34:03

  Modified:    src/conf cache.ccf cache2.ccf remote.cache.ccf
                        remote.cache2.ccf
               src/java/org/apache/jcs/auxiliary/remote/server
                        RemoteCacheServer.java
  Log:
  Fixed a small problem where the listener id when failing over was not getting updated by the server.
  Basic failover and clustering seems to be working.  I will test more.
  
  Revision  Changes    Path
  1.15      +3 -5      jakarta-turbine-jcs/src/conf/cache.ccf
  
  Index: cache.ccf
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/src/conf/cache.ccf,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- cache.ccf	13 Jan 2005 09:12:40 -0000	1.14
  +++ cache.ccf	14 Jan 2005 01:34:02 -0000	1.15
  @@ -130,15 +130,13 @@
   # just a remove lock to add
   jcs.auxiliary.RC=org.apache.jcs.auxiliary.remote.RemoteCacheFactory
   jcs.auxiliary.RC.attributes=org.apache.jcs.auxiliary.remote.RemoteCacheAttributes
  -jcs.auxiliary.RC.attributes.FailoverServers=localhost:1102
  -#jcs.auxiliary.RC.attributes.RemoteHost=localhost
  -#jcs.auxiliary.RC.attributes.RemotePort=1102
  -jcs.auxiliary.RC.attributes.LocalPort=1103
  +jcs.auxiliary.RC.attributes.FailoverServers=localhost:1102,localhost:1103
  +jcs.auxiliary.RC.attributes.LocalPort=1201
   jcs.auxiliary.RC.attributes.RemoveUponRemotePut=false
   #jcs.auxiliary.RC.attributes.RemoteServiceName=RemoteCache
   #-1 means no timeout, this is the default
   # if the timeout is -1, no threadpool will be used.
  -jcs.auxiliary.RC.attributes.GetTimeoutMillis=0
  +jcs.auxiliary.RC.attributes.GetTimeoutMillis=500
   jcs.auxiliary.RC.attributes.ThreadPoolName=remote_cache_client
   jcs.auxiliary.RC.attributes.GetOnly=false
   
  
  
  
  1.6       +1 -4      jakarta-turbine-jcs/src/conf/cache2.ccf
  
  Index: cache2.ccf
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/src/conf/cache2.ccf,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- cache2.ccf	13 Jan 2005 09:12:40 -0000	1.5
  +++ cache2.ccf	14 Jan 2005 01:34:02 -0000	1.6
  @@ -49,11 +49,8 @@
   jcs.auxiliary.RC=org.apache.jcs.auxiliary.remote.RemoteCacheFactory
   jcs.auxiliary.RC.attributes=org.apache.jcs.auxiliary.remote.RemoteCacheAttributes
   jcs.auxiliary.RC.attributes.FailoverServers=localhost:1102
  -jcs.auxiliary.RC.attributes.LocalPort=1104
  +jcs.auxiliary.RC.attributes.LocalPort=1202
   jcs.auxiliary.RC.attributes.RemoveUponRemotePut=false
  -#jcs.auxiliary.RC.attributes.RemoteServiceName=RemoteCache
  -#-1 means no timeout, this is the default
  -# if the timeout is -1, no threadpool will be used.
   jcs.auxiliary.RC.attributes.GetTimeoutMillis=5000
   jcs.auxiliary.RC.attributes.ThreadPoolName=remote_cache_client
   jcs.auxiliary.RC.attributes.GetOnly=false
  
  
  
  1.6       +3 -17     jakarta-turbine-jcs/src/conf/remote.cache.ccf
  
  Index: remote.cache.ccf
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/src/conf/remote.cache.ccf,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- remote.cache.ccf	7 Jan 2005 22:29:16 -0000	1.5
  +++ remote.cache.ccf	14 Jan 2005 01:34:02 -0000	1.6
  @@ -25,25 +25,11 @@
   jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
   jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes
   jcs.default.elementattributes.IsEternal=false
  -jcs.default.elementattributes.MaxLifeSeconds=7
  +jcs.default.elementattributes.MaxLifeSeconds=7000
   jcs.default.elementattributes.IdleTime=1800
   jcs.default.elementattributes.IsSpool=true
   jcs.default.elementattributes.IsRemote=true
   jcs.default.elementattributes.IsLateral=true
  -
  -# SYSTEM CACHE
  -# should be defined for the storage of group attribute list
  -jcs.system.groupIdCache=DC
  -jcs.system.groupIdCache.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
  -jcs.system.groupIdCache.cacheattributes.MaxObjects=10000
  -jcs.system.groupIdCache.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
  -jcs.system.groupIdCache.elementattributes=org.apache.jcs.engine.ElementAttributes
  -jcs.system.groupIdCache.elementattributes.IsEternal=true
  -jcs.system.groupIdCache.elementattributes.MaxLifeSeconds=3600
  -jcs.system.groupIdCache.elementattributes.IdleTime=1800
  -jcs.system.groupIdCache.elementattributes.IsSpool=true
  -jcs.system.groupIdCache.elementattributes.IsRemote=true
  -jcs.system.groupIdCache.elementattributes.IsLateral=true
    
   
   ##############################################################
  @@ -60,9 +46,9 @@
   jcs.auxiliary.RCluster1.attributes=org.apache.jcs.auxiliary.remote.RemoteCacheAttributes
   jcs.auxiliary.RCluster1.attributes.RemoteTypeName=CLUSTER
   jcs.auxiliary.RCluster1.attributes.RemoveUponRemotePut=false
  -#jcs.auxiliary.RCluster1.attributes.ClusterServers=localhost:1103
  +jcs.auxiliary.RCluster1.attributes.ClusterServers=localhost:1103
   jcs.auxiliary.RCluster1.attributes.GetOnly=false
  -#jcs.auxiliary.RCluster1.attributes.LocalClusterConsistency=true
  +jcs.auxiliary.RCluster1.attributes.LocalClusterConsistency=true
   
   # server to update for clustering
   jcs.auxiliary.RCluster2=org.apache.jcs.auxiliary.remote.RemoteCacheFactory
  
  
  
  1.4       +4 -18     jakarta-turbine-jcs/src/conf/remote.cache2.ccf
  
  Index: remote.cache2.ccf
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/src/conf/remote.cache2.ccf,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- remote.cache2.ccf	7 Jan 2005 22:29:16 -0000	1.3
  +++ remote.cache2.ccf	14 Jan 2005 01:34:02 -0000	1.4
  @@ -26,31 +26,16 @@
   jcs.default.cacheattributes.ShrinkerIntervalSeconds=60
   jcs.default.elementattributes=org.apache.jcs.engine.ElementAttributes
   jcs.default.elementattributes.IsEternal=false
  -jcs.default.elementattributes.MaxLifeSeconds=7
  +jcs.default.elementattributes.MaxLifeSeconds=7000
   jcs.default.elementattributes.IdleTime=1800
   jcs.default.elementattributes.IsSpool=true
   jcs.default.elementattributes.IsRemote=true
   jcs.default.elementattributes.IsLateral=true
   
  -# SYSTEM CACHE
  -# should be defined for the storage of group attribute list
  -jcs.system.groupIdCache=DC,RCluster1
  -jcs.system.groupIdCache.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
  -jcs.system.groupIdCache.cacheattributes.MaxObjects=10000
  -jcs.system.groupIdCache.cacheattributes.MemoryCacheName=org.apache.jcs.engine.memory.lru.LRUMemoryCache
  -jcs.system.groupIdCache.elementattributes=org.apache.jcs.engine.ElementAttributes
  -jcs.system.groupIdCache.elementattributes.IsEternal=true
  -jcs.system.groupIdCache.elementattributes.MaxLifeSeconds=3600
  -jcs.system.groupIdCache.elementattributes.IdleTime=1800
  -jcs.system.groupIdCache.elementattributes.IsSpool=true
  -jcs.system.groupIdCache.elementattributes.IsRemote=true
  -jcs.system.groupIdCache.elementattributes.IsLateral=true
  -
  - 
   
   ##############################################################
   ################## CACHE REGIONS AVAILABLE ###################
  -jcs.region.testCache1=DC,RCluster1,RCluster2
  +jcs.region.testCache1=DC,RCluster1
   jcs.region.testCache1.cacheattributes=org.apache.jcs.engine.CompositeCacheAttributes
   jcs.region.testCache1.cacheattributes.MaxObjects=1000
   
  @@ -75,11 +60,12 @@
   jcs.auxiliary.RCluster2.attributes.GetOnly=false
   jcs.auxiliary.RCluster2.attributes.LocalClusterConsistency=true
   
  +# disk cache
   jcs.auxiliary.DC=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheFactory
   jcs.auxiliary.DC.attributes=org.apache.jcs.auxiliary.disk.indexed.IndexedDiskCacheAttributes
   jcs.auxiliary.DC.attributes.DiskPath=@project_home@/raf/remote
  -
    
  +# Lateral cache 
   jcs.auxiliary.LC=org.apache.jcs.auxiliary.lateral.LateralCacheFactory
   jcs.auxiliary.LC.attributes=org.apache.jcs.auxiliary.lateral.LateralCacheAttributes
   jcs.auxiliary.LC.attributes.TransmissionTypeName=UDP
  
  
  
  1.22      +80 -46    jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java
  
  Index: RemoteCacheServer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-turbine-jcs/src/java/org/apache/jcs/auxiliary/remote/server/RemoteCacheServer.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- RemoteCacheServer.java	13 Jan 2005 09:12:52 -0000	1.21
  +++ RemoteCacheServer.java	14 Jan 2005 01:34:03 -0000	1.22
  @@ -226,7 +226,30 @@
       }
   
   
  -    /** Description of the Method */
  +    /**
  +     * An update can come from either a local cache's remote auxiliary, or it
  +     * can come from a remote server.  A remote server is considered a a source of
  +     * type cluster.
  +     * 
  +     * If the update came from a cluster, then we should tell the cache manager that 
  +     * this was a remote put.  This way, any lateral and remote auxiliaries configured
  +     * for the region will not be updated.  This is basically how a remote listener works
  +     * when plugged into a local cache.
  +     * 
  +     * If the cluster is configured to keep local cluster consistency, then all
  +     * listeners will be updated.  This allows cluster server A to update cluster server B 
  +     * and then B to update its clients if it is told to keep local cluster consistency.  Otherwise,
  +     * server A will update server B and B will not tell its clients.  If you cluster using
  +     * lateral caches for instance, this is how it will work.  Updates to a cluster node, will
  +     * never get to the leavess.  The remote cluster, with local cluster consistency, allows you
  +     * to update leaves.  This basically allows you to have a failover remote server.
  +     * 
  +     * Since currently a cluster will not try to get from other cluster servers, you can scale a bit
  +     * with a cluster configuration.  Puts and removes will be broadcasted to all clients, but the
  +     * get load on a remote server can be reduced. 
  +     * 
  +     * 
  +     */
       public void update( ICacheElement item, long requesterId )
           throws IOException
       {
  @@ -255,8 +278,13 @@
           {
               CacheListeners cacheDesc = getCacheListeners( item.getCacheName() );
               /*Object val = */item.getVal();
  -
  +            
               Integer remoteTypeL = ( Integer ) idTypeMap.get( new Long( requesterId ) );
  +            if ( log.isDebugEnabled() )
  +            {
  +                log.debug( "in update, requesterId = [" + requesterId + "] remoteType = " + remoteTypeL );
  +            }
  +
               boolean fromCluster = false;
               if ( remoteTypeL.intValue() == IRemoteCacheAttributes.CLUSTER )
               {
  @@ -269,9 +297,10 @@
                   {
                       CompositeCache c = ( CompositeCache ) cacheDesc.cache;
   
  -                    //TODO; make this a bit less of a hack
  -                    // If the source of this request was from a cluster, then
  -                    // update the remote caches.  COnsider it a local update.
  +                    // If the source of this request was not from a cluster, then
  +                    // consider it a local update.  The cache manager will try to update all
  +                    // auxiliaries.  
  +                    //
                       // This requires that two local caches not be connected to
                       // two clustered remote caches. The failover runner will
                       // have to make sure of this.  ALos, the local cache needs
  @@ -279,13 +308,11 @@
                       // id somehow.  The remote cache should udate all local caches
                       // but not update the cluster source.  Cluster remote caches
                       // should only be updated by the server and not the RemoteCache.
  -                    // PUT LOGIC IN REMOTE CACHE
  -                    // WILL TRY UPDATING REMOTES
                       if ( fromCluster )
                       {
                           if ( log.isDebugEnabled() )
                           {
  -                            log.debug( "not updating clusters **************************************" );
  +                            log.debug( "Put FROM cluster, NOT updating other auxiliaries for region." );
                           }
   
                           c.localUpdate( item );
  @@ -294,7 +321,7 @@
                       {
                           if ( log.isDebugEnabled() )
                           {
  -                            log.debug( "updating clusters **************************************" );
  +                            log.debug( "Put NOT from cluster, updating other auxiliaries for region." );
                           }
   
                           c.update( item );
  @@ -312,18 +339,25 @@
   
                       ICacheEventQueue[] qlist = getEventQList( cacheDesc, requesterId );
   
  -                    if ( log.isDebugEnabled() )
  -                    {
  -                        log.debug( "qlist.length = " + qlist.length );
  -                    }
  -
  -                    for ( int i = 0; i < qlist.length; i++ )
  +                    if ( qlist != null )
                       {
  +                      if ( log.isDebugEnabled() )
  +                      {
  +                          log.debug( "qlist.length = " + qlist.length );                          
  +                      }    
  +                      for ( int i = 0; i < qlist.length; i++ )
  +                      {
                           qlist[i].addPutEvent( item );
  +                      }
                       }
  -
  +                    else 
  +                    {
  +                      if ( log.isDebugEnabled() )
  +                      {
  +                        log.debug( "q list is null" );
  +                      }
  +                    }    
                   }
  -
               }
           }
           catch ( NotBoundException ex )
  @@ -333,7 +367,7 @@
           }
           catch ( Exception e )
           {
  -            log.error( e );
  +            log.error( "Trouble in Update", e );
           }
   
           // TODO use JAMON
  @@ -407,13 +441,6 @@
               log.debug( "get " + key + " from cache " + cacheName );
           }
   
  -//        Integer remoteTypeL = ( Integer ) idTypeMap.get( new Long( requesterId ) );
  -//        boolean fromCluster = false;
  -//        if ( remoteTypeL.intValue() == IRemoteCacheAttributes.CLUSTER )
  -//        {
  -//            fromCluster = true;
  -//        }
  -
           CacheListeners cacheDesc = null;
           try
           {
  @@ -496,7 +523,7 @@
                   {
                       if ( log.isDebugEnabled() )
                       {
  -                        log.debug( "not updating clusters **************************************" );
  +                        log.debug( "Remove FROM cluster, NOT updating other auxiliaries for region" );
                       }
                       removeSuccess = c.localRemove( key );
                   }
  @@ -504,11 +531,14 @@
                   {
                       if ( log.isDebugEnabled() )
                       {
  -                        log.debug( "updating clusters **************************************" );
  +                        log.debug( "Remove NOT from cluster, updating other auxiliaries for region" );
                       }
                       removeSuccess = c.remove( key );
                   }
   
  +                // this assumes that if it is not on remote server then it is not on a local.
  +                //  this is probalby a bad assumption.
  +                //TODO change
                   if ( removeSuccess )
                   {
   
  @@ -703,31 +733,35 @@
                   long id = 0;
                   try
                   {
  -                    id = listener.getListenerId();
  -                    if ( id == 0 )
  +                    id = listener.getListenerId();                                        
  +                    // clients problably shouldn't do this.
  +                    if ( id != 0 )
                       {
  -                        // must start at one so the next gets recognized
  -                        long listenerIdB = nextListenerId();
  -                        if ( log.isDebugEnabled() )
  -                        {
  -                            log.debug( "listener id=" + ( listenerIdB & 0xff ) + " addded for cache " + cacheName );
  -                        }
  -                        listener.setListenerId( listenerIdB );
  -                        id = listenerIdB;
  -                        // in case it needs synchronization
  -                        p1( "added new vm listener " + listenerIdB );
  -
  -                        // relate the type to an id
  -                        this.idTypeMap.put( new Long( listenerIdB ), new Integer( remoteType ) );
  -
  -                    }
  -                    else
  +                      log.info ( "added existing vm listener under new id, old id = " + id ); 
  +                      p1( "added existing vm listener " + id );                      
  +                    }  
  +                    
  +                    // always get a new listern id, assume that this listener could not be in another queue
  +                    
  +                    // must start at one so the next gets recognized
  +                    long listenerIdB = nextListenerId();
  +                    if ( log.isDebugEnabled() )
                       {
  -                        p1( "added existing vm listener " + id );
  +                        log.debug( "listener id=" + ( listenerIdB & 0xff ) + " addded for cache " + cacheName );
                       }
  +                    listener.setListenerId( listenerIdB );
  +                    id = listenerIdB;
  +                    // in case it needs synchronization
  +                    log.info ( "added vm listener under new id = " + listenerIdB ); 
  +                    p1( "added vm listener under new id = " + listenerIdB );
  +
  +                    // relate the type to an id
  +                    this.idTypeMap.put( new Long( listenerIdB ), new Integer( remoteType ) );
  +
                   }
                   catch ( IOException ioe )
                   {
  +                  log.error( "Problem setting listener id", ioe );
                   }
   
                   CacheEventQueueFactory fact = new CacheEventQueueFactory();
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: turbine-jcs-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: turbine-jcs-dev-help@jakarta.apache.org