5 Replies Latest reply on Jan 5, 2011 11:54 AM by galder.zamarreno

    Infinispan 4.1 and 4.2 eviction error

    silenius

      Hello all,

       

      I can't find a proper way to get eviction working with Infinispan 4.1 and 4.2.

      Can anyone point me a way to get it working please?

       

      Bellow is my Infinispan configuration file which works fine with Infinispan 4.0.

      <?xml version="1.0" encoding="UTF-8"?>
      <infinispan
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="urn:infinispan:config:4.0 http://www.infinispan.org/schemas/infinispan-config-4.0.xsd"
          xmlns="urn:infinispan:config:4.0">
          <global>
              <transport clusterName="ApplicationCluster">
                  <properties>
                      <property name="configurationFile" value="jgroups-udp.xml" />
                  </properties>
              </transport>
          </global>
          <default>
              <eviction strategy="FIFO" wakeUpInterval="6000" />
          </default>
          <namedCache name="cache1" />
          <namedCache name="cache2" />
          <namedCache name="cache3">
              <eviction strategy="NONE" />
              <expiration lifespan="3000" />
              <clustering mode="distribution">
                  <async />
                  <hash />
                  <l1 lifespan="3000" />
              </clustering>
          </namedCache>
      </infinispan>

       

      And bellow are the unit tests I use to test both eviction and expiration configurations.

      Unfortunatly getCache1 method fails with both Infinispan 4.1 and 4.2.

      @Test
      public void getCache3() throws InterruptedException {
          Cache<String, String> cache3 = service.getManager().getCache("cache3");
          long expirationLifespan = cache3.getConfiguration().getExpirationLifespan();
      
          cache3.put("key", "value");
      
          LOGGER.info("ChartCache expiration lifespan: {}", expirationLifespan);
          LOGGER.info("ChartCache contains key? {}", cache3.containsKey("key"));
          Assert.assertTrue(cache3.containsKey("key"));
          Thread.sleep(expirationLifespan + 500L);
          LOGGER.info("ChartCache contains key? {}", cache3.containsKey("key"));
          Assert.assertFalse(cache3.containsKey("key"));
      }
      
      @Test
      public void getCache1() throws InterruptedException {
          Cache<String, String> cache1 = service.getManager().getCache("cache1");
          long evictionWakeUpInterval = cache1.getConfiguration().getEvictionWakeUpInterval();
      
          cache1.put("key", "value");
      
          LOGGER.info("MenuCache eviction wake up: {}", evictionWakeUpInterval);
          LOGGER.info("MenuCache contains key? {}", cache1.containsKey("key"));
          Assert.assertTrue(cache1.containsKey("key"));
          Thread.sleep(evictionWakeUpInterval + 500L);
          LOGGER.info("MenuCache contains key? {}", cache1.containsKey("key"));
          Assert.assertFalse(cache1.containsKey("key"));
      }
      

       

      Thanks.

        • 1. Re: Infinispan 4.1 and 4.2 eviction error
          galder.zamarreno

          Looks to me that for cache1, or the default cache, you're setting eviction, which indicates the algorithm which should be used to evict cache entries, but you're not setting any limits. In other words, you're not indicating when entries should be considered for eviction. IOW, if the cache is bigger than X, start evicting stuff. You have maxEntries attribute missing in eviction. For example:

           

          <eviction wakeUpInterval="500" maxEntries="5000" strategy="FIFO"/>

           

          The sample.xml provided with latest 4.2.0.Final to find recommended cache configurations.

          1 of 1 people found this helpful
          • 2. Re: Infinispan 4.1 and 4.2 eviction error
            galder.zamarreno

            We should probably throw some kind of warning in this case. I can't see how eviction with an strategy other than NONE makes sense with no maxEntries being set: https://issues.jboss.org/browse/ISPN-847

            • 3. Re: Infinispan 4.1 and 4.2 eviction error
              silenius

              Hi Galder,

               

              It seems that eviction thread does not work as I thought on newer Infinispan versions.

               

              The default maxEntries value is -1, which means no limit, and is indeed what I want.

               

              I need to remove all my cache entries based on time, no matter the number of entries in the cache.
              My problem would be solved if eviction could remove entries based on lifespan and/or idle time.

               

              Expiration does not work for me either, since after 24 hours the data is no longer valid and must all be removed.

              • 4. Re: Infinispan 4.1 and 4.2 eviction error
                silenius

                Can this actually be done with Infinispan 4.2?

                • 5. Re: Infinispan 4.1 and 4.2 eviction error
                  galder.zamarreno

                  Looking again at the test above for getCache1, it seems like it's is not working because cache1 has no expiration settings in it, whereas cache3 has. If you add expiration element to default or namedCache for cache1 should work.

                   

                  Removing entries based on lifespan or max idle works in 4.2 either with expiration correctly configured via configuration, or programmatically passing the right lifespan, max idle values in the cache operation itself.

                  1 of 1 people found this helpful