Search code examples
hazelcasthazelcast-imap

Hazelcast Map Expire Listener on key, race condition


I have IMap<Long, SomeObject> on hazelcast member, where some part of Long keys have expiration time (TTL).

For this purpose I am registering EntryExpiredListener on key using addEntryListener(MapListener, K, boolean).

Everything works fine, but I have doubts.

As documentation states:

With the above approach, there is the possibility of missing events between the creation of the instance and registering the listener. To overcome this race condition, Hazelcast allows you to register listeners in configuration.

Will I encounter 'missing events' described above, if I register EntryExpiredListener on key?


Solution

  • If it’s on the member & you mark the listener as local ( so each member receive only local expration events) and define in the config, you wont since events will be local to each member.

    If you register the listener after you create the instance, after partitions distributed & before you register the listener, its possible that some data could expire. This is why above statements says you need to define listener in the config to prevent this.