Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clarify Behavior of Negative TTL #7729

Closed
shelley-jean-baker opened this issue Mar 11, 2016 · 2 comments
Closed

Clarify Behavior of Negative TTL #7729

shelley-jean-baker opened this issue Mar 11, 2016 · 2 comments
Assignees
Milestone

Comments

@shelley-jean-baker
Copy link

@shelley-jean-baker shelley-jean-baker commented Mar 11, 2016

The documentation for map entry ttl [1,2] does not indicate the expected behavior if a negative value is provided:

Puts an entry into this map with a given ttl (time to live) value. Entry will expire and get evicted after the ttl. If ttl is 0, then the entry lives forever.

ttl - maximum time for this entry to stay in the map 0 means infinite.

It is ambiguous as to whether this entry will immediately expire, live forever, or throw an exception. Some testing indicates that the entry will live forever (i.e. negative values seem to be functionally equivalent to zero).

public static void main(String[] args) throws Exception {
    HazelcastInstance instance = Hazelcast.newHazelcastInstance(new Config());
    IMap<String, Long> map = instance.getMap("map");
    set(map, "zero", 0);
    set(map, "negative", -10);
    set(map, "positive", 10);
    instance.shutdown();
}
private static void set(IMap<String, Long> map, String key, long ttl) {
    map.set(key, ttl, ttl, TimeUnit.SECONDS);
    EntryView<String, Long> view = map.getEntryView(key);
    System.out.println(String.format("%s=%s ttl=%d expiration=%s", 
            key, map.get(key), 
            view != null ? view.getTtl() : null,
            view != null ? new Date(view.getExpirationTime()) : null));
}

The javadoc should be updated to clarify this behavior.

[1] IMap.put(K, V, long, TimeUnit)
[2] IMap.set(K, V, long, TimeUnit)

@Serdaro
Copy link
Member

@Serdaro Serdaro commented Mar 13, 2017

@ahmetmircik, May I help on this one?

@mmedenjak mmedenjak added this to the 3.9 milestone Aug 22, 2017
@Donnerbart Donnerbart self-assigned this Aug 31, 2017
@Donnerbart
Copy link
Contributor

@Donnerbart Donnerbart commented Aug 31, 2017

The behavior seems to be a bit more complex, since there is also the option to configure a TTL in for the whole map (which has "live forever" as default). It should be like:

  • positive TTL: is used, wins over the TTL from the MapConfig
  • zero TTL: entry lives forever, wins over TTL from the MapConfig
  • negative TTL: is ignored, TTL from the MapConfig is used

I created a PR with a test for these scenarios. I also created a PR to fix and cleanup the IMap JavaDoc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

5 participants
You can’t perform that action at this time.