5 Replies Latest reply on Sep 2, 2008 4:57 PM by jreeman

    Problem with expiration eviction

    jreeman

      Hello,

      I wrote the following code to use expiration eviction policy :

      Region region = admDataCache.getRegion(fqn, true);
      
       ExpirationConfiguration expirationConfiguration = new ExpirationConfiguration();
       expirationConfiguration.setTimeToLiveSeconds(10);
       region.setEvictionPolicy(expirationConfiguration);
      
       admDataCache.getRoot().put(fqn, objectToCache);


      But my cached objects never expire.

      My cache-configuration doesn't contain any eviction property :

      <?xml version="1.0" encoding="UTF-8"?>
      
      <server>
       <mbean code="org.jboss.cache.jmx.CacheJmxWrapper"
       name="jboss.cache:service=TreeCache">
      
       <depends>jboss:service=Naming</depends>
       <attribute name="IsolationLevel">SERIALIZABLE</attribute>
       <attribute name="CacheMode">INVALIDATION_SYNC</attribute>
       <attribute name="ClusterName">Cluster-Of-Controllers</attribute>
      
       <attribute name="ClusterConfig">
       <config>
       <TCP start_port="7800" loopback="true"/>
       <MPING timeout="3000" bind_to_all_interfaces="false"
       mcast_addr="225.0.0.1" mcast_port="7500" ip_ttl="0"
       num_initial_members="2" />
       <MERGE2 max_interval="20000" min_interval="10000" />
       <FD_SOCK />
       <VERIFY_SUSPECT timeout="1500"/>
       <pbcast.NAKACK gc_lag="50" max_xmit_size="8192" retransmit_timeout="600,1200,2400,4800" />
       <UNICAST timeout="600,1200,2400"/>
       <pbcast.STABLE desired_avg_gossip="20000" />
       <pbcast.GMS join_retry_timeout="2000" join_timeout="5000" print_local_addr="false" shun="true" />
       <pbcast.STATE_TRANSFER />
       </config>
       </attribute>
      
       <attribute name="FetchStateOnStartup">false</attribute>
       <attribute name="InitialStateRetrievalTimeout">5000</attribute>
       <attribute name="LockAcquisitionTimeout">15000</attribute>
       <attribute name="UseMarshalling">false</attribute>
       <attribute name="CacheLoaderShared">true</attribute>
       <attribute name="CacheLoaderPreload">/</attribute>
       <attribute name="CacheLoaderPassivation">false</attribute>
       <attribute name="CacheLoaderFetchPersistentState">false</attribute>
       <attribute name="CacheLoaderFetchTransientState">false</attribute>
       <attribute name="CacheLoaderAsynchronous">false</attribute>
       </mbean>
      </server>
      


      Could you tell to me why my code doesn't work ?

      Thx

        • 1. Re: Problem with expiration eviction
          lovelyliatroim

          Have a read here

          http://www.jboss.org/file-access/default/members/jbosscache/freezone/docs/2.2.0.CR6/userguide_en/html_single/index.html#d0e3603

          Looks to me that your missing the equivalent of this

          // sets the expiry time for a node
          cache.getRoot().addChild(fqn1).put(ExpirationConfiguration.EXPIRATION_KEY, future);
          



          You have add to set the EXPIRATION_KEY on the node as well as your data item that your caching!!



          • 2. Re: Problem with expiration eviction
            mircea.markus

            If you want to specify the eviction melodramatically only (no eviction config in the xml file), you have to do it like this:

            ExpirationConfiguration expirationConfiguration = new ExpirationConfiguration();
             expirationConfiguration.setTimeToLiveSeconds(2);
             EvictionConfig ec = new EvictionConfig();
             List<EvictionRegionConfig> ercs = new ArrayList<EvictionRegionConfig>();
             EvictionRegionConfig erc = new EvictionRegionConfig(fqn, expirationConfiguration);
             ercs.add(erc);
             ec.setEvictionRegionConfigs(ercs);
             admDataCache.getConfiguration().setEvictionConfig(ec);

            Re:expirationConfiguration.setTimeToLiveSeconds(10);
            This is a bug, and the workaround is to set EXPIRATION_KEY for all elements, as lovelyliatroim suggested.
            https://jira.jboss.org/jira/browse/JBCACHE-1399 was created


            • 3. Re: Problem with expiration eviction
              jreeman

              Ok thx to all. In fact I removed the expiration configuration in the config file and the code. I just added the line suggested by lovelyliatroim and it sounds to work fine I just have warnings in the log file about the different nodes of the FQN where I add my object :


              2008-09-01 11:01:25,709: WARN [EvictionTimer-0] ExpirationAlgorithm, org.jboss.cache.eviction.ExpirationAlgorithm: No expiration key 'expiration' for Node: /node1
              2008-09-01 11:01:25,712: WARN [EvictionTimer-0] ExpirationAlgorithm, org.jboss.cache.eviction.ExpirationAlgorithm: No expiration key 'expiration' for Node: /node1/node2
              2008-09-01 11:01:25,713: WARN [EvictionTimer-0] ExpirationAlgorithm, org.jboss.cache.eviction.ExpirationAlgorithm: No expiration key 'expiration' for Node: /node1/node2/node3


              Anyway mircea is right, it should work with my previous code and with the fix (in 3.0.0.GA version), it should be surely possible to set the expiration at the root of a tree or subtree without having to do it again on every sub nodes and object.

              Tomorow I will add these additionnal note in the consequently created issue.

              • 4. Re: Problem with expiration eviction
                jreeman

                Oups here is my eviction configuration (I choose the most simple thing ;) ) :

                <attribute name="EvictionPolicyConfig">
                <config>
                <!-- Name of the DEFAULT eviction policy class. -->
                <attribute name="policyClass">org.jboss.cache.eviction.ExpirationPolicy</attribute>
                </config>
                </attribute>


                • 5. Re: Problem with expiration eviction
                  jreeman

                  -->

                  <attribute name="EvictionPolicyConfig">
                   <config>
                   <attribute name="policyClass">org.jboss.cache.eviction.ExpirationPolicy</attribute>
                   </config>
                   </attribute>