time-to-live-seconds (ttl) doesn't work

2,060 views
Skip to first unread message

mayo...@gmail.com

unread,
Feb 11, 2014, 3:00:36 AM2/11/14
to haze...@googlegroups.com
Hi, I am using hazelcast 3.1.5.  It seems ttl doesn't work (maybe I don't know how to get time-to-live-seconds work). Basically, per my testing and observation, if max-idle-seconds is 0 or not set (i.e. commented out), time-to-live-seconds doesn't work -- map entry is not evicted when ttl expires. It seems to me only max-idle-seconds setting takes effect and applies. Did I miss anything fundamental? Below is the config I used to test and repro this issue.


    <map name="testMap">
        <in-memory-format>BINARY</in-memory-format>
        <backup-count>0</backup-count>
        <async-backup-count>0</async-backup-count>
        <time-to-live-seconds>300</time-to-live-seconds>
        <max-idle-seconds>1200</max-idle-seconds>
        <eviction-policy>LRU</eviction-policy>
        <max-size policy="PER_NODE">200000</max-size>
        <eviction-percentage>25</eviction-percentage>
        <merge-policy>com.hazelcast.map.merge.LatestUpdateMapMergePolicy</merge-policy>
    </map>

Questions:
1. How to get time-to-live-seconds to work alone?
2. Do time-to-live-seconds and max-idle-seconds have to go together?
Thanks!

ali gurbuz

unread,
Feb 11, 2014, 3:09:02 AM2/11/14
to haze...@googlegroups.com
Here is a simple test which shows that TTL works:

        Config config = new Config();
        final MapConfig mapConfig = config.getMapConfig("m");
        mapConfig.setTimeToLiveSeconds(5);
        final HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);
        final IMap m = instance.getMap("m");
        m.put("key", "value");
        assertNotNull(m.get("key"));
        Thread.sleep(1000);
        assertNotNull(m.get("key"));
        Thread.sleep(1000);
        assertNotNull(m.get("key"));
        Thread.sleep(4000);
        assertNull(m.get("key"));


--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at http://groups.google.com/group/hazelcast.
To view this discussion on the web visit https://groups.google.com/d/msgid/hazelcast/924ef7cd-d674-44c3-b81f-d32fea667f61%40googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

mayo...@gmail.com

unread,
Feb 11, 2014, 4:25:48 PM2/11/14
to haze...@googlegroups.com
If it works programmatically, what is wrong with my hazelcast.xml? Can you please share a working sample xml or point out where is wrong? Or do XML config works differently from the programmatic way? Thanks!

ali gurbuz

unread,
Feb 11, 2014, 4:37:28 PM2/11/14
to haze...@googlegroups.com
xml config does not work differently, and your config seems fine too.
So if you can come up with a reproducible test code it would be easy to work on



On Tue, Feb 11, 2014 at 11:25 PM, <mayo...@gmail.com> wrote:
If it works programmatically, what is wrong with my hazelcast.xml? Can you please share a working sample xml or point out where is wrong? Or do XML config works differently from the programmatic way? Thanks!

--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at http://groups.google.com/group/hazelcast.

mayo...@gmail.com

unread,
Feb 12, 2014, 3:27:56 AM2/12/14
to haze...@googlegroups.com
Weird. If I run that in a program (without connecting to hazelcast mancenter 3.1.5), then I can't repro (i.e. the map entry is evicted when ttl expires). However, if I start a standalone/dedicated node using com.hazelcast.examples.StartServer, then the map entry is not evicted. But both use

Hazelcast.newHazelcastInstance(null) with hazelcast.xml in same dir/classpath to initiate hazelcast. Any clue what went wrong?


 

Ali Gürbüz

unread,
Feb 12, 2014, 4:38:16 AM2/12/14
to haze...@googlegroups.com
When you run StartServer which config file does it pick? you can see this from logs


On 12 Feb 2014, at 10:27, mayo...@gmail.com wrote:

Weird. If I run that in a program (without connecting to hazelcast mancenter 3.1.5), then I can't repro (i.e. the map entry is evicted when ttl expires). However, if I start a standalone/dedicated node using com.hazelcast.examples.StartServer, then the map entry is not evicted. But both use

Hazelcast.newHazelcastInstance(null) with hazelcast.xml in same dir/classpath to initiate hazelcast. Any clue what went wrong?


 

--
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at http://groups.google.com/group/hazelcast.

mayo...@gmail.com

unread,
Feb 12, 2014, 2:32:30 PM2/12/14
to haze...@googlegroups.com
I am able to reproduce this by calling the REST interface (I used the Apached common HTTP Client 3.0.1) to put the key/value. It seems to do with the Hazelcast REST interface implementation.  Enclosed is the test and attached is the hazelcast.xml used by the test.
Interestingly, if the map entry is PUT/POST using the Hz native client (and then GET using the HTTP client against REST interface), then the entry will be evicted when ttl expires. 


Let me know if any questions.

import org.apache.commons.httpclient.HttpClient;

import org.apache.commons.httpclient.methods.GetMethod;

import org.apache.commons.httpclient.methods.PostMethod;

import org.junit.Assert;

import com.hazelcast.client.HazelcastClient;

import com.hazelcast.client.config.ClientConfig;

import com.hazelcast.config.ClasspathXmlConfig;

import com.hazelcast.config.Config;

import com.hazelcast.config.FileSystemXmlConfig;

import com.hazelcast.config.MapConfig;

import com.hazelcast.core.Hazelcast;

import com.hazelcast.core.HazelcastInstance;

import com.hazelcast.core.IMap;

public class HazelcastTest {

public static void main(String[] args) throws Exception {

HazelcastTest c = new HazelcastTest();

c.testTtlUsingHttpClientAgainstRestInterface();

   

}

public void testTtlUsingHttpClientAgainstRestInterface() throws Exception {

Config config = new FileSystemXmlConfig("hazelcast.xml");

final MapConfig mapConfig = config.getMapConfig("testMap");

System.out.println(mapConfig.getBackupCount());

System.out.println(mapConfig.getTimeToLiveSeconds());

System.out.println(mapConfig.getMaxIdleSeconds());

System.out.println(mapConfig.getName());

final HazelcastInstance instance = Hazelcast.newHazelcastInstance(config);

HttpClient client = new HttpClient();

String url = "http://localhost:5701/hazelcast/rest/maps/testMap/key2";

PostMethod post = new PostMethod(url);

post.setRequestBody("value2");

int resp = client.executeMethod(post);

// System.out.println(resp);

GetMethod get = new GetMethod(url);

Thread.sleep(1000);

client.executeMethod(get);

System.out.println(get.getStatusCode());

System.out.println(get.getResponseBodyAsString());

Assert.assertNotNull(get.getResponseBodyAsString());

Thread.sleep(1000);

client.executeMethod(get);

System.out.println(get.getStatusCode());

System.out.println(get.getResponseBodyAsString());

Assert.assertNotNull(get.getResponseBodyAsString());

Thread.sleep(5000);

client.executeMethod(get);

System.out.println(get.getStatusCode());

System.out.println(get.getResponseBodyAsString());

Assert.assertNull(get.getResponseBodyAsString());

}

hazelcast.xml

mayo...@gmail.com

unread,
Feb 14, 2014, 3:13:15 PM2/14/14
to haze...@googlegroups.com
Were you able to repro? When (in which release) do you plan to release the fix?

Ali Gürbüz

unread,
Feb 14, 2014, 3:56:19 PM2/14/14
to haze...@googlegroups.com
Yes I’ve reproduced and fixed, thank you for your contribution.
Fix will be in 3.1.6, which I hope will be released next week


-- 
You received this message because you are subscribed to the Google Groups "Hazelcast" group.
To unsubscribe from this group and stop receiving emails from it, send an email to hazelcast+...@googlegroups.com.
To post to this group, send email to haze...@googlegroups.com.
Visit this group at http://groups.google.com/group/hazelcast.

Matt

unread,
May 22, 2014, 7:01:52 AM5/22/14
to haze...@googlegroups.com, gurb...@gmail.com
The details seem a bit hazy here - we're in the process of upgrading to 3.1.5 and size-based eviction doesn't seem to be working either: is this expected in 3.1.5?

Thanks
Matt
Reply all
Reply to author
Forward
0 new messages