5 Replies Latest reply on Feb 12, 2013 2:44 PM by Dan Berindei

    infinispan remote-cache expiration failure, but works in embedded mode

    gibsosmat Newbie

      I am using infinispan-5.1.6.FINAL as a remote-cache server and hot-rod protocol to access it.

      but found that it is not working as intended, i.e cached value of a key is not evicted after 1ms as per the config below. (jmx is enabled but I am not monitoring it)

       

      <infinispan xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:infinispan="urn:infinispan:config:5.1"
          xsi:schemaLocation="urn:config:5.1 http://www.infinispan.org/schemas/infinispan-config-5.1.xsd">
          <global >
              <globalJmxStatistics enabled="true"/>
          </global>
      
          <namedCache name="my-cache">
              <expiration lifespan="1" maxIdle="1" reaperEnabled="true" wakeUpInterval="1" />
          </namedCache>
      </infinispan>

       

      So to verify the failure, I used rest server provided in the dist

      I exploded war (infinispan-5.1.6.FINAL/modules/rest/infinispan-server-rest.war),

      saved the above config, changed web.xml to use it and deployed in tomcat 6.0.32

       

      I was able to PUT/POST into the cache and retrieve from it, using GET

      http://localhost:8080/infinispan-server-rest/rest/my-cache/1

      but the entry is not evicted even after 10mins. i.e I was able to get the value through GET request after 10minutes.

      but the same config was working in embedded-cache mode. (I used spring-cache-abstraction on method return value caching)

       

      did I miss something obvious? how can I get this working?

        • 1. Re: infinispan remote-cache expiration failure, but works in embedded mode
          Dan Berindei Expert

          In the REST server, the default values for the timeToLiveSeconds and maxIdleTimeSeconds parameters is -1, which means the entries never expire. If you set them to 0 explicitly, the REST server will use the defaults configured in the cache configuration.

           

          This is a bit counter-intuitive, so I've created a feature request to change the defaults to 0: ISPN-2810. I've tentatively set the fix version to 5.3.0.Alpha1, but it is for backwards-compatibility reasons it may get fixed only in 6.0.0.

          1 of 1 people found this helpful
          • 2. Re: infinispan remote-cache expiration failure, but works in embedded mode
            gibsosmat Newbie

            thanks for the reply, rest server was hosted to verify the behaviour.

            my original problem is on hot-rod protocol and spring-cache-abstraction (3.1.x) using org.infinispan.client.hotrod.RemoteCacheManager

            how can I set timeToLiveSeconds and maxIdleTimeSeconds to 0 from hotrod client by default, so that server side xml config is honored?

             

            my spring xml config of hot-rod client

             

            <cache:annotation-driven mode="aspectj"/>
            <bean id="remoteCacheManager" class="org.infinispan.client.hotrod.RemoteCacheManager">
                <constructor-arg name="host" value="${infinispan.client.hotrod.host}" /> 
                <constructor-arg name="port" value="${infinispan.client.hotrod.port}" />
            </bean>
            
            <bean id="cacheManager" class="org.infinispan.spring.provider.SpringRemoteCacheManager">
                <constructor-arg name="nativeCacheManager" ref="remoteCacheManager" />
            </bean>
            

             

            EDIT: added spring config

            • 3. Re: infinispan remote-cache expiration failure, but works in embedded mode
              gibsosmat Newbie

              I think hotrod client is actually setting these values to 0 by default, but still cache didnt expire on server.

              I executed the following test

               

                  @Test
                  public void cacheTestSpring() throws Exception {
                      String key = "my-key-1";
                      Long sleepTime = 15000L;
                      cachedMethod(key); // this will put in the cache
                      logger.info("----------sleeping for: {}", sleepTime);
                      Thread.sleep(sleepTime);
                      logger.info("---------------------result: {}", cachedMethod(key));
                  }
                  
                  @Cacheable("my-cache")
                  private String cachedMethod(String key){
                      logger.info("cache miss for key: {}", key);
                      return "my-value-"+ key.substring(7);
                  }
              

               

              from logs

               

              [main] TRACE org.infinispan.client.hotrod.impl.RemoteCacheImpl  - For key(my-key-1) returning null
              [main] INFO  com.tests.CacheTest - cache miss for key: my-key-1
              [main] TRACE org.infinispan.client.hotrod.impl.RemoteCacheImpl  - About to add (K,V): (my-key-1, my-value-1) lifespanSecs:0, maxIdleSecs:0
              ...
              [main] TRACE org.infinispan.client.hotrod.impl.transport.tcp.TcpTransportFactory  - For server localhost/127.0.0.1:11222: active = 0; idle = 1
              [main] INFO  com.tests.CacheTest - ----------sleeping for: 15000
              [main] TRACE o.s.c.aspectj.AnnotationCacheAspect - Computed cache key my-key-1 for operation CacheableOperation[private java.lang.String com.tests.CacheTest.cachedMethod(java.lang.String)] caches=[my-cache] | condition='' | key=''
              ...
              [main] TRACE org.infinispan.client.hotrod.impl.RemoteCacheImpl  - For key(my-key-1) returning my-value-1
              [main] INFO  com.tests.CacheTest - ---------------------result: my-value-1
              

               

              full log attached.

              I also tried programatic cache by wiring cacheManager of spring abstraction.

              @Test
              public void cacheTestBasic() throws Exception {
                  Cache cache = cacheManager.getCache("my-cache");
                  String key = "my-key-2";
                  String value = "my-value-2";
                  Long sleepTime = 15000L;
              
                  cache.put(key, value);
                  
                  logger.info("---------------------sleeping for: {}", sleepTime);
                  Thread.sleep(sleepTime);
                  
                  ValueWrapper result = cache.get(key);
                  if(result != null){
                      logger.info("---------------------result: {}", result.get());
                  }
              }
              

               

              but still the 2nd call succeeded to get from cache. and logs show that idle times are set to 0.

              • 4. Re: infinispan remote-cache expiration failure, but works in embedded mode
                gibsosmat Newbie

                one more observation.

                I switched version to 5.2.1.Final server & client and the same config, test case is working as expected. i.e 2nd call dosent get it from cache.

                but 5.2 server with 5.1.6 client, cache dosent expire. may be the client is sending the value -1 or somesort.

                my problem is fixed by changing version. as I am just trying it out.

                 

                just for posterity I am leaving this question open.

                • 5. Re: infinispan remote-cache expiration failure, but works in embedded mode
                  Dan Berindei Expert

                  Yes, this only works with HotRod protocol 1.2 (which is used when both the client and the server are 5.2.0+).

                   

                  For reference, this is the issue in JIRA: https://issues.jboss.org/browse/ISPN-1293