10 Replies Latest reply on Jun 19, 2015 3:06 AM by georgespurlock

    Cache eviction & expiration config has no effect on 7.1.0.CR1b

    rbertoncelj

      I've created a test application that uses 2 caches with similar configuration - only names and means by which they are configured are different. One is configured in standalone.xml and the other is created programatically. The catch is that the frist one (configured in infinispan subsystem) does not honor eviction and expiration policies. No entries are ever removed - I can keep on putting stuff in the cache until OutOfMemoryError occures. The second cache that is configured programatically works fine - entries are removed after configured idle time or when max-entries is reached.

       

      Am I missing something or is this a bug in JBoss's configuration/integration of infinispan?

       

       

      This is how the first cache "cars-cache" is configured:

       

      <cache-container name="iskratest" default-cache="cars-cache">
          <local-cache name="cars-cache">
              <eviction strategy="FIFO" max-entries="10"/>
              <expiration lifespan="10000" interval="1000" max-idle="5000"/>
          </local-cache>
      </cache-container>
      

       

       

      This is a bean where the second cache is created. Also both caches are made available trough CDI to the rest of the application.

      @ManagedBean
      @ApplicationScoped
      public class CacheFactory {
      
          @SuppressWarnings({"EjbEnvironmentInspection"})
          @Resource(lookup = "java:jboss/infinispan/iskratest")
          private EmbeddedCacheManager container;
      
          @Produces
          @Cars
          @ApplicationScoped
          public Cache getCarsCache() {
              return container.getCache();
          }
      
          @Produces
          @Cars2
          @ApplicationScoped
          public Cache getCars2Cache() {
              container.defineConfiguration("cars2", new Configuration().fluent()
                      .mode(Configuration.CacheMode.LOCAL)
                      .eviction().strategy(EvictionStrategy.FIFO).maxEntries(10)
                      .expiration().lifespan(10000L).maxIdle(5000L).wakeUpInterval(1000L)
                      .build());
              return container.getCache("cars2");
          }
      }
      
        • 1. Re: Cache eviction & expiration config has no effect on 7.1.0.CR1b
          alesj

          I've stumbled upon this as well, and this are my findings.

           

          JNDI lookup is broken wrt cache-config service.

           

          e.g. if you lookup cache container via JNDI (as I do), and then grab some cache from it,

          cache-config service is never started, hence custom config is never registered against container -- you get default.

           

          So, imo, the only way to get cache in proper state/config is via MSC,

          which refs CacheService, which depends on cache-config service.

           

          Which is kinda hard from "static" (non-JBoss AS7/MSC integrated) usecase.

           

          Just my 0.02$, as I spent the evening finding why my cache is not indexable. :-)


           

          This describes how AS7' Infinispan sub-system handles things - container and its cache configs are 2 diff MSC services.

          Unless you access that cache via MSC, its config will never get applied to container, hence you end-up with default config.

           

          Workaround is to somehow trigger that Cache-config service to start -- who's purpose is to register the config against container.

          * https://github.com/alesj/jboss-as/commit/cf96f588aaa94d864f459e4dc5e277dab81eb170#diff-2

          (since you're doing that from the app, not another sub-system as this code, try ServiceActivator pattern from MSC integration)

          • 2. Re: Cache eviction & expiration config has no effect on 7.1.0.CR1b
            ctomc

            Ales,

            I don't know if this is the case here, your problem was when trying to do JNDI lookup of the cache, but if you do it trough @Resource it should work.

            Problem is similar but not the same, as this is application and you ware in subsystem of as where you cannot get to many of resources that application has on disposial.

             

            I will try to reproduce and debug this.

            • 3. Re: Cache eviction & expiration config has no effect on 7.1.0.CR1b
              alesj

              Ales,

              I don't know if this is the case here, your problem was when trying to do JNDI lookup of the cache, but if you do it trough @Resource it should work.

              Problem is similar but not the same, as this is application and you ware in subsystem of as where you cannot get to many of resources that application has on disposial.

              That was a different issue. ;-)

              * it was not even finding container jndi binding, since I'm doing a programmatic lookup, w/o metadata

              ** it was fixed by adding proper metadata during deployment processing; similar to what is produced from @Resource

               

              This one is about cache-config, which is not properly appiled.

              Put a break point into cache-config service' start and you'll see it never gets invoked, hence it's never registered against container.

              • 4. Re: Cache eviction & expiration config has no effect on 7.1.0.CR1b
                pferraro
                • 5. Re: Cache eviction & expiration config has no effect on 7.1.0.CR1b
                  alesj

                  FYI:

                  https://issues.jboss.org/browse/AS7-3189

                  Is there a way to make non-metadata described JNDI lookup start on_demand service?

                  Atm this is not the case, as deep down in some Naming service, you simply do a ServiceContainer lookup via name.

                  The service is there, but it's not started yet -- that error msg I sent you before NY.

                  "Error looking up infinispan/capedwarf, service service jboss.naming.context.java.jboss.infinispan.capedwarf is not started"

                   

                  I guess this is a MSC thing, and we need to check how it enables on_demand services.

                  (it already does that properly if you do have the right metadata; e.g. @Resouorce)

                   

                  Just asking since I know we had that for MC -- as I wrote it. :-)

                  * we fully installed a service/bean if it was on_demand

                  • 6. Re: Cache eviction & expiration config has no effect on 7.1.0.CR1b
                    shant

                    I face same problem, the eviction that is set in the standalone.xml does not work.. Could you resolve this problem?

                     

                    Also, are there any examples that you know of that give more information on eviction in jboss AS 7.1.0.

                     

                    Thank you.

                    • 7. Re: Cache eviction & expiration config has no effect on 7.1.0.CR1b
                      pferraro

                      The issue addressed in the thread *should* already be fixed.  Cache configururation services are installed as passive, such that when the cache manager is referenced, all caches defined by the subsystem will already be registered with the cache manager.

                      Can you post your eviction configuration and the evidence you have that it isn't working?

                      • 8. Re: Cache eviction & expiration config has no effect on 7.1.0.CR1b
                        shant

                        I see that the evictionmanager is running, when I switch the infinispan to "TRACE" mode.

                         

                        But, I am adding String to the cache using one thread , and removing the object using  another thread. But I see that even after adding 20 strings to the cache , when i remove the first string, it is still there in the cache. The configuration I am using is :

                        <cache-container name="localCacheCont" default-cache="localCache" jndi-name="java:jboss/infinispan/container/localCacheCont">
                                        <local-cache name="localCache" jndi-name="java:jboss/infinispan/cache/localCacheCont/localCache">
                                            <eviction strategy="LRU" max-entries="5"/>
                                            <expiration max-idle="10"/>
                                        </local-cache>
                                    </cache-container>
                        May be I am missing something, Is there anything wrong in the above configuration.

                        thanks

                         

                        • 9. Re: Cache eviction & expiration config has no effect on 7.1.0.CR1b
                          lucianob

                          Ales Justin ha scritto:

                           

                          FYI:

                          https://issues.jboss.org/browse/AS7-3189

                          Is there a way to make non-metadata described JNDI lookup start on_demand service?

                          Atm this is not the case, as deep down in some Naming service, you simply do a ServiceContainer lookup via name.

                          The service is there, but it's not started yet -- that error msg I sent you before NY.

                          "Error looking up infinispan/capedwarf, service service jboss.naming.context.java.jboss.infinispan.capedwarf is not started"

                           

                          I guess this is a MSC thing, and we need to check how it enables on_demand services.

                          (it already does that properly if you do have the right metadata; e.g. @Resouorce)

                           

                          Just asking since I know we had that for MC -- as I wrote it. :-)

                          * we fully installed a service/bean if it was on_demand

                          Hi Ales,

                           

                          I faced the same exception (service not started), and I resolved with the start="EAGER" attribute in cache tag, after having read https://docs.jboss.org/author/display/ISPN/Getting+Started+Guide+-+JBoss+AS+7 , Cache container lifecycle paragraph.

                          JBoss 7.1.1.Final, Infinispan 5.1.2.FINAL

                           

                          Bye

                           

                          LB

                          • 10. Re: Cache eviction & expiration config has no effect on 7.1.0.CR1b
                            georgespurlock

                            I had problem with this sub-system service